Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
Gondwana.Audio.AudioResourceManager Class Referencesealed

Manages the lifecycle of audio resources independently of the playback backend. More...

Inheritance diagram for Gondwana.Audio.AudioResourceManager:

Public Member Functions

void ConfigureBackend (IAudioBackend backend)
 Configures the backend used for subsequently loaded audio resources. A backend cannot be replaced while resources are loaded.
AudioResource LoadFromFile (string key, string filePath, float volume, float pan)
 Compatibility overload that loads an audio resource from a file path. Retains the pre-backend-refactor CLR signature for compiled callers.
AudioResource LoadFromFile (string key, string filePath, float volume=1.0f, float pan=0.0f, float playbackSpeed=1.0f)
 Loads an audio resource from a file on disk.
AudioResource LoadFromStream (string key, Stream input, string fileExt, float volume, float pan)
 Compatibility overload that loads an audio resource from a stream. Retains the pre-backend-refactor CLR signature for compiled callers.
AudioResource LoadFromStream (string key, Stream input, string fileExt, float volume=1.0f, float pan=0.0f, float playbackSpeed=1.0f)
 Loads an audio resource from the provided Stream.
AudioResource LoadFromUri (string key, string uri, float volume=1.0f, float pan=0.0f, float playbackSpeed=1.0f)
 Loads an audio source by URI. This is primarily intended for URI-capable backends such as browser audio.
List< AudioResource > LoadFromEngineAssetsFile (AssetsFile resourceFile, float defaultVolume, float defaultPan)
 Compatibility overload that loads audio resources from an AssetsFile. Retains the pre-backend-refactor CLR signature for compiled callers.
List< AudioResource > LoadFromEngineAssetsFile (AssetsFile resourceFile, float defaultVolume=1.0f, float defaultPan=0.0f, float defaultPlaybackSpeed=1.0f)
 Loads all audio entries from the provided AssetsFile and returns the loaded resources.
AudioResource? Clone (string key, string? newKey, float? volume, float? pan)
 Compatibility overload that creates a clone of an existing audio resource. Retains the pre-backend-refactor CLR signature; the clone inherits its source's playback speed.
AudioResource? Clone (string key, string? newKey=null, float? volume=null, float? pan=null, float? playbackSpeed=null)
 Creates a clone of an existing AudioResource. The clone may inherit or override volume, pan, and playback speed from the source resource.
void Unload (string key)
 Unloads and disposes the audio resource with the specified key, if it exists.
void Clear ()
 Disposes and clears all loaded audio resources.
bool TryGet (string key, out AudioResource? resource)
 Attempts to retrieve a loaded audio resource by key.
AudioResource? Get (string key)
 Gets the AudioResource with the specified key, or null if not found.
bool Contains (string key)
 Determines whether an audio resource with the specified key is loaded.
IEnumerable< string > GetAllKeys ()
 Returns all loaded audio resource keys.
Dictionary< string, AudioResource > GetAll ()
 Returns a snapshot dictionary of all loaded audio resources.
void Dispose ()
 Disposes the manager and all loaded audio resources. This method is idempotent.

Properties

static AudioResourceManager Instance [get]
 Gets the singleton AudioResourceManager instance.
IAudioBackend? Backend [get]
 Gets the currently configured audio backend, or null if none has been configured.
bool IsBackendConfigured [get]
 Gets whether an audio backend has been configured.

Events

EventHandler<(string Key, AudioResource Resource)>? SoundDisposed
 Occurs when a loaded AudioResource is disposed and removed from the manager. The event payload contains the resource key and the AudioResource instance.

Detailed Description

Manages the lifecycle of audio resources independently of the playback backend.

Definition at line 10 of file AudioResourceManager.cs.

Member Function Documentation

◆ Clear()

void Gondwana.Audio.AudioResourceManager.Clear ( )

Disposes and clears all loaded audio resources.

Definition at line 436 of file AudioResourceManager.cs.

◆ Clone() [1/2]

AudioResource? Gondwana.Audio.AudioResourceManager.Clone ( string key,
string? newKey,
float? volume,
float? pan )

Compatibility overload that creates a clone of an existing audio resource. Retains the pre-backend-refactor CLR signature; the clone inherits its source's playback speed.

Parameters
keyKey of the source resource to clone.
newKeyOptional key for the clone. If null, a generated key is used.
volumeOptional volume override for the clone.
panOptional pan override for the clone.
Returns
The cloned AudioResource or null if the source was not found or could not be cloned.

◆ Clone() [2/2]

AudioResource? Gondwana.Audio.AudioResourceManager.Clone ( string key,
string? newKey = null,
float? volume = null,
float? pan = null,
float? playbackSpeed = null )

Creates a clone of an existing AudioResource. The clone may inherit or override volume, pan, and playback speed from the source resource.

Parameters
keyKey of the resource to clone.
newKeyOptional new key for the clone. If null a generated key is used.
volumeOptional volume override for the clone.
panOptional pan override for the clone.
playbackSpeedOptional playback speed override for the clone.
Returns
The cloned AudioResource or null if cloning was not possible.

Definition at line 274 of file AudioResourceManager.cs.

◆ ConfigureBackend()

void Gondwana.Audio.AudioResourceManager.ConfigureBackend ( IAudioBackend backend)

Configures the backend used for subsequently loaded audio resources. A backend cannot be replaced while resources are loaded.

Parameters
backendThe IAudioBackend implementation to use for audio playback.
Exceptions
InvalidOperationExceptionThrown if attempting to replace the configured backend while audio resources are still loaded.

Definition at line 46 of file AudioResourceManager.cs.

◆ Contains()

bool Gondwana.Audio.AudioResourceManager.Contains ( string key)

Determines whether an audio resource with the specified key is loaded.

Parameters
keyKey to check for existence.
Returns
True if the key exists; otherwise false.

◆ Dispose()

void Gondwana.Audio.AudioResourceManager.Dispose ( )

Disposes the manager and all loaded audio resources. This method is idempotent.

Definition at line 485 of file AudioResourceManager.cs.

◆ Get()

AudioResource? Gondwana.Audio.AudioResourceManager.Get ( string key)

Gets the AudioResource with the specified key, or null if not found.

Parameters
keyKey of the audio resource to retrieve.
Returns
The AudioResource if found; otherwise null.

◆ GetAll()

Dictionary< string, AudioResource > Gondwana.Audio.AudioResourceManager.GetAll ( )

Returns a snapshot dictionary of all loaded audio resources.

Returns
A Dictionary<String,AudioResource> containing the loaded resources.

◆ GetAllKeys()

IEnumerable< string > Gondwana.Audio.AudioResourceManager.GetAllKeys ( )

Returns all loaded audio resource keys.

Returns
An IEnumerable<String> of all resource keys.

◆ LoadFromEngineAssetsFile() [1/2]

List< AudioResource > Gondwana.Audio.AudioResourceManager.LoadFromEngineAssetsFile ( AssetsFile resourceFile,
float defaultVolume,
float defaultPan )

Compatibility overload that loads audio resources from an AssetsFile. Retains the pre-backend-refactor CLR signature for compiled callers.

Parameters
resourceFileThe AssetsFile containing audio entries.
defaultVolumeDefault volume to apply to loaded resources.
defaultPanDefault pan to apply to loaded resources.
Returns
A list of loaded AudioResource instances.

◆ LoadFromEngineAssetsFile() [2/2]

List< AudioResource > Gondwana.Audio.AudioResourceManager.LoadFromEngineAssetsFile ( AssetsFile resourceFile,
float defaultVolume = 1::0f,
float defaultPan = 0::0f,
float defaultPlaybackSpeed = 1::0f )

Loads all audio entries from the provided AssetsFile and returns the loaded resources.

Parameters
resourceFileThe AssetsFile to read audio entries from.
defaultVolumeDefault volume to apply when an entry does not specify one.
defaultPanDefault pan to apply when an entry does not specify one.
defaultPlaybackSpeedDefault playback speed for loaded resources.
Returns
A list of loaded AudioResource instances.

Definition at line 194 of file AudioResourceManager.cs.

◆ LoadFromFile() [1/2]

AudioResource Gondwana.Audio.AudioResourceManager.LoadFromFile ( string key,
string filePath,
float volume,
float pan )

Compatibility overload that loads an audio resource from a file path. Retains the pre-backend-refactor CLR signature for compiled callers.

Parameters
keyUnique key for the audio resource.
filePathPath to the audio file to load.
volumeInitial volume (0.0 to 1.0).
panInitial stereo pan (-1.0 to 1.0).
Returns
The loaded AudioResource.

◆ LoadFromFile() [2/2]

AudioResource Gondwana.Audio.AudioResourceManager.LoadFromFile ( string key,
string filePath,
float volume = 1::0f,
float pan = 0::0f,
float playbackSpeed = 1::0f )

Loads an audio resource from a file on disk.

Parameters
keyUnique key for the audio resource.
filePathPath to the audio file.
volumeInitial volume (0.0 to 1.0).
panInitial stereo pan (-1.0 to 1.0).
playbackSpeedInitial playback speed (clamped to allowed range).
Returns
The loaded AudioResource.

Definition at line 87 of file AudioResourceManager.cs.

◆ LoadFromStream() [1/2]

AudioResource Gondwana.Audio.AudioResourceManager.LoadFromStream ( string key,
Stream input,
string fileExt,
float volume,
float pan )

Compatibility overload that loads an audio resource from a stream. Retains the pre-backend-refactor CLR signature for compiled callers.

Parameters
keyUnique key for the audio resource.
inputInput Stream containing audio data.
fileExtFile extension or hint for the audio data (e.g. ".wav").
volumeInitial volume (0.0 to 1.0).
panInitial stereo pan (-1.0 to 1.0).
Returns
The loaded AudioResource.

◆ LoadFromStream() [2/2]

AudioResource Gondwana.Audio.AudioResourceManager.LoadFromStream ( string key,
Stream input,
string fileExt,
float volume = 1::0f,
float pan = 0::0f,
float playbackSpeed = 1::0f )

Loads an audio resource from the provided Stream.

Parameters
keyUnique key for the audio resource.
inputInput Stream containing audio data.
fileExtFile extension or hint for the audio data (e.g. ".ogg").
volumeInitial volume (0.0 to 1.0).
panInitial stereo pan (-1.0 to 1.0).
playbackSpeedInitial playback speed (clamped to allowed range).
Returns
The loaded AudioResource.

Definition at line 121 of file AudioResourceManager.cs.

◆ LoadFromUri()

AudioResource Gondwana.Audio.AudioResourceManager.LoadFromUri ( string key,
string uri,
float volume = 1::0f,
float pan = 0::0f,
float playbackSpeed = 1::0f )

Loads an audio source by URI. This is primarily intended for URI-capable backends such as browser audio.

Parameters
keyUnique key for the audio resource.
uriThe URI referencing the audio resource.
volumeInitial volume (0.0 to 1.0).
panInitial stereo pan (-1.0 to 1.0).
playbackSpeedInitial playback speed (clamped to allowed range).
Returns
The created AudioResource.
Exceptions
ArgumentExceptionThrown when uri is null or whitespace.

Definition at line 144 of file AudioResourceManager.cs.

◆ TryGet()

bool Gondwana.Audio.AudioResourceManager.TryGet ( string key,
out AudioResource? resource )

Attempts to retrieve a loaded audio resource by key.

Parameters
keyKey of the audio resource to retrieve.
resourceWhen this method returns, contains the AudioResource associated with the key, if found; otherwise null.
Returns
True if the resource was found; otherwise false.

◆ Unload()

void Gondwana.Audio.AudioResourceManager.Unload ( string key)

Unloads and disposes the audio resource with the specified key, if it exists.

Parameters
keyKey of the audio resource to unload.

Definition at line 424 of file AudioResourceManager.cs.

Property Documentation

◆ Backend

IAudioBackend? Gondwana.Audio.AudioResourceManager.Backend
get

Gets the currently configured audio backend, or null if none has been configured.

Definition at line 35 of file AudioResourceManager.cs.

◆ Instance

AudioResourceManager Gondwana.Audio.AudioResourceManager.Instance
staticget

Gets the singleton AudioResourceManager instance.

Definition at line 32 of file AudioResourceManager.cs.

◆ IsBackendConfigured

bool Gondwana.Audio.AudioResourceManager.IsBackendConfigured
get

Gets whether an audio backend has been configured.

Definition at line 38 of file AudioResourceManager.cs.

Event Documentation

◆ SoundDisposed

EventHandler<(string Key, AudioResource Resource)>? Gondwana.Audio.AudioResourceManager.SoundDisposed

Occurs when a loaded AudioResource is disposed and removed from the manager. The event payload contains the resource key and the AudioResource instance.

Definition at line 25 of file AudioResourceManager.cs.