summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-06-28 16:22:11 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-20 13:30:25 +0100
commit1844f89239a8f873aae9dec8375087606b9a4541 (patch)
tree1133ec5f3a13b20fc1f59cf7808b238cb84889f3
parentc640f53d5daf4f12680e19c53094cd7c7a17b7e0 (diff)
Fix read of memory that was alreay freed. Fix misaligned SIMD copy.
-rw-r--r--src/drumgizmo.cc27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 8661232..28ac2c6 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -430,15 +430,22 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t *s, size_t sz)
// Find the end point intra-buffer
if((evt->t + end - n) > af->size) end = af->size - evt->t + n;
- // This should not be necessary but make absolutely shure that we do
+ // This should not be necessary but make absolutely sure that we do
// not write over the end of the buffer.
if(end > sz) end = sz;
size_t t = 0; // Internal buffer counter
if(evt->rampdown == NO_RAMPDOWN) {
+ if(n > 0) {
+ // We cannot use SIMD on this buffer.
+ for(; n < end; n++) {
+ s[n] += evt->buffer[t];
+ t++;
+ }
+ }
#ifdef SSE
size_t optend = ((end - n) / N) * N + n;
- for(; n < optend; n += N) {
+ for(; (n < optend) && (t < evt->buffer_size); n += N) {
*(vNsf*)&(s[n]) += *(vNsf*)&(evt->buffer[t]);
t += N;
}
@@ -454,21 +461,19 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t *s, size_t sz)
t++;
evt->rampdown--;
}
-
- if(evt->rampdown == 0) {
- removeevent = true; // Down ramp done. Remove event.
- cacheManager.close(evt->cache_id);
- }
}
+
evt->t += t; // Add internal buffer counter to "global" event counter.
- if(evt->t >= af->size) {
- removeevent = true;
- cacheManager.close(evt->cache_id);
- } else {
+ if((evt->t < af->size) && (evt->rampdown != 0)) {
evt->buffer = cacheManager.next(evt->cache_id, evt->buffer_size);
+ } else {
+ removeevent = true;
}
+ if(removeevent) {
+ cacheManager.close(evt->cache_id);
+ }
}
}
break;