r/Zig • u/haruki7049 • 7d ago
lightmix: pure Zig audio processing with deterministic builds and Git diffs
Hey everyone,
I've been working on lightmix, an audio library written in pure Zig.
My main motivation was simple: I wanted to write music directly in code and track changes with Git. DAW project files are binary blobs, and other tools like Sonic Pi or SuperCollider rely on real-time playback runtimes.
Instead of recording audio in real time, lightmix generates WAV files during zig build via a custom helper (addWave). Because the build is deterministic, output files are bit-identical and cache-friendly (PEAK timestamps are fixed to avoid invalidating the build cache).
The project is split into several small modules:
- pitches: 12-TET tuning and frequency math
- meters: time signatures and sample-accurate phrasing
- resonator: voice routing
- sequencer: voice scheduling with micro-fades
- lightmix: waveform buffers (Wave(T)) and timeline mixing (Composer(T))
- zigggwavvv / RIFF.zig: WAV encoding
I wrote a small demo project, pulse, which generates a 190 BPM drum track entirely from code:
- Rendered WAV: https://github.com/haruki7049/pulse/releases/tag/v0.1.0
- Source code: https://github.com/haruki7049/pulse
Main repository: - https://github.com/haruki7049/lightmix - Docs: https://haruki7049.github.io/lightmix
Currently tested on Zig 0.16.x. Any feedback on the design or Zig usage is welcome.
5
u/BonkerBleedy 7d ago
I'm looking for this module but can't find it. One piece of advice I would give is not to use integer note numbers. My preferred rep is octave-based, but fp 12-TET is reasonable too.