An array 3 sized circle buffer
CircleBuffer.cpp
- Committer:
- oprospero
- Date:
- 2013-10-15
- Revision:
- 0:410ebbfd5e14
- Child:
- 1:8c7e5801d763
File content as of revision 0:410ebbfd5e14:
#include "CircleBuffer.h" CircleBuffer::CircleBuffer(void) { index = 0; for (int i = 0; i < 3; i++) { buffersum[i] = 0; for (int j = 0; j < BUFFERSIZE; j++) { buffer[j][i] = 0; } } } void CircleBuffer::queue(float value[3]) { for (int i = 0; i < 3 ; i++) { buffersum[i] -= buffer[index][i]; buffersum[i] += value[i]; buffer[index][i] = value[i]; } index++; if (index >= BUFFERSIZE) { index = 0; } } void CircleBuffer::read(float rawfilter[3]) { rawfilter[0] = buffersum[0] / BUFFERSIZE; rawfilter[1] = buffersum[1] / BUFFERSIZE; rawfilter[2] = buffersum[2] / BUFFERSIZE; }