From 8f5a0cab9c4d7f17fe19e9547677eda3759132c3 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 23 May 2023 17:05:54 -0500 Subject: [PATCH] fix(ui): write silence to audio when emu is paused --- src/platform.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/platform.zig b/src/platform.zig index d034ad7..2bff2f8 100644 --- a/src/platform.zig +++ b/src/platform.zig @@ -196,6 +196,8 @@ pub const Gui = struct { _ = channel.gui.pop(); channel.emu.push(.Resume); + SDL.SDL_PauseAudioDevice(self.audio.device, 0); + self.state.emulation = .Active; }, .Inactive => { @@ -203,7 +205,9 @@ pub const Gui = struct { if (channel.gui.peek()) |value| std.debug.assert(value != .Paused); + SDL.SDL_PauseAudioDevice(self.audio.device, 1); channel.emu.push(.Pause); + self.state.emulation = .Inactive; }, }, @@ -251,6 +255,12 @@ pub const Gui = struct { opengl_impl.drawScreenTexture(emu_tex, prog_id, objects, buf); } + // FIXME: We only really care about locking the audio device (and therefore writing silence) + // since if nfd-zig is used the emu may be paused for way too long. Perhaps we should try and limit + // spurious calls to SDL_LockAudioDevice? + SDL.SDL_LockAudioDevice(self.audio.device); + defer SDL.SDL_UnlockAudioDevice(self.audio.device); + zgui_redraw = imgui.draw(&self.state, win_dim, out_tex, cpu); }, .Inactive => zgui_redraw = imgui.draw(&self.state, win_dim, out_tex, cpu),