Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple C++ Sound API

Tags:

c++

linux

qt

audio

My commercial embedded C++ Linux project requires playing wav files and tones at individual volume levels concurrently. A few examples of the sounds:

• “Click” sounds each time user presses screen played at a user-specified volume
• Warning sounds played at max-volume
• Warning tones requested by other applications at app-specified volume level (0-100%)
• Future support for MP3 player and/or video playback (with sound) at user-specified volume. All other sounds should continue while song/video is playing.

We're using Qt as our UI framework which has QtMultimedia and Phonon support. However, I heard the former has spotty sound support on Linux and the latter is an older version and may be deprecated in an upcoming Qt release.

I've done some research and here are a few APIs I've come across:
KDE Phonon
SFML
PortAudio
SDL_Mixer
OpenAL Soft
FMOD (though I'd prefer to avoid license fees)
ALSA (perhaps a bit too low-level...)

Other considerations: Cross-platform isn't required but preferred. We'd like to limit dependencies as much as possible. There is no need for advanced features like 3D audio or special effects in the foreseeable future. My team doesn't have much audio experience so ease-of-use is important.

Are any of these overkill for my application? Which seems like the best fit?

Update: It turns out we were already dependent on SDL for other reasons so we decided on SDL_Mixer. For other Embedded applications, however, I'd take a long at the PortAudio/libsndfile combo as well due to their minimal dependencies.

like image 691
rocky Avatar asked Apr 02 '12 17:04

rocky


5 Answers

libao is simple, cross-platform, Xiphy goodness. There's documentation too!

Usage is outlined here - simple usage goes like this:

  • Initialize (ao_initialize())
  • Call ao_open_live() or ao_open_file()
  • Play sound using ao_play()
  • Close device/file using ao_close() and then ao_shutdown() to clean up.
like image 188
gnud Avatar answered Nov 10 '22 01:11

gnud


i have used SDL_Mixer time and time again, lovely library, it should serve well for your needs, the license is flexible and its heavily documented. i have also experimented with SFML, while more modern and fairly documented, i find it a bit bulky and cumbersome to work with even tho both libraries are very similar. imo SDL_Mixer is the best.

however you might also want to check out this one i found a few weeks ago http://www.mpg123.de/, i haven't delved too much into it, but it is very lightweight and again the license is flexible.

like image 27
iKlsR Avatar answered Nov 09 '22 23:11

iKlsR


Go for PortAudio. For just plain audio without unneeded overhead such as complex streaming pipelines, or 3D, it is the best lib out there. In addition you have really nice cross-platform support. It is used by several professional audio programs and has really high quality.

like image 2
André Bergner Avatar answered Nov 10 '22 00:11

André Bergner


There is a sound library called STK that would meet most of your requirements:

https://ccrma.stanford.edu/software/stk/faq.html

like image 1
Mario Avatar answered Nov 09 '22 23:11

Mario


Don't forget about:

  • FFmpeg: is a complete, cross-platform solution to record, convert and stream audio and video.

  • GStreamer: is a library for constructing graphs of media-handling components. The applications it supports range from simple Ogg/Vorbis playback, audio/video streaming to complex audio (mixing) and video (non-linear editing) processing.

like image 1
karlphillip Avatar answered Nov 10 '22 00:11

karlphillip