錄成 8k 16bit 的程式原始碼,要改格式直接改參數.
HINSTANCE g_hInstance;
HANDLE m_hMCIWnd;
int deviceID;
//---------------------------------------------------------------------------
void __fastcall TForm1::RecordButtonClick(TObject *Sender){
MediaPlayer->Close();
MediaPlayer->FileName = "";
MCIWndNew(m_hMCIWnd, "waveaudio");
// change the default audio setting (which is 11khz 8bit mono)
MCI_WAVE_SET_PARMS set_parms;
set_parms.wFormatTag = WAVE_FORMAT_PCM;
set_parms.wBitsPerSample = 16;
set_parms.nChannels = 1;
set_parms.nBlockAlign = (set_parms.nChannels*set_parms.wBitsPerSample)/8;
set_parms.nSamplesPerSec = 8000;
set_parms.nAvgBytesPerSec = ((set_parms.wBitsPerSample) *
set_parms.nChannels *
set_parms.nSamplesPerSec)/8;
// params.WaveSetParms.nBlockAlign = ((params.WaveSetParms.wBitsPerSample)/8) * params.WaveSetParms.nChannels;
// params.WaveSetParms.nAvgBytesPerSec = params.WaveSetParms.nBlockAlign * params.WaveSetParms.nSamplesPerSec;
// params.WaveSetParms.wFormatTag = WAVE_FORMAT_PCM; /* Uncompressed format */
//int deviceID=MCIWndGetDeviceID(m_hMCIWnd);
//mciSendCommand需要deviceID當作傳入的參數
deviceID=MCIWndGetDeviceID(m_hMCIWnd);
int result = mciSendCommand( deviceID, MCI_SET,
MCI_WAIT
| MCI_WAVE_SET_FORMATTAG
| MCI_WAVE_SET_BITSPERSAMPLE
| MCI_WAVE_SET_CHANNELS
| MCI_WAVE_SET_SAMPLESPERSEC
| MCI_WAVE_SET_AVGBYTESPERSEC
| MCI_WAVE_SET_BLOCKALIGN,
(DWORD)(LPVOID)&set_parms);
if(result){
char buffer[100];
mciGetErrorString(result, buffer, sizeof(buffer));
Application->MessageBox(buffer, "On-Line PC 錄音模擬電話語音輸入", MB_OK);
return;
}
MCIWndRecord(m_hMCIWnd);
RecordButton->Enabled = false;
EndRecordButton->Enabled = true;
RecordLabel->Caption="錄音中 ...";
WaveLengthLabel->Caption = "00:00:00.00";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EndRecordButtonClick(TObject *Sender){
MCIWndStop(m_hMCIWnd);
//MCIWndSave(m_hMCIWnd,"test.wav");
Mmsystem::MCI_SAVE_PARMS mciSP;
mciSP.lpfilename ="temp.wav";
mciSendCommand(deviceID, MCI_SAVE, MCI_SAVE_FILE | MCI_WAIT,(DWORD)(LPVOID)&mciSP);
MCIWndClose(m_hMCIWnd);
RecordButton->Enabled = true;
EndRecordButton->Enabled = false;
RecordLabel->Caption = "IDLE";
}