# Audio plugin produces static over track

**URL:** <https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325>\
**Category:** Audio Plugins\
**Created:** [December 20, 2016, 6:20pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325 "2016-12-20T18:20:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mUmbler](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mUmbler](https://forum.juce.com/u/mUmbler)\
**Post date:** [December 20, 2016, 6:20pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/1 "2016-12-20T18:20:51Z")

</div>

Hi!

I had seen a post on this forum a while back asking this similar question, and I cannot find it through the forum search. If someone could link that thread for me I would be mighty obliged.

Here is my question regardless. I am still attempting to implement a simple low pass filter. I have gotten over the previous hurtles with null pointers. When I open a track in Audacity and apply my VST, all that occurs is the track plays with some static and pops in the background.

Here is my process audio block:

```auto
void FishTankAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
	const int totalNumInputChannels = getTotalNumInputChannels();
	const int totalNumOutputChannels = getTotalNumOutputChannels();

	// If it ever becomes the point that there are more ouputs then inputs,
	// Then regenerate this file, and see what they did for that sitch :)

	// This is the place where you'd normally do the guts of your plugin's
	// audio processing...

	// Set up variables
	//AudioSampleBuffer mainInputOutput = busArrangement.getBusBuffer(buffer, true, 0);

	float sr = m_sampleRate;

	for (int chan = 0; chan < buffer.getNumChannels(); chan++)
	{
		for (int samp = 0; samp < buffer.getNumChannels(); samp++)
		{
			// Test values
			float testReadPointer = buffer.getReadPointer(chan)[samp];
			float testValue = calculate(buffer.getReadPointer(chan)[samp]);

			// Actual code.
			buffer.getWritePointer(chan)[samp] = calculate(buffer.getReadPointer(chan)[samp]);
		}
	}

}
```

And here is my calculate function, which does the low pass

```auto
float FishTankAudioProcessor::calculate(float input)
{
	float test = m_sampleRate;

	float aExp = (-2 * M_PI) / (m_lowPassSmoothingRate * 1000.0f * m_sampleRate);
	m_a = exp(aExp);
	m_b = 1.0f - m_a;
	m_c = (input * m_b) + (m_c * m_a);
	return m_c;

}
```

If there are any glaring issues, please point them out. I am still new to audio development and the JUCE framework in general.

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [December 20, 2016, 6:29pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/2 "2016-12-20T18:29:39Z")

</div>

This is a common mistake…  
Your calculate is a stateful method. But you are using the same state for all channels.  
You need a separate set of m\_a, m\_b and m\_c for every channel (or better create a filter class you can instanciate for each channel)

Hope that helps…

---

<div class="post-metadata">

**Author:** ![mUmbler](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mUmbler](https://forum.juce.com/u/mUmbler)\
**Post date:** [December 20, 2016, 6:33pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/3 "2016-12-20T18:33:12Z")

</div>

Ok, I will give that a try.

Will changing them to an AudioParameterFloat fix this state problem, or is this unrelated?

---

<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:** [December 20, 2016, 6:38pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/4 "2016-12-20T18:38:57Z")

</div>

> [@mUmbler](#):
>
> Ok, I will give that a try.
> 
> Will changing them to an AudioParameterFloat fix this state problem, or is this unrelated?

You need separate **filter** states for each channel, so you should restructure your code so that you can freely instantiate as many independent filter objects as you need. (That is, implement your filter as a class that you then instantiate in your plugin audioprocessor object as many times as you have audio channels to process.)

There is another bug, you have :

> [@mUmbler](#):
>
> for (int samp = 0; samp \< buffer.getNumChannels(); samp++)

You need buffer.getNumSamples() in that.

---

<div class="post-metadata">

**Author:** ![mUmbler](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mUmbler](https://forum.juce.com/u/mUmbler)\
**Post date:** [December 20, 2016, 6:43pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/5 "2016-12-20T18:43:47Z")

</div>

Yes, I will do that then. And I will fix that bug.

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [December 20, 2016, 6:47pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/6 "2016-12-20T18:47:49Z")

</div>

That’s actually not what I meant. Rather like this:

```
struct Coeffs {
    float a;
    float b;
    float c;
}

```

And have a separate set for every channel:

```
Array<Coeffs> m_coeffs;
void prepareToPlay (double sampleRate, int maximumExpectedSamplesPerBlock) {
    m_coeffs.resize (numChannels);
    // [...]
}

```

and your calculate should use per channel:

```
float FishTankAudioProcessor::calculate (Coeffs& coeffs, float input)
{
    float test = m_sampleRate;
    float aExp = (-2 * M_PI) / (m_lowPassSmoothingRate * 1000.0f * m_sampleRate);
    coeffs.a = exp(aExp);
    coeffs.b = 1.0f - coeffs.a;
    coeffs.c = (input * coeffs.b) + (coeffs.c * coeffs.a);
    return c.m_c;
}

```

and in processBlock:

```
buffer.getWritePointer(chan)[samp] = calculate (m_coeffs.getReference (chan), buffer.getReadPointer(chan)[samp]);

```

Maybe that makes it clearer…

---

<div class="post-metadata">

**Author:** ![mUmbler](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mUmbler](https://forum.juce.com/u/mUmbler)\
**Post date:** [December 20, 2016, 6:55pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/7 "2016-12-20T18:55:15Z")

</div>

No, I understood what you meant. I was going to make a vector of a new class, as opposed to an Array of a struct. But I think I will just use an Array instead. I appreciate the clarification though! I’m new to JUCE, not C++.

---

<div class="post-metadata">

**Author:** ![mUmbler](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mUmbler](https://forum.juce.com/u/mUmbler)\
**Post date:** [December 20, 2016, 6:56pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/8 "2016-12-20T18:56:25Z")

</div>

Or is it a better practice to use your Array, as opposed to the std::vector?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [December 20, 2016, 7:00pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/9 "2016-12-20T19:00:27Z")

</div>

Sorry, got your answer wrong then 😉 No problem

Array or std::vector is no (noticable) difference for that purpose (afaik)… everybody has his own preference there…

And the AudioProcessorParameterFloat is only needed to expose a parameter for control from the host.

Good luck

---

<div class="post-metadata">

**Author:** ![mUmbler](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mUmbler](https://forum.juce.com/u/mUmbler)\
**Post date:** [December 20, 2016, 7:41pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/10 "2016-12-20T19:41:54Z")

</div>

Hi I have one more question. You say to resize the Array to numChannels. I can’t seem how to retrieve this value from the documentation. Am I able to access the AudioSourceChannelInfo struct?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [December 20, 2016, 7:52pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/11 "2016-12-20T19:52:17Z")

</div>

You are in a processor’s context, right?  
For instance you can check the num of outbut channels using [int AudioProcessor::getMainBusNumOutputChannels()](https://www.juce.com/doc/classAudioProcessor#a89e5d408f21d930bd56c21dd2aa8f69b)…  
If you are in an audioSource, you can use the AudioSourceChannelInfo struct, but only in the getNextAudioBlock(), where you shouldn’t make allocations…  
For some reasons a pure AudioSource has no channel numbers property, I don’t know why…

---

<div class="post-metadata">

**Author:** ![mUmbler](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mUmbler](https://forum.juce.com/u/mUmbler)\
**Post date:** [December 20, 2016, 7:56pm UTC](https://forum.juce.com/t/audio-plugin-produces-static-over-track/20325/12 "2016-12-20T19:56:18Z")

</div>

Ahh, I was poking around in the wrong preparetoplay method in the documentation.
