20.3 BASS


20.3 BASS

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/.

image from book
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.

20.3.1 Installing and Configuring

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.

20.3.2 Playing Sound and Music

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.




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

Similar book on Amazon
Beginning C++ Through Game Programming
Beginning C++ Through Game Programming
Beginning Game Programming
Beginning Game Programming
The Ultimate Guide to Video Game Writing and Design
The Ultimate Guide to Video Game Writing and Design

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net