开发者

Playing Sound in C++

I开发者_开发百科 need to play sound in C++. It should be compatible across all platforms.

Thanks,

goerdy


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


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

)))


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.


"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"?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