Gorilla.Audio.OpenAL Unit Reference

Overview

The Gorilla.Audio.OpenAL unit implements the Gorilla3D audio manager on top of OpenAL Soft. It provides TGorillaOpenALManager together with three collections: sounds (OpenAL buffers), channels (OpenAL sources) and effects (EFX auxiliary effect slots).

Class Hierarchy

TGorillaAudioManager
  └── TGorillaOpenALManager

TGorillaSoundItem
  └── TGorillaOpenALSoundItem

TGorillaChannelItem
  └── TGorillaOpenALChannelItem

TGorillaAudioEffectItem
  └── TGorillaOpenALEffectItem

TOwnedCollection
  ├── TGorillaOpenALSounds
  ├── TGorillaOpenALChannels
  └── TGorillaOpenALEffects

Companion Units

Unit Content
Gorilla.Audio.OpenAL.Loader LoadWAVFile(), LoadOGGFile(), LoadMP3File(), LoadAudioFile(), TAudioData
Gorilla.Audio.OpenAL.API OpenAL and EFX bindings (openal32.dll and platform equivalents)
Gorilla.Audio.MP3.API libmpg123 bindings
Gorilla.Audio.OGG.API libogg / libvorbis / libvorbisfile bindings

Enumerations

TDistanceModel

Value Description
dmInverse Inverse distance attenuation
dmLinear Linear distance attenuation
dmExponent Exponential distance attenuation

TEffectType

Value Description
etNone No effect
etReverb Reverb
etChorus Chorus
etEcho Echo
etDistortion Distortion
etFlanger Flanger
etCompressor Compressor

TPlaybackState

Value Description
psInitial Channel has never been played
psPlaying Currently playing
psPaused Paused, can be resumed
psStopped Stopped

Records

TStreamFormat

Format information about loaded audio data.

Member Description
IsMono() True for single channel data
IsStereo() True for two channel data
ToString() Human readable description

TVector6D

Six-component vector for the listener orientation: the first three components are the "at" (forward) vector, the last three the up vector.

Member Description
Create(AAtX, AAtY, AAtZ, AUpX, AUpY, AUpZ) Constructor
Default The standard orientation

TGorillaOpenALManager

Public Properties

Property Type Description
Initialized Boolean True once device and context exist

Published Properties

Property Type Description
Sounds TGorillaOpenALSounds Collection of audio buffers
Channels TGorillaOpenALChannels Collection of audio sources
Effects TGorillaOpenALEffects Collection of EFX effects
ListenerPosition TPoint3D Global listener position
ListenerVelocity TPoint3D Listener velocity, for the Doppler effect
ListenerOrientation TVector6D Forward and up vectors
DopplerFactor Single Doppler magnitude multiplier, default 1.0

Lifecycle

Method Description
InitializeOpenAL() Initializes device and context, returns success
ShutdownOpenAL() Releases all OpenAL resources
LoadAllSounds() Loads every file configured in Sounds
ClearSounds() Removes all buffers
Update() Updates streaming buffers and retires finished sources

Sound Loading

Method Description
CreateSoundItem(AName) Creates an empty item for the two step creation
LoadSoundItemFromFile(AFilename) Loads and returns the item
LoadSoundFromFile(AFilename) Loads without returning it
LoadSoundItemFromStream(AStream) Stream variants
LoadSoundItemFromStream(AMemStream) Memory stream variant
LoadSoundFromStream(...) Same without a return value
GetSoundItem(AHandle) Item by backend handle
GetSoundItemByFilename(AFilename) Item by file name

Channel Handling

Method Description
AddSoundToChannel(AChannelName, ASoundName) Adds a sound to a channel
RemoveSoundFromChannel(AChannelName, ASoundName) Removes it again
ClearChannelSounds(AChannelName) Empties a channel
ChannelHasSound(AChannelName, ASoundName) Membership test
GetChannelSoundCount(AChannelName) Number of sounds in a channel
PlayChannel(AChannelName / AChannel) Plays every sound of the channel
StopChannel(...), PauseChannel(...), ResumeChannel(...) Channel playback control
GetChannelState(...) Returns the TPlaybackState of a channel
StopAllChannels() Stops everything
ClearAllChannels() Clears every channel
PlaySound(ASoundName) Plays one sound, returns the channel it landed in
PlaySound(AIndex) / PlaySound(ASound) Base class overloads
PlaySoundItem(ASound) Plays an item, returns the channel
SetListenerWorldPosition(APosition) Convenience listener update
ApplyEffectToChannel(AChannelName, AEffectName) Routes a channel through an effect slot

TGorillaOpenALSoundItem

An OpenAL buffer plus the source settings applied when it is played.

Public

Member Description
BufferID The OpenAL buffer id
LoadBuffer() Loads the audio file into the buffer
LoadBufferFromStream(AStream) Loads from a stream
UnloadBuffer() Releases the buffer
IsPlaying(), Play(), Pause(), Resume(), Stop() Playback control
LoadFromStream(AStream) Fills an item created by CreateSoundItem()
Supports3DAudio(), Set3DAudio(), SetWorldPosition(), Set3DDistance(), SetPlaybackVolume(), SetPlaybackPitch() Backend independent 3D interface

Published Properties

Property Type Description
DisplayName String Unique identifier, used to link channels
FileName TFileName Audio file path
Loaded Boolean True when the buffer holds data (read-only)
Format TStreamFormat Mono/stereo, sample rate (read-only)
PlaybackLength UInt32 Length in ms
PlaybackPosition UInt32 Position in ms
Streaming Boolean Streams from disk instead of loading completely
Position TPoint3D 3D position
Velocity TPoint3D Velocity for the Doppler effect
Volume Single Gain, 0.0 … 1.0+
Looping Boolean Loops continuously
Pitch Single Playback speed / pitch, 1.0 normal
DistanceModel TDistanceModel Attenuation model
MaxDistance Single Distance the attenuation stops at
ReferenceDistance Single Distance up to which nothing is attenuated
RolloffFactor Single Strength of the distance attenuation
ConeInnerAngle Single Inner angle of the sound cone in degrees
ConeOuterAngle Single Outer angle in degrees
ConeOuterGain Single Gain outside the outer cone

TGorillaOpenALChannelItem

A named group of sounds played, paused and positioned together — the OpenAL counterpart to an FMOD channel group.

Member Type Description
IsPlaying Boolean True while any sound of the channel plays
SoundCount Integer Number of sounds in the channel
Sounds[Index] TGorillaOpenALSoundItem Sounds of the channel
Name String Channel name
Paused Boolean Pause state
PlaybackPosition Cardinal Position in ms
Position, Velocity TPoint3D 3D placement
Volume, Looping, Pitch Playback settings
DistanceModel, MaxDistance, ReferenceDistance, RolloffFactor Attenuation
ConeInnerAngle, ConeOuterAngle, ConeOuterGain Single Sound cone

TGorillaOpenALEffectItem

Property Type Description
Name String Unique identifier of the effect
EffectType TEffectType Kind of effect
Enabled Boolean Toggles the effect
Slot Integer Auxiliary effect slot used by OpenAL
EffectID Cardinal OpenAL effect id (read-only)

EFX requires an OpenAL implementation that supports the extension. OpenAL Soft does; some vendor drivers do not.

Collections

Class Notable members
TGorillaOpenALSounds Add(), FindByName(), FindByFileName(), Items[]
TGorillaOpenALChannels Add(), Items[]
TGorillaOpenALEffects Add(), Items[]

Supported Formats

Format Decoder Library
WAV (PCM) Built in —
OGG Vorbis Gorilla.Audio.OGG.API ogg, vorbis, vorbisfile
MP3 Gorilla.Audio.MP3.API libmpg123-0.dll / libmpg123.so / libmpg123.dylib

LoadAudioFile() picks the decoder by file extension.

See Also