violin about right
This commit is contained in:
parent
11ca33ffd8
commit
3226a429d7
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "assigner.hpp"
|
||||
#include "generator.hpp"
|
||||
#define DEBUG
|
||||
//#define DEBUG
|
||||
|
||||
void Assigner::dumpTables() {
|
||||
#ifdef DEBUG
|
||||
|
@ -94,6 +94,9 @@ void Assigner::noteOff(uint8_t note) {
|
|||
memmove(voiceTbl + i, voiceTbl + i + 1, NUM_VOICES - i - 1);
|
||||
voiceTbl[NUM_VOICES - 1] = v;
|
||||
noteTbl[v] |= 0x80;
|
||||
voices[v].stopNote(note, 48000);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Assigner::noteOn(uint8_t note) {
|
||||
|
|
|
@ -38,23 +38,35 @@ void Generator::setupGenerator(double sampleRate) {
|
|||
}
|
||||
|
||||
void Generator::runBlock(float *output, uint8_t *noteTable, uint32_t frames) {
|
||||
Voice *v;
|
||||
uint32_t i;
|
||||
uint8_t k, p, key, n1, n2, d;
|
||||
float n;
|
||||
|
||||
memset(output, 0, frames * sizeof(float));
|
||||
|
||||
for (uint32_t i = 0; i < frames; i++) {
|
||||
for (uint8_t p = 0; p < 12; p++) {
|
||||
for (i = 0; i < frames; i++) {
|
||||
for (p = 0; p < 12; p++) {
|
||||
phase[p] += omega[p];
|
||||
}
|
||||
|
||||
for (uint8_t k = 0; k < NUM_VOICES; k++) {
|
||||
uint8_t n1 = noteTable[k] % 12, n2 = (noteTable[k] / 12 - 3);
|
||||
float n = ((phase[n1] & (0x80000000 >> n2)) ? 0.25 : -0.25);
|
||||
for (k = 0; k < NUM_VOICES; k++) {
|
||||
key = noteTable[k] & 0x7f;
|
||||
n1 = key % 12, n2 = (key / 12 - 3);
|
||||
d = (phase[n1] & (0x40000000 >> n2)) != 0;
|
||||
n = d ? 0.25 : -0.25;
|
||||
|
||||
voices[k].vc34 = ((n - voices[k].vc34) * voices[k].c34) + voices[k].vc34;
|
||||
v = &voices[k];
|
||||
v->vc34 = ((n - v->vc34) * v->c34) + v->vc34;
|
||||
n -= v->vc34;
|
||||
n *= d ? 1 : 0;
|
||||
|
||||
n -= voices[k].vc34;
|
||||
n *= (phase[n1] & (0x80000000 >> n2)) ? 1 : 0;
|
||||
v->vc78 = ((n - v->vc78) * v->c78) + v->vc78;
|
||||
v->vc107 = ((v->vc78 - v->vc107) * v->c107) + v->vc107;
|
||||
|
||||
output[i] += n * (noteTable[k] & 0x80 ? 0 : 1);
|
||||
v->vca = ((v->gate - v->vca) * v->vcatc) + v->vca;
|
||||
|
||||
output[i] += (v->vc78 - v->vc107) * v->vca; //((noteTable[k]&0x80)?0:1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +75,17 @@ void Voice::startNote(uint8_t key, double sampleRate) {
|
|||
// start a new note
|
||||
// float fc = 88.4 * powf(2, 0.083334 * (key - 36));
|
||||
// c34 = powf((1 - 2 * fc / sampleRate), 2);
|
||||
float fc = 88.4 * powf(2, 0.083334 * (key - 36));
|
||||
float coef = 1 - exp(-6.283 * fc / 48000.0);
|
||||
c34 = coef;
|
||||
printf("key = %d, shaper cutoff = %f, coefficient = %f %f\n", key, fc, coef, c34);
|
||||
float fc = 88.4 * powf(2, 0.083334 * (key - 24));
|
||||
c34 = 1 - exp(-6.283 * fc / 48000.0);
|
||||
fc = 4000 * powf(2, 0.06 * (key - 24));
|
||||
c78 = 1 - exp(-6.283 * fc / 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);
|
||||
gate = 1;
|
||||
vcatc = 0.0001;
|
||||
}
|
||||
|
||||
void Voice::stopNote(uint8_t key, double sampleRate) {
|
||||
gate = 0;
|
||||
vcatc = 0.000033;
|
||||
}
|
||||
|
|
|
@ -30,13 +30,16 @@ class Voice {
|
|||
|
||||
public:
|
||||
void startNote(uint8_t key, double sampleRate);
|
||||
void stopNote(uint8_t key, double sampleRate);
|
||||
|
||||
private:
|
||||
uint8_t semi, oct;
|
||||
float c34=0, vc34=0;
|
||||
float c34 = 0, vc34 = 0;
|
||||
float c78 = 0, vc78 = 0;
|
||||
float c107 = 0, vc107 = 0;
|
||||
float vca = 0, vcatc = 0, gate = 0;
|
||||
};
|
||||
|
||||
|
||||
class Generator {
|
||||
public:
|
||||
Generator();
|
||||
|
@ -49,5 +52,4 @@ class Generator {
|
|||
uint32_t omega[12];
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue