Gorilla.Audio.Manager Unit Reference
Overview
The Gorilla.Audio.Manager unit defines the backend independent audio API of
Gorilla3D. It contains the abstract TGorillaAudioManager implemented by the
FMOD and OpenAL drivers, the abstract TGorillaSoundItem, and the older
TGorillaLegacyAudioManager, a thread based wrapper around the FMX
TMediaPlayer.
Class Hierarchy
TThread
└── TGorillaLegacyAudioManager
TFmxObject
└── TGorillaAudioManager (abstract)
├── TGorillaFMODAudioManager (Gorilla.Audio.FMOD)
└── TGorillaOpenALManager (Gorilla.Audio.OpenAL)
TCollectionItem
├── TGorillaSoundItem (abstract)
│ ├── TGorillaFMODSoundItem
│ └── TGorillaOpenALSoundItem
├── TGorillaChannelItem
└── TGorillaAudioEffectItem
Exception Classes
EGorillaAudioException = Exception;
Enumerations
TGorillaAudioAction
| Value |
Description |
Cache |
Cache audio file to memory |
Play |
Start playback |
Stop |
Stop playback |
Pause |
Pause or resume playback |
TGorillaAudioMode
| Value |
Description |
Once |
Play audio once |
Loop |
Play audio in a loop |
Records
TCacheAudioEntry
| Field |
Type |
Description |
Id |
Integer |
Unique audio identifier |
Mode |
TGorillaAudioMode |
Playback mode |
Volume |
Single |
Volume level |
Player |
TMediaPlayer |
FMX media player instance |
TQueueAudioEntry
| Field |
Type |
Description |
Id |
Integer |
Unique audio identifier |
Mode |
TGorillaAudioMode |
Playback mode |
Action |
TGorillaAudioAction |
Queue action |
AudioFile |
String |
File path |
Volume |
Single |
Volume (default 0.75) |
Types
TGorillaAudioCache = TDictionary<Integer, TCacheAudioEntry>;
TGorillaAudioManager
Abstract base class of the modern audio backends. Everything built on top of the
audio stack — playlist, text-to-speech, speech-to-text — programs against this
class, which is what makes the driver exchangeable.
Public Properties
| Property |
Type |
Description |
OnUpdate |
TNotifyEvent |
Fired when Update() was called; synchronized with the main thread when the auto-update thread triggered it |
OnListenerUpdated |
TNotifyEvent |
Fired when the listener settings changed |
Sound Handling
| Method |
Description |
ClearSounds() |
Removes all sound handles (abstract) |
LoadSoundFromFile(AFilename) |
Loads a sound handle from file (abstract) |
LoadSoundFromStream(AStream) |
Loads a sound handle from a stream, read completely into memory (abstract) |
LoadSoundFromStream(AMemStream) |
Loads from a memory stream, supports continuous streaming (abstract) |
LoadSoundItemFromFile(AFilename) |
Loads a file and returns the TGorillaSoundItem (abstract) |
LoadSoundItemFromStream(AStream) |
Loads from a stream and returns the item (abstract) |
LoadSoundItemFromStream(AMemStream) |
Loads from a memory stream and returns the item (abstract) |
CreateSoundItem(AName) |
Creates an empty item that does not hold audio data yet |
GetSoundItem(AHandle) |
Returns the item belonging to a backend handle (abstract) |
GetSoundItemByFilename(AFilename) |
Returns the item loaded from that file (abstract) |
CreateSoundItem() exists because some settings — 3D handling for example — are
evaluated while the audio data is created and cannot be changed afterwards. The
item is created first, configured, and filled through
TGorillaSoundItem.LoadFromStream(). It returns nil when the backend does not
support the two step creation, in which case callers have to fall back to
LoadSoundItemFromStream().
Playback and Channels
| Method |
Description |
PlaySound(AIndex) |
Plays a sound by index (abstract) |
PlaySound(ASound) |
Plays a sound item (abstract) |
StopAllChannels() |
Stops every channel (abstract) |
ClearAllChannels() |
Stops and releases every channel (abstract) |
Update() |
Updates streaming buffers and pending changes; call periodically (abstract) |
TGorillaSoundItem
Abstract collection item representing a single sound.
Published Properties
| Property |
Type |
Description |
FileName |
TFileName |
Sound file path |
PlaybackPosition |
UInt32 |
Current playback position in ms (read-only) |
PlaybackLength |
UInt32 |
Total length in ms (read-only) |
Playback Methods (abstract)
| Method |
Description |
IsPlaying() |
True while the sound is audible |
Play() |
Starts playback |
Pause() |
Pauses playback |
Resume() |
Resumes playback |
Stop() |
Stops playback |
LoadFromStream(AStream) |
Loads the audio data into an item created by CreateSoundItem() |
3D Interface
These methods form the backend independent interface used by modules on top of
the audio stack, such as text-to-speech. The base class implements them as
no-ops, so a backend only overrides what it actually supports.
| Method |
Description |
Supports3DAudio() |
True when the backend can play this sound at a position in 3D space |
Set3DAudio(AEnabled) |
Enables positional playback — has to be called before the audio data is loaded, because some backends decide about 3D handling while creating the sound |
SetWorldPosition(APosition) |
Moves the sound to a world space position |
Set3DDistance(AMin, AMax) |
Distance range the sound is attenuated in |
SetPlaybackVolume(AVolume) |
Playback gain, 0.0 silent, 1.0 unchanged |
SetPlaybackPitch(APitch) |
Playback pitch, 1.0 unchanged, 2.0 one octave up |
TGorillaChannelItem / TGorillaAudioEffectItem
Empty TCollectionItem base classes. The drivers derive their concrete channel
and effect items from them — see TGorillaOpenALChannelItem,
TGorillaOpenALEffectItem and the FMOD channel groups.
TGorillaLegacyAudioManager
Thread based audio manager using FMX TMediaPlayer, one player per audio file.
Simple, but not built for performance. A global instance named AudioManager is
created by the unit.
var
AudioManager : TGorillaLegacyAudioManager;
Public Properties
| Property |
Type |
Default |
Description |
LoopCheckInterval |
Integer |
100 |
Interval in ms at which finished loops are restarted; lower values cost performance |
QueueTimeout |
Integer |
250 |
Time in ms the worker waits for a queue event |
Mute |
Boolean |
False |
Mutes every loaded audio file |
Public Methods
| Method |
Description |
BeginCaching() |
Starts batch caching — call before adding files |
EndCaching() |
Ends the batch |
AudioAlreadyCached(AId) |
True when that id is already cached |
Add(AId, AFilename, AVolume) |
Caches an audio file under a unique id |
Play(AId, AMode, AVolume) |
Plays a cached file |
Stop(AId) |
Stops playback |
Pause(AId) |
Pauses, or resumes a paused file |
PauseAll() |
Pauses everything currently playing |
StopAll() |
Stops everything currently playing |
Remarks
- The first
TMediaPlayer has to be created in the main thread. The unit
therefore stores an empty.mp3 resource in
System.IOUtils.TPath.GetTempPath() during initialization; if that fails, no
playback is possible.
- One media player per file — memory use grows quickly.
- Caching loads every file completely, which can slow startup down noticeably.
See Also