From d2e1919a5c700997bd31dd087b2bf51a9da00e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sat, 19 Jun 2021 14:36:29 +0200 Subject: read file extension when opening file --- mumd/src/audio/sound_effects.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'mumd/src/audio/sound_effects.rs') diff --git a/mumd/src/audio/sound_effects.rs b/mumd/src/audio/sound_effects.rs index aac9852..21a514b 100644 --- a/mumd/src/audio/sound_effects.rs +++ b/mumd/src/audio/sound_effects.rs @@ -90,13 +90,17 @@ pub fn load_sound_effects(overrides: &[SoundEffect], num_channels: usize) -> Has // effect (if omitted). We then use dasp to convert to the correct sample rate. NotificationEvents::iter() .map(|event| { - // Open the file if overriden, otherwise use the default sound effect. let file = overrides.get(&event); + // Try to open the file if overriden, otherwise use the default sound effect. let (data, kind) = file - .map(|file| ( - get_sfx(file), - AudioFileKind::Wav - )) + .and_then(|file| { + // Try to get the file kind from the extension. + let kind = file + .split('.') + .last() + .and_then(|ext| AudioFileKind::try_from(ext).ok())?; + Some((get_sfx(file), kind)) + }) .unwrap_or_else(|| (get_default_sfx(), AudioFileKind::Wav)); // Unpack the samples. let (samples, spec) = unpack_audio(data, kind); -- cgit v1.2.1