views:

6473

answers:

10

I am programming in C++ (Visual Studio 2008) and wish to do the following in both Windows XP and Windows Vista.

  1. Play audio files (wav, mp3, others if they come along for free...) and be able to control the left/right sound levels independently.

  2. Play tracks from audio CDs and be able to control the left/right sound levels independently.

What is the best sound API to let me do this? Ideally I would like to use some kind of third party sound library that wraps the Windows API that is easy to use.

+4  A: 

Check out FMOD music & sound system: http://www.fmod.org/

It's free if your product is free. $100 if you are a hobbyist, otherwise it is quite expensive. It is very powerful and has lots of features, but is still easy to use. I wrote a DJing mp3 player with it in less than a day.

FigBug
+2  A: 

SDL Mixer (built on SDL audio) is pretty easy to work with and is free.

It works with .ogg's and 'in theory' works with .mp3's However, note "in thoery". I suggest it as I haven't used it in a while so those issues may have been resolved. It's certainly worth taking a look at.

xan
+1  A: 

Another thing to look at are the DirectX type functionality. Using things like DirectSound, DirectShow allows you to utilize the codec packs that people install on their machines. If they want to play ogg, flac or some other 'unsupported' audio formats on windows, they can install the codec pack and it would work if you are using these DirectX APIs.

Disclaimer: I am not a C++ windows programmer, my knowledge of this is limited, however this is what I have noticed in terms of how Windows does audio and I am familiar with some of these codec packs.

Redbeard 0x0A
+2  A: 

Have a look at this: http://stackoverflow.com/questions/158282/is-directsound-the-best-audio-abstraction-layer-for-windows

The question is for .NET but suggested libraries have C++ bindings.

Also, check out irrKlang which has easy to use 2D/3D sound playing and is pretty cheap.

kshahar
A: 

FMOD, definately. I use it almost exclusively.

Kawa
+2  A: 

I'm working with trolltech's qt4.4 right now. And I have seen that they added a sound module called "Phonon" since this version. I didn't use that module right now but it looks quite interesting.

Here are some links:

nutario
A: 

You don't need any external libraries (libs are for those who can't program...)

Everything is included natively into Win32 api (MM) and very easy to use

The Win32 API is a collection of libraries for people that can't program. Surely you should be coding your own operating system in machine language?
1800 INFORMATION
+3  A: 

I can recommend the BASS library. It has many plugins for all kinds of sound formats (WMA, MP3, AAC, OGG and many more). You can also use Winamp DSP plugins and much more. It has a clean API and is free for non-commercial use.

Read more here: http://www.un4seen.com

Magnus Johansson
I also worked a little with BASS and found it quite dependable and easy to use.
Thomas
+13  A: 

It all depends on what you're doing.

If you're just going to be rednering stereo PCM audio, simplest API is probably the wave family of APIs (waveOutOpen/waveOutPrepareHeader/waveOutBufferWrite/waveOutClose).

If you're going to be rendering existing files, then DirectShow is probably your best bet - the RenderFile API makes it totally trivial.

The DirectShow family of APIs has the ability to mix multiple streams of audio and (with Direct3D) has the ability to interpolate positional information to handle the streams properly.

If you want low latency audio, you need to use either ASIO or DirectKS (on XP) or WASAPI (on > Vista).

Larry Osterman
One of the Principal SDEs for Audio in Windows' answer deserves at least one point :)
Paul Betts
+1  A: 

I program exclusively with win api (in c and assembly no less), but I don't understand the statement that "libs are for those who can't program". A dll is a dynamic link library and the win api is exposed through dll's that you load at runtime or ad hoc. A lib is a static executable, but a dll is a dynamic executable so I fail to see how using a lib is for those who can't program, especially since the functions need to be called and implemented.

*On the actual note:

Video Lan Project has a nice mm library (static) or a set of dll's (for real programmers....)

The BSD license is the best way to go with open source, anything short of that is a waste of time if you are trying to commercialize a project.

Cheers!