views:

298

answers:

2

Hey everyone,

I am working on an app that will play back notes from a 12-tone diatonic scale that spans several octaves. This will basically be a makeshift wavetable synthesizer.

Times that with the number of instruments to use.

The notes are stored as .wav files and will be cached into RAM to prevent overhead from hard drive retrieval. However, there's a major time-space tradeoff in terms of physical memory, since .wav files can be quite large.

Does anyone have an idea of how to make caching these .wav files more space-efficient? Compression is a good option, but too much can degrade quality. Modulating or distorting frequencies on the fly will definitely be too laggy. Correct me if I'm wrong, but playing 200 BPM with this implementation will not work.

If you have had experience with music apps, please share your advice.

+1  A: 

No experience with music apps, per se, but I have used audio, including recording.

On the iPhone, you do not normally load the entire audio into RAM, because of the size constraints and the speed of the disk. Using the AudioQueue API, you write a callback function that populates a buffer from the disk (usually using AudioFile methods). You can select buffer sizes and buffer counts appropriately to keep your application's audio playback running smoothly.

You should probably examine the compression possibilities, as well; something like lossless AAC should buy you a 50% reduction in file size with no loss in quality, at the cost of significantly increased processing overhead.

Really it sounds like you're trying to optimize too early here. Write some experimental code to see if you can get 200BPM out of the standard file loading style of audio playback routine. It could be that the file loading style using WAVs is actually faster than compressing and using RAM, due to the decode time.

mythogen
+1  A: 

You should compress the .wav files to caf files (Core Audio Format) with IMA4 compression. The iPhone can play multiple of these files at the same time (MP3/AAC cannot, because you need the hardware decoder)..

You can convert WAV to CAF with the following terminal command on Mac OS X:

$ afconvert -f caff -c 1 -d ima4 loop1.wav

Also, if you play these with AVAudioPlayer (AVFoundation) you will not have to worry about caching, as AVAudioPlayer already does this.. For more advanced audio you'll need to look in to Audio Services (Audio Queue) though..

StijnSpijker
This worked really well! CAFs are much faster to load and play rapidly.
ayman