118 lines
3.0 KiB
C++
118 lines
3.0 KiB
C++
/*
|
|
Peacock-8 VA polysynth
|
|
|
|
Copyright 2025 Gordon JC Pearce <gordonjcp@gjcp.net>
|
|
|
|
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 _MODULE_HPP
|
|
#define _MODULE_HPP
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "DistrhoPluginInfo.h"
|
|
#include "chorus.hpp"
|
|
|
|
extern double sampleRate;
|
|
|
|
class Voice;
|
|
|
|
class Module {
|
|
public:
|
|
Module();
|
|
~Module();
|
|
|
|
void lfoRampOn();
|
|
|
|
void run(Voice* voices, uint32_t blockLeft);
|
|
|
|
float res = 0;
|
|
// 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 = 0x58;
|
|
uint8_t lfoDelay = 0x00;
|
|
uint8_t vcoLfo = 0x00;
|
|
uint8_t pwmLfo = 0x3b;
|
|
uint8_t noise = 0x00;
|
|
uint8_t vcfFreq = 0x25; // 1c; // 0x3f80
|
|
uint8_t vcfReso = 0x6a;
|
|
uint8_t vcfEnv = 0x25; // 4e;
|
|
uint8_t vcfLfo = 0x00;
|
|
uint8_t vcfKey = 0x00; // 47;
|
|
uint8_t vca = 0x35;
|
|
uint8_t env_a = 0x00;
|
|
uint8_t env_d = 0x3c;
|
|
uint8_t env_s = 0x00; // 0x3f80
|
|
uint8_t env_r = 0x3c;
|
|
uint8_t sub = 0x7f;
|
|
uint8_t switch1 = 0x4a;
|
|
uint8_t switch2 = 0x18;
|
|
} patchRam;
|
|
Chorus* chorus;
|
|
|
|
float vcaTC;
|
|
uint32_t bufPtr = 0;
|
|
|
|
float* vcaBuf;
|
|
float* subBuf;
|
|
float* pwmBuf;
|
|
|
|
private:
|
|
// precalculated coefficients for RC networks
|
|
float pwmTC = 0, subTC = 0, mVcaTC = 0;
|
|
float pwmRC = 0, subRC = 0, vcaRC = 0;
|
|
|
|
uint16_t lfoDelay = 0;
|
|
uint8_t lfoDelayState = 0;
|
|
uint16_t lfoDelayTimer = 0;
|
|
};
|
|
|
|
class Voice {
|
|
friend Module;
|
|
|
|
public:
|
|
Voice();
|
|
void on(uint8_t midiNote);
|
|
void off();
|
|
void run(Module* m, float* buffer, uint32_t samples);
|
|
|
|
private:
|
|
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 vcaRC = 0, vcfRC = 0;
|
|
|
|
uint8_t note = 0;
|
|
|
|
// filter
|
|
float b1 = 0, b2 = 0, b3 = 0, b4 = 0;
|
|
};
|
|
|
|
#endif
|