Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which API to play audio from a buffer in ios and osx?

I would like to do this very simple thing: playing PCM audio data from memory.

The audio samples will come from sound-synthesis algorithms, pre-loaded sample files or whatever. My question is really about how to play the buffers, not how to fill them with data.

So I'm looking for the best way to re-implement my old, deprecated AudioWrapper (which was based on AudioUnits V1), but I could not find in the Apple Documentation an API that would fulfill the following:

  • Compatible with 10.5 through 10.7.
  • Available in ios.
  • Does not rely on a third-party library.
  • Be future proof (for example: not based on Carbon, 64 bits...).

I'm considering using OpenAL, but is it really the best option ? I've seen negative opinions about it, it might be too complex and overkill, and might add performance overhead ?

At worse, I could have two different implementations of that AudioWrapper, but if possible, I'd really like to avoid having one version for each system (ios, 10.5, 10.6, 10.7...). Also, it will be in C++.

EDIT: I need a good latency, the system must respond to user interactions in under 20 ms (the buffers must be between 128 and 512 samples at 44KHz)

like image 612
Jem Avatar asked Oct 09 '22 19:10

Jem


1 Answers

AudioQueues are quite common. However, their I/O buffer sizes are large enough that they are not ideal for interactive I/O (e.g. a synth).

For lower latency, try AudioUnits -- the MixerHost sample may be a good starting point.

like image 179
justin Avatar answered Oct 13 '22 10:10

justin