pretty reasonable viola
This commit is contained in:
parent
3226a429d7
commit
fcadaf3980
|
@ -53,34 +53,55 @@ void Generator::runBlock(float *output, uint8_t *noteTable, uint32_t frames) {
|
||||||
for (k = 0; k < NUM_VOICES; k++) {
|
for (k = 0; k < NUM_VOICES; k++) {
|
||||||
key = noteTable[k] & 0x7f;
|
key = noteTable[k] & 0x7f;
|
||||||
n1 = key % 12, n2 = (key / 12 - 3);
|
n1 = key % 12, n2 = (key / 12 - 3);
|
||||||
|
v = &voices[k];
|
||||||
|
|
||||||
d = (phase[n1] & (0x40000000 >> n2)) != 0;
|
d = (phase[n1] & (0x40000000 >> n2)) != 0;
|
||||||
n = d ? 0.25 : -0.25;
|
n = d ? 0.25 : -0.25;
|
||||||
|
|
||||||
v = &voices[k];
|
|
||||||
v->vc34 = ((n - v->vc34) * v->c34) + v->vc34;
|
v->vc34 = ((n - v->vc34) * v->c34) + v->vc34;
|
||||||
n -= v->vc34;
|
n -= v->vc34;
|
||||||
n *= d ? 1 : 0;
|
n *= d ? 1 : 0;
|
||||||
|
|
||||||
v->vc78 = ((n - v->vc78) * v->c78) + v->vc78;
|
v->vc78 = ((n - v->vc78) * v->c78) + v->vc78;
|
||||||
v->vc107 = ((v->vc78 - v->vc107) * v->c107) + v->vc107;
|
v->vc107 = ((v->vc78 - v->vc107) * v->c107) + v->vc107;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
d = (phase[n1] & (0x80000000 >> n2)) != 0;
|
||||||
|
n = d ? 0.25 : -0.25;
|
||||||
|
v->vc33 = ((n - v->vc33) * v->c33) + v->vc33;
|
||||||
|
n -= v->vc33;
|
||||||
|
n *= d ? 1 : 0;
|
||||||
|
v->vc22 = ((n - v->vc22) * v->c22) + v->vc22;
|
||||||
|
v->vc31 = ((v->vc31 - v->vc31) * v->c31) + v->vc31;
|
||||||
|
|
||||||
|
|
||||||
v->vca = ((v->gate - v->vca) * v->vcatc) + v->vca;
|
v->vca = ((v->gate - v->vca) * v->vcatc) + v->vca;
|
||||||
|
|
||||||
output[i] += (v->vc78 - v->vc107) * v->vca; //((noteTable[k]&0x80)?0:1);
|
float v4 = (v->vc78 - v->vc107);
|
||||||
|
float v8 = (v->vc22 - v->vc31);
|
||||||
|
|
||||||
|
output[i] += (v4 + v8) * v->vca; //((noteTable[k]&0x80)?0:1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::startNote(uint8_t key, double sampleRate) {
|
void Voice::startNote(uint8_t key, double sampleRate) {
|
||||||
// start a new note
|
// start a new note
|
||||||
// float fc = 88.4 * powf(2, 0.083334 * (key - 36));
|
// violin and viola filter params
|
||||||
// c34 = powf((1 - 2 * fc / sampleRate), 2);
|
|
||||||
float fc = 88.4 * powf(2, 0.083334 * (key - 24));
|
float fc = 88.4 * powf(2, 0.083334 * (key - 24));
|
||||||
c34 = 1 - exp(-6.283 * fc / 48000.0);
|
c34 = 1 - exp(-6.283 * fc / 48000.0);
|
||||||
|
c33 = 1 - exp(-6.283 * fc /2 / 48000.0);
|
||||||
|
|
||||||
|
// violin register
|
||||||
fc = 4000 * powf(2, 0.06 * (key - 24));
|
fc = 4000 * powf(2, 0.06 * (key - 24));
|
||||||
c78 = 1 - exp(-6.283 * fc / 48000.0);
|
c78 = 1 - exp(-6.283 * fc / 48000.0);
|
||||||
c107 = 1 - exp(-6.283 * 154.0 / 48000.0);
|
c107 = 1 - exp(-6.283 * 154.0 / 48000.0);
|
||||||
// printf("key = %d, shaper cutoff = %f, coefficient = %f %f\n", key, fc, c78, c34);
|
|
||||||
|
// viola register
|
||||||
|
fc = 6000 * powf(2, 0.07 * (key - 24));
|
||||||
|
c22 = 1 - exp(-6.283 * fc / 48000.0);
|
||||||
|
c31 = 1 - exp(-6.283 * 54.0 / 48000.0);
|
||||||
|
|
||||||
|
|
||||||
gate = 1;
|
gate = 1;
|
||||||
vcatc = 0.0001;
|
vcatc = 0.0001;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,10 @@ class Voice {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t semi, oct;
|
uint8_t semi, oct;
|
||||||
|
float c22 = 0, vc22 = 0;
|
||||||
|
float c31 = 0, vc31 = 0;
|
||||||
float c34 = 0, vc34 = 0;
|
float c34 = 0, vc34 = 0;
|
||||||
|
float c33 = 0, vc33 = 0;
|
||||||
float c78 = 0, vc78 = 0;
|
float c78 = 0, vc78 = 0;
|
||||||
float c107 = 0, vc107 = 0;
|
float c107 = 0, vc107 = 0;
|
||||||
float vca = 0, vcatc = 0, gate = 0;
|
float vca = 0, vcatc = 0, gate = 0;
|
||||||
|
|
Loading…
Reference in New Issue