From e5dd51fcddee9910d9310d453f3841dc80f34c0f Mon Sep 17 00:00:00 2001
From: Galen Lynch <glynch@mit.edu>
Date: Mon, 29 Aug 2016 01:38:11 -0400
Subject: [PATCH] Eliminate offset in audio out channels

The Intan recording module allows users to route two channels to the
audio jack on the acquisition board. Up to this point, selecting channel
1 in the params tab would output software channel 2. In addition,
channel 1 is inaccessible.

This stems from a mismatch between the one-based indexing used by Open
Ephys GUI and the zero-based indexing that the Intan ecosystem uses.
---
 Source/Processors/DataThreads/RhythmNode/RHD2000Editor.cpp | 3 ++-
 Source/Processors/DataThreads/RhythmNode/RHD2000Thread.cpp | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.cpp b/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.cpp
index 5aeb37d65..0220c2534 100644
--- a/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.cpp
+++ b/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.cpp
@@ -871,13 +871,14 @@ void RHD2000Editor::buttonEvent(Button* button)
 
 void RHD2000Editor::channelChanged (int channel, bool /*newState*/)
 {
+    // Audio output is tied to DAC channels 0 and 1
     for (int i = 0; i < 2; i++)
     {
         if (electrodeButtons[i]->getToggleState())
         {
             electrodeButtons[i]->setChannelNum (channel);
             electrodeButtons[i]->repaint();
-            board->setDACchannel (i, channel);
+            board->setDACchannel (i, channel - 1); // HW channels are zero-based
         }
     }
 }
diff --git a/Source/Processors/DataThreads/RhythmNode/RHD2000Thread.cpp b/Source/Processors/DataThreads/RhythmNode/RHD2000Thread.cpp
index 1376f93a9..63309e45d 100644
--- a/Source/Processors/DataThreads/RhythmNode/RHD2000Thread.cpp
+++ b/Source/Processors/DataThreads/RhythmNode/RHD2000Thread.cpp
@@ -216,7 +216,7 @@ void RHD2000Thread::setDACchannel(int dacOutput, int channel)
             {
                 dacChannels[dacOutput] = channel - channelCount;
                 dacStream[dacOutput] = i;
-				break;
+                break;
             }
             else
             {
@@ -1666,7 +1666,7 @@ bool RHD2000Thread::updateBuffer()
 
     }
 
-	
+
     if (dacOutputShouldChange)
     {
 		std::cout << "DAC" << std::endl;
-- 
GitLab