views:

315

answers:

3

I'm making an iphone game, currently using openAL for SFX, we want to keep the game under 10 meg.

iphone (through openAL atleast) only natively plays uncompressed PCM.

what would be the most strait forward way of getting music from some sort of good compressed format (mp3, aac, ogg ect) into my game?

is there some sort of decoder api? should I be using openAL?

EDIT:

ok, we've done some calculations, and we should be able to fit everything in nicely with a simple 64kb/s compression scheme, so I'm looking for the easiest way to decode a compressed file (preferably from memory) to raw pcm in memory for use with open al. we will also need a streaming decoder, it is not necessary for it to be able to decode the stream from memory, but it would be nice. We want to put looping in for the track, so it would be ideal if the decoder had “random access” so you could move around the track easily.

+2  A: 

The most compressed way would be a tracker or MIDI. That lets you store only the score for the music, not sound samples.

Maybe this is what you're looking for.

Andrew McGregor
hmm, yes I looked at that MIDI question, the problem is our sound guy gave the impression he would rather crush up his own beloved Iphone and eat all the broken shards than have to do MIDI for it...thanks for the help though, if we have to go down this avenue.
matt
Ok, well, I added another option.
Andrew McGregor
MIDI is a good option if you provide some good audio samples to go with it. Audio tracker can also be good as mentioned by Andrew.
Mr.Gando
+2  A: 

Another option would be to compile an open source synth/sampler in your game, and communicate a MIDI player to the synth samples/sounds, that could give you really good music ( I am a Software Engineering student and almost studied music ( 15 years of Piano/Synths etc ), that could be a bit more complex, BUT, can give you awesome sounds being played by the synth with light weight MIDI tracks to trigger the synth sounds.

Good luck, and I think this is actually a really nice ( a bit more complex maybe ) , way to go!

Mr.Gando
A: 

Ok, I've just got it all set up.

I used Audio Queues for the music stream simply because it is the ONE part of the iPhone SDK that is well documented:

http://developer.apple.com/iphone/library/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/AboutAudioQueues/AboutAudioQueues.html#//apple_ref/doc/uid/TP40005343-CH5-SW1

for the general explanation and

http://developer.apple.com/iphone/library/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/AQPlayback/PlayingAudio.html#//apple_ref/doc/uid/TP40005343-CH3-SW1

for a great example (that is a bit buggy)

this seems to work fine along side openAL. and it does seem that it will allow us to jump randomly about the stream at a sample level of accuracy.

the only remaining thing to do is get it so we can load from memory, this is done by replacing the:

AudioFileOpenURL

Call with a call to:

AudioFileOpenWithCallbacks

Unfortunately the documentation for the Audio File Services is... poor... to say the least.

read it at your own risk, and then after it inexplicably doesn't work read: http://developer.apple.com/iphone/library/qa/qa2009/qa1676.html

where it tells you that the callbacks are actually optional, and by supplying a write one you are telling it to open the file for writing which it can't do for MP4s, so just pass NULL for the write and setSize callback.

I would also like to say that the two answers here recommending MIDI are almost certainly the right way to go if you really want the smallest size.

Unfortunately we are lazy and just wanted something in quickly, it also came to light that we could fit in moderately compressed audio. I was also slightly worried about the performance implication (I don't know what that would be for midi) but apparently this method for compressed audio here uses hardware decoding.

If you want to go the traditional compressed audio route hopefully this helps, you could also try the Audio Converter Services if you want to use the data with openal, unfortunately this API also falls into the embarrassingly poorly documented reference manuals. I don't even know if it works, and if it does, I'm not sure if it uses the hardware decoders.

matt