Table of Contents

Class AudioEngine

Namespace
PopcorningGuineaPig.Engine.Services
Assembly
PopcorningGuineaPig.Engine.dll

Singleton that owns the OwnAudioSharp lifecycle and the single AudioMixer. All audio playback goes through this one instance.

public sealed class AudioEngine : IDisposable
Inheritance
AudioEngine
Implements
Inherited Members

Fields

BufferFrames

Frames per mixer quantum. Matches CreateDefaultConfig().BufferSize.

public const int BufferFrames = 512

Field Value

int

Channels

public const int Channels = 2

Field Value

int

DefaultDeviceLabel

UI label for the system-default output row.

public const string DefaultDeviceLabel = "Default"

Field Value

string

SampleRate

Mixer format. Matches OwnaudioNet.CreateDefaultConfig().

public const int SampleRate = 48000

Field Value

int

Properties

Instance

public static AudioEngine Instance { get; }

Property Value

AudioEngine

IsInitialized

public bool IsInitialized { get; }

Property Value

bool

Mixer

public AudioMixer? Mixer { get; }

Property Value

AudioMixer

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

ListOutputDeviceNames()

Friendly names only — prefer ListOutputDevices() for settings UI.

public static IReadOnlyList<string> ListOutputDeviceNames()

Returns

IReadOnlyList<string>

ListOutputDevices()

Active output devices for a settings dropdown. Does not include the synthetic DefaultDeviceLabel row — callers prepend that themselves. OwnAudioSharp.Basic 4.0.8 lists these from the running engine (OwnaudioNet.GetOutputDevices), so this is empty until Instance has started. Names are full endpoint strings.

public static IReadOnlyList<AudioOutputDeviceOption> ListOutputDevices()

Returns

IReadOnlyList<AudioOutputDeviceOption>

LoadSoundEffect(string)

Loads a short clip as a fully in-memory OwnaudioNET.Sources.SampleSource.

OwnaudioNET.Sources.FileSource streams, and its Play() spins a fixed ~500-iteration sleep loop filling the decode pre-buffer before the first sample reaches the mixer. That costs ~800 ms at 1 ms timer resolution and ~7.8 s at Windows' default 15.6 ms tick — measured, not estimated — and no constructor argument tunes it away. Fine for music, which starts once and off-screen; fatal for a click or a piece landing. SampleSource has no pre-buffer: Play() returns immediately and audio lands within one mixer buffer (~10 ms).

Clips longer than PopcorningGuineaPig.Engine.Services.AudioEngine.MaxSfxDuration, and files whose duration the decoder cannot report, fall back to a streaming FileSource — late audio beats no audio.

public static IAudioSource LoadSoundEffect(string path)

Parameters

path string

Returns

IAudioSource

SetOutputDevice(string?)

Opens (or re-opens) the mixer on deviceKey. Accepts DefaultDeviceLabel, blank, a DeviceId, or a friendly Name (legacy settings). Unknown keys fall back to the system default.

public void SetOutputDevice(string? deviceKey)

Parameters

deviceKey string

Events

Reset

Fired after a new mixer is running on the selected device.

public static event Action? Reset

Event Type

Action

Resetting

Fired before the native engine is torn down to switch output devices.

public static event Action? Resetting

Event Type

Action