AudioTrackSink

The Android audio output: one AudioTrack in MODE_STREAM behind the engine's pull contract.

AudioTrack is a push API while the engine and KotlinAudioRing expose a pull callback that owns the audio clock anchor. The adaptation is the one wrapper the AudioSink KDoc names for push platforms: a dedicated priority-audio writer thread turns "the device has room" into a pull. Each loop iteration computes the deadline of the LAST frame of the requested block, invokes the engine's AudioRenderCallback into a preallocated buffer, silences any tail a short return leaves (nothing above the sink zeroes it, per the callback contract), and loops write(..., WRITE_BLOCKING) until the block is fully submitted or a lifecycle signal lands.

The sink accepts mono or stereo only and never converts: mixing and resampling remain in the engine, where their latency is known and where they are testable in commonMain.

The internal constructor takes the driver factory and the clock so the host suite drives every lifecycle and arithmetic arm with a fake, and so production cannot accidentally pair AudioTimestamp (System.nanoTime CLOCK_MONOTONIC base) with another time base: the public constructor hard-wires AndroidMonotonicClock.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
Link copied to clipboard
open override val deviceBufferFrames: Int
Link copied to clipboard
open override val events: Flow<AudioSinkEvent>
Link copied to clipboard
open override val latencyQuality: LatencyQuality
Link copied to clipboard
open override val platformSessionId: Int?

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open suspend override fun drain()
Link copied to clipboard
open override fun latencyNanos(): Long
Link copied to clipboard
open suspend override fun open(request: AudioFormat, render: AudioRenderCallback): AudioFormat
Link copied to clipboard
open override fun setContent(content: AudioContent)
Link copied to clipboard
open suspend override fun setPaused(paused: Boolean): Boolean
Link copied to clipboard
open suspend override fun start()
Link copied to clipboard
open suspend override fun stop()