about summary refs log tree commit diff
path: root/src/zeal.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/zeal.zig')
-rw-r--r--src/zeal.zig41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/zeal.zig b/src/zeal.zig
index 1749e28..b3126ec 100644
--- a/src/zeal.zig
+++ b/src/zeal.zig
@@ -80,13 +80,21 @@ pub const Context = struct {
 };
 
 pub const listener = struct {
+    pub fn setMetersPerUnit(factor: f32) Error!void {
+        try al.listener.set(.meters_per_unit, factor);
+    }
+
     pub fn setPosition(position: [3]f32) Error!void {
-        try al.listener.set(al.POSITION, position);
+        try al.listener.set(.position, position);
+    }
+
+    pub fn setVelocity(velocity: [3]f32) Error!void {
+        try al.listener.set(.velocity, velocity);
     }
 
     pub fn setOrientation(at: [3]f32, up: [3]f32) Error!void {
         const orientation = [_]f32{ at[0], at[1], at[2], up[0], up[1], up[2] };
-        try al.listener.set(al.ORIENTATION, orientation);
+        try al.listener.set(.orientation, orientation);
     }
 };
 
@@ -125,6 +133,7 @@ pub const Buffer = struct {
 
     pub fn init(audio: Audio) Error!Buffer {
         const reference = try al.buffer.create();
+        errdefer al.buffer.destroy(&reference) catch unreachable;
         try al.buffer.fill(reference, audio.data, audio.frequency);
         return Buffer{ .reference = reference };
     }
@@ -146,30 +155,36 @@ pub const Source = struct {
         try al.source.destroy(&self.reference);
     }
 
+    pub fn bind(self: Source, buffer: Buffer) Error!void {
+        try al.source.set(self.reference, .buffer,
+                          @intCast(i32, buffer.reference));
+    }
+
     /// Specify if the source always has 3D spatialization features (al.ON),
     /// never has 3D spatialization features (al.OFF), or if spatialization
     /// is enabled based on playing a mono sound or not (al.AUTO, default).
     pub fn setSpatialize(self: Source, value: i32) Error!void {
-        try al.source.set(self.reference, al.SOURCE_SPATIALIZE, value);
+        try al.source.set(self.reference, .spatialize, value);
     }
 
-    pub fn setPosition(self: Source, position: [3]f32) Error!void {
-        try al.source.set(self.reference, al.POSITION, position);
+    fn getState(self: Source) Error!al.source.State {
+        return try al.source.get(al.source.State, self.reference, .state);
     }
 
     pub fn isPlaying(self: Source) Error!bool {
-        const state = try al.source.get(i32, self.reference, al.SOURCE_STATE);
-        return state == al.PLAYING;
+        return (try self.getState()) == .playing;
     }
 
-    pub fn getSecOffset(self: Source) Error!f32 {
-        return try al.source.get(f32, self.reference, al.SEC_OFFSET);
+    pub fn play(self: Source) Error!void {
+        try al.source.play(self.reference);
     }
 
-    pub fn play(self: Source, buffer: Buffer) Error!void {
-        try al.source.set(self.reference, al.BUFFER,
-                          @intCast(i32, buffer.reference));
-        try al.source.play(self.reference);
+    pub fn setPosition(self: Source, position: [3]f32) Error!void {
+        try al.source.set(self.reference, .position, position);
+    }
+
+    pub fn getSecOffset(self: Source) Error!f32 {
+        return try al.source.get(f32, self.reference, .sec_offset);
     }
 };