From ac51a8d34415650ddb30c76f8766003c33f92c48 Mon Sep 17 00:00:00 2001 From: Jose Diaz Rohena Date: Mon, 24 Jul 2023 22:54:23 +0200 Subject: [PATCH] Downsample after upsample. Sounds nasty! Too nasty to be the default. Keep for posterity --- libs/tote_bag/dsp/DigiDegraders.cpp | 13 +++++++++++++ libs/tote_bag/dsp/DigiDegraders.h | 1 + src/PluginProcessor.cpp | 23 ++++++++++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/libs/tote_bag/dsp/DigiDegraders.cpp b/libs/tote_bag/dsp/DigiDegraders.cpp index e3635334..9115d2aa 100644 --- a/libs/tote_bag/dsp/DigiDegraders.cpp +++ b/libs/tote_bag/dsp/DigiDegraders.cpp @@ -55,6 +55,19 @@ void SimpleZOH::processBlock (juce::AudioBuffer& inAudio, } } +void SimpleZOH::processChannel (float* buffer, size_t samplesPerBlock) +{ + auto intDownSampleCoeff = static_cast (downsampleCoeff); + auto frac = downsampleCoeff - intDownSampleCoeff; + + for (int sample = 0; sample < samplesPerBlock; ++sample) + { + auto y1 = getZOHSample (buffer, sample, intDownSampleCoeff); + auto y2 = getZOHSample (buffer, sample, intDownSampleCoeff + 1); + buffer[sample] = tote_bag::audio_helpers::linearInterp (y1, y2, frac); + } +} + inline float SimpleZOH::getZOHSample (const float* channelData, int sampleIndex, int dsCoef) { diff --git a/libs/tote_bag/dsp/DigiDegraders.h b/libs/tote_bag/dsp/DigiDegraders.h index 92da09a6..d1f5bd54 100644 --- a/libs/tote_bag/dsp/DigiDegraders.h +++ b/libs/tote_bag/dsp/DigiDegraders.h @@ -30,6 +30,7 @@ class SimpleZOH void processBlock (juce::AudioBuffer& inAudio, int samplesPerBlock, int numChannels); + void processChannel (float* buffer, size_t samplesPerBlock); float getZOHSample (const float* channelData, int sampleIndex, int dsCoef); private: diff --git a/src/PluginProcessor.cpp b/src/PluginProcessor.cpp index c8a88ad4..70db4596 100644 --- a/src/PluginProcessor.cpp +++ b/src/PluginProcessor.cpp @@ -243,7 +243,9 @@ void ValentineAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBl FFCompParameterID()[getParameterIndex (VParameter::attack)])); ffCompressor->setRelease (*treeState.getRawParameterValue ( FFCompParameterID()[getParameterIndex (VParameter::release)])); - ffCompressor->setSampleRate (sampleRate * oversampleMultiplier); + + const auto processingSampleRate = sampleRate * oversampleMultiplier; + ffCompressor->setSampleRate (processingSampleRate); ffCompressor->reset (samplesPerBlock * oversampleMultiplier); ffCompressor->setOversampleMultiplier (oversampleMultiplier); @@ -252,7 +254,8 @@ void ValentineAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBl saturator->reset (sampleRate); boundedSaturator->reset (sampleRate); - simpleZOH->setParams (static_cast (sampleRate / detail::kDownSampleRate)); + simpleZOH->setParams ( + static_cast (processingSampleRate / detail::kDownSampleRate)); updateLatencyCompensation (true); @@ -362,12 +365,26 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::dsp::AudioBlock highSampleRateBlock = oversampler->processSamplesUp (processBlock); + if (crushOn.get()) + { + for (size_t channel = 0; channel < highSampleRateBlock.getNumChannels(); + ++channel) + { + simpleZOH->processChannel (highSampleRateBlock.getChannelPointer (channel), + highSampleRateBlock.getNumSamples()); + } + + // simpleZOH->processBlock (processBuffer, + // currentSamplesPerBlock, + // totalNumOutputChannels); + } + ffCompressor->process (highSampleRateBlock); if (saturateOn.get()) { // Clear the buffers if saturate just got turned back on - if(!saturateOnState) + if (!saturateOnState) { saturator->clearBuffers(); saturateOnState = true;