changeset 8:4c738d26de4f

added channel macro in ContextJack
author Fiore Martin <f.martin@qmul.ac.uk>
date Tue, 19 Jul 2016 10:27:59 +0200
parents a4a336624f5a
children 20bb004a36de
files JackDevice/ContextJack.cpp
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/JackDevice/ContextJack.cpp	Fri Jul 15 16:05:34 2016 +0200
+++ b/JackDevice/ContextJack.cpp	Tue Jul 19 10:27:59 2016 +0200
@@ -47,6 +47,8 @@
 #include "cinder/audio/linux/ContextJack.h"
 #include "cinder/audio/Exception.h"
 
+#define NUM_CHANNELS 2
+
 namespace cinder { namespace audio { namespace linux {
 
 
@@ -90,7 +92,7 @@
     auto ctx = renderData->outputNode->getContext();
     if( ! ctx ) {
         // this is from some cinder library code but it should not happen in Collidoscope as the context is set
-        for( size_t chan = 0; chan < 2; chan++)
+        for( size_t chan = 0; chan < NUM_CHANNELS; chan++)
             zeroJackPort( outputDeviceNode->mOutputPorts[chan], nframes );
 
         return 0;
@@ -102,7 +104,7 @@
     ctx = renderData->outputNode->getContext();
     if( ! ctx ) {
 
-        for( size_t chan = 0; chan < 2; chan++)
+        for( size_t chan = 0; chan < NUM_CHANNELS; chan++)
             zeroJackPort( outputDeviceNode->mOutputPorts[chan], nframes );
 
         return 0;
@@ -118,11 +120,11 @@
     
     // if clip detection is enabled and buffer clipped, silence it
     //if( outputDeviceNode->checkNotClipping() ){
-        //for( size_t chan = 0; chan < 2; chan++)
+        //for( size_t chan = 0; chan < NUM_CHANNELS; chan++)
         //    zeroJackPort( outputDeviceNode->mOutputPorts[chan], nframes );
     //} 
     //else {
-        for( size_t chan = 0; chan < 2; chan++)
+        for( size_t chan = 0; chan < NUM_CHANNELS; chan++)
             copyToJackPort( outputDeviceNode->mOutputPorts[chan], internalBuffer->getChannel( chan ), nframes  );
     //}
 
@@ -281,7 +283,7 @@
 // Takes audio interface input from the jack port and copies it in the node buffer
 void InputDeviceNodeJack::process( Buffer *buffer )
 {
-    for( size_t chan = 0; chan < 2; chan++){
+    for( size_t chan = 0; chan < NUM_CHANNELS; chan++){
        copyFromJackPort(mInputPorts[chan], buffer->getChannel( chan ), buffer->getNumFrames() ); 
     }
 }
@@ -295,7 +297,7 @@
     if( mOutputDeviceNode  == nullptr ) {
         auto thisRef = std::static_pointer_cast<ContextJack>( shared_from_this() );
 
-        mOutputDeviceNode = makeNode( new OutputDeviceNodeJack( device, Node::Format().channels(2), thisRef ) ) ;
+        mOutputDeviceNode = makeNode( new OutputDeviceNodeJack( device, Node::Format().channels(NUM_CHANNELS), thisRef ) ) ;
 
         // the output device node must have a reference to input device node. In OutputDeviceNodeJack::initialize() 
         // the input node is passed the jack input ports that it will use to fetch incoming audio from the audio interface
@@ -314,7 +316,7 @@
     if( mInputDeviceNode  == nullptr ) {
         auto thisRef = std::static_pointer_cast<ContextJack>( shared_from_this() );
 
-        mInputDeviceNode = makeNode( new InputDeviceNodeJack( device, Node::Format().channels(2), thisRef ) ) ;
+        mInputDeviceNode = makeNode( new InputDeviceNodeJack( device, Node::Format().channels( NUM_CHANNELS ), thisRef ) ) ;
 
         // the output device node must have a reference to input device node. In OutputDeviceNodeJack::initialize() 
         // the input node is passed the jack input ports that it will use to fetch incoming audio from the audio interface