We don’t allow questions se开发者_高级运维eking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this questionIs there an API only for sound?
APIs such as Allegro or SDL provide too much for my needs. I simply need a library that can do something like:
InitSound();
Sound *door = LoadSound("door.wav");
PlaySound(door,volume);
It would also be great if it could support compressed formats such as Vorbis or MP3.
I'm a big fan of the SFML library. It does provide additional graphics and network features, but what is relevant to this question, is that it also has neat audio package.
Audio features are:
- Uses hardware acceleration whenever possible
- Can load and save standard sound formats: Ogg, WAV, FLAC, AIFF, Au, RAW, paf, 8SVX, NIST, VOC, IRCAM, W64, MAT4, MAT5 PVF, HTK, SDS, AVR, SD2, Core Audio Format, WVE, MPC2K, RF64
- Can load all audio resources directly from files in memory
- 3D sound spacialization
- Easy interface for capturing audio
- Manages memory efficiently, so that you don't have to worry about resources lifetime or storage
- Supports streaming for big files; you can even write your custom streaming class for any source (network, ...)
- Supports multi-channels formats (mono, stereo, 4.0, 5.1, 6.1, 7.1)
Website: http://www.sfml-dev.org/
Use PortAudio. It is a portable cross-platform audio API.
If you are use to using OpenGL then you might like to try OpenAL?
The API is very similar to OpenGL so you should feel at home.
I really like SFML, it's written in C++ and follows most of the rules of good API design (RAII and so forth).
If you prefer a more "C-like" library, SDL needs to be mentioned.
SDL_sound is very simple to use, and handles the decoding for you. If you used OpenAL, you would have to do the decoding yourself (last I used it, anyway). I actually prefer OpenAL for games, though.
I know it's an old question but anyone stumbling upon this now might like to check out FMOD
You can make use of the low-level API to start simple then make use of the more powerful features (and FMOD Studio) later-on if required.
Here's the documentation for playing a sound, which references the samples in the API:
This example shows how to simply load and play multiple sounds, the simplest usage of FMOD.
I used this low-level API for a cross platform (Mac, Windows) Space Invaders clone I developed and found it very useful!
You may want to have a look at the Kowalski project, a cross platform audio API geared towards games and similar interactive applications. It's released under the zlib license.
If you are looking for a professional cross-platform sound design API and authoring application, take a look at Audiokinetic Wwise. It can do much more than just play sounds. It has effects, complex sound logic system, sound layering, profiling, interactive music tools, etc... It provides Ogg Vorbis and MP3 support, and it is free for non-commercial projects.
Although it is only free for non-commercial applications, Bass is really easy to implement.
Example of usage:
// initialize device at 44kHz
if (!BASS_Init(-1,44100,0,0,NULL))
{
printf("Can't initialize device");
return 0;
}
HSAMPLE sample;
HCHANNEL channel;
// load from disk
if( sample = BASS_SampleLoad(FALSE,"foo.wav",0,0,1,BASS_SAMPLE_OVER_POS) ) {
// get playable channel
channel = BASS_SampleGetChannel( sample,FALSE);
// play
BASS_ChannelPlay(channel,TRUE);
// wait for playback to finish
while( BASS_ChannelIsActive( channel ) )
Sleep(100);
BASS_SampleFree(sample);
}
// cleanup
BASS_Free();
Consider libsoundio. It does not support compression or codecs, but it does provide a robust cross platform sound API. It might be a bit low level for your needs; the library you're looking for might be built on top of libsoundio.
Try libao http://www.xiph.org/ao/ - its very simple & supports variety of platforms. I tried it on a raspberry pi with success.
精彩评论