changeset 485:506a319c08cf prerelease

Scope can now take a float* to an array instead of individual variables
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 21 Jun 2016 15:17:38 +0100
parents afbc8f973bb3
children 7f8d1a3e4cef
files core/Scope.cpp include/Scope.h
diffstat 2 files changed, 63 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/core/Scope.cpp	Tue Jun 21 15:16:55 2016 +0100
+++ b/core/Scope.cpp	Tue Jun 21 15:17:38 2016 +0100
@@ -80,6 +80,47 @@
     started = false;
 }
 
+void Scope::log(float* values){
+	//TODO: contains lots of duplicated code from log(float,...).
+	//TODO: needs refactoring
+    // check for any received OSC messages
+    while (oscServer.messageWaiting()){
+        parseMessage(oscServer.popMessage());
+    }
+
+    if (!started) return;
+
+    if (downSampling > 1){
+        if (downSampleCount < downSampling){
+            downSampleCount++;
+            return;
+        }
+        downSampleCount = 1;
+    }
+
+    int startingWritePointer = writePointer;
+
+    // save the logged samples into the buffer
+    for (int i=0; i<numChannels; i++) {
+        buffer[i*channelWidth + writePointer] = values[i];
+    }
+
+    writePointer = (writePointer+1)%channelWidth;
+
+    // if upSampling > 1, save repeated samples into the buffer
+    for (int j=1; j<upSampling; j++){
+
+        buffer[writePointer] = buffer[startingWritePointer];
+
+        for (int i=1; i<numChannels; i++) {
+            buffer[i*channelWidth + writePointer] = buffer[i*channelWidth + startingWritePointer];
+        }
+
+        writePointer = (writePointer+1)%channelWidth;
+
+    }
+
+}
 void Scope::log(float chn1, ...){
 
     // check for any received OSC messages
--- a/include/Scope.h	Tue Jun 21 15:16:55 2016 +0100
+++ b/include/Scope.h	Tue Jun 21 15:17:38 2016 +0100
@@ -16,8 +16,29 @@
     public:
         Scope();
         
+        /**
+         * Setup the Scope.
+         *
+         * @param numChannels number of channels in the scope.
+         * @param sampleRate sampleRate of the data passed in.
+         */
         void setup(unsigned int numChannels, float sampleRate);
+
+        /**
+         * Logs a frame of data to the scope.
+         *
+         * Pass one argument per channel (starting from the first), up to the
+         * number of channels of the object.
+         * Omitted values will be set to 0.
+         */
         void log(float chn1, ...);
+
+        /**
+         * Logs a frame of data to the scope.
+         *
+         * @param values a pointer to an array containing numChannels values.
+         */
+        void log(float* values);
         bool trigger();
         
     private:
@@ -83,4 +104,4 @@
         
 };
 
-#endif
\ No newline at end of file
+#endif