Skip to content

Commit

Permalink
Updated APU to return stereo audio
Browse files Browse the repository at this point in the history
Signed-off-by: Amjad Alsharafi <[email protected]>
  • Loading branch information
Amjad50 committed Dec 26, 2024
1 parent 19cb6c5 commit ed9c093
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions plastic_core/src/apu2a03/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32> {
Expand Down
3 changes: 2 additions & 1 deletion plastic_core/src/apu2a03/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<f32> {
self.buffered_channel.take_buffer()
}
Expand Down
4 changes: 1 addition & 3 deletions plastic_core/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Fps {
/// `speed_modifier == 1.0` means normal speed
pub fn process_audio(audio_buffer: &[f32], speed_modifier: f32) -> Vec<f32> {
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;
Expand All @@ -107,8 +107,6 @@ pub fn process_audio(audio_buffer: &[f32], speed_modifier: f32) -> Vec<f32> {
} 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);
}

Expand Down
2 changes: 1 addition & 1 deletion plastic_core/src/nes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ed9c093

Please sign in to comment.