BASS is a comprehensive sound library similar to FMOD. It's not free for commercial development, but its license fee is affordable for indie developers such as small teams and individuals making shareware products. Like FMOD, BASS is a simple library to use. It can be downloaded from http://www.un4seen.com/.
Figure 20.2
Some of BASS's features and properties are listed below.
Supported Platforms
Windows
Mac
Supported Audio File Formats
AIFF
MP2
MP3
OGG
WAV
Refer to section 20.2 for a description of these audio formats.
Once downloaded, the BASS SDK can be used immediately. All projects referencing BASS must link to the BASS.lib library, and must also include the BASS.h source file.
In BASS, sound files such as MP3, OGG, and so on are called streams. Streams can be played easily using BASS. Consider the following sample program:
#include "bass.h" int main() { if (!BASS_Init(-1,44100,0,hwnd,NULL)) { HSTREAM stream=BASS_StreamCreateFile(FALSE,"song.mp3",0,0,0); BASS_ChannelPlay(stream, false); } BASS_Free(); return 0; }
If using this new library seemed simple, it's probably because your programming experience and practice with other libraries is allowing you to see the similarities, themes, and standards that underpin most libraries. Here, the BASS_Init function sets up the sound hardware so it is ready to use. It accepts a window handle, the number of sound channels to use, and the playback rate at which sound is to be played.
Once BASS has been initialized with the first function call, the BASS_StreamCreateFile function is called. This actually loads a sound file into a stream, represented by class HSTREAM. Then finally the whole system is set in motion and the sound is played using the BASS_ChannelPlay function. For more examples of using the BASS library, take a look at the sample code on the companion downloadable files.