comparison core/ReceiveAudioThread.cpp @ 133:04b1678614c9 scope-refactoring

Using moving average for clock detection during synchronization seems to be working better but audio gets worse and worse
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 27 Aug 2015 03:33:32 +0100
parents e24c531220ee
children e77e2e712fbc
comparison
equal deleted inserted replaced
132:e24c531220ee 133:04b1678614c9
200 { 200 {
201 if (!(samplingRateRatio>0 && samplingRateRatio<=2)) 201 if (!(samplingRateRatio>0 && samplingRateRatio<=2))
202 return -2; 202 return -2;
203 if(isListening()==false) 203 if(isListening()==false)
204 return -1; 204 return -1;
205 if(writePointer<0){ //if writePointer has not been initalized yet ... 205 static int numCalls=0;
206 if(writePointer<0 || (numCalls&16383)==0){ //if writePointer has not been initalized yet ...
207 #ifdef USE_JUCE
208 #else //debug
209 rt_printf("reinit the writePointer, readPointer: %f;\n",readPointer);
210 readPointer=0;
211 #endif /* USE_JUCE */
206 writePointer=2*length; // do it, so that it starts writing at a safety margin from where we write. 212 writePointer=2*length; // do it, so that it starts writing at a safety margin from where we write.
207 // This will help keeping them in sync. 213 // This will help keeping them in sync.
208 //TODO: handle what happens when the remote stream is interrupted and then restarted 214 //TODO: handle what happens when the remote stream is interrupted and then restarted
209 } 215 }
216 numCalls++;
210 if(length>lastValidPointer) { 217 if(length>lastValidPointer) {
211 //not enough samples available, we fill the buffer with what is available, but the destination buffer will not be filled completely 218 //not enough samples available, we fill the buffer with what is available, but the destination buffer will not be filled completely
212 //at this very moment the other thread might be writing at most one payload into the buffer. 219 //at this very moment the other thread might be writing at most one payload into the buffer.
213 //To avoid a race condition, we need to let alone the buffer where we are currently writing 220 //To avoid a race condition, we need to let alone the buffer where we are currently writing
214 //as writing the payload also temporarily overwrites the previous headerLength samples, we need to account for them as well 221 //as writing the payload also temporarily overwrites the previous headerLength samples, we need to account for them as well