I’m currently working on a filter plugin with the filter cutoff frequency controlled by a slider. Every time the slider is moved, I need to recalculate my filter using the new cutoff frequency. The function that calculates the filter looks something like this:
for (auto i = 0; i < filterSize; ++i)
filter[i] = /some index dependent value/
filter[filterSize/2] = /specific index independent value/
The statement outside the loop is necessary to avoid a NaN result.
This works fine the first time is runs but I’m having some issues when this function is called as a result of the slider changing.
I’ve made my plugin editor inherit from Slider::Listener, have added it as the slider listener and have overriden sliderValueChanged:
void sliderValueChanged(juce::Slider* slider)
if (slider == &cutoffFreqSlider)
float cutoff = cutoffFreqSlider.getValue();
The call to setCutoffFreq also includes a call to the filter calculation function but this time when the function runs it is interupted immediately after the loop finishes by AudioDeviceManager::audioDeviceIOCallback on the WASAPI thread, which in turn calls my processBlock function before the NaN value is dealt with.
My main question, is there any way to guarantee my filter calculation function fully executes without interruption?
As a secondary question, I noticed that my filter calculation function is running on the Juce Message Thread. Is this a problem? Is this because it is called by sliderValueChanged on the editor side rather than the processor side?
I’m not well versed in multithreading so apologies if I’ve left out any important details.
edit: changed an incorrect variable name