$ show mozilla/cubeb
cubeb is a cross-platform C library for low-latency audio playback and recording, originally developed by Mozilla for Firefox. It provides a simple callback-based API and supports a wide range of backends including ALSA, PulseAudio, WASAPI, CoreAudio, OpenSL ES, AAudio, JACK, and others. The library handles device enumeration, resampling (via vendored Speex), channel mixing, and real-time streaming. Its architecture uses a vtable pattern ('cubeb_ops') to abstract backend implementations, and includes several high-quality lock-free data structures. While primarily a production library, it includes extensive test suites and debugging tools like audio dumping. The codebase is actively maintained, with ongoing migrations of some backends to Rust, but retains legacy backends (WinMM, OSS) with limited functionality.
The LLM identified 3 files worth highlighting for reuse:
Provides a thread-safe, lock-free single-producer single-consumer (SPSC) ring buffer (lock_free_queue) and a specialized audio ring buffer (lock_free_audio_ring_buffer) that minimizes copies. The implementation uses atomic operations and a fixed-size buffer, making it suitable for real-time audio streams. It can be extracted and reused in any C++ audio project needing a high-performance, low-latency inter-thread communication channel.
Implements a wait-free triple buffer for single-producer single-consumer scenarios. It uses three slots and atomic indices to ensure producers and consumers never block, even under contention. The design is compact and can be easily extracted for any application requiring a lock-free, low-latency data exchange pattern.
A simple string interning module that stores unique strings in a hash-based table and returns integer IDs. This reduces memory usage and comparison costs for frequently repeated strings (e.g., device names). The implementation is standalone, with no internal cubeb dependencies, and can be reused in any C project needing efficient string deduplication.