From da3b3c270c60f70ac9948071f9496594f02aa0be Mon Sep 17 00:00:00 2001 From: Nilton Constantino Date: Thu, 22 Jan 2026 13:58:44 +0000 Subject: [PATCH] sounds pause is allowed via debugger --- crates/prometeu-core/src/hardware/audio.rs | 4 ++++ crates/prometeu-runtime-desktop/src/audio.rs | 15 +++++++++++++++ crates/prometeu-runtime-desktop/src/runner.rs | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/crates/prometeu-core/src/hardware/audio.rs b/crates/prometeu-core/src/hardware/audio.rs index 6dd06645..45fff287 100644 --- a/crates/prometeu-core/src/hardware/audio.rs +++ b/crates/prometeu-core/src/hardware/audio.rs @@ -89,6 +89,10 @@ pub enum AudioCommand { voice_id: usize, pitch: f64, }, + /// Pause all audio processing. + MasterPause, + /// Resume audio processing. + MasterResume, } /// PROMETEU Audio Subsystem. diff --git a/crates/prometeu-runtime-desktop/src/audio.rs b/crates/prometeu-runtime-desktop/src/audio.rs index 2df3e80a..858767f9 100644 --- a/crates/prometeu-runtime-desktop/src/audio.rs +++ b/crates/prometeu-runtime-desktop/src/audio.rs @@ -88,6 +88,7 @@ impl HostAudio { pub struct AudioMixer { voices: [Channel; MAX_CHANNELS], pub last_processing_time: Duration, + paused: bool, } impl AudioMixer { @@ -95,6 +96,7 @@ impl AudioMixer { Self { voices: Default::default(), last_processing_time: Duration::ZERO, + paused: false, } } @@ -144,6 +146,14 @@ impl AudioMixer { self.voices[voice_id].pitch = pitch; } } + AudioCommand::MasterPause => { + println!("[AudioMixer] Master Pause"); + self.paused = true; + } + AudioCommand::MasterResume => { + println!("[AudioMixer] Master Resume"); + self.paused = false; + } } } @@ -154,6 +164,11 @@ impl AudioMixer { *sample = 0.0; } + if self.paused { + self.last_processing_time = start.elapsed(); + return; + } + for voice in self.voices.iter_mut() { let sample_data = match &voice.sample { Some(s) => s, diff --git a/crates/prometeu-runtime-desktop/src/runner.rs b/crates/prometeu-runtime-desktop/src/runner.rs index efdef750..eb59992c 100644 --- a/crates/prometeu-runtime-desktop/src/runner.rs +++ b/crates/prometeu-runtime-desktop/src/runner.rs @@ -64,6 +64,8 @@ pub struct HostRunner { /// The physical audio driver. audio: HostAudio, + /// Last known pause state to sync with audio. + last_paused_state: bool, } impl HostRunner { @@ -99,6 +101,7 @@ impl HostRunner { debugger: HostDebugger::new(), overlay_enabled: false, audio: HostAudio::new(), + last_paused_state: false, } } @@ -279,6 +282,20 @@ impl ApplicationHandler for HostRunner { self.firmware.tick(&self.input.signals, &mut self.hardware); } + // Sync pause state with audio. + // We do this AFTER firmware.tick to avoid MasterPause/Resume commands + // being cleared by the OS if a new logical frame starts in this tick. + let is_paused = self.firmware.os.paused || self.debugger.waiting_for_start; + if is_paused != self.last_paused_state { + self.last_paused_state = is_paused; + let cmd = if is_paused { + prometeu_core::hardware::AudioCommand::MasterPause + } else { + prometeu_core::hardware::AudioCommand::MasterResume + }; + self.hardware.audio.commands.push(cmd); + } + // Sync virtual audio commands to the physical mixer. self.audio.send_commands(&mut self.hardware.audio.commands);