summaryrefslogtreecommitdiff
path: root/FESgui/src/audiobuffer.h
diff options
context:
space:
mode:
authorTim Redfern <tim@getdrop.com>2023-04-17 19:44:00 +0100
committerTim Redfern <tim@getdrop.com>2023-04-17 19:44:00 +0100
commit19be92e0aff674b95bdae72fe7a2e409fd1bf77a (patch)
tree079acfc11ffbff8f11b120649f5cb3a623e354d6 /FESgui/src/audiobuffer.h
parent5309ef89393aa56083d1c2238c517c3d576907ec (diff)
add to archive
Diffstat (limited to 'FESgui/src/audiobuffer.h')
-rw-r--r--FESgui/src/audiobuffer.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/FESgui/src/audiobuffer.h b/FESgui/src/audiobuffer.h
new file mode 100644
index 0000000..a56dd4b
--- /dev/null
+++ b/FESgui/src/audiobuffer.h
@@ -0,0 +1,42 @@
+#pragma once
+
+
+#define min(a,b) (a<b?a:b)
+#define max(a,b) (a>b?a:b)
+
+class Buffer{
+public:
+ Buffer(size_t sz=0){
+ if (sz){
+ data =new float[sz];
+ memset(data,0,sz*sizeof(float));
+ size=sz;
+ }
+ else data=NULL;
+ }
+ ~Buffer(){
+ if (data){
+ delete[] data; //why is this throwing an error
+ }
+ }
+ void add(float * input, int num){
+ //this assumes that num < size
+ memcpy(&data[writePoint],input,min(num,size-writePoint)*sizeof(float));
+ if (size-writePoint<num){ //we have to wrap
+ //copy the remaining chunk to the start and set the new writePoint
+ memcpy(data,&input[size-writePoint],(num-(size-writePoint))*sizeof(float));
+ writePoint=num-(size-writePoint);
+ }
+ else writePoint+=num;
+ }
+ float operator [] (int i) const {
+ return data[(writePoint>i?writePoint-i:size-(i-writePoint))-1];
+ }
+ float& operator [] (int i) {
+ return data[(writePoint>i?writePoint-i:size-(i-writePoint))-1];
+ }
+private:
+ size_t size;
+ float *data;
+ int writePoint;
+}; \ No newline at end of file