[SOLVED] Beginner - Need Buffer Clarification


#1

Hi,
I’ve just started to learn c++ programming with online video tutorials and Juce (i read the getting started book).

I also purchased Will Pirkle’s book “Designing Audio Effect Plug-Ins in C++” which uses RackAFX, and i’m trying to convert the code into Juce.

But apparently there’s something i don’t understand with the buffer in Juce. Cause everything i’m trying is very glitchy.

For example here is my attempt to create, using Juce, one of the first example in Will’s book. a simple HPF (using a one sample delay).

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

for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
    buffer.clear (i, 0, buffer.getNumSamples());

for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
float* channelData = buffer.getWritePointer(channel);
float previousSample = 0;
float a0 = sliderVal;
float a1 = sliderVal - 1;
float z1 = 0;

  for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
  {		
  	float xn = channelData[sample];
  	float xn_1 = z1;
  	float yn = (a0*xn) + (a1*xn_1);
  	z1 = xn;
  	channelData[sample] = yn;
  }

}
}

Could anyone help me understand why each time i’m trying to modify the content of channelData[sample], i’m getting glitches.
Thanks!


#2

z1 needs to be a member variable of your LearningJuceAudioProcessor class. In your code z1 is local to the function so it gets reset to zero on each callback.


#3

Hey buddy, I’m just skimming through this on a quick lunch break so I may be wrong but is it not because you aren’t saving the z1 delay elements state between process blocks ?

The unit delay (z1) goes out of scope with every call to processBlock which I think may be causing glitches.

Checkout a link here for a similar filter (one pole VA filter) that works in a demo plugin I whacked together and have still yet to finish because I was getting used to the new parameters system and then got side tracked with work and the joys of C# .Net web stuff…dull.

Have a look at VAOnePoleFilter.cpp and VAOnePoleFilter.h on the repo above for an idea of how the filter should work.

File above shows the filter being called in the processBlock.

Cheers.

Josh


#4

Note you probably also want to have your unit z1 delay set up as a 2 channel delay. i.e z1[2] and use z1[channelNumber] in your process block to avoid glitches if your going to process the filter in stereo.

So maybe do that and ensure your maintaining the z1 delay state between process blocks (by having it as a member variable in either your filter class or PluginProcessor.h file/Class.

That should get you on the way.

Check the example link I posted.

I’ll take a quick look at this again for you tonight if that doesn’t work. Best be back to the C# !


#5

Haha.

Clearly sat dropping the same response on our lunch breaks…

Loved the new MIDI tutorial by the way Martin.

Cheers


#6

Thanks for the help!

Ok so i declared z1 as a float array[2] in the private variables (in my PluginProcessor.h)

And changed my sample for loop to this:

for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
{
float xn = channelData[sample];
float xn_1 = z1[channel];
float yn = (a0xn) + (a1xn_1);
z1[channel] = xn;
channelData[sample] = yn;
}

The glitches are gone. But there’s is no filtering (just a volume attenuation).
By the way, the range of sliderVal is 0.0 to 0.49 (to prevent the filter blowing up)


#7

Are the filter coefficients right ?

Should a0 = sliderVal - 1 rather than a1 ?

Not sure if that’s right. Just quickly skimmed the chapter with that filter as I have access to an online version.


#8

yes! Thank you so much!

I so wish this book would be for Juce.
I guess its gonna be a nice challenge to translate as i go along.


#9

No Problem.

The Synth book by Will Pirkle is also great and I can also recommend Nigel Redmon’s blog:

http://www.earlevel.com/main/

Also the following book is very similar to Will Pirkle’s work with specific JUCE examples and written by two guys at QMUL so definitive worth a look:

Some of the parameter examples are a little out of date with the new JUCE classes but you should be able to translate it all across fairly easily. Feel free to drop me a message if you ever have any newbie questions.

I’m hoping to put together a few example plugins and other things when I finally get the time and may try to see if I can provide a tutorial on something in the future.


#10

Purchased!
Thanks for the recommendation and support.