Skip to main content
gamedev.net
🔒 Locked

DirectSound:MsgWaitForMultipleObjects ???

Started by Radu094 Mar 2, 2004 at 1:28 AM 2 replies 1k views
Original Post
Radu094
Radu094
Ok, I''m having the weirdest bug I had in the last month or so. It''s a bit long to explain, so I don''t mind if you don''t have the patience to read through.Hope someone is listening ''though: 1. I''m using DirectSound (9.0). I have 3 .wav sounds, each played from it''s own secondary buffers.No streaming. Also, I have 3 .ogg sounds, each from a buffer, but the .ogg files are quite large so I''m streaming them. 2. When I create the streaming sounds I use IID_IDirectSoundNotify to set up a notification when buffer reaches 0%, 33% and 66%. I do this for EACH stream, and setup diferent handles for each stream respectivly, but the same handle for each of the 3 positions.
...
	hNotifyEvent[0] = CreateEvent( NULL, FALSE, FALSE, NULL );
	hNotifyEvent[1] = CreateEvent( NULL, FALSE, FALSE, NULL );
	hNotifyEvent[2] = CreateEvent( NULL, FALSE, FALSE, NULL );

...

::CreateStreamingOGG(..int ID..)
{ 
...
m_pDS->CreateSoundBuffer( &dsbd, &pDSBuffer, NULL );
pDSBuffer->QueryInterface( IID_IDirectSoundNotify, 
                                                (VOID**)&pDSNotify ) ) );

    aPosNotify = new DSBPOSITIONNOTIFY[ dwNotifyCount ];
    for( DWORD i = 0; i < dwNotifyCount; i++ )
    {
        aPosNotify[i].dwOffset     = (dwNotifySize * i) + dwNotifySize - 1;
        aPosNotify[i].hEventNotify = hNotifyEvent[ID];             
    }
    
    pDSNotify->SetNotificationPositions( dwNotifyCount,aPosNotify ) ) );
    ...
};
3. Now, in a loop I''m using

 dwResult = MsgWaitForMultipleObjects( 3,&(theSoundManager->hNotifyEvent[0]), FALSE, 1000,QS_ALLINPUT );
 switch (dwResult)
 { case WAIT_OBJECT_0 + 0:
    stream[0]->HandleWaveStreamNotification(TRUE);
   case WAIT_OBJECT_0 +1:
    stream[1]->HandleWaveStreamNotification(TRUE);
   case WAIT_OBJECT_0 + 1:
    stream[2]->HandleWaveStreamNotification(TRUE);
}
Funkyest thing (and this goes beyond my comprehension)... this works as expected on W2000. On WinXP hoever, I get notifications for WAIT_OBJECT_0 + 0 regardless on what sound is playing . Even if one of the non-streaming buffer sounds is played I get 3 notifications for WAIT_OBJECT_0 + 0 and 1 for WAIT_OBJECT_0 + 2 ... ??? What is this all about??
Quidquid latine dictum sit, altum viditur
foofightr
foofightr
Force the sound buffer to be created in system memory.
Radu094
Radu094

Pheuu....You're right..

If I create the buffers (both streaming and non) with DSBCAPS_LOCSOFTWARE, then notifications are propely handled. If I don't specify it.. then notifications get scrambled up...

sound driver problem?

Well, I suppose I could go software all the way, I don't have that much of a sound to play. What's the usuall penalty for keeping the all the sound buffers in software? I mean, is this like video software proc('cause that's a pretty big hit there?)


forgot the Thanks!!

[edited by - Radu094 on March 2, 2004 2:44:24 AM]
Quidquid latine dictum sit, altum viditur
foofightr
foofightr
Well, I ran into the same problem a few months ago and it left me scratching my head as well. Then I found this in the DirectX docs


Notifications for hardware-controlled buffers are not provided reliably by all drivers; some may generate false notifications. To work around this problem, you can call IDirectSoundBuffer8::GetCurrentPosition whenever your application receives a notification, to be sure that the notification position has actually been reached. Another solution is to create the buffer in software.


If you're worried about performance, perhaps you could instead use hardware buffers with the verification method. At the time, I was looking for a quick fix, and specifying an additional flag was simpler. I doubt that there's any performance hit for using software buffers this way though, because even a 44.1 16bit stereo buffer is only 176KB per second. That kind of memory bandwidth requirement is peanuts in the grand scheme of things. Of course, I could be wrong.

By the way, you don't need to create ALL sound buffers in system memory. Only those that need notifications. The rest you don't care about (and you shouldn't specify their location, as the driver will pick what's best).

[edited by - foofightr on March 2, 2004 7:14:00 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.