diff --git a/gui/src/imp/native_audio.rs b/gui/src/imp/native_audio.rs index 3867bd6..3778aac 100644 --- a/gui/src/imp/native_audio.rs +++ b/gui/src/imp/native_audio.rs @@ -22,6 +22,8 @@ pub struct AudioSystem { const SAMPLE_RATE: u32 = 48_000; const PACKET_SAMPLES: u32 = 960; +// Divide by 1000 to get samples per ms, then multiply by 60ms for max Opus frame size. +const MAX_DECODE_SAMPLES: usize = SAMPLE_RATE as usize / 1000 * 60; fn encode_and_send( state: TransmitState, @@ -184,7 +186,7 @@ impl AudioSystem { decoder, stream, buffer, - tmp: vec![0; 2400], + tmp: vec![0; MAX_DECODE_SAMPLES], }) } } @@ -198,13 +200,11 @@ pub struct AudioPlayer { impl AudioPlayer { pub fn play_opus(&mut self, payload: &[u8]) { - let len = loop { - match self.decoder.decode(payload, &mut self.tmp, false) { - Ok(l) => break l, - Err(e) => { - error!("opus decode error {e:?}"); - return; - } + let len = match self.decoder.decode(payload, &mut self.tmp, false) { + Ok(l) => l, + Err(e) => { + error!("opus decode error {e:?}"); + return; } };