Jump to content
  • Advertisement
Sign in to follow this  
fazekaim

when load music files?

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

Hello, i would like to play music files for my game. I have 30 music files (approx 150mbyte in ogg format). When should I load these files? When I would like to play it? In this case, the file loading spped depends on cpu useage (in high cpu usage, the file access hasn't got enough process time - i/o interrupt). Or should i cashe the files? 150mbyte? Thanks...

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
In what circumstances do you need to play the sounds. Are they background music or just sound effects? How big are the files that are a problem.

If they are background music files and each one is played on a particular level, I would cache just the needed ogg file for that level. If they are played in a particular zone, I would check to see if the player is getting close to that zone and start caching that ogg and remove the previous ogg file if the player is far enough away that it would not be played again anytime soon.

Another solution, why ogg? Could you use another sound file format. I have never compared ogg file sizes with mp3 or any other format, but could you make the files smaller.

Share this post


Link to post
Share on other sites
For music, the files are large enough that you pretty much have to stream them. That means that not only do you not load a file until you need it, you don't even load the whole file; you just load a small piece that you will play right then, say a second or so.

Quote:
Original quote by an anonymous poster
Another solution, why ogg? Could you use another sound file format. I have never compared ogg file sizes with mp3 or any other format, but could you make the files smaller.

The compression on .ogg files is very good, on par with .mp3. In any case, compression only shrinks the files on disc. You can't play a compressed file directly; you have to decompress it into something like PCM before the sound card can make sense of it.

The general solution to your problem, fazekaim, is to stream the music in, a piece at a time, as I said. There will be a significant amount of CPU usage, since you will have to run the decompression algorithms in real time, but it is managable. People generally do the streaming in a separate thread so that it doesn't disturb the rest of the program. The only way to avoid (most of) the CPU usage is to use an uncompressed file format (most likely .wav), but that is out of the question if your music files are already 150 MB in .ogg files; I believe it would come out to somewhere between 500 MB and 1 GB in .wav format, depending on the quality settings used in the creation of the .ogg files. Even then, there would still be some CPU usage and significant hard drive access, since you would have to stream the music. You might be able to improve performance somewhat by loading one file at a time into RAM and then streaming it into your sound buffer, but even that will take a lot of memory, especially if you decide to try to do the decompression then, as well.

The short answer is, you shouldn't try to load it all at once, and you will need to stream it from somewhere, but beyond that you will have to look into the various options and decide what makes the most sense for you.

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!