summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components.cpp4
-rw-r--r--src/muxer.cpp15
-rw-r--r--src/muxer.h2
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)
216 velocity.second = 0.0; 216 velocity.second = 0.0;
217 } else if (msg.type == Message::Type::jump) 217 } else if (msg.type == Message::Type::jump)
218 { 218 {
219 playSound("../res/Randomize87.wav"); 219 playSound("../res/Randomize87.wav", 0.25);
220 220
221 velocity.second = jump_velocity; 221 velocity.second = jump_velocity;
222 accel.second = jump_gravity; 222 accel.second = jump_gravity;
@@ -573,7 +573,7 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli
573 Message msg(Message::Type::die); 573 Message msg(Message::Type::die);
574 collider.send(game, msg); 574 collider.send(game, msg);
575 575
576 playSound("../res/Hit_Hurt5.wav"); 576 playSound("../res/Hit_Hurt5.wav", 0.25);
577 577
578 game.schedule(FRAMES_PER_SECOND * 0.75, [&] () { 578 game.schedule(FRAMES_PER_SECOND * 0.75, [&] () {
579 game.loadGame(map); 579 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 @@
3#include <sndfile.h> 3#include <sndfile.h>
4#include <portaudio.h> 4#include <portaudio.h>
5#include <list> 5#include <list>
6#include <cmath>
6 7
7#define SAMPLE_RATE (44100) 8#define SAMPLE_RATE (44100)
8 9
9class Sound { 10class Sound {
10 public: 11 public:
11 Sound(const char* filename); 12 Sound(const char* filename, float vol);
12 ~Sound(); 13 ~Sound();
13 14
14 float* ptr; 15 float* ptr;
15 unsigned long pos; 16 unsigned long pos;
16 unsigned long len; 17 unsigned long len;
18 float vol;
17}; 19};
18 20
19struct Muxer { 21struct Muxer {
@@ -44,9 +46,7 @@ int paMuxerCallback(const void*, void* outputBuffer, unsigned long framesPerBuff
44 { 46 {
45 if (sound.pos < sound.len) 47 if (sound.pos < sound.len)
46 { 48 {
47 *out *= curAmount++; 49 *out += sound.ptr[sound.pos++] * sound.vol;
48 *out += sound.ptr[sound.pos++];
49 *out /= (float) curAmount;
50 } 50 }
51 } 51 }
52 52
@@ -77,16 +77,16 @@ void destroyMuxer()
77 muxer = 0; 77 muxer = 0;
78} 78}
79 79
80void playSound(const char* filename) 80void playSound(const char* filename, float vol)
81{ 81{
82 // First, clear out any sounds that have finished playing 82 // First, clear out any sounds that have finished playing
83 muxer->playing.remove_if([] (Sound& value) { return value.pos >= value.len; }); 83 muxer->playing.remove_if([] (Sound& value) { return value.pos >= value.len; });
84 84
85 // Then, add the new sound 85 // Then, add the new sound
86 muxer->playing.emplace_back(filename); 86 muxer->playing.emplace_back(filename, vol);
87} 87}
88 88
89Sound::Sound(const char* filename) 89Sound::Sound(const char* filename, float vol)
90{ 90{
91 SF_INFO info; 91 SF_INFO info;
92 SNDFILE* file = sf_open(filename, SFM_READ, &info); 92 SNDFILE* file = sf_open(filename, SFM_READ, &info);
@@ -99,6 +99,7 @@ Sound::Sound(const char* filename)
99 ptr = (float*) malloc(info.frames * info.channels * sizeof(float)); 99 ptr = (float*) malloc(info.frames * info.channels * sizeof(float));
100 len = info.frames * info.channels; 100 len = info.frames * info.channels;
101 pos = 0; 101 pos = 0;
102 this->vol = vol;
102 103
103 sf_readf_float(file, ptr, info.frames); 104 sf_readf_float(file, ptr, info.frames);
104 105
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 @@
3 3
4void initMuxer(); 4void initMuxer();
5void destroyMuxer(); 5void destroyMuxer();
6void playSound(const char* filename); 6void playSound(const char* filename, float vol);
7 7
8#endif 8#endif