@d-healey this seems wrong, the second parameter numSamples
should be your stepSize
(protected), not the position j
Also you need to protect it when reaching the end as Chris mentioned
for (j = stepSize; j < buf[i].length; j += stepSize)
{
local position = j - stepSize;
local numSamples = Math.min(buf[i].length - position, stepSize); // protect
buf[i].getMagnitude(position, numSamples);
}
And why not starting the loop at 0 to save some calculations
for (j = 0; j < buf[i].length; j += stepSize)
{
local numSamples = Math.min(buf[i].length - j, stepSize); // protect
buf[i].getMagnitude(j, numSamples);
}