giuliomoro@217: #include "NetworkSend.h" giuliomoro@217: giuliomoro@217: #ifdef USE_JUCE giuliomoro@217: #else giuliomoro@217: //initialize the static members of NetworkSend giuliomoro@217: bool NetworkSend::staticConstructed=false; giuliomoro@217: int NetworkSend::sleepTimeMs; giuliomoro@217: bool NetworkSend::threadIsExiting; giuliomoro@217: bool NetworkSend::threadRunning; giuliomoro@217: std::vector NetworkSend::objAddrs(0); giuliomoro@217: AuxiliaryTask NetworkSend::sendDataTask=NULL; giuliomoro@217: giuliomoro@217: void sendData(){ giuliomoro@217: NetworkSend::run(); giuliomoro@217: } giuliomoro@217: void NetworkSend::staticConstructor(){ giuliomoro@217: if(staticConstructed==true) giuliomoro@217: return; giuliomoro@217: staticConstructed=true; giuliomoro@217: threadIsExiting=false; giuliomoro@217: threadRunning=false; giuliomoro@217: sendDataTask = BeagleRT_createAuxiliaryTask(::sendData, 95, "sendDataTask"); //TODO: allow variable priority giuliomoro@217: } giuliomoro@217: void NetworkSend::sendAllData(){ giuliomoro@217: for(unsigned int n=0; nsendData(); giuliomoro@217: } giuliomoro@217: } giuliomoro@217: int NetworkSend::getNumInstances(){ giuliomoro@217: return objAddrs.size(); giuliomoro@217: } giuliomoro@217: void NetworkSend::startThread(){ giuliomoro@217: BeagleRT_scheduleAuxiliaryTask(sendDataTask); giuliomoro@217: } giuliomoro@217: void NetworkSend::stopThread(){ giuliomoro@217: threadIsExiting=true; giuliomoro@217: } giuliomoro@217: bool NetworkSend::threadShouldExit(){ giuliomoro@217: return(gShouldStop || threadIsExiting); giuliomoro@217: } giuliomoro@217: bool NetworkSend::isThreadRunning(){ giuliomoro@217: return threadRunning; giuliomoro@217: } giuliomoro@217: #endif /* USE_JUCE */ giuliomoro@217: giuliomoro@217: #ifdef USE_JUCE giuliomoro@217: NetworkSend::NetworkSend(const String &threadName): giuliomoro@217: Thread(threadName) giuliomoro@217: #else giuliomoro@217: NetworkSend::NetworkSend() giuliomoro@217: #endif /* USE_JUCE */ giuliomoro@217: { giuliomoro@217: channel.buffers=NULL; giuliomoro@217: channel.doneOnTime=NULL; giuliomoro@217: channel.readyToBeSent=NULL; giuliomoro@217: channel.enabled=false; giuliomoro@217: sleepTimeMs=2; //This should actually be initialized in the staticConstructor for non-Juce code, but doing it here makes it more portable giuliomoro@217: channel.sampleCount=0; giuliomoro@217: } giuliomoro@217: giuliomoro@217: NetworkSend::~NetworkSend(){ giuliomoro@217: #ifdef USE_JUCE giuliomoro@217: stopThread(1000); giuliomoro@217: #else giuliomoro@217: stopThread(); giuliomoro@217: for(unsigned int n=0; n4*channel.bufferLength ? blockSize*4 : 4*channel.bufferLength; giuliomoro@217: channel.numBuffers= 1+numSamples/channel.bufferLength; //the +1 takes the ceil() of the division giuliomoro@217: channel.buffers=(float**)malloc(channel.numBuffers*sizeof(float*)); giuliomoro@217: printf("NumBuffers: %d\n", channel.numBuffers); giuliomoro@217: if(channel.buffers==NULL) giuliomoro@217: return; giuliomoro@217: for(int n=0; n( t3 - t1 ).count(); giuliomoro@217: // auto duration2 = std::chrono::duration_cast( t2 - t1 ).count(); giuliomoro@217: // if(duration2>0) giuliomoro@217: // std::cout << "Duration is: " << duration2 <<". Whole loop is: " << duration1 << "\n"; giuliomoro@219: usleep(1000); giuliomoro@217: } giuliomoro@217: #else giuliomoro@217: threadRunning=true; giuliomoro@217: while(threadShouldExit()==false){ giuliomoro@217: sendAllData(); giuliomoro@217: usleep(sleepTimeMs*1000); giuliomoro@217: } giuliomoro@217: threadRunning=false; giuliomoro@217: #endif giuliomoro@217: }