# How to fix JUCE Slider Updating Filter Delay?

**URL:** <https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113>\
**Category:** Audio Plugins\
**Created:** [June 26, 2019, 9:45pm UTC](https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113 "2019-06-26T21:45:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rarrar](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@rarrar](https://forum.juce.com/u/rarrar)\
**Post date:** [June 26, 2019, 9:45pm UTC](https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113/1 "2019-06-26T21:45:05Z")

</div>

Hello, I’m new to JUCE and I was testing filters on some input. I’m using the Slider component to adjust the frequency, but I realized the filter updates extremely slowly. When I suddenly change the frequency slider, it takes about half a second for me to actually hear the filter change. Am I doing something wrong?

This is my processBlock function:

```auto
    void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
{
	filter.setCoefficients(IIRCoefficients::makeHighPass(getSampleRate(), std::max(0.000000001,frequencyPercentage*0.5f*getSampleRate())));
    auto totalNumOutputChannels = getTotalNumOutputChannels();
	for (int channel = 0; channel < totalNumOutputChannels; ++channel)
	{
		auto* outData = buffer.getWritePointer(channel);
		for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
		{
			outData[sample] = random.nextFloat() - 1;
		}
		filter.processSamples(outData, buffer.getNumSamples());
	}

```

This is my sliderValueChanged function:

```auto
    void sliderValueChanged(Slider* slider)
{
	processor.frequencyPercentage = frequencySlider.getValue();
}

```

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [June 26, 2019, 9:54pm UTC](https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113/2 "2019-06-26T21:54:02Z")

</div>

How long is the processing buffer? (buffer.getNumSamples()) What operating system/device are you trying it on?

---

<div class="post-metadata">

**Author:** ![rarrar](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@rarrar](https://forum.juce.com/u/rarrar)\
**Post date:** [June 26, 2019, 10:47pm UTC](https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113/3 "2019-06-26T22:47:30Z")

</div>

I’m on windows 10, and getNumSamples() returns 2560

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [June 26, 2019, 11:13pm UTC](https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113/4 "2019-06-26T23:13:03Z")

</div>

That’s already a relatively long buffer and an experienced user/musician would easily notice it, but it wouldn’t cause a latency of “half a second” by itself. Maybe there’s additional latency coming from your sound hardware or its driver…? What hardware/device are you using to listen to the sound? (Or are you running the code as a plugin inside some host application? If yes, which host?)

---

<div class="post-metadata">

**Author:** ![rarrar](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@rarrar](https://forum.juce.com/u/rarrar)\
**Post date:** [June 27, 2019, 3:05am UTC](https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113/5 "2019-06-27T03:05:56Z")

</div>

Never mind, I don’t know how but somehow it’s fixed. But now I’m running into another problem, my highpass filter is producing a horrible Buzz when there’s any input audio and I can’t see why.

```auto
processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
{
    auto totalNumInputChannels = getTotalNumInputChannels();
    auto totalNumOutputChannels = getTotalNumOutputChannels();
	for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
		buffer.clear (i, 0, buffer.getNumSamples());
	for (int channel = 0; channel < totalNumOutputChannels; ++channel)
	{
		float* channelData = buffer.getWritePointer(channel);
		mFrequencySmoothed = mFrequencySmoothed - 0.4*(mFrequencySmoothed - mFrequencyParameter->get());
		filter->setCoefficients(IIRCoefficients::makeHighPass(getSampleRate(), mFrequencySmoothed));
		filter->processSamples(channelData, buffer.getNumSamples());
	}
}

```

---

<div class="post-metadata">

**Author:** ![jMahn](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@jMahn](https://forum.juce.com/u/jMahn)\
**Post date:** [June 27, 2019, 4:56pm UTC](https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113/6 "2019-06-27T16:56:06Z")

</div>

An IIR filter maintains internal state from the previous call to processSamples so you can’t reuse the same filter instance across multiple channels.

You need to have an instance of the filter for each channel and then in the code above, assuming you did that by declaring an array of filters, use filter[channel]-\>…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 27, 2019, 5:07pm UTC](https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113/7 "2019-06-27T17:07:05Z")

</div>

> [@\#1 most common programming mistake that we see on the forum](https://forum.juce.com/t/1-most-common-programming-mistake-that-we-see-on-the-forum/26013):
>
> This post is here so that we have something we can link to when this same issue comes up, because the JUCE team is getting very bored of spending time replying again and again to the same damned problem! This isn’t a JUCE bug - there’s nothing we can do in our codebase that would stop people making it, which makes it painful for us to watch beginner after beginner come along and fall headfirst into the same trap! It’s also understandable that people will post a new topic when they hit it, beca…

---

<div class="post-metadata">

**Author:** ![rarrar](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@rarrar](https://forum.juce.com/u/rarrar)\
**Post date:** [July 3, 2019, 3:13am UTC](https://forum.juce.com/t/how-to-fix-juce-slider-updating-filter-delay/34113/8 "2019-07-03T03:13:47Z")

</div>

Thanks for the reply! Maybe add a section called “Common mistakes” in the “learn” section of the main website, that may stop beginners from repeating the same mistakes again and again.
