This topic is now archived and is closed to further replies.


DirectSound Notification events

Recommended Posts

Gyannea    122
And churning right along with Direct Sound problems is the area of setting up notification events. I want to set up notification events in both the capture and playback buffers. The initial state of the events are unsignaled. Seems to work except for some reason after the record/send thread is created, the ''WaitForMultipleObjects()'' function immediately returns as if the playback event has been signaled. It happens only once. And the ->Play() DS method hasn''t even been called yet. Anyone know what one could do wrong such that the event would be signaled? Here is the setup of the playback buffer notifications: ================================================================dsTXbd.dwSize = sizeof(DSBUFFERDESC); dsTXbd.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY; // Make large enough to hold one second temp = 1 + rxwave.nAvgBytesPerSec / bytestoread; dsTXbd.dwBufferBytes = bytestoread * temp; // ''temp'' reads dsTXbd.guid3DAlgorithm = GUID_NULL; dsTXbd.lpwfxFormat = &rxwave; // Create the DirectSound buffer if(FAILED(pdsTXOb->CreateSoundBuffer(&dsTXbd, &pdsTXSecBufOb, NULL))) { return(DS_CREATE_BUF_FAIL); } // Create Notification interface for the send buffer if(FAILED(hr = pdsTXSecBufOb->QueryInterface( IID_IDirectSoundNotify, (void **)&pdsNotifyOb))) { return(DS_QUERY_NOTIFY_FAIL); } // Create the notification points and Event object dsNotify = new DSBPOSITIONNOTIFY [temp]; // Allocate memory offset = bytestoread - 1; // Create event object unsignaled hevent[1] = CreateEvent(NULL, FALSE, FALSE, NULL); // Load the notify structure with positions for(index = 0; index < temp; index++) { (dsNotify + index)->dwOffset = offset; (dsNotify + index)->hEventNotify = hevent[1]; offset = offset + bytestoread; } if(FAILED(pdsNotifyOb->SetNotificationPositions(temp,dsNotify))) { delete dsNotify; dsNotify = NULL; hevent[1] = NULL; SAFE_RELEASE(pdsNotifyOb);// Release buffer notify object return(DS_NOTIFY_POS_FAIL); } delete dsNotify; dsNotify = NULL; SAFE_RELEASE(pdsNotifyOb);// Release buffer notify object ==================================================== That creates the notification events in the playback buffer. They should be unsignaled and something should happen only after the playback begins and the safepointer reaches ''bytetoread-1'' assuming a start at zero (which is the case). Now for the thread where the wait function is found. Note the thread is created after all of DirectSOund has been setup. All buffers have been created and are waiting to be used. ====================================================== event = WaitForMultipleObjects(2, hevent, FALSE, INFINITE); if(event == WAIT_OBJECT_0) { if(ReceiveSignal() != ALL_OKAY) // Read the data { break; } SplitStereoSignals(); // Separate the stereo data } else if(event == WAIT_OBJECT_0 + 1) { // SendData(); } ========================================================== The ''SendData()'' routine is commented out since it is signalled on thread creation and all the arrays in it wont be dynamically allocated until a user asks to send something. Why is it signalled? And only once? After that, it is signalled properly after the user requests it. (Of course, nothing but silence is sent since the send fucntion is killed right now!) Brian Reinhold

Share this post

Link to post
Share on other sites