Skip to content

Format Conversion, Layouts & TPDF Dither

Native OS endpoints typically stream at 48 kHz or 44.1 kHz stereo float32 (or packed 24-in-32 PCM), whereas speech-to-text models (faster-whisper, openai-whisper), VADs (Silero, WebRTC), and Realtime Voice AI SDKs require 16 kHz mono float32/int16 or 24 kHz int16.

OutputConverter performs resampling, channel downmix/upmix, endianness conversion, and integer quantization inside the safe-Rust pipeline with zero steady-state heap allocations.


Downstream Consumer Recommended OutputConverter Settings Frame Stride
faster-whisper / openai-whisper / Silero VAD rate=16000, channels=1, sample_format=F32 4 B / frame
WebRTC VAD / SpeechRecognition / Picovoice rate=16000, channels=1, sample_format=I16, dither=TPDF 2 B / frame
OpenAI Realtime / LiveKit Voice Agents rate=24000, channels=1, sample_format=I16, dither=TPDF 2 B / frame
Discord Bots / Broadcast / WAV Mastering rate=48000, channels=2, sample_format=I16 or I24 or F32 4–8 B / frame

Supported SampleTypes:

  • F32 (32-bit IEEE 754 float, nominal [-1.0, +1.0])
  • I16 (16-bit signed PCM)
  • I24 (packed 3-byte 24-bit signed PCM; PcmBlock.to_numpy(unpack_i24=True) sign-extends to int32 in Python when needed!)
  • I32 (32-bit signed PCM)

2. Canonical Speaker Layouts & Early Validation

Section titled “2. Canonical Speaker Layouts & Early Validation”

OutputConverter validates channel layouts during request.inspect() before opening any OS audio device:

  • 1 channel: [Channel::Mono]
  • 2 channels: [Channel::FrontLeft, Channel::FrontRight]
  • 4 / 6 channels: Validated Layout::Known speaker masks (Identity pass-through when matching native multichannel endpoints; incompatible multichannel downmixes reject early at inspect() with PlanError::UnsupportedCapturePlan).

3. Stateless SplitMix64 TPDF Dither vs None

Section titled “3. Stateless SplitMix64 TPDF Dither vs None”

Quantizing 32-bit floating-point audio directly to I16 or I24 by truncation introduces correlated harmonic distortion on quiet decays.

  • DitherMode::Tpdf (Default for integer outputs): Applies stateless, deterministic SplitMix64 Triangular Probability Density Function (TPDF) dither prior to integer rounding, linearizing quantization noise with zero state drift.
  • DitherMode::None: Disables dithering for bit-exact zero-silence integer tests.

4. Mid-Stream Native Format Changes (OnFormatChange)

Section titled “4. Mid-Stream Native Format Changes (OnFormatChange)”

What happens if a user changes their Windows speaker sample rate from 48 kHz to 96 kHz in Control Panel, or Follow mode switches from 48 kHz speakers to a 44.1 kHz Bluetooth headset?

  • OnFormatChange::Adapt (Default): When OutputConverter is configured, CaptureManager transparently updates the input resampler ratio so your downstream consumer continues receiving uninterrupted 16 kHz (or 48 kHz) frames! Without OutputConverter, it emits BoundaryKind::FormatChanged so callers see the new Format.
  • OnFormatChange::Fail: Immediately terminates the read with a typed format-change error (CSPA_STATUS_FORMAT_CHANGED / CapabilityError::FormatChangeRejected) for pipelines that forbid mid-session sample-rate transitions.
import capture_system_or_process_audio as cspa
conv = cspa.OutputConverter(
rate=16000,
channels=1,
sample_format=cspa.SampleType.I16,
dither=cspa.DitherMode.TPDF,
)
req = cspa.request(
cspa.default_output(),
output_converter=conv,
on_format_change=cspa.OnFormatChange.ADAPT,
silence_on_idle=True,
)
plan = req.inspect()
print("Uses OutputConverter:", plan.uses_output_converter)

Continue to Real-Time Safety, Zero-Alloc Reads & Lifecycle.