Skip to content

Commit

Permalink
Downsample after upsample. Sounds nasty! Too nasty to be the default.…
Browse files Browse the repository at this point in the history
… Keep for posterity
  • Loading branch information
JoseDiazRohena committed Jul 24, 2023
1 parent 50200d2 commit ac51a8d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
13 changes: 13 additions & 0 deletions libs/tote_bag/dsp/DigiDegraders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ void SimpleZOH::processBlock (juce::AudioBuffer<float>& inAudio,
}
}

void SimpleZOH::processChannel (float* buffer, size_t samplesPerBlock)
{
auto intDownSampleCoeff = static_cast<int> (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)
{
Expand Down
1 change: 1 addition & 0 deletions libs/tote_bag/dsp/DigiDegraders.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SimpleZOH
void processBlock (juce::AudioBuffer<float>& inAudio,
int samplesPerBlock,
int numChannels);
void processChannel (float* buffer, size_t samplesPerBlock);
float getZOHSample (const float* channelData, int sampleIndex, int dsCoef);

private:
Expand Down
23 changes: 20 additions & 3 deletions src/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -252,7 +254,8 @@ void ValentineAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBl

saturator->reset (sampleRate);
boundedSaturator->reset (sampleRate);
simpleZOH->setParams (static_cast<float> (sampleRate / detail::kDownSampleRate));
simpleZOH->setParams (
static_cast<float> (processingSampleRate / detail::kDownSampleRate));

updateLatencyCompensation (true);

Expand Down Expand Up @@ -362,12 +365,26 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
juce::dsp::AudioBlock<float> 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;
Expand Down

0 comments on commit ac51a8d

Please sign in to comment.