Skip to content

zig-gamedev/zaudio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zig build package and wrapper for miniaudio v0.11.21

As an example program please see audio experiments (wgpu).

Features

Provided structs:

  • Device
  • Engine
  • Sound
  • SoundGroup
  • NodeGraph
  • Fence
  • Context (missing methods)
  • ResourceManager (missing methods)
  • Log (missing methods)
  • DataSource (missing methods)
    • Waveform
    • Noise
    • custom data sources
  • Node
    • DataSourceNode
    • SplitterNode
    • BiquadNode
    • LpfNode // Low-Pass Filter
    • HpfNode // High-Pass Filter
    • NotchNode
    • PeakNode
    • LoshelfNode // Low Shelf Filter
    • HishelfNode // High Shelf Filter
    • DelayNode
    • custom nodes

Getting started

In your build.zig add:

pub fn build(b: *std.Build) void {
    const exe = b.addExecutable(.{ ... });

    const zaudio = b.dependency("zaudio", .{});
    exe.root_module.addImport("zaudio", zaudio.module("root"));
    exe.linkLibrary(zaudio.artifact("miniaudio"));
}

Now in your code you may import and use zaudio:

const zaudio = @import("zaudio");

pub fn main() !void {
    ...
    zaudio.init(allocator);
    defer zaudio.deinit();

    const engine = try zaudio.Engine.create(null);
    defer engine.destroy();

    const music = try engine.createSoundFromFile(
        content_dir ++ "Broke For Free - Night Owl.mp3",
        .{ .flags = .{ .stream = true } },
    );
    defer music.destroy();
    try music.start();
    ...
}