Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS X/Linux audio playback with an event-based interface?

Tags:

c

linux

macos

audio

I'm working on a streaming audio player for Linux/OS X with a bizarre use case that has convinced me nothing that already exists will work. For the first portion, I just want to receive MP3 data and play it. I'm currently using libmad for decoding and libao for playback. My problem is with libao, and I'm not convinced it's my best option.

In particular, the ao_play function is blocking. It doesn't return until the entire buffer passed to it has been played. This doesn't give enough time to decode blocks between calls to ao_play, so the decoding has to be done either entirely ahead of time, or concurrently. Since this is intended to be streaming, I'm rejecting ahead-of-time decoding offhand. (It's conceivable I could send more than an hour's worth of audio data - I don't want to use that much memory.) This leaves concurrency. But while pthreads is standard across Linux and OS X, many of the surrounding libraries are not. I'm not really convinced I want to go to concurrency - so I'm reconsidering my choice of libao.

For my application, the best model I can think of for audio playback would be getting a file descriptor I could select on to get notified when it's ready for writes, then issue non-blocking writes to. (This is due to the rest of the details of the use case, which imply I really want a select loop anyway.)

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

like image 632
Carl Avatar asked Feb 20 '23 23:02

Carl


1 Answers

Although it's much hated, PulseAudio basically works exactly like you describe (using the Asynchronous API, not the simple one).

Unless what you want to do involves low-latencies or advanced sound work, in which case you might want to look at the JACK Audio Connection Kit.

like image 94
cha0site Avatar answered Feb 24 '23 17:02

cha0site