You can send a variety of Windows CE messages to a windows procedure function to manage waveform audio playback. The following table shows these messages.
Message |
Description |
MM_WIM_CLOSE | Sent when the waveOutClose or the waveInClose function closes a device |
MM_WIM_DATA | Sent when the device driver finishes with a data block sent by waveOutWrite or waveInAddBuffer |
MM_WIM_OPEN | Sent when waveOutOpen or waveInOpen opens a device |
MM_WIM_DATA is the most useful message in this table. When MM_WIM_DATA signals a completed data block, you can clean up and free that data block. Unless you need to allocate memory or initialize variables, you probably do not need to process the MM_WIM_OPEN or MM_WIM_CLOSE messages.
Like other windows messages, these window messages have a wParam and an lParam parameter associated with them. The wParam always specifies a handle to the open waveform audio output device. For the MM_WIM_DATA message, lParam specifies a pointer to a WAVEHDR structure. This structure identifies a completed data block. The MM_WIM_CLOSE and MM_WIM_OPEN messages do not use lParam.
The following code example shows how to process the MM_WIM_DATA message.
// WndProc-Main window procedure
LRESULT FAR PASCAL WndProc (HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam)
{
switch (msg)
{
case MM_WIM_DATA:
// A waveform audio data block has been played and can now be
// freed.
waveOutUnprepareHeader ((HWAVEOUT)wParam, (LPWAVEHDR)lParam,
sizeof (WAVEHDR));
// Free hData memory
waveOutClose ((HWAVEOUT)wParam);
break;
}
return DefWindowProc (hWnd, msg, wParam, lParam);
}
The preceding example assumes that the application does not play multiple data blocks, so it can close the output device after playing a single data block.