From ed9c093d0b779e3fcd34f491ca9ceda5280580cd Mon Sep 17 00:00:00 2001 From: Amjad Alsharafi <26300843+Amjad50@users.noreply.github.com> Date: Thu, 26 Dec 2024 18:49:41 +0800 Subject: [PATCH] Updated APU to return stereo audio Signed-off-by: Amjad Alsharafi <26300843+Amjad50@users.noreply.github.com> --- plastic_core/src/apu2a03/channel.rs | 1 + plastic_core/src/apu2a03/mod.rs | 3 ++- plastic_core/src/misc.rs | 4 +--- plastic_core/src/nes.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plastic_core/src/apu2a03/channel.rs b/plastic_core/src/apu2a03/channel.rs index a40a59e..3ee52bb 100644 --- a/plastic_core/src/apu2a03/channel.rs +++ b/plastic_core/src/apu2a03/channel.rs @@ -26,6 +26,7 @@ impl BufferedChannel { pub fn recored_sample(&mut self, sample: f32) { self.buffer.push_back(sample); + self.buffer.push_back(sample); } pub fn take_buffer(&mut self) -> Vec { diff --git a/plastic_core/src/apu2a03/mod.rs b/plastic_core/src/apu2a03/mod.rs index 699784a..8ab48bc 100644 --- a/plastic_core/src/apu2a03/mod.rs +++ b/plastic_core/src/apu2a03/mod.rs @@ -11,7 +11,7 @@ use crate::common::{ CPU_FREQ, }; use apu2a03_registers::Register; -use channel::{APUChannel, BufferedChannel, Dac, TimedAPUChannel}; +use channel::{BufferedChannel, Dac, TimedAPUChannel}; use channels::{Dmc, NoiseWave, SquarePulse, TriangleWave}; use envelope::EnvelopedChannel; use length_counter::LengthCountedChannel; @@ -485,6 +485,7 @@ impl APU2A03 { } } + /// Take and return the audio buffer as f32 format stereo (2 channels) pub fn take_audio_buffer(&mut self) -> Vec { self.buffered_channel.take_buffer() } diff --git a/plastic_core/src/misc.rs b/plastic_core/src/misc.rs index b283011..4a2b190 100644 --- a/plastic_core/src/misc.rs +++ b/plastic_core/src/misc.rs @@ -92,7 +92,7 @@ impl Fps { /// `speed_modifier == 1.0` means normal speed pub fn process_audio(audio_buffer: &[f32], speed_modifier: f32) -> Vec { let target_len = (audio_buffer.len() as f32 * speed_modifier).ceil() as usize; - let mut adjusted_buffer = Vec::with_capacity(target_len * 2); + let mut adjusted_buffer = Vec::with_capacity(target_len); for i in 0..target_len { let src_index_f = i as f32 / speed_modifier; @@ -107,8 +107,6 @@ pub fn process_audio(audio_buffer: &[f32], speed_modifier: f32) -> Vec { } else { *audio_buffer.last().unwrap_or(&0.0) }; - // Add the sample twice for left and right channels - adjusted_buffer.push(sample); adjusted_buffer.push(sample); } diff --git a/plastic_core/src/nes.rs b/plastic_core/src/nes.rs index d9a0422..6b63716 100644 --- a/plastic_core/src/nes.rs +++ b/plastic_core/src/nes.rs @@ -353,7 +353,7 @@ impl NES { self.cpu.bus().ppu.tv().display_pixel_buffer() } - /// Take and return the audio buffer as f32 format + /// Take and return the audio buffer as f32 format stereo (2 channels) /// /// **Take** here means that if you call the function again, it will return an empty buffer /// until the emulator runs again.