From fcadaf3980a2160f85f87b6d86300d2b77cf058d Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Mon, 18 Aug 2025 00:27:23 +0100 Subject: [PATCH] pretty reasonable viola --- plugin/generator.cpp | 35 ++++++++++++++++++++++++++++------- plugin/generator.hpp | 3 +++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/plugin/generator.cpp b/plugin/generator.cpp index 24c0108..2d9a03a 100644 --- a/plugin/generator.cpp +++ b/plugin/generator.cpp @@ -53,34 +53,55 @@ void Generator::runBlock(float *output, uint8_t *noteTable, uint32_t frames) { for (k = 0; k < NUM_VOICES; k++) { key = noteTable[k] & 0x7f; n1 = key % 12, n2 = (key / 12 - 3); + v = &voices[k]; + d = (phase[n1] & (0x40000000 >> n2)) != 0; n = d ? 0.25 : -0.25; - - v = &voices[k]; v->vc34 = ((n - v->vc34) * v->c34) + v->vc34; n -= v->vc34; n *= d ? 1 : 0; - v->vc78 = ((n - v->vc78) * v->c78) + v->vc78; 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; - 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) { // start a new note - // float fc = 88.4 * powf(2, 0.083334 * (key - 36)); - // c34 = powf((1 - 2 * fc / sampleRate), 2); + // violin and viola filter params float fc = 88.4 * powf(2, 0.083334 * (key - 24)); 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)); 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); + + // 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; vcatc = 0.0001; } diff --git a/plugin/generator.hpp b/plugin/generator.hpp index a222842..0b36a75 100644 --- a/plugin/generator.hpp +++ b/plugin/generator.hpp @@ -34,7 +34,10 @@ class Voice { private: uint8_t semi, oct; + float c22 = 0, vc22 = 0; + float c31 = 0, vc31 = 0; float c34 = 0, vc34 = 0; + float c33 = 0, vc33 = 0; float c78 = 0, vc78 = 0; float c107 = 0, vc107 = 0; float vca = 0, vcatc = 0, gate = 0;