Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 3 additions & 44 deletions source/dsp/Voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class Voice : public SynthesiserVoice, private Timer {
// Initialize Oscillators

firstOscillator().initialize(lookupTable);
secondOscillator().initialize(lookupTable);

processorChain.prepare(spec);

Expand All @@ -98,7 +97,6 @@ class Voice : public SynthesiserVoice, private Timer {
adsr.setSampleRate(lfoSampleRate);

firstOscillator().setRampDurationSeconds(lfoSampleDuration);
secondOscillator().setRampDurationSeconds(lfoSampleDuration);

gainProcessor().setGainLinear(1.0 - gainHeadroom);

Expand Down Expand Up @@ -128,11 +126,6 @@ class Voice : public SynthesiserVoice, private Timer {
1.0f - (*parameters.velocityEnvelopeAmount) * (1.0f - velocity);

firstOscillator().setLevel(currentVelocity);
firstOscillator().setLevel(currentVelocity);

if (modulationAmount > 0.0f) {
updateModulation();
}

updateADSRParameters();

Expand Down Expand Up @@ -207,8 +200,6 @@ class Voice : public SynthesiserVoice, private Timer {
float currentFilterDrive = *parameters.filterDrive;

float currentOsc1Frequency = 0.0;
float currentOsc2Frequency = 0.0;
float currentOsc2AnalogFactor = 0.0;

Waveform currentWaveform =
static_cast<Waveform>(static_cast<int>(*parameters.oscillatorWaveform));
Expand All @@ -217,13 +208,12 @@ class Voice : public SynthesiserVoice, private Timer {

enum {
osc1Index,
osc2Index,
filterIndex,
gainIndex,
};

dsp::ProcessorChain<VCAOscillator<float>, VCAOscillator<float>,
blackbird::dsp::LadderFilter<float>, dsp::Gain<float>>
dsp::ProcessorChain<VCAOscillator<float>, blackbird::dsp::LadderFilter<float>,
dsp::Gain<float>>
processorChain;

dsp::Oscillator<float> lfo;
Expand All @@ -236,10 +226,6 @@ class Voice : public SynthesiserVoice, private Timer {
return processorChain.get<osc1Index>();
}

VCAOscillator<float> &secondOscillator() {
return processorChain.get<osc2Index>();
}

dsp::Gain<float> &gainProcessor() { return processorChain.get<gainIndex>(); }

blackbird::dsp::LadderFilter<float> &filter() {
Expand All @@ -259,16 +245,9 @@ class Voice : public SynthesiserVoice, private Timer {
updateLevelWithADSRSample(nextADSRSample);
updateFilterWithADSRSample(nextADSRSample);

updateModulation();

processorChain.process(context);
}

static float analogFactor() {
return (Random::getSystemRandom().nextBool() ? 1.0f : -1.0f) *
maxAnalogFactor * Random::getSystemRandom().nextFloat();
}

static double getBendedFrequencyForWheel(int newPitchWheelValue,
int currentlyPlayingNote) {
auto bendSemitonesValue =
Expand Down Expand Up @@ -311,7 +290,6 @@ class Voice : public SynthesiserVoice, private Timer {
static_cast<Waveform>(static_cast<int>(*parameters.oscillatorWaveform));

firstOscillator().setWaveform(currentWaveform);
secondOscillator().setWaveform(currentWaveform);
}

void updateADSRParameters() {
Expand All @@ -320,17 +298,8 @@ class Voice : public SynthesiserVoice, private Timer {
}

void updateOscillatorsFrequency() {
currentOsc1Frequency = currentNoteFrequency * (1.0f + analogFactor());
currentOsc2AnalogFactor = analogFactor();
currentOsc2Frequency =
currentNoteFrequency *
(1.0f + maxDetuningFactor * (*parameters.detuningAmount) *
currentOsc2AnalogFactor);

currentDetuningAmount = *parameters.detuningAmount;

currentOsc1Frequency = currentNoteFrequency;
firstOscillator().setFrequency(currentOsc1Frequency);
secondOscillator().setFrequency(currentOsc2Frequency);
}

void updateFilterDrive() {
Expand All @@ -339,14 +308,6 @@ class Voice : public SynthesiserVoice, private Timer {
filter().setDrive(currentFilterDrive);
}

void updateModulation() {
secondOscillator().setFrequency(
currentOsc2Frequency *
(1.0 + modulationAmount * lfo.processSample(0.0f) *
(maxDetuningFactor - defaultDetuningFactor) *
maxAnalogFactor));
}

void updateFilterWithADSRSample(float nextADSRSample) {
const auto envelopeCutoffValue =
*parameters.cutoffEnvelopeAmount >= 0
Expand All @@ -372,7 +333,6 @@ class Voice : public SynthesiserVoice, private Timer {
nextADSRSample;

firstOscillator().setLevel(envelopeVelocityValue);
secondOscillator().setLevel(envelopeVelocityValue);
}

#pragma mark - Note Lifecycle
Expand All @@ -389,7 +349,6 @@ class Voice : public SynthesiserVoice, private Timer {

void setProcessorsBypassed(bool bypassed) {
processorChain.template setBypassed<osc1Index>(bypassed);
processorChain.template setBypassed<osc2Index>(bypassed);

filter().setEnabled(!bypassed);
}
Expand Down