uses lookup table for pitch
This commit is contained in:
parent
6a00521656
commit
7813659494
|
|
@ -48,6 +48,8 @@ void Module::run(Voice* voice) {
|
|||
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;
|
||||
|
||||
for (uint32_t i = 0; i < NUM_VOICES; i++) {
|
||||
switch (voice[i].envPhase) {
|
||||
case 0: // release phase FIXME use an enum I guess
|
||||
|
|
@ -70,8 +72,10 @@ void Module::run(Voice* voice) {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,19 +71,22 @@ class Module {
|
|||
class Voice {
|
||||
public:
|
||||
Voice();
|
||||
void on(uint8_t note);
|
||||
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
|
||||
|
|
|
|||
|
|
@ -85,3 +85,19 @@ uint16_t lfoRateTable[128] = {
|
|||
|
||||
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
|
||||
};
|
||||
|
|
@ -38,8 +38,10 @@ Voice::Voice() {
|
|||
env = 0;
|
||||
}
|
||||
|
||||
void Voice::on(uint8_t note) {
|
||||
omega = 261.63 * powf(2, (note - 60) / 12.0f) / 48000.0f;
|
||||
void Voice::on(uint8_t midiNote) {
|
||||
//omega = 261.63 * powf(2, (note - 60) / 12.0f) / 48000.0f;
|
||||
if (midiNote>24) note = midiNote-24;
|
||||
else note = 24;
|
||||
envPhase = 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue