From 9a8c2885804547581708805f145ec55c7d0e0aee Mon Sep 17 00:00:00 2001 From: DaforLynx Date: Sat, 6 Aug 2022 21:29:38 +0000 Subject: [PATCH] Lower volume of river sfx --- assets/voxygen/audio/soundtrack.ron | 2 +- voxygen/src/audio/channel.rs | 4 +- voxygen/src/audio/mod.rs | 39 ++++++++++++++++++- .../src/audio/sfx/event_mapper/block/mod.rs | 26 +++++++++---- voxygen/src/hud/mod.rs | 2 +- 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/assets/voxygen/audio/soundtrack.ron b/assets/voxygen/audio/soundtrack.ron index 50da4ff7f4..c776cf6436 100644 --- a/assets/voxygen/audio/soundtrack.ron +++ b/assets/voxygen/audio/soundtrack.ron @@ -76,7 +76,7 @@ )), Individual(( title: "A Hero's Sorrow", - path: "voxygen.audio.soundtrack.overworld.a_heroes_sorrow", + path: "voxygen.audio.soundtrack.overworld.a_heros_sorrow", length: 251.0, timing: None, weather: Some(Rain), diff --git a/voxygen/src/audio/channel.rs b/voxygen/src/audio/channel.rs index 099c9c34d5..d446a431dd 100644 --- a/voxygen/src/audio/channel.rs +++ b/voxygen/src/audio/channel.rs @@ -253,12 +253,12 @@ impl SfxChannel { /// Same as SfxChannel::play but with the source passed through /// a low pass filter at 300 Hz - pub fn play_with_low_pass_filter(&mut self, source: S) + pub fn play_with_low_pass_filter(&mut self, source: S, freq: u32) where S: Sized + Send + 'static, S: Source, { - let source = source.low_pass(300); + let source = source.low_pass(freq); self.sink.append(source); } diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 86db868caa..ad23c7e8ab 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -276,7 +276,7 @@ impl AudioFrontend { channel.set_pos(position); channel.update(&listener); if underwater { - channel.play_with_low_pass_filter(sound.convert_samples()); + channel.play_with_low_pass_filter(sound.convert_samples(), 300); } else { channel.play(sound); } @@ -290,6 +290,43 @@ impl AudioFrontend { } } + /// Play a sfx file given its position, SfxEvent, and volume with a low-pass + /// filter at the given frequency + pub fn emit_filtered_sfx( + &mut self, + trigger_item: Option<(&SfxEvent, &SfxTriggerItem)>, + position: Vec3, + volume: Option, + freq: Option, + underwater: bool, + ) { + if let Some(sfx_file) = Self::get_sfx_file(trigger_item) { + // Play sound in empty channel at given position + if self.audio_stream.is_some() && volume.map_or(true, |v| v > MIN_HEARABLE_VOLUME) { + let sound = load_ogg(sfx_file).amplify(volume.unwrap_or(1.0)); + + let listener = self.listener.clone(); + if let Some(channel) = self.get_sfx_channel() { + channel.set_pos(position); + channel.update(&listener); + if !underwater { + channel.play_with_low_pass_filter( + sound.convert_samples(), + freq.unwrap_or(20000), + ) + } else { + channel.play_with_low_pass_filter(sound.convert_samples(), 300) + }; + } + } + } else { + debug!( + "Missing sfx trigger config for sfx event at position: {:?}", + position + ); + } + } + /// Plays a sfx using a non-spatial sink at the given volume; doesn't need a /// position /// Passing no volume will default to 1.0 diff --git a/voxygen/src/audio/sfx/event_mapper/block/mod.rs b/voxygen/src/audio/sfx/event_mapper/block/mod.rs index 6b70442345..d5c7efc669 100644 --- a/voxygen/src/audio/sfx/event_mapper/block/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/block/mod.rs @@ -101,14 +101,14 @@ impl EventMapper for BlockEventMapper { blocks: |boi| &boi.slow_river, range: 1, sfx: SfxEvent::RunningWaterSlow, - volume: 1.5, + volume: 1.2, cond: |_| true, }, BlockSounds { blocks: |boi| &boi.fast_river, range: 1, sfx: SfxEvent::RunningWaterFast, - volume: 2.5, + volume: 1.5, cond: |_| true, }, //BlockSounds { @@ -238,12 +238,22 @@ impl EventMapper for BlockEventMapper { .unwrap_or(false); let sfx_trigger_item = triggers.get_key_value(&sounds.sfx); - audio.emit_sfx( - sfx_trigger_item, - block_pos, - Some(sounds.volume), - underwater, - ); + if sounds.sfx == SfxEvent::RunningWaterFast { + audio.emit_filtered_sfx( + sfx_trigger_item, + block_pos, + Some(sounds.volume), + Some(8000), + underwater, + ); + } else { + audio.emit_sfx( + sfx_trigger_item, + block_pos, + Some(sounds.volume), + underwater, + ); + } } internal_state.time = Instant::now(); internal_state.event = sounds.sfx.clone(); diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 3d51f3e6af..62530d6950 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -2448,7 +2448,7 @@ impl Hud { // Current song info Text::new(&format!( - "Currently playing: {} [{}]", + "Now playing: {} [{}]", debug_info.current_track, debug_info.current_artist, )) .color(TEXT_COLOR)