summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-04-11 17:05:04 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-20 13:23:11 +0100
commit0b0d73ead2235077debae5e045ed2b4cb191f5b2 (patch)
tree24891ec9974b3f69e7afb7b0baff4988dcf4e09d /src
parentd700b874c344a19bfef4abad2bf0dd293e93c6d6 (diff)
Integrate CacheManager into the engine.
Diffstat (limited to 'src')
-rw-r--r--src/drumgizmo.cc34
-rw-r--r--src/drumgizmo.h3
-rw-r--r--src/events.h6
3 files changed, 36 insertions, 7 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 7ce05ef..d6b0f9e 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -50,10 +50,12 @@ DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i)
loader(), oe(o), ie(i)
{
is_stopping = false;
+ cacheManager.init(1000); // start thread
}
DrumGizmo::~DrumGizmo()
{
+ cacheManager.deinit(); // stop thread
}
bool DrumGizmo::loadkit(std::string file)
@@ -373,6 +375,7 @@ void DrumGizmo::run(int endpos)
free(samples);
}
+#undef SSE
#ifdef SSE
#define N 8
typedef float vNsf __attribute__ ((vector_size(sizeof(float)*N)));
@@ -398,6 +401,18 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t *s, size_t sz)
break;
}
+ // Don't handle event now is is scheduled for a future iteration?
+ if(evt->offset > (pos + sz)) {
+ continue;
+ }
+
+ if(evt->cache_id == CACHE_NOID) {
+ size_t initial_chunksize = (pos + sz) - evt->offset;
+ evt->buffer =
+ cacheManager.open(af, initial_chunksize, ch, evt->cache_id);
+ evt->buffer_size = initial_chunksize;
+ }
+
{
MutexAutolock l(af->mutex);
@@ -409,32 +424,37 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t *s, size_t sz)
if(evt->rampdown == NO_RAMPDOWN) {
#ifdef SSE
-// DEBUG(drumgizmo,"%d\n", evt->t); fflush(stdout);
- size_t optend = ((end - n) / N) * N + n;
- for(; n < optend; n += N) {
- *(vNsf*)&(s[n]) += *(vNsf*)&(af->data[evt->t]);
+ size_t optend = ((end - n) / N) * N + n;
+ size_t t;
+ for(; n < optend; n += N) {
+ t = evt->t % evt->buffer_size;
+ *(vNsf*)&(s[n]) += *(vNsf*)&(evt->buffer[t]);
evt->t += N;
- }
+ }
#endif
for(; n < end; n++) {
- s[n] += af->data[evt->t];
+ s[n] += evt->buffer[evt->t % evt->buffer_size];
evt->t++;
}
} else { // Ramp down in progress.
for(; n < end && evt->rampdown; n++) {
float scale = (float)evt->rampdown/(float)evt->ramp_start;
- s[n] += af->data[evt->t] * scale;
+ s[n] += evt->buffer[evt->t % evt->buffer_size] * scale;
evt->t++;
evt->rampdown--;
}
if(evt->rampdown == 0) {
removeevent = true; // Down ramp done. Remove event.
+ cacheManager.close(evt->cache_id);
}
}
if(evt->t >= af->size) {
removeevent = true;
+ cacheManager.close(evt->cache_id);
+ } else {
+ evt->buffer = cacheManager.next(evt->cache_id, evt->buffer_size);
}
}
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index 5e58ba5..f1ec546 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -38,6 +38,7 @@
#include "drumkit.h"
#include "drumkitloader.h"
+#include "cachemanager.h"
#include "mutex.h"
@@ -95,6 +96,8 @@ private:
std::map<std::string, AudioFile *> audiofiles;
+ CacheManager cacheManager;
+
DrumKit kit;
};
diff --git a/src/events.h b/src/events.h
index fa0147b..ea897f1 100644
--- a/src/events.h
+++ b/src/events.h
@@ -35,6 +35,7 @@
#include "audiofile.h"
#include "audio.h"
#include "mutex.h"
+#include "cachemanager.h"
typedef unsigned int timepos_t;
@@ -58,6 +59,7 @@ public:
EventSample(channel_t c, float g, AudioFile *af, std::string grp,
void *instr)
{
+ cache_id = CACHE_NOID;
channel = c;
gain = g;
t = 0;
@@ -70,6 +72,10 @@ public:
Event::type_t type() { return Event::sample; }
+ cacheid_t cache_id;
+ sample_t *buffer;
+ size_t buffer_size;
+
float gain;
unsigned int t;
AudioFile *file;