diff options
| author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-09-18 17:34:49 +0700 |
|---|---|---|
| committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-09-18 17:34:49 +0700 |
| commit | bc11a6806dd7fb79c0976c5ae7f60593fca6e06f (patch) | |
| tree | 321e93bb3fc8396b1e07257d559464bc673e3e28 /src/misc.zig | |
| parent | 96f80b1a331d5e2e18fec57d8d6c5e0eac22e459 (diff) | |
| download | blackshades-bc11a6806dd7fb79c0976c5ae7f60593fca6e06f.tar.gz | |
Use zeal for sound loading
Effectively vorbisfile is replaced by libsndfile,
which can support formats other than Ogg Vorbis.
Diffstat (limited to 'src/misc.zig')
| -rw-r--r-- | src/misc.zig | 16 |
1 files changed, 14 insertions, 2 deletions
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 { |
