diff core/ReceiveAudioThread.cpp @ 128:2696a7f00053 scope-refactoring

ReceiveAudioThread is now the same with/without JUCE
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 24 Aug 2015 18:55:19 +0100
parents 6c8fb6f07b47
children ff28e56e5b7e
line wrap: on
line diff
--- a/core/ReceiveAudioThread.cpp	Mon Aug 24 15:36:09 2015 +0100
+++ b/core/ReceiveAudioThread.cpp	Mon Aug 24 18:55:19 2015 +0100
@@ -1,6 +1,6 @@
 #include "ReceiveAudioThread.h"
 
-#ifdef JUCE
+#ifdef USE_JUCE
 #else
 //initialise static members
 bool ReceiveAudioThread::staticConstructed=false;
@@ -20,7 +20,7 @@
     threadIsExiting=false;
 	receiveDataTask=BeagleRT_createAuxiliaryTask(receiveData, 90, "receiveDataTask"); //TODO: allow different priorities
 }
-#endif /* JUCE */
+#endif /* USE_JUCE */
 
 void ReceiveAudioThread::dealloc(){
     free(buffer);
@@ -100,13 +100,13 @@
     }
     return 0; //timeout occurred
 }
-//JUCE    Thread(threadName),
-#ifdef JUCE
+//USE_JUCE    Thread(threadName),
+#ifdef USE_JUCE
 ReceiveAudioThread::ReceiveAudioThread(const String &threadName) :
 			Thread(threadName),
 #else
 ReceiveAudioThread::ReceiveAudioThread() :
-#endif /* JUCE */
+#endif /* USE_JUCE */
 	socket(0),
     listening(false),
     bufferReady(false),
@@ -115,31 +115,31 @@
     bufferLength(0),
     lastValidPointer(0),
     waitForSocketTime(5),
-#ifdef JUCE
+#ifdef USE_JUCE
     threadPriority(5)
 #else
     threadPriority(88)
-#endif /* JUCE */
+#endif /* USE_JUCE */
 {};
 ReceiveAudioThread::~ReceiveAudioThread(){
-#ifdef JUCE
+#ifdef USE_JUCE
 	stopThread(1000);
 #else
 	while(threadRunning){
 		usleep(sleepTime*2);	//wait for thread to stop
 		std::cout<< "Waiting for receiveAudioTask to stop" << std::endl;
 	}
-#endif /* JUCE */
+#endif /* USE_JUCE */
 	//TODO: check if thread stopped, otherwise kill it before dealloc
     dealloc();
 }
 void ReceiveAudioThread::init(int aPort, int aSamplesPerBlock, int aChannel){
   dealloc();
-#ifdef JUCE
+#ifdef USE_JUCE
 #else
   staticConstructor();
   objAddrs.push_back(this);//TODO: this line should be in the constructor
-#endif /* JUCE */
+#endif /* USE_JUCE */
   bindToPort(aPort);
   channel=aChannel;
   printf("Channel %d is receiving on port %d\n",aChannel, aPort);
@@ -162,20 +162,20 @@
   writePointer=-1;
   readPointer=0;
   sleepTime=payloadLength/(float)44100 /4.0; //set sleepTime so that you do not check too often or too infrequently
-#ifdef JUCE
+#ifdef USE_JUCE
   startThread(threadPriority);
 #else
   //TODO: the thread cannot be started here at the moment because init() is called in setup(), where tasks cannot be scheduled
-#endif /* JUCE */
+#endif /* USE_JUCE */
 }
 
 void ReceiveAudioThread::bindToPort(int aPort){
     listening=socket.bindToPort(aPort);
-#ifdef JUCE
+#ifdef USE_JUCE
 #else
-    if(listening==false) //this condition is valid also for JUCE, but we do not printf in JUCE
+    if(listening==false) //this condition is valid also for USE_JUCE, but we do not printf in USE_JUCE
     	printf("Could not bind to port %d\n",aPort);
-#endif /* JUCE */
+#endif /* USE_JUCE */
 }
 bool ReceiveAudioThread::isListening(){
     return listening;
@@ -231,12 +231,10 @@
 bool ReceiveAudioThread::isBufferReady(){
     return bufferReady;
 }
-#ifdef JUCE
+#ifdef USE_JUCE
 #else
 void ReceiveAudioThread::startThread(){
-	printf("receivedata is going to be  scheduled\n");
 	BeagleRT_scheduleAuxiliaryTask(receiveDataTask);
-	printf("receivedata has been scheduled\n");
 }
 void ReceiveAudioThread::stopThread(){
 	threadIsExiting=true;
@@ -244,22 +242,22 @@
 bool ReceiveAudioThread::threadShouldExit(){
 	return(gShouldStop || threadIsExiting );
 }
-#endif /* JUCE */
+#endif /* USE_JUCE */
 void ReceiveAudioThread::run(){
     //  fd2=fopen("buffer.m","w"); //DEBUG
     //  fprintf(fd2, "buf=["); //DEBUG
 	threadRunning=true;
     while(!threadShouldExit()){ //TODO: check that the socket buffer is empty before starting
-#ifdef JUCE
+#ifdef USE_JUCE
         readUdpToBuffer(); // read into the oldBuffer
-        usleep(sleepTime);
+        sleep(sleepTime);
 #else
 		for(unsigned int n=0; n<ReceiveAudioThread::objAddrs.size(); n++){
 //			printf("%d\n", n);
 			ReceiveAudioThread::objAddrs[n]->readUdpToBuffer();
 		}
 		usleep(sleepTime); //TODO: use rt_task_sleep instead
-#endif /* JUCE */
+#endif /* USE_JUCE */
     }
     threadRunning=false;
     printf("Thread is not running \n");