diff core/ReceiveAudioThread.cpp @ 120:cdd441a304a9 scope-refactoring

Added read to interleaved buffer
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 21 Aug 2015 15:52:37 +0100
parents c692827083e1
children bc514f29c3aa
line wrap: on
line diff
--- a/core/ReceiveAudioThread.cpp	Fri Aug 21 15:21:34 2015 +0100
+++ b/core/ReceiveAudioThread.cpp	Fri Aug 21 15:52:37 2015 +0100
@@ -132,6 +132,7 @@
 #endif
   bindToPort(aPort);
   channel=aChannel;
+  printf("Channel %d is receiving on port %d\n",aChannel, aPort);
   //  fd=fopen("output.m","w"); //DEBUG
   //  fprintf(fd,"var=["); //DEBUG
   headerLength=2;
@@ -147,7 +148,7 @@
   stackBuffer=(float*)malloc(sizeof(float)*headerLength);
   bytesToRead=sizeof(float)*(payloadLength + headerLength);
   writePointer=-1;
-  readPointer=0; //TODO: this *4 is sortof a security margin
+  readPointer=0;
   sleepTime=payloadLength/(float)44100 /4.0; //set sleepTime so that you do not check too often or too infrequently
 //JUCE    startThread(threadPriority);
 }
@@ -173,7 +174,10 @@
     }
     return buffer+(int)readPointer;
 };
-int ReceiveAudioThread::getSamplesSrc(float *destination, int length, float samplingRateRatio){//TODO: add interleaved version
+int ReceiveAudioThread::getSamplesSrc(float *destination, int length,
+		float samplingRateRatio, int numChannelsInDestination,
+		int channelToWriteTo)
+{
     if (!(samplingRateRatio>0 && samplingRateRatio<=2))
         return -2;
     if(isListening()==false)
@@ -194,7 +198,7 @@
             return 0;
     }
     for(int n=0; n<length; n++){
-        destination[n]=buffer[(int)(0.5+readPointer)];//simple ZOH non-interpolation (nearest neighbour)
+        destination[n*numChannelsInDestination+channelToWriteTo]=buffer[(int)(0.5+readPointer)];//simple ZOH non-interpolation (nearest neighbour)
         //  fprintf(fd,"%f, %d, %f;\n",readPointer,writePointer,destination[n]); //DEBUG
         readPointer+=samplingRateRatio;
         if((int)(0.5+readPointer)>=lastValidPointer){
@@ -203,7 +207,11 @@
     }
     return readPointer; 
 }
-
+int ReceiveAudioThread::getSamplesSrc(float *destination, int length, float samplingRateRatio){
+	return getSamplesSrc(destination, length, samplingRateRatio, 1,0);
+	// TODO: rewriting this so that it does not call the override method we can save a multiply and add
+	// for each sample.
+}
 bool ReceiveAudioThread::isBufferReady(){
     return bufferReady;
 }