AudioService Class

SDL3_mixer implementation of audio service with spatial audio support and proper callbacks.

internal sealed class AudioService : Brine2D.Audio.IAudioService, Brine2D.Audio.ISoundLoader, System.IDisposable, Brine2D.Audio.IMusicLoader, Brine2D.Audio.IAudioPlayer

Inheritance System.Object → AudioService

Implements IAudioService, ISoundLoader, System.IDisposable, IMusicLoader, IAudioPlayer

Properties
ActiveSoundTrackCount Gets the number of currently active sound-effect tracks (excludes music).
MasterVolume Gets or sets the master volume (0.0 to 1.0).
MaxSoundTracks Gets the maximum number of concurrent sound-effect tracks.
MusicDurationMs Gets the total duration of the currently loaded music in milliseconds, or -1 if no music is playing or the duration is unknown (e.g. streaming sources).
MusicPositionMs Gets the current music playback position in milliseconds, or -1 if no music is playing. Paused tracks report the position at which they were paused.
MusicVolume Gets or sets the music volume (0.0 to 1.0).
SoundVolume Gets or sets the sound effects volume (0.0 to 1.0).
Methods
CrossfadeMusic(IMusic, float, int, long, string) Crossfades from the currently playing music to music over duration seconds. If no music is playing or duration is \<= 0, behaves identically to PlayMusic(IMusic, int, long, string). Call Update(float) each frame to advance the fade.
GetBusVolume(string) Gets the current volume multiplier for the given bus, or 1.0 if the bus volume has not been explicitly set via SetBusVolume(string, float).
IsBusPaused(string) Returns whether the given bus is currently paused via PauseBus(string).
LoadMusicAsync(string, CancellationToken) Loads music from a file.
LoadSoundAsync(string, CancellationToken) Loads a sound effect from a file.
PauseAllSounds() Pauses all currently playing sound-effect tracks. Music is not affected. Paused tracks remain alive and can be resumed with ResumeAllSounds().
PauseBus(string) Pauses all tracks tagged with bus. Paused tracks remain alive and can be resumed with ResumeBus(string).
PauseMusic() Pauses the currently playing music.
PlayMusic(IMusic, int, long, string) Plays background music.
PlaySound(ISoundEffect, float, int, float, float, int, string) Plays a sound effect and returns the track handle for lifecycle tracking.
ResumeAllSounds() Resumes all paused sound-effect tracks. Music is not affected.
ResumeBus(string) Resumes all tracks tagged with bus.
ResumeMusic() Resumes paused music.
SeekMusic(double) Seeks the currently playing music to positionMs milliseconds. Does nothing if no music is playing.
SetBusVolume(string, float) Sets the volume multiplier for all tracks tagged with bus. This is an additional multiplier on top of per-track gain and SoundVolume/MusicVolume.
SetMusicPitch(float) Sets the playback speed (pitch) of the current music track. Does nothing if no music is playing.
SetMusicTrackVolume(float) Sets the per-track volume multiplier for the current music track. The final music gain is MusicVolume × volume. Does nothing during a crossfade (the crossfade drives gains directly).
StopBus(string, float) Stops all tracks tagged with bus with optional fade-out.
StopMusic(float) Stops the currently playing music. When fadeDuration is greater than zero the music fades out over that many seconds; call Update(float) each frame to advance the fade.
StopNonMusicTracksOnBus(string) Stops non-music tracks on a bus individually. Used by StopBus(string, float) when a managed music fade is active to avoid StopTag cancelling the fade.
UnloadMusic(IMusic) Unloads music and frees its resources. Implementations must be idempotent — calling this twice with the same instance must not throw or cause a double-free of native resources.
UnloadSound(ISoundEffect) Unloads a sound effect and frees its resources. Implementations must be idempotent — calling this twice with the same instance must not throw or cause a double-free of native resources.
Update(float) Per-frame update that processes deferred track cleanup and advances any in-progress music crossfade. Call once per frame with the frame delta time.