summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-03-14 17:22:17 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-03-14 17:22:17 -0400
commit25855f327a0b2b1386a3fd8c568817bb7782cac2 (patch)
treee651ddf541eb9ff3a0662f92de9aea27faf013af /src
parent81992165f5cf6ddebe7952c694b211b16cc45bd4 (diff)
downloadtherapy-25855f327a0b2b1386a3fd8c568817bb7782cac2.tar.gz
therapy-25855f327a0b2b1386a3fd8c568817bb7782cac2.tar.bz2
therapy-25855f327a0b2b1386a3fd8c568817bb7782cac2.zip
Added reverb to sound effects
Also removed some extraneous parentheses
Diffstat (limited to 'src')
-rw-r--r--src/components.cpp6
-rw-r--r--src/entityfactory.cpp2
-rw-r--r--src/game.cpp4
-rw-r--r--src/map.cpp2
-rw-r--r--src/muxer.cpp28
5 files changed, 30 insertions, 12 deletions
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
556 if (dir == Direction::left) 556 if (dir == Direction::left)
557 { 557 {
558 collider.position.first = GAME_WIDTH-collider.size.first/2; 558 collider.position.first = GAME_WIDTH-collider.size.first/2;
559 game.loadMap(*(map.getLeftMap())); 559 game.loadMap(*map.getLeftMap());
560 } else if (dir == Direction::right) 560 } else if (dir == Direction::right)
561 { 561 {
562 collider.position.first = -collider.size.first/2; 562 collider.position.first = -collider.size.first/2;
563 game.loadMap(*(map.getRightMap())); 563 game.loadMap(*map.getRightMap());
564 } 564 }
565 565
566 return true; 566 return true;
@@ -610,6 +610,6 @@ void SimpleColliderComponent::receive(Game& game, Entity&, const Message& msg)
610{ 610{
611 if (msg.type == Message::Type::collision) 611 if (msg.type == Message::Type::collision)
612 { 612 {
613 callback(game, *(msg.collisionEntity)); 613 callback(game, *msg.collisionEntity);
614 } 614 }
615} 615}
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<Entity> EntityFactory::createNamedEntity(const std::string name,
59 { 59 {
60 xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); 60 xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
61 data.hasPhysics = true; 61 data.hasPhysics = true;
62 sscanf((char*) key, "%d,%d", &(data.width), &(data.height)); 62 sscanf((char*) key, "%d,%d", &data.width, &data.height);
63 xmlFree(key); 63 xmlFree(key);
64 } 64 }
65 } 65 }
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)
151 playSound("../res/Hit_Hurt5.wav", 0.25); 151 playSound("../res/Hit_Hurt5.wav", 0.25);
152 152
153 schedule(0.75, [&] () { 153 schedule(0.75, [&] () {
154 if (curMap != *(save.map)) 154 if (curMap != *save.map)
155 { 155 {
156 loadMap(*(save.map)); 156 loadMap(*save.map);
157 } 157 }
158 158
159 player.position = save.position; 159 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)
74 } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position")) 74 } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position"))
75 { 75 {
76 xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); 76 xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1);
77 sscanf((char*) key, "%lf,%lf", &(data.position.first), &(data.position.second)); 77 sscanf((char*) key, "%lf,%lf", &data.position.first, &data.position.second);
78 xmlFree(key); 78 xmlFree(key);
79 } 79 }
80 } 80 }
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 @@
6#include <cmath> 6#include <cmath>
7 7
8#define SAMPLE_RATE (44100) 8#define SAMPLE_RATE (44100)
9#define DELAY_IN_SECS (0.075)
10#define GAIN (1.0)
11#define FEEDBACK (0.2)
12#define DRY (1.0)
13#define WET (0.5)
14
15const int delaySize = SAMPLE_RATE * DELAY_IN_SECS;
9 16
10class Sound { 17class Sound {
11 public: 18 public:
@@ -21,6 +28,8 @@ class Sound {
21struct Muxer { 28struct Muxer {
22 std::list<Sound> playing; 29 std::list<Sound> playing;
23 PaStream* stream; 30 PaStream* stream;
31 float* delay;
32 unsigned long delayPos;
24}; 33};
25 34
26inline void dealWithPaError(PaError err) 35inline void dealWithPaError(PaError err)
@@ -39,18 +48,24 @@ int paMuxerCallback(const void*, void* outputBuffer, unsigned long framesPerBuff
39 48
40 for (unsigned long i = 0; i<framesPerBuffer; i++) 49 for (unsigned long i = 0; i<framesPerBuffer; i++)
41 { 50 {
42 unsigned long curAmount = 0; 51 float in = 0.0;
43 *out = 0;
44 52
45 for (auto& sound : muxer->playing) 53 for (auto& sound : muxer->playing)
46 { 54 {
47 if (sound.pos < sound.len) 55 if (sound.pos < sound.len)
48 { 56 {
49 *out += sound.ptr[sound.pos++] * sound.vol; 57 in += sound.ptr[sound.pos++] * sound.vol;
50 } 58 }
51 } 59 }
52 60
53 out++; 61 if (in > 1) in = 1;
62 if (in < -1) in = -1;
63
64 float sample = muxer->delay[muxer->delayPos] * GAIN;
65 muxer->delay[muxer->delayPos] = in + (muxer->delay[muxer->delayPos] * FEEDBACK);
66 muxer->delayPos++;
67 if (muxer->delayPos > delaySize) muxer->delayPos = 0;
68 *out++ = (in * DRY) + (sample * WET);
54 } 69 }
55 70
56 return 0; 71 return 0;
@@ -63,8 +78,10 @@ void initMuxer()
63 muxer = new Muxer(); 78 muxer = new Muxer();
64 79
65 dealWithPaError(Pa_Initialize()); 80 dealWithPaError(Pa_Initialize());
66 dealWithPaError(Pa_OpenDefaultStream(&(muxer->stream), 0, 1, paFloat32, SAMPLE_RATE, paFramesPerBufferUnspecified, paMuxerCallback, muxer)); 81 dealWithPaError(Pa_OpenDefaultStream(&muxer->stream, 0, 1, paFloat32, SAMPLE_RATE, paFramesPerBufferUnspecified, paMuxerCallback, muxer));
67 dealWithPaError(Pa_StartStream(muxer->stream)); 82 dealWithPaError(Pa_StartStream(muxer->stream));
83
84 muxer->delay = (float*) calloc(delaySize, sizeof(float));
68} 85}
69 86
70void destroyMuxer() 87void destroyMuxer()
@@ -73,6 +90,7 @@ void destroyMuxer()
73 dealWithPaError(Pa_CloseStream(muxer->stream)); 90 dealWithPaError(Pa_CloseStream(muxer->stream));
74 dealWithPaError(Pa_Terminate()); 91 dealWithPaError(Pa_Terminate());
75 92
93 free(muxer->delay);
76 delete muxer; 94 delete muxer;
77 muxer = 0; 95 muxer = 0;
78} 96}