Problems with a decimator


Hello I am a vst / juce newbie.

I am trying to figure out sample rate reduction and bit crushing. I got the code of a nice vst decimator example , and I am trying to understand what it does. I already understand bit curshing well. However, I am having problems with downsampling. The main problem I have is that I think the plugin doesn’t process audio properly.

Can you guys check this video and tell me what you think?

If you see the video, you will quickly realize what the problem is: when I change sample rates, I get annoying pops and crackles.

Does anybody know what is wrong with the audio processing of this code?

Here is the code that does all the decimation (I posted an image because syntax highlighting helps, if it is annoying I won’t do that anymore):

Here is processBlock again

void myPlugin::processBlock (AudioSampleBuffer& buffer,
                                   MidiBuffer& midiMessages)
  // initialize y1 and cnt to 0

  // go through each active input channel
	for (int channel = 0; channel < getNumInputChannels(); ++channel){
		float *p = buffer.getSampleData (channel);
		int size = buffer.getNumSamples();

    //pass each sample from sample data and decimate
    for (int x=0; x<size; x++){
    	cnt += sampleRate;
    	if (cnt >= 1){
    		cnt -= 1;
    		y1 = (*(p+x));
			*(p+x) = y1;

	for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
		buffer.clear (i, 0, buffer.getNumSamples());


I remember doing the same thing some time ago, the project is still there
you can check the code in kitty.cpp it does almost the same stuff your code does (the vars have the same name, we problay used the same source to get this working).


Yea, I got the code from there as well as you did.

I changed it a little bit and placed everything in processBlock to make it easier for people to understand.
That said, if I compile the original kitty-vst. I still have the same exact problem: pops and clicks because of samplerate processing.

In fact, if I use the binary kitty-vst dll, the pops are still there.

Any ideas of what may be causing those and how to fix them?

If I run any other bitcrusher, like cubase’s bitcrusher or kore lo-fi they work well (that’s why I am assuming it’s not my computer).