Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update dpf, move smoothers there and split convolver class
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Apr 15, 2023
1 parent 5984d57 commit 3f1a9e1
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 317 deletions.
2 changes: 1 addition & 1 deletion dpf-widgets
15 changes: 7 additions & 8 deletions plugins/AB-InputSelector/OneKnobPlugin.cpp
Expand Up @@ -19,7 +19,6 @@
#include "DistrhoPluginInfo.h"

#include "OneKnobPlugin.hpp"
#include "LinearSmoother.hpp"

START_NAMESPACE_DISTRHO

Expand All @@ -31,9 +30,11 @@ class OneKnobInputSelectorPlugin : public OneKnobPlugin
OneKnobInputSelectorPlugin()
: OneKnobPlugin()
{
abSmooth.setTimeConstant(1e-3f);
abSmooth.setTargetValue((kParameterRanges[kParameterSelect].def + 100.0f) / 200.0f);

init();
sampleRateChanged(getSampleRate());
abSmooth.setTimeConstant(1e-3f);
}

protected:
Expand Down Expand Up @@ -117,7 +118,8 @@ class OneKnobInputSelectorPlugin : public OneKnobPlugin
{
OneKnobPlugin::setParameterValue(index, value);

// TODO do something extra here? if not, remove this
if (index == kParameterSelect)
abSmooth.setTargetValue((value + 100.0f) / 200.0f);
}

void loadProgram(const uint32_t index) override
Expand All @@ -144,8 +146,7 @@ class OneKnobInputSelectorPlugin : public OneKnobPlugin
{
OneKnobPlugin::activate();

abSmooth.setTarget((parameters[kParameterSelect] + 100.0f) / 200.0f);
abSmooth.clearToTarget();
abSmooth.clearToTargetValue();
}

void run(const float** const inputs, float** const outputs, const uint32_t frames) override
Expand All @@ -157,8 +158,6 @@ class OneKnobInputSelectorPlugin : public OneKnobPlugin
/* */ float* const lo = outputs[0];
/* */ float* const ro = outputs[1];

abSmooth.setTarget((parameters[kParameterSelect] + 100.0f) / 200.0f);

float sel, As, Bs;
for (uint32_t i = 0; i < frames; ++i)
{
Expand All @@ -181,7 +180,7 @@ class OneKnobInputSelectorPlugin : public OneKnobPlugin
}

// -------------------------------------------------------------------
LinearSmoother abSmooth;
LinearValueSmoother abSmooth;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OneKnobInputSelectorPlugin)
};
Expand Down
17 changes: 8 additions & 9 deletions plugins/AB-OutputSelector/OneKnobPlugin.cpp
Expand Up @@ -19,7 +19,6 @@
#include "DistrhoPluginInfo.h"

#include "OneKnobPlugin.hpp"
#include "LinearSmoother.hpp"

START_NAMESPACE_DISTRHO

Expand All @@ -31,9 +30,11 @@ class OneKnobOutputSelectorPlugin : public OneKnobPlugin
OneKnobOutputSelectorPlugin()
: OneKnobPlugin()
{
abSmooth.setTimeConstant(1e-3f);
abSmooth.setTargetValue((kParameterRanges[kParameterSelect].def + 100.0f) / 200.0f);

init();
sampleRateChanged(getSampleRate());
abSmooth.setTimeConstant(1e-3f);
}

protected:
Expand Down Expand Up @@ -117,7 +118,8 @@ class OneKnobOutputSelectorPlugin : public OneKnobPlugin
{
OneKnobPlugin::setParameterValue(index, value);

// TODO do something extra here? if not, remove this
if (index == kParameterSelect)
abSmooth.setTargetValue((value + 100.0f) / 200.0f);
}

void loadProgram(const uint32_t index) override
Expand All @@ -137,15 +139,14 @@ class OneKnobOutputSelectorPlugin : public OneKnobPlugin
{
OneKnobPlugin::sampleRateChanged(newSampleRate);

abSmooth.setSampleRate((float)newSampleRate);
abSmooth.setSampleRate(newSampleRate);
}

void activate() override
{
OneKnobPlugin::activate();

abSmooth.setTarget((parameters[kParameterSelect] + 100.0f) / 200.0f);
abSmooth.clearToTarget();
abSmooth.clearToTargetValue();
}

void run(const float** const inputs, float** const outputs, const uint32_t frames) override
Expand All @@ -157,8 +158,6 @@ class OneKnobOutputSelectorPlugin : public OneKnobPlugin
/* */ float* const l2 = outputs[2];
/* */ float* const r2 = outputs[3];

abSmooth.setTarget((parameters[kParameterSelect] + 100.0f) / 200.0f);

float sel, As, Bs;
for (uint32_t i = 0; i < frames; ++i)
{
Expand All @@ -183,7 +182,7 @@ class OneKnobOutputSelectorPlugin : public OneKnobPlugin
}

// -------------------------------------------------------------------
LinearSmoother abSmooth;
LinearValueSmoother abSmooth;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OneKnobOutputSelectorPlugin)
};
Expand Down
115 changes: 20 additions & 95 deletions plugins/ConvolutionReverb/OneKnobPlugin.cpp
Expand Up @@ -19,7 +19,6 @@
#include "DistrhoPluginInfo.h"

#include "OneKnobPlugin.hpp"
#include "LinearSmoother.hpp"
#include "Korg35Filters.hpp"

#include "Semaphore.hpp"
Expand All @@ -30,83 +29,11 @@
#include "dr_wav.h"
// -Wunused-variable
#include "r8brain/CDSPResampler.h"
#include "FFTConvolver/TwoStageFFTConvolver.h"

START_NAMESPACE_DISTRHO

#if defined(_MOD_DEVICE_DUO)
static constexpr const size_t headBlockSize = 256;
static constexpr const size_t tailBlockSize = 4096;
#elif defined(_MOD_DEVICE_DWARF)
static constexpr const size_t headBlockSize = 128;
static constexpr const size_t tailBlockSize = 2048;
#else
static constexpr const size_t headBlockSize = 128;
static constexpr const size_t tailBlockSize = 1024;
#endif

// -----------------------------------------------------------------------

class TwoStageThreadedConvolver : public fftconvolver::TwoStageFFTConvolver,
private Thread
{
Semaphore semBgProcStart;
Semaphore semBgProcFinished;

public:
TwoStageThreadedConvolver()
: fftconvolver::TwoStageFFTConvolver(),
Thread("TwoStageThreadedConvolver"),
semBgProcStart(1),
semBgProcFinished(0)
{
}

~TwoStageThreadedConvolver() override
{
stop();
}

void start()
{
startThread(true);
}

void stop()
{
signalThreadShouldExit();
semBgProcStart.post();
stopThread(5000);
}

protected:
void startBackgroundProcessing() override
{
semBgProcStart.post();
}

void waitForBackgroundProcessing() override
{
if (isThreadRunning() && !shouldThreadExit())
semBgProcFinished.wait();
}

void run() override
{
while (!shouldThreadExit())
{
semBgProcStart.wait();
// must be last
#include "TwoStageThreadedConvolver.hpp"

if (shouldThreadExit())
break;

doBackgroundProcessing();
semBgProcFinished.post();
}
}

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TwoStageThreadedConvolver)
};
START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

Expand All @@ -130,8 +57,8 @@ class OneKnobConvolutionReverbPlugin : public OneKnobPlugin
smoothDryLevel.setTimeConstant(0.1f);
smoothWetLevel.setTimeConstant(0.1f);

smoothDryLevel.setTarget(std::pow(10.f, 0.05f * kParameterRanges[kParameterDryLevel].def));
smoothWetLevel.setTarget(std::pow(10.f, 0.05f * kParameterRanges[kParameterWetLevel].def));
smoothDryLevel.setTargetValue(std::pow(10.f, 0.05f * kParameterRanges[kParameterDryLevel].def));
smoothWetLevel.setTargetValue(std::pow(10.f, 0.05f * kParameterRanges[kParameterWetLevel].def));
}

