audiooutput: specify number of frames of audio to buffer
This commit is contained in:
parent
59d85ab371
commit
89dc1160ed
|
@ -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(
|
||||
|
|
|
@ -32,6 +32,8 @@ pub struct GameboyEmu {
|
|||
type FrameReceiver = Mutex<Option<Receiver<Vec<[u8; 4]>>>>;
|
||||
type JoypadSender = Mutex<Option<Sender<(JoypadButtons, bool)>>>;
|
||||
|
||||
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::<EmulatorMessage>();
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue