goerdy
goerdy

Reputation: 11

Playing Sound in C++

I need to play sound in C++. It should be compatible across all platforms.

Thanks,

goerdy

Upvotes: 1

Views: 2691

Answers (4)

Isaac Nequittepas
Isaac Nequittepas

Reputation: 392

My suggestion is to go with OpenAl (3D cross platform Audio API)

It's fairly easy to learn and meant to have a similar flow of programming as OpenGl. It's free and has different extensions to take advantage of sound cards. OpenAl has a library akin to OpenGl's Utility Toolkit (GLUT) that's called freealut. It makes things even simpler.

This might be a good place to get started: http://www.devmaster.net/articles/openal/

Some of the functions in that code are deprecated but reading the documentation, you'll be able to update it.

The devmaster tutorial also teaches you how to load ogg vorbis (royalty free) files into memory and play them. You'll need to download and build libvorbis and libogg to do that but there's good documentation and, in case you're using Visual Studio, already made solutions.

The fact that Creative Labs (largest sound card manufacturer) is a major contributor to the project is a great point in it's favor. Hardware will not be ignored.

Last thing, remember to download the OpenAl SDK and link to the proper libraries and include directories. There's always a lot of people asking for specific files stored inside it.

Upvotes: 2

Kevin Lacquement
Kevin Lacquement

Reputation: 5117

"Compatible to all platforms" is a bit of a tall order. After all, "all platforms" includes the controller in your car, the regulator in a nuclear plant, and the router in your network.

If you mean "all desktop platforms", you may have a bit more luck. While it is impossible to produce sound in 100% standards C++, there are libraries that are available. However, I don't think that even these will get you "all platforms". Are you willing to settle for "most common platforms"?

Upvotes: 1

Armen Tsirunyan
Armen Tsirunyan

Reputation: 133092

std::cout << "\a\a\a\a\a\a\a\a";

)))

Upvotes: 5

Kos
Kos

Reputation: 72299

Try OpenAL, FMOD or SDL_mixer. The choice is wide.

Upvotes: 5

Related Questions