Skip to content

Commit

Permalink
Fix note-off timing (and crash)
Browse files Browse the repository at this point in the history
  • Loading branch information
falkTX committed Jul 17, 2016
1 parent 8fac001 commit 25ecafb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions drmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ static inline void untrigger_sample(DrMr *drmr, int nn, uint32_t offset) {
fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]);
}
drmr->samples[nn].active = 0;
drmr->samples[nn].offset = 0;
drmr->samples[nn].dataoffset = offset;
}
pthread_mutex_unlock(&drmr->load_mutex);
Expand Down Expand Up @@ -378,7 +377,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) {

pthread_mutex_lock(&drmr->load_mutex);
for (i = 0;i < drmr->num_samples;i++) {
int pos,lim;
uint32_t pos,lim;
drmr_sample* cs = drmr->samples+i;
if ((cs->active || cs->dataoffset) && (cs->limit > 0)) {
float coef_right, coef_left;
Expand All @@ -392,20 +391,28 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
else {
coef_right = coef_left = 1.0f;
}
uint32_t dataoffset = cs->dataoffset;

uint32_t datastart, dataend;
if (cs->active) {
datastart = cs->dataoffset;
dataend = (uint32_t)-1;
} else {
datastart = 0;
dataend = cs->dataoffset;
}
cs->dataoffset = 0;

if (cs->info->channels == 1) { // play mono sample
lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset));
for(pos = dataoffset; pos < lim; pos++) {
for (pos = datastart; pos < lim && pos < dataend; pos++) {
drmr->left[pos] += cs->data[cs->offset]*coef_left;
drmr->right[pos] += cs->data[cs->offset]*coef_right;
cs->offset++;
}
} else { // play stereo sample
lim = (cs->limit-cs->offset)/cs->info->channels;
if (lim > n_samples) lim = n_samples;
for (pos = dataoffset; pos < lim; pos++) {
for (pos = datastart; pos < lim && pos < dataend; pos++) {
drmr->left[pos] += cs->data[cs->offset++]*coef_left;
drmr->right[pos] += cs->data[cs->offset++]*coef_right;
}
Expand Down
1 change: 1 addition & 0 deletions drmr_hydrogen.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ drmr_sample* load_hydrogen_kit(char *path, double rate, int *num_samples) {
samples[i].data = NULL;
}
samples[i].active = 0;
samples[i].dataoffset = 0;
i_to_free = cur_i;
cur_i = cur_i->next;

Expand Down

0 comments on commit 25ecafb

Please sign in to comment.