Skip to content

PlatformAPI reference

Interface IAudioSink

Namespace: MicroEngine.Platform
Assembly: MicroEngine.Platform.dll
Guide: The platform host

A PCM audio output, version 1 of the contract: the engine’s one mixer renders, the sink plays. The sink chooses the thread that renders (Schedule).

C#
public interface IAudioSink : IDisposable

Implements

IDisposable

Remarks

Threading rules, part of the contract:

  1. [AudioRender](/docs/api/microengine.platform.audiorender/) runs on exactly one thread at a time, the sink's choice (its own thread, the browser's main thread, a test thread); the mixer is written once, thread-agnostic.
  2. Game code reaches the mixer only through a single-producer, single-consumer command queue; rendering never takes a lock shared with the main thread.
  3. Rendering never allocates and never touches files: sounds and music are decoded from memory already loaded, and streamed music is decoded ahead outside rendering.
  4. The host calls [Pump](/docs/api/microengine.platform.iaudiosink/#MicroEngine_Platform_IAudioSink_Pump) once per frame after the simulation steps, on every host; it costs nothing on [SinkThread](/docs/api/microengine.platform.audiosinkschedule/) sinks, so the loop does not branch on the platform.
  5. `Dispose` returns only after the sink has stopped calling the render function.
  6. Page-driven hosts start the sink inside the user gesture that starts the game, and suspend audio while the page is hidden.

Determinism rule for the engine mixer: a sound starts at an exact output frame, its simulation step plus a fixed delay of at least [LatencyFrames](/docs/api/microengine.platform.iaudiosink/#MicroEngine_Platform_IAudioSink_LatencyFrames), so the output does not depend on the block sizes a sink asks for.

Properties

Format

The format the sink plays.

C#
AudioFormat Format { get; }

Property Value

AudioFormat

LatencyFrames

Frames rendered ahead of the device (queue target plus device period): the mixer’s minimum scheduling delay.

C#
int LatencyFrames { get; }

Property Value

int

Schedule

Who calls the render function.

C#
AudioSinkSchedule Schedule { get; }

Property Value

AudioSinkSchedule

Methods

Pump()

HostPump sinks render until their queue holds its target; SinkThread sinks do nothing. Main thread, once per host frame, after the steps.

C#
void Pump()

Start(AudioRender)

Starts calling render. Page-driven hosts call it inside the user gesture that starts the game.

C#
void Start(AudioRender render)

Parameters

render AudioRender