From ae4cebef6fb522f5108c9b21958b513377d320fa Mon Sep 17 00:00:00 2001 From: lif Date: Sat, 16 Nov 2019 21:34:28 -0800 Subject: [PATCH] smol touch of polish on the sdl2 audio path --- src/bin/example.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/bin/example.rs b/src/bin/example.rs index 371fa37..f2f763f 100644 --- a/src/bin/example.rs +++ b/src/bin/example.rs @@ -87,7 +87,9 @@ impl MyEmulator { let mut audio_spec = None; let audio_device = audio .open_playback(None, &desired_spec, |spec| { - println!("audio format {:?}", spec.format); + if spec.format != AudioFormat::S16LSB { + println!("unsupported audio format {:?}", spec.format); + } audio_spec = Some(spec.clone()); MySdlAudio { audio_spec: spec, @@ -254,13 +256,10 @@ impl AudioCallback for MySdlAudio { type Channel = i16; fn callback(&mut self, out: &mut [Self::Channel]) { - match self.audio_spec.format { - AudioFormat::S16LSB | AudioFormat::U16LSB => { - if let Ok(samples) = self.audio_receiver.recv() { - out.copy_from_slice(&samples[..out.len()]); - } + if self.audio_spec.format == AudioFormat::S16LSB { + if let Ok(samples) = self.audio_receiver.recv() { + out.copy_from_slice(&samples[..out.len()]); } - _ => {} } } }