smol touch of polish on the sdl2 audio path

This commit is contained in:
lif 2019-11-16 21:34:28 -08:00
parent 4e22289ef0
commit ae4cebef6f
1 changed files with 6 additions and 7 deletions

View File

@ -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()]);
}
_ => {}
}
}
}