Gondwana Game Engine
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, mobile, and web platforms using SkiaSharp for graphics and NAudio for sound.
Loading...
Searching...
No Matches
Gondwana.Audio.AudioResourceManager Class Referencesealed

Manages the lifecycle of audio resources, providing loading, retrieval, cloning, and disposal functionality. More...

Inheritance diagram for Gondwana.Audio.AudioResourceManager:

Public Member Functions

AudioResource LoadFromFile (string key, string filePath, float volume=1.0f, float pan=0.0f)
 Loads an audio resource from a file on disk.
AudioResource LoadFromStream (string key, Stream input, string fileExt, float volume=1.0f, float pan=0.0f)
 Loads an audio resource from a stream.
List< AudioResourceLoadFromEngineResourceFile (AssetsFile resourceFile, float defaultVolume=1.0f, float defaultPan=0.0f)
 Loads all audio resources from an AssetsFile.
AudioResourceClone (string key, string? newKey=null, float? volume=null, float? pan=null)
 Creates a copy of an existing audio resource with a new key and optionally different settings.
void Unload (string key)
 Unloads a sound resource by its key, disposing of it and removing it from the manager.
void Clear ()
 Clears all sound resources, disposing of each one.
bool TryGet (string key, out AudioResource? resource)
 Attempts to retrieve an audio resource by its key.
AudioResourceGet (string key)
 Retrieves an audio resource by its key.
bool Contains (string key)
 Determines whether the manager contains an audio resource with the specified key.
IEnumerable< string > GetAllKeys ()
 Gets all keys of audio resources currently managed by this instance.
Dictionary< string, AudioResourceGetAll ()
 Gets all audio resources currently managed by this instance as a dictionary.
void Dispose ()
 Releases all resources used by the AudioResourceManager.

Properties

static AudioResourceManager Instance [get]
 Singleton instance of the AudioResourceManager.

Events

EventHandler<(string Key, AudioResource Resource)>? SoundDisposed
 Event that is raised when a sound resource is disposed.

Detailed Description

Manages the lifecycle of audio resources, providing loading, retrieval, cloning, and disposal functionality.

This class implements the singleton pattern to ensure a single instance manages all audio resources throughout the application. It supports loading audio from files, streams, and asset files, and tracks all loaded resources in a thread-safe manner.

Member Function Documentation

◆ Clear()

void Gondwana.Audio.AudioResourceManager.Clear ( )

Clears all sound resources, disposing of each one.

◆ Clone()

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

Creates a copy of an existing audio resource with a new key and optionally different settings.

Cloning requires the original resource to have its raw byte data available. If the new key already exists or the original resource cannot be found, the method returns null.

Parameters
keyThe key of the existing audio resource to clone.
newKeyThe key for the cloned resource. If null, a unique key will be generated automatically.
volumeThe volume level for the cloned resource. If null, uses the original resource's volume.
panThe stereo pan position for the cloned resource. If null, uses the original resource's pan.
Returns
The cloned AudioResource if successful; otherwise, null.

◆ Contains()

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

Determines whether the manager contains an audio resource with the specified key.

Parameters
keyThe key to check for existence.
Returns
true if the manager contains an audio resource with the specified key; otherwise, false.

◆ Dispose()

void Gondwana.Audio.AudioResourceManager.Dispose ( )

Releases all resources used by the AudioResourceManager.

This method clears all managed audio resources, disposing of each one. After disposal, the manager should not be used further.

◆ Get()

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

Retrieves an audio resource by its key.

Parameters
keyThe unique identifier of the audio resource to retrieve.
Returns
The AudioResource associated with the specified key if found; otherwise, null.

◆ GetAll()

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

Gets all audio resources currently managed by this instance as a dictionary.

Returns
A dictionary containing all audio resources, keyed by their unique identifiers.

◆ GetAllKeys()

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

Gets all keys of audio resources currently managed by this instance.

Returns
An enumerable collection of all resource keys.

◆ LoadFromEngineResourceFile()

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

Loads all audio resources from an AssetsFile.

This method iterates through all audio entries in the asset file and loads them into the manager. Resources that are already loaded will be skipped. Failed loads are logged but do not prevent other resources from being loaded.

Parameters
resourceFileThe AssetsFile containing audio resources.
defaultVolumeThe default volume level for all loaded audio resources, ranging from 0.0 to 1.0. Defaults to 1.0.
defaultPanThe default stereo pan position for all loaded audio resources, ranging from -1.0 to 1.0. Defaults to 0.0.
Returns
A list of successfully loaded AudioResource instances.

◆ LoadFromFile()

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

Loads an audio resource from a file on disk.

If a resource with the same key already exists, it will be disposed and replaced with the new resource. The audio file format is determined by the file extension.

Parameters
keyA unique identifier for the audio resource.
filePathThe path to the audio file on disk.
volumeThe initial volume level for the audio resource, ranging from 0.0 (silent) to 1.0 (full volume). Defaults to 1.0.
panThe initial stereo pan position, ranging from -1.0 (full left) to 1.0 (full right). Defaults to 0.0 (center).
Returns
The loaded AudioResource instance.

◆ LoadFromStream()

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

Loads an audio resource from a stream.

If a resource with the same key already exists, it will be disposed and replaced with the new resource. The audio format is determined by the specified file extension.

Parameters
keyA unique identifier for the audio resource.
inputThe stream containing the audio data.
fileExtThe file extension indicating the audio format (e.g., ".wav", ".mp3").
volumeThe initial volume level for the audio resource, ranging from 0.0 (silent) to 1.0 (full volume). Defaults to 1.0.
panThe initial stereo pan position, ranging from -1.0 (full left) to 1.0 (full right). Defaults to 0.0 (center).
Returns
The loaded AudioResource instance.

◆ TryGet()

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

Attempts to retrieve an audio resource by its key.

Parameters
keyThe unique identifier of the audio resource to retrieve.
resourceWhen this method returns, contains the AudioResource associated with the specified key, if the key is found; otherwise, null.
Returns
true if the audio resource was found; otherwise, false.

◆ Unload()

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

Unloads a sound resource by its key, disposing of it and removing it from the manager.

Parameters
keyUnique identifier for AudioResource.

Property Documentation

◆ Instance

AudioResourceManager Gondwana.Audio.AudioResourceManager.Instance
staticget

Singleton instance of the AudioResourceManager.

Event Documentation

◆ SoundDisposed

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

Event that is raised when a sound resource is disposed.