From 011f105bee60346bacd3466cb188b60b31872859 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:13:09 -0300 Subject: [PATCH] feat(config): add config option to mute ZBA --- example.toml | 2 ++ src/config.zig | 3 +++ src/platform.zig | 10 ++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/example.toml b/example.toml index 8e3aa00..cbf5c31 100644 --- a/example.toml +++ b/example.toml @@ -4,6 +4,8 @@ win_scale = 4 # Enable VSYNC on the UI thread vsync = true +# Mute ZBA +mute = false [Guest] # Sync Emulation to Audio diff --git a/src/config.zig b/src/config.zig index 0573d40..3434e0c 100644 --- a/src/config.zig +++ b/src/config.zig @@ -18,6 +18,8 @@ const Config = struct { /// /// Note: This does not affect whether Emulation is synced to 59Hz vsync: bool = true, + /// Mute ZBA + mute: bool = false, }; // Settings realted to the emulation itself @@ -59,6 +61,7 @@ pub fn load(allocator: Allocator, config_path: []const u8) !void { if (table.keys.get("Host")) |host| { if (host.Table.keys.get("win_scale")) |scale| state.host.win_scale = scale.Integer; if (host.Table.keys.get("vsync")) |vsync| state.host.vsync = vsync.Boolean; + if (host.Table.keys.get("mute")) |mute| state.host.mute = mute.Boolean; } if (table.keys.get("Guest")) |guest| { diff --git a/src/platform.zig b/src/platform.zig index d623748..b587fc4 100644 --- a/src/platform.zig +++ b/src/platform.zig @@ -178,10 +178,16 @@ const Audio = struct { export fn callback(userdata: ?*anyopaque, stream: [*c]u8, len: c_int) void { const apu = @ptrCast(*Apu, @alignCast(@alignOf(*Apu), userdata)); - _ = SDL.SDL_AudioStreamGet(apu.stream, stream, len); + + // TODO: Find a better way to mute this + if (!config.config().host.mute) { + _ = SDL.SDL_AudioStreamGet(apu.stream, stream, len); + } else { + // FIXME: I don't think this hack to remove DC Offset is acceptable :thinking: + std.mem.set(u8, stream[0..@intCast(usize, len)], 0x40); + } // If we don't write anything, play silence otherwise garbage will be played - // FIXME: I don't think this hack to remove DC Offset is acceptable :thinking: // if (written == 0) std.mem.set(u8, stream[0..@intCast(usize, len)], 0x40); } };