~OneKnobConvolutionReverbPlugin() override
Expand Down Expand Up @@ -261,11 +188,11 @@ class OneKnobConvolutionReverbPlugin : public OneKnobPlugin
{
case kParameterDryLevel:
if (!bypassed)
smoothDryLevel.setTarget(std::pow(10.f, 0.05f * value));
smoothDryLevel.setTargetValue(std::pow(10.f, 0.05f * value));
break;
case kParameterWetLevel:
if (!bypassed)
smoothWetLevel.setTarget(std::pow(10.f, 0.05f * value));
smoothWetLevel.setTargetValue(std::pow(10.f, 0.05f * value));
break;
case kParameterHighPassFilter:
korgFilterL.setFrequency(value);
Expand All @@ -274,21 +201,21 @@ class OneKnobConvolutionReverbPlugin : public OneKnobPlugin
case kParameterTrails:
trails = value > 0.5f;
if (bypassed)
smoothWetLevel.setTarget(trails ? std::pow(10.f, 0.05f * parameters[kParameterWetLevel]) : 0.f);
smoothWetLevel.setTargetValue(trails ? std::pow(10.f, 0.05f * parameters[kParameterWetLevel]) : 0.f);
break;
case kParameterBypass:
bypassed = value > 0.5f;
if (bypassed)
{
smoothDryLevel.setTarget(1.f);
smoothWetLevel.setTarget(trails ? std::pow(10.f, 0.05f * parameters[kParameterWetLevel]) : 0.f);
smoothDryLevel.setTargetValue(1.f);
smoothWetLevel.setTargetValue(trails ? std::pow(10.f, 0.05f * parameters[kParameterWetLevel]) : 0.f);
}
else
{
korgFilterL.reset();
korgFilterR.reset();
smoothDryLevel.setTarget(std::pow(10.f, 0.05f * parameters[kParameterDryLevel]));
smoothWetLevel.setTarget(std::pow(10.f, 0.05f * parameters[kParameterWetLevel]));
smoothDryLevel.setTargetValue(std::pow(10.f, 0.05f * parameters[kParameterDryLevel]));
smoothWetLevel.setTargetValue(std::pow(10.f, 0.05f * parameters[kParameterWetLevel]));
}
break;
}
Expand All @@ -308,8 +235,8 @@ class OneKnobConvolutionReverbPlugin : public OneKnobPlugin
korgFilterL.reset();
korgFilterR.reset();

smoothDryLevel.clearToTarget();
smoothWetLevel.clearToTarget();
smoothDryLevel.clearToTargetValue();
smoothWetLevel.clearToTargetValue();
}

void setState(const char* const key, const char* const value) override
Expand Down Expand Up @@ -401,12 +328,10 @@ class OneKnobConvolutionReverbPlugin : public OneKnobPlugin
}

newConvolverL = new TwoStageThreadedConvolver();
newConvolverL->init(headBlockSize, tailBlockSize, irBufL, numFrames);
newConvolverL->start();
newConvolverL->init(irBufL, numFrames);

newConvolverR = new TwoStageThreadedConvolver();
newConvolverR->init(headBlockSize, tailBlockSize, irBufR, numFrames);
newConvolverR->start();
newConvolverR->init(irBufR, numFrames);

{
const MutexLocker cml(mutex);
Expand Down Expand Up @@ -441,8 +366,8 @@ class OneKnobConvolutionReverbPlugin : public OneKnobPlugin
korgFilterL.reset();
korgFilterR.reset();

smoothDryLevel.clearToTarget();
smoothWetLevel.clearToTarget();
smoothDryLevel.clearToTargetValue();
smoothWetLevel.clearToTargetValue();

OneKnobPlugin::activate();
}
Expand Down Expand Up @@ -639,8 +564,8 @@ class OneKnobConvolutionReverbPlugin : public OneKnobPlugin
uint32_t bufferSize = 0;

// smoothed parameters
LinearSmoother smoothDryLevel;
LinearSmoother smoothWetLevel;
LinearValueSmoother smoothDryLevel;
LinearValueSmoother smoothWetLevel;

// buffers for placing highpass signal before convolution
float* highpassBufL = nullptr;
Expand Down

0 comments on commit 3f1a9e1

Please sign in to comment.