Sign in to follow this  
UltimateWalrus

Best way to store music?

Recommended Posts

I have a DirectX game that plays music using DirectSound. The problem is, the game's music is stored as *.wav, which takes up a lot of space (which is bad, because I want to game to be distributed over the internet). I've searched the internet and the site, but it's only confused me. What's the best way to solve this problem? (By "best" I mean smallest file size while still maintaining quality and speed) Is it using *.mp3 or *.ogg files and playing them with DirectShow? Will that slow down my game at all? Will I still be able to play sound effects? I've heard that there is a way of compressing wav files... is this a good solution? Thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by UltimateWalrus
Is it using *.mp3 or *.ogg files and playing them with DirectShow?
I would go for .ogg. I've used them a few times and they always resolved to be slightly smaller than mp3 for similar quality... but the difference was rather small. I don't know how it is now but I think there's enough to go for .ogg anyway.
By the way, I simply love libvorbis - I managed to compile and use it in a few hours. Personally I would suggest to give it a ride instad of DS in this case!
Quote:
Original post by UltimateWalrus
Will that slow down my game at all?
Sure, you have to manage it correctly, but consider today's processors can encode multiple streams in real time... decoding isn't really so difficult.
Quote:
Original post by UltimateWalrus
I've heard that there is a way of compressing wav files... is this a good solution?
As far as I know, not nearly as good as using vorbis (or any other "natively compressed" format)... by the way, UT2003 and later uses them so it's a pretty good reference!


Share this post


Link to post
Share on other sites
you can encode a .wav file with a lossless algorithm, which generally will reduce the size by over 50%, without affecting sound quality
FLAC is a great one, apple also has their lossless formats (which the iPod can actually play), just search for "lossless compression" or "lossless audio"

I can say FLAC has had some playback issues on my computer though, so I'm not sure how that would work in a game, performance wise.

I agree that .ogg files seem to be smaller than .mp3 files, though by only a little. I'm not terribly familiar with their specifications, however.

***I just realized you said over the internet - definitely just go with .ogg or .mp3, lossless is far too large***

Share this post


Link to post
Share on other sites
Another vote for OGG. It's incredibly simple to get code working with DirectSound and ogg vorbis. You just pass vorbis a file (or a file in memory, and you write functions to interface with vorbis), and it gives you raw wave data back out.

Share this post


Link to post
Share on other sites
I noticed that you also mentioned sound effects... if you're worried that other formats may slow down your game, you can keep the sound effects as wave files. Unless I'm assumeing too much, your sound effects will be short (~2 seconds max) and so shouldn't take up much space any way.

Alex~

Share this post


Link to post
Share on other sites
Forget about MP3. You need a licence to use it in a commercial application and its inferior to OGG in every way that counts.

And don't worry about decoding performance either. If you want reassurance, try measuring your game's performance with and without a media player running in the background.

Admiral

Share this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
Forget about MP3. You need a licence to use it in a commercial application and its inferior to OGG in every way that counts.

And don't worry about decoding performance either. If you want reassurance, try measuring your game's performance with and without a media player running in the background.

Admiral


Of course if you're talking Windows (which you are if you're using DirectX) your customer has already paid for the license, and you can use the Windows APIs to play the MP3 with no repercussions. Personally I'd probably use WMA mostly because I'm pretty sure Windows will continue to support it well. In terms of compression and performance it's better than MP3 and probably about equivalent to OGG (perhaps the audiophiles and the open-source junkies will quibble one way or the other).

Geoff


Share this post


Link to post
Share on other sites
Quote:
Original post by gdunbar
Quote:
Original post by TheAdmiral
Forget about MP3. You need a licence to use it in a commercial application and its inferior to OGG in every way that counts.

And don't worry about decoding performance either. If you want reassurance, try measuring your game's performance with and without a media player running in the background.

Admiral


Of course if you're talking Windows (which you are if you're using DirectX) your customer has already paid for the license, and you can use the Windows APIs to play the MP3 with no repercussions.
The subtle difference is that the Windows OS contains a license to include a player. The Windows Media / DirectShow components doing exactly this.

Depending on how successful the product is you might not be affected, but just distributing MP3 encoded content requires a license - regardless of whether you offer them a means to play it or not:

Quote:
5) Do I need a license to distribute mp3, mp3PRO or mp3surround encoded content?:

Yes. A license is needed for commercial (i.e., revenue-generating) use of mp3/mp3PRO in broadcast systems (terrestrial, satellite, cable and/or other distribution channels), streaming applications (via Internet, intranets and/or other networks), other content distribution systems (pay-audio or audio-on-demand applications and the like) or for use of mp3/mp3PRO on physical media (compact discs, digital versatile discs, semiconductor chips, hard drives, memory cards and the like).

However, no license is needed for private, non-commercial activities (e.g., home-entertainment, receiving broadcasts and creating a personal music library), not generating revenue or other consideration of any kind or for entities with associated annual gross revenue less than US$ 100 000.00.


I've not used OGG myself but I've yet to hear anything bad about it [smile]

hth
Jack

Share this post


Link to post
Share on other sites
I`ve been using Ogg for last 6 years in about 5 projects and the quality/size ratio is surely better than with MP3 (at that time we didn`t have to even think about the absurd license fees). However, Audiere library that I`ve been using so far, has some issues with Vista (which is understandable, since that library was written even before WinXP). I just switched to irrKlang and this seems to work fine under Vista.

Regarding the performance, even on 450 MHz Celeron with 64MB of RAM, the streamed music wasn`t slowing it down very much - maybe 5% hit on such an ancient machine. But on anything over 1 GHz, the performance difference was barely 1-2 fps (Music On/Off). Always streamed, of course.
So don`t worry about the performance at all.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
Forget about MP3. You need a licence to use it in a commercial application and its inferior to OGG in every way that counts.
Everything but encoding voice tracks.

Share this post


Link to post
Share on other sites
I forgot to mention I'm not using managed DirectX or .NET or anything like that.

I looked at the Google results and have done some more searching but now I'm just confused again. What OGG libraries do I need to download? How do I stream an OGG to DirectSound? Isn't there a standard way of doing this?? I'm really surprised that there seem to be no tutorials on the subject...

Share this post


Link to post
Share on other sites
Go HERE and grab the latest stable build. You will need their code to convert from a file.ogg to a byte stream. Then you will need a good knowledge of DirectSound (or possibly DirectMusic) to upload the data to the card and play.

They didn't have the best documentation when I was doing it. There are only a few function calls you need to worry about:
ov_open, ov_info, ov_read, and ov_clear

I programmed an Ogg loader into DirectSound almost a year ago. I'm not sure how much the Ogg/Vorbis stuff has changed since then. I had a few problems with file format, some of the functions were failing because I didn't have the correct Ogg format (as best I can remember). The website distributes a simple EXE that makes Ogg files for you. Everything has been peachy with it since then.

Share this post


Link to post
Share on other sites
I'm gonna make the obligatory FMOD mentioning. FMOD will do everything you want with regard to audio and it will do it faster than you could, easier, and it's free/cheap depending on your needs. .OGG files are no problem, of course, and I love the OXM (XM tracker files with OGG compressed samples) support. It will take care of mixing your sound effects and whatnot in as well, using the best available algorithms, and has been tested and debugged on a huge range of systems/sound cards. The API is ridiculously easy to use as well. My FMOD site license purchase was a trivially easy decision!

Share this post


Link to post
Share on other sites
Quote:
Original post by blaze02
Quote:
Original post by TheAdmiral
Forget about MP3. You need a licence to use it in a commercial application and its inferior to OGG in every way that counts.
Everything but encoding voice tracks.
Of course if you're dealing with voice, you're better off with Speex anyway.

Share this post


Link to post
Share on other sites

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

Sign in to follow this