Random background music

BlitzMax Forums/BlitzMax Beginners Area/Random background music

Qweeg(Posted 2005) [#1]
Is there a way to pick up music files randomly from a directory? I wanted to allow users to put their own music files in a directory and then the game to randomly select one of them and use it as background music for my game.

Also on this point I was thinking that mp3 would be the most logical format for this, but it seems as though there is no native support in blitzmax for this, and also that there are commercial licencing issues associated with the use of mp3 format. So do people generally use the OGG format for game music?


SillyPutty(Posted 2005) [#2]
have lookup table for your music in a directory, an array perhaps.

then randomise an indexer into this table. Then from the item that is indexed, pull out the name of the file, and play it.

pseudo code below.

// or load from dir into array
track[0] = "blah.ogg"
track[1] = "meh.ogg"

i = random()

load(track[i])


Booticus(Posted 2005) [#3]
Well in Bmax it seems that most use .ogg. You can grab a program called Audacity that will allow you to save out mp3s, wavs, etc as ogg. Check it out!


Qweeg(Posted 2005) [#4]
Cool - thanks guys. An array sounds good Deux - I think I can use the LoadDir() function to load the contents of my music directory and then randomly select from the array.

I guess the only thing is is whether users would be too keen on having to convert their mp3 files to ogg to use them in the game. Given that Audacity (thanks for that Mario) is GNU GPL - I guess I could include it with the game though.


DannyD(Posted 2005) [#5]
I'm sure there is an open source application that converts mp3s to oggs.Pack this as part of the package and then call the application with the input mp3 and output ogg ?