From cc75196b1baca28a142e66c69cd51200649d252a Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 12 Mar 2015 21:20:40 -0400 Subject: Lowered volume of sounds and fixed weird mixing --- src/components.cpp | 4 ++-- src/muxer.cpp | 15 ++++++++------- src/muxer.h | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/components.cpp b/src/components.cpp index 9f37771..5925d14 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -216,7 +216,7 @@ void PlayerPhysicsComponent::receive(Game&, Entity& entity, const Message& msg) velocity.second = 0.0; } else if (msg.type == Message::Type::jump) { - playSound("../res/Randomize87.wav"); + playSound("../res/Randomize87.wav", 0.25); velocity.second = jump_velocity; accel.second = jump_gravity; @@ -573,7 +573,7 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli Message msg(Message::Type::die); collider.send(game, msg); - playSound("../res/Hit_Hurt5.wav"); + playSound("../res/Hit_Hurt5.wav", 0.25); game.schedule(FRAMES_PER_SECOND * 0.75, [&] () { game.loadGame(map); diff --git a/src/muxer.cpp b/src/muxer.cpp index 0844faa..d5409e5 100644 --- a/src/muxer.cpp +++ b/src/muxer.cpp @@ -3,17 +3,19 @@ #include #include #include +#include #define SAMPLE_RATE (44100) class Sound { public: - Sound(const char* filename); + Sound(const char* filename, float vol); ~Sound(); float* ptr; unsigned long pos; unsigned long len; + float vol; }; struct Muxer { @@ -44,9 +46,7 @@ int paMuxerCallback(const void*, void* outputBuffer, unsigned long framesPerBuff { if (sound.pos < sound.len) { - *out *= curAmount++; - *out += sound.ptr[sound.pos++]; - *out /= (float) curAmount; + *out += sound.ptr[sound.pos++] * sound.vol; } } @@ -77,16 +77,16 @@ void destroyMuxer() muxer = 0; } -void playSound(const char* filename) +void playSound(const char* filename, float vol) { // First, clear out any sounds that have finished playing muxer->playing.remove_if([] (Sound& value) { return value.pos >= value.len; }); // Then, add the new sound - muxer->playing.emplace_back(filename); + muxer->playing.emplace_back(filename, vol); } -Sound::Sound(const char* filename) +Sound::Sound(const char* filename, float vol) { SF_INFO info; SNDFILE* file = sf_open(filename, SFM_READ, &info); @@ -99,6 +99,7 @@ Sound::Sound(const char* filename) ptr = (float*) malloc(info.frames * info.channels * sizeof(float)); len = info.frames * info.channels; pos = 0; + this->vol = vol; sf_readf_float(file, ptr, info.frames); diff --git a/src/muxer.h b/src/muxer.h index b0f5378..4301049 100644 --- a/src/muxer.h +++ b/src/muxer.h @@ -3,6 +3,6 @@ void initMuxer(); void destroyMuxer(); -void playSound(const char* filename); +void playSound(const char* filename, float vol); #endif -- cgit 1.4.1