ATTENTION READERS! Lucky's VB Gaming Site is no longer active. For updated game programming information and tutorials, please visit The Game Programming Wiki!
Have you ever wanted to use mp3's as the background music for your game? Easy right, load an mp3 file instead of a wav file, and hit play! WRONG, even though mp3s have been popular for quite some time Miscrosoft didn't add ANY support for them in Direct Sound(Why Not?). But not to worry there are other ways of using them with directsound!!
What I will show you involves compressing a wav file with "MPEG-Layer 3 Compression", but results in a normal .wav file that can be played(with a codec) though DSound. The process of performing this conversion is actually quite simple. Because direct sound decompresses the whole file on load there is no performance hit, but the load time suffers a little. Ok, well here is how you do it:
Well were not ready just yet, the compression codec MUST be installed on you system before you can encode your files.
To install it just download this file: l3codecp.exe which is the FHG MPEG II Layer 3 audio
codec profesional version developed by Fraunhofer. This is the profesional version which must be bought for a hefty
sum(how do I have it you ask, don't worry about that just download it already), there is also an advanced version
l3codecp.exe which is free, but can only encode at rates upto 56kbps. Well on with it,
all you need to do after downloading this is double click, and it should do the rest.
The only catch is that your users must also have this codec installed, but I think the advanced version comes automatically with Win98+, or with IE4. But just in case I plan on writing a vb module that takes care of installing it for you, but in the meantime just have them install it, or hope they have it. For more info on codecs and such check out these pages:
One more thing while we are on the subject of codecs, to check which ones you have installed go into Control Panel|Multimedia|Advanced|Audio Compression Codecs, and you should be able to find out anything about them.
Now for the easy part, once you have done all that just follow these easy steps, and you should be on your way!
Step 1. Open the *.wav file in Windows Sound Recorder (Start|Programs|Accesories|MultiMedia) Step 2. Load the file in Sound Recorder Step 3. Goto Properties (File|Properties) Step 4. Click Convert Now Step 5. For format Select "MPEG-Layer 3", for Attributes select the bitrate Step 6. (Optional) Click "Save as" to give the settings a name(I use MP3) Step 7. Click Ok until you are back at the main window Step 8. Save it! (File|Save)
Last thing, to play the encoded wavs with direct sound is no different then playing a normal wav file. I am not going to explain that whole process, but instead here are a few links to tutorials for doing that:
Well, thank you for reading this tutorial I hope you found it useful and educational. If you have any more questions or comments PLEASE email me at troll1184@cs.com
Thanks Again, Brian Clark
A note from Lucky:
Click here to see if you've got the codec to play MPEG-Layer 3 compressed files. If you get an error when attempting
to play the wave file, you'll need to install one of the above codecs.