summaryrefslogtreecommitdiff
path: root/src/soundplayer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/soundplayer.cc')
-rw-r--r--src/soundplayer.cc22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/soundplayer.cc b/src/soundplayer.cc
index c170ff2..d24eec5 100644
--- a/src/soundplayer.cc
+++ b/src/soundplayer.cc
@@ -30,6 +30,7 @@
#include <ao/ao.h>
#include <sndfile.h>
#include <samplerate.h>
+#include <cmath>
#define BUFSZ 512
@@ -62,6 +63,8 @@ void SoundPlayer::run()
running = true;
short s[BUFSZ];
+ float _sf[BUFSZ];
+ double scale = 1.0;
while(running)
{
{ // Check for new Selection.
@@ -74,6 +77,7 @@ void SoundPlayer::run()
}
memset(s, 0, BUFSZ * sizeof(short));
+ memset(_sf, 0, BUFSZ * sizeof(float));
QList<QueueItem>::iterator it = active.begin();
while(it != active.end())
@@ -87,8 +91,20 @@ void SoundPlayer::run()
it = active.erase(it);
goto nextitem;
}
- s[i] += item.samples[item.pos] * 32536 * 0.5;
+
+ //while(std::abs(_sf[i] + item.samples[item.pos] * scale) > 1.0)
+ //{
+ // scale *= 0.999999;
+ //}
+ scale = 1.0 / active.size();
+ _sf[i] += item.samples[item.pos] * scale;
+
item.pos++;
+ scale += 0.00000001;
+ if(scale > 1.0)
+ {
+ scale = 1.0;
+ }
}
it++;
@@ -97,6 +113,10 @@ void SoundPlayer::run()
int a = 1;(void)a;
}
+ for(size_t i = 0; i < BUFSZ; i++)
+ {
+ s[i] = _sf[i] * 32000.0;
+ }
ao_play(dev, (char*)s, BUFSZ * sizeof(short));
}