FMOD Driver
TGorillaFMODAudioManager implements the Gorilla3D audio manager on top of the
FMOD Core API. It is the richer of the two drivers: channel groups, DSP
effect chains, 3D reverb zones and geometry based occlusion are all available,
and FMOD brings its own broad set of codecs.
Table of Contents
- Units
- Setting up the Manager
- Sound Items
- Channel Groups
- 3D Audio and the Listener
- DSP Effects
- 3D Reverb
- Geometry Occlusion
- The Update Loop
- Libraries and Deployment
- Platform Notes
- Best Practices
- See Also
Units
| Unit | Content |
|---|---|
Gorilla.Audio.FMOD |
TGorillaFMODAudioManager, TGorillaFMODSoundItem, channel groups, effects |
Gorilla.Audio.FMOD.System |
FMOD system initialization and global settings |
Gorilla.Audio.FMOD.Sound |
Sound handles |
Gorilla.Audio.FMOD.Channel |
Channel handling |
Gorilla.Audio.FMOD.ChannelGroup |
Channel group handling |
Gorilla.Audio.FMOD.SoundGroup |
Sound groups |
Gorilla.Audio.FMOD.DSP |
Digital signal processing effects |
Gorilla.Audio.FMOD.Reverb3D |
3D reverb zones |
Gorilla.Audio.FMOD.Geometry |
Geometry based occlusion |
Gorilla.Audio.FMOD.Custom |
Hooks for custom FMOD extensions |
Android.JNI.FMOD |
JNI bridge used on Android |
Setting up the Manager
uses
Gorilla.Audio.Manager, Gorilla.Audio.FMOD;
var LAudio : TGorillaFMODAudioManager;
begin
LAudio := TGorillaFMODAudioManager.Create(Self);
LAudio.Parent := GorillaViewport1;
LAudio.AutoUpdate := true; // internal update thread
LAudio.AutoUpdateInterval := 33; // ms
end;
| Property | Default | Description |
|---|---|---|
AutoUpdate |
True | Runs an internal thread calling Update() |
AutoUpdateInterval |
33 | Interval of that thread in ms |
Sounds |
— | Design-time collection of TGorillaFMODSoundItem |
ChannelGroups |
— | Design-time collection of channel groups |
ListenerPosition |
— | Position of the listener |
ListenerVelocity |
— | Listener velocity, drives the Doppler effect |
ListenerForward |
— | Listener forward direction |
ListenerUp |
— | Listener up direction |
ListenerTarget |
— | A TControl3D the listener follows automatically |
ListenerUpdateInterval |
— | How often the target is polled |
AutoUpdateListenerForward |
— | Whether the forward vector follows the target too |
Read-only helpers: SystemObject (the raw IGorillaFMODSystem for anything the
component does not wrap), SoundRefs[], ChannelGroupRefs[] and IsPlaying.
Sound Items
TGorillaFMODSoundItem derives from TGorillaSoundItem and adds the full FMOD
channel feature set:
| Property | Description |
|---|---|
FileName |
Audio file to load |
Mode |
Mode2D or Mode3D — evaluated when the sound is created |
ChannelGroup |
Name of the group the sound plays in |
Loop, LoopCount |
Looped playback, -1 = endless |
AutoStart |
Starts automatically once the manager is loaded |
Volume, Pitch, Mute, Frequency |
Basic channel settings; a negative frequency plays non-streamed sounds backwards |
Priority |
0 (most important) … 256, default 128 — decides who gets dropped when channels run out |
PositionInMilliseconds |
Seek position |
VolumeRamp |
Smooths abrupt volume changes |
LowPassGain |
Gain of the low pass applied by occlusion and reverb |
FadeIn, FadeOut |
Fade durations |
AntiFatigue, AntiFatigueLevel |
Tiny random volume variation, so a sample repeated over and over stops sounding identical |
FadeInMinVol … FadeOutMaxVol |
Range the anti-fatigue variation works in |
Position3D, Velocity3D |
3D placement of the sound |
MinMax3DDistance |
Distance range for attenuation |
Cone3DSettings |
Inner angle, outer angle and outer volume of a directional sound |
Delay, DelayDSPClockStart, DelayDSPClockEnd |
Sample accurate scheduling |
Effects |
Collection of DSP effects attached to this sound |
OnPlay, OnPause, OnStop |
Playback events |
var LSound : TGorillaFMODSoundItem;
begin
LSound := LAudio.Sounds.Add();
LSound.FileName := 'sounds/torch.wav';
LSound.Mode := TGorillaFMODSoundMode.Mode3D;
LSound.ChannelGroup := 'SFX';
LSound.Loop := true;
LSound.LoopCount := -1;
LSound.AntiFatigue := true;
LSound.MinMax3DDistance := Position(1, 30);
end;
Mode decides whether FMOD creates a 2D or a 3D sound and is read while the
sound is created — set it before the audio data is loaded. That is exactly why
CreateSoundItem() exists, see Audio Manager.
Channel Groups
Channel groups are the FMOD way of building buses: music, SFX, voice. A sound is assigned to a group by name, and the group controls volume, muting and effects for everything inside it at once.
var LGroup : TGorillaFMODChannelGroupItem;
begin
LGroup := LAudio.ChannelGroups.Add();
LGroup.DisplayName := 'SFX';
// later on, through the FMOD interface
LAudio.ChannelGroupRefs['SFX'].SetVolume(0.4);
end;
3D Audio and the Listener
The simplest setup links the listener to the camera and lets the manager do the rest:
LAudio.ListenerTarget := Camera1;
LAudio.AutoUpdateListenerForward := true;
LAudio.ListenerUpdateInterval := 33;
Without a target, set the four listener vectors yourself, or use
Set3DListener() for the complete attribute set in one call. OnListenerUpdated
fires whenever the listener changed.
DSP Effects
Gorilla.Audio.FMOD.DSP wraps the FMOD DSP units — reverb, echo, chorus,
distortion, compressor, parametric EQ, pitch shifter and the rest of the FMOD
catalogue. Effects are attached per sound through its Effects collection, and
AttachEffects() / DetachEffects() on the sound item switch the whole chain on
and off.
For everything the component does not wrap, go through SystemObject and use
the FMOD API directly.
3D Reverb
Gorilla.Audio.FMOD.Reverb3D defines reverb zones in 3D space: a position, an
inner and an outer radius and a reverb preset. As the listener moves through the
world, FMOD blends between the zones automatically — a cave sounds like a cave
without a single line of gameplay code.
Geometry Occlusion
Gorilla.Audio.FMOD.Geometry feeds polygons into FMOD's occlusion engine.
Sounds behind a wall are then attenuated and low-pass filtered by the geometry
instead of being audible through it. Use a very coarse version of the level
geometry — occlusion meshes are a budget item, not a copy of the render mesh.
The Update Loop
FMOD has to be updated regularly, otherwise 3D positions, streaming and virtual
voices go stale. Either leave AutoUpdate on and let the internal thread do it,
or switch it off and call Update() in your render loop:
LAudio.AutoUpdate := false;
// ...
procedure TForm1.GorillaViewport1Render(Sender : TObject; ...);
begin
LAudio.Update();
end;
Libraries and Deployment
The FMOD binaries ship with Gorilla3D under <installation>\lib\fmod\. Two
variants exist:
| Library | Purpose |
|---|---|
fmodL / fmodL64 |
Logging build, verbose diagnostics — the default |
fmod / fmod64 |
Productive build, no logging |
Switch to the productive build at the very start of your application, before the first manager is created:
// in the .dpr file
TGorillaFMODAudioManager.UseProductiveLibrary := true;
For design-time support the logging DLL has to be copied into the IDE binary folder, see Installation.
FMOD itself is a commercial product of Firelight Technologies. It is free below a revenue threshold, but it always requires registration and attribution — check the current terms before shipping:
- FMOD Engine downloads: https://www.fmod.com/download
- Licensing terms: https://www.fmod.com/licensing
- API documentation: https://www.fmod.com/docs
Platform Notes
| Platform | Support |
|---|---|
| Windows | 32 and 64 bit |
| macOS | Yes |
| iOS | Yes |
| Android | Yes, through the JNI bridge in Android.JNI.FMOD |
| Linux | Not supported by this driver — use OpenAL |
Best Practices
- Set
Modeand the 3D distances before the audio data is loaded - Group sounds into channel groups and mix through the group, not per sound
- Use
Priorityso important sounds survive when the channel limit is reached - Enable
AntiFatiguefor footsteps, impacts and other frequently repeated samples - Keep occlusion geometry coarse
- Ship the productive library and set
UseProductiveLibraryin release builds
See Also
API Reference
- Gorilla.Audio.FMOD — Full class reference
- Gorilla.Audio.Manager — Base classes
Related Topics
- Audio Manager — The backend independent API
- OpenAL Driver — The open source alternative
- Audio Playlist — Playlist on top of this driver
- Installation — Deploying the FMOD library