Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple C audio library

I'm looking for a simple-ish library for outputting audio. I'd like it to meet these criteria:

  • Licensed under LPGL/zlib/MIT or something similar – i'm going to use it in an indie commercial application and i don't have the money for a license.
  • Written in C, but C++ is fine.
  • Cross-platform (Windows, Linux, maybe OSX)
  • Able to read from some sort of audio file (i'd prefer WAV or OGG but i will gladly use less popular formats if need be) in memory (i've seen the use of a memfile struct and user-defined I/O callbacks). I need the file to be in memory because i put all my resources into a .zip archive, and i use another library to load those archived files into memory.
  • Supports playing multiple sounds at the same time, having a max of 8 or so is ok.
  • I'd really like to either have the source code or a static library (MinGW/GCC lib???.a), but if nothing else is available i will use a shared library.

I must have come accross two dozen different audio libraries in my search, all of which haven't quite met these criteria...

like image 909
nuju Avatar asked Aug 20 '12 22:08

nuju


4 Answers

I would recommend PortAudio + libsndfile. Very popular combo, meets your requirements. Used by many other software applications including audacity.

like image 170
Bjorn Roche Avatar answered Nov 15 '22 14:11

Bjorn Roche


Some of the candidates that immediately spring to my mind are:

  • SDL (there is a tutorial that demonstrates how to play a .wav format sound)
  • libav
  • ffmpeg
  • libao
  • OpenAL Soft
  • Jack Audio

You may have already looked at these and eliminated them, though. Can you give some more detail about the libraries that you have eliminated from consideration and why? This will help narrow down our recommendations.

like image 2
bta Avatar answered Nov 15 '22 15:11

bta


You might want to look into SDL and SDL_mixer. Here is a good tutorial. I've used SDL_mixer and it makes it easy to play background sounds or music and play multiple simultaneous sounds without having a need to write your own sound sample mixer.

like image 1
Chimera Avatar answered Nov 15 '22 13:11

Chimera


I ended up using PortAudio (very low-level, flexible license) and wrote a mixer myself. See this topic i made on the C++ forums for some other people's tips on writing a custom mixer. It's not hard at all, really; i'm surprised that there are so many mixer libraries out there. For a breakdown of the WAV format (ready-to-stream raw audio data with a 44-byte header) see this.

like image 1
nuju Avatar answered Nov 15 '22 15:11

nuju