This commit is contained in:
Theron 2019-12-25 21:51:54 -06:00
parent b128ad485e
commit bf2317dc28
5 changed files with 26 additions and 4 deletions

View File

@ -17,6 +17,9 @@ impl DMC {
}
}
pub fn clock(&mut self) {
}
pub fn write_control(&mut self, value: u8) {

View File

@ -57,8 +57,10 @@ pub struct Apu {
impl Apu {
pub fn new() -> Self {
let square_table = (0..31).map(|x| 95.52/(8128.0 / x as f32) + 100.0).collect();
let tnd_table = (0..203).map(|x| 163.67/(24329.0 / x as f32) + 100.0).collect();
let square_table = (0..31).map(|x| 95.52/((8128.0 / x as f32) + 100.0)).collect();
let tnd_table = (0..203).map(|x| 163.67/((24329.0 / x as f32) + 100.0)).collect();
println!("square_table: {:?}", square_table);
println!("tnd_table: {:?}", tnd_table);
Apu {
square1: Square::new(false),
square2: Square::new(true),
@ -82,6 +84,12 @@ impl Apu {
pub fn clock(&mut self) -> Option<f32> {
let mut sample = None;
self.square1.clock();
self.square2.clock();
self.triangle.clock();
self.noise.clock();
self.dmc.clock();
if (self.frame_counter == 4 && FRAME_COUNTER_STEPS[..4].contains(&self.cycle))
|| (self.frame_counter == 5 && FRAME_COUNTER_STEPS.contains(&self.cycle)) {
self.clock_frame_counter();

View File

@ -83,6 +83,7 @@ impl Square {
} else {
self.decay_counter
};
println!("{}", self.sample);
}
pub fn clock_envelope(&mut self) {

View File

@ -32,6 +32,10 @@ impl Triangle {
}
pub fn clock(&mut self) {
}
pub fn clock_linear_counter(&mut self) {
}

View File

@ -68,12 +68,18 @@ fn main() -> Result<(), String> {
}
for _ in 0..apu_cycles {
match cpu.apu.clock() {
Some(sample) => {sps += 1; audio_buffer.push(sample)},
Some(sample) => {
sps += 1;
// if sample != 0.0 {
// println!("sample {}", sample);
// }
audio_buffer.push(sample)
},
None => (),
};
}
if audio_buffer.len() == 44_100 {
println!("queueing: {:?}", &audio_buffer[..32]);
// println!("queueing: {:?}", &audio_buffer[..32]);
audio_device.queue(&audio_buffer);
audio_buffer = vec![];
}