Hey,
I decided to have some fun and write an FIR filter. Overall, here’s what I came up with:
#pragma once
#include <JuceHeader.h>
namespace Filter
{
juce::dsp::FIR::Coefficients<float> createLowFilterFIR(float sampleRate, float frequency, float gain, bool isShelf)
{
int numTaps = 101; // count FIR coeffs
std::vector<float> taps(numTaps, 0.0f);
float omega = juce::MathConstants<float>::twoPi * frequency / sampleRate;
float alpha = std::sin(omega) / (2.0f * (isShelf ? 0.71f : 1.0f)); // Q for Shelf / Bell
for (int i = 0; i < numTaps; ++i)
{
float window = 0.54f - 0.46f * std::cos(juce::MathConstants<float>::twoPi * i / (numTaps - 1));
if (isShelf)
{
taps[i] = window * (std::sin(omega * i) / (i + 1.0f) * alpha); // Shelf
}
else
{
taps[i] = window * (std::sin(omega * i) / (i + 1.0f) * alpha); // Bell
}
}
// Normalization coeffs
float sum = 0.0f;
for (float tap : taps)
sum += tap;
for (float& tap : taps)
tap /= sum;
return juce::dsp::FIR::Coefficients<float>(taps.data(), taps.size());
}
}
Using in dsp main:
void EQAudioProcessor::updateFilters()
{
auto LF_Coefficients = Filter::createLowFilterFIR(getSampleRate(), LF_Frequency, juce::Decibels::decibelsToGain(LF_Volume), false);
leftChain.get<ChainPositions::LowCut>().coefficients = LF_Coefficients;
rightChain.get<ChainPositions::LowCut>().coefficients = LF_Coefficients;
}
in main head:
void updateFilters();
using FIRFilter = juce::dsp::FIR::Filter<float>;
using MonoChain = juce::dsp::ProcessorChain<FIRFilter, FIRFilter, FIRFilter, FIRFilter>;
MonoChain leftChain, rightChain;
So the plugin validates fine, but when I add it to the insert, the sound disappears, and there are no errors or anything like that in the code. If anyone has developed similar filters before, I’d appreciate a few tips on how to fix the situation or investigate using DBG.
