Pindrop
An open source project by
FPL.
|
The AudioEngine
is the main interface to library. The AudioEngine
is responsible for loading and unloading SoundBanks, playing sounds, managing channel priorities, spawning and despawing Listeners, and more.
To initialize the AudioEngine
, you must specify an AudioConfig. You may either load one yourself or supply a path to an AudioConfig FlatBuffer binary. For example:
Alternatively, you can also do this:
Once the library is initialized, the AudioConfig object is no longer necessary and can be deallocated.
Once during every game loop there should be a call to AdvanceFrame. This is where the AudioEngine
performs all prioritization and gain adjustments.
Before any audio can be played, the associated SoundBank must be loaded into memory. Loading a SoundBank loads all SoundCollectionDefs listed in the file, making them available to be played.
To load a SoundBankDef
simply call
And when the SoundBank is no longer required you can unload it with
Once a SoundCollectionDef has been loaded, it may be played with the following code:
However, playing a sound in this way incurs a map lookup. If a sound is going to be played frequently, a handle may be cached to improve performance.
SoundCollectionDefs may be either positional or non-positional. When they are positional, the loudness of a channel is determined by its distance from the nearest Listener. Typically you will only need a single Listener, positioned at the camera, but in some cases (such as games with split screen multiplayer for example) it may be desirable to have more than one Listener. When there are more than one Listeners, only the distance from the nearest listener is considered. If there are no Listeners at all, all positional audio will be silent.
The maximum number of listeners is specified in the AudioConfig. Listeners can be spawned as follows:
The location of the listener can be updated as often as is necessary. When a Listener is no longer needed it can be removed like so: