TIGSource Forums

Developer => Technical => Topic started by: eclectocrat on November 03, 2011, 02:51:27 AM



Title: Best C/C++ Audio API
Post by: eclectocrat on November 03, 2011, 02:51:27 AM
What is the simplest audio playback API for C/C++ that supports at least Windows?

By audio playback, I mean something that handles buffering files (preferably MP3's, but WAV's/AIFF's are fine), and doesn't require me to fool around with audio data callbacks. I can handle crossfading and such by myself.

OSX has a shit-ton of audio API's, it's too easy. Right now I'd be leaning towards SDL_mixer, except the homepage has it listed under the LGPL license, even though there was a non-commital comment made by the author to switch to SDL 1.3's zlib license on the SDL mailing list a few months back.

Does Windows have a good high level audio API? I'm so out of touch with MS stuff...


Title: Re: Best C/C++ Audio API
Post by: increpare on November 03, 2011, 03:03:35 AM
fmod ex.  for freeware it's free. 


Title: Re: Best C/C++ Audio API
Post by: PompiPompi on November 03, 2011, 03:17:35 AM
I am not sure, there is XAudio2 that comes with the DX SDK, but I didn't mess with it that much, so I don't know how well it will be for you.


Title: Re: Best C/C++ Audio API
Post by: eclectocrat on November 03, 2011, 03:22:56 AM
fmod ex.  for freeware it's free. 

Looks very good but... it's got an indie license and a commercial licence on it's webpage. Both for pay. Plus I'm not sure what the future of my product is.

I'm not too interested in messing with licenses. I'd rather split the codebase to support multiple OS's than get caught up in some licensing BS.


Title: Re: Best C/C++ Audio API
Post by: ThemsAllTook on November 03, 2011, 08:15:35 AM
OpenAL isn't too bad. It took me a bit of messing around to get it to work properly on Windows, but it's free, cross-platform, and has a nice API. It won't help you decompress audio, but if you're not set on MP3, libvorbisfile is pretty easy to use (http://sacredsoftware.net/svn/misc/StemLibProjects/vorbisaudioio/trunk/source/vorbisaudioio/).

Edit: Whoops, if LGPL is a show-stopper for you, never mind... Just using OpenAL doesn't trigger the more offensive clauses of LGPL, though. You don't have to open source your own project or anything.


Title: Re: Best C/C++ Audio API
Post by: Ludophonic on November 03, 2011, 09:25:44 AM
I did an evaluation for myself during the summer and decided to use Core Audio on OS X and XAudio2 on Windows.

XAudio2 is very simple to use.


Title: Re: Best C/C++ Audio API
Post by: rivon on November 03, 2011, 09:31:17 AM
Take a look at SFML audio... Its very easy to use, multiplatform and under zlib license.


Title: Re: Best C/C++ Audio API
Post by: BrianSlipBit on November 03, 2011, 09:33:28 AM
I'm not too interested in messing with licenses. I'd rather split the codebase to support multiple OS's than get caught up in some licensing BS.

Well, you'll be limiting yourself to something less than the best of options then.  If you want the best, then FMOD or BASS (http://www.un4seen.com/) are what you're looking for.  I think BASS has more favorable licensing terms though.


Title: Re: Best C/C++ Audio API
Post by: PompiPompi on November 03, 2011, 10:18:36 AM
Take a look at SFML audio... Its very easy to use, multiplatform and under zlib license.
Do note that SFML 1.6 has tons of bugs, SFML 2.0 might be better, but I didn't use it so I can't tell. (I use SFML 1.6 by the way).


Title: Re: Best C/C++ Audio API
Post by: Vino on November 03, 2011, 11:41:17 AM
I've had decent results with SDL_mixer, but I wouldn't really recommend it for game work. I'm thinking of switching to OpenAL since it provides spatial sound and SDL_mixer doesn't.


Title: Re: Best C/C++ Audio API
Post by: Aloshi on November 03, 2011, 12:30:22 PM
Take a look at SFML audio... Its very easy to use, multiplatform and under zlib license.

If I remember right, SFML's audio is just a wrapper for OpenAL anyway.


Title: Re: Best C/C++ Audio API
Post by: rivon on November 03, 2011, 12:42:11 PM
Yeah, it is, but it is very simple and has all the features OP asked for.


Title: Re: Best C/C++ Audio API
Post by: Falmil on November 03, 2011, 12:53:57 PM
What's wrong with LGPL stuff?


Title: Re: Best C/C++ Audio API
Post by: PompiPompi on November 03, 2011, 02:32:40 PM
Yea, SFML is relatively simple and easy to use(when it works :/).


Title: Re: Best C/C++ Audio API
Post by: Nix on November 03, 2011, 02:35:48 PM
What's wrong with LGPL stuff?

You have to worry about whether you will be forced to release you game as open source


Title: Re: Best C/C++ Audio API
Post by: Falmil on November 03, 2011, 02:52:34 PM
Oh, I thought you didn't have to if you just linked to the LGPL software. I am trying to see where this gets complex but cannot really find an explanation.


Title: Re: Best C/C++ Audio API
Post by: rivon on November 03, 2011, 03:07:22 PM
If you dynamically link to a LGPL library, then you can freely use it to make commercial/proprietary products. Only if you statically linked the library, would you have to provide the sources of your app or object files, so that the user would be able to link the app with newer versions of the library. Also, if you modified the library in any way, you would have to provide it's sources of course (though not your app's code).

So, unless you plan to modify the library or you have some serious reason not to use dynamic linking, you can freely use it however you want.


Title: Re: Best C/C++ Audio API
Post by: eclectocrat on November 03, 2011, 04:31:55 PM
Thanks a lot guys, I think I'll use XAudio2 on Windows. I already have a very capable audio wrapper library on OSX. I'll probably end up writing a full engine for Linux, since I used to write realtime signal processing engines and I'm feeling a bit nostalgic.

My problem with LGPL is that I may not be able to have dynamic linking on all platforms (ie, iOS), so any LGPL lib turns instantly into a GPL lib. Admittedly this is no problem on Windows, I'm just paranoid.


Title: Re: Best C/C++ Audio API
Post by: ThemsAllTook on November 04, 2011, 06:33:06 AM
My problem with LGPL is that I may not be able to have dynamic linking on all platforms (ie, iOS), so any LGPL lib turns instantly into a GPL lib. Admittedly this is no problem on Windows, I'm just paranoid.

Conveniently, OpenAL is a system framework on iOS and Mac OS X, so you don't need to include it with your application at all. All users already have it.


Title: Re: Best C/C++ Audio API
Post by: eclectocrat on November 04, 2011, 06:44:29 AM
Ugh. I have to do large file streaming on my own... What is this, 1998?


Title: Re: Best C/C++ Audio API
Post by: rivon on November 04, 2011, 03:48:57 PM
On Win/Lin/Mac you can have dynamic linking so why not use SFML for it and some other lib for iOS?


Title: Re: Best C/C++ Audio API
Post by: Paul Jeffries on November 04, 2011, 06:16:10 PM
I've used IrrKlang before and that's nice and simple to get working, although I think you have to buy a license if you want to sell the game.  For my current project I'm using OpenAL, which needed a lot more manual work but seems to work OK.


Title: Re: Best C/C++ Audio API
Post by: eclectocrat on November 04, 2011, 06:46:15 PM
I'm shocked and appalled at the state of audio API's on non-Mac systems. WTF? You want me to set up a thread and a queue myself? Why don't you do it for me Microsoft? On OSX you can just write [audioPlayer playThisFuckingBigFileForMe:@"file"]; and it'll do it right. It'll decompress and buffer it, and you can set it's volume, pan and even playback rate. But the biggest gorram software company in the world wants me to use file handles and parse RIFF chunks on my own?

I'm disgusted and pissed off. I will write an audio wrapper around OpenAL. It'll be easy as hell to use. Get ready, 'cus I'm gonna fuck shit up.


Title: Re: Best C/C++ Audio API
Post by: mcc on November 05, 2011, 01:18:11 AM
I'm shocked and appalled at the state of audio API's on non-Mac systems. WTF? You want me to set up a thread and a queue myself? Why don't you do it for me Microsoft? On OSX you can just write [audioPlayer playThisFuckingBigFileForMe:@"file"]; and it'll do it right. It'll decompress and buffer it, and you can set it's volume, pan and even playback rate. But the biggest gorram software company in the world wants me to use file handles and parse RIFF chunks on my own?

I'm disgusted and pissed off. I will write an audio wrapper around OpenAL. It'll be easy as hell to use. Get ready, 'cus I'm gonna fuck shit up.
SDL makes a thread for you on all systems, right?


Title: Re: Best C/C++ Audio API
Post by: eclectocrat on November 05, 2011, 01:43:40 AM
I'm shocked and appalled at the state of audio API's on non-Mac systems. WTF? You want me to set up a thread and a queue myself? Why don't you do it for me Microsoft? On OSX you can just write [audioPlayer playThisFuckingBigFileForMe:@"file"]; and it'll do it right. It'll decompress and buffer it, and you can set it's volume, pan and even playback rate. But the biggest gorram software company in the world wants me to use file handles and parse RIFF chunks on my own?

I'm disgusted and pissed off. I will write an audio wrapper around OpenAL. It'll be easy as hell to use. Get ready, 'cus I'm gonna fuck shit up.
SDL makes a thread for you on all systems, right?

SDL makes an audio thread for you, yeah, but if you want to stream large audio files from disk, then you'll probably want to make another thread yourself. SDL_mixer does everything for you AFAIK, it's higher level.