Add per sample gains (up to sixteen)

This commit is contained in:
Nick Lanham 2012-02-07 09:31:51 +01:00
parent ae0f9aaa53
commit a4c2826def
3 changed files with 246 additions and 13 deletions

76
drmr.c
View File

@ -24,8 +24,8 @@
int load_sample(char* path, drmr_sample* samp) {
SNDFILE* sndf;
int size;
printf("Loading: %s\n",path);
//printf("Loading: %s\n",path);
samp->active = 0;
@ -81,6 +81,9 @@ instantiate(const LV2_Descriptor* descriptor,
return 0;
}
drmr->gains = malloc(16*sizeof(float*));
for(i = 0;i<16;i++) drmr->gains[i] = NULL;
load_hydrogen_kit(drmr,"/usr/share/hydrogen/data/drumkits/GMkit/");
//load_hydrogen_kit(drmr,"/usr/share/hydrogen/data/drumkits/3355606kit/");
@ -102,6 +105,54 @@ connect_port(LV2_Handle instance,
case DRMR_RIGHT:
drmr->right = (float*)data;
break;
case DRMR_GAIN_ONE:
if (data) drmr->gains[0] = (float*)data;
break;
case DRMR_GAIN_TWO:
if (data) drmr->gains[1] = (float*)data;
break;
case DRMR_GAIN_THREE:
if (data) drmr->gains[2] = (float*)data;
break;
case DRMR_GAIN_FOUR:
if (data) drmr->gains[3] = (float*)data;
break;
case DRMR_GAIN_FIVE:
if (data) drmr->gains[4] = (float*)data;
break;
case DRMR_GAIN_SIX:
if (data) drmr->gains[5] = (float*)data;
break;
case DRMR_GAIN_SEVEN:
if (data) drmr->gains[6] = (float*)data;
break;
case DRMR_GAIN_EIGHT:
if (data) drmr->gains[7] = (float*)data;
break;
case DRMR_GAIN_NINE:
if (data) drmr->gains[8] = (float*)data;
break;
case DRMR_GAIN_TEN:
if (data) drmr->gains[9] = (float*)data;
break;
case DRMR_GAIN_ELEVEN:
if (data) drmr->gains[10] = (float*)data;
break;
case DRMR_GAIN_TWELVE:
if (data) drmr->gains[11] = (float*)data;
break;
case DRMR_GAIN_THIRTEEN:
if (data) drmr->gains[12] = (float*)data;
break;
case DRMR_GAIN_FOURTEEN:
if (data) drmr->gains[13] = (float*)data;
break;
case DRMR_GAIN_FIFTEEN:
if (data) drmr->gains[14] = (float*)data;
break;
case DRMR_GAIN_SIXTEEN:
if (data) drmr->gains[15] = (float*)data;
break;
default:
break;
}
@ -139,9 +190,9 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
default:
printf("Unhandeled status: %i\n",(*data)>>4);
}
}
} else printf("unrecognized event\n");
lv2_event_increment(&eit);
}
}
}
first_active = 1;
@ -149,20 +200,21 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
int pos,lim;
drmr_sample* cs = drmr->samples+i;
if (cs->active) {
float gain = *(drmr->gains[i]);
one_active = 1;
if (cs->info.channels == 1) { // play mono sample
lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset));
if (first_active) {
for(pos = 0;pos < lim;pos++) {
drmr->left[pos] = cs->data[cs->offset];
drmr->right[pos] = cs->data[cs->offset];
drmr->left[pos] = cs->data[cs->offset]*gain;
drmr->right[pos] = cs->data[cs->offset]*gain;
cs->offset++;
}
first_active = 0;
} else {
for(pos = 0;pos < lim;pos++) {
drmr->left[pos] += cs->data[cs->offset];
drmr->right[pos] += cs->data[cs->offset];
drmr->left[pos] += cs->data[cs->offset]*gain;
drmr->right[pos] += cs->data[cs->offset]*gain;
cs->offset++;
}
}
@ -171,14 +223,14 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
if (lim > n_samples) lim = n_samples;
if (first_active) {
for (pos=0;pos<lim;pos++) {
drmr->left[pos] = cs->data[cs->offset++];
drmr->right[pos] = cs->data[cs->offset++];
drmr->left[pos] = cs->data[cs->offset++]*gain;
drmr->right[pos] = cs->data[cs->offset++]*gain;
}
first_active = 0;
} else {
for (pos=0;pos<lim;pos++) {
drmr->left[pos] += cs->data[cs->offset++];
drmr->right[pos] += cs->data[cs->offset++];
drmr->left[pos] += cs->data[cs->offset++]*gain;
drmr->right[pos] += cs->data[cs->offset++]*gain;
}
}
}

20
drmr.h
View File

@ -45,6 +45,22 @@ typedef enum {
DRMR_MIDI = 0,
DRMR_LEFT,
DRMR_RIGHT,
DRMR_GAIN_ONE,
DRMR_GAIN_TWO,
DRMR_GAIN_THREE,
DRMR_GAIN_FOUR,
DRMR_GAIN_FIVE,
DRMR_GAIN_SIX,
DRMR_GAIN_SEVEN,
DRMR_GAIN_EIGHT,
DRMR_GAIN_NINE,
DRMR_GAIN_TEN,
DRMR_GAIN_ELEVEN,
DRMR_GAIN_TWELVE,
DRMR_GAIN_THIRTEEN,
DRMR_GAIN_FOURTEEN,
DRMR_GAIN_FIFTEEN,
DRMR_GAIN_SIXTEEN,
DRMR_NUM_PORTS
} DrMrPortIndex;
@ -54,6 +70,10 @@ typedef struct {
float* right;
LV2_Event_Buffer *midi_port;
// params
float** gains;
// URIs
LV2_URI_Map_Feature* map;
struct {

163
drmr.ttl
View File

@ -34,4 +34,165 @@
lv2:index 2;
lv2:symbol "right";
lv2:name "Right";
].
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 3;
lv2:symbol "gain_one";
lv2:name "Sample One Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 4;
lv2:symbol "gain_two";
lv2:name "Sample Two Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 5;
lv2:symbol "gain_three";
lv2:name "Sample Three Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 6;
lv2:symbol "gain_four";
lv2:name "Sample Four Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 7;
lv2:symbol "gain_five";
lv2:name "Sample Five Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 8;
lv2:symbol "gain_siz";
lv2:name "Sample Siz Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 9;
lv2:symbol "gain_seven";
lv2:name "Sample Seven Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 10;
lv2:symbol "gain_eight";
lv2:name "Sample Eight Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 11;
lv2:symbol "gain_nine";
lv2:name "Sample Nine Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 12;
lv2:symbol "gain_ten";
lv2:name "Sample Ten Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 13;
lv2:symbol "gain_eleven";
lv2:name "Sample Eleven Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 14;
lv2:symbol "gain_twelve";
lv2:name "Sample Twelve Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 15;
lv2:symbol "gain_thirteen";
lv2:name "Sample Thirteen Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 16;
lv2:symbol "gain_fourteen";
lv2:name "Sample Fourteen Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 17;
lv2:symbol "gain_fifteen";
lv2:name "Sample Fifteen Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 18;
lv2:symbol "gain_sixteen";
lv2:name "Sample Sixteen Gain";
lv2:minimum 0.0;
lv2:maximum 1.0;
lv2:default 1.0;
].