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