DirectSound, Streaming, Threads

Started by
0 comments, last by paulecoyote 18 years, 10 months ago
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
Advertisement
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
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.

This topic is closed to new replies.

Advertisement