Phased is a small audio backend library written in Zig.
It wraps platform-specific audio APIs (CoreAudio for now) and lets you play simple tones built from layered oscillators.
It's meant as a building block for synth experiments, music tools, or just messing around with sound from code.
- Provides access to CoreAudio through a Zig-friendly interface
- Lets you define one or more oscillators (
sine,saw,square,triangle) - Plays a frequency for a duration using those oscillators
- Runs synchronously (no threads, no event loop yet)
You can add Phased as a dependency using zig fetch:
zig fetch --save git+https://github.com/Mouradif/phased#mainUpdate your build.zig to include Phased:
const phased_dep = b.dependency("phased", .{
.target = target,
.optimize = optimize,
});
const exe_mod = b.createModule(.{
// ...
.imports = &.{
.{ .name = "phased", .module = phased_dep.module("phased") },
},
});
const Phased = @import("phased");
const std = @import("std");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
var phased = Phased.init(allocator);
try phased.addOscillator(Phased.Osc.init(.{}));
try phased.connect();
try phased.play(440, 1); // Play A4 for 1 second
}
zig build
Should produce the static library at zig-out/lib/libphased.a
- Multiple voices / polyphony
- Event loop or scheduling
- Other backends (only CoreAudio works right now)
- MIDI or any real input
Mostly for fun. Partially to learn Zig’s audio and FFI capabilities. Maybe useful down the line for algorithmic music, livecoding, or small synth tools.
MIT