From 25855f327a0b2b1386a3fd8c568817bb7782cac2 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 14 Mar 2015 17:22:17 -0400 Subject: Added reverb to sound effects Also removed some extraneous parentheses --- src/components.cpp | 6 +++--- src/entityfactory.cpp | 2 +- src/game.cpp | 4 ++-- src/map.cpp | 2 +- src/muxer.cpp | 28 +++++++++++++++++++++++----- 5 files changed, 30 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/components.cpp b/src/components.cpp index e41e2cd..d5261ef 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -556,11 +556,11 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli if (dir == Direction::left) { collider.position.first = GAME_WIDTH-collider.size.first/2; - game.loadMap(*(map.getLeftMap())); + game.loadMap(*map.getLeftMap()); } else if (dir == Direction::right) { collider.position.first = -collider.size.first/2; - game.loadMap(*(map.getRightMap())); + game.loadMap(*map.getRightMap()); } return true; @@ -610,6 +610,6 @@ void SimpleColliderComponent::receive(Game& game, Entity&, const Message& msg) { if (msg.type == Message::Type::collision) { - callback(game, *(msg.collisionEntity)); + callback(game, *msg.collisionEntity); } } diff --git a/src/entityfactory.cpp b/src/entityfactory.cpp index 3fcb9ed..bf137e2 100644 --- a/src/entityfactory.cpp +++ b/src/entityfactory.cpp @@ -59,7 +59,7 @@ std::shared_ptr EntityFactory::createNamedEntity(const std::string name, { xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); data.hasPhysics = true; - sscanf((char*) key, "%d,%d", &(data.width), &(data.height)); + sscanf((char*) key, "%d,%d", &data.width, &data.height); xmlFree(key); } } diff --git a/src/game.cpp b/src/game.cpp index a36c56f..edde71e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -151,9 +151,9 @@ void Game::playerDie(Entity& player, const Map& curMap) playSound("../res/Hit_Hurt5.wav", 0.25); schedule(0.75, [&] () { - if (curMap != *(save.map)) + if (curMap != *save.map) { - loadMap(*(save.map)); + loadMap(*save.map); } player.position = save.position; diff --git a/src/map.cpp b/src/map.cpp index 5119d85..5201cf2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -74,7 +74,7 @@ Map::Map(const std::string name) } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position")) { xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); - sscanf((char*) key, "%lf,%lf", &(data.position.first), &(data.position.second)); + sscanf((char*) key, "%lf,%lf", &data.position.first, &data.position.second); xmlFree(key); } } diff --git a/src/muxer.cpp b/src/muxer.cpp index d5409e5..d831e6d 100644 --- a/src/muxer.cpp +++ b/src/muxer.cpp @@ -6,6 +6,13 @@ #include #define SAMPLE_RATE (44100) +#define DELAY_IN_SECS (0.075) +#define GAIN (1.0) +#define FEEDBACK (0.2) +#define DRY (1.0) +#define WET (0.5) + +const int delaySize = SAMPLE_RATE * DELAY_IN_SECS; class Sound { public: @@ -21,6 +28,8 @@ class Sound { struct Muxer { std::list playing; PaStream* stream; + float* delay; + unsigned long delayPos; }; inline void dealWithPaError(PaError err) @@ -39,18 +48,24 @@ int paMuxerCallback(const void*, void* outputBuffer, unsigned long framesPerBuff for (unsigned long i = 0; iplaying) { if (sound.pos < sound.len) { - *out += sound.ptr[sound.pos++] * sound.vol; + in += sound.ptr[sound.pos++] * sound.vol; } } - out++; + if (in > 1) in = 1; + if (in < -1) in = -1; + + float sample = muxer->delay[muxer->delayPos] * GAIN; + muxer->delay[muxer->delayPos] = in + (muxer->delay[muxer->delayPos] * FEEDBACK); + muxer->delayPos++; + if (muxer->delayPos > delaySize) muxer->delayPos = 0; + *out++ = (in * DRY) + (sample * WET); } return 0; @@ -63,8 +78,10 @@ void initMuxer() muxer = new Muxer(); dealWithPaError(Pa_Initialize()); - dealWithPaError(Pa_OpenDefaultStream(&(muxer->stream), 0, 1, paFloat32, SAMPLE_RATE, paFramesPerBufferUnspecified, paMuxerCallback, muxer)); + dealWithPaError(Pa_OpenDefaultStream(&muxer->stream, 0, 1, paFloat32, SAMPLE_RATE, paFramesPerBufferUnspecified, paMuxerCallback, muxer)); dealWithPaError(Pa_StartStream(muxer->stream)); + + muxer->delay = (float*) calloc(delaySize, sizeof(float)); } void destroyMuxer() @@ -73,6 +90,7 @@ void destroyMuxer() dealWithPaError(Pa_CloseStream(muxer->stream)); dealWithPaError(Pa_Terminate()); + free(muxer->delay); delete muxer; muxer = 0; } -- cgit 1.4.1