Sign in to follow this  

DirectSound, Streaming, Threads

This topic is 4586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, One Sleepless night with directsound and more to go.. :) I am coding a Synthesizer that plays notes that reads from a LAN using UDP. The Synthesizer use DirectSound and generates a sin wave from the note that reads from the Internet and writes it to a Secondari Buffer. The streaming code is similar to the one in the DirectX SDK and uses IDirectSoundNotify notifications. The buffer Size is 16*1024 The wave is written to a buffer in a secondary thread. The thread main looks like this in pseudocode: ThreadMain() { (The thread is encapsulated within an obj that has a) SoundBuffer b) NoteToRecord c) Event while object = WaitForSingleObject()^ { LockDirectSoundBuffer WriteInBuffer (sin (2 * PI * NoteToRecord.Frecuency. time); UnlockDirectSoundBuffer } } The code works perfectly until I start to record a second note in a second buffer in a secondary thread. The notes are not mixed correctly. (I hear like one note on the backgound and an echo of the second note) After many hours I managed to solve that situation adding a Sleep in the code shown above and I could play both notes at once correctly If I play both from code. But If I send the notes from an other program though UDP and the Synthesizer APP doesnt have the focus I still hear the echo. I have a Thread for each DXSoundSecondary buffer and as far as i see both threads dont share any common data at all (they are different objects instances). I feel it is a problem concerning how procesor time is divided between the threads or thread Syncronization but not a resource sharing problem... but you never know. Any help would really be appreciated. If you need more info please ask. Esteban Calabria

Share this post


Link to post
Share on other sites
from what I recall DirectX does have a threading mode that I think may be off by default.

Your use of sleep is probably a pretty brittle hack way of achieving thread syncronisation. You may want to employ a gate kind of strategy.

I appoligise in advance if you've been looking in to / know about all that stuff, but here's a C++ article you may be interested in

http://www.frostbytes.com/~jimf/papers/c++sync/c++sync.html

Share this post


Link to post
Share on other sites

This topic is 4586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this