summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-03-13 17:19:09 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2016-03-13 17:19:09 +0100
commit08a929d3d32e50e7787428d130289c0f5fc2ff42 (patch)
tree3bdab5e5345e498424c809be05115697d34c7d3b
parent53271c82f9cdcc2fec0da348c7c93cee80a6bb0f (diff)
Fix wierd stuttering bug when one sample is done playing that interrupts existsing playing samples.
-rw-r--r--src/drumgizmo.cc24
-rw-r--r--src/drumgizmo.h2
2 files changed, 20 insertions, 6 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 9e33f48..d4c6427 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -28,6 +28,7 @@
#include <math.h>
#include <stdio.h>
+#include <assert.h>
#include <event.h>
#include <audiotypes.h>
@@ -87,8 +88,9 @@ bool DrumGizmo::loadkit(std::string file)
// Check if there is enough free RAM to load the drumkit.
if(!memchecker.enoughFreeMemory(kit))
{
- printf("WARNING: There doesn't seem to be enough RAM available to load the kit.\n"
- "Trying to load it anyway...\n");
+ printf("WARNING: "
+ "There doesn't seem to be enough RAM available to load the kit.\n"
+ "Trying to load it anyway...\n");
}
loader.loadKit(&kit);
@@ -486,6 +488,7 @@ typedef float vNsf __attribute__ ((vector_size(sizeof(sample_t)*N)));
void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz)
{
+ std::vector< Event* > erase_list;
std::list< Event* >::iterator i = activeevents[ch].begin();
for(; i != activeevents[ch].end(); ++i)
{
@@ -516,7 +519,7 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz)
{
size_t initial_chunksize = (pos + sz) - evt.offset;
evt.buffer = audioCache.open(af, initial_chunksize,
- af.filechannel, evt.cache_id);
+ af.filechannel, evt.cache_id);
evt.buffer_size = initial_chunksize;
}
@@ -568,6 +571,12 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz)
#endif
for(; (n < end) && (t < evt.buffer_size); ++n)
{
+ assert(n >= 0);
+ assert(n < sz);
+
+ assert(t >= 0);
+ assert(t < evt.buffer_size);
+
s[n] += evt.buffer[t];
++t;
}
@@ -606,11 +615,16 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz)
if(removeevent)
{
- delete event;
- i = activeevents[ch].erase(i);
+ erase_list.push_back(event); // don't delete until we are out of the loop.
continue;
}
}
+
+ for(auto& event : erase_list)
+ {
+ activeevents[ch].remove(event);
+ delete event;
+ }
}
void DrumGizmo::stop()
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index 2ff4e8b..e0aea85 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -102,7 +102,7 @@ protected:
AudioCache audioCache;
DrumKit kit;
- MemChecker memchecker;
+ MemChecker memchecker;
size_t framesize;
bool freewheel;