fmod

http://www.fmod.org/
http://www.fmod.org/docs/

fmod is a cross-platform (Linux, Windows, Mac, & gaming consoles) sound toolkit, marketed for game development.

Some advantages over bergen:

fmod automatically starts several separate threads in your program when it is initialized, to handle the audio in parallel. This means that there isn't any extra server program to run.

Playing sounds

To use fmod in a program, you must first initialize it:

if (FSOUND_GetVersion() < FMOD_VERSION)
    {
    printf("Error: You have the wrong FMOD version"
           " - you should be using FMOD %.02f\n",
           FMOD_VERSION);
    exit(1);
    }

FSOUND_SetOutput(FSOUND_OUTPUT_OSS);

if (!FSOUND_Init(44100, 1024,
                 FSOUND_INIT_USEDEFAULTMIDISYNTH))
    {
    printf("Error: %s\n",
           FMOD_ErrorString(FSOUND_GetError()));
    exit(1);
    }

To play a sample file (WAV format), use FSOUND_Sample_Load() and FSOUND_PlaySound():

FSOUND_SAMPLE *samplesound;
samplesound = FSOUND_Sample_Load(FSOUND_UNMANAGED,
                                 "boing.wav",
                                 FSOUND_NORMAL, 0);
FSOUND_Sample_SetMode(samplesound, FSOUND_LOOP_OFF);
FSOUND_PlaySound(FSOUND_FREE, samplesound);

To play a stream sound (MP3 or Ogg), use FSOUND_Stream_Load() and FSOUND_Stream_Play():

FSOUND_STREAM *mp3sound;
mp3sound = FSOUND_Stream_OpenFile("tarotplane.mp3",
                                  FSOUND_NORMAL, 0);
FSOUND_Stream_Play(FSOUND_FREE, mp3sound);

FSOUND_PlaySound() and FSOUND_Stream_Play() return channel numbers, indicating the channel that the sound is being played on. The channel number can be used to control a playing sound, such as changing its volume (FSOUND_SetVolume()) or pausing/unpausing it (FSOUND_SetPaused()). FSOUND_PlaySoundEx() can be used to start a sample in paused mode, so that you can adjust settings on the channel before actually having it start playing. FSOUND_Stream_PlayEx() similarly lets you start a stream sound in paused mode.

Example: fmod0.cpp

3D sounds

Sound spatialization in fmod is handled by setting a position for each 3D sound, and a position & orientation for the listener. The 'MinMaxDistance' setting for a sound can be used to affect how quickly the volume of the sound falls off with distance. FSOUND_Update() must be called any time the 3D settings change, in order for them to actually take effect.

float soundPos[3] = {5, 5, 0};
float listenerPos[3] = { 0, 0, -2 };
FSOUND_Sample_SetMinMaxDistance(samplesound, 5.0, 1000.0);    
int channel = FSOUND_PlaySound(FSOUND_FREE, samplesound);
FSOUND_3D_SetAttributes(channel, soundpos, NULL);

FSOUND_3D_Listener_SetAttributes(listenerPos, NULL,
                     0.0, 0.0, -1.0, 0.0, 1.0, 0.0);
FSOUND_Update();

Example: fmod1.cpp

The spatialization features allow you to assign velocities to the listener and the sound emitters, to produce doppler effects. You can also set reverb properties, to get the effect of different types of spaces.

There are many other advanced features in fmod. See the documentation for details.

Compiling with fmod

I have placed a copy of the fmod API files in ~dave/424/ (lib & include). To compile a program with fmod, add -I/home/dms/dave/424/include to your compile flags (if you don't already have it), and /home/dms/dave/424/lib/libfmod-3.61.so to your link libraries (LIBS) (using -lfmod-3.61 does not seem to correctly link everything).
For example:

CFLAGS = -O -I/home/dms/dave/424/include
CPPFLAGS = $(CFLAGS)
LFLAGS = -O
LIBS = -L/home/dms/dave/424/lib -ldms -limage -ltiff \
       /home/dms/dave/424/lib/libfmod-3.61.so \
       -lglut -lGLU -lGL -L/usr/X11R6/lib -lX11 -lm

fmod0: fmod0.o
	c++ $(LFLAGS) -o fmod0 fmod0.o  $(LIBS)