You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.8 KiB
74 lines
1.8 KiB
#ifndef __VOICE_H__
|
|
#define __VOICE_H__
|
|
|
|
#include "globals.h"
|
|
#include "preset.h"
|
|
|
|
#include "dsp/oscillator.h"
|
|
#include "dsp/filter.h"
|
|
#include "dsp/adsr.h"
|
|
|
|
class Voice {
|
|
public:
|
|
typedef struct {
|
|
float unison;
|
|
|
|
Oscillator::Mode osc1Mode;
|
|
Oscillator::Mode osc2Mode;
|
|
float oscMix;
|
|
float oscDetune;
|
|
float osc2Pitch;
|
|
|
|
float noiseMix;
|
|
|
|
Filter::Settings filter;
|
|
|
|
ADSR::Envelope ampEnv;
|
|
ADSR::Envelope modEnv;
|
|
|
|
float modEnvFltGain;
|
|
float keyTrack;
|
|
float lfoStep;
|
|
float lfoPitchMod;
|
|
float lfoFltMod;
|
|
|
|
float reverb;
|
|
} Settings;
|
|
|
|
private:
|
|
Settings const * settings;
|
|
|
|
ADSR adsrAmp;
|
|
ADSR adsrMod;
|
|
Oscillator osc1;
|
|
Oscillator osc2;
|
|
Filter filter;
|
|
|
|
public:
|
|
int note;
|
|
float gain;
|
|
float pan;
|
|
float detune;
|
|
|
|
void reset();
|
|
void assign(Settings const * settings);
|
|
void noteOn(int note, float detune = 0, float gain = 1.0, float pan = 0.5);
|
|
void noteOff();
|
|
inline bool isIdle() { return adsrAmp.isIdle(); }
|
|
|
|
inline float tick(float pitchMod, float fltMod) {
|
|
const float basePitch = note + pitchMod + detune;
|
|
const float osc1CV = noteToCV(basePitch - settings->oscDetune);
|
|
const float osc2CV = noteToCV(basePitch + settings->oscDetune + settings->osc2Pitch);
|
|
float out = 0;
|
|
out += (1 - settings->oscMix) * osc1.tick(osc1CV);
|
|
out += settings->oscMix * osc2.tick(osc2CV);
|
|
out += settings->noiseMix * ((1.f / 3.f) * (whiteNoise() + whiteNoise() + whiteNoise()) - out);
|
|
const float keyTrackVal = settings->keyTrack * (note - 72) / 12.f;
|
|
out = filter.tick(out, settings->modEnvFltGain * adsrMod.tick() + keyTrackVal + fltMod);
|
|
out *= gain * adsrAmp.tick();
|
|
return out;
|
|
}
|
|
};
|
|
|
|
#endif |