Two simple ways to do this without slowing things down:
-
Keep a global running total, initialised to zero. Take a sample each main loop. Take the oldest sample in the array and subtract it from the running total and add in the new sample. Store the latest sample in the oldest sample's place. Update array pointer.
-
Keep a global running total, initialised to zero. Take a sample each main loop. Multiply the running total by 7/8ths and add 1/8th of the new sample to the running total.