Hi there,
This issue occurs after about half an hour running on a Windows CE 5.0
platform. Some post said it's due to the incorrect initialization of
the WAVEHDR. But it does not help. Below is the main body of the
codes:
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
__inline void INIT_WAVEHDR(LPWAVEHDR pwh, LPBYTE pData, DWORD cbData)
{
pwh->lpData = (LPSTR)pData;
pwh->dwBufferLength = cbData;
pwh->dwFlags = 0;
pwh->dwLoops = 1; // or 0, same result
}
void CALLBACK waveInProc(
HWAVEIN hwi,
UINT uMsg,
DWORD dwInstance,
DWORD dwParam1,
DWORD dwParam2)
{
switch(uMsg)
{
case WIM_DATA: ReleaseSemaphore((HANDLE)dwInstance, 1, NULL);
break;
default: break;
}
}
void CALLBACK waveOutProc(
HWAVEOUT hwo,
UINT uMsg,
DWORD dwInstance,
DWORD dwParam1,
DWORD dwParam2)
{
switch(uMsg)
{
case WOM_DONE: ReleaseSemaphore((HANDLE)dwInstance, 1, NULL);
break;
default: break;
}
}
MainFunction()
{
const DWORD cbwh = sizeof(WAVEHDR);
HANDLE hWaveOutDone = CreateSemaphore(NULL, NOF, NOF, NULL);
HANDLE hWaveInReady = CreateSemaphore(NULL, 0, NOF, NULL);
waveInOpen(&hwi, 0, &wfx, (DWORD)waveInProc, (DWORD)hWaveInReady,
CALLBACK_FUNCTION);
waveOutOpen(&hwo, 0, &wfx, (DWORD)waveOutProc,
(DWORD)hWaveOutDone, CALLBACK_FUNCTION);
for(dwIndex = 0; dwIndex < NOF; ++dwIndex)
{
memset(&who[dwIndex], 0, cbwh);
memset(&whi[dwIndex], 0, cbwh);
INIT_WAVEHDR(&whi[dwIndex], pWaveInBuffer[dwIndex], cbwh);
waveInPrepareHeader(hwi, &whi[dwIndex], cbwh);
waveInAddBuffer(hwi, &whi[dwIndex],cbwh);
}
waveInStart(hwi);
dwIndex=0;
for(;;)
{
WaitForSingleObject(hWaveInReady, INFINITE);
// the line below is commented out and the issue also occurs...
// AudioProcess(pWaveInBuffer[dwIndex],
pWaveOutBuffer[dwIndex]);
WaitForSingleObject(hWaveOutDone, INFINITE);
INIT_WAVEHDR(&who[dwIndex], pWaveOutBuffer[dwIndex], BUF_LEN);
waveOutUnprepareHeader(hwo, &who[dwIndex], cbwh);
memset(&who[dwIndex], 0, cbwh);
INIT_WAVEHDR(&who[dwIndex], pWaveOutBuffer[dwIndex], BUF_LEN);
waveOutPrepareHeader(hwo, &who[dwIndex], cbwh);
waveOutWrite(hwo, who[dwIndex], cbwh);
INIT_WAVEHDR(&whi[dwIndex], pWaveInBuffer[dwIndex], BUF_LEN);
waveInUnprepareHeader(hwi, &whi[dwIndex], cbwh);
memset(&whi[dwIndex], 0, cbwh);
INIT_WAVEHDR(&whi[dwIndex], pWaveInBuffer[dwIndex], BUF_LEN);
waveInPrepareHeader(hwi, &whi[dwIndex], cbwh);
waveInAddBuffer(hwi, &whi[dwIndex], cbwh);
dwIndex = (NOF == dwIndex + 1) ? 0 : dwIndex + 1;
}
}
//-----------------------------------------------------------------------------