This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Description
byte getAverageSample(byte samples[], unsigned int num, unsigned int pos, unsigned int step)
{
unsigned int ret;
/* This is the number of samples that will be used to create each
* average sample; i.e. all the skipped samples before and after
* the current sample */
unsigned int size = step * 2;
/* Don't do any averaging, if we are at the beginning or end
* of the sample window */
if (pos < (step * 3) || pos > (num * 3) - (step * 3)) {
ret = samples[pos];
} else {
ret = 0;
pos -= (step * 3);
/* Calculate the sum of 'step' samples before, and after,
* the current sample */
for (unsigned int i = 0; i < size; ++i) {
ret += samples[pos - (3 * i)]; **// ERROR: I think this should be pos + (3*i) since you already decremented pos right before this.**
}
ret /= size;
}
return (byte)ret;
}