X-Git-Url: https://codewiz.org/gitweb?p=mandelwow.git;a=blobdiff_plain;f=sound.rs;h=9f116ad05f531cdaef992ee07b0d760020b670e0;hp=d7dae929fa75cf9df80097d8db954338662f5464;hb=c0cff536ab1cc34f0643770bee8e2a88373269d7;hpb=d3f9906bc53b97fc955cc2babde3fe7b7e09d64b diff --git a/sound.rs b/sound.rs index d7dae92..9f116ad 100644 --- a/sound.rs +++ b/sound.rs @@ -29,11 +29,11 @@ fn play_xm(raw_xm: &[u8]) -> SoundPlayer { let desired_spec = AudioSpecDesired { freq: Some(SAMPLE_RATE), - channels: Some(2u8), - samples: None, + channels: Some(2), + samples: Some(4096), // 85ms }; let device = sdl_audio.open_playback(None, &desired_spec, |actual_spec| { - let xm = XMContext::new(&raw_xm, actual_spec.freq as u32).unwrap(); + let xm = XMContext::new(raw_xm, actual_spec.freq as u32).unwrap(); XmCallback { xm: xm, @@ -59,16 +59,14 @@ pub fn start() -> SoundPlayer { println!("Couldn't open module {}: {:?}", filename, err); }, } - return SoundPlayer { device: None }; + SoundPlayer { device: None } } pub fn hit_event(player: &mut SoundPlayer) -> f32 { use std::ops::Deref; - let maybe_audio_device = &mut player.device; - let audio_device = &mut maybe_audio_device.as_mut().unwrap(); - let audio_device_lock = audio_device.lock(); + let audio_device_lock = player.device.as_mut().unwrap().lock(); let xm_callback = audio_device_lock.deref(); let xm = &xm_callback.xm; let n_samples = xm.latest_trigger_of_instrument(0x1D); - return n_samples as f32 / SAMPLE_RATE as f32; + n_samples as f32 / SAMPLE_RATE as f32 }