From 792e6e59b51afe676cd9a6671a62f8ee99b5f1b6 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Fri, 19 Dec 2025 22:53:59 +0000 Subject: [PATCH] pitch and pw lfo working --- plugin/Makefile | 1 + plugin/module.cpp | 61 +++++++++++++++----------- plugin/module.hpp | 44 ++++++++++--------- plugin/tables.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++++++ plugin/tables.hpp | 89 +++++--------------------------------- plugin/voice.cpp | 22 ++++++---- 6 files changed, 192 insertions(+), 132 deletions(-) create mode 100644 plugin/tables.cpp diff --git a/plugin/Makefile b/plugin/Makefile index 306d0cb..ea645b8 100644 --- a/plugin/Makefile +++ b/plugin/Makefile @@ -13,6 +13,7 @@ FILES_DSP = \ assigner.cpp \ module.cpp \ voice.cpp \ + tables.cpp \ peacock.cpp include ../dpf/Makefile.plugins.mk diff --git a/plugin/module.cpp b/plugin/module.cpp index f51c34d..eee33e1 100644 --- a/plugin/module.cpp +++ b/plugin/module.cpp @@ -37,45 +37,58 @@ void Module::run(Voice* voice) { square = (patchRam.switch2 & 0x08) ? 0.63 : 0; saw = (patchRam.switch2 & 0x10) ? 0.8 : 0; sub = patchRam.sub / 127.0f; + lfoPhase += lfoRateTable[patchRam.lfoRate]; - // printf("%f %f %f %02x\n", square, saw, sub, patchRam.switch2); + if (lfoPhase & 0x4000) + lfo = 0x1fff - (lfoPhase & 0x3fff); + else + lfo = (lfoPhase & 0x3fff) - 0x1fff; - // work out the "master" cutoff - // vcfCutoff = patchRam.vcfFreq / 127.0f; - // vcfCutoff += lfo * (patchRam.vcfLfo / 127.0f); - // also needs pitch bend amount for the base level + pw = 0.5- ((0x2000 + lfo) * patchRam.pwmLfo) / (32768.0f*128); + + // printf("%5d\n", (lfo * lfoDepthTable[patchRam.vcoLfo])>>8); int16_t vcf = (patchRam.vcfEnv << 7) * ((patchRam.switch2 & 0x02) ? -1 : 1); - // int16_t vca = (patchRam.vcfEnv << 7) * (patchRam.switch2 & 0x01) ? -1 : 1; int16_t pitchBase = 0x1818; + pitchBase += (lfo * lfoDepthTable[patchRam.vcoLfo]) >> 9; + for (uint32_t i = 0; i < NUM_VOICES; i++) { - switch (voice[i].envPhase) { - case 0: // release phase FIXME use an enum I guess - voice[i].env = (voice[i].env * d) >> 16; // "RC" decay to zero + // maybe move all this into voice.cpp FIXME + Voice* v = &voice[i]; + switch (v->envPhase) { + case 0: // release phase FIXME use an enum I guess + v->env = (v->env * d) >> 16; // "RC" decay to zero break; - case 1: // attack phase - voice[i].env += a; // linear attack to 0x3fff + case 1: // attack phase + v->env += a; // linear attack to 0x3fff break; case 2: - voice[i].env = (((voice[i].env - s) * d) >> 16) + s; + v->env = (((v->env - s) * d) >> 16) + s; break; } - if (voice[i].env > 0x3fff) { - voice[i].env = 0x3fff; - voice[i].envPhase = 2; // flip to decay + if (v->env > 0x3fff) { + v->env = 0x3fff; + v->envPhase = 2; // flip to decay } - // per voice we need to calculate the key follow amount and envelope amount - voice[i].vcfCut = (patchRam.vcfFreq << 7) + ((vcf * voice[i].env) >> 16); - - if (voice[i].vcfCut > 0x3fff) voice[i].vcfCut = 0x3fff; - if (voice[i].vcfCut < 0) voice[i].vcfCut = 0; - - voice[i].vcaEnv = (patchRam.switch2 & 0x04) ? (voice[i].envPhase ? 0x3fff : 0) : voice[i].env; // pitch - float p1 = pitchTable[voice[i].note], p2 = pitchTable[voice[i].note+1]; - voice[i].omega = ((p2-p1)*0.10667 + p1)/48000.0f; // fixme use proper scaler + int16_t pitch = pitchBase + (v->note << 8); + int16_t semi = pitch >> 8; + float frac = (pitch & 0xff) / 256.0; + + float p1 = pitchTable[semi], p2 = pitchTable[semi + 1]; + int16_t px = ((p2 - p1) * frac + p1); + + v->omega = px / 192000.0f; // fixme use proper scaler + + // per voice we need to calculate the key follow amount and envelope amount + v->vcfCut = (patchRam.vcfFreq << 7) + ((vcf * v->env) >> 16); + v->vcfCut += (int)(v->note * (patchRam.vcfKey << 1) * 0.375); + + if (v->vcfCut > 0x3fff) v->vcfCut = 0x3fff; + if (v->vcfCut < 0) v->vcfCut = 0; + v->vcaEnv = (patchRam.switch2 & 0x04) ? (v->envPhase ? 0x3fff : 0) : v->env; } } diff --git a/plugin/module.hpp b/plugin/module.hpp index 7a2a930..3d4bb7e 100644 --- a/plugin/module.hpp +++ b/plugin/module.hpp @@ -26,41 +26,42 @@ class Voice; class Module { + public: Module(); void run(Voice* voice); // Voice voices[NUM_VOICES]; float vcfCutoff = 0, vcfReso = 0; - float lfo = 0, lfoTheta = 0; - - // precomputed values for all voices - float pw;//, saw, square, sub; + // precomputed values for all voices + float pw; //, saw, square, sub; // "internal state" values for patch parameters uint16_t a, d, s, r; + int16_t lfo; + uint32_t lfoPhase; float saw = 0, square = 0, sub = 0, noise = 0; struct { - uint8_t lfoRate = 0x30; // lookup value defaults to 0x0200 + uint8_t lfoRate = 0x18; uint8_t lfoDelay = 0x00; - uint8_t vcoLfo = 0x0a; - uint8_t pwmLfo = 0x30; + uint8_t vcoLfo = 0x00; + uint8_t pwmLfo = 0x60; uint8_t noise = 0x00; - uint8_t vcfFreq = 0x4c; // 0x3f80 + uint8_t vcfFreq = 0x10;//1c; // 0x3f80 uint8_t vcfReso = 0x00; - uint8_t vcfEnv = 0x4e; + uint8_t vcfEnv = 0x40;//4e; uint8_t vcfLfo = 0; - uint8_t vcfKey = 0x47; + uint8_t vcfKey = 0x7f; // 47; uint8_t vca = 0x28; uint8_t env_a = 0x00; uint8_t env_d = 0x39; - uint8_t env_s = 0x39; // 0x3f80 + uint8_t env_s = 0x30; // 0x3f80 uint8_t env_r = 0x30; - uint8_t sub = 0x7f; + uint8_t sub = 0x40; uint8_t switch1 = 0x1a; - uint8_t switch2 = 0x18; + uint8_t switch2 = 0x08; } patchRam; private: @@ -69,28 +70,29 @@ class Module { }; class Voice { + friend Module; public: Voice(); void on(uint8_t midiNote); void off(); void run(Module* m, float* buffer, uint32_t samples); - uint8_t envPhase = 0; - int16_t env = 0; // output amplitude - int16_t vcfCut; - int16_t vcaEnv; - uint8_t note=0; - - float omega; private: // control float vcaRC = 0, vcfRC = 0; - float /*omega = 0,*/ theta = 0; // phase increment and angle FIXME better names + float omega = 0, theta = 0; // phase increment and angle FIXME better names float delay = 0, lastpw = 0; // delay slots for antialiasing uint8_t pulseStage = 1; // pulse wave phase float subosc = 1; // sub oscillator flipflop output + uint8_t envPhase = 0; + int16_t env = 0; // output amplitude + int16_t vcfCut; + int16_t vcaEnv; + float vcaEnvRC = 0; + uint8_t note = 0; + // filter float b1 = 0, b2 = 0, b3 = 0, b4 = 0; }; diff --git a/plugin/tables.cpp b/plugin/tables.cpp new file mode 100644 index 0000000..e08bf4a --- /dev/null +++ b/plugin/tables.cpp @@ -0,0 +1,107 @@ +/* + Chassis polysynth framework + + Copyright 2024 Gordon JC Pearce + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef __TABLES_HPP +#define __TABLES_HPP + +#include + +uint16_t attackTable[128] = { + 0x4000, 0x2000, 0x1000, 0x0aaa, 0x0800, 0x0666, 0x0555, 0x0492, 0x0400, + 0x038e, 0x0333, 0x02e9, 0x02ab, 0x0276, 0x0249, 0x0222, 0x0200, 0x01e2, + 0x01c7, 0x01af, 0x0199, 0x0186, 0x0174, 0x0164, 0x0155, 0x0148, 0x013b, + 0x012f, 0x0124, 0x011a, 0x0111, 0x0108, 0x0100, 0x00f8, 0x00f1, 0x00ea, + 0x00e4, 0x00dd, 0x00d8, 0x00d2, 0x00cd, 0x00c8, 0x00c3, 0x00bf, 0x00ba, + 0x00b6, 0x00b2, 0x00ae, 0x00ab, 0x00a7, 0x00a4, 0x00a1, 0x009e, 0x009b, + 0x0098, 0x0095, 0x0092, 0x0090, 0x008d, 0x008b, 0x0089, 0x0086, 0x0084, + 0x0082, 0x007f, 0x007d, 0x007a, 0x0077, 0x0074, 0x0072, 0x006f, 0x006c, + 0x0069, 0x0067, 0x0064, 0x0061, 0x005e, 0x005c, 0x0059, 0x0056, 0x0053, + 0x0050, 0x004e, 0x004b, 0x0048, 0x0045, 0x0042, 0x0040, 0x003f, 0x003d, + 0x003c, 0x003a, 0x0039, 0x0037, 0x0036, 0x0034, 0x0033, 0x0031, 0x0030, + 0x002e, 0x002d, 0x002b, 0x002a, 0x0028, 0x0027, 0x0025, 0x0024, 0x0022, + 0x0021, 0x0021, 0x0020, 0x0020, 0x001f, 0x001f, 0x001e, 0x001e, 0x001d, + 0x001d, 0x001c, 0x001c, 0x001b, 0x001b, 0x001a, 0x0019, 0x0018, 0x0017, + 0x0016, 0x0015}; + +uint16_t decayTable[128] = { + 0x1000, 0x3000, 0x5000, 0x7000, 0x9000, 0xa000, 0xa800, 0xb000, 0xb800, + 0xc000, 0xc800, 0xd000, 0xd800, 0xe000, 0xe800, 0xf000, 0xf080, 0xf100, + 0xf180, 0xf200, 0xf280, 0xf300, 0xf380, 0xf400, 0xf480, 0xf500, 0xf580, + 0xf600, 0xf680, 0xf700, 0xf780, 0xf800, 0xf880, 0xf900, 0xf980, 0xfa00, + 0xfa80, 0xfb00, 0xfb80, 0xfc00, 0xfc80, 0xfd00, 0xfd80, 0xfe00, 0xfe0c, + 0xfe18, 0xfe24, 0xfe30, 0xfe3c, 0xfe48, 0xfe54, 0xfe60, 0xfe6c, 0xfe78, + 0xfe84, 0xfe90, 0xfe9c, 0xfea8, 0xfeb4, 0xfec0, 0xfecc, 0xfed8, 0xfee4, + 0xfef0, 0xfefc, 0xff08, 0xff0c, 0xff10, 0xff14, 0xff18, 0xff1c, 0xff20, + 0xff24, 0xff28, 0xff2c, 0xff30, 0xff34, 0xff38, 0xff3c, 0xff40, 0xff44, + 0xff48, 0xff4c, 0xff50, 0xff54, 0xff58, 0xff5c, 0xff60, 0xff64, 0xff68, + 0xff6c, 0xff70, 0xff74, 0xff78, 0xff7c, 0xff80, 0xff84, 0xff88, 0xff8c, + 0xff90, 0xff94, 0xff98, 0xff9c, 0xffa0, 0xffa4, 0xffa8, 0xffac, 0xffb0, + 0xffb4, 0xffb8, 0xffbc, 0xffc0, 0xffc4, 0xffc8, 0xffcc, 0xffd0, 0xffd4, + 0xffd8, 0xffdc, 0xffe0, 0xffe4, 0xffe8, 0xffec, 0xfff0, 0xfff1, 0xfff2, + 0xfff3, 0xfff4}; + +uint8_t lfoDepthTable[128] = { + 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, + 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, + 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, + 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x60, 0x62, 0x64, + 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, + 0x80, 0x84, 0x88, 0x8c, 0x90, 0x94, 0x98, 0x9c, 0xa0, 0xa4, 0xa8, 0xac, + 0xb0, 0xb4, 0xb8, 0xbc, 0xc0, 0xc4, 0xc8, 0xcc, 0xd0, 0xd4, 0xd8, 0xdc, + 0xe0, 0xe4, 0xe8, 0xec, 0xf0, 0xf8, 0xff, 0xff}; + +uint16_t lfoRateTable[128] = { + 0x0005, 0x000f, 0x0019, 0x0028, 0x0037, 0x0046, 0x0050, 0x005a, 0x0064, + 0x006e, 0x0078, 0x0082, 0x008c, 0x0096, 0x00a0, 0x00aa, 0x00b4, 0x00be, + 0x00c8, 0x00d2, 0x00dc, 0x00e6, 0x00f0, 0x00fa, 0x0104, 0x010e, 0x0118, + 0x0122, 0x012c, 0x0136, 0x0140, 0x014a, 0x0154, 0x015e, 0x0168, 0x0172, + 0x017c, 0x0186, 0x0190, 0x019a, 0x01a4, 0x01ae, 0x01b8, 0x01c2, 0x01cc, + 0x01d6, 0x01e0, 0x01ea, 0x01f4, 0x01fe, 0x0208, 0x0212, 0x021c, 0x0226, + 0x0230, 0x023a, 0x0244, 0x024e, 0x0258, 0x0262, 0x026c, 0x0276, 0x0280, + 0x028a, 0x029a, 0x02aa, 0x02ba, 0x02ca, 0x02da, 0x02ea, 0x02fa, 0x030a, + 0x031a, 0x032a, 0x033a, 0x034a, 0x035a, 0x036a, 0x037a, 0x038a, 0x039a, + 0x03aa, 0x03ba, 0x03ca, 0x03da, 0x03ea, 0x03fa, 0x040a, 0x041a, 0x042a, + 0x043a, 0x044a, 0x045a, 0x046a, 0x047a, 0x048a, 0x04be, 0x04f2, 0x0526, + 0x055a, 0x058e, 0x05c2, 0x05f6, 0x062c, 0x0672, 0x06b8, 0x0708, 0x0758, + 0x07a8, 0x07f8, 0x085c, 0x08c0, 0x0924, 0x0988, 0x09ec, 0x0a50, 0x0ab4, + 0x0b18, 0x0b7c, 0x0be0, 0x0c58, 0x0cd0, 0x0d48, 0x0dde, 0x0e74, 0x0f0a, + 0x0fa0, 0x1000}; + +uint16_t lfoDelayTable[8] = { + 0xffff, 0x0419, 0x020c, 0x015e, 0x0100, 0x0100, 0x0100, 0x0100}; + +float pitchTable[104] = { +32.494, 34.430, 36.486, 38.658, 40.962, 43.399, 45.990, 48.731, +51.633, 54.711, 57.969, 61.419, 65.072, 68.944, 73.059, 77.405, +82.014, 86.892, 92.077, 97.556, 103.365, 109.529, 116.043, 122.933, +130.242, 137.988, 146.220, 154.919, 164.136, 173.898, 184.264, 195.217, +206.847, 219.178, 232.207, 245.972, 260.586, 276.091, 292.569, 309.981, +328.407, 347.947, 368.664, 390.549, 413.822, 438.500, 464.576, 492.005, +521.241, 552.334, 585.309, 620.155, 657.030, 696.136, 737.463, 781.250, +827.815, 877.193, 929.368, 984.252, 1042.753, 1104.972, 1170.960, 1240.695, +1314.060, 1392.758, 1474.926, 1562.500, 1655.629, 1754.386, 1858.736, 1968.504, +2085.506, 2209.945, 2341.920, 2481.390, 2628.121, 2785.515, 2949.853, 3125.000, +3311.258, 3508.772, 3717.472, 3937.008, 4175.365, 4424.779, 4683.841, 4962.779, +5263.158, 5571.031, 5899.705, 6250.000, 6622.517, 7017.544, 7434.944, 7874.016, +8333.333, 8849.558, 9389.671, 9950.249, 10526.316, 11173.184, 11834.320, 12500.000 +}; + +#endif \ No newline at end of file diff --git a/plugin/tables.hpp b/plugin/tables.hpp index 98ab353..014fe22 100644 --- a/plugin/tables.hpp +++ b/plugin/tables.hpp @@ -16,88 +16,19 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma once +#ifndef __TABLES_HPP +#define __TABLES_HPP + #include -uint16_t attackTable[128] = { - 0x4000, 0x2000, 0x1000, 0x0aaa, 0x0800, 0x0666, 0x0555, 0x0492, 0x0400, - 0x038e, 0x0333, 0x02e9, 0x02ab, 0x0276, 0x0249, 0x0222, 0x0200, 0x01e2, - 0x01c7, 0x01af, 0x0199, 0x0186, 0x0174, 0x0164, 0x0155, 0x0148, 0x013b, - 0x012f, 0x0124, 0x011a, 0x0111, 0x0108, 0x0100, 0x00f8, 0x00f1, 0x00ea, - 0x00e4, 0x00dd, 0x00d8, 0x00d2, 0x00cd, 0x00c8, 0x00c3, 0x00bf, 0x00ba, - 0x00b6, 0x00b2, 0x00ae, 0x00ab, 0x00a7, 0x00a4, 0x00a1, 0x009e, 0x009b, - 0x0098, 0x0095, 0x0092, 0x0090, 0x008d, 0x008b, 0x0089, 0x0086, 0x0084, - 0x0082, 0x007f, 0x007d, 0x007a, 0x0077, 0x0074, 0x0072, 0x006f, 0x006c, - 0x0069, 0x0067, 0x0064, 0x0061, 0x005e, 0x005c, 0x0059, 0x0056, 0x0053, - 0x0050, 0x004e, 0x004b, 0x0048, 0x0045, 0x0042, 0x0040, 0x003f, 0x003d, - 0x003c, 0x003a, 0x0039, 0x0037, 0x0036, 0x0034, 0x0033, 0x0031, 0x0030, - 0x002e, 0x002d, 0x002b, 0x002a, 0x0028, 0x0027, 0x0025, 0x0024, 0x0022, - 0x0021, 0x0021, 0x0020, 0x0020, 0x001f, 0x001f, 0x001e, 0x001e, 0x001d, - 0x001d, 0x001c, 0x001c, 0x001b, 0x001b, 0x001a, 0x0019, 0x0018, 0x0017, - 0x0016, 0x0015}; +extern uint16_t attackTable[128]; -uint16_t decayTable[128] = { - 0x1000, 0x3000, 0x5000, 0x7000, 0x9000, 0xa000, 0xa800, 0xb000, 0xb800, - 0xc000, 0xc800, 0xd000, 0xd800, 0xe000, 0xe800, 0xf000, 0xf080, 0xf100, - 0xf180, 0xf200, 0xf280, 0xf300, 0xf380, 0xf400, 0xf480, 0xf500, 0xf580, - 0xf600, 0xf680, 0xf700, 0xf780, 0xf800, 0xf880, 0xf900, 0xf980, 0xfa00, - 0xfa80, 0xfb00, 0xfb80, 0xfc00, 0xfc80, 0xfd00, 0xfd80, 0xfe00, 0xfe0c, - 0xfe18, 0xfe24, 0xfe30, 0xfe3c, 0xfe48, 0xfe54, 0xfe60, 0xfe6c, 0xfe78, - 0xfe84, 0xfe90, 0xfe9c, 0xfea8, 0xfeb4, 0xfec0, 0xfecc, 0xfed8, 0xfee4, - 0xfef0, 0xfefc, 0xff08, 0xff0c, 0xff10, 0xff14, 0xff18, 0xff1c, 0xff20, - 0xff24, 0xff28, 0xff2c, 0xff30, 0xff34, 0xff38, 0xff3c, 0xff40, 0xff44, - 0xff48, 0xff4c, 0xff50, 0xff54, 0xff58, 0xff5c, 0xff60, 0xff64, 0xff68, - 0xff6c, 0xff70, 0xff74, 0xff78, 0xff7c, 0xff80, 0xff84, 0xff88, 0xff8c, - 0xff90, 0xff94, 0xff98, 0xff9c, 0xffa0, 0xffa4, 0xffa8, 0xffac, 0xffb0, - 0xffb4, 0xffb8, 0xffbc, 0xffc0, 0xffc4, 0xffc8, 0xffcc, 0xffd0, 0xffd4, - 0xffd8, 0xffdc, 0xffe0, 0xffe4, 0xffe8, 0xffec, 0xfff0, 0xfff1, 0xfff2, - 0xfff3, 0xfff4}; +extern uint16_t decayTable[128]; -uint8_t lfoDepthTable[128] = { - 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, - 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, - 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, - 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, - 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x60, 0x62, 0x64, - 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, - 0x80, 0x84, 0x88, 0x8c, 0x90, 0x94, 0x98, 0x9c, 0xa0, 0xa4, 0xa8, 0xac, - 0xb0, 0xb4, 0xb8, 0xbc, 0xc0, 0xc4, 0xc8, 0xcc, 0xd0, 0xd4, 0xd8, 0xdc, - 0xe0, 0xe4, 0xe8, 0xec, 0xf0, 0xf8, 0xff, 0xff}; +extern uint8_t lfoDepthTable[128]; +extern uint16_t lfoRateTable[128]; -uint16_t lfoRateTable[128] = { - 0x0005, 0x000f, 0x0019, 0x0028, 0x0037, 0x0046, 0x0050, 0x005a, 0x0064, - 0x006e, 0x0078, 0x0082, 0x008c, 0x0096, 0x00a0, 0x00aa, 0x00b4, 0x00be, - 0x00c8, 0x00d2, 0x00dc, 0x00e6, 0x00f0, 0x00fa, 0x0104, 0x010e, 0x0118, - 0x0122, 0x012c, 0x0136, 0x0140, 0x014a, 0x0154, 0x015e, 0x0168, 0x0172, - 0x017c, 0x0186, 0x0190, 0x019a, 0x01a4, 0x01ae, 0x01b8, 0x01c2, 0x01cc, - 0x01d6, 0x01e0, 0x01ea, 0x01f4, 0x01fe, 0x0208, 0x0212, 0x021c, 0x0226, - 0x0230, 0x023a, 0x0244, 0x024e, 0x0258, 0x0262, 0x026c, 0x0276, 0x0280, - 0x028a, 0x029a, 0x02aa, 0x02ba, 0x02ca, 0x02da, 0x02ea, 0x02fa, 0x030a, - 0x031a, 0x032a, 0x033a, 0x034a, 0x035a, 0x036a, 0x037a, 0x038a, 0x039a, - 0x03aa, 0x03ba, 0x03ca, 0x03da, 0x03ea, 0x03fa, 0x040a, 0x041a, 0x042a, - 0x043a, 0x044a, 0x045a, 0x046a, 0x047a, 0x048a, 0x04be, 0x04f2, 0x0526, - 0x055a, 0x058e, 0x05c2, 0x05f6, 0x062c, 0x0672, 0x06b8, 0x0708, 0x0758, - 0x07a8, 0x07f8, 0x085c, 0x08c0, 0x0924, 0x0988, 0x09ec, 0x0a50, 0x0ab4, - 0x0b18, 0x0b7c, 0x0be0, 0x0c58, 0x0cd0, 0x0d48, 0x0dde, 0x0e74, 0x0f0a, - 0x0fa0, 0x1000}; +extern uint16_t lfoDelayTable[8]; +extern float pitchTable[104]; -uint16_t lfoDelayTable[8] = { - 0xffff, 0x0419, 0x020c, 0x015e, 0x0100, 0x0100, 0x0100, 0x0100}; - -float pitchTable[104] = { -32.494, 34.430, 36.486, 38.658, 40.962, 43.399, 45.990, 48.731, -51.633, 54.711, 57.969, 61.419, 65.072, 68.944, 73.059, 77.405, -82.014, 86.892, 92.077, 97.556, 103.365, 109.529, 116.043, 122.933, -130.242, 137.988, 146.220, 154.919, 164.136, 173.898, 184.264, 195.217, -206.847, 219.178, 232.207, 245.972, 260.586, 276.091, 292.569, 309.981, -328.407, 347.947, 368.664, 390.549, 413.822, 438.500, 464.576, 492.005, -521.241, 552.334, 585.309, 620.155, 657.030, 696.136, 737.463, 781.250, -827.815, 877.193, 929.368, 984.252, 1042.753, 1104.972, 1170.960, 1240.695, -1314.060, 1392.758, 1474.926, 1562.500, 1655.629, 1754.386, 1858.736, 1968.504, -2085.506, 2209.945, 2341.920, 2481.390, 2628.121, 2785.515, 2949.853, 3125.000, -3311.258, 3508.772, 3717.472, 3937.008, 4175.365, 4424.779, 4683.841, 4962.779, -5263.158, 5571.031, 5899.705, 6250.000, 6622.517, 7017.544, 7434.944, 7874.016, -8333.333, 8849.558, 9389.671, 9950.249, 10526.316, 11173.184, 11834.320, 12500.000 -}; \ No newline at end of file +#endif \ No newline at end of file diff --git a/plugin/voice.cpp b/plugin/voice.cpp index 6c98a87..51291d0 100644 --- a/plugin/voice.cpp +++ b/plugin/voice.cpp @@ -20,6 +20,7 @@ #include #include "module.hpp" +#include "tables.hpp" // antialiasing using polybleps, as described in KVRAudio forum by Mystran @@ -60,9 +61,6 @@ void Voice::run(Module* m, float* buffer, uint32_t samples) { cut = 0.25 * 6.2832 * cut / 48000.0f; // FIXME hardcoded values cut = cut/(1+cut); // correct tuning warp - // printf("%f ", delay); - m->pw = 0.5; - float amp = vcaEnv / 4096.0f; for (uint32_t i = 0; i < samples; i++) { @@ -100,20 +98,28 @@ void Voice::run(Module* m, float* buffer, uint32_t samples) { delay += m->sub * subosc; // delay += (1-(m->noisegen/(float)(1<<30))) * m->noise; FIXME figure out what to do about noise + //out = 0.5-(rand() & 0xffff) / 65536.0; + out *= 0.5; + float res = 3; + for (uint8_t ovs = 0; ovs < 4; ovs++) { fb = b4; // hard clip - if (fb > 1) fb = 1; - if (fb < -1) fb = -1; + fb = ((out*0.5) - fb) * res; + if (fb > 4) fb = 4; + if (fb < -4) fb = -4; + // fb = 1.5 * fb - 0.5 * fb * fb * fb; +// - fb = out - (fb * 1.7); - b1 = ((fb - b1) * cut) + b1; + b1 = ((out + fb - b1) * cut) + b1; b2 = ((b1 - b2) * cut) + b2; b3 = ((b2 - b3) * cut) + b3; b4 = ((b3 - b4) * cut) + b4; } - buffer[i] += 0.0625 * amp * b4; + vcaEnvRC = (amp - vcaEnvRC) * 0.0203 + vcaEnvRC; + + buffer[i] += 0.0367 * vcaEnvRC * b4; lastpw = m->pw; } // buffer[0] += 1;