Skip to content

PlatformAPI reference

Class SdlAudioDevice

Namespace: MicroEngine.Sdl
Assembly: MicroEngine.Sdl.dll
Guide: Backends and platforms

SDL3 audio: the engine’s mixer (MixerAudioDevice, the same voices, priorities and music on every backend) playing through SDL’s default playback device. A feeder thread keeps DefaultLatencyMilliseconds of audio queued in an SDL audio stream (48 kHz stereo float), so main-thread stalls and garbage collections shorter than that are not heard. It works without a window, so a host can use it with another platform. In a browser SDL’s own audio is not used: the mixer plays through the page’s AudioWorklet queue, filled once per frame (BrowserAudioSink).

C#
public sealed class SdlAudioDevice : MixerAudioDevice, IAudioDevice, IDisposable

Inheritance

object ← MixerAudioDevice ← SdlAudioDevice

Implements

IAudioDevice, IDisposable

Inherited Members

MixerAudioDevice.LoadSound(string, AudioClip), MixerAudioDevice.LoadMusic(string, AudioClip, bool), MixerAudioDevice.LoadMusicStream(string, byte[], string, bool), MixerAudioDevice.Play(SoundHandle, float, float, float), MixerAudioDevice.PlayMusic(MusicHandle, float), MixerAudioDevice.StopMusic(), MixerAudioDevice.SetMusicVolume(float), MixerAudioDevice.PauseMusic(bool), MixerAudioDevice.Update(), MixerAudioDevice.Pump(), MixerAudioDevice.Dispose(), MixerAudioDevice.Engine, MixerAudioDevice.IsAvailable, MixerAudioDevice.MusicFormats, MixerAudioDevice.CurrentMusic, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Fields

DefaultLatencyMilliseconds

Audio kept queued by default, in milliseconds: longer than the longest collection measured on desktop.

C#
public const double DefaultLatencyMilliseconds = 60

Field Value

double

Methods

TryCreate()

Opens the default playback device, or returns a silent device (and says why) when there is none.

C#
public static IAudioDevice TryCreate()

Returns

IAudioDevice

TryCreate(ILog)

Opens the default playback device, or returns a silent device and writes why to log when there is none.

C#
public static IAudioDevice TryCreate(ILog log)

Parameters

log ILog

Returns

IAudioDevice

TryCreate(string)

Opens the default playback device of SDL’s audio driver driver: “dummy” runs SDL’s whole audio path without any device or sound, for tests; “disk” writes the mixed output to a file (SDL’s SDL_AUDIO_DISK_OUTPUT_FILE hint). Returns a silent device (and says why) when the driver is unavailable or SDL’s audio was already started with another driver.

C#
public static IAudioDevice TryCreate(string driver)

Parameters

driver string

Returns

IAudioDevice

TryCreate(string?, double)

Opens the default playback device (of driver, or SDL’s choice when null) keeping latencyMilliseconds of audio queued: lower plays sounds sooner, higher survives longer pauses.

C#
public static IAudioDevice TryCreate(string? driver, double latencyMilliseconds)

Parameters

driver string?

latencyMilliseconds double

Returns

IAudioDevice

Exceptions

ArgumentOutOfRangeException

latencyMilliseconds is not between 5 and 1000.