Slight randomization in sound effect pitches for noise variety.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
pull/35/head
sigonasr2, Sig, Sigo 10 months ago
parent 790a1f7181
commit 1ab521ecc0
  1. 21
      Adventures in Lestoria/SoundEffect.cpp
  2. 6
      Adventures in Lestoria/SoundEffect.h
  3. 76
      Adventures in Lestoria/assets/config/audio/events.txt
  4. 5
      Adventures in Lestoria/olcPGEX_MiniAudio.h

@ -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 <EFBFBD> 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::multimap<EventName,SoundEffect>SoundEffect::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 "<<std::quoted(eventName)<<" does not have any sound effects loaded/doesn't exist!")
size_t soundEffectChoice=util::random()%soundCount;
int counter=0;
auto it=itr.first;
while(counter!=soundEffectChoice){
@ -78,8 +83,12 @@ void SoundEffect::PlaySFX(const std::string_view eventName,const vf2d&pos){
++it;
}
const SoundEffect&sfx=(*it).second;
float pitchDiff=sfx.maxPitch-sfx.minPitch;
float pitch=util::random(pitchDiff)+sfx.minPitch;
if(pos==CENTERED){
Audio::Engine().Play(operator""_SFX(sfx.filename.c_str(),sfx.filename.length()),sfx.vol);
Audio::Engine().Play(operator""_SFX(sfx.filename.c_str(),sfx.filename.length()),sfx.vol,0.0f,pitch);
}else{
const float soundActivationRange="Audio.Environmental Audio Activation Range"_F;
@ -90,7 +99,7 @@ void SoundEffect::PlaySFX(const std::string_view eventName,const vf2d&pos){
float vol=distRatio*sfx.vol;
float pan=xDistRatio;
Audio::Engine().Play(operator""_SFX(sfx.filename.c_str(),sfx.filename.length()),vol,pan);
Audio::Engine().Play(operator""_SFX(sfx.filename.c_str(),sfx.filename.length()),vol,pan,pitch);
}
}
}

@ -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 <EFBFBD> 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
@ -45,7 +45,7 @@ using EventName=std::string;
class SoundEffect{
public:
SoundEffect(const std::string_view filename,const float&vol);
SoundEffect(const std::string_view filename,const float&vol,const float&minPitch=0.9f,const float&maxPitch=1.1f);
static void PlaySFX(const std::string_view eventName,const vf2d&pos);
static void Initialize();
static const vf2d CENTERED;
@ -53,4 +53,6 @@ private:
static std::multimap<EventName,SoundEffect>SOUND_EFFECTS;
std::string filename;
float vol;
float minPitch=0.9f;
float maxPitch=1.1f;
};

@ -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%
}
}

@ -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);
}

Loading…
Cancel
Save