comparison projects/scope/render.cpp @ 128:2696a7f00053 scope-refactoring

ReceiveAudioThread is now the same with/without JUCE
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 24 Aug 2015 18:55:19 +0100
parents bc514f29c3aa
children ff28e56e5b7e
comparison
equal deleted inserted replaced
127:6c8fb6f07b47 128:2696a7f00053
5 5
6 float gPhase1, gPhase2; 6 float gPhase1, gPhase2;
7 float gFrequency1, gFrequency2; 7 float gFrequency1, gFrequency2;
8 float gInverseSampleRate; 8 float gInverseSampleRate;
9 9
10 Scope scope(2); //create a scope object with 2 channels 10 //Scope scope(2); //create a scope object with 2 channels
11 NetworkSend networkSend; 11 NetworkSend networkSend;
12 12
13 // initialise_render() is called once before the audio rendering starts. 13 // initialise_render() is called once before the audio rendering starts.
14 // Use it to perform any initialisation and allocation which is dependent 14 // Use it to perform any initialisation and allocation which is dependent
15 // on the period size or sample rate. 15 // on the period size or sample rate.
16 // 16 //
17 // 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
18 // in from the call to initAudio(). 18 // in from the call to initAudio().
19 // 19 //
20 // Return true on success; returning false halts the program. 20 // Return true on success; returning false halts the program.
21 ReceiveAudioThread receiveAudio0; 21 //ReceiveAudioThread receiveAudio0;
22 ReceiveAudioThread receiveAudio1; 22 //ReceiveAudioThread receiveAudio1;
23 bool setup(BeagleRTContext *context, void *userData) 23 bool setup(BeagleRTContext *context, void *userData)
24 { 24 {
25 receiveAudio0.init(9999, context->audioFrames, 0); 25 // receiveAudio0.init(9999, context->audioFrames, 0);
26 receiveAudio1.init(10000, context->audioFrames, 1); 26 // receiveAudio1.init(10000, context->audioFrames, 1);
27 27 //
28 scope.setup(); //call this once in setup to initialise the scope 28 // scope.setup(); //call this once in setup to initialise the scope
29 scope.setPort(0, 9999); 29 // scope.setPort(0, 9999);
30 scope.setPort(1, 10000); 30 // scope.setPort(1, 10000);
31 // networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1"); 31 networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1");
32 32
33 gInverseSampleRate = 1.0/context->audioSampleRate; 33 gInverseSampleRate = 1.0/context->audioSampleRate;
34 34
35 gPhase1 = 0.0; 35 gPhase1 = 0.0;
36 gPhase2 = 0.0; 36 gPhase2 = 0.0;
47 // will be 0. 47 // will be 0.
48 48
49 void render(BeagleRTContext *context, void *userData) 49 void render(BeagleRTContext *context, void *userData)
50 { 50 {
51 static int count=0; 51 static int count=0;
52 if(count==0){ 52 // if(count==0){
53 printf("startHread\n"); 53 // printf("startHread\n");
54 ReceiveAudioThread::startThread(); 54 // ReceiveAudioThread::startThread();
55 } 55 // }
56 for(unsigned int n = 0; n < context->audioFrames; n++) { 56 for(unsigned int n = 0; n < context->audioFrames; n++) {
57 57
58 float chn0 = sinf(gPhase1); 58 float chn0 = sinf(gPhase1);
59 float chn1 = sinf(gPhase2); 59 float chn1 = sinf(gPhase2);
60 60
61 // float chn2 = context->audioIn[n*2 + 0]; 61 // float chn2 = context->audioIn[n*2 + 0];
62 // float chn3 = context->audioIn[n*2 + 1]; 62 // float chn3 = context->audioIn[n*2 + 1];
63 63
64 // float chn4 = context->analogIn[(int)n/2*8 + 0]; 64 // float chn4 = context->analogIn[(int)n/2*8 + 0];
65 // float chn5 = context->analogIn[(int)n/2*8 + 1]; 65 // float chn5 = context->analogIn[(int)n/2*8 + 1];
66 scope.log(0, chn0); 66 networkSend.log(chn0);
67 scope.log(1, chn1); 67 // scope.log(0, chn0);
68 // scope.log(1, chn1);
68 // scope.log(2, chn2); 69 // scope.log(2, chn2);
69 // scope.log(3, chn3); 70 // scope.log(3, chn3);
70 // scope.log(4, chn4); 71 // scope.log(4, chn4);
71 // scope.log(5, chn5); 72 // scope.log(5, chn5);
72 73
84 if(gPhase2 > 2.0 * M_PI) 85 if(gPhase2 > 2.0 * M_PI)
85 gPhase2 -= 2.0 * M_PI; 86 gPhase2 -= 2.0 * M_PI;
86 87
87 } 88 }
88 if(count>0){ 89 if(count>0){
89 int readPointer0=receiveAudio0.getSamplesSrc(context->audioOut, context->audioFrames, 1, 2, 0); 90 // int readPointer0=receiveAudio0.getSamplesSrc(context->audioOut, context->audioFrames, 1, 2, 0);
90 int readPointer1=receiveAudio1.getSamplesSrc(context->audioOut, context->audioFrames, 1, 2, 1); 91 // int readPointer1=receiveAudio1.getSamplesSrc(context->audioOut, context->audioFrames, 1, 2, 1);
91 } 92 }
92 count++; 93 count++;
93 } 94 }
94 95
95 // cleanup_render() is called once at the end, after the audio has stopped. 96 // cleanup_render() is called once at the end, after the audio has stopped.