Mercurial > hg > beaglert
diff projects/scope/render.cpp @ 119:c692827083e1 scope-refactoring
Enabled multi channel audio receive
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 21 Aug 2015 15:21:34 +0100 |
parents | 26ad97b8aa9e |
children | cdd441a304a9 |
line wrap: on
line diff
--- a/projects/scope/render.cpp Fri Aug 21 14:37:19 2015 +0100 +++ b/projects/scope/render.cpp Fri Aug 21 15:21:34 2015 +0100 @@ -7,7 +7,7 @@ float gFrequency1, gFrequency2; float gInverseSampleRate; -Scope scope(6); //create a scope object with 6 channels +Scope scope(2); //create a scope object with 2 channels NetworkSend networkSend; // initialise_render() is called once before the audio rendering starts. @@ -18,12 +18,16 @@ // in from the call to initAudio(). // // Return true on success; returning false halts the program. -ReceiveAudioThread receiveAudio; +ReceiveAudioThread receiveAudio0; +ReceiveAudioThread receiveAudio1; bool setup(BeagleRTContext *context, void *userData) { - receiveAudio.bindToPort(9999); - receiveAudio.init(context->audioFrames); + receiveAudio0.init(9999, context->audioFrames, 0); + receiveAudio1.init(10000, context->audioFrames, 1); + scope.setup(); //call this once in setup to initialise the scope + scope.setPort(0, 9999); + scope.setPort(1, 10000); // networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1"); gInverseSampleRate = 1.0/context->audioSampleRate; @@ -46,12 +50,12 @@ { static int count=0; if(count==0) - receiveAudio.startThread(); + ReceiveAudioThread::startThread(); for(unsigned int n = 0; n < context->audioFrames; n++) { float chn0 = sinf(gPhase1); - // float chn1 = sinf(gPhase2); + float chn1 = sinf(gPhase2); // float chn2 = context->audioIn[n*2 + 0]; // float chn3 = context->audioIn[n*2 + 1]; @@ -59,7 +63,7 @@ // float chn4 = context->analogIn[(int)n/2*8 + 0]; // float chn5 = context->analogIn[(int)n/2*8 + 1]; scope.log(0, chn0); - // scope.log(1, chn1); + scope.log(1, chn1); // scope.log(2, chn2); // scope.log(3, chn3); // scope.log(4, chn4); @@ -80,18 +84,18 @@ gPhase2 -= 2.0 * M_PI; } - static float buffer[32]; //this should be context->audioFrames + static float buffer[2][32]; //this should be context->audioFrames if(count==0){ - for(int n=0; n<32; n++) - buffer[n]=0; + memset(buffer,2*32*sizeof(float),0); } if(count>0){ - int readPointer=receiveAudio.getSamplesSrc(buffer, context->audioFrames, 1); - for(int n=0; n<context->audioFrames; n++){ - context->audioOut[n*2]=buffer[n]; - context->audioOut[n*2+1]=buffer[n]; - } - } + int readPointer0=receiveAudio0.getSamplesSrc(buffer[0], context->audioFrames, 1); + int readPointer1=receiveAudio1.getSamplesSrc(buffer[1], context->audioFrames, 1); + for(unsigned int n=0; n<context->audioFrames; n++){ + context->audioOut[n*2]=buffer[0][n]; + context->audioOut[n*2+1]=buffer[1][n]; + } + } count++; }