diff --git a/src/audio.rs b/src/audio.rs index e986c72..f2dc71d 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -2,29 +2,29 @@ extern crate sdl2; use sdl2::audio::{AudioCallback, AudioSpecDesired}; -pub struct Speaker { - buffer: [f32; 4096*4], - head: usize, -} +// pub struct Speaker { +// buffer: [f32; 4096*4], +// head: usize, +// } -impl AudioCallback for Speaker { - type Channel = f32; - fn callback(&mut self, out: &mut [f32]) { - for (i, x) in out.iter_mut().enumerate() { - *x = self.buffer[i+self.head]; // get data from apu - } - self.head = (self.head + 4096) % (4096*4) - } -} +// impl AudioCallback for Speaker { +// type Channel = f32; +// fn callback(&mut self, out: &mut [f32]) { +// for (i, x) in out.iter_mut().enumerate() { +// *x = self.buffer[i+self.head]; // get data from apu +// } +// self.head = (self.head + 4096) % (4096*4) +// } +// } -impl Speaker { - pub fn append(&mut self, sample: f32) { - self.buffer[self.head] = sample; - self.head = (self.head + 1) % (4096*4); - } -} +// impl Speaker { +// pub fn append(&mut self, sample: f32) { +// self.buffer[self.head] = sample; +// self.head = (self.head + 1) % (4096*4); +// } +// } -pub fn initialize(context: &sdl2::Sdl) -> Result, String> { +pub fn initialize(context: &sdl2::Sdl) -> Result, String> { let audio_subsystem = context.audio()?; let desired_spec = AudioSpecDesired { @@ -33,11 +33,7 @@ pub fn initialize(context: &sdl2::Sdl) -> Result Result<(), String> { } for _ in 0..apu_cycles { match cpu.apu.clock() { - Some(sample) => audio_device.speaker.append(sample), - None => (), - } + Some(sample) => audio_device.queue(&wav), + None => false, + }; } // clock PPU three times for every CPU cycle for _ in 0..cpu_cycles * 3 {