錄音配置多個buffer問題 |
答題得分者是:qmlab
|
ericnien
一般會員 發表:4 回覆:0 積分:0 註冊:2007-11-11 發送簡訊給我 |
我使用的環境是VC++6.0
#include #include #include #include #pragma comment(lib, "winmm.lib") #define LENGTH 40000 void CALLBACK waveInProc(HWAVEIN wave_in, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2); static HWAVEIN wave_in; static WAVEFORMATEX wave; static WAVEHDR temp[8]; char buffer[8][LENGTH]={""}; int a=0; int main(int argc, char* argv[]) { int i; wave.wFormatTag=WAVE_FORMAT_PCM; wave.nChannels=1; wave.nSamplesPerSec=8000; wave.nAvgBytesPerSec=8000; wave.nBlockAlign=1; wave.wBitsPerSample=8; wave.cbSize=0; waveInOpen(&wave_in,WAVE_MAPPER,&wave, (DWORD)waveInProc,0,CALLBACK_FUNCTION); for(i=0;i<8;i ){ temp[i].lpData=buffer[i]; temp[i].dwBufferLength=LENGTH; temp[i].dwFlags=0; waveInPrepareHeader(wave_in,&temp[i],sizeof(WAVEHDR)); waveInAddBuffer(wave_in,&temp[i],sizeof(WAVEHDR)); } waveInStart(wave_in); waveInStop(wave_in); waveInClose(wave_in); return 0; } void CALLBACK waveInProc(HWAVEIN wave_in, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { switch(uMsg) { case WIM_DATA: a=(a 8)%8; waveInAddBuffer(wave_in,&temp[a],sizeof(WAVEHDR)); a ; break; } } 我想問的是,在main函式內我將8個buffer都配置進去了,但不知道接下來是怎樣運算,網路上文章都說,當waveInStart中buffer存滿,就會回傳WIM_DATA到waveInProc,接著在裡面配置新的buffer進去,我的想法是:一開始配置buffer是否一個接一個,當第一個buffer存滿,這時第二個buffer即會接著去儲存,而我們要做的則是將資料作處理後,再配置新的buffer使之不會中斷,但執行結果似乎只存滿了一個buffer就結束了,不知是否有人知道問題何在。 |
qmlab
一般會員 發表:0 回覆:6 積分:11 註冊:2008-02-15 發送簡訊給我 |
//使用Double Buffer交替錄音即可,多了會當O!Struct 填入如下即可正常運作.
void TSPEECH::Record(int OFF_ON_RESET) { if(OFF_ON_RESET==ON) //ON { WaveHdr1.lpData = (LPSTR)SpeechBuffer1; WaveHdr1.dwBufferLength = Def_SPEECHBUFFER_LENGTH_X; WaveHdr1.dwBytesRecorded = 0L; WaveHdr1.dwUser = 0L; WaveHdr1.dwFlags = 0L; WaveHdr1.dwLoops = 0L; WaveHdr1.lpNext = NULL; WaveHdr1.reserved = 0L; waveInPrepareHeader(HWaveIn,&WaveHdr1,sizeof(WAVEHDR)); waveInAddBuffer(HWaveIn,&WaveHdr1,sizeof(WAVEHDR)); WaveHdr2.lpData = (LPSTR)SpeechBuffer2; WaveHdr2.dwBufferLength = Def_SPEECHBUFFER_LENGTH_X; WaveHdr2.dwBytesRecorded = 0L; WaveHdr2.dwUser = 0L; WaveHdr2.dwFlags = 0L; WaveHdr2.dwLoops = 0L; WaveHdr2.lpNext = NULL; WaveHdr2.reserved = 0L; waveInPrepareHeader(HWaveIn,&WaveHdr2,sizeof(WAVEHDR)); waveInAddBuffer(HWaveIn,&WaveHdr2,sizeof(WAVEHDR)); waveInStart(HWaveIn); } else if(OFF_ON_RESET==OFF) //OFF { //waveInStop(HWaveIn); waveInReset(HWaveIn); waveInClose(HWaveIn); } else if(OFF_ON_RESET==RESET) //RESET { PWaveHdr->dwBufferLength = Def_SPEECHBUFFER_LENGTH_X; PWaveHdr->dwBytesRecorded = 0L; PWaveHdr->dwUser = 0L; PWaveHdr->dwFlags = 0L; //PWaveHdr->dwLoops = 0L; //test //PWaveHdr->lpNext = NULL; //test PWaveHdr->reserved = 0L; //win98 不可用 waveInPrepareHeader(HWaveIn,PWaveHdr,sizeof(WAVEHDR)); //win98 不可用 waveInAddBuffer(HWaveIn,PWaveHdr,sizeof(WAVEHDR)); } } |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |