Fix note-off timing (and crash)

This commit is contained in:
falkTX 2016-07-17 15:56:43 +02:00
parent 8fac001331
commit 25ecafb56f
2 changed files with 13 additions and 5 deletions

17
drmr.c
View File

@ -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]); fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]);
} }
drmr->samples[nn].active = 0; drmr->samples[nn].active = 0;
drmr->samples[nn].offset = 0;
drmr->samples[nn].dataoffset = offset; drmr->samples[nn].dataoffset = offset;
} }
pthread_mutex_unlock(&drmr->load_mutex); pthread_mutex_unlock(&drmr->load_mutex);
@ -378,7 +377,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
pthread_mutex_lock(&drmr->load_mutex); pthread_mutex_lock(&drmr->load_mutex);
for (i = 0;i < drmr->num_samples;i++) { for (i = 0;i < drmr->num_samples;i++) {
int pos,lim; uint32_t pos,lim;
drmr_sample* cs = drmr->samples+i; drmr_sample* cs = drmr->samples+i;
if ((cs->active || cs->dataoffset) && (cs->limit > 0)) { if ((cs->active || cs->dataoffset) && (cs->limit > 0)) {
float coef_right, coef_left; float coef_right, coef_left;
@ -392,12 +391,20 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
else { else {
coef_right = coef_left = 1.0f; 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; cs->dataoffset = 0;
if (cs->info->channels == 1) { // play mono sample if (cs->info->channels == 1) { // play mono sample
lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset)); 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->left[pos] += cs->data[cs->offset]*coef_left;
drmr->right[pos] += cs->data[cs->offset]*coef_right; drmr->right[pos] += cs->data[cs->offset]*coef_right;
cs->offset++; cs->offset++;
@ -405,7 +412,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
} else { // play stereo sample } else { // play stereo sample
lim = (cs->limit-cs->offset)/cs->info->channels; lim = (cs->limit-cs->offset)/cs->info->channels;
if (lim > n_samples) lim = n_samples; 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->left[pos] += cs->data[cs->offset++]*coef_left;
drmr->right[pos] += cs->data[cs->offset++]*coef_right; drmr->right[pos] += cs->data[cs->offset++]*coef_right;
} }

View File

@ -565,6 +565,7 @@ drmr_sample* load_hydrogen_kit(char *path, double rate, int *num_samples) {
samples[i].data = NULL; samples[i].data = NULL;
} }
samples[i].active = 0; samples[i].active = 0;
samples[i].dataoffset = 0;
i_to_free = cur_i; i_to_free = cur_i;
cur_i = cur_i->next; cur_i = cur_i->next;