onAudioReady

open fun onAudioReady(buffer: FloatArray, numFrames: Int): Int

Called when the audio stream needs data (output) or has data available (input).

For output streams, fill buffer with numFrames frames of audio data. Samples are interleaved by channel (e.g., [L0, R0, L1, R1, ...] for stereo).

For input streams, buffer already contains numFrames frames of captured audio data for the application to consume.

Threading: on Android, Apple, JVM, and native desktop this is a worker thread (not the platform audio callback). On JS this is the browser main thread, not the AudioWorklet render quantum. Slow work still underruns.

Return

The number of frames actually processed. Return numFrames for normal operation. Returning fewer frames than requested for an output stream will result in silence for the remaining frames.

Parameters

buffer

The audio buffer to read from (input) or write to (output). The array length is at least numFrames * channelCount.

numFrames

The number of frames requested (output) or available (input).