Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Fix comb-filter effect on oversampled dry/wet; Fix link-in-out knob positioning; Fix oversampled filter artefacts #100

Merged
merged 19 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix comb filter effect
  • Loading branch information
vvvar committed Aug 5, 2023
commit 94ad687772a7ad3e2d6c9b547608aa2584c50528
12 changes: 6 additions & 6 deletions source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void PeakEaterAudioProcessor::changeProgramName(int /* index */, juce::String co
void PeakEaterAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) {
juce::dsp::ProcessSpec const spec{sampleRate, static_cast<juce::uint32>(samplesPerBlock), 2};
dryWet.prepare(spec);
dryWet.setWetLatency(54);
inputGain.prepare(spec);
for (auto &clipper : clippers) {
clipper.prepare(spec);
Expand Down Expand Up @@ -214,7 +215,11 @@ void PeakEaterAudioProcessor::processBlock(juce::AudioBuffer<float> &buffer, juc
for (auto &clipper : clippers) {
clipper.setClippingType(parameterChoiceToClippingType(*mClippingType));
clipper.setThreshold(*mCeiling);
clipper.setDryWetProportion(*mDryWet);
if (clipper.getOversamplingFactor() == static_cast<size_t>(*mOversampleRate)) {
auto const latency = clipper.getLatency();
setLatencySamples(latency);
dryWet.setWetLatency(latency);
}
}
outputGain.setGainDecibels(*mOutputGain);
//-----------------------------------------------------------
Expand All @@ -234,11 +239,6 @@ void PeakEaterAudioProcessor::processBlock(juce::AudioBuffer<float> &buffer, juc
outputGain.process(context);
mLevelMeterPostOut->updateLevels(context.getOutputBlock());
dryWet.setWetMixProportion(*mDryWet);
for (auto &clipper : clippers) {
if (clipper.getOversamplingFactor() == static_cast<size_t>(*mOversampleRate)) {
dryWet.setWetLatency(clipper.oversampler.getLatencyInSamples());
}
}
dryWet.mixWetSamples(context.getOutputBlock());
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PeakEaterAudioProcessor : public juce::AudioProcessor {
juce::AudioParameterChoice* mOversampleRate;
juce::AudioParameterFloat* mDryWet;

juce::dsp::DryWetMixer<float> dryWet;
juce::dsp::DryWetMixer<float> dryWet{66};
juce::dsp::Gain<float> inputGain;
std::array<Clipper<float>, 6> clippers{Clipper<float>{0}, Clipper<float>{1}, Clipper<float>{2},
Clipper<float>{3}, Clipper<float>{4}, Clipper<float>{5}};
Expand Down
16 changes: 4 additions & 12 deletions source/processor/Clipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ void Clipper<SampleType>::prepare(juce::dsp::ProcessSpec const& spec) {
preGain.prepare(oversampledSpec);
preGain.setRampDurationSeconds(0.1f);
//-----------------------------------------------------------
// Setup dry/wet
dryWet.prepare(oversampledSpec);
//-----------------------------------------------------------
// Prepare wave shaper
waveShaper.prepare(oversampledSpec);
//-----------------------------------------------------------
Expand All @@ -73,7 +70,6 @@ void Clipper<SampleType>::reset() {
oversampler.reset();
preFilter.reset();
preGain.reset();
dryWet.reset();
waveShaper.reset();
postGain.reset();
postFilter.reset();
Expand Down Expand Up @@ -180,17 +176,13 @@ void Clipper<SampleType>::setClippingType(ClippingType const type) {
}

template <typename SampleType>
void Clipper<SampleType>::setDryWetProportion(SampleType const proportion) {
// 0.0 - fully dry(un-clipped)
// 1.0 - fully wet(clipped)
// Everything above/beyond - incorrect
jassert(proportion >= static_cast<SampleType>(0.0) && proportion <= static_cast<SampleType>(1.0));
dryWet.setWetMixProportion(proportion);
[[nodiscard]] size_t Clipper<SampleType>::getOversamplingFactor() const {
return oversamplingFactor;
}

template <typename SampleType>
[[nodiscard]] size_t Clipper<SampleType>::getOversamplingFactor() const {
return oversamplingFactor;
[[nodiscard]] int Clipper<SampleType>::getLatency() const {
return static_cast<int>(oversampler.getLatencyInSamples());
}

} // namespace pe::processor
Expand Down
11 changes: 3 additions & 8 deletions source/processor/Clipper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,17 @@ class Clipper {
*/
void setClippingType(ClippingType const type);

/*! \brief Set dry/wet mixing proportion.
*
* Signal would be mixed right after the wave shaping.
*/
void setDryWetProportion(SampleType const proportion);

[[nodiscard]] size_t getOversamplingFactor() const;

juce::dsp::Oversampling<SampleType> oversampler;
/*! \brief Get latency in samples */
[[nodiscard]] int getLatency() const;

private:
size_t oversamplingFactor = 0;

juce::dsp::ProcessorDuplicator<juce::dsp::IIR::Filter<SampleType>, juce::dsp::IIR::Coefficients<SampleType>> preFilter;
juce::dsp::Gain<SampleType> preGain;
juce::dsp::DryWetMixer<SampleType> dryWet;
juce::dsp::Oversampling<SampleType> oversampler;
juce::dsp::WaveShaper<SampleType> waveShaper;
juce::dsp::Gain<SampleType> postGain;
juce::dsp::ProcessorDuplicator<juce::dsp::IIR::Filter<SampleType>, juce::dsp::IIR::Coefficients<SampleType>> postFilter;
Expand Down