diff options
author | Jonas Suhr Christensen <jsc@umbraculum.org> | 2015-04-11 19:14:28 +0200 |
---|---|---|
committer | Jonas Suhr Christensen <jsc@umbraculum.org> | 2015-04-11 19:14:28 +0200 |
commit | fd3edab5680fbbf998d70aadb269efd62b284ae5 (patch) | |
tree | b0a5e74e28413b8ffaa5c50864529673ca796929 | |
parent | 9c52ab4a6688782d0db723bd411db745fed08087 (diff) | |
parent | b7e50d0f21e5619e746dafac129bb66b746c8d64 (diff) |
Merge branch 'diskstreaming' of http://git.drumgizmo.org/drumgizmo into diskstreaming
-rw-r--r-- | src/drumgizmo.cc | 33 | ||||
-rw-r--r-- | src/drumgizmo.h | 3 | ||||
-rw-r--r-- | src/events.h | 6 |
3 files changed, 35 insertions, 7 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 7ce05ef..2f04488 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) @@ -398,6 +400,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 +423,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<std::string, AudioFile *> 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; |