diff --git a/gb-emu/src/main.rs b/gb-emu/src/main.rs index e44f258..996e699 100644 --- a/gb-emu/src/main.rs +++ b/gb-emu/src/main.rs @@ -132,7 +132,7 @@ fn create_audio_output() -> (AudioOutput, Stream) { let sample_rate = config.sample_rate().0; - let (output, mut rx) = AudioOutput::new_unfilled(sample_rate as f32, true); + let (output, mut rx) = AudioOutput::new_unfilled(sample_rate as f32, true, 1); let stream = device .build_output_stream( diff --git a/gb-vst/src/lib.rs b/gb-vst/src/lib.rs index f5a8171..cc194b8 100644 --- a/gb-vst/src/lib.rs +++ b/gb-vst/src/lib.rs @@ -32,6 +32,8 @@ pub struct GameboyEmu { type FrameReceiver = Mutex>>>; type JoypadSender = Mutex>>; +const FRAMES_TO_BUFFER: usize = 3; + impl Plugin for GameboyEmu { const NAME: &'static str = "Gameboy"; @@ -118,14 +120,16 @@ impl Plugin for GameboyEmu { }; if let Some(ref mut vars) = self.vars { - let (output, rx) = AudioOutput::new_unfilled(buffer_config.sample_rate, false); + let (output, rx) = + AudioOutput::new_unfilled(buffer_config.sample_rate, false, FRAMES_TO_BUFFER); vars.emulator_core.replace_output(output); vars.rx = rx; } else { let (sender, receiver) = channel::(); - let (output, rx) = AudioOutput::new_unfilled(buffer_config.sample_rate, false); + let (output, rx) = + AudioOutput::new_unfilled(buffer_config.sample_rate, false, FRAMES_TO_BUFFER); let (renderer, frame_receiver, key_handler) = EmulatorRenderer::new(); diff --git a/lib/src/connect/mod.rs b/lib/src/connect/mod.rs index d4f1329..05c069f 100644 --- a/lib/src/connect/mod.rs +++ b/lib/src/connect/mod.rs @@ -46,8 +46,12 @@ pub struct AudioOutput { } impl AudioOutput { - pub fn new(sample_rate: f32, wait_for_output: bool) -> (Self, AsyncHeapConsumer<[f32; 2]>) { - let (mut output, rx) = Self::new_unfilled(sample_rate, wait_for_output); + pub fn new( + sample_rate: f32, + wait_for_output: bool, + frames_to_buffer: usize, + ) -> (Self, AsyncHeapConsumer<[f32; 2]>) { + let (mut output, rx) = Self::new_unfilled(sample_rate, wait_for_output, frames_to_buffer); executor::block_on( output @@ -62,8 +66,9 @@ impl AudioOutput { pub fn new_unfilled( sample_rate: f32, wait_for_output: bool, + frames_to_buffer: usize, ) -> (Self, AsyncHeapConsumer<[f32; 2]>) { - let rb_len = sample_rate as usize / 60; + let rb_len = (sample_rate as usize / 60) * frames_to_buffer; let rb = AsyncHeapRb::<[f32; 2]>::new(rb_len); let (send_rb, rx) = rb.split();