Understanding how to use processblock in an audio plug in


#1

Hey :slight_smile:

I am building a VST at the moment and I think I need some help making it work properly.
I got my functions working all nicely, that is not the issue, its more framework related stuff, for example:

A. I am having issues with loading several of the plug in in a Logic project.
If i load 3 plug ins, all the tracks with the plug ins on are silenced.

B. Another thing is that sometimes when I open a project all the tracks with the plug ins
on are silenced.

C. A third thing, I can only load the plug in on a mono track, if I load it on a stereo track, I get all kinds of weird clicks and pops and all kinds of artefacts.

I know that I have not set up the process block correctly, but I have been kind of pushing
it in front of me, but now I am at a point I have to get this fixed before I proceed any further. I tried to implement some new functions and only got worse, so I guess I can’t delay learning how to set up the process buffer correctly any longer.

But I need some tips on understanding how to set it up. I think have set it up a bit differently than others do, as I am still learning and I need to understand what I am doing, so I am doing it “my own way”, and probably need to change this, as it doesn’t look like how most people do this.

I am not sure I understand how it works, so bare with me if I am completely off:

In my processor block:

Standard stuff for an audio plug in;
ScopedNoDenormals noDenormals;
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();

for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
{
As I understand it this gets the number of channels loaded in the DAW.
If its a stereo track it rapports “2“ to Juce, if mono it rapports “1”.

  Channel assignment:
  	  for (int channel = 0; channel < totalNumInputChannels; ++channel)
		 {	
   Input/output delcarations within buffer
    		  const float* InputData = buffer.getReadPointer (channel);
    		 float* OutputData = buffer.getWritePointer (channel);

  Notes for channels:
  As I understand it, when I use this set up, the algorithm inside the { } 
  will be assigned to the amount of channels actually loaded in DAW. So If I load it  on a mono 
  track It only processes the algorithm inside the { } ONE single time, for the mono channel.

  But when Stereo plug in is loaded it processes the algorithm 2 times, one for left and one for right. 
  Is my understanding correct?
  		
  PSEUDOCODE
  float* filterin[channel] = InputData[channel];		
  
  DO FILTERING
  
  float* filterout[channel] = filtered signal:

  Why my filter algorithm is put in channels. 
  The reason why I have it here is cause as I understand it, the algorithm will be processed 
  according to how many channels is rapport from “buffer.getNumSamples”. Again loaded on 
  mono track the algorithm is only processed 1 time, stereo 2 times…..  If stereo, the filter
  is processed 2 times, one for each channel set from the DAW.




  	Finally assign filter to each sample, on each channel:
  	for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
    			{

  	I tried to implement the filter into the sample buffer. But this I am not sure how to do it.
  	I think this is where it goes wrong for me and causes > the issues I am having. I know
  	its not right set up, but not sure what to do. The stuff > 
                    beneath is pure guess work.

  	float* Filterinput[sample] 		= filterout[channel];
  	OutputData[channel]  		= Filterinput[sample]; 
  	}
  }

}

Just to clarify I know that this code will not working practice i am just trying to understand how to work with the buffer, when
having more than 1 channel. I know I could copy everything and make duplicate of the code, but that doesn’t really
seem like a very efficient idea.

ESPECIALLY the last part, assigning the process to each sample, I know I am totally off here, as its now working at all here.
And I am thinking that most of the problem I am having is related to the misunderstanding of who to use the process block.

Anyway if any one got a few words on this it would be appreciated. I think I might have to go many steps back in the plug in development and get this working properly, it seems like I have painted myself into a corner as everything I do right now only makes it more unstable.

Thanks


#2

Hey, check this tutorial it should help get you moving in the right direction.

In terms of loading the plugin in the right state…have you set up a value tree and are you saving your plugin state to xml? If not then start here:



#3

Hey Joshua :slight_smile:

I watched the tutorial a few times all ready and tried to recreate it. But my set up is a bit different than yours.

I could follow it all the way until you start to implement the DSPProcess into the output. At that point I lost it, hehe :slight_smile:

Anyway, my plug in is like this:
Audio in> filter > drive > audio out.

and I think its because my filter is a diffrent filter and it is not set up same way as yours. I have mine in the process block directly atm. Maybe I should go back a few steps and try making it into a class, as yours. I think I’ll try that.

After the filter I also have a drive stage. But yeah, going a few steps back is probably the best way to solve this, then first solve the stereo issue and THEN add more to my filter.

Thanks :slight_smile:

Regarding the vaue tree, I first implemented the filter and the drive and then I added the XML for recalling. But it has become more unstable after I implemented this, so I went back a few steps.

But recalling works, I think its simply the process block thing I need to fix. I hope when I get this fixed, audio will work properly when clsoing/opening projects.


#4

If the behaviour changes depending if you have only one or several instances of your plugin, it sounds like you are using static variables maybe? These would be shared amongst each instance and leading to unwanted side effects.

If it happens sometimes, it sounds like you didn’t initialise your variables. You have to assign them a value before you use them. Your compiler should warn you (try to address ALL warnings in your code, they are there for a reason)

This sounds like you use one state on all channels. Most filters have the previous samples as context, so when you use that on the other channel, the signal is interrupted and sudden jumps in the signal are unavoidable.

Good luck!


#5

Thanks guys, I had to take a break from the vst plug in development. All this framework stuff is a bit more than I understood so I am taking some more programming courses.

And also focusing on writing algo’s on other platforms that I can port over as soon as I understand the coding a bit better.

Thanks again!