Jump to content
  • Advertisement
Sign in to follow this  
Halsafar

DS Buffer Duplicate - Multiple Buffers

This topic is 4898 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

I may be wrong but I've read that using the duplicatebuffer functions do not help in playing a single buffer multiple times at once. As you may know a buffer has a write/read pointer, when you play that pointer slides across the memory, since there is only 1 pointer you cannot play the same buffer twice at once. The solution is to check if it is currently playing and then play a copy of that sound buffer. I need to know which is the most effecient way of doing this, since DuplicateBuffer, stated on the MSDN will only sometimes create a buffer with new memory, most of the time the DuplicateBuffer will use the same memory location thus 1 pointer still thus the same problem. So, my solution is to at compile time tell each buffer if it needs copies of itself and create them before gametime. For example, a machine gun sound effect will need like 10 buffers to allow a user to fire constantly and hear multiple bullet shots at once. I have seen some programs which just check during gametime if a sound is playing and if it is then it will create a copy and play it, then release the copy. I find that very ineffiecent. If I was running, multiple footsteps may need to be played, thus a new buffer created every few frames, pointless CPU work. So em I correct by assuming multiplebuffers at game loadtime and loading the buffers into an array or is it better to have only one and duplicate it if necessary during a frame, or is a combination of the two the better way to go.

Share this post


Link to post
Share on other sites
Advertisement
I think you are confusing the pointer to the actual data buffer with the IDirectSoundBuffer8 pointer. It is the IDirectSoundBuffer8 that maintains the read/write pointer and buffer parameters. If you use DuplicateSoundBuffer(), you will get a new IDirectSoundBuffer8 that points to the same sound buffer, but with it's own read/write pointer and parameters.

From MSDN:
Quote:
Initially, the duplicate buffer will have the same parameters as the original buffer. However, the application can change the parameters of each buffer independently, and each can be played or stopped without affecting the other.


You should be able to use DuplicateSoundBuffer to play the same sound as many times as you want.

Share this post


Link to post
Share on other sites
I wasn't confused just my terminology was.
I have tried this method before tho and ended up with nothing. Although last time I tried it was Dx7 DirectSound.

A very simple GetStatus, if playing, duplicate buffer, play new buffer. The new buffer never makes a peep of noise :(

Share this post


Link to post
Share on other sites
When you duplicate the buffer, everything about the buffer is duplicated, including the current position. So, unless you reset the position to 0, it will play at the same point as the already playing buffer. It may just be that you don't hear anything because you now have two buffers playing at the same position.

I've used this method before and not had any problems with it. Generally, I never play the original buffer. I load the sounds up front and, whenever I need to play a sound, I duplicate the buffer for that sound and play the duplicate. When the duplicate is done playing, I release it.

Share this post


Link to post
Share on other sites
Given that the sound buffer data itself isn't actually duplicated the cost is quite minimal. It's like having 100 sprites sharing the same texture.

Share this post


Link to post
Share on other sites
Sorry for the little bump here but the problem is now being shown.

I just got around to attempting to play one buffer twice, nearly at once.

if (IsPlaying()) {
LPDIRECTSOUNDBUFFER pDestBuf = 0;
hr = cSoundLayer::Sound()->DuplicateSoundBuffer(m_pBuffer, &pDestBuf);
pDestBuf->SetCurrentPosition(0);
pDestBuf->Play(0,0,false);
pDestBuf->Release();
return true;
}

Nothing, not a peep.
any assistance? I know the original buffer works flawlessly.

Share this post


Link to post
Share on other sites
This may be a completely worthless reply (I'm good at these), but I'll try anyways.

Do you ever set the volume of any sound effects? If you use a 3D or 2D panning / volume calculation based on distance from the screen, the last sound played may have been out of range to hear it. If so, you may need to set all of the sound's properties when you duplicate it.

You don't seem to be checking the return value of DuplicateSoundBuffer. Are you sure it's succeeding? Seems like a crash would occur, but you never know.

You release the duplicate right after you duplicate it. Was this just for an example or test? I don't think you should even check to see if the original sound was playing if you plan to immediately release the duplicate. There's very little reason to ever play the original sound with your current setup. It might be that the original sound was not playing when you tested the second play. Of course I have no idea. Just tossing guesses at you.

Share this post


Link to post
Share on other sites
Well actually I am just fiddling with it, so that is my current setup but it is not to stay. I just wanted to see it work. So because I am fiddling I am not setting volume or panning. I have a 5sec wave file which I want to play twice over.

So I actually went and the only buffer I play when the sound is requested is the duplicate and it is 100% blank.

Also, when in break mode stepping through I confirmed that it is returning S_OK everytime or at least many 100's of times in a row...




Ugh, I had this exacty problem in DX7 DirectSound, the only solution was to create multiple buffers and use up extra memory... Saved repetitious Duplicatebuffer calls....

Share this post


Link to post
Share on other sites
WELL!

I hope someone replies to this for some help...

The fix was to not Release it right away obviously.
How and where should I wait to release it now???

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!