From 5fa47e69fb003238e1558a93b3e3cd50e3eb260e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 11 Apr 2015 17:05:04 +0200 Subject: Integrate CacheManager into the engine. --- src/drumgizmo.cc | 34 +++++++++++++++++++++++++++------- src/drumgizmo.h | 3 +++ src/events.h | 6 ++++++ 3 files changed, 36 insertions(+), 7 deletions(-) (limited to 'src') 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 f8d45f5..b6711b4 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" @@ -92,6 +93,8 @@ private: std::map audiofiles; + CacheManager cacheManager; + #ifdef TEST_DRUMGIZMO public: #endif 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; -- cgit v1.2.3