dev/asset-management #6
@ -89,6 +89,10 @@ pub enum AudioCommand {
|
||||
voice_id: usize,
|
||||
pitch: f64,
|
||||
},
|
||||
/// Pause all audio processing.
|
||||
MasterPause,
|
||||
/// Resume audio processing.
|
||||
MasterResume,
|
||||
}
|
||||
|
||||
/// PROMETEU Audio Subsystem.
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user