Hi all,

I have a big DSound buffer which contains some audio.

I want to start playback of it when a certain time is reached (corresponding to something that happens at the same time on video).
I noticed that it doesn't start always at the same time, but can have even 300+ ms of "random" delay.

How can I fix it and keep my video and audio always in synch?

Thank you.
Posted on 2002-04-24 11:26:04 by Maverick
Hi !


Do you use different threads ?

Maybe a timing precalculation will help. So try to estimate the time when a next sound-play-point will appear and position the sound into the soundbuffer at the right time-point.

Greetings, Caleb
Posted on 2002-04-24 16:13:40 by Caleb
First - I know nothing of DirectSound.This is a shot in the dark but....

On MSDN it says
"Loss can also occur when an application with the write-primary cooperative level moves to the foreground; in this case, DirectSound makes all other sound buffers lost so that the foreground application can write directly to the primary buffer."

This would lead me to beleive that by setting your coop level to write-primary you can directly write to the primary buffer. This should keep other crap from messing with it at the same time. Perhaps then you would see more reliable operation (IE less delay)?

Just a guess.

Also MSDN says
"When streaming audio, you may want your application to be notified when the play cursor reaches a certain point in the buffer, or when playback is stopped. By using the DirectSoundSecondaryBuffer8.SetNotificationPositions method, you can set any number of points within the buffer where events are to be signaled. You cannot do this while the buffer is playing."

Have you tried synching the video to several different points inside the audio instead of the other way around?

hope I haven't wasted your time too much.... :)
Posted on 2002-04-24 16:41:33 by emonk
Thank you guys.

Caleb: the problem is that 7/8 times out of 10 it works perfectly.. but the other times - under the same identical conditions - the audio will be a bit out of synch.

emonk: no, you haven't wasted my time.. a kind reply like yours is always very wellcome. Actually as a possible solution I thought that too (to synch the video to the audio, instead of trying to get the audio correctly synched).. but at the end I decided instead to force audio synching from time to time. The right moments will be when there's silence (so no eventual audio clicks will be heard).. and if there's no silence in x time, force audio resynch anyway. I just implemented this and it works well. Still, I feel bitter that I had to.. that sort of workarounds ideally shouldn't really be needed. :/

<edit>The primary reason why I didn't want to synch video to audio is because video has already a synch source.. and audio should follow that as well.</edit>
Posted on 2002-04-24 18:08:37 by Maverick
Maverick, what do you expect from Windows ;)

It's not designed to be a real time multimedia systems. So task switching disturbs your timings ... ( even with 39177 Pentium-IV processors :grin: )
Posted on 2002-04-24 18:35:30 by Caleb
Hi Caleb :)


Maverick, what do you expect from Windows ;)

It's not designed to be a real time multimedia systems. So task switching disturbs your timings ... ( even with 39177 Pentium-IV processors :grin: )
In fact, and how sad is this.. :mad:

Anyway.. I fixed "just another Windows bug in my application". :grin:

PS: sometimes, to be fair, it's not Windows to be blamed but the drivers. I feel no duty to feel pity towards Windows, though. :o
Posted on 2002-04-24 20:15:42 by Maverick