added filter, not properly connected

This commit is contained in:
Gordon JC Pearce 2024-10-19 19:49:24 +01:00
parent 202ddac184
commit d15b80a46b
5 changed files with 24 additions and 10 deletions

View File

@ -14,6 +14,7 @@ FILES_DSP = \
controls.cpp \
ic1.cpp \
oscillator.cpp \
filter.cpp \
ic29.cpp
include ../dpf/Makefile.plugins.mk

View File

@ -35,6 +35,15 @@ void Synth::buildTables(double sampleRate) {
// on the real synth the tuning knob is tweaked a little off to pull it in
pitchTable[i] = 260.15f * powf(2, (i - 36) / 12.0f) / sampleRate;
}
// precompute a table of values to map the filter value to a filter coefficient
// the ROM preset for adjusting the VCF scale and centre presets cutoff to $31
// and key scale to $7f, which corresponds to C4 = 248Hz and C6 = 992Hz, B3 and B5
for (uint16_t i = 0; i< 256; i++) {
}
}
void Synth::run() {

View File

@ -73,11 +73,13 @@ class Voice {
Voice();
uint8_t note = 0x3c; // middle C
void run(float *buffer, uint32_t pos, uint32_t samples);
void filter(float *buffer, uint32_t pos, uint32_t samples);
void update();
void on(uint8_t note);
void off();
private:
// private:
Envelope env; // calculated envelope value
uint16_t pitch = 0x1818; // calculated pitch value with porta and master pitch etc
float delay = 0; // delay slot for polyblep
@ -91,6 +93,8 @@ class Voice {
V_ON } voiceState;
void calcPitch();
float fb=0, b1=0, b2=0, b3=0, b4=0, cut=0.1, reso=4;
};
class Synth {
@ -113,6 +117,7 @@ class Synth {
int8_t portaCoeff;
bool sustained;
double pitchTable[104];
double filterTable[256];
float *noise;

View File

@ -30,8 +30,7 @@ static inline float poly3blep1(float t) {
void Voice::run(float *buffer, uint32_t pos, uint32_t samples) {
// generate a full block of samples for the oscillator
float y, out, t;
float gain = env.level / 16384.0;
float y, t;
if (subosc > 0) subosc = sub; else subosc = -sub;
@ -71,9 +70,8 @@ void Voice::run(float *buffer, uint32_t pos, uint32_t samples) {
delay += subosc;
delay += ic29.noise[i+pos];
out = y * 0.15;
lastpw = pwrc;
buffer[i + pos] += out * gain;
buffer[i + pos] = y * 0.707;
}
}

View File

@ -29,8 +29,6 @@ Peacock::Peacock() : Plugin(paramCount, 0, 0), sampleRate(getSampleRate()) {
ic29.bufferSize = getBufferSize();
}
void Peacock::runMidi(const MidiEvent *ev, uint32_t count, uint32_t timeLimit) {
// handle MIDI events, starting at lastEvent and continuing until timeLimit
uint32_t i;
@ -52,7 +50,6 @@ void Peacock::initAudioPort(bool input, uint32_t index, AudioPort &port) {
if (!input && index == 1) port.name = "Right Out";
}
void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) {
// calculate an entire jack period's worth of samples
// harder than it sounds because for short jack periods there may be many
@ -73,7 +70,7 @@ void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEv
runMidi(midiEvents, midiEventCount, blockLeft);
// generate a buffer's worth of samples
memset(outputs[0], 0, sizeof(float) * frames);
memset(outputs[1], 0, sizeof(float) * frames);
while (framePos < frames) {
if (blockLeft == 0) {
@ -88,6 +85,10 @@ void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEv
// run every synth voice into the buffer here FIXME
for (uint8_t i = 0; i < NUM_VOICES; i++) {
ic29.voices[i].run(outputs[0], framePos, sizeThisTime);
ic29.voices[i].filter(outputs[0], framePos, sizeThisTime);
for (uint8_t j=0; j<sizeThisTime; j++) {
outputs[1][framePos+j] += outputs[0][framePos+j] * ic29.voices[i].env.level/16384.0;
}
}
framePos += sizeThisTime; // move along the frame
@ -95,7 +96,7 @@ void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEv
blockLeft -= sizeThisTime;
}
// output processing goes here
memcpy(outputs[1], outputs[0], sizeof(float) * frames);
memcpy(outputs[0], outputs[1], sizeof(float) * frames);
}
Plugin *createPlugin() { return new Peacock(); }