diff options
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | src/al.zig | 17 | ||||
-rw-r--r-- | src/main.zig | 8 |
3 files changed, 33 insertions, 8 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..3d0a4ed --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# zeal + +Zig easy audio library, or zeal, is an OpenAL wrapper inspired +by [alure] and [palace]. + +## Copying + + + +Zeal is free software: you can redistribute it and/or modify it +under the terms of the GNU [Lesser General Public License][lgplv3] as +published by the Free Software Foundation, either version 3 of the License, +or (at your option) any later version. + +[alure]: https://github.com/kcat/alure +[palace]: https://mcsinyx.gitlab.io/palace diff --git a/src/al.zig b/src/al.zig index b15f2a1..e806e90 100644 --- a/src/al.zig +++ b/src/al.zig @@ -16,14 +16,25 @@ // You should have received a copy of the GNU Lesser General Public License // along with zeal. If not, see <https://www.gnu.org/licenses/>. -usingnamespace @cImport({ @cInclude("AL/al.h"); }); +const Child = @import("std").meta.Child; + +usingnamespace @cImport(@cInclude("AL/al.h")); pub const POSITION = AL_POSITION; pub const ORIENTATION = AL_ORIENTATION; pub const listener = struct { - pub const setFloat = alListenerf; - pub const setFloatVector = alListenerfv; + pub fn set(comptime T: type, param: ALenum, value: T) void { + switch (T) { + f32 => alListenerf(param, value), + i32 => alListeneri(param, value), + else => switch (Child(T)) { + f32 => alListenerfv(param, value[0..]), + i32 => alListeneriv(param, value[0..]), + else => unreachable, + } + } + } }; // alBufferData diff --git a/src/main.zig b/src/main.zig index 249d7c7..fc13fa8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -73,15 +73,13 @@ pub const Listener = struct { pub fn setPosition(self: Listener, position: [3]f32) !void { try checkContext(self.context); - al.listener.setFloatVector(al.POSITION, &position); + al.listener.set([3]f32, al.POSITION, position); } pub fn setOrientation(self: Listener, at: [3]f32, up: [3]f32) !void { try checkContext(self.context); - al.listener.setFloatVector(al.ORIENTATION, &[_]f32 { - at[0], at[1], at[2], - up[0], up[1], up[2], - }); + const orientation = [_]f32{ at[0], at[1], at[2], up[0], up[1], up[2] }; + al.listener.set(@TypeOf(orientation), al.ORIENTATION, orientation); } }; |