Skip to content

Commit

Permalink
Correct offset
Browse files Browse the repository at this point in the history
  • Loading branch information
falkTX committed Jul 17, 2016
1 parent a26418b commit 8fac001
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions drmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ static inline void trigger_sample(DrMr *drmr, int nn, uint8_t* const data, uint3
build_midi_info_message(drmr,data);
}
drmr->samples[nn].active = 1;
drmr->samples[nn].offset = offset;
drmr->samples[nn].offset = 0;
drmr->samples[nn].velocity = drmr->ignore_velocity?1.0f:((float)data[2])/VELOCITY_MAX;
drmr->samples[nn].dataoffset = offset;
}
pthread_mutex_unlock(&drmr->load_mutex);
}
Expand All @@ -259,7 +260,8 @@ 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 = offset;
drmr->samples[nn].offset = 0;
drmr->samples[nn].dataoffset = offset;
}
pthread_mutex_unlock(&drmr->load_mutex);
}
Expand Down Expand Up @@ -378,7 +380,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
for (i = 0;i < drmr->num_samples;i++) {
int pos,lim;
drmr_sample* cs = drmr->samples+i;
if (cs->active && (cs->limit > 0)) {
if ((cs->active || cs->dataoffset) && (cs->limit > 0)) {
float coef_right, coef_left;
if (i < 32) {
float gain = DB_CO(*(drmr->gains[i]));
Expand All @@ -390,18 +392,20 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
else {
coef_right = coef_left = 1.0f;
}
uint32_t dataoffset = 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 = 0;pos < lim;pos++) {
for(pos = dataoffset; pos < lim; 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=0;pos<lim;pos++) {
for (pos = dataoffset; pos < lim; 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.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct {
float velocity;
drmr_layer *layers;
float* data;
uint32_t dataoffset;
} drmr_sample;

// lv2 stuff
Expand Down

0 comments on commit 8fac001

Please sign in to comment.