Question

I want to playback an mp3 rather than an uncompressed file using RemoteIO / AudioUnit. Using uncompressed files obviously uses far too much disk space (30MB vs 3MB for mp3).

Is this even possible? If so, can you provide a little code headstart?

Thanks a million.

Was it helpful?

Solution

Yes, it is possible. But it requires multiple audio API use and multiple threads.

Due to the real-time constraints of the Audio Unit buffer callback thread, you will have do the conversion of compressed files to raw PCM samples outside the Audio Unit callback. You could use Extended Audio File Services or AVAssetReader to do the conversion to uncompressed samples outside the Audio Unit callback. However, you don't need to uncompress the entire file at once. A short uncompressed buffer of a fraction of a second will likely do, as long as you keep filling it far enough ahead of the Audio Unit callback buffer consumption rate. This can be done in a separate timer driven thread that monitors buffer consumption, and decompresses just enough audio accordingly, perhaps into a ring buffer or circular FIFO.

What you will end up with will be similar to a rewrite of the Audio Queue API layer, but with more customizability.

OTHER TIPS

How low-level do you want to go? You could use the AudioHardware API:

err = AudioDeviceAddIOProc(deviceID, ioProc, self);

and in your ioProc fill the buffers yourself, listen for hardware changes, and deal with real-time threading and a lot of other low-level stuff.

I'm assuming you're already decoding the mp3 data with AudioConverter and know how to do that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top