fixed DK walking sound though not sure why exactly.
This commit is contained in:
parent
73549d6c2d
commit
73b0a28034
|
@ -97,6 +97,12 @@ impl Apu {
|
||||||
sample
|
sample
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn mix(&self) -> f32 {
|
||||||
|
let square_out = self.square_table[(self.square1.sample + self.square2.sample) as usize];
|
||||||
|
let tnd_out = self.tnd_table[((3*self.triangle.sample)+(2*self.noise.sample) + self.dmc.sample) as usize];
|
||||||
|
square_out + tnd_out
|
||||||
|
}
|
||||||
|
|
||||||
pub fn write_reg(&mut self, address: usize, value: u8) {
|
pub fn write_reg(&mut self, address: usize, value: u8) {
|
||||||
// println!("writing 0b{:08b} to 0x{:X}", value, address);
|
// println!("writing 0b{:08b} to 0x{:X}", value, address);
|
||||||
match address {
|
match address {
|
||||||
|
@ -128,12 +134,6 @@ impl Apu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mix(&self) -> f32 {
|
|
||||||
let square_out = self.square_table[(self.square1.sample + self.square2.sample) as usize];
|
|
||||||
let tnd_out = self.tnd_table[((3*self.triangle.sample)+(2*self.noise.sample) + self.dmc.sample) as usize];
|
|
||||||
square_out + tnd_out
|
|
||||||
}
|
|
||||||
|
|
||||||
// mode 0: mode 1: function
|
// mode 0: mode 1: function
|
||||||
// --------- ----------- -----------------------------
|
// --------- ----------- -----------------------------
|
||||||
// - - - f - - - - - IRQ (if bit 6 is clear)
|
// - - - f - - - - - IRQ (if bit 6 is clear)
|
||||||
|
|
|
@ -107,17 +107,18 @@ impl Square {
|
||||||
// When the divider is clocked while at 0, it is loaded with V and clocks the decay level counter.
|
// When the divider is clocked while at 0, it is loaded with V and clocks the decay level counter.
|
||||||
if self.envelope_divider == 0 {
|
if self.envelope_divider == 0 {
|
||||||
self.envelope_divider = self.envelope;
|
self.envelope_divider = self.envelope;
|
||||||
} else {
|
|
||||||
self.envelope_divider -= 1;
|
|
||||||
}
|
|
||||||
// Then one of two actions occurs: If the counter is non-zero, it is decremented,
|
// Then one of two actions occurs: If the counter is non-zero, it is decremented,
|
||||||
if self.decay_counter != 0 {
|
if self.decay_counter != 0 {
|
||||||
self.decay_counter -= 1;
|
self.decay_counter -= 1;
|
||||||
// println!("decaying to {}", self.decay_counter);
|
// println!("decaying to {}", self.decay_counter);
|
||||||
} else if self.length_counter_halt {
|
} else if self.length_counter_halt {
|
||||||
// otherwise if the loop flag is set, the decay level counter is loaded with 15.
|
// otherwise if the loop flag is set, the decay level counter is loaded with 15.
|
||||||
|
println!("looping decay counter");
|
||||||
self.decay_counter = 15;
|
self.decay_counter = 15;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self.envelope_divider -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clock_length_counter(&mut self) {
|
pub fn clock_length_counter(&mut self) {
|
||||||
|
@ -130,7 +131,7 @@ impl Square {
|
||||||
self.calculate_target_period();
|
self.calculate_target_period();
|
||||||
// When the frame counter sends a half-frame clock (at 120 or 96 Hz), two things happen.
|
// When the frame counter sends a half-frame clock (at 120 or 96 Hz), two things happen.
|
||||||
// If the divider's counter is zero, the sweep is enabled, and the sweep unit is not muting the channel: The pulse's period is adjusted.
|
// If the divider's counter is zero, the sweep is enabled, and the sweep unit is not muting the channel: The pulse's period is adjusted.
|
||||||
if self.sweep_counter == 0 && self.sweep_enabled && !(self.timer_period < 8 || self.timer_period > 0x7FF) {
|
if self.sweep_counter == 0 && self.sweep_enabled && !(self.timer_period < 8 || self.target_period > 0x7FF) {
|
||||||
self.timer_period = self.target_period;
|
self.timer_period = self.target_period;
|
||||||
println!("timer period adjusted to {}", self.timer_period);
|
println!("timer period adjusted to {}", self.timer_period);
|
||||||
}
|
}
|
||||||
|
@ -138,6 +139,7 @@ impl Square {
|
||||||
if self.sweep_counter == 0 || self.sweep_reload {
|
if self.sweep_counter == 0 || self.sweep_reload {
|
||||||
self.sweep_counter = self.sweep_divider;
|
self.sweep_counter = self.sweep_divider;
|
||||||
self.sweep_reload = false;
|
self.sweep_reload = false;
|
||||||
|
if self.sweep_enabled { self.timer_period = self.target_period; } // This fixes the DK walking sound. Why? Not reflected in documentation.
|
||||||
} else {
|
} else {
|
||||||
self.sweep_counter -= 1;
|
self.sweep_counter -= 1;
|
||||||
}
|
}
|
||||||
|
@ -170,6 +172,7 @@ impl Square {
|
||||||
self.duty_cycle = DUTY_CYCLE_SEQUENCES[(value >> 6) as usize];
|
self.duty_cycle = DUTY_CYCLE_SEQUENCES[(value >> 6) as usize];
|
||||||
self.length_counter_halt = value & (1<<5) != 0;
|
self.length_counter_halt = value & (1<<5) != 0;
|
||||||
self.constant_volume_flag = value & (1<<4) != 0;
|
self.constant_volume_flag = value & (1<<4) != 0;
|
||||||
|
// println!("using envelope volume: {}", !self.constant_volume_flag);
|
||||||
self.envelope = value as u16 & 0b1111;
|
self.envelope = value as u16 & 0b1111;
|
||||||
// if self.constant_volume_flag {
|
// if self.constant_volume_flag {
|
||||||
// value as u16 & 0b1111
|
// value as u16 & 0b1111
|
||||||
|
@ -180,6 +183,7 @@ impl Square {
|
||||||
|
|
||||||
// $4001/$4005
|
// $4001/$4005
|
||||||
pub fn write_sweep(&mut self, value: u8) {
|
pub fn write_sweep(&mut self, value: u8) {
|
||||||
|
// println!("writing sweep 0b{:08b}", value);
|
||||||
self.sweep_enabled = value >> 7 == 1;
|
self.sweep_enabled = value >> 7 == 1;
|
||||||
self.sweep_divider = ((value as u16 >> 4) & 0b111) + 1;
|
self.sweep_divider = ((value as u16 >> 4) & 0b111) + 1;
|
||||||
self.sweep_negate = value & 0b1000 != 0;
|
self.sweep_negate = value & 0b1000 != 0;
|
||||||
|
|
|
@ -69,7 +69,7 @@ fn main() -> Result<(), String> {
|
||||||
match cpu.apu.clock() {
|
match cpu.apu.clock() {
|
||||||
Some(sample) => {
|
Some(sample) => {
|
||||||
sps += 1;
|
sps += 1;
|
||||||
if sps < 44100 {audio_device.queue(&vec![sample]);}
|
if sps < 44_100 {audio_device.queue(&vec![sample]);}
|
||||||
},
|
},
|
||||||
None => (),
|
None => (),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue