From 9510869870504692e9f7b3c21ad9bec3a9a1eefa Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 16 Jun 2021 15:04:00 +0100 Subject: [PATCH] Significantly more efficient sound effect processing, more NPC sounds --- assets/voxygen/audio/sfx.ron | 24 ++++++++++++++ .../voxygen/audio/sfx/utterance/cow_calm.ogg | 3 ++ .../sfx/utterance/humanmale_greeting.ogg | 3 ++ .../voxygen/audio/sfx/utterance/pig_calm.ogg | 3 ++ .../audio/sfx/utterance/sheep_calm.ogg | 3 ++ server/src/sys/agent.rs | 16 +++++++++- voxygen/src/audio/mod.rs | 12 +++---- voxygen/src/audio/sfx/mod.rs | 10 ++++-- voxygen/src/audio/soundcache.rs | 32 +++++++++---------- 9 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 assets/voxygen/audio/sfx/utterance/cow_calm.ogg create mode 100644 assets/voxygen/audio/sfx/utterance/humanmale_greeting.ogg create mode 100644 assets/voxygen/audio/sfx/utterance/pig_calm.ogg create mode 100644 assets/voxygen/audio/sfx/utterance/sheep_calm.ogg diff --git a/assets/voxygen/audio/sfx.ron b/assets/voxygen/audio/sfx.ron index b4f3a0f5e8..1f6ae01af3 100644 --- a/assets/voxygen/audio/sfx.ron +++ b/assets/voxygen/audio/sfx.ron @@ -856,5 +856,29 @@ ], threshold: 4.0, ), + Utterance(Calm, Pig): ( + files: [ + "voxygen.audio.sfx.utterance.pig_calm", + ], + threshold: 4.0, + ), + Utterance(Calm, Cow): ( + files: [ + "voxygen.audio.sfx.utterance.cow_calm", + ], + threshold: 4.0, + ), + Utterance(Calm, Sheep): ( + files: [ + "voxygen.audio.sfx.utterance.sheep_calm", + ], + threshold: 4.0, + ), + Utterance(Greeting, HumanMale): ( + files: [ + "voxygen.audio.sfx.utterance.humanmale_greeting", + ], + threshold: 4.0, + ), } ) diff --git a/assets/voxygen/audio/sfx/utterance/cow_calm.ogg b/assets/voxygen/audio/sfx/utterance/cow_calm.ogg new file mode 100644 index 0000000000..fcb6058d93 --- /dev/null +++ b/assets/voxygen/audio/sfx/utterance/cow_calm.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eb54f07923524c80c8cb35d908165fa55582f0b085790473802fbb578766f347 +size 22691 diff --git a/assets/voxygen/audio/sfx/utterance/humanmale_greeting.ogg b/assets/voxygen/audio/sfx/utterance/humanmale_greeting.ogg new file mode 100644 index 0000000000..69dbe5a088 --- /dev/null +++ b/assets/voxygen/audio/sfx/utterance/humanmale_greeting.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac12e8915ff261097d5aa24debf5685c4da3bc439ba64e6fd0bc12070f2ebff7 +size 12604 diff --git a/assets/voxygen/audio/sfx/utterance/pig_calm.ogg b/assets/voxygen/audio/sfx/utterance/pig_calm.ogg new file mode 100644 index 0000000000..b5660f8b39 --- /dev/null +++ b/assets/voxygen/audio/sfx/utterance/pig_calm.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:397fca64b10178b05d5007b86e166e2ff335380dae69491f95df0e5724b7c2a5 +size 10729 diff --git a/assets/voxygen/audio/sfx/utterance/sheep_calm.ogg b/assets/voxygen/audio/sfx/utterance/sheep_calm.ogg new file mode 100644 index 0000000000..23e9151f17 --- /dev/null +++ b/assets/voxygen/audio/sfx/utterance/sheep_calm.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32fd1868f9f58774e1cd93b5e577795e20a6c3f93683ba4adc7666f2157d0eb3 +size 12028 diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index dd77610f29..d6dab17616 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -409,6 +409,14 @@ impl<'a> System<'a> for Sys { .uid_allocator .retrieve_entity_internal(by.id()) { + if agent.target.is_none() { + controller.push_event( + ControlEvent::Utterance( + UtteranceKind::Angry, + ), + ); + } + agent.target = Some(Target { target: attacker, hostile: true, @@ -511,6 +519,12 @@ impl<'a> System<'a> for Sys { &mut event_emitter, ); } else { + if agent.target.is_none() { + controller.push_event(ControlEvent::Utterance( + UtteranceKind::Angry, + )); + } + agent.target = Some(Target { target: attacker, hostile: true, @@ -945,7 +959,7 @@ impl<'a> AgentData<'a> { controller.actions.push(ControlAction::Unwield); } - if thread_rng().gen_bool(0.001) { + if thread_rng().gen::() < 0.0015 { controller.push_event(ControlEvent::Utterance(UtteranceKind::Calm)); } diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index c0fb8dc175..e6f50f9e9f 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -265,8 +265,8 @@ impl AudioFrontend { ) -> Result<(), rodio::decoder::DecoderError> { if self.audio_stream.is_some() { let sound = OggSound::load_expect(sound) - .cloned() - .decoder()? + .read() + .to_source() .amplify(vol.unwrap_or(1.0)); let listener = self.listener.clone(); @@ -291,9 +291,7 @@ impl AudioFrontend { ) { if self.audio_stream.is_some() { if let Some(channel) = self.get_ambient_channel(channel_tag, volume_multiplier) { - if let Ok(sound) = OggSound::load_expect(sound).cloned().decoder() { - channel.play(sound); - } + channel.play(OggSound::load_expect(sound).read().to_source()); } } } @@ -349,9 +347,7 @@ impl AudioFrontend { fn play_music(&mut self, sound: &str, channel_tag: MusicChannelTag) { if self.music_enabled() { if let Some(channel) = self.get_music_channel(channel_tag) { - if let Ok(sound) = OggSound::load_expect(sound).cloned().decoder() { - channel.play(sound, channel_tag); - } + channel.play(OggSound::load_expect(sound).read().to_source(), channel_tag); } } } diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index c4a0905337..99193012be 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -91,7 +91,7 @@ use client::Client; use common::{ assets::{self, AssetExt, AssetHandle}, comp::{ - beam, biped_large, + beam, biped_large, humanoid, item::{ItemKind, ToolKind}, object, poise::PoiseState, @@ -189,7 +189,8 @@ pub enum SfxEvent { #[derive(Clone, Debug, PartialEq, Deserialize, Hash, Eq)] pub enum VoiceKind { Mute, - Human, + HumanFemale, + HumanMale, BipedLarge, Wendigo, Reptile, @@ -204,7 +205,10 @@ pub enum VoiceKind { fn body_to_voice(body: &Body) -> VoiceKind { match body { - Body::Humanoid(_) => VoiceKind::Human, + Body::Humanoid(body) => match &body.body_type { + humanoid::BodyType::Female => VoiceKind::HumanFemale, + humanoid::BodyType::Male => VoiceKind::HumanMale, + }, Body::QuadrupedSmall(body) => match body.species { quadruped_small::Species::Sheep => VoiceKind::Sheep, quadruped_small::Species::Pig | quadruped_small::Species::Boar => VoiceKind::Pig, diff --git a/voxygen/src/audio/soundcache.rs b/voxygen/src/audio/soundcache.rs index 545f6cef42..7fcdae187f 100644 --- a/voxygen/src/audio/soundcache.rs +++ b/voxygen/src/audio/soundcache.rs @@ -1,6 +1,7 @@ //! Handles caching and retrieval of decoded `.ogg` sfx sound data, eliminating //! the need to decode files on each playback -use common::assets; +use common::assets::{self, Loader}; +use rodio::{source::Buffered, Decoder, Source}; use std::{borrow::Cow, io, sync::Arc}; use tracing::warn; @@ -10,16 +11,16 @@ use tracing::warn; pub struct SoundLoader; #[derive(Clone)] -pub struct OggSound(Arc>); +pub struct OggSound(Buffered>>>); -impl AsRef<[u8]> for OggSound { - fn as_ref(&self) -> &[u8] { &self.0 } -} +// impl AsRef<[u8]> for OggSound { +// fn as_ref(&self) -> &[u8] { &self.0 } +// } -impl assets::Loader for SoundLoader { +impl Loader for SoundLoader { fn load(content: Cow<[u8]>, _: &str) -> Result { - let arc = Arc::new(content.into_owned()); - Ok(OggSound(arc)) + let source = Decoder::new(io::Cursor::new(content.into_owned()))?.buffered(); + Ok(OggSound(source)) } } @@ -37,16 +38,13 @@ impl assets::Asset for OggSound { /// Wrapper for decoded audio data impl OggSound { - pub fn decoder( - self, - ) -> Result>, rodio::decoder::DecoderError> { - let cursor = io::Cursor::new(self); - rodio::Decoder::new(cursor) - } + pub fn to_source(&self) -> impl Source + Iterator { self.0.clone() } pub fn empty() -> OggSound { - OggSound(Arc::new( - include_bytes!("../../../assets/voxygen/audio/null.ogg").to_vec(), - )) + SoundLoader::load( + Cow::Borrowed(include_bytes!("../../../assets/voxygen/audio/null.ogg")), + "empty", + ) + .unwrap() } }