A small command-line metronome for Linux that I wrote for my drumming practice.
It utilizes the ALSA (Advanced Linux Sound Architecture) API for audio playback and Unix timers for interval management.
- Direct ALSA PCM interface for low-latency audio.
- Precise timing using
SIGALRMandsetitimer. - Support for custom BPM and time signatures.
- Minimalist implementation with a custom WAV parser and allocator wrapper.
- Zig 0.15.2 or later.
- ALSA development headers (e.g.,
libasound2-devon Ubuntu/Debian oralsa-libon Arch Linux).
To build the project using the Zig build system, run:
zig build -Doptimize=ReleaseSmallThe executable will be located at zig-out/bin/metronome.
Alternatively, a Makefile is provided for convenience. The default target builds and runs the
application in Debug mode. Available commands:
make # Build and run (default: OPTIMIZE=Debug)
make debug # Build for debugging
make release # Build for ReleaseSmall
make clean # Remove build artifactsThe application provides an interactive command-line interface. The following commands are available:
<num>: Set the tempo in Beats Per Minute (BPM). Example:120./sig <num>: Set the time signature (beats per measure). Example:/sig 4.q: Terminate the application.
- Audio: The engine opens the default ALSA PCM device and writes 16-bit signed little-endian (S16_LE) samples.
- Timing: Intervals are managed by the Linux kernel via
setitimer(ITIMER_REAL), which triggersSIGALRMat calculated intervals based on the BPM. - Memory: A custom allocator wrapper switches between
std.heap.DebugAllocatorin debug builds andstd.heap.c_allocatorin release builds for optimal performance.