AudioStreamConfig
Configuration for creating an AudioStream via AudioEngine.openStream.
All properties have sensible defaults, so you only need to specify the ones you want to override. Unspecified values will be resolved by the platform.
Example
// Stereo output stream at 48 kHz with low latency
val config = AudioStreamConfig(
sampleRate = 48000,
channelCount = 2,
performanceMode = PerformanceMode.LOW_LATENCY,
)
// Mono input stream for recording
val micConfig = AudioStreamConfig(
direction = StreamDirection.INPUT,
channelCount = 1,
)Platform Behavior
Android: The platform may adjust the requested sampleRate and bufferCapacityInFrames to match the device's native values when sharingMode is SharingMode.SHARED.
Apple: Core Audio will perform sample-rate conversion automatically if the requested rate differs from the hardware rate.
Constructors
Properties
Sample format used for the audio data buffer. AudioStreamCallback.onAudioReady always receives AudioFormat.PCM_FLOAT samples. On Android, any other value throws UnsupportedFormatException. Default: AudioFormat.PCM_FLOAT.
Total buffer capacity in frames. A value of 0 lets the platform choose an optimal size. Larger values increase latency but reduce the risk of underruns. Must be non-negative. Default: 0 (platform default).
Number of audio channels. 1 = mono, 2 = stereo. Values above 2 are supported only if the hardware allows it. Must be a positive integer. Default: 1.
Optional platform device id from AudioDeviceInfo.id. null (the default) uses the platform's default device for direction. A value that does not match a currently available device causes DeviceNotFoundException when the stream is opened.
Whether this is a playback (StreamDirection.OUTPUT) or recording (StreamDirection.INPUT) stream. This determines whether AudioStream.write or AudioStream.read should be used, and which callback path is taken in AudioStreamCallback.onAudioReady. Default: StreamDirection.OUTPUT.
Performance vs. power trade-off hint. PerformanceMode.LOW_LATENCY minimizes latency at the expense of power, while PerformanceMode.POWER_SAVING does the opposite. Default: PerformanceMode.LOW_LATENCY.
Sample rate in Hz. Common values: 44100, 48000. Must be a positive integer. A value of 0 lets the platform choose. Default: 48000.
Whether this stream should share the audio device with other applications. SharingMode.EXCLUSIVE may provide lower latency but can fail if another app already holds the device. Default: SharingMode.SHARED.