Add purpose, architecture, and public API summary to each crate README following chanora_resolver pattern. Update verification master plan with new evidence sources and entry/exit criteria.
3.5 KiB
3.5 KiB
chanora_audio
Real-time audio subsystem: capture, Opus encoding/decoding, voice rendering, PTT gating, and audio processing. Promoted from poc/audio-capture-playback-spike.
Architecture
Engine
AudioEngine— the primary type. Starts a platform audio backend (capture + playback), wires anAudioTransmitGatefor PTT gating, and feeds encoded Opus frames to the protocol layer viavoice_out. Inbound voice packets are decoded and mixed bytsclientlib::audio::AudioHandlerand pulled by the platform output callback at 48 kHz stereo.
Platform backends (cfg-gated)
| Target | Backend | Notes |
|---|---|---|
| Android | Oboe (via android_voice_unit) |
Requires ndk_context before start |
| iOS/macOS | Apple VoiceProcessingIO (ios_voice_unit) |
Platform AEC/AGC/NS, route-change handling |
| Linux | SDL (sdl_output) |
PulseAudio/ALSA via SDL |
| Other desktop | cpal | Fallback |
Key modules
audio_processing— P1 audio processing config, stats, route policy, effect ownership (Platform/Sonora/WebRTC APM)opus_voice— 20 ms / 48 kHz mono Opus encode/decode viaaudiopustransmit_mode—TransmitModeenum: Ptt, Continuous, VoiceActivitytransmit_selector—TransmitModeSelectorcombining mode, hard-mute, PTT gate, permission gate, and in-channel stateptt—AudioTransmitGate(atomic bool),PttCapabilityLevel,PttBackendDescriptorptt_backends— platform PTT backends:DesktopPttBackend(Linux portal),FocusedPttBackend(in-app fallback)release_tail—ReleaseTailTimerfor configurable PTT release delay (default 200 ms, max 500 ms)vad— Voice-activity detection: Silero ONNX (desktop), WebRTC fallback, energy debugvoice_render— mixes per-client decoded f32 PCM into the output bufferdebug_wav— optional WAV file dump for diagnostics (DIAG_002/003)mobile_voice_backend— shared mobile voice-unit lifecycle abstractionframe— frame-aligned buffer utilities
Public API Summary
Types
| Type | Role |
|---|---|
AudioEngine |
Start/stop audio, set gain/mute/volume, read stats |
AudioEngineConfig |
Capture/playback device selection, PTT initial state, processing config |
AudioDeviceInfo / AudioDeviceList |
Device enumeration |
AudioTransmitGate |
Atomic PTT gate |
TransmitMode / TransmitModeSelector |
Mode selection with hard-mute clamp |
ReleaseTailTimer |
Configurable release delay (SDD-096) |
PttBinding / PttInputClass |
PTT key binding types |
PttBackendDescriptor / PttCapabilityLevel |
Capability query |
AudioProcessingConfig / AudioProcessingStats |
P1 processing control and telemetry |
AudioRoute |
Speaker/Earpiece/Wired/Bluetooth enum |
AudioEffects |
Effect toggles (AEC/AGC/NS/HPF), all enabled by default (DEC-007..010) |
AudioError |
Typed error catalogue |
Key functions
AudioEngine::start_with_gate(cfg, voice_out, voice_in, gate)— construct and startAudioEngine::stop()— tear downlist_audio_devices()— enumerate available input/output devicesselect_ptt_backend()— choose the best PTT backend for the current platform
Platform notes
- Android requires
initChanoraContext(NDK context) before engine start. - iOS/macOS uses VoiceProcessingIO for platform AEC/AGC/NS in the default route.
- Desktop can use Silero ONNX VAD when the model file is available.
bench_seamis exposed (#[doc(hidden)]) for criterion benchmarks on non-mobile targets.