comparison projects/scope/render.cpp @ 117:ada68d50e56a scope-refactoring

ReceiveAudioThread hs been ported to BBB. The scope project now is sending audio locally and receiving it at the same time
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 20 Aug 2015 16:37:15 +0100
parents 3168919fdb07
children 26ad97b8aa9e
comparison
equal deleted inserted replaced
116:8341df5e404b 117:ada68d50e56a
1 #include <BeagleRT.h> 1 #include <BeagleRT.h>
2 #include <NetworkSend.h> 2 #include <NetworkSend.h>
3 #include <ReceiveAudioThread.h>
3 #include <cmath> 4 #include <cmath>
4 5
5 float gPhase1, gPhase2; 6 float gPhase1, gPhase2;
6 float gFrequency1, gFrequency2; 7 float gFrequency1, gFrequency2;
7 float gInverseSampleRate; 8 float gInverseSampleRate;
15 // 16 //
16 // userData holds an opaque pointer to a data structure that was passed 17 // userData holds an opaque pointer to a data structure that was passed
17 // in from the call to initAudio(). 18 // in from the call to initAudio().
18 // 19 //
19 // Return true on success; returning false halts the program. 20 // Return true on success; returning false halts the program.
20 21 ReceiveAudioThread receiveAudio;
21 bool setup(BeagleRTContext *context, void *userData) 22 bool setup(BeagleRTContext *context, void *userData)
22 { 23 {
24 receiveAudio.bindToPort(9999);
25 receiveAudio.init(context->audioFrames);
23 scope.setup(); //call this once in setup to initialise the scope 26 scope.setup(); //call this once in setup to initialise the scope
24 // networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1"); 27 // networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1");
25 28
26 gInverseSampleRate = 1.0/context->audioSampleRate; 29 gInverseSampleRate = 1.0/context->audioSampleRate;
27 30
40 // will be 0. 43 // will be 0.
41 44
42 void render(BeagleRTContext *context, void *userData) 45 void render(BeagleRTContext *context, void *userData)
43 { 46 {
44 static int count=0; 47 static int count=0;
48 if(count==0)
49 receiveAudio.startThread();
50
45 for(unsigned int n = 0; n < context->audioFrames; n++) { 51 for(unsigned int n = 0; n < context->audioFrames; n++) {
46 52
47 float chn0 = sinf(gPhase1); 53 float chn0 = sinf(gPhase1);
48 float chn1 = sinf(gPhase2); 54 float chn1 = sinf(gPhase2);
49 55
72 gPhase1 -= 2.0 * M_PI; 78 gPhase1 -= 2.0 * M_PI;
73 if(gPhase2 > 2.0 * M_PI) 79 if(gPhase2 > 2.0 * M_PI)
74 gPhase2 -= 2.0 * M_PI; 80 gPhase2 -= 2.0 * M_PI;
75 81
76 } 82 }
83 if(count>100)
84 receiveAudio.getSamplesSrc(context->audioOut, context->audioFrames, 1);
77 count++; 85 count++;
78 } 86 }
79 87
80 // cleanup_render() is called once at the end, after the audio has stopped. 88 // cleanup_render() is called once at the end, after the audio has stopped.
81 // Release any resources that were allocated in initialise_render(). 89 // Release any resources that were allocated in initialise_render().