diff options
Diffstat (limited to 'src/host/audio.zig')
| -rw-r--r-- | src/host/audio.zig | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/host/audio.zig b/src/host/audio.zig index fc8dcfb..87332b1 100644 --- a/src/host/audio.zig +++ b/src/host/audio.zig @@ -55,19 +55,22 @@ pub const Audio = struct { return out; } + /// `.none` when the file is missing or unreadable, remembered so the + /// warning prints once. pub fn load(self: *Audio, path: []const u8) abi.Audio { if (self.paths.get(path)) |audio| return audio; - const audio = self.add(decodeFile(self.gpa, path) catch |err| blk: { + const audio: abi.Audio = if (decodeFile(self.gpa, path)) |samples| self.add(samples) else |err| blk: { std.log.warn("sound {s}: {t}", .{ path, err }); - break :blk &.{}; - }); + break :blk .none; + }; const key = self.gpa.dupe(u8, path) catch return audio; self.paths.put(self.gpa, key, audio) catch self.gpa.free(key); return audio; } + /// `.none` when `wav` does not decode. pub fn decode(self: *Audio, wav: []const u8) abi.Audio { - return self.add(decodeWav(self.gpa, wav) catch &.{}); + return self.add(decodeWav(self.gpa, wav) catch return .none); } fn add(self: *Audio, samples: []f32) abi.Audio { |
