aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-01-03 18:12:53 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-01-03 18:12:53 +0100
commit07f84c7738f7dd1aeaba3f7cae6a26d6a7e5835b (patch)
tree44799cd2164c1efd212b015bde2215f80be92d45
parent3fdaf1a59687d9f4e47810826e4ea9d527a0c689 (diff)
downloadmum-07f84c7738f7dd1aeaba3f7cae6a26d6a7e5835b.tar.gz
load fallback sfx if no file can be found
-rw-r--r--mumd/src/audio.rs41
-rw-r--r--mumd/src/fallback_sfx.wav (renamed from mumd/src/resources/channel_join.wav)bin32002 -> 32002 bytes
-rw-r--r--mumd/src/resources/channel_leave.wavbin32002 -> 0 bytes
-rw-r--r--mumd/src/resources/connect.wavbin32002 -> 0 bytes
-rw-r--r--mumd/src/resources/deafen.wavbin32002 -> 0 bytes
-rw-r--r--mumd/src/resources/disconnect.wavbin303364 -> 0 bytes
-rw-r--r--mumd/src/resources/mute.wavbin32002 -> 0 bytes
-rw-r--r--mumd/src/resources/undeafen.wavbin32002 -> 0 bytes
-rw-r--r--mumd/src/resources/unmute.wavbin32002 -> 0 bytes
9 files changed, 27 insertions, 14 deletions
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs
index 67c3e59..61e2179 100644
--- a/mumd/src/audio.rs
+++ b/mumd/src/audio.rs
@@ -11,23 +11,23 @@ use log::*;
use mumble_protocol::voice::VoicePacketPayload;
use mumlib::config::SoundEffect;
use opus::Channels;
-use std::{collections::hash_map::Entry, fs::File, io};
+use std::{collections::hash_map::Entry, fs::File, io::Read};
use std::collections::{HashMap, VecDeque};
use std::sync::{Arc, Mutex};
use tokio::sync::{mpsc, watch};
//TODO? move to mumlib
pub const DEFAULT_SOUND_FILES: &[(NotificationEvents, &str)] = &[
- (NotificationEvents::ServerConnect, "connect.wav"),
- (NotificationEvents::ServerDisconnect, "disconnect.wav"),
- (NotificationEvents::UserConnected, "channel_join.wav"),
- (NotificationEvents::UserDisconnected, "channel_leave.wav"),
- (NotificationEvents::UserJoinedChannel, "channel_join.wav"),
- (NotificationEvents::UserLeftChannel, "channel_leave.wav"),
- (NotificationEvents::Mute, "mute.wav"),
- (NotificationEvents::Unmute, "unmute.wav"),
- (NotificationEvents::Deafen, "deafen.wav"),
- (NotificationEvents::Undeafen, "undeafen.wav"),
+ (NotificationEvents::ServerConnect, "fallback_sfx.wav"),
+ (NotificationEvents::ServerDisconnect, "fallback_sfx.wav"),
+ (NotificationEvents::UserConnected, "fallback_sfx.wav"),
+ (NotificationEvents::UserDisconnected, "fallback_sfx.wav"),
+ (NotificationEvents::UserJoinedChannel, "fallback_sfx.wav"),
+ (NotificationEvents::UserLeftChannel, "fallback_sfx.wav"),
+ (NotificationEvents::Mute, "fallback_sfx.wav"),
+ (NotificationEvents::Unmute, "fallback_sfx.wav"),
+ (NotificationEvents::Deafen, "fallback_sfx.wav"),
+ (NotificationEvents::Undeafen, "fallback_sfx.wav"),
];
const SAMPLE_RATE: u32 = 48000;
@@ -251,7 +251,12 @@ impl Audio {
} else {
*file
};
- let reader = hound::WavReader::new(get_resource(file).unwrap()).unwrap();
+ let bytes = if let Some(bytes_vec) = get_resource(file) {
+ &*bytes_vec.leak() // needs immutability
+ } else {
+ include_bytes!("fallback_sfx.wav")
+ };
+ let reader = hound::WavReader::new(bytes).unwrap();
let spec = reader.spec();
let samples = match spec.sample_format {
hound::SampleFormat::Float => reader
@@ -382,6 +387,14 @@ impl Audio {
}
}
-fn get_resource(file: &str) -> io::Result<File> {
- File::open(file)
+fn get_resource(file: &str) -> Option<Vec<u8>> {
+ let mut buf: Vec<u8> = Vec::new();
+ if let Ok(mut file) = File::open(file)
+ .or_else(|_| File::open(format!("/home/gustav/dev/mum/mumd/src/resources/{}", file)))
+ {
+ file.read_to_end(&mut buf).unwrap();
+ Some(buf)
+ } else {
+ None
+ }
}
diff --git a/mumd/src/resources/channel_join.wav b/mumd/src/fallback_sfx.wav
index 82ee4d4..82ee4d4 100644
--- a/mumd/src/resources/channel_join.wav
+++ b/mumd/src/fallback_sfx.wav
Binary files differ
diff --git a/mumd/src/resources/channel_leave.wav b/mumd/src/resources/channel_leave.wav
deleted file mode 100644
index 82ee4d4..0000000
--- a/mumd/src/resources/channel_leave.wav
+++ /dev/null
Binary files differ
diff --git a/mumd/src/resources/connect.wav b/mumd/src/resources/connect.wav
deleted file mode 100644
index 82ee4d4..0000000
--- a/mumd/src/resources/connect.wav
+++ /dev/null
Binary files differ
diff --git a/mumd/src/resources/deafen.wav b/mumd/src/resources/deafen.wav
deleted file mode 100644
index 82ee4d4..0000000
--- a/mumd/src/resources/deafen.wav
+++ /dev/null
Binary files differ
diff --git a/mumd/src/resources/disconnect.wav b/mumd/src/resources/disconnect.wav
deleted file mode 100644
index fb2ca76..0000000
--- a/mumd/src/resources/disconnect.wav
+++ /dev/null
Binary files differ
diff --git a/mumd/src/resources/mute.wav b/mumd/src/resources/mute.wav
deleted file mode 100644
index 82ee4d4..0000000
--- a/mumd/src/resources/mute.wav
+++ /dev/null
Binary files differ
diff --git a/mumd/src/resources/undeafen.wav b/mumd/src/resources/undeafen.wav
deleted file mode 100644
index 82ee4d4..0000000
--- a/mumd/src/resources/undeafen.wav
+++ /dev/null
Binary files differ
diff --git a/mumd/src/resources/unmute.wav b/mumd/src/resources/unmute.wav
deleted file mode 100644
index 82ee4d4..0000000
--- a/mumd/src/resources/unmute.wav
+++ /dev/null
Binary files differ