From bc11a6806dd7fb79c0976c5ae7f60593fca6e06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Sat, 18 Sep 2021 17:34:49 +0700 Subject: Use zeal for sound loading Effectively vorbisfile is replaced by libsndfile, which can support formats other than Ogg Vorbis. --- src/misc.zig | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/misc.zig') diff --git a/src/misc.zig b/src/misc.zig index 9015a02..9ad5933 100644 --- a/src/misc.zig +++ b/src/misc.zig @@ -22,14 +22,26 @@ usingnamespace @cImport({ @cInclude("lodepng.h"); }); +const al = @import("zeal"); const allocator = std.heap.c_allocator; const cwd = std.fs.cwd; const data_dir = @import("build_options").data_dir ++ [_]u8{ sep }; const free = std.c.free; -const sep = std.fs.path.sep; +const join = std.fs.path.joinZ; const maxInt = std.math.maxInt; -const std = @import("std"); +const sep = std.fs.path.sep; const span = std.mem.span; +const std = @import("std"); + +pub fn loadSound(filename: [*:0]const u8) callconv(.C) u32 { + const path = join(allocator, &.{ data_dir ++ "sounds", span(filename) }) + catch unreachable; + defer allocator.free(path); + const audio = al.Audio.read(allocator, span(path)) catch unreachable; + defer audio.free(); + const buffer = al.Buffer.init(audio) catch unreachable; + return buffer.reference; +} fn check(errorString: fn (c_uint) callconv(.C) [*c]const u8, status: anytype) void { -- cgit v1.2.3