From: sid on 20 Apr 2006 06:53 Hi Guys Apologies for such a lengthy mail but I want to be elaborate so that things are clear to the reader... I am trying to record microphone input into a buffer which I can later manipulate accordingly or even record on a wave file if need be, but I am facing nightmares. Can anyone help me out so that I can get going... At present i have a START and STOP button and the code is as follows in both click events..(Just to remind its running on a PPC 2003) Problem: The code hangs after starting the recording and never stops it and goes in a deadlock situation. I am using a callback routine to handle messages HWAVEIN hWaveIn; WAVEFORMATEX wfex; WAVEHDR wvhdr; LPSTR p_Buff; BOOL fRecording; MMRESULT mRes; START ===== UINT numDevices=waveInGetNumDevs(); /* Initialize the WAVEFORMATEX and WAVEHDR*/ wfex.wFormatTag=WAVE_FORMAT_PCM; wfex.nChannels=1;//Monoaural data Recording..For stereo use 2 wfex.nSamplesPerSec=8000; wfex.wBitsPerSample=8;//can use 16 also for WAVE_FORMAT_PCM wfex.nBlockAlign=(wfex.nChannels*wfex.wBitsPerSample)/8; wfex.nAvgBytesPerSec=wfex.nSamplesPerSec*wfex.nBlockAlign; wfex.cbSize=0; mRes=waveInOpen(&hWaveIn,0,&wfex,(DWORD)waveInProcHandler,0,CALLBACK_FUNCTION); ZeroMemory(&wvhdr,sizeof(WAVEHDR)); wvhdr.dwBufferLength=wfex.nAvgBytesPerSec*5;//5 second data p_Buff=(LPSTR)LocalAlloc(LMEM_FIXED,wvhdr.dwBufferLength); wvhdr.lpData=p_Buff; wvhdr.dwFlags=0; mRes=waveInPrepareHeader(hWaveIn,&wvhdr,sizeof(WAVEHDR)); if(mRes==MMSYSERR_NOERROR) { mRes=waveInAddBuffer(hWaveIn,&wvhdr,sizeof(WAVEHDR)); if(mRes==MMSYSERR_NOERROR) { mRes=waveInStart(hWaveIn); if(mRes==MMSYSERR_NOERROR) { fRecording=TRUE; SetDlgItemText(hwnd,IDC_DISPLAYAREA,TEXT("Recording Started...")); } else SetDlgItemText(hwnd,IDC_DISPLAYAREA,TEXT("Recording Not Started")); } This code seems to be working as it gives me Recording Started...notification without any hassels, but thereafter everything hangs and my STOP button never works and comes out of a hang... STOP ==== if(fRecording) { waveInStop(hWaveIn); waveInReset(hWaveIn); waveInUnprepareHeader(hWaveIn,&wvhdr,sizeof(WAVEHDR)); fRecording=FALSE; SetDlgItemText(hwnd,IDC_DISPLAYAREA,TEXT("Recording Terminated...")); } Ideally I guess waveInUnprepareHeader should fire the WIM_DATA event wherein I have coded as under case WIM_DATA: if(fRecording) { waveInStop(hWaveIn); waveInReset(hWaveIn); waveInUnprepareHeader(hWaveIn,&wvhdr,sizeof(WAVEHDR)); fRecording=FALSE; } waveInReset(hWaveIn); waveInClose(hWaveIn); Regards Sid
|
Pages: 1 Prev: IMailSyncCallBack Next: IImageSinkFilter and encoder format |