AnalogTapeModel

Physical modelling signal processing for analog tape recording
Log | Files | Refs | Submodules | README | LICENSE

commit 8df3b4a32781f3d2a6c55b3f37c2d885e03edd3d
parent a38b58c7967ea80e4e523f925228e18afadf73ce
Author: jatinchowdhury18 <jatinchowdhury18@gmail.com>
Date:   Sun,  6 Sep 2020 20:30:04 -0700

Update DC blocker to 4th-order Butterworth HPF (#83)

Co-authored-by: jatinchowdhury18 <jatinchowdhury18@users.noreply.github.com>
Diffstat:
MPlugin/Source/Processors/Hysteresis/HysteresisProcessor.cpp | 33++++++++++++++++++---------------
MPlugin/Source/Processors/Hysteresis/HysteresisProcessor.h | 4+---
2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/Plugin/Source/Processors/Hysteresis/HysteresisProcessor.cpp b/Plugin/Source/Processors/Hysteresis/HysteresisProcessor.cpp @@ -132,15 +132,18 @@ void HysteresisProcessor::prepareToPlay (double sampleRate, int samplesPerBlock) overSample[i]->initProcessing (samplesPerBlock); prevOS = curOS; - dcBlocker[0].reset (sampleRate); - dcBlocker[0].calcCoefs (dcFreq, 0.707f); - dcBlocker[1].reset (sampleRate); - dcBlocker[1].calcCoefs (dcFreq, 0.707f); - - // dcLower[0].reset (sampleRate); - // dcLower[0].calcCoefs (dcShelfFreq, 0.707f, Decibels::decibelsToGain (-12.0f)); - // dcLower[1].reset (sampleRate); - // dcLower[1].calcCoefs (dcShelfFreq, 0.707f, Decibels::decibelsToGain (-12.0f)); + for (int ch = 0; ch < 2; ++ch) + { + // Q values for 4th-order Butterworth filter + // (https://en.wikipedia.org/wiki/Butterworth_filter#Normalized_Butterworth_polynomials) + constexpr float orders[] = { 1.0f / 0.7654f, 1.0f / 1.8478f }; + + for (int order = 0; order < 2; ++order) + { + dcBlocker[ch][order].reset (sampleRate); + dcBlocker[ch][order].calcCoefs (dcFreq, orders[order]); + } + } } void HysteresisProcessor::releaseResources() @@ -180,7 +183,7 @@ void HysteresisProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& dsp::AudioBlock<float> block (buffer); dsp::AudioBlock<float> osBlock = overSample[curOS]->processSamplesUp (block); - + if (needsSmoothing) { if (useV1) @@ -195,7 +198,7 @@ void HysteresisProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& else process (osBlock); } - + overSample[curOS]->processSamplesDown (block); applyDCBlockers (buffer); @@ -273,11 +276,11 @@ void HysteresisProcessor::applyDCBlockers (AudioBuffer<float>& buffer) { for (int channel = 0; channel < buffer.getNumChannels(); ++channel) { - auto* x = buffer.getWritePointer (channel); - for (int samp = 0; samp < buffer.getNumSamples(); samp++) + for (int order = 0; order < 2; ++order) { - x[samp] = dcBlocker[channel].processSample (x[samp]); - // x[samp] = dcLower[channel].processSample (x[samp]); + auto* x = buffer.getWritePointer (channel); + for (int samp = 0; samp < buffer.getNumSamples(); samp++) + x[samp] = dcBlocker[channel][order].processSample (x[samp]); } } } diff --git a/Plugin/Source/Processors/Hysteresis/HysteresisProcessor.h b/Plugin/Source/Processors/Hysteresis/HysteresisProcessor.h @@ -53,12 +53,10 @@ private: int curOS = 0, prevOS = 0; HysteresisProcessing hProcs[2]; std::unique_ptr<dsp::Oversampling<float>> overSample[5]; // needs oversampling to avoid aliasing - TransformerHPF dcBlocker[2]; - // TransformerShelf dcLower[2]; + TransformerHPF dcBlocker[2][2]; int overSamplingFactor = 2; const float dcFreq = 35.0f; - const float dcShelfFreq = 60.0f; float biasGain = 10.0f; float biasFreq = 48000.0f;