views:

379

answers:

3

Hi everyone,

I'm writing a cross-platform program that involves scrolling a waveform along with uncompressed wav/aiff audio playback. Low latency and accuracy are pretty important. What is the best cross-platform audio library for audio playback when synchronizing to an external clock? By that I mean that I would like to be able to write the playback code so it sends events to a listener many times per second that includes the "hearing frame" at the moment of the notification. That's all I need to do. No recording, no mixing, no 3d audio, nothing. Just playback with the best possible hearing frame notifications available.

Right now I am considering RTAudio and PortAudio, mostly the former since it uses ALSA. The target platforms, in order of importance, are Mac OSX 10.5/6, Ubuntu 10.11, Windows XP/7. C/C++ are both fine.

Thanks for your help!

+1  A: 

OpenAL maybe an option for you.

Simon
Hi Simon,Thanks for the feedback. I looked into OpenAL but I am concerned that it is only supported on creative cards and has a somewhat uncertain future. Do you disagree, or are there added benefits to OpenAL over a cross-platform library that wraps the system's native audio API?Thanks again.
Yuvi Masory
OpenAL is supported on lots of cards and platforms from the iPhone to Linux to Windows to Mac OS X.It was originally started by creative but can now be considered to be the audio equivalent of OpenGL and the other Open* standards.In fact OpenAL is the native audio API of the iPhone.
Simon
+1  A: 

The best performing cross platform library for this is jack. Properly configured, jack on Linux can outperform Windows asio easily (in terms of low latency processing without dropouts). But you cannot expect normal users to use jack (the demon should be started by the user before the app is started, and it can be a bit tricky to set up). If you are making an app specifically for pro-audio I would highly recommend looking in to jack.

Edit:

Portaudio is not as high-performance, but is much simpler for the user (no special configuration should be needed on their end, unlike jack). Most open source cross platform audio programs that I have used use portaudio (much moreso than openal), but unlike jack I have not used it personally. It is callback based, and looks pretty straightforward though.

Justin Smith
Thanks for the idea. Is there any way to statically link to a redistributable version of jack? If not I don't think it will work for me. We're very concerned about easy deployment. I'll keep reading up on them.
Yuvi Masory
For enduser convenience portaudio is probably your best bet, I edited my answer to reflect that.
Justin Smith
I re-read and see you are already using portaudio - if you are having performance problems just displaying a waveform I recommend removing non-rt-safe functions from your callback, and moving them into the main thread. Non-rt functions are mainly: printf or any other io to files or sockets, anything that waits on a semaphor, or malloc.
Justin Smith
Thans again. I'm not currently using PortAudio, Right now the app uses Java Sound which is good on Mac, barely acceptable on Windows, and essentially broken on Linux. So I'm looking to reimplement my audio interface with JNI. I played with RTAudio a bit. I can't get it to compile on Linux, but in Mac it works well. The only drawback I see is that it's very high level so the only way to get progress notifications is to query the line in a sleeping loop. And it doesn't support gain controls.
Yuvi Masory
gain control is easy to do in the client for(i = 0; i < BUFFSIZE; i++) { buffer[i] *= gain } - unless you are mixing a large number of channels this should not be too much of an efficiency hit. Also - if by progress notifications you mean playback progress, you could increment a progress counter in your callback.
Justin Smith
+1  A: 

NO I strongly recommend against Portaudio. I've had problems with functions behaving differently on Linux and Windows, or don't working as documented (if documented). Basically I couldn't synchronize sound playback to the system clock while correcting for the sound card deviation from perfect 44100hz.

The project seems dead anyway.

ponce
What is your suggestion?
Yuvi Masory
Well if you want to synchronize to an external clock you may want need to know the delay between playback and effective ouput in the sound card. With portaudio you can do that with Windows... But it's not that common in sound libraries. I don't know if any other library can do that. In the audio world ASIO is known to bring lower latency but I've no experience with programming with that.
ponce