subSample in AudioLiveScrollingDisplay.h


#1

From this code in JuceDemo


void pushSample (const float newSample)

    {

        accumulator += newSample;

        if (subSample == 0)

        {

            const int inputSamplesPerPixel = 200;

            samples[nextSample] = accumulator / inputSamplesPerPixel;

            nextSample = (nextSample + 1) % numElementsInArray (samples);

            subSample = inputSamplesPerPixel;

            accumulator = 0;

        }

        else

        {

            --subSample;

        }
}

and i have no idea that What is the functionality of the parameter named subSample ?


#2

I think, roughly:

  • For each new sample, add it to an accumulator. 
  • If we've had inputSamplesPerPixel samples, then store the total accumulated sample into the samples[] array. 
  • Identify the next slot for the next input sample to be stored in.
  • Zero accumulator.

subSample is just a counter.  It counts the number of samples until inputSamplesPerPixel has been reached.

I'm not sure why this makes sense as a way of displaying a waveform mind you.  If you had a high-pitched sine wave the average sample might be zero ... maybe I'm missing something by not looking at all the code. 

 


#3

Ah - I ran the demo - it's probably ok because the buffer isn't that big :)