Skip to content

Commit

Permalink
Updated Filterbank to use interpolated TwoPole
Browse files Browse the repository at this point in the history
  • Loading branch information
adanlbenito committed Mar 16, 2023
1 parent 98523bf commit e4d8d44
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
59 changes: 48 additions & 11 deletions NeuralResonatorVST/Filterbank.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#include "Filterbank.h"
Filterbank::Filterbank()
{
mNumParallel = 0;
mNumBiquads = 0;
mStride = 0;
}

Filterbank::Filterbank(int numParallel, int numBiquads)
{
setup(numParallel, numBiquads);
}

void Filterbank::setup(int numParallel, int numBiquads)
{
mNumParallel = numParallel;
mNumBiquads = numBiquads;
Expand All @@ -17,29 +28,44 @@ Filterbank::Filterbank(int numParallel, int numBiquads)
{
for (int j = 0; j < mNumBiquads; j++)
{
mIIRFilters[i][j].set_coefficients(0.0, 0.0, 0.0, 0.0, 0.0);
mIIRFilters[i][j].setup(0);
mIIRFilters[i][j].setCoefficientValues(0.0, 0.0, 0.0, 0.0, 0.0);
}
}
}

Filterbank::~Filterbank() {}
Filterbank::~Filterbank()
{
cleanup();
}

void Filterbank::cleanup()
{
juce::Logger::writeToLog("Filterbank::cleanup()");
for (int i = 0; i < mNumParallel; i++)
{
for (int j = 0; j < mNumBiquads; j++)
{
mIIRFilters[i][j].cleanup();
}
}
}

void Filterbank::setCoefficients(const std::vector<float>& coeffs)
{
const juce::SpinLock::ScopedLockType lock(mProcessLock);

for (int i = 0; i < mNumParallel; i++)
{
for (int j = 0; j < mNumBiquads; j++)
{
int idx = i * mNumBiquads * mStride + j * mStride;
mIIRFilters[i][j].set_coefficients(
coeffs[idx],
coeffs[idx + 1],
coeffs[idx + 2],
coeffs[idx + 4],
coeffs[idx + 5]
);
mIIRFilters[i][j].set_coefficients(
coeffs[idx],
coeffs[idx + 1],
coeffs[idx + 2],
coeffs[idx + 4],
coeffs[idx + 5]
);
}
}
}
Expand Down Expand Up @@ -69,4 +95,15 @@ void Filterbank::processBuffer(juce::AudioBuffer<float>& buffer)
buffer.setSample(channel, sampleIdx, static_cast<float>(out));
}
}
}
}
void Filterbank::setInterpolationDelta(unsigned int delta)
{
mInterpolationDelta = delta;
for (int i = 0; i < mNumParallel; i++)
{
for (int j = 0; j < mNumBiquads; j++)
{
mIIRFilters[i][j].setDelta(mInterpolationDelta);
}
}
}
13 changes: 10 additions & 3 deletions NeuralResonatorVST/Filterbank.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#pragma once

#include "TwoPole.h"
#include "TwoPoleInterpolated.h"
#include <juce_core/juce_core.h>
#include <juce_audio_basics/juce_audio_basics.h>
#include <vector>

class Filterbank
{
public:
Filterbank(int numParallel, int numBiquads);
Filterbank();
~Filterbank();

Filterbank(int numParallel, int numBiquads);
void setup(int numParallel, int numBiquads);

void cleanup();
/**
* @brief Set the coefficients of the filterbank
* @note The coefficients are expected to be in the following order:
Expand All @@ -28,12 +32,15 @@ class Filterbank
*/
void processBuffer(juce::AudioBuffer<float>& buffer);

void setInterpolationDelta(unsigned int delta);

private:
std::vector<std::vector<TwoPole<double>>> mIIRFilters;
std::vector<std::vector<TwoPoleInterpolated>> mIIRFilters;

int mNumParallel;
int mNumBiquads;
int mStride;
unsigned int mInterpolationDelta;

juce::SpinLock mProcessLock;

Expand Down

0 comments on commit e4d8d44

Please sign in to comment.