Jump to content


DirectX.DirectSound make simultaneous into successive


3 replies to this topic

#1 volking

    New Member

  • Members
  • Pip
  • 1 posts

Posted 30 November 2008 - 08:43 PM

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
{
get
{
if (m_SoundBuffer == null)
{
m_SoundDevice = new Device();
m_SoundDevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
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;
}
return m_SoundBuffer;
}
}
internal void SoundPlay()
{
SoundBuffer.Play(0, m_SoundBufferFlags);
}

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.

How?

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5308 posts
  • LocationSanta Clara, CA

Posted 01 December 2008 - 12:23 AM

Hi volking, please use the [code]...[/code] tags when you post code, to preserve the formatting.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 alphadog

    DevMaster Staff

  • Moderators
  • 1716 posts

Posted 03 December 2008 - 08:47 PM

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?

#4 alphadog

    DevMaster Staff

  • Moderators
  • 1716 posts

Posted 03 December 2008 - 09:36 PM

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().





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users