基本信息
源码名称:c++ pcm转mp3编码(编码器为lamp)
源码大小:10.10M
文件格式:.rar
开发语言:C/C++
更新时间:2019-07-12
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
这是一个采集PCM数据,并可编码为MP3的例子,编码器为lamp
这是一个采集PCM数据,并可编码为MP3的例子,编码器为lamp
// mp3_stream.cpp : Defines the entry point for the console application. // #pragma setlocale(".1251") #include "stdafx.h" #include "INCLUDE/mp3_simple.h" #include "INCLUDE/waveIN_simple.h" //--------------------------------------- #include "INCLUDE/BladeMP3EncDLL.h" //---------------------------------------- #include <conio.h> // An example of the implementation. class mp3Writer: public IReceiver{ private: CMP3Simple m_mp3Enc; FILE *f; public: mp3Writer(unsigned int bitrate = 128, unsigned int finalSimpleRate = 0): m_mp3Enc(bitrate, 44100, finalSimpleRate) { f = fopen("music.mp3", "wb"); if (f == NULL) throw "Can't create MP3 file."; }; ~mp3Writer() { fclose(f); }; virtual void ReceiveBuffer(LPSTR lpData, DWORD dwBytesRecorded) { BYTE mp3Out[44100 * 4]; DWORD dwOut; m_mp3Enc.Encode((PSHORT) lpData, dwBytesRecorded/2, mp3Out, &dwOut); fwrite(mp3Out, dwOut, 1, f); }; }; // Prints the application's help. void printHelp(char *progname) { printf("%s -devices\n\tWill list WaveIN devices.\n\n", progname); printf("%s -device=<device_name>\n\tWill list recording lines of the WaveIN <device_name> device.\n\n", progname); printf("%s -device=<device_name> -line=<line_name> [-v=<volume>] [-br=<bitrate>] [-sr=<samplerate>]\n", progname); printf("\tWill record from the <line_name> at the given voice <volume>, output <bitrate> (in Kbps)\n"); printf("\tand output <samplerate> (in Hz).\n\n"); printf("\t<volume>, <bitrate> and <samplerate> are optional parameters.\n"); printf("\t<volume> - integer value between (0..100), defaults to 0 if not set.\n"); printf("\t<bitrate> - integer value (16, 24, 32, .., 64, etc.), defaults to 128 if not set.\n"); printf("\t<samplerate> - integer value (44100, 32000, 22050, etc.), defaults to 44100 if not set.\n"); } // Lists WaveIN devices present in the system. void printWaveINDevices() { const vector<CWaveINSimple*>& wInDevices = CWaveINSimple::GetDevices(); UINT i; for (i = 0; i < wInDevices.size(); i ) { OutputDebugString(wInDevices[i]->GetName()); printf("%s\n", wInDevices[i]->GetName()); } } // Prints WaveIN device's lines. void printLines(CWaveINSimple& WaveInDevice) { CHAR szName[MIXER_LONG_NAME_CHARS]; UINT j; try { CMixer& mixer = WaveInDevice.OpenMixer(); const vector<CMixerLine*>& mLines = mixer.GetLines(); for (j = 0; j < mLines.size(); j ) { ::CharToOem(mLines[j]->GetName(), szName); printf("%s\n", szName); } mixer.Close(); } catch (const char *err) { printf("%s\n",err); } } int main(int argc, char* argv[]) { char *strDeviceName = "FrontMic (Realtek High Definiti"/*NULL*/; char *strLineName = "主音量"; char *strTemp = NULL; UINT nVolume = 100; UINT nBitRate = 128; UINT nFSimpleRate = 0; printWaveINDevices(); setlocale(LC_ALL, ".866"); mp3Writer *mp3Wr; printf("\nRecording at %dKbps, ", nBitRate); if (nFSimpleRate == 0) printf("44100Hz\n"); else printf("%dHz\n", nFSimpleRate); printf("from %s (%s).\n", strLineName, strDeviceName); printf("Volume %d%%.\n\n", nVolume); CWaveINSimple& device = CWaveINSimple::GetDevice(strDeviceName); CMixer& mixer = device.OpenMixer(); //mixer.InitLines(); CMixerLine& mixerline = mixer.GetLine(strLineName); mixerline.UnMute(); mixerline.SetVolume(nVolume); mixerline.Select(); mixer.Close(); mp3Wr = new mp3Writer(nBitRate, nFSimpleRate); device.Start((IReceiver *)mp3Wr); printf("hit <ENTER> to stop ...\n"); while (!_kbhit()) ::Sleep(100); device.Stop(); delete mp3Wr; CWaveINSimple::CleanUp(); return 0; } /* int main(int argc, char* argv[]) { mp3Writer *mp3Wr; char *strDeviceName = NULL; char *strLineName = NULL; char *strTemp = NULL; UINT nVolume = 0; UINT nBitRate = 128; UINT nFSimpleRate = 0; printWaveINDevices(); setlocale( LC_ALL, ".866"); try { if (argc < 2) printHelp(argv[0]); else if (argc == 2) { if (::strcmp(argv[1],"-devices") == 0) printWaveINDevices(); else if ((strTemp = ::strstr(argv[1],"-device=")) == argv[1]) { strDeviceName = &strTemp[8]; CWaveINSimple& device = CWaveINSimple::GetDevice(strDeviceName); printLines(device); } else printHelp(argv[0]); } else { if ((strTemp = ::strstr(argv[1],"-device=")) == argv[1]) { strDeviceName = &strTemp[8]; } if ((strTemp = ::strstr(argv[2],"-line=")) == argv[2]) { strLineName = &strTemp[6]; } if ((strDeviceName == NULL) || (strLineName == NULL)) { printHelp(argv[0]); return 0; } for (int i = 3; i < argc; i ) { if ((strTemp = ::strstr(argv[i],"-v=")) == argv[i]) { strTemp = &strTemp[3]; nVolume = (UINT) atoi(strTemp); } else if ((strTemp = ::strstr(argv[i],"-br=")) == argv[i]) { strTemp = &strTemp[4]; nBitRate = (UINT) atoi(strTemp); } else if ((strTemp = ::strstr(argv[i],"-sr=")) == argv[i]) { strTemp = &strTemp[4]; nFSimpleRate = (UINT) atoi(strTemp); } else { printHelp(argv[0]); return 0; } } printf("\nRecording at %dKbps, ", nBitRate); if (nFSimpleRate == 0) printf("44100Hz\n"); else printf("%dHz\n", nFSimpleRate); printf("from %s (%s).\n", strLineName, strDeviceName); printf("Volume %d%%.\n\n", nVolume); CWaveINSimple& device = CWaveINSimple::GetDevice(strDeviceName); CMixer& mixer = device.OpenMixer(); CMixerLine& mixerline = mixer.GetLine(strLineName); mixerline.UnMute(); mixerline.SetVolume(nVolume); mixerline.Select(); mixer.Close(); mp3Wr = new mp3Writer(nBitRate, nFSimpleRate); device.Start((IReceiver *) mp3Wr); printf("hit <ENTER> to stop ...\n"); while( !_kbhit() ) ::Sleep(100); device.Stop(); delete mp3Wr; } } catch (const char *err) { printf("%s\n",err); } CWaveINSimple::CleanUp(); return 0; } */