Skip to content

Commit

Permalink
Closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
LLeny committed Oct 17, 2024
1 parent f20e5e3 commit 29091fe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl Lynx {
postcard::experimental::serialized_size(&self).unwrap()
}

pub fn audio_sample(&self) -> i16 {
pub fn audio_sample(&self) -> (i16, i16) {
self.mikey.audio_sample()
}

Expand Down
30 changes: 27 additions & 3 deletions src/mikey/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,32 @@ impl Mikey {
&self.timers
}

pub fn audio_sample(&self) -> i16 {
self.timers.audio_sample()
pub fn audio_sample(&self) -> (i16, i16) {
let audio0 = self.timers.audio_out(8) as i32;
let audio1 = self.timers.audio_out(9) as i32;
let audio2 = self.timers.audio_out(10) as i32;
let audio3 = self.timers.audio_out(11) as i32;

let atten0 = self.registers.data(ATTEN_A) as i32;
let atten1 = self.registers.data(ATTEN_B) as i32;
let atten2 = self.registers.data(ATTEN_C) as i32;
let atten3 = self.registers.data(ATTEN_D) as i32;

let left = (
(audio0 * (atten0 >> 4) / 0xF) +
(audio1 * (atten1 >> 4) / 0xF) +
(audio2 * (atten2 >> 4) / 0xF) +
(audio3 * (atten3 >> 4) / 0xF)
) << 5;

let right = (
(audio0 * (atten0 & 0xF) / 0xF) +
(audio1 * (atten1 & 0xF) / 0xF) +
(audio2 * (atten2 & 0xF) / 0xF) +
(audio3 * (atten3 & 0xF) / 0xF)
) << 5;

(left as i16, right as i16)
}

pub fn video_mut(&mut self) -> &mut Video {
Expand All @@ -567,4 +591,4 @@ impl Default for Mikey {
fn default() -> Self {
Mikey::new()
}
}
}
6 changes: 1 addition & 5 deletions src/mikey/timers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,12 @@ impl Timers {
self.timer_triggers.sort_by_key(|ti| ti.0);
}

fn audio_out(&self, n: usize) -> i16 {
pub fn audio_out(&self, n: usize) -> i16 {
match &self.timers[n] {
TimerType::Audio(t) => t.output() as i16,
_ => 0
}
}

pub fn audio_sample(&self) -> i16 {
(self.audio_out(8) + self.audio_out(9) + self.audio_out(10) + self.audio_out(11) ) << 5
}
}

impl Default for Timers {
Expand Down

0 comments on commit 29091fe

Please sign in to comment.