Skip to content

Commit

Permalink
sapemu: scaffolding around audio processing
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinesfilmroellchen committed Oct 16, 2024
1 parent 444395f commit ba2a187
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sapemu/src/dsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Dsp {

// Note that we can't run the processing just once per sample cycle due to when hardware registers are written
// back.
self.run_audio_processing(memory);
self.run_audio_processing();
}

/// Execute memory reads for this sample cycle.
Expand Down
56 changes: 54 additions & 2 deletions sapemu/src/dsp/audio_processing.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
//! Audio processing code for the DSP.
use super::Dsp;
use super::{Dsp, VoiceState};
use crate::memory::Memory;

impl Dsp {
#[allow(clippy::match_same_arms)]
pub(super) fn run_audio_processing(&mut self) {
match self.sample_cycle {
0 => {},
1 => {},
2 => self.voices_state[0].run_voice_processing(),
3 => {},
4 => {},
5 => self.voices_state[1].run_voice_processing(),
6 => {},
7 => {},
8 => self.voices_state[2].run_voice_processing(),
9 => {},
10 => {},
11 => self.voices_state[3].run_voice_processing(),
12 => {},
13 => {},
14 => self.voices_state[4].run_voice_processing(),
15 => {},
16 => {},
17 => self.voices_state[5].run_voice_processing(),
18 => {},
19 => {},
20 => self.voices_state[6].run_voice_processing(),
21 => {},
22 => {},
23 => self.voices_state[7].run_voice_processing(),
24 => {},
25 => {},
26 => {},
27 => {},
28 => {},
29 => self.run_main_processing(),
30 => {},
31 => {},
_ => unreachable!(),
}
}

/// Runs the main audio processing for voice mixing and echo processing.
/// In hardware, this step is distributed between cycles 24 (or 25) and 31 (or 29 for echo).
/// Since all necessary registers are read in cycle 29 (EDL&ESA take effect one sample later at the earliest!), but
/// we need to write the echo result starting in cycle 30, this seems to be the perfect time to run the sound
/// emulation.
#[allow(clippy::needless_pass_by_ref_mut, clippy::unused_self)]
fn run_main_processing(&mut self) {}
}

impl VoiceState {
/// Runs the per-voice audio processing. In hardware, this step is distributed between the first cycle that reads
/// the voice’s SRCN register (this happens fairly early!) and the last cycle before the voice’s OUTX register is
/// written. We run all the processing in the cycle before the OUTX write, which doesn’t lose cycle-accuracy.
#[allow(clippy::needless_pass_by_ref_mut, clippy::unused_self)]
pub(super) fn run_audio_processing(&mut self, memory: &mut Memory) {}
pub(super) fn run_voice_processing(&mut self) {}
}

0 comments on commit ba2a187

Please sign in to comment.