volking at November 30th, 2008 15:43 — #1
I have 100 tones.
Each tone has it's own .WAV file.
Each tone is (about) 0.2 secs long.
Each .WAV file is loaded and kept in an instance of a custom CLASS
The custom class has ...
private Microsoft.DirectX.DirectSound.Buffer m_SoundBuffer = null;
private Microsoft.DirectX.DirectSound.Device m_SoundDevice;
private Microsoft.DirectX.DirectSound.BufferDescription m_SoundBufferDescription;
private Microsoft.DirectX.DirectSound.BufferPlayFlags m_SoundBufferFlags;
internal Microsoft.DirectX.DirectSound.Buffer SoundBuffer
if (m_SoundBuffer == null)
m_SoundDevice = new Device();
m_SoundBufferDescription = new BufferDescription();
m_SoundBufferDescription.ControlVolume = true;
m_SoundBufferDescription.ControlPan = true;
m_SoundBufferDescription.ControlFrequency = true;
m_SoundBufferDescription.StickyFocus = true;
m_SoundBufferDescription.GlobalFocus = true;
m_SoundBuffer = new SecondaryBuffer(SoundDPFE, m_SoundBufferDescription, m_SoundDevice);
m_SoundBufferFlags = BufferPlayFlags.Default;
internal void SoundPlay()
I decide to play 5 specific tones. But, when I rapidly call "SoundPlay" for the 5 class instances, all 5 tones play SIMULTANEOUSLY! Not what I want.
I want each tone to FINISH before the next tone begins.
reedbeta at November 30th, 2008 19:23 — #2
Hi volking, please use the ...[/code] tags when you post code, to preserve the formatting. [code]...[/code****] tags when you post code, to preserve the formatting.
alphadog at December 3rd, 2008 15:47 — #3
How do you "rapidly call "SoundPlay" for the 5 class instances"? Can you show us that code?
I suspect you may not quite understand how DirectSound buffers work.
When DirectSound is initialized, it automatically creates a primary buffer for mixing sounds and sending them to the output device. Basically and overly-simplistically, think of this primary buffer as a single bucket that you don't usually touch directly, who's content gets dumped into the soundcard's memory "periodically", and the only way you get to fill it is from one or more secondary buckets (buffers).
Now, when you instantiate five of your classes, you create and fill five secondary buckets. As soon as you hit Play(), you dump that secondary bucket into the primary bucket and they all get "mixed". Mixing is done automatically when you call Play(). If you call Play() fast enough, then it seems like the five sounds play "at the same time".
A little more accurately, some of the primary bucket starts flowing out to the card (committed to play) right after your first call to Play(), and as you call Play() on your second bucket (and so on...), you add those buckets with a little offset. Depending on how you instantiate and then play the five sounds, it may be an imperceptible difference to human ears...
Does this help?
alphadog at December 3rd, 2008 16:36 — #4
To add, the way for the five sounds to play sequentially is to work with Play Buffer Notifications and hit Play() only when the previous sound is done playing.
There are, as always, more "hackish" ways to skin the cat. For example, if all sounds are the same length of time, you can simply wait between calls to Play().