/*

//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文件加进去,进行相应的设置,就可以了。

最新文章

  1. .NET 4.5.1 预览版新特性
  2. 没有对“C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files”的写访问权限 的解决方案
  3. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(十一) 代码重构使用反射工厂解耦
  4. java--- Map详解
  5. percona
  6. C#中virtual和abstract的区别
  7. iOS第三方支付-微信支付
  8. 为网站添加网址图标favicon.ico
  9. Android Studio常用快捷键汇总(mac)
  10. c++ 孟岩推荐 书籍
  11. Oracle与DB2的区别
  12. 基于Visual C++2013拆解世界五百强面试题--题17-程序结果分析1
  13. 声明数组变量/// 计算所有元素的总和/打印所有元素总和/输出/foreach循环/数组作为函数的参数/调用printArray方法打印
  14. 2018/1/28 RocketMq学习笔记
  15. 从零开始学安全(三十四)●百度杯 ctf比赛 九月场 sqli
  16. ubuntu常见问题解决方法
  17. (1) 安卓导入mqtt包基本通信
  18. [Err] 1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creator【s
  19. Java面向对象程序设计
  20. wepy - 与原生有什么不同(x.wpy)使用实例

热门文章

  1. 集合篇 —— Collection(1):JDK 中的重复实现问题
  2. ubuntu安装mysql&lt;服务器&gt;
  3. [LOJ#2255][BZOJ5017][Snoi2017]炸弹
  4. mybatis学习(八)——resultMap之association&amp;&amp;collection解析
  5. 优化join语句
  6. JavaWeb学习总结(十三)——使用Session防止表单重复提交(转)
  7. python3基础语法(标识符,注释,数据类型,获取用户输出,代码块,python保留字)
  8. buffer和cache怎么让你们解释的那么难理解?
  9. 关于toggle的用法
  10. npm-debug.log文件出现原因