How daft-engineers/vocoder works
Project type and purpose
• It captures voice + synth inputs, applies filtering/envelope-follower + modulation, mixes and outputs audio in real time.
File structure
• Top-level build/config: CMakeLists.txt, setup.sh, checks.sh, .github/workflows (CI), Doxyfile.
• /: public headers for each DSP block (amp.hh, filter.hh, rms.hh, mixer.hh, pipe.hh, scheduler_helper.hh, callbacks.hh, audio.hh, alsa_out.hh).
• src/: implementation of main.cc, DSP modules, ALSA I/O.
• unit_tests/: Python linker helper + GoogleTest suites for every DSP block.
README for additional insights
• Hardware: Raspberry Pi + Codec Zero (ALSA device).
• Software stack: C++11, CMake, ALSA, GoogleTest, clang-tidy/format, doxygen/graphviz.
Main components & data flows
a. Hardware Layer
– Codec Zero analog I/O (mic + synth inputs, headphone/speaker out)
– ALSA kernel driver
b. Audio I/O Layer
– include/alsa_out.hh & src/alsa_out.cc
– audio.hh: defines AudioBuffer, sample formats, device selection
c. Scheduler & Callbacks
– scheduler_helper.hh & callbacks.hh
– Drive the real-time audio loop: register input/output callbacks with ALSA
d. DSP Processing Pipeline
1. pipe.hh: lock-free FIFO buffers for inter-module data passing
2. filter.cc / filter.hh: bank of IIR filters (via Bernd Porr’s iir1)
3. rms.cc / rms.hh: envelope follower to compute RMS of voice
4. amp.cc / amp.hh: apply gain/envelope modulation to synth
5. mixer.cc / mixer.hh: mix modulated synth + original voice (if desired)
e. Application Entry Point
– src/main.cc: parse CLI args (-i, ‑o, ‑g), assemble modules, start scheduler
f. Build/Test/CI
– CMake + Python script to link tests
– checks.sh: clang-tidy/clang-format
– .github/workflows: build, static analysis, unit tests, nightly threaded tests, doxygen deploy
Architectural patterns & principles
• Modular DSP blocks with single responsibility (filter, rms, amp, mixer)
• Callback-driven scheduling for real-time processing
• Lock-free circular buffers (pipe.hh) to decouple I/O from DSP
• Clear separation: I/O vs. scheduling vs. DSP vs. CLI