summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--build.zig32
-rw-r--r--src/al.zig16
-rw-r--r--src/zeal.zig3
3 files changed, 31 insertions, 20 deletions
diff --git a/build.zig b/build.zig
index 67f6993..aa7fbff 100644
--- a/build.zig
+++ b/build.zig
@@ -18,12 +18,20 @@
 
 const std = @import("std");
 const Build = std.Build;
+const Compile = Build.Step.Compile;
 const CrossTarget = std.zig.CrossTarget;
-const LibExeObjStep = std.build.LibExeObjStep;
+const Module = Build.Module;
 const OptimizeMode = std.builtin.OptimizeMode;
 
+/// Link given library, executable, or object with shared libraries.
+pub fn link(compile: *Compile) void {
+    compile.linkSystemLibrary("openal");
+    compile.linkSystemLibrary("sndfile");
+    compile.linkSystemLibrary("c");
+}
+
 fn addExampleStep(comptime name: []const u8, description: []const u8,
-                  b: *Build, lib: *LibExeObjStep,
+                  b: *Build, module: *Module,
                   target: CrossTarget, optimize: OptimizeMode) void {
     const bin = b.addExecutable(.{
         .name = name,
@@ -31,23 +39,16 @@ fn addExampleStep(comptime name: []const u8, description: []const u8,
         .target = target,
         .optimize = optimize,
     });
-    bin.addPackagePath("zeal", "src/zeal.zig");
-    bin.linkLibrary(lib);
+    bin.addModule("zeal", module);
+    link(bin);
 
-    const cmd = bin.run();
+    const cmd = b.addRunArtifact(bin);
     cmd.step.dependOn(b.getInstallStep());
     if (b.args) |args|
         cmd.addArgs(args);
     b.step(name, description).dependOn(&cmd.step);
 }
 
-/// Link given library, executable, or object with shared libraries.
-pub fn link(lib_exe_obj: *LibExeObjStep) void {
-    lib_exe_obj.linkSystemLibrary("openal");
-    lib_exe_obj.linkSystemLibrary("sndfile");
-    lib_exe_obj.linkSystemLibrary("c");
-}
-
 pub fn build(b: *Build) void {
     const target = b.standardTargetOptions(.{});
     const optimize = b.standardOptimizeOption(.{});
@@ -67,6 +68,9 @@ pub fn build(b: *Build) void {
     main_tests.linkLibrary(lib);
     b.step("test", "Run library tests").dependOn(&main_tests.step);
 
-    //addExampleStep("play", "Play audio", b, lib, target, optimize);
-    //addExampleStep("hrtf", "Play audio with HRTF", b, lib, target, optimize);
+    const module = b.createModule(.{
+        .source_file = .{ .path = "src/zeal.zig" },
+    });
+    addExampleStep("play", "Play audio", b, module, target, optimize);
+    addExampleStep("hrtf", "Play audio with HRTF", b, module, target, optimize);
 }
diff --git a/src/al.zig b/src/al.zig
index ccabc7e..1eea14e 100644
--- a/src/al.zig
+++ b/src/al.zig
@@ -116,15 +116,21 @@ pub const buffer = struct {
 
     /// Fill a buffer with audio data.
     pub fn fill(reference: u32, data: Data, freq: i32) Error!void {
-        c.alBufferData(reference, switch (data) {
+        const format = switch (data) {
             .mono8 => c.AL_FORMAT_MONO8,
             .mono16 => c.AL_FORMAT_MONO16,
             .stereo8 => c.AL_FORMAT_STEREO8,
             .stereo16 => c.AL_FORMAT_STEREO16,
-        }, switch (data) { else => |slice| slice.ptr }, switch (data) {
-            .mono8, .stereo8 => |slice| @intCast(slice.len),
-            .mono16, .stereo16 => |slice| @intCast(slice.len * 2),
-        }, freq);
+        };
+
+        switch (data) {
+            .mono8, .stereo8 => |slice|
+                c.alBufferData(reference, format,
+                               slice.ptr, @intCast(slice.len), freq),
+            .mono16, .stereo16 => |slice|
+                c.alBufferData(reference, format,
+                               slice.ptr, @intCast(slice.len * 2), freq),
+        }
 
         switch (c.alGetError()) {
             c.AL_NO_ERROR => {},
diff --git a/src/zeal.zig b/src/zeal.zig
index 3be59fb..cf88b11 100644
--- a/src/zeal.zig
+++ b/src/zeal.zig
@@ -201,7 +201,8 @@ pub const Source = struct {
     }
 
     pub fn bind(self: Source, buffer: Buffer) Error!void {
-        try al.source.set(self.reference, .buffer, @intCast(buffer.reference));
+        const reference: i32 = @intCast(buffer.reference);
+        try al.source.set(self.reference, .buffer, reference);
     }
 
     /// Specify if the source always has 3D spatialization features (true),