Add "cut" control to Crunch
This commit is contained in:
parent
cb21797593
commit
5bfcf6f151
21
crunch.h
21
crunch.h
@ -31,6 +31,7 @@ struct CrunchSTFX : public BaseEffect {
|
||||
ParamRange drive{4};
|
||||
ParamRange fuzz{0};
|
||||
ParamRange toneHz{2000};
|
||||
ParamRange cutHz{50};
|
||||
ParamRange outGain{1};
|
||||
|
||||
const bool autoGain;
|
||||
@ -52,6 +53,9 @@ struct CrunchSTFX : public BaseEffect {
|
||||
stfx::units::rangeHz(storage.range("toneHz", toneHz)
|
||||
.info("tone", "limits the brightness of the distortion")
|
||||
.range(100, 4000, 20000));
|
||||
stfx::units::rangeHz(storage.range("cutHz", cutHz)
|
||||
.info("cut", "prevents low frequencies from driving the distortion")
|
||||
.range(20, 100, 5000));
|
||||
|
||||
stfx::units::rangeGain(storage.range("outGain", outGain)
|
||||
.info("out", "output gain")
|
||||
@ -66,6 +70,7 @@ struct CrunchSTFX : public BaseEffect {
|
||||
|
||||
oversampler.resize(channels, config.maxBlockSize, oversampleHalfLatency, std::min(0.45, 21000/config.sampleRate));
|
||||
gainshapers.resize(channels);
|
||||
cutFilters.resize(channels);
|
||||
toneFilters.resize(channels);
|
||||
outputFilters.resize(channels);
|
||||
}
|
||||
@ -73,6 +78,7 @@ struct CrunchSTFX : public BaseEffect {
|
||||
void reset() {
|
||||
oversampler.reset();
|
||||
for (auto &g : gainshapers) g.reset();
|
||||
for (auto &f : cutFilters) f.reset();
|
||||
for (auto &f : toneFilters) f.reset();
|
||||
for (auto &f : outputFilters) f.reset();
|
||||
}
|
||||
@ -88,13 +94,18 @@ struct CrunchSTFX : public BaseEffect {
|
||||
double outputGainFrom = outGain.from();
|
||||
double outputGainTo = outGain.to();
|
||||
if (autoGain) {
|
||||
Sample averageGain = gainshapers[0].averageGain(autoGainLevel*drive.from());
|
||||
outputGainFrom /= drive.from()*averageGain;
|
||||
outputGainTo /= drive.to()*gainshapers[0].averageGain(autoGainLevel*drive.to());
|
||||
Sample cutRatioFrom = 1 - cutHz.from()/(cutHz.from() + 200);
|
||||
Sample averageGainFrom = gainshapers[0].averageGain(autoGainLevel*cutRatioFrom*drive.from());
|
||||
outputGainFrom /= drive.from()*averageGainFrom;
|
||||
Sample cutRatioTo = 1 - cutHz.to()/(cutHz.to() + 200);
|
||||
Sample averageGainTo = gainshapers[0].averageGain(autoGainLevel*cutRatioTo*drive.to());
|
||||
outputGainTo /= drive.to()*averageGainTo;
|
||||
}
|
||||
auto outputGain = block.smooth(outputGainFrom, outputGainTo);
|
||||
|
||||
for (int c = 0; c < channels; ++c) {
|
||||
auto &cutFilter = cutFilters[c];
|
||||
cutFilter.highpass(cutHz/(config.sampleRate*2));
|
||||
auto &gainshaper = gainshapers[c];
|
||||
gainshaper.setFuzzFactor(fuzz);
|
||||
auto &toneFilter = toneFilters[c];
|
||||
@ -107,7 +118,7 @@ struct CrunchSTFX : public BaseEffect {
|
||||
for (int i = 0; i < block.length*2; ++i) {
|
||||
double hi = i*0.5;
|
||||
Sample x = samples[i]*inputGain.at(hi);
|
||||
Sample gain = gainshaper(x)*outputGain.at(hi);
|
||||
Sample gain = gainshaper(cutFilter(x))*outputGain.at(hi);
|
||||
Sample y = x*toneFilter(gain);
|
||||
samples[i] = outputFilter(y);
|
||||
}
|
||||
@ -162,7 +173,7 @@ private:
|
||||
};
|
||||
std::vector<GainshapeADAA> gainshapers;
|
||||
using Filter = signalsmith::filters::BiquadStatic<Sample>;
|
||||
std::vector<Filter> toneFilters, outputFilters;
|
||||
std::vector<Filter> cutFilters, toneFilters, outputFilters;
|
||||
};
|
||||
|
||||
}} // namespace
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user