Repository navigation
2 Audio Engine Deep Dive
Your Name edited this page Aug 26, 2026
·
1 revision
Tincan's audio engine (src/audio/) is built for sub-30ms real-time voice communications over lossy networks.
[ Microphone ]
│ (cpal capture callback)
▼
[ Lock-Free Ring Buffer (rtrb) ]
│ (audio processing thread)
▼
[ Voice Activity Detector (VAD) ]
│ (speech detected)
▼
[ Opus Encoder (audiopus) ]
│ (encoded frames)
▼
[ QUIC Datagram Network Mesh ]
│ (incoming UDP packets)
▼
[ Adaptive Jitter Buffer ]
│ (reordered & PLC concealed)
▼
[ Opus Decoder ]
│ (PCM frames)
▼
[ Multi-Source Mixer & Limiter ]
│ (cpal playback callback)
▼
[ Speakers ]
- Uses
cpalto interface with native system sound servers: CoreAudio (macOS), ALSA / PulseAudio / PipeWire (Linux), WASAPI (Windows). - Enforces native 48000 Hz sample rate and 20ms frame lengths (960 samples per frame).
- Audio hardware callbacks run in high-priority real-time threads.
- Real-time threads must never block, lock mutexes, allocate memory, or perform I/O.
- Tincan uses lock-free Single-Producer Single-Consumer (SPSC) ring buffers (
rtrb) to bridge audio callbacks with network worker threads.
- Encodes 16-bit PCM mono audio into 48 kHz Opus frames (typically 40–80 bytes per packet).
- Features built-in Packet Loss Concealment (PLC). When network packets drop, the decoder interpolates missing audio frames based on linear predictive coding.
- Calculates frame Root Mean Square (RMS) energy against background noise floors.
- Enables Discontinuous Transmission (DTX): suppresses packet generation during silence, cutting upload bandwidth to zero when not speaking.
- Smooths out packet arrival jitter caused by Wi-Fi or internet routing variance.
- Reorders out-of-order sequence numbers and dynamically adjusts buffer depth to minimize latency while preventing dropouts.
- Sums PCM samples from all active speakers in a channel.
- Employs a soft limiter to prevent digital clipping when multiple peers talk simultaneously.