Expand description
AudioMixer — sum two mono/stereo F32 input streams into a
single interleaved F32LE output (M-EXPORT.2 of M-RECORD-EXPORT).
Pure-Rust math; no GStreamer dep. Bridges the per-channel mic
crate::audio::AudioChunk callbacks + the per-channel system-
audio SCK delegate samples into one stream of audio chunks the
crate::encode::VideoEncoder::push_audio_chunk sink consumes.
§Mix strategy
Both inputs are assumed F32 interleaved at the same sample rate and channel count as the configured output (validated at construction).
Each pull() call returns the common prefix of both buffers
— min(mic_avail, sys_avail) samples — summed per-channel and
soft-clipped to [-1.0, 1.0].
When only one input is available (the other isn’t pushing), the mixer returns that input’s samples unchanged. This is the “mic-only” / “sys-audio-only” v0 mode — both channels enabled but one yet to fire.
Naive `(a + b) / 2` halves the loudness when only one source is
active. Soft-clip preserves loudness when one source is silent
and prevents distortion when both are loud — closer to what a
real mixer's bus does.Structs§
- Audio
Mixer - Two-source audio mixer. Both inputs must use the same sample rate + channel count as the configured output.
Enums§
- Mixer
Error - Failure modes for the audio mixer.
Functions§
- soft_
clip 🔒 - Soft-clip a sample to
[-1.0, 1.0]usingtanh. Smooth — no hard clip artifacts when both inputs sum past the rail.