From 4e4884d602887c5d8f886bf51188c645a8e7d310 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 15 Nov 2022 23:44:36 +0000 Subject: offset read by 1 --- audioin/src/ofApp.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 'audioin') diff --git a/audioin/src/ofApp.h b/audioin/src/ofApp.h index d62dfa0..3ac6b39 100644 --- a/audioin/src/ofApp.h +++ b/audioin/src/ofApp.h @@ -23,16 +23,62 @@ public: //delete[] data; //why is this throwing an error } } +/* +if the size is 1000 and the num is 600 +1st frame: writePoint=0 +memcpy(&data[0],input,min(600,1000-0)) +-> we copied the whole 600 starting at 0 and ending at 599 +2nd frame: writePoint=600 +memcpy(&data[600],input, min(600,1000-600)) +-> we copied 400 starting at 600 and ending at 999 +yes (1000-600<600) + so + memcpy(data,&input[1000-600],600-(1000-600)) + -> we copied 200 starting at input:400 and ending at 599 to the start of data + writePoint=600-(1000-600) +3rd frame: writePoint=200 +memcpy(&data[200],input, min(600,1000-200)) +-> we copied the whole 600 starting at 200 and ending at 799 +4th frame: writePoint=800 +memcpy(&data[800],input, min(600,1000-800)) +-> we copied 200 starting at 800 and ending at 999 +yes (1000-800<600) + so + memcpy(data,&input[1000-800],600-(1000-800)) + -> we copied 400 starting at input:200 and ending at 599 to the start of data + writePoint=600-(1000-800) +5th frame: writePoint=400 +memcpy(&data[400],input, min(600,1000-400)) +-> we copied the whole 600 starting at 400 and ending at 999 + +back to square one. 5*600=3000 +*/ void add(float * input, int num){ memcpy(&data[writePoint],input,min(num,size-writePoint)*sizeof(float)); - if (size-writePointi?writePoint-i:size-(i-writePoint)];} - float& operator [] (int i) {return data[writePoint>i?writePoint-i:size-(i-writePoint)];} +/* +if size is 1000 and writePoint is 1000 +0: return data[1000] +writePoint can never be 1000? + +if size is 1000 and writePoint is 800 +0: return data[800] +1: return data[799] +799: return data[1] --> this should be data[0] !? +800: return data[1000-(800-800)->1000] -> this should be data[999] +*/ + 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; -- cgit v1.2.3