View Single Post
Old 04-03-2019, 07:51 PM   #443
Human being with feelings
mrelwood's Avatar
Join Date: Nov 2006
Location: Finland
Posts: 1,391

You might just word them out differently, but it sounds like a few things call for a better explanation.

Originally Posted by danerius View Post
//They need to be odd numbers to set a correct midpoint.
I thought like that at first as well. But I think the center point is meaningless. The code can only average the samples after they have all been stored, and it can only output the result once new samples will no longer affect the result. So it should always calculate the average from the sample ”now” backwards to "slider1" samples ago. It doesn’t matter wether it averages 2 or 3 samples, it will still store the latest sample and output the average of all samples.

I think of it as a box that I’m dragging across sand. The box has holes in the front and back. As I drag it forward, at every step a bunch of sand gets into the box from the front hole, gets mixed with the previous sand particles, and a part of the sand mix drops out from the rear hole. The box can be 2 or 3 feet long, makes no difference.

//"buffer" zeros current memory slot
Not quite. Memory slots in JS are just simple numbers from [0] onwards. ”Buffer” is not a memory slot, only the first zero in 0+[0]. ”Buffer” is never changed in this plugin, so it is always just zero. "buffer[bufPos] = 0" would zero the memory slot. Or "[0] = 0".

//"pdc_delay" sets a midpoint for samples to be averaged
No, pdc_delay is just the amount of samples that other plugins are delayer for. It does not affect the output or behaviour of your plugin.

//"buOffs" resets the stored samples and restarts the averaging
Like all others, “bufOffs” is just a parameter that can have a single value. Here the “bufOffs” is given the value of “bufSize +1”. If bufSize (the slider in ZCM) is 3, bufOffs would now be 4.

The above lines were in the @slider section, so they are executed only when a slider is changed.

//"bufPos" is the input for samples to store. ie the left channel
“bufPos” is the second number in 0+[0]. So the memory slot being written to in “buffer[bufPos]” is “buffer” + “bufPos”.

//The second line here is where I get confused.
The second line actually combines two lines of code. I’m sure they make more sense when separated:
bufPos += 1;
bufPos > bufSize ? bufPos = 0 ;

But theres no reference to the slider value.
In ZCM “bufSize” is the slider value. The part that you didn’t include in your code was in the @slider section (simplified as):
pdc_delay = bufSize = slider3;
Which sets both of the parameters to the value of the slider3.
______Announcing__mrelwood plugins______
.. MacBook Pro 15" Late '13 .. Scarlett 6i6, Saffire Pro 24 DSP (+ADA8000) .. FCA610 .. EVE: SC207 .. Focal: Alpha 65, CMS 40, Listen Pro ..
mrelwood is offline   Reply With Quote