I’m doing audio sampling with waveInProc callback. The problem is that when I’m trying to stop sampling and close the audio device I get no msg in the callback – tried waveInStop, waveInClose, waveInReset.
Pls advice.
10xs,
Nahum
HWAVEIN hWaveIn
waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)waveInProc,0, CALLBACK_FUNCTION);
waveInStart(hWaveIn);
waveInStop(hWaveIn); //OR
waveInClose(hWaveIn); //OR
waveInReset(hWaveIn); //OR
UPDATE: Here is the code:
Starting:
waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)waveInProc,0, CALLBACK_FUNCTION);
waveInPrepareHeader(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInAddBuffer(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInStart(hWaveIn);
void CALLBACK waveInProc( HWAVEIN hwi, UINT uMsg, DWORD dwInstance,
DWORD dwParam1, DWORD dwParam2 )
{
if (uMsg == WIM_OPEN)
{
return;
}
if (uMsg == WIM_DATA)
{
//process data
waveInAddBuffer(hWaveIn,(PWAVEHDR)dwParam1,sizeof(WAVEHDR));
return;
}
if (uMsg == WIM_CLOSE) //NOT GETTING THIS MSG
{
printf("*****************got WIM_CLOSE\n");
}
}
So how to stop sampling and close the audio device?
Here is the code:
Starting:
waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)waveInProc,0, CALLBACK_FUNCTION);
waveInPrepareHeader(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInAddBuffer(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInStart(hWaveIn);
void CALLBACK waveInProc( HWAVEIN hwi, UINT uMsg, DWORD dwInstance,
DWORD dwParam1, DWORD dwParam2 )
{
if (uMsg == WIM_OPEN)
{
return;
}
if (uMsg == WIM_DATA)
{
//process data
waveInAddBuffer(hWaveIn,(PWAVEHDR)dwParam1,sizeof(WAVEHDR));
return;
}
if (uMsg == WIM_CLOSE) //NOT GETTING THIS MSG
{
printf("*****************got WIM_CLOSE\n");
}
}
So how to stop sampling and close the audio device?
10xs,
Nahum
Are you checking your
waveInOpenresult?Because it works as expected:
Code:
While processing data in real code make sure to take this into consideration: within the callback function:
To re-add buffer, you need to indicate such as need by signalling to another thread, using
PostMessageorSetEvent, so that your code outside of the callback could receive this indication and re-add the empty buffer from there.