Mercurial > hg > beaglert
comparison core/NetworkSend.cpp @ 220:46bd63a50933 mergingClockSync
Fixed initialization of writePointer
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sat, 13 Feb 2016 16:55:39 +0000 |
parents | 0183185cab1b |
children | 6a23c07d0fbb |
comparison
equal
deleted
inserted
replaced
219:0183185cab1b | 220:46bd63a50933 |
---|---|
98 //because of limitations in BeagleRT_createAuxiliaryTask() | 98 //because of limitations in BeagleRT_createAuxiliaryTask() |
99 //keep track of added active instances | 99 //keep track of added active instances |
100 objAddrs.push_back(this);//TODO: this line should be in the constructor, but something weird happens if | 100 objAddrs.push_back(this);//TODO: this line should be in the constructor, but something weird happens if |
101 // an instance of NetworkSend is then declared globally: the constructor gets called, | 101 // an instance of NetworkSend is then declared globally: the constructor gets called, |
102 // and objAddrs.size()==1 but when you get to setup, objAddrs.size() has reverted back to 0, without | 102 // and objAddrs.size()==1 but when you get to setup, objAddrs.size() has reverted back to 0, without |
103 // any destructor being called in between ... | 103 // any destructor being called in between ... Have a look here |
104 // http://stackoverflow.com/questions/7542054/global-vector-emptying-itself-between-calls . | |
105 // and maybe use accessor function instead of global, as was done in #1374 | |
104 #endif /* USE_JUCE */ | 106 #endif /* USE_JUCE */ |
105 cleanup(); | 107 cleanup(); |
106 int numSamples=blockSize*4>4*channel.bufferLength ? blockSize*4 : 4*channel.bufferLength; | 108 int numSamples=blockSize*4>4*channel.bufferLength ? blockSize*4 : 4*channel.bufferLength; |
107 channel.numBuffers= 1+numSamples/channel.bufferLength; //the +1 takes the ceil() of the division | 109 channel.numBuffers= 1+numSamples/channel.bufferLength; //the +1 takes the ceil() of the division |
108 channel.buffers=(float**)malloc(channel.numBuffers*sizeof(float*)); | 110 channel.buffers=(float**)malloc(channel.numBuffers*sizeof(float*)); |
120 channel.readyToBeSent[n]=false; | 122 channel.readyToBeSent[n]=false; |
121 channel.doneOnTime[n]=true; | 123 channel.doneOnTime[n]=true; |
122 } | 124 } |
123 if(channel.readyToBeSent==NULL || channel.doneOnTime==NULL) | 125 if(channel.readyToBeSent==NULL || channel.doneOnTime==NULL) |
124 return; | 126 return; |
125 channel.writePointer=0; | 127 channel.writePointer=channel.headerLength; |
126 channel.writeBuffer=0; | 128 channel.writeBuffer=0; |
127 channel.readBuffer=0; | 129 channel.readBuffer=0; |
128 setChannelNumber(aChannelNumber); | 130 setChannelNumber(aChannelNumber); |
129 setPort(aPort); //TODO: check for the return value | 131 setPort(aPort); //TODO: check for the return value |
130 setServer(aServer); //TODO: check for the return value | 132 setServer(aServer); //TODO: check for the return value |
142 channel.writeBuffer=(channel.writeBuffer+1); //switch buffer | 144 channel.writeBuffer=(channel.writeBuffer+1); //switch buffer |
143 if(channel.writeBuffer==channel.numBuffers) // and wrap it | 145 if(channel.writeBuffer==channel.numBuffers) // and wrap it |
144 channel.writeBuffer=0; | 146 channel.writeBuffer=0; |
145 // printf("WriteBuffer:%d\n", channel.writeBuffer); | 147 // printf("WriteBuffer:%d\n", channel.writeBuffer); |
146 if(channel.doneOnTime[channel.writeBuffer]==false){ //check if this buffer's last sending has completed on time ... | 148 if(channel.doneOnTime[channel.writeBuffer]==false){ //check if this buffer's last sending has completed on time ... |
147 printf("Network buffer underrun. timestamp: %d :-{\n", | 149 printf("NetworkSend buffer underrun. timestamp: %d :-{\n", |
148 (int)channel.buffers[channel.writeBuffer][channel.headerTimestampIndex]); | 150 (int)channel.buffers[channel.writeBuffer][channel.headerTimestampIndex]); |
149 } | 151 } |
150 channel.doneOnTime[channel.writeBuffer]=false; // ... and then reset the flag | 152 channel.doneOnTime[channel.writeBuffer]=false; // ... and then reset the flag |
151 #ifdef USE_JUCE | 153 #ifdef USE_JUCE |
152 if(isThreadRunning()==false){ | 154 if(isThreadRunning()==false){ |
183 #endif /* USE_JUCE */ | 185 #endif /* USE_JUCE */ |
184 } | 186 } |
185 | 187 |
186 void NetworkSend::setChannelNumber(int aChannelNumber){ | 188 void NetworkSend::setChannelNumber(int aChannelNumber){ |
187 channel.channelNumber=aChannelNumber; | 189 channel.channelNumber=aChannelNumber; |
188 for(int n=0; n<channel.numBuffers; n++){ //initialize the header | 190 for(int n=0; n < channel.numBuffers; n++){ //initialize the header |
189 channel.buffers[n][channel.headerChannelIndex]=channel.channelNumber; | 191 channel.buffers[n][channel.headerChannelIndex]=channel.channelNumber; |
190 //add here more static header fields | 192 //add here more static header fields |
191 } | 193 } |
192 }; | 194 }; |
193 int NetworkSend::getChannelNumber(){ | 195 int NetworkSend::getChannelNumber(){ |
216 } else { | 218 } else { |
217 // printf ("Not ready timestamp: %d\n", (int)((float*)sourceBuffer)[1]); | 219 // printf ("Not ready timestamp: %d\n", (int)((float*)sourceBuffer)[1]); |
218 } | 220 } |
219 #else | 221 #else |
220 udpClient.send(sourceBuffer, numBytesToSend); | 222 udpClient.send(sourceBuffer, numBytesToSend); |
223 // printf("sent sourceBuffer: %d, channel: %f, timestamp: %f\n", channel.readBuffer, channel.buffers[channel.readBuffer][0], | |
224 // channel.buffers[channel.readBuffer][1]); | |
221 channel.doneOnTime[channel.readBuffer]=true; | 225 channel.doneOnTime[channel.readBuffer]=true; |
222 #endif /* USE_JUCE */ | 226 #endif /* USE_JUCE */ |
223 channel.readBuffer++; | 227 channel.readBuffer++; |
224 if(channel.readBuffer==channel.numBuffers) | 228 if(channel.readBuffer==channel.numBuffers) |
225 channel.readBuffer=0; | 229 channel.readBuffer=0; |