THIS PAGE REQUIRES UPDATING FOR CLANLIB 3.0
ClanSound provides you with easy-to-use and powerful sound functionality.
To play sound in ClanLib, you have to initialize clan::SetupSound and also create a clan::SoundOutput. clan::SoundOutput is the interface to a sound output device, which is used to control the main mixer volume and other global settings. It is used as a singleton.
A clan::SoundBuffer contains a sample or music stream. To load and play a WAV file, you do the following:
You can set the volume and panning of soundbuffers. This will change the default attributes of the soundbuffer, and will be effective on all subsequent calls to play().
Note that setting these attributes don't affect already playing soundbuffers, only when you call play() again afterwards. To have individual control over each playing sound, you need to use a sound session - read about that further down.
There isn't much difference between playing wav samples and music stream. ClanSound itself doesn't provide more than wav samples playback, so you'll need one or more additional music modules. ClanLib currently has two, MikMod and Vorbis. They are initialized using clan::SetupMikMod and clan::SetupVorbis.
Then to play music, you use the same approach as with wav samples:
If you want to control the playback of sound, or want to know if the sound is still playing, you use clan::SoundBuffer_Session. This can be created in two ways, either by calling clan::SoundBuffer::play() or clan::SoundBuffer::prepare(). The difference between prepare() and play() is that prepare will just load the sound, but not play it. You can then call play() from your resulting clan::SoundBuffer_Session.
When you have a session object, you can modify the attributes of the playing sound in many ways. These take effect immidiately, you can change it while it is playing. You can set the volume, panning, position, and frequency (speed). You can make it loop, and adding filters. You can query if it is still playing, and you can ofcourse start and stop it as you want.
Example of the fade filter:
Example of the echo filter:
You can also code your own filters. Check the SoundFilters example how do to that.
It is also possible to create sound on-the-fly, or adding extra sound providers. See the StreamSoundProvider example for code how to do this.