Skip to content

Commit

Permalink
allowed disable reverb fx. dont alloc memory everytime call PDR func …
Browse files Browse the repository at this point in the history
…(maybe faster?).
  • Loading branch information
BLumia committed Sep 30, 2016
1 parent 756506b commit 70a157a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
44 changes: 28 additions & 16 deletions Synthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum EParams
mVerbWidth,
mVerbDry,
mVerbWet,
mVerbOn,
kNumParams
};

Expand Down Expand Up @@ -87,6 +88,7 @@ Synthesis::Synthesis(IPlugInstanceInfo instanceInfo)
IBitmap waveformBitmap = pGraphics->LoadIBitmap(WAVEFORM_ID, WAVEFORM_FN, 5);
IBitmap filtermodeBitmap = pGraphics->LoadIBitmap(FILTERMODE_ID, FILTERMODE_FN, 3);
IBitmap switcherLightBitmap = pGraphics->LoadIBitmap(SWITCHER_LIGHT_ID, SWITCHER_LIGHT_FN, 2);
IBitmap switcherOnOffBitmap = pGraphics->LoadIBitmap(SWITCHER_ONOFF_ID, SWITCHER_ONOFF_FN, 2);

// OSC1 Waveform switch
GetParam(mOsc1Waveform)->InitEnum("Waveform1", Oscillator::OSCILLATOR_MODE_SINE, Oscillator::kNumOscillatorModes);
Expand Down Expand Up @@ -214,6 +216,11 @@ Synthesis::Synthesis(IPlugInstanceInfo instanceInfo)
pGraphics->AttachControl(filterEnvAdsrVisualization);

// Reverb
// Reverb switch
GetParam(mVerbOn)->InitEnum("Reverb On/Off", 0, 2);
GetParam(mVerbOn)->SetDisplayText(0, "On");
pGraphics->AttachControl(new ISwitchControl(this, 42, kPurpleRow + kSwitcherTopPadding, mVerbOn, &switcherOnOffBitmap));

GetParam(mVerbRoomSize)->InitDouble("Room Size", 0.5, 0.3, 0.99, 0.001);
pGraphics->AttachControl(new IKnobMultiControl(this, 137, kPurpleRow, mVerbRoomSize, &purpleKnobBitmap));
GetParam(mVerbDamp)->InitDouble("Dampening", 0.5, 0., 1., 0.001);
Expand Down Expand Up @@ -241,7 +248,10 @@ Synthesis::Synthesis(IPlugInstanceInfo instanceInfo)

}

Synthesis::~Synthesis() {}
Synthesis::~Synthesis() {
if (ori_l != nullptr) free(ori_l);
if (ori_r != nullptr) free(ori_r);
}

void Synthesis::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
Expand All @@ -255,31 +265,33 @@ void Synthesis::ProcessDoubleReplacing(double** inputs, double** outputs, int nF
return; // MIDIReceiver.
}
*/
double* ori_l;
double* ori_r;
ori_l = (double*)malloc(nFrames * sizeof(double));
ori_r = (double*)malloc(nFrames * sizeof(double));

// don't alloc new mem space every time we call ProcessDoubleReplacing. Will faster?
if (ori_l == nullptr || sizeof(*ori_l) != nFrames * sizeof(double)) ori_l = (double*)malloc(nFrames * sizeof(double));
if (ori_r == nullptr || sizeof(*ori_r) != nFrames * sizeof(double)) ori_r = (double*)malloc(nFrames * sizeof(double));

double *leftOutput = outputs[0];
double *rightOutput = outputs[1];
bool verbFxOn = GetParam(mVerbOn)->Int() == 0;

processVirtualKeyboard();
for (int i = 0; i < nFrames; ++i) {
mMIDIReceiver.advance();

ori_l[i] = ori_r[i] = leftOutput[i] = rightOutput[i] = voiceManager.nextSample();

// Reverb
mVerbEngine.ProcessSample(leftOutput + i, rightOutput + i);
// Mix dry/wet
leftOutput[i] = mDry * ori_l[i] + mWet * leftOutput[i];
rightOutput[i] = mDry * ori_r[i] + mWet * rightOutput[i];

if (!verbFxOn) {
//Off
leftOutput[i] = rightOutput[i] = voiceManager.nextSample();
} else {
ori_l[i] = ori_r[i] = leftOutput[i] = rightOutput[i] = voiceManager.nextSample();

// Reverb
mVerbEngine.ProcessSample(leftOutput + i, rightOutput + i);
// Mix dry/wet
leftOutput[i] = mDry * ori_l[i] + mWet * leftOutput[i];
rightOutput[i] = mDry * ori_r[i] + mWet * rightOutput[i];
}
}

free(ori_l);
free(ori_r);

mMIDIReceiver.Flush(nFrames);
}

Expand Down
1 change: 1 addition & 0 deletions Synthesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Synthesis : public IPlug
private:
WDL_ReverbEngine mVerbEngine;
double mDry = 1., mWet = 0.5;
double *ori_l = nullptr, *ori_r = nullptr; // to make free alloced space easy.
double mFrequency;
void CreatePresets();
VoiceManager voiceManager;
Expand Down
1 change: 1 addition & 0 deletions Synthesis.rc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FILTERMODE_ID PNG FILTERMODE_FN
ORANGE_KNOB_ID PNG ORANGE_KNOB_FN
PURPLE_KNOB_ID PNG PURPLE_KNOB_FN
SWITCHER_LIGHT_ID PNG SWITCHER_LIGHT_FN
SWITCHER_ONOFF_ID PNG SWITCHER_ONOFF_FN

#ifdef SA_API
//Standalone stuff
Expand Down
2 changes: 2 additions & 0 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ instrument determined by PLUG _IS _INST
#define BLUE_KNOB_CENTER_ID 109
#define GREEN_KNOB_CENTER_ID 110
#define SWITCHER_LIGHT_ID 111
#define SWITCHER_ONOFF_ID 112

// Image resource locations for this plug.
#define BG_FN "resources/img/bg.png"
Expand All @@ -84,6 +85,7 @@ instrument determined by PLUG _IS _INST
#define GREEN_KNOB_CENTER_FN "resources/img/greenknob-center0.png"
#define BLUE_KNOB_CENTER_FN "resources/img/blueknob-center0.png"
#define SWITCHER_LIGHT_FN "resources/img/switcherlight.png"
#define SWITCHER_ONOFF_FN "resources/img/switcheronoff.png"

// GUI default dimensions
#define GUI_WIDTH 665
Expand Down
Binary file modified resources/img/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/img/switcheronoff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 70a157a

Please sign in to comment.