/*

//My_lame.h

*/

#pragma once
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "BladeMP3EncDLL.h"
class My_lame
{
public:
My_lame(void);
~My_lame(void);

HINSTANCE hDLL;
BEINITSTREAM beInitStream;
BEENCODECHUNK beEncodeChunk;
BEDEINITSTREAM beDeinitStream;
BECLOSESTREAM beCloseStream;
BEVERSION beVersion;
BEWRITEVBRHEADER beWriteVBRHeader;
BEWRITEINFOTAG beWriteInfoTag;
int km_convertMp3();
};

/*

//My_lame.cpp

/*

#include "StdAfx.h"
#include "My_lame.h"
#include <string>
using namespace std;
My_lame::My_lame(void)
{
hDLL =NULL;
beInitStream=NULL;
beEncodeChunk=NULL;
beDeinitStream=NULL;
beCloseStream=NULL;
beVersion=NULL;
beWriteVBRHeader=NULL;
beWriteInfoTag=NULL;
hDLL = LoadLibrary("lame_enc.dll");

}

My_lame::~My_lame(void)
{
FreeLibrary(hDLL);

}

int My_lame::km_convertMp3()
{

FILE* pFileIn =NULL;
FILE* pFileOut =NULL;
BE_VERSION Version ={0,};
BE_CONFIG beConfig ={0,};

CHAR* strFileIn1="F:\\1.wav";
CHAR* strFileOut1="F:\\1.mp3";

DWORD dwSamples =0;
DWORD dwMP3Buffer =0;
HBE_STREAM hbeStream =0;
BE_ERR err =0;

PBYTE pMP3Buffer =NULL;
PSHORT pWAVBuffer =NULL;
// Load lame_enc.dll library (Make sure though that you set the
// project/settings/debug Working Directory correctly, otherwhise the DLL can't be loaded

hDLL = LoadLibrary("lame_enc.dll");

if ( NULL == hDLL )
{
hDLL = LoadLibrary("lame_enc.dll");
}

if( NULL == hDLL )
{
fprintf(stderr,"Error loading lame_enc.DLL");
return -1;
}

// Get Interface functions from the DLL
beInitStream = (BEINITSTREAM) GetProcAddress(hDLL, TEXT_BEINITSTREAM);
beEncodeChunk = (BEENCODECHUNK) GetProcAddress(hDLL, TEXT_BEENCODECHUNK);
beDeinitStream = (BEDEINITSTREAM) GetProcAddress(hDLL, TEXT_BEDEINITSTREAM);
beCloseStream = (BECLOSESTREAM) GetProcAddress(hDLL, TEXT_BECLOSESTREAM);
beVersion = (BEVERSION) GetProcAddress(hDLL, TEXT_BEVERSION);
beWriteVBRHeader= (BEWRITEVBRHEADER) GetProcAddress(hDLL,TEXT_BEWRITEVBRHEADER);
beWriteInfoTag = (BEWRITEINFOTAG) GetProcAddress(hDLL,TEXT_BEWRITEINFOTAG);

// Check if all interfaces are present
if(!beInitStream || !beEncodeChunk || !beDeinitStream || !beCloseStream || !beVersion || !beWriteVBRHeader)
{
printf("Unable to get LAME interfaces");
return -1;
}

// Get the version number
beVersion( &Version );

printf(
"lame_enc.dll version %u.%02u (%u/%u/%u)\n"
"lame_enc Engine %u.%02u\n"
"lame_enc homepage at %s\n\n",
Version.byDLLMajorVersion, Version.byDLLMinorVersion,
Version.byDay, Version.byMonth, Version.wYear,
Version.byMajorVersion, Version.byMinorVersion,
Version.zHomepage);

// Try to open the WAV file, be sure to open it as a binary file!

pFileIn = fopen( strFileIn1, "rb" );

// Check file open result
if(pFileIn == NULL)
{
return -1;
}

// Open MP3 file
pFileOut= fopen(strFileOut1,"wb+");

// Check file open result
if(pFileOut == NULL)
{
fprintf(stderr,"Error creating file %s", strFileOut1);
return -1;
}

memset(&beConfig,0,sizeof(beConfig)); // clear all fields

// use the LAME config structure
beConfig.dwConfig = BE_CONFIG_LAME;

// this are the default settings for testcase.wav
beConfig.format.LHV1.dwStructVersion = 1;
beConfig.format.LHV1.dwStructSize = sizeof(beConfig);
beConfig.format.LHV1.dwSampleRate = 44100; // INPUT FREQUENCY
beConfig.format.LHV1.dwReSampleRate = 0; // DON"T RESAMPLE
beConfig.format.LHV1.nMode = BE_MP3_MODE_JSTEREO; // OUTPUT IN STREO
beConfig.format.LHV1.dwBitrate = 128; // MINIMUM BIT RATE
beConfig.format.LHV1.nPreset = LQP_R3MIX; // QUALITY PRESET SETTING
beConfig.format.LHV1.dwMpegVersion = MPEG1; // MPEG VERSION (I or II)
beConfig.format.LHV1.dwPsyModel = 0; // USE DEFAULT PSYCHOACOUSTIC MODEL
beConfig.format.LHV1.dwEmphasis = 0; // NO EMPHASIS TURNED ON
beConfig.format.LHV1.bOriginal = TRUE; // SET ORIGINAL FLAG
beConfig.format.LHV1.bWriteVBRHeader = TRUE; // Write INFO tag

beConfig.format.LHV1.bNoRes = TRUE; // No Bit resorvoir

// Init the MP3 Stream
err = beInitStream(&beConfig, &dwSamples, &dwMP3Buffer, &hbeStream);

// Check result
if(err != BE_ERR_SUCCESSFUL)
{
fprintf(stderr,"Error opening encoding stream (%lu)", err);
return -1;
}

// Allocate MP3 buffer
pMP3Buffer = new BYTE[dwMP3Buffer];

// Allocate WAV buffer
pWAVBuffer = new SHORT[dwSamples];

// Check if Buffer are allocated properly
if(!pMP3Buffer || !pWAVBuffer)
{
printf("Out of memory");
return -1;
}

DWORD dwRead=0;
DWORD dwWrite=0;
DWORD dwDone=0;
DWORD dwFileSize=0;

// Seek to end of file
fseek(pFileIn,0,SEEK_END);

// Get the file size
dwFileSize=ftell(pFileIn);

// Seek back to start of WAV file,
// but skip the first 44 bytes, since that's the WAV header
fseek(pFileIn,44,SEEK_SET);

// Convert All PCM samples
while ( (dwRead=fread(pWAVBuffer,sizeof(SHORT),dwSamples,pFileIn)) >0 )
{
// Encode samples
err = beEncodeChunk(hbeStream, dwRead, pWAVBuffer, pMP3Buffer, &dwWrite);

// Check result
if(err != BE_ERR_SUCCESSFUL)
{
beCloseStream(hbeStream);
fprintf(stderr,"beEncodeChunk() failed (%lu)", err);
return -1;
}

// write dwWrite bytes that are returned in tehe pMP3Buffer to disk
if(fwrite(pMP3Buffer,1,dwWrite,pFileOut) != dwWrite)
{
fprintf(stderr,"Output file write error");
return -1;
}

dwDone += dwRead*sizeof(SHORT);

printf("Done: %0.2f%% \r", 100 * (float)dwDone/(float)(dwFileSize));
}

// Deinit the stream
err = beDeinitStream(hbeStream, pMP3Buffer, &dwWrite);

// Check result
if(err != BE_ERR_SUCCESSFUL)
{

beCloseStream(hbeStream);
fprintf(stderr,"beExitStream failed (%lu)", err);
return -1;
}

// Are there any bytes returned from the DeInit call?
// If so, write them to disk
if( dwWrite )
{
if( fwrite( pMP3Buffer, 1, dwWrite, pFileOut ) != dwWrite )
{
fprintf(stderr,"Output file write error");
return -1;
}
}

// close the MP3 Stream
beCloseStream( hbeStream );

// Delete WAV buffer
delete [] pWAVBuffer;

// Delete MP3 Buffer
delete [] pMP3Buffer;

// Close input file
fclose( pFileIn );

// Close output file
fclose( pFileOut );

if ( beWriteInfoTag )
{
// Write the INFO Tag
//change
//beWriteInfoTag( hbeStream, strFileOut );
beWriteInfoTag( hbeStream, strFileOut1 );
}
else
{

//change
//beWriteVBRHeader( strFileOut );
beWriteVBRHeader( strFileOut1 );
}

return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
My_lame lame;
lame.km_convertMp3();

return 0;
}

再把dll文件加进去,进行相应的设置,就可以了。

vs2010音频文件压缩 调用lame_enc.dll将WAV格式转换成MP3的更多相关文章

  1. 怎样将M4A音频格式转换成MP3格式

    因为MP3音频格式应用的广泛性,所以很多时候我们都需要将不同的音频格式转换成MP3格式的,那么如果我们需要将M4A音频格式转换成MP3格式,我们应该怎样进行实现呢?下面我们就一起来看一下吧. 操作步骤 ...

  2. 怎样将flac音频格式转换成MP3格式

    Flac音频格式怎样转换成MP3格式呢?随着现在音频格式的不断多样性,生活中很多时候我们都会遇到音频格式转换的问题,如flac音频转MP3的问题,那么我们应该如何去解决这个问题呢?下面我们就一起去来一 ...

  3. 如何将AAC音频转换成MP3格式

    我们应该怎样将AAC音频转换成MP3格式呢?AAC是一种专为声音数据设计的文件压缩格式,相对于MP3音频来说更加高效,性价比跟高.但是因为MP3音频格式的通用性,我们还是时常需要将AAC音频转换成MP ...

  4. .net amr格式文件转换成mp3格式文件的方法

    前言:winform端对于音频文件的格式多有限制,大多数不支持amr格式的文件的播放.但是,手机端传过来的音频文件大多数是amr格式的文件,所以,要想在winform客户端支持音频文件的播放,可以通过 ...

  5. iOS 通过(lame)将录制音频转换成Mp3

    版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明出处,保留原帖地址及作者署名. Url:http://blog.csdn.net/ysy441088327/article/detail ...

  6. 使用jave2将音频wav转换成mp3格式

    最近需要用到语音合成功能,网上查阅了一番,发现可以使用腾讯云的语音合成API来完成这个功能,但是腾讯云的api返回的是wav格式的音频文件,这个格式的文件有些不通用,因此需要转换成mp3格式的文件.  ...

  7. python脚本实现音频m4a格式转成MP3格式

    群里看到有人询问:谁会用python将微信音频文件后缀m4a格式转成mp3格式,毫不犹豫回了句:我会.然后就私下聊起来了 解决方法介绍如下: 工具:windows系统,python2.7,转换库ffm ...

  8. 使用jave2实现将wav格式的音频转换成mp3格式

    最近需要用到语音合成功能,网上查阅了一番,发现可以使用腾讯云的语音合成API来完成这个功能,但是腾讯云的api返回的是wav格式的音频文件,这个格式的文件有些不通用,因此需要转换成mp3格式的文件. ...

  9. 调用CImg库显示WAV格式音频波形

    最近在做傅里叶变换和小波变换时经常要通过显示波形来检验算法,但通过visual studio之类显示波形又显得麻烦,而且不能跨平台. CImg是一个跨平台的C++的图像处理库,提供的图像处理等功能十分 ...

随机推荐

  1. WebSocket & websockets

    WebSocket & websockets https://en.wikipedia.org/wiki/WebSocket https://developer.mozilla.org/en- ...

  2. 【bzoj2111】[ZJOI2010]Perm 排列计数 dp+Lucas定理

    题目描述 称一个1,2,...,N的排列P1,P2...,Pn是Mogic的,当且仅当2<=i<=N时,Pi>Pi/2. 计算1,2,...N的排列中有多少是Mogic的,答案可能很 ...

  3. 【bzoj4292】[PA2015]Równanie 暴力

    题目描述 对于一个正整数n,定义f(n)为它十进制下每一位数字的平方的和.现在给定三个正整数k,a,b,请求出满足a<=n<=b且k*f(n)=n的n的个数. 输入 第一行包含三个正整数k ...

  4. 【bzoj3105】[cqoi2013]新Nim游戏 高斯消元求线性基

    题目描述 传统的Nim游戏是这样的:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量可以不同).两个游戏者轮流操作,每次可以选一个火柴堆拿走若干根火柴.可以只拿一根,也可以拿走整堆火柴,但不能同时从 ...

  5. Linux 终端操作之「I/O Redirection」

    I/O 重定向是在终端运行程序时很常用的技巧,但是我对它所知甚少.今天我在 DigitalOcean 上发现了一篇很好的 tutorial.这篇随笔记录一下我的心得体会和发现的一个问题. I/O re ...

  6. BZOJ 4821 [Sdoi2017]相关分析 ——线段树

    打开题面,看到许多$\sum$ woc,好神啊,SDOI好强啊 然后展开之后,woc,SDOI好弱啊,怎么T3出个线段树裸题啊. 最后写代码的时候,woc,SDOI怎么出个这么码农的题啊,怎么调啊. ...

  7. SpringBoot jackson传入List引起的坑

    一.jackson无法解析value为[]的json 当入参为{xxxx1:[1,2,3],xxxx2:[obj1,obj2,obj3]}时,springmvn controller接收入参写为Lon ...

  8. bzoj 4555 NTT优化子集斯特林

    题目大意 读入n 求\(f(n)=\sum_{i=0}^n\sum_{j=0}^i\left\{\begin{matrix}i \\ j\end{matrix}\right\}*2^j*j!\) 分析 ...

  9. gulp前端自动化入门

    一.从零开始搭建gulp前端自动化 1.首先安装nodejs 2.npm init 初始化 生成package.json 2.1 可以选装cnpm cnpm是淘宝提供的服务 安装:命令提示符执行npm ...

  10. 下拉菜单的option的value属性值问题

    下拉菜单的所有option都必须有value值,如果没有value会将标签中间的值传上去: 比如: <span class="el_spans">试卷级别:</s ...