feat: added mixer component and add wet/dry mix to distortion
This commit is contained in:
parent
9acddeb29c
commit
c6f8cb1e0e
4 changed files with 122 additions and 4 deletions
59
core/Mixer.cpp
Normal file
59
core/Mixer.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
#include "Mixer.hpp"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
template <uint32_t NumInputs>
|
||||||
|
Mixer<NumInputs>::Mixer(float init_gain) : normalise_(false) {
|
||||||
|
for (uint32_t i = 0; i < NumInputs; ++i) {
|
||||||
|
gains_[i] = init_gain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <uint32_t NumInputs>
|
||||||
|
void Mixer<NumInputs>::process(const float **inputs, float *out,
|
||||||
|
uint32_t frames) {
|
||||||
|
mixChannels(inputs, out, frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <uint32_t NumInputs>
|
||||||
|
void Mixer<NumInputs>::processStereo(const float **inputsL,
|
||||||
|
const float **inputsR, float *outL,
|
||||||
|
float *outR, uint32_t frames) {
|
||||||
|
mixChannels(inputsL, outL, frames);
|
||||||
|
mixChannels(inputsR, outR, frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <uint32_t NumInputs>
|
||||||
|
void Mixer<NumInputs>::mixChannels(const float **inputs, float *out,
|
||||||
|
uint32_t frames) {
|
||||||
|
float scale = normalise_ ? (1.0f / NumInputs) : 1.0f;
|
||||||
|
for (uint32_t i = 0; i < frames; ++i) {
|
||||||
|
float sum = 0.0f;
|
||||||
|
for (uint32_t j = 0; j < NumInputs; ++j) {
|
||||||
|
sum += inputs[j][i] * (gains_[j] * scale);
|
||||||
|
}
|
||||||
|
out[i] = sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <uint32_t NumInputs>
|
||||||
|
void Mixer<NumInputs>::setInputGain(uint32_t index, float gain) {
|
||||||
|
gains_[index] = gain;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <uint32_t NumInputs>
|
||||||
|
float Mixer<NumInputs>::getInputGain(uint32_t index) const {
|
||||||
|
return isValidInputIndex(index) ? gains_[index] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <uint32_t NumInputs> void Mixer<NumInputs>::setNormalise(bool norm) {
|
||||||
|
normalise_ = norm;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <uint32_t NumInputs> bool Mixer<NumInputs>::getNormalise() const {
|
||||||
|
return normalise_;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <uint32_t NumInputs>
|
||||||
|
bool Mixer<NumInputs>::isValidInputIndex(float index) const {
|
||||||
|
return index >= 0 && index < NumInputs;
|
||||||
|
}
|
||||||
29
core/Mixer.hpp
Normal file
29
core/Mixer.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef MIXER_HPP_INCLUDED
|
||||||
|
#define MIXER_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
template <uint32_t NumInputs> class Mixer {
|
||||||
|
public:
|
||||||
|
Mixer(float init_gain);
|
||||||
|
|
||||||
|
void process(const float **inputs, float *out, uint32_t frames);
|
||||||
|
void processStereo(const float **inputsL, const float **inputsR, float *outL,
|
||||||
|
float *outR, uint32_t frames);
|
||||||
|
|
||||||
|
void setInputGain(uint32_t index, float gain);
|
||||||
|
float getInputGain(uint32_t index) const;
|
||||||
|
|
||||||
|
void setNormalise(bool norm);
|
||||||
|
bool getNormalise() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void mixChannels(const float **inputs, float *out, uint32_t frames);
|
||||||
|
bool isValidInputIndex(float index) const;
|
||||||
|
float gains_[NumInputs];
|
||||||
|
bool normalise_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MIXER_HPP_INCLUDED
|
||||||
|
|
||||||
|
template class Mixer<2u>;
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/make -f
|
#!/usr/bin/make -f
|
||||||
NAME = SquidgeDistortion
|
NAME = SquidgeDistortion
|
||||||
|
|
||||||
FILES_DSP = SquidgeDistortion.cpp ../../core/Gain.cpp ../../core/Clipper.cpp
|
FILES_DSP = SquidgeDistortion.cpp ../../core/Gain.cpp ../../core/Clipper.cpp ../../core/Mixer.cpp
|
||||||
|
|
||||||
TARGETS = vst3 clap
|
TARGETS = vst3 clap
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,28 @@
|
||||||
|
#include "DistrhoDetails.hpp"
|
||||||
#include "DistrhoPlugin.hpp"
|
#include "DistrhoPlugin.hpp"
|
||||||
#include "DistrhoPluginInfo.h"
|
#include "DistrhoPluginInfo.h"
|
||||||
|
|
||||||
#include "../../core/Clipper.hpp"
|
#include "../../core/Clipper.hpp"
|
||||||
#include "../../core/Gain.hpp"
|
#include "../../core/Gain.hpp"
|
||||||
|
#include "../../core/Mixer.hpp"
|
||||||
|
|
||||||
START_NAMESPACE_DISTRHO
|
START_NAMESPACE_DISTRHO
|
||||||
|
|
||||||
class SquidgeDistortion : public Plugin {
|
class SquidgeDistortion : public Plugin {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum MixerChannels { kChannelDry, kChannelWet, KChannelCount };
|
||||||
enum Parameters {
|
enum Parameters {
|
||||||
kParamGain,
|
kParamGain,
|
||||||
kParamClipMode,
|
kParamClipMode,
|
||||||
|
kParamMixVolume,
|
||||||
kParameterCount // must be last
|
kParameterCount // must be last
|
||||||
};
|
};
|
||||||
SquidgeDistortion() : Plugin(kParameterCount, 0, 0), gain_(2.0f) {}
|
SquidgeDistortion()
|
||||||
|
: Plugin(kParameterCount, 0, 0), gain_(2.0f), mixer_(1.0f) {
|
||||||
|
mixer_.setInputGain(kChannelDry, 0.0f);
|
||||||
|
mixer_.setInputGain(kChannelWet, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char *getLabel() const override { return "SquidgeDistortion"; }
|
const char *getLabel() const override { return "SquidgeDistortion"; }
|
||||||
|
|
@ -52,6 +60,14 @@ protected:
|
||||||
parameter.enumValues.values =
|
parameter.enumValues.values =
|
||||||
const_cast<ParameterEnumerationValue *>(sClipModes);
|
const_cast<ParameterEnumerationValue *>(sClipModes);
|
||||||
break;
|
break;
|
||||||
|
case kParamMixVolume:
|
||||||
|
parameter.name = "Dry/Wet";
|
||||||
|
parameter.symbol = "drywetvolume";
|
||||||
|
parameter.ranges.min = 0.0f;
|
||||||
|
parameter.ranges.def = 1.0f;
|
||||||
|
parameter.ranges.max = 1.0f;
|
||||||
|
parameter.hints = kParameterIsAutomatable;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,6 +77,8 @@ protected:
|
||||||
return gain_.getGain();
|
return gain_.getGain();
|
||||||
case kParamClipMode:
|
case kParamClipMode:
|
||||||
return (float)clipper_.getMode();
|
return (float)clipper_.getMode();
|
||||||
|
case kParamMixVolume:
|
||||||
|
return mixer_.getInputGain(kChannelWet);
|
||||||
}
|
}
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
@ -73,18 +91,30 @@ protected:
|
||||||
case kParamClipMode:
|
case kParamClipMode:
|
||||||
clipper_.setMode((Clipper::ClipperMode)value);
|
clipper_.setMode((Clipper::ClipperMode)value);
|
||||||
break;
|
break;
|
||||||
|
case kParamMixVolume:
|
||||||
|
mixer_.setInputGain(kChannelWet, value);
|
||||||
|
mixer_.setInputGain(kChannelDry, 1.0f - value);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(const float **inputs, float **outputs, uint32_t frames) override {
|
void run(const float **inputs, float **outputs, uint32_t frames) override {
|
||||||
gain_.processStereo(inputs[0], inputs[1], outputs[0], outputs[1], frames);
|
gain_.processStereo(inputs[0], inputs[1], wetBufferL_, wetBufferR_, frames);
|
||||||
clipper_.processStereo(outputs[0], outputs[1], outputs[0], outputs[1],
|
clipper_.processStereo(wetBufferL_, wetBufferR_, wetBufferL_, wetBufferR_,
|
||||||
frames);
|
frames);
|
||||||
|
|
||||||
|
const float *inputsL[2] = {inputs[0], wetBufferL_};
|
||||||
|
const float *inputsR[2] = {inputs[1], wetBufferR_};
|
||||||
|
|
||||||
|
mixer_.processStereo(inputsL, inputsR, outputs[0], outputs[1], frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Gain gain_;
|
Gain gain_;
|
||||||
Clipper clipper_;
|
Clipper clipper_;
|
||||||
|
Mixer<2> mixer_;
|
||||||
|
float wetBufferL_[4096];
|
||||||
|
float wetBufferR_[4096];
|
||||||
|
|
||||||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SquidgeDistortion);
|
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SquidgeDistortion);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue