Using opus with OpenAL

04 Jan 2013

opus is a new low-latency audio codec which provides good quality sound at very low bitrates. I though I'd try getting it to work with OpenAL. Thanks to the magic of libopusfile it was pretty easy to get going.

This is a quick example of how to integrate opusfile into an OpenAL program. It quite simply loads the entire file into memory and plays it — no streaming, recording or fancy spacial effects.

I've also put together another demo which streams an opus file. It works pretty much the same way, but is much better for longer files, as only the currently played bit of audio is in memory at once.

I was running Ubuntu 12.10, and the opus library can easily be installed with sudo apt-get install libopus-dev opus-tools (you'll want opus-tools to be able to encode opus files). Unfortunately, libopusfile is not in the repository — you'll have to download and compile it yourself.

Compiling is as easy as g++ -o opusal opusal.cpp -lopusfile -lopenal, though you may need to set up your opusfile include and library paths. To run, just ./opusal < filename >.

All-in-all, I am very impressed with opus and libopusfile, which is a worthy successor to vorbisfile (although it would be nice if you could decode more than ~960 samples at once).

— David