From f2904ed73fc869fe773255c27f553807ac8cf9f2 Mon Sep 17 00:00:00 2001
From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es>
Date: Wed, 4 May 2016 18:15:01 +0200
Subject: [PATCH] Fix aux channels for input block < 4channels

---
 Source/Plugins/PCIeRhythm/RHD2000Thread.cpp | 4 +++-
 Source/Plugins/PCIeRhythm/RHD2000Thread.h   | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/Source/Plugins/PCIeRhythm/RHD2000Thread.cpp b/Source/Plugins/PCIeRhythm/RHD2000Thread.cpp
index d4ec664c9..bca61cce7 100644
--- a/Source/Plugins/PCIeRhythm/RHD2000Thread.cpp
+++ b/Source/Plugins/PCIeRhythm/RHD2000Thread.cpp
@@ -1307,6 +1307,7 @@ bool RHD2000Thread::startAcquisition()
 
     std::cout << "Expecting " << getNumChannels() << " channels." << std::endl;
 	lastThreshold = false;
+	auxSamp = 0;
     //memset(filter_states,0,256*sizeof(double));
 
     /*int ledArray[8] = {1, 1, 0, 0, 0, 0, 0, 0};
@@ -1465,7 +1466,8 @@ bool RHD2000Thread::updateBuffer()
 			{
 				if (chipId[dataStream] != CHIP_ID_RHD2164_B)
 				{
-					int auxNum = (samp+3) % 4;
+					int auxNum = (auxSamp+3) % 4;
+					auxSamp = (++auxSamp) % 4;
 					if (auxNum < 3)
 					{
 						auxSamples[dataStream][auxNum] = float(*(uint16*)(bufferPtr + auxIndex) - 32768)*0.0000374;
diff --git a/Source/Plugins/PCIeRhythm/RHD2000Thread.h b/Source/Plugins/PCIeRhythm/RHD2000Thread.h
index 18d4bc998..582dc9b73 100644
--- a/Source/Plugins/PCIeRhythm/RHD2000Thread.h
+++ b/Source/Plugins/PCIeRhythm/RHD2000Thread.h
@@ -211,6 +211,8 @@ namespace PCIeRhythm {
 
 		void checkThreshold(float s);
 
+		int auxSamp;
+
 		// Sync ouput divide factor
 		uint16 clockDivideFactor;
 
-- 
GitLab