From 161dcdb204d2d10dd407dcb29bfe47838e9d36f1 Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Mon, 5 Nov 2012 22:08:33 -0500
Subject: [PATCH] Minor updates to RecordNode

---
 Source/Processors/RecordNode.cpp | 22 ++++++++++++-------
 Source/Processors/RecordNode.h   | 36 ++++++++++++++++++++++++++++++--
 2 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/Source/Processors/RecordNode.cpp b/Source/Processors/RecordNode.cpp
index 7321b55b1..419ba22ea 100755
--- a/Source/Processors/RecordNode.cpp
+++ b/Source/Processors/RecordNode.cpp
@@ -30,7 +30,8 @@ RecordNode::RecordNode()
 
 	
 //	newDataFolder = true; // defaults to creating a new data folder on startup
-	continuousDataBuffer = new int16[10000];
+	continuousDataIntegerBuffer = new int16[10000];
+	continuousDataFloatBuffer = new float[10000];
 	signalFilesShouldClose = false;
 
 }
@@ -142,10 +143,8 @@ void RecordNode::addInputChannel(GenericProcessor* sourceNode, int chan)
 		continuousChannels.insert(newPair);
 
 		
-
 	} else {
 
-
 		std::map<int, Channel> eventChans;
 
 		int ID = sourceNode->getNodeId();
@@ -317,9 +316,15 @@ float RecordNode::getFreeSpace()
 void RecordNode::writeContinuousBuffer(float* data, int nSamples, int channel)
 {
 
+	// scale the data appropriately
+	for (int n = 0; n < nSamples; n++)
+	{
+		*(continuousDataFloatBuffer+n) = *(data+n) / 10000.0f; 
+	}
+
 	// find file and write samples to disk
 
-	AudioDataConverters::convertFloatToInt16BE(data, continuousDataBuffer, nSamples);
+	AudioDataConverters::convertFloatToInt16BE(continuousDataFloatBuffer, continuousDataIntegerBuffer, nSamples);
 
 	//int16 samps = nSamples;
 
@@ -333,7 +338,7 @@ void RecordNode::writeContinuousBuffer(float* data, int nSamples, int channel)
 			   1, 		  						// count 
 			   continuousChannels[channel].file);   // ptr to FILE object
 
-	int n = fwrite(continuousDataBuffer,			// ptr
+	int n = fwrite(continuousDataIntegerBuffer,		// ptr
 			   2,			     					// size of each element
 			   nSamples, 		  					// count 
 			   continuousChannels[channel].file);   // ptr to FILE object
@@ -354,10 +359,11 @@ void RecordNode::process(AudioSampleBuffer &buffer,
 	//std::cout << "Record node processing block." << std::endl;
 	//std::cout << "Num channels: " << buffer.getNumChannels() << std::endl;
 
-	timestamp = timer.getHighResolutionTicks();
 
 	if (isRecording) {
 
+		timestamp = timer.getHighResolutionTicks();
+
 		// WHY IS THIS AFFECTING THE LFP DISPLAY?
 		//buffer.applyGain(0, nSamples, 5.2438f);
 
@@ -385,10 +391,10 @@ void RecordNode::process(AudioSampleBuffer &buffer,
 
 	}
 
+	// this is intended to prevent parameter changes from closing files
+	// before recording stops
 	if (signalFilesShouldClose)
 	{
-		// prevent parameter changes from closing files
-		// before recording stops
 		closeAllFiles();
 		signalFilesShouldClose = false;
 	}
diff --git a/Source/Processors/RecordNode.h b/Source/Processors/RecordNode.h
index 3d4eda2b1..d6af23e3d 100755
--- a/Source/Processors/RecordNode.h
+++ b/Source/Processors/RecordNode.h
@@ -52,9 +52,20 @@ public:
 	
 	RecordNode();
 	~RecordNode();
-	
+
+  /** Handle incoming data and decide which files and events to write to disk.
+  */	
 	void process(AudioSampleBuffer &buffer, MidiBuffer &eventBuffer, int& nSamples);
 
+  /** Overrides implementation in GenericProcessor; used to change recording parameters
+      on the fly.
+
+      parameterIndex = 0: stop recording
+      parameterIndex = 1: start recording
+      parameterIndex = 2: 
+            newValue = 0: turn off recording for current channel
+            newValue = 1: turn on recording for current channel
+  */
 	void setParameter (int parameterIndex, float newValue);
 
   void addInputChannel(GenericProcessor* sourceNode, int chan);
@@ -67,16 +78,30 @@ public:
   */
 	float getFreeSpace();
 
+  /** Selects a channel relative to a particular processor with ID = id
+  */
   void setChannel(int id, int chan);
 
+  /** Turns recording on and off for a particular channel.
+
+      Channel numbers are absolute (based on RecordNode channel mapping).
+  */
   void setChannelStatus(int chan, bool status);
 
+  /** Used to clear all connections prior to the start of acquisition.
+  */
   void resetConnections();
 
+  /** Overrides implementation by GenericProcessor.
+  */
   bool isAudioOrRecordNode() {return true;}
 
+  /** Callback to indicate when user has chosen a new data directory.
+  */
   void filenameComponentChanged(FilenameComponent*);
 
+  /** Creates a new data directory in the location specified by the fileNameComponent.
+  */
   void createNewDirectory();
 	
 private:
@@ -102,7 +127,12 @@ private:
   /** Holds data that has been converted from float to int16 before
       saving. 
   */
-  int16* continuousDataBuffer;
+  int16* continuousDataIntegerBuffer;
+
+  /** Holds data that has been converted from float to int16 before
+      saving. 
+  */
+  float* continuousDataFloatBuffer;
 
   /** Integer timestamp saved for each buffer. 
   */ 
@@ -125,6 +155,8 @@ private:
     FILE* file;
   };
 
+  /** Closes all open files after recording has finished.
+  */ 
   void closeAllFiles();
 
   /** Map of continuous channels. 
-- 
GitLab