feat(config): add config option to mute ZBA

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-10-13 00:54:15 -03:00
parent 5a72a8e7f3
commit 19e70c39d1
3 changed files with 13 additions and 2 deletions

View File

@ -4,6 +4,8 @@
win_scale = 4 win_scale = 4
# Enable VSYNC on the UI thread # Enable VSYNC on the UI thread
vsync = true vsync = true
# Mute ZBA
mute = false
[Guest] [Guest]
# Sync Emulation to Audio # Sync Emulation to Audio

View File

@ -18,6 +18,8 @@ const Config = struct {
/// ///
/// Note: This does not affect whether Emulation is synced to 59Hz /// Note: This does not affect whether Emulation is synced to 59Hz
vsync: bool = true, vsync: bool = true,
/// Mute ZBA
mute: bool = false,
}; };
// Settings realted to the emulation itself // 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 (table.keys.get("Host")) |host| {
if (host.Table.keys.get("win_scale")) |scale| state.host.win_scale = scale.Integer; 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("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| { if (table.keys.get("Guest")) |guest| {

View File

@ -178,10 +178,16 @@ const Audio = struct {
export fn callback(userdata: ?*anyopaque, stream: [*c]u8, len: c_int) void { export fn callback(userdata: ?*anyopaque, stream: [*c]u8, len: c_int) void {
const apu = @ptrCast(*Apu, @alignCast(@alignOf(*Apu), userdata)); 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 // 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); // if (written == 0) std.mem.set(u8, stream[0..@intCast(usize, len)], 0x40);
} }
}; };