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;
}
}
//-----------------------------------------------------------------------------

Re: MMSYSERR_NOMEM in WaveInPrepareHeader() by voidcoder

voidcoder
Fri Nov 02 09:18:31 PDT 2007


What about memory usage the time it happens? How much
free memory is available? It looks like a memory leak
somewhere in your code ...

--
Oleg


Calvin wrote:
> 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;
> }
> }
> //-----------------------------------------------------------------------------
>

Re: MMSYSERR_NOMEM in WaveInPrepareHeader() by Calvin

Calvin
Sun Nov 04 21:18:15 PST 2007

All codes in the main loop is there. I can not find memory leak
anywhere.

the pWaveInBuffer and pWaveOutBuffer is on the stack:
BYTE pWaveInBuffer[NOF][BUF_LEN];

I've seen some codes which allocates memory in the heap:
h = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, BUF_LEN);
pWaveInBuffer[i] = GlobalLock(h);

However, there's no GlobalAlloc() & GlobalLock() under Windows CE. So
I try to allocate memory with C++ operator new, which I think it
equals LocalAlloc()

pWaveInBuffer[i] = new BYTE[BUF_LEN];

But it does not help.


On 11 3 , 12 18 , voidcoder <voidco...@yahoo.com> wrote:
> What about memory usage the time it happens? How much
> free memory is available? It looks like a memory leak
> somewhere in your code ...
>
> --
> Oleg
>


Re: MMSYSERR_NOMEM in WaveInPrepareHeader() by voidcoder

voidcoder
Tue Nov 06 04:41:46 PST 2007


If you just add the GlobalMemoryStatus call to your
main loop and debug print the memory status, does
the app consume any memory during the run?


--
Oleg


Calvin wrote:
> All codes in the main loop is there. I can not find memory leak
> anywhere.
>
> the pWaveInBuffer and pWaveOutBuffer is on the stack:
> BYTE pWaveInBuffer[NOF][BUF_LEN];
>
> I've seen some codes which allocates memory in the heap:
> h = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, BUF_LEN);
> pWaveInBuffer[i] = GlobalLock(h);
>
> However, there's no GlobalAlloc() & GlobalLock() under Windows CE. So
> I try to allocate memory with C++ operator new, which I think it
> equals LocalAlloc()
>
> pWaveInBuffer[i] = new BYTE[BUF_LEN];
>
> But it does not help.
>
>
> On 11 3 , 12 18 , voidcoder <voidco...@yahoo.com> wrote:
>> What about memory usage the time it happens? How much
>> free memory is available? It looks like a memory leak
>> somewhere in your code ...
>>
>> --
>> Oleg
>>
>

Re: MMSYSERR_NOMEM in WaveInPrepareHeader() by Calvin

Calvin
Tue Nov 06 22:47:39 PST 2007

Yes, the trend of dwAvailPhys is down, dwAvailVirtual keeps same.

On 11 6 , 8 41 , voidcoder <voidco...@yahoo.com> wrote:
> If you just add the GlobalMemoryStatus call to your
> main loop and debug print the memory status, does
> the app consume any memory during the run?
>
> --
> Oleg
>


Re: MMSYSERR_NOMEM in WaveInPrepareHeader() by voidcoder

voidcoder
Wed Nov 07 05:20:09 PST 2007


Hm, sounds interesting. It looks like the leak is not
in the app itself (wavedev driver?). Try isolating
the exact place where it consumes the memory, there
should be an API call or whatever leading to memory
leakage. Use GlobalMemoryStatus() for that.


--
Oleg


Calvin wrote:
> Yes, the trend of dwAvailPhys is down, dwAvailVirtual keeps same.
>
> On 11 6 , 8 41 , voidcoder <voidco...@yahoo.com> wrote:
>> If you just add the GlobalMemoryStatus call to your
>> main loop and debug print the memory status, does
>> the app consume any memory during the run?
>>
>> --
>> Oleg
>>
>