Archived

This topic is now archived and is closed to further replies.

shadowDragon

3D positional sound in Direct X - managing sound buffers

Recommended Posts

I''m currently working with 3D sound in DirectX 8.1 [haven''t upgraded to 9.0 yet ]. The dilemma I have is this: Say you have 1 gun sound effect, and you want 2 guys to shoot at each other who are standing x meters away from each other. You want that sound to sound like it''s at 2 different 3D positions (if both the guys shoot at each other at the same time). How is that done in 3D games? The way I understand it is you need a separate SoundBuffer (with it''s 3DSoundBuffer gotten out of that) to play the same sound effect at two different positions in 3D space. I thought about just setting its 3D position to the first shooter, playing it, then setting the buffer''s position again to the second shooter, and playing it again, because it''s really only 1 sound effect, just played at two different positions, so I''d only want 1 copy in memory right? But this would cause the first shooters gun sound to become cut off when the second shooters gun played (making a "Ba-Bang" sound). Then I thought about just giving each character a set of soundBuffers for every possible sound they could make (then I thought about how wasteful that would be ). So I''m currently thinking about either having a linked list of sound buffers per sound effect, or just allocating 5 buffers a piece for each sound effect and if more are needed they just aren''t played. The linked list approach would work in this manner. A request for a certain sound effect to be played would be made, if the sound buffer was currently playing, another sound buffer would be created and the sound effect would be loaded into that and played (adding another node to the list). However, I don''t know how expensive [how slow] it is to create sound buffers and load in wavs is DURING the game. I also can''t use DuplicateSoundBuffer() for this because, according to the DX 8 docs, DuplicateSoundBuffer() is deprecated. The second approach would just allocate 5 soundBuffers per sound effect (up to 5 of the same sound can play at once in different positions). When a sound effect request is made the game would check to see if the first buffer is playing, if so, it would check the second buffer and so on until either a buffer is not being played or we reach the 5th buffer (in which case, we don''t play the sound). This is wasteful also (and kind of hacked ). How is this done in FPS''? Anyone know or have any ideas on how I could solve this problem? What are your thoughts on this? Anyone ever do this for their game?

Share this post


Link to post
Share on other sites
I''m intrested in this as well. When I messed with 3D sound in DirectX I just hacked it up by loading multiple copies of a sound into multiple buffers... Surely there must be a better way.

Share this post


Link to post
Share on other sites
DuplicateSoundBuffer was designed to deal with the memory and driver architecture of older soundcards. Modern soundcards work in quite a different way, and that is why it is depreciated.

A more detailed explaination can be found here

If you just want to get sound up and running then use DuplicateSoundBuffer. It works well, is simple to use.

Modern games often load a single instance of each sound into memory - not into a soundbuffer - and then copy (or stream) the sound into a free soundbuffer when it is needed. So, if two gunshot sounds are needed then the gunshot audio would be copied into the two free buffers, their properties set, and then both played individually.

You can also copy or stream from the Harddrive or CD but this introduces some latency concerns.

I hope this helps.

Cheers,
John

www.zejo.com

Share this post


Link to post
Share on other sites
one thing you should take notice of, unless you haven''t.. to use 3d positional sound, the waveformat (or whatever you''re using) MUST be mono... i''ve hooked up on that problem a several times

Share this post


Link to post
Share on other sites