diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-06-25 08:29:02 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-06-26 07:55:51 +0200 |
| commit | a6c574b04802b5522cf1db12caa85e77062a71b8 (patch) | |
| tree | 6d2018e63ec1ba89d1c0e26e0d28c809a03b24e1 /mumd/src/audio.rs | |
| parent | dd6fdbc60f53290af99ba0640c284917a85070e5 (diff) | |
| download | mum-a6c574b04802b5522cf1db12caa85e77062a71b8.tar.gz | |
move hashmap to audio output
Diffstat (limited to 'mumd/src/audio.rs')
| -rw-r--r-- | mumd/src/audio.rs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index bbaf2e1..aeedf2b 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -18,12 +18,13 @@ use mumble_protocol::Serverbound; use mumlib::config::SoundEffect; use std::collections::{hash_map::Entry, HashMap}; use std::fmt::Debug; +use std::path::PathBuf; use std::sync::{Arc, Mutex}; use tokio::sync::watch; use self::input::{AudioInputDevice, DefaultAudioInputDevice}; use self::output::{AudioOutputDevice, ClientStream, DefaultAudioOutputDevice}; -use self::sound_effects::NotificationEvents; +use self::sound_effects::{NotificationEvent, SoundEffects, SoundEffectId}; /// The sample rate used internally. const SAMPLE_RATE: u32 = 48000; @@ -101,8 +102,11 @@ pub struct AudioOutput { /// Shared with [DefaultAudioOutputDevice]. client_streams: Arc<Mutex<ClientStream>>, - /// Which sound effect should be played on an event. - sounds: HashMap<NotificationEvents, Vec<f32>>, + /// Opened sound effects. + sound_effects: SoundEffects, + + /// Which file should be played on specific events. + sound_effect_events: HashMap<NotificationEvent, SoundEffectId>, } impl AudioOutput { @@ -116,18 +120,17 @@ impl AudioOutput { let mut res = Self { device: default, - sounds: HashMap::new(), - client_streams, user_volumes, + client_streams, + sound_effects: SoundEffects::new(2), + sound_effect_events: HashMap::new(), }; res.load_sound_effects(&[]); Ok(res) } - /// Sets the sound effects according to some overrides, using some default - /// value if an event isn't overriden. - pub fn load_sound_effects(&mut self, overrides: &[SoundEffect]) { - self.sounds = sound_effects::load_sound_effects(overrides, self.device.num_channels()); + pub fn load_sound_effects(&mut self, sound_effects: &[SoundEffect]) { + todo!() } /// Decodes a voice packet. @@ -173,8 +176,13 @@ impl AudioOutput { } /// Queues a sound effect. - pub fn play_effect(&self, effect: NotificationEvents) { - let samples = self.sounds.get(&effect).unwrap(); + pub fn play_effect(&self, effect: NotificationEvent) { + let id = self + .sound_effect_events + .get(&effect) + .cloned() + .unwrap_or_else(SoundEffects::default_sound_effect); + let samples = &self.sound_effects[id]; self.client_streams.lock().unwrap().add_sound_effect(samples); } } |
