summary refs log tree commit diff stats
path: root/src/muxer.cpp
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/muxer.cpp
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/muxer.cpp')
-rw-r--r--src/muxer.cpp28
1 files changed, 23 insertions, 5 deletions
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}