Jump to content
  • Advertisement
  • entries
  • comments
  • views

Sound buffer improvements

Sign in to follow this  


Previously, I had a command line program that would take a bunch of .WAV files, convert them into DirectSound buffers of a specific frequency and bitrate and so on, then dump them all into one file, called a .sfx file.

My game then loaded a single .sfx file into multiple CSoundBuffers (from my DirectSound wrapper). All good.

I got a bit fed up though since I had to specify indicies into a vector of CSoundBuffers to play sounds, which was a bit rubbish.

So I've just invented .dsb (DirectSound Buffer) format files that tag each buffer data in the file with a string name, specified via the command line DSB utility. You create a little script like:

"boing" boing.wav
"ding" bell.wav

save "\projects\udo\resource\effects.dsb"

and compile it with DSB.EXE.

My sound wrapper now loads DSB as well as SFX files. When you use the LoadDSBFile() method, you also pass in a std::map that records the index of each named buffer in the vector.

It is then pretty trivial in the game to write a function that takes a string argument, searches the map for the string as a key, then plays the appropriate sound buffer if it exists.

And to add a new sound, I just add it to the dsb script, compile the script and then specify the string anywhere in the game code, without having to recompile anything else or worry about remembering which index is which, or accidentally specify an index that causes an out of range index in the CSoundBuffer vector.

I know that this is not optimally efficient, but I'm relying on std::map to implement some kind of intelligent internal structure and as long as there are not thousands of elements, I can't see it ever causing a significant bottleneck.

It is dead flexible though, so I'm quite pleased.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!