From 1ab521ecc0606d266f63f0dbda07dc0ab7dba648 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Wed, 17 Jan 2024 16:18:09 +0000 Subject: [PATCH] Slight randomization in sound effect pitches for noise variety. Co-authored-by: sigonasr2 --- Adventures in Lestoria/SoundEffect.cpp | 21 +++-- Adventures in Lestoria/SoundEffect.h | 6 +- .../assets/config/audio/events.txt | 76 +++++++++---------- Adventures in Lestoria/olcPGEX_MiniAudio.h | 5 +- 4 files changed, 60 insertions(+), 48 deletions(-) diff --git a/Adventures in Lestoria/SoundEffect.cpp b/Adventures in Lestoria/SoundEffect.cpp index a4f739dc..1495fcb6 100644 --- a/Adventures in Lestoria/SoundEffect.cpp +++ b/Adventures in Lestoria/SoundEffect.cpp @@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -Portions of this software are copyright © 2023 The FreeType +Portions of this software are copyright � 2023 The FreeType Project (www.freetype.org). Please see LICENSE_FT.txt for more information. All rights reserved. */ @@ -49,8 +49,8 @@ INCLUDE_game std::multimapSoundEffect::SOUND_EFFECTS; const vf2d SoundEffect::CENTERED={-8419.f,-3289.f}; -SoundEffect::SoundEffect(const std::string_view filename,const float&vol) - :filename(filename),vol(vol){ +SoundEffect::SoundEffect(const std::string_view filename,const float&vol,const float&minPitch,const float&maxPitch) + :filename(filename),vol(vol),minPitch(minPitch),maxPitch(maxPitch){ if(vol<0.f||vol>1.f)ERR(std::format("WARNING! Volume must be between 0.0f ~ 1.0f! Provided value {}",vol)); } @@ -59,7 +59,11 @@ void SoundEffect::Initialize(){ int counter=0; while(DATA["Events"]["SFX"][key].HasProperty(std::format("File[{}]",counter))){ utils::datafile&data=DATA["Events"]["SFX"][key][std::format("File[{}]",counter)]; - SOUND_EFFECTS.insert({key,SoundEffect{data.GetString(0),data.GetInt(1)/100.f}}); + float minPitch=0.9f; + float maxPitch=1.1f; + if(data.GetValueCount()>=3){minPitch=data.GetInt(2)/100.f}; + if(data.GetValueCount()>=4){maxPitch=data.GetInt(3)/100.f}; + SOUND_EFFECTS.insert({key,SoundEffect{data.GetString(0),data.GetInt(1)/100.f,minPitch,maxPitch}}); counter++; } } @@ -71,6 +75,7 @@ void SoundEffect::PlaySFX(const std::string_view eventName,const vf2d&pos){ size_t soundCount=std::distance(itr.first,itr.second); if(soundCount==0)ERR("WARNING! Sound Effect "<SOUND_EFFECTS; std::string filename; float vol; + float minPitch=0.9f; + float maxPitch=1.1f; }; \ No newline at end of file diff --git a/Adventures in Lestoria/assets/config/audio/events.txt b/Adventures in Lestoria/assets/config/audio/events.txt index 973e253c..31183159 100644 --- a/Adventures in Lestoria/assets/config/audio/events.txt +++ b/Adventures in Lestoria/assets/config/audio/events.txt @@ -9,201 +9,201 @@ Events { Bear Slam Attack { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = bear_slam.ogg, 70% } Consume Potion { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = consume_potion.ogg, 70% } Consume Item { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = consume_item.ogg, 60% } Equip Armor { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = equip.ogg, 60% File[1] = equip2.ogg, 60% } Equip Accessory { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = equip_ring.ogg, 100% } Footstep { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = footsteps.ogg, 90% } Footstep - Wet { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = footsteps_wet.ogg, 100% } Buy Item { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = item_buy.ogg, 70% } Sell Item { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = item_sell.ogg, 80% } Craft Item { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = item_craft.ogg, 70% } Enhance Item { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = item_enhance.ogg, 100% } Collect Item { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = item_collect.ogg, 40% } Monster Hurt { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = monster_hurt.ogg, 40% } Player Hit { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = player_hit1.ogg, 40% File[1] = player_hit2.ogg, 100% } Ranger Auto Attack { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = ranger_auto1.ogg, 50% File[1] = ranger_auto2.ogg, 50% } Ranger Retreat { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = ranger_backstep.ogg, 90% } Ranger Multishot { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = ranger_multishot.ogg, 100% } Ranger Rapid Fire { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = ranger_rapid_fire.ogg, 100% } Ranger Charged Shot { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = ranger_charged_shot.ogg, 70% } Slime Dead { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = slime_dead.ogg, 60% File[1] = slime_dead2.ogg, 60% } Monster Dead { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = slime_dead2.ogg, 60% } Slime King Land { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = slime_king_landing.ogg, 100% } Slime King Shoot { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = slime_king_shoot.ogg, 60% } Slime Shoot { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = slime_shoot.ogg, 100% File[1] = slime_shoot2.ogg, 80% } Slime Walk { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = slime_walk.ogg, 10% File[1] = slime_walk2.ogg, 10% File[2] = slime_walk3.ogg, 10% } Warrior Auto Attack { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = warrior_auto1.ogg, 60% } Warrior Battlecry { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = warrior_battlecry.ogg, 100% } Warrior Block Hit { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = warrior_blockhit1.ogg, 100% File[1] = warrior_blockhit2.ogg, 100% } Warrior Ground Slam { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = warrior_groundslam.ogg, 100% } Warrior Sonic Slash { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = warrior_sonicslash.ogg, 70% } Wizard Auto Attack { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = wizard_auto1.ogg, 60% File[1] = wizard_auto2.ogg, 60% } Wizard Fire Bolt Shoot { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = wizard_firebolt.ogg, 100% } Wizard Fire Bolt Hit { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = wizard_firebolt_hit.ogg, 100% } Wizard Lightning Bolt Shoot { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = wizard_lightningbolt.ogg, 60% } Wizard Lightning Bolt Hit { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = wizard_firebolt_hit.ogg, 100% } Wizard Meteor { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = wizard_meteor.ogg, 100% } Wizard Meteor Flames { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = wizard_meteor_lingering.ogg, 100% } Wizard Teleport { - # Specify file names, followed by volume % + # Specify file names, followed by volume %. Optional min and max pitch adjustment (Defaults are 90%,110%) File[0] = wizard_teleport.ogg, 100% } } diff --git a/Adventures in Lestoria/olcPGEX_MiniAudio.h b/Adventures in Lestoria/olcPGEX_MiniAudio.h index f8e1a51e..959274d0 100644 --- a/Adventures in Lestoria/olcPGEX_MiniAudio.h +++ b/Adventures in Lestoria/olcPGEX_MiniAudio.h @@ -89,7 +89,7 @@ namespace olc // plays a sample, can be set to loop void Play(const int id, const bool loop = false); // plays a sound file, as a one off, and automatically unloads it - void Play(const std::string& path,const float&vol=1.0f,const float&pan=0.0f); + void Play(const std::string& path,const float&vol=1.0f,const float&pan=0.0f,const float&pitch=1.0f); // stops a sample, rewinds to beginning void Stop(const int id); // pauses a sample, does not change position @@ -335,7 +335,7 @@ namespace olc ma_sound_start(vecSounds.at(id)); } - void MiniAudio::Play(const std::string& path,const float&vol,const float&pan) + void MiniAudio::Play(const std::string& path,const float&vol,const float&pan,const float&pitch) { // create the sound ma_sound* sound = new ma_sound(); @@ -346,6 +346,7 @@ namespace olc ma_sound_set_volume(sound,vol); ma_sound_set_pan(sound,pan); + ma_sound_set_pitch(sound,pitch); ma_sound_start(sound); vecOneOffSounds.push_back(sound); }