Compare commits
No commits in common. "b70ab64dc147402ea29a047d63b7a9e3c9fe1a85" and "81b17f1a0a533fba959bea3ce12d5c7812d39b51" have entirely different histories.
b70ab64dc1
...
81b17f1a0a
|
@ -17,7 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "assigner.hpp"
|
#include "assigner.hpp"
|
||||||
|
|
||||||
#include "generator.hpp"
|
#include "generator.hpp"
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
|
|
||||||
|
@ -58,9 +57,10 @@ void Assigner::handleMidi(MidiEvent *ev) {
|
||||||
break;
|
break;
|
||||||
case 0xb0:
|
case 0xb0:
|
||||||
switch (ev->data[1]) {
|
switch (ev->data[1]) {
|
||||||
// maybe handle the following
|
// handle the following
|
||||||
// CC 1 - modwheel
|
// CC 1 - modwheel
|
||||||
// CC 64 - sustain
|
// CC 64 - sustain
|
||||||
|
// possibly JU-06 CC values
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,8 @@ void Assigner::noteOff(uint8_t note) {
|
||||||
voiceTbl[NUM_VOICES - 1] = v;
|
voiceTbl[NUM_VOICES - 1] = v;
|
||||||
noteTbl[v] |= 0x80;
|
noteTbl[v] |= 0x80;
|
||||||
voices[v].stopNote();
|
voices[v].stopNote();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Assigner::noteOn(uint8_t note) {
|
void Assigner::noteOn(uint8_t note) {
|
||||||
|
@ -134,12 +136,10 @@ void Assigner::noteOn(uint8_t note) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// printf("at end, l=%d e=%d\n", l,e);
|
||||||
noteTbl[v] = note;
|
noteTbl[v] = note;
|
||||||
|
|
||||||
// limit highest note to C7, one octave above the Solina's maximum range
|
voices[v].startNote(note, 48000);
|
||||||
while(note>96) note -= 12;
|
|
||||||
|
|
||||||
voices[v].startNote(note);
|
|
||||||
|
|
||||||
d_debug("send voice on %3d to voice %d", note, v);
|
d_debug("send voice on %3d to voice %d", note, v);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,12 @@ class Assigner {
|
||||||
public:
|
public:
|
||||||
Assigner(Voice *v);
|
Assigner(Voice *v);
|
||||||
void handleMidi(MidiEvent *ev);
|
void handleMidi(MidiEvent *ev);
|
||||||
|
uint8_t noteTbl[NUM_VOICES]; // note played by voice
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void noteOn(uint8_t note); // incoming note on (or off, if velocity = 0)
|
void noteOn(uint8_t note); // incoming note on (or off, if velocity = 0)
|
||||||
void noteOff(uint8_t note); // incoming note off
|
void noteOff(uint8_t note); // incoming note off
|
||||||
uint8_t voiceTbl[NUM_VOICES]; // voices in order of use
|
uint8_t voiceTbl[NUM_VOICES]; // voices in order of use
|
||||||
uint8_t noteTbl[NUM_VOICES]; // note played by voice
|
|
||||||
|
|
||||||
Voice *voices;
|
Voice *voices;
|
||||||
|
|
||||||
|
|
|
@ -24,16 +24,16 @@
|
||||||
|
|
||||||
#include "DistrhoPluginInfo.h"
|
#include "DistrhoPluginInfo.h"
|
||||||
|
|
||||||
// some unit-local globals
|
Generator::Generator(uint32_t bufferSize) {
|
||||||
|
|
||||||
float sampleRate = 0;
|
|
||||||
|
|
||||||
float envTc[2];
|
|
||||||
|
|
||||||
|
|
||||||
Generator::Generator(uint32_t bufferSize, double xSampleRate) {
|
|
||||||
sampleRate = xSampleRate;
|
|
||||||
output = new float[bufferSize];
|
output = new float[bufferSize];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Generator::~Generator() {
|
||||||
|
delete output;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Generator::setupGenerator(double sampleRate) {
|
||||||
// create the phase increments for each semitone
|
// create the phase increments for each semitone
|
||||||
for (uint8_t i = 0; i < 12; i++) {
|
for (uint8_t i = 0; i < 12; i++) {
|
||||||
phase[i] = 0;
|
phase[i] = 0;
|
||||||
|
@ -43,11 +43,7 @@ Generator::Generator(uint32_t bufferSize, double xSampleRate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Generator::~Generator() {
|
void Generator::runBlock(uint8_t *noteTable, uint32_t frames) {
|
||||||
delete output;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Generator::runBlock(uint32_t frames) {
|
|
||||||
Voice *v;
|
Voice *v;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint8_t k, p, key, n1, n2, d;
|
uint8_t k, p, key, n1, n2, d;
|
||||||
|
@ -61,9 +57,11 @@ void Generator::runBlock(uint32_t frames) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (k = 0; k < NUM_VOICES; k++) {
|
for (k = 0; k < NUM_VOICES; k++) {
|
||||||
|
key = noteTable[k] & 0x7f;
|
||||||
|
n1 = key % 12, n2 = (key / 12 - 3);
|
||||||
v = &voices[k];
|
v = &voices[k];
|
||||||
|
|
||||||
d = (phase[v->semi] & (0x40000000 >> v->oct)) != 0;
|
d = (phase[n1] & (0x40000000 >> n2)) != 0;
|
||||||
n = d ? 0.25 : -0.25;
|
n = d ? 0.25 : -0.25;
|
||||||
v->vc34 = ((n - v->vc34) * v->c34) + v->vc34;
|
v->vc34 = ((n - v->vc34) * v->c34) + v->vc34;
|
||||||
n -= v->vc34;
|
n -= v->vc34;
|
||||||
|
@ -71,52 +69,50 @@ void Generator::runBlock(uint32_t frames) {
|
||||||
v->vc78 = ((n - v->vc78) * v->c78) + v->vc78;
|
v->vc78 = ((n - v->vc78) * v->c78) + v->vc78;
|
||||||
v->vc107 = ((v->vc78 - v->vc107) * v->c107) + v->vc107;
|
v->vc107 = ((v->vc78 - v->vc107) * v->c107) + v->vc107;
|
||||||
|
|
||||||
d = (phase[v->semi] & (0x80000000 >> v->oct)) != 0;
|
|
||||||
|
|
||||||
|
d = (phase[n1] & (0x80000000 >> n2)) != 0;
|
||||||
n = d ? 0.25 : -0.25;
|
n = d ? 0.25 : -0.25;
|
||||||
v->vc33 = ((n - v->vc33) * v->c33) + v->vc33;
|
v->vc33 = ((n - v->vc33) * v->c33) + v->vc33;
|
||||||
n -= v->vc33;
|
n -= v->vc33;
|
||||||
n *= d ? 1 : 0;
|
n *= d ? 1 : 0;
|
||||||
v->vc22 = ((n - v->vc22) * v->c22) + v->vc22;
|
v->vc22 = ((n - v->vc22) * v->c22) + v->vc22;
|
||||||
v->vc31 = ((v->vc22 - v->vc31) * v->c31) + v->vc31;
|
v->vc31 = ((v->vc31 - v->vc31) * v->c31) + v->vc31;
|
||||||
|
|
||||||
v->vca = ((v->gate - v->vca) * envTc[v->vcatc]) + v->vca;
|
|
||||||
|
v->vca = ((v->gate - v->vca) * v->vcatc) + v->vca;
|
||||||
|
|
||||||
float v4 = (v->vc78 - v->vc107);
|
float v4 = (v->vc78 - v->vc107);
|
||||||
float v8 = (v->vc22 - v->vc31);
|
float v8 = (v->vc22 - v->vc31);
|
||||||
|
|
||||||
output[i] += 0.25 * (v4 + v8) * v->vca;
|
output[i] += (v4 + v8) * v->vca; //((noteTable[k]&0x80)?0:1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::startNote(uint8_t key) {
|
void Voice::startNote(uint8_t key, double sampleRate) {
|
||||||
// start a new note
|
// start a new note
|
||||||
// violin and viola filter params
|
// violin and viola filter params
|
||||||
float fc = 88.4 * powf(2, 0.083334 * (key - 24));
|
float fc = 88.4 * powf(2, 0.083334 * (key - 24));
|
||||||
c34 = 1 - exp(-6.283 * fc / sampleRate);
|
c34 = 1 - exp(-6.283 * fc / sampleRate);
|
||||||
c33 = 1 - exp(-6.283 * fc / 2 / sampleRate);
|
c33 = 1 - exp(-6.283 * fc /2 / sampleRate);
|
||||||
|
|
||||||
// violin register
|
// violin register
|
||||||
fc = 4000 + 65.8 * powf(2, 0.08 * (key - 24));
|
fc = 4000 * powf(2, 0.06 * (key - 24));
|
||||||
c78 = 1 - exp(-6.283 * fc / sampleRate);
|
c78 = 1 - exp(-6.283 * fc / sampleRate);
|
||||||
c107 = 1 - exp(-6.283 * 154.0 / sampleRate);
|
c107 = 1 - exp(-6.283 * 154.0 / sampleRate);
|
||||||
|
|
||||||
// viola register
|
// viola register
|
||||||
fc = 3000 + 65.8 * powf(2, 0.07 * (key - 24));
|
fc = 6000 * powf(2, 0.07 * (key - 24));
|
||||||
c22 = 1 - exp(-6.283 * fc / sampleRate);
|
c22 = 1 - exp(-6.283 * fc / sampleRate);
|
||||||
c31 = 1 - exp(-6.283 * 150.0 / sampleRate);
|
c31 = 1 - exp(-6.283 * 54.0 / sampleRate);
|
||||||
|
|
||||||
|
|
||||||
gate = 1;
|
gate = 1;
|
||||||
vcatc = 0;
|
vcatc = 0.0001;
|
||||||
semi = key % 12, oct = (key / 12 - 3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::stopNote() {
|
void Voice::stopNote() {
|
||||||
gate = 0;
|
gate = 0;
|
||||||
vcatc = 1;
|
vcatc = 0.000033;
|
||||||
}
|
|
||||||
|
|
||||||
void Generator::setEnvelope(float attack, float sustain) {
|
|
||||||
envTc[0] = ((96* powf(100, -attack))/sampleRate);
|
|
||||||
envTc[1] = ((48* powf(100, -sustain))/sampleRate);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class Voice {
|
||||||
friend Generator;
|
friend Generator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void startNote(uint8_t key);
|
void startNote(uint8_t key, double sampleRate);
|
||||||
void stopNote();
|
void stopNote();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -40,16 +40,15 @@ class Voice {
|
||||||
float c33 = 0, vc33 = 0;
|
float c33 = 0, vc33 = 0;
|
||||||
float c78 = 0, vc78 = 0;
|
float c78 = 0, vc78 = 0;
|
||||||
float c107 = 0, vc107 = 0;
|
float c107 = 0, vc107 = 0;
|
||||||
float vca = 0, gate = 0;
|
float vca = 0, vcatc = 0, gate = 0;
|
||||||
uint8_t vcatc;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Generator {
|
class Generator {
|
||||||
public:
|
public:
|
||||||
Generator(uint32_t bufferSize, double xSampleRate);
|
Generator(uint32_t bufferSize);
|
||||||
~Generator();
|
~Generator();
|
||||||
void setEnvelope(float attack, float sustain);
|
void setupGenerator(double sampleRate);
|
||||||
void runBlock(uint32_t frames);
|
void runBlock(uint8_t *noteTable, uint32_t frames);
|
||||||
Voice voices[NUM_VOICES];
|
Voice voices[NUM_VOICES];
|
||||||
float *output;
|
float *output;
|
||||||
|
|
||||||
|
|
|
@ -21,20 +21,6 @@
|
||||||
void Sonnenlicht::initParameter(uint32_t index, Parameter& parameter) {
|
void Sonnenlicht::initParameter(uint32_t index, Parameter& parameter) {
|
||||||
// define all the different control input parameters
|
// define all the different control input parameters
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case pContraBass:
|
|
||||||
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
|
|
||||||
parameter.name = "Contrabass";
|
|
||||||
parameter.symbol = "s_contra";
|
|
||||||
parameter.ranges.def = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case pCello:
|
|
||||||
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
|
|
||||||
parameter.name = "Cello";
|
|
||||||
parameter.symbol = "s_cello";
|
|
||||||
parameter.ranges.def = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case pViola:
|
case pViola:
|
||||||
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
|
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
|
||||||
parameter.name = "Viola";
|
parameter.name = "Viola";
|
||||||
|
@ -49,26 +35,6 @@ void Sonnenlicht::initParameter(uint32_t index, Parameter& parameter) {
|
||||||
parameter.ranges.def = 1;
|
parameter.ranges.def = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case pTrumpet:
|
|
||||||
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
|
|
||||||
parameter.name = "Trumpet";
|
|
||||||
parameter.symbol = "s_trumpet";
|
|
||||||
parameter.ranges.def = 0;
|
|
||||||
break;
|
|
||||||
case pHorn:
|
|
||||||
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
|
|
||||||
parameter.name = "Horn";
|
|
||||||
parameter.symbol = "s_horn";
|
|
||||||
parameter.ranges.def = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case pChorale:
|
|
||||||
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
|
|
||||||
parameter.name = "Chorale";
|
|
||||||
parameter.symbol = "s_chorale";
|
|
||||||
parameter.ranges.def = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case pBassVolume:
|
case pBassVolume:
|
||||||
parameter.hints = kParameterIsAutomatable;
|
parameter.hints = kParameterIsAutomatable;
|
||||||
parameter.name = "Bass Volume";
|
parameter.name = "Bass Volume";
|
||||||
|
@ -77,54 +43,19 @@ void Sonnenlicht::initParameter(uint32_t index, Parameter& parameter) {
|
||||||
parameter.ranges.max = 1.0f;
|
parameter.ranges.max = 1.0f;
|
||||||
parameter.ranges.def = 0.7f;
|
parameter.ranges.def = 0.7f;
|
||||||
break;
|
break;
|
||||||
case pAttack:
|
|
||||||
parameter.hints = kParameterIsAutomatable;
|
|
||||||
parameter.name = "Attack";
|
|
||||||
parameter.symbol = "s_attack";
|
|
||||||
parameter.ranges.min = 0.0f;
|
|
||||||
parameter.ranges.max = 1.0f;
|
|
||||||
parameter.ranges.def = 0.7f;
|
|
||||||
break;
|
|
||||||
case pSustain:
|
|
||||||
parameter.hints = kParameterIsAutomatable;
|
|
||||||
parameter.name = "Sustain";
|
|
||||||
parameter.symbol = "s_sustain";
|
|
||||||
parameter.ranges.min = 0.0f;
|
|
||||||
parameter.ranges.max = 1.0f;
|
|
||||||
parameter.ranges.def = 0.7f;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sonnenlicht::setParameterValue(uint32_t index, float value) {
|
void Sonnenlicht::setParameterValue(uint32_t index, float value) {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case pViola:
|
case pViola:
|
||||||
prog.viola = value;
|
viola = value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case pViolin:
|
case pViolin:
|
||||||
prog.violin = value;
|
violin = value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case pBassVolume:
|
case pBassVolume:
|
||||||
prog.bassVolume = value;
|
bassVolume = value;
|
||||||
break;
|
|
||||||
|
|
||||||
case pAttack:
|
|
||||||
prog.attack = value;
|
|
||||||
genny->setEnvelope(prog.attack, prog.sustain);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case pSustain:
|
|
||||||
prog.sustain = value;
|
|
||||||
genny->setEnvelope(prog.attack, prog.sustain);
|
|
||||||
//printf("pSustain: value=%f p.a %f p.s %f\n", value, prog.attack, prog.sustain);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case pChorale:
|
|
||||||
prog.enableChorus = (bool)value;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -136,26 +67,14 @@ void Sonnenlicht::setParameterValue(uint32_t index, float value) {
|
||||||
float Sonnenlicht::getParameterValue(uint32_t index) const {
|
float Sonnenlicht::getParameterValue(uint32_t index) const {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case pViola:
|
case pViola:
|
||||||
return prog.viola;
|
return viola;
|
||||||
|
|
||||||
case pViolin:
|
|
||||||
return prog.violin;
|
|
||||||
|
|
||||||
case pAttack:
|
|
||||||
return prog.attack;
|
|
||||||
|
|
||||||
case pSustain:
|
|
||||||
return prog.sustain;
|
|
||||||
|
|
||||||
case pBassVolume:
|
case pBassVolume:
|
||||||
return prog.bassVolume;
|
return bassVolume;
|
||||||
|
|
||||||
case pChorale:
|
|
||||||
return (float)prog.enableChorus;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// if we fall all the way through...
|
// if we fall all the way through...
|
||||||
return 0;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
START_NAMESPACE_DISTRHO
|
START_NAMESPACE_DISTRHO
|
||||||
|
|
||||||
Sonnenlicht::Sonnenlicht() : Plugin(kParameterCount, 0, 0), fSampleRate(getSampleRate()) {
|
Sonnenlicht::Sonnenlicht() : Plugin(kParameterCount, 0, 0), fSampleRate(getSampleRate()) {
|
||||||
genny = new Generator(getBufferSize(), fSampleRate);
|
genny = new Generator(getBufferSize());
|
||||||
|
genny->setupGenerator(fSampleRate);
|
||||||
|
|
||||||
assigner = new Assigner(genny->voices);
|
assigner = new Assigner(genny->voices);
|
||||||
|
|
||||||
|
@ -54,15 +55,9 @@ void Sonnenlicht::run(const float**, float** outputs, uint32_t frames,
|
||||||
assigner->handleMidi((MidiEvent*)&ev[i]);
|
assigner->handleMidi((MidiEvent*)&ev[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
genny->runBlock(frames);
|
genny->runBlock(assigner->noteTbl, frames);
|
||||||
|
|
||||||
if (prog.enableChorus) {
|
|
||||||
|
|
||||||
chorus->run(genny->output, outputs, frames);
|
chorus->run(genny->output, outputs, frames);
|
||||||
} else {
|
|
||||||
memcpy(outputs[0], genny->output, frames * sizeof(float));
|
|
||||||
memcpy(outputs[1], genny->output, frames * sizeof(float));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin* createPlugin() { return new Sonnenlicht(); }
|
Plugin* createPlugin() { return new Sonnenlicht(); }
|
||||||
|
|
|
@ -26,26 +26,12 @@
|
||||||
|
|
||||||
START_NAMESPACE_DISTRHO
|
START_NAMESPACE_DISTRHO
|
||||||
|
|
||||||
class Program {
|
|
||||||
public:
|
|
||||||
float viola = 0, violin = 0, bassVolume = 0;
|
|
||||||
float attack, sustain;
|
|
||||||
bool enableChorus;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Sonnenlicht : public Plugin {
|
class Sonnenlicht : public Plugin {
|
||||||
public:
|
public:
|
||||||
enum Parameters {
|
enum Parameters {
|
||||||
pContraBass,
|
|
||||||
pCello,
|
|
||||||
pBassVolume,
|
|
||||||
pAttack,
|
|
||||||
pSustain,
|
|
||||||
pViola,
|
pViola,
|
||||||
pViolin,
|
pViolin,
|
||||||
pTrumpet,
|
pBassVolume,
|
||||||
pHorn,
|
|
||||||
pChorale,
|
|
||||||
kParameterCount
|
kParameterCount
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,9 +63,8 @@ class Sonnenlicht : public Plugin {
|
||||||
const MidiEvent *midiEvents, uint32_t midiEventCount) override;
|
const MidiEvent *midiEvents, uint32_t midiEventCount) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float viola = 0, violin = 0, bassVolume = 0;
|
||||||
double fSampleRate;
|
double fSampleRate;
|
||||||
|
|
||||||
Program prog;
|
|
||||||
Assigner *assigner;
|
Assigner *assigner;
|
||||||
Generator *genny;
|
Generator *genny;
|
||||||
Chorus *chorus;
|
Chorus *chorus;
|
||||||
|
|
Loading…
Reference in New Issue