Using custom filter coefficients in the DSP module


I’m running into an issue I can’t seem to find an answer to by Googling or searching the forums, so I figured I’d make a separate post about it. I’m trying to initialize a

dsp::ProcessorDuplicator <dsp::IIR::Filter , dsp::IIR::Coefficients> filter1;

with custom coefficients (i.e. not using the make functions provided). In the initialization, I run

filter1(dsp::IIR::Coefficients::Coefficients(1.0f, 1.876976933974730f, 0.913309801365904f, 1.0f, 1.934382545704437f, 0.971826620399618f))

which in my limited knowledge seems right, but I get an assertion failure at run after this line. The error I get is in juce_ReferenceCountedObject.h and the piece of code is as follows:

virtual ~ReferenceCountedObject()
    // it's dangerous to delete an object that's still referenced by something else!
    jassert (getReferenceCount() == 0);

I’m out of ideas as to what could be going wrong. I’ve tried multiple variations of this so far and can’t seem to escape this error. Using the same procedure with the make functions works fine.

Thank you!

You should wrap the coefficients in a Ptr, since that is reference counted.
By creating the Coefficients directly on the stack, they are deleted twice.

I think it looks like that, have a look at the IIR::Coefficients::makeLowPass etc. functions for reference

juce::dsp::IIR::Coefficients<float>::Ptr coeffs (new juce::dsp::IIR::Coefficients<float>(1.0f, 1.876976933974730f, 0.913309801365904f, 1.0f, 1.934382545704437f, 0.971826620399618f));

*filter1.state = *coeffs;

This shows a design problem, that the coefficients shouldn’t be created on the audio thread, but that is a different discussion, and there is already a thread about that

Daniel, thank you - that seems to have worked!