Playing OS X / Linux sound using an event based interface?

I'm working on a streaming audio player for Linux / OS X with a fancy use case that convinced me that the existing one doesn't work. For the first part, I just want to receive MP3 data and play it back. I am currently using libmad for decoding and libao for playing. My problem is with libao and I'm not sure if this is the best option.

In particular, the function is ao_play

blocked. It does not return until the entire buffer passed to it has been played. This does not give enough time to decode blocks between calls to ao_play, so decoding must be done either completely ahead of time or at the same time. Since this is for streaming, I reject pre-decoding. (One can assume that I could send more than an hour of audio data - I don't want to use that memory.) This leaves concurrency. But while pthreads is standard on Linux and OS X, many of the surrounding libraries are not. I'm not sure if I want to switch to concurrency - so I'm revisiting my libao choice.

For my application, the best model I can think of for playing audio would be to receive a file descriptor, which I could choose to be notified when it's ready to be recorded, and then emit non-blocking recordings. (This has to do with the rest of the usage details, which implies that I really want the selection loop anyway.)

Is there a library that works on Linux and OS X that works this way?

+3


source to share


2 answers


While he hated it a lot, PulseAudio basically works exactly the same way you describe (using the Asynchronous API, not the simple one).



If you don't want this to be associated with lower latencies or improved audio performance, then you can check out the JACK Audio Connection Kit .

+3


source


PortAudio is yours. It has a simple API with a callback. It's cross-platform and low latency. This is the best solution if you don't need any fancy features (3D, audiographic, ...).



+3


source







All Articles