An array 3 sized circle buffer

Revision:
0:410ebbfd5e14
Child:
1:8c7e5801d763
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CircleBuffer.cpp	Tue Oct 15 16:32:18 2013 +0000
@@ -0,0 +1,38 @@
+#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;
+}
\ No newline at end of file