Cross-Platform Game Programming with gameplay3d/Audio

Overview
Gameplay3d supports 3D audio (using OpenAL, the specification for which can be found here). The basic principles behind using sound in gameplay3d are as follows:


 * Your game can have one or more, which can, if desired, be attached to a   and positioned in 3D space;
 * Non-positional audio, such as music, is achieved by creating and playing an  which is not attached to a  ; and
 * Your game has one  which receives the sound from the  . By default, the   is bound to the active camera of the scene, but can be attached to another camera or positioned manually if desired.

Supported audio formats
Gameplay3d currently supports the following formats:


 * .ogg vorbis audio, which is a free and open-source compressed audio format specification; and
 * .wav files, whichis a Microsoft and IBM uncompressed audio format.

Using .ogg files is recommended for release versions of your game, as they are compressed and therefore use less memory.

Creating an AudioSource
can be created from an audio sample file as follows:

can also be created and configured from a  file - see below for further details.

Positioning the AudioSource
An  can be bound to a Node in your scene using. The position of the audio source is automatically updated when the node is transformed.

For example, we could use the following example to position an  emitting a bird sound:

Playing and controlling the AudioSource
To play an audio source:

Other member functions controlling playback are,  ,   and.

We can configure the sound as follows:

Positioning the AudioListener manually
The  can be positioned manually (in this case at the scene's origin) as follows:

The  can be attached to a specific camera (e.g where multiple viewpoints are onscreen simultaneously) as follows:

.audio files
The following example illustrates how to set all of the AudioSource properties using a .audio file.

Add the following in your  file:

Add the following in your  file: