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

Error in example #40

Description

@pmpeter1

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;

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions