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).
public interface IAudioSink : IDisposableImplements
Remarks
Threading rules, part of the contract:
- [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.
- Game code reaches the mixer only through a single-producer, single-consumer command queue; rendering never takes a lock shared with the main thread.
- Rendering never allocates and never touches files: sounds and music are decoded from memory already loaded, and streamed music is decoded ahead outside rendering.
- 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.
- `Dispose` returns only after the sink has stopped calling the render function.
- 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.
AudioFormat Format { get; }Property Value
LatencyFrames
Frames rendered ahead of the device (queue target plus device period): the mixer’s minimum scheduling delay.
int LatencyFrames { get; }Property Value
Schedule
Who calls the render function.
AudioSinkSchedule Schedule { get; }Property Value
Methods
Pump()
HostPump sinks render until their queue holds its target; SinkThread sinks do nothing. Main thread, once per host frame, after the steps.
void Pump()Start(AudioRender)
Starts calling render. Page-driven hosts call it inside the user gesture that starts the game.
void Start(AudioRender render)Parameters
render AudioRender