# HG changeset patch # User Giulio Moro # Date 1455412163 0 # Node ID 6a23c07d0fbb94512bd216b0926ac03031c28c5c # Parent dbff109f64c2c9f5eee4952b011bc132c5ff5757 Working with UdpIoPlugin diff -r dbff109f64c2 -r 6a23c07d0fbb .cproject --- a/.cproject Sat Feb 13 16:56:29 2016 +0000 +++ b/.cproject Sun Feb 14 01:09:23 2016 +0000 @@ -123,7 +123,7 @@ - + @@ -240,7 +240,7 @@ - + diff -r dbff109f64c2 -r 6a23c07d0fbb core/NetworkSend.cpp --- a/core/NetworkSend.cpp Sat Feb 13 16:56:29 2016 +0000 +++ b/core/NetworkSend.cpp Sun Feb 14 01:09:23 2016 +0000 @@ -106,7 +106,7 @@ #endif /* USE_JUCE */ cleanup(); int numSamples=blockSize*4>4*channel.bufferLength ? blockSize*4 : 4*channel.bufferLength; - channel.numBuffers= 1+numSamples/channel.bufferLength; //the +1 takes the ceil() of the division + channel.numBuffers= (1+numSamples/channel.bufferLength) * 3; //the +1 takes the ceil() of the division channel.buffers=(float**)malloc(channel.numBuffers*sizeof(float*)); printf("NumBuffers: %d\n", channel.numBuffers); if(channel.buffers==NULL) @@ -143,7 +143,7 @@ channel.writePointer=channel.headerLength; //reset the writePointer channel.writeBuffer=(channel.writeBuffer+1); //switch buffer if(channel.writeBuffer==channel.numBuffers) // and wrap it - channel.writeBuffer=0; + channel.writeBuffer=0; // printf("WriteBuffer:%d\n", channel.writeBuffer); if(channel.doneOnTime[channel.writeBuffer]==false){ //check if this buffer's last sending has completed on time ... printf("NetworkSend buffer underrun. timestamp: %d :-{\n", diff -r dbff109f64c2 -r 6a23c07d0fbb core/ReceiveAudioThread.cpp --- a/core/ReceiveAudioThread.cpp Sat Feb 13 16:56:29 2016 +0000 +++ b/core/ReceiveAudioThread.cpp Sun Feb 14 01:09:23 2016 +0000 @@ -39,7 +39,7 @@ // for(int n=headerLength;n>5, the + // destructor (always or sometimes) never actually gets called, despite run() returns ...see issue #1381 #ifdef USE_JUCE #else lastTime=rt_timer_read(); // rt_printf("lastTimeread= %llu\n", lastTime); #endif /* USE_JUCE */ - // destructor (always or sometimes) never actually gets called, despite run() returns ...see issue #1381 pushPayload(writePointer); //backup headerLength samples. This could be skipped if writePointer==0 //read header+payload int numBytes=socket.read(buffer+writePointer, bytesToRead, true); //read without waiting. @@ -150,7 +151,7 @@ // fprintf(fd,"var=["); //DEBUG headerLength=2; payloadLength=300; //TODO: make sure that payloadLength and headerLength are the same as the client is sending. - bufferLength=std::max(headerLength+(payloadLength*4), headerLength+(aSamplesPerBlock*4)); //there are many considerations that can be done here ... + bufferLength=10 * std::max(headerLength+(payloadLength*4), headerLength+(aSamplesPerBlock*4)); //there are many considerations that can be done here ... //We keep a headerLength padding at the beginning of the array to allow full reads from the socket buffer=(float*)malloc(sizeof(float)*bufferLength); if(buffer==NULL) // something wrong @@ -206,12 +207,15 @@ if(writePointer<0 /*|| (numCalls&16383)==0*/){ //if writePointer has not been initalized yet ... #ifdef USE_JUCE #else //debug - rt_printf("reinit the writePointer, readPointer: %f;\n",readPointer); - readPointer=0; + readPointer = headerLength; #endif /* USE_JUCE */ - writePointer=2*length; // do it, so that it starts writing at a safety margin from where we write. + // this cumbersome line means: start writing at a position which is as close as possible + // to the center of the buffer, but still is aligned to (payloadLength*x)+headerLength + // thus allowing buffering to allow clock drift to go either way + writePointer = headerLength + ((bufferLength-headerLength)/payloadLength/2)*payloadLength; // This will help keeping them in sync. //TODO: handle what happens when the remote stream is interrupted and then restarted + printf("write pointer inited at: %d\n", writePointer); } numCalls++; if(length>lastValidPointer) { @@ -295,7 +299,6 @@ sleep(sleepTime); #else for(unsigned int n=0; nreadUdpToBuffer(); } usleep(sleepTime); //TODO: use rt_task_sleep instead diff -r dbff109f64c2 -r 6a23c07d0fbb projects/basic_network/render.cpp --- a/projects/basic_network/render.cpp Sat Feb 13 16:56:29 2016 +0000 +++ b/projects/basic_network/render.cpp Sun Feb 14 01:09:23 2016 +0000 @@ -9,6 +9,7 @@ //#include #include #include +#include #include // setup() is called once before the audio rendering starts. @@ -21,6 +22,7 @@ // Return true on success; returning false halts the program. NetworkSend networkSend; +ReceiveAudioThread receive; float gFrequency; float gInverseSampleRate; float gPhase; @@ -29,9 +31,11 @@ // Retrieve a parameter passed in from the initAudio() call gFrequency = *(float *)userData; - networkSend.setup(context->audioSampleRate, context->audioFrames, 3, 9999, "192.168.7.1"); + networkSend.setup(context->audioSampleRate, context->audioFrames, 0, 9999, "192.168.7.1"); + receive.init(10000, context->audioFrames, 0); + receive.startThread(); gInverseSampleRate = 1.0 / context->audioSampleRate; - gPhase = 0.2132; + gPhase = 0; return true; } @@ -48,10 +52,12 @@ if(gPhase > 2.0 * M_PI) gPhase -= 2.0 * M_PI; + networkSend.log(out); + float in; + int ret = receive.getSamplesSrc(&in, 1, 1); for(unsigned int channel = 0; channel < context->audioChannels; channel++){ - context->audioOut[n * context->audioChannels + channel] = out; + audioWriteFrame(context, n, channel, in); } - networkSend.log(out); } }