Microsoft Windows CE 3.0  

Capture Buffer Notification

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

You may want your application to be notified when the current read position reaches a certain point in the buffer, or when it reaches the end. The current read position is the point up to which it is safe to read data from the buffer. With the IDirectSoundNotify::SetNotificationPositionsmethod you can set any number of points within the buffer where events are to be signaled.

First you have to obtain a pointer to the IDirectSoundNotifyinterface. You can do this with the capture buffer's QueryInterfacemethod, as shown in the example under Play Buffer Notification.

Next create an event object with the Win32 CreateEventfunction. You put the handle to this event in the hEventNotifymember of a DSBPOSITIONNOTIFYstructure, and in the dwOffsetmember of that structure you specify the offset within the buffer where you want the event to be signaled. Then you pass the address of the structure or array of structures, if you want to set more than one notification position to the IDirectSoundNotify::SetNotificationPositionsmethod.

The following example sets up three notification positions in a one-second buffer. One event will be signaled when the read position nears the halfway point in the buffer, another will be signaled when it nears the end of the buffer, and the third will be signaled when capture stops.

#define cEvents 3 /* In this example it is
assumed that the following variables have been properly
initialized, and that wfx was included in the buffer description
when the buffer was created. LPDIRECTSOUNDNOTIFY lpDsNotify;
WAVEFORMATEX wfx; */ HANDLE rghEvent[cEvents] = {0};
DSBPOSITIONNOTIFY rgdsbpn[cEvents]; HRESULT hr; int i; // Create
the events for (i = 0; i < cEvents; ++i) { rghEvent[i] =
CreateEvent(NULL, TRUE, FALSE, NULL); if (NULL == rghEvent[i]) { hr
= GetLastError(); goto Error; } } // Describe notifications.
rgdsbpn[0].dwOffset = (wfx.nAvgBytesPerSec/2) -1;
rgdsbpn[0].hEventNotify = rghEvent[0]; rgdsbpn[1].dwOffset =
wfx.nAvgBytesPerSec - 1; rgdsbpn[1].hEventNotify = rghEvent[1];
rgdsbpn[2].dwOffset = DSBPN_OFFSETSTOP; rgdsbpn[2].hEventNotify =
rghEvent[2]; // Create notifications. hr =
lpDsNotify->SetNotificationPositions(cEvents, rgdsbpn);


 Last updated on Tuesday, May 18, 2004

© 2004 Microsoft Corporation. All rights reserved.