comparison projects/scope/render.cpp @ 111:9928b6366227 scope-refactoring

Refactored the Scope class into NetworkSend and Scope classes. No need for a global pointer anymore!
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 19 Aug 2015 22:40:05 +0100
parents ad8a93cd7c39
children 3168919fdb07
comparison
equal deleted inserted replaced
110:fb56681ab1d6 111:9928b6366227
4 4
5 float gPhase1, gPhase2; 5 float gPhase1, gPhase2;
6 float gFrequency1, gFrequency2; 6 float gFrequency1, gFrequency2;
7 float gInverseSampleRate; 7 float gInverseSampleRate;
8 8
9 Scope scope(1); //create a scope object with numChannels 9 Scope scope(6); //create a scope object with 6 channels
10 NetworkSend networkSend;
10 11
11 // initialise_render() is called once before the audio rendering starts. 12 // initialise_render() is called once before the audio rendering starts.
12 // Use it to perform any initialisation and allocation which is dependent 13 // Use it to perform any initialisation and allocation which is dependent
13 // on the period size or sample rate. 14 // on the period size or sample rate.
14 // 15 //
15 // userData holds an opaque pointer to a data structure that was passed 16 // userData holds an opaque pointer to a data structure that was passed
16 // in from the call to initAudio(). 17 // in from the call to initAudio().
17 // 18 //
18 // Return true on success; returning false halts the program. 19 // Return true on success; returning false halts the program.
20
19 bool setup(BeagleRTContext *context, void *userData) 21 bool setup(BeagleRTContext *context, void *userData)
20 { 22 {
21 scope.setup(context->audioSampleRate); //call this once in setup to initialise the scope 23 scope.setup(); //call this once in setup to initialise the scope
24 // networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1");
22 25
23 gInverseSampleRate = 1.0/context->audioSampleRate; 26 gInverseSampleRate = 1.0/context->audioSampleRate;
24 27
25 gPhase1 = 0.0; 28 gPhase1 = 0.0;
26 gPhase2 = 0.0; 29 gPhase2 = 0.0;
27 30
28 gFrequency1 = 200.0; 31 gFrequency1 = 200.0;
29 gFrequency2 = 201.0; 32 gFrequency2 = 201.0;
33
30 return true; 34 return true;
31 } 35 }
32 36
33 // render() is called regularly at the highest priority by the audio engine. 37 // render() is called regularly at the highest priority by the audio engine.
34 // Input and output are given from the audio hardware and the other 38 // Input and output are given from the audio hardware and the other
38 void render(BeagleRTContext *context, void *userData) 42 void render(BeagleRTContext *context, void *userData)
39 { 43 {
40 static int count=0; 44 static int count=0;
41 for(unsigned int n = 0; n < context->audioFrames; n++) { 45 for(unsigned int n = 0; n < context->audioFrames; n++) {
42 46
43 float chn1 = sinf(gPhase1); 47 float chn0 = sinf(gPhase1);
44 float chn2 = sinf(gPhase2); 48 float chn1 = sinf(gPhase2);
45 49
46 float chn3 = context->audioIn[n*2 + 0]; 50 float chn2 = context->audioIn[n*2 + 0];
47 float chn4 = context->audioIn[n*2 + 1]; 51 float chn3 = context->audioIn[n*2 + 1];
48 52
49 float chn5 = context->analogIn[(int)n/2*8 + 0]; 53 float chn4 = context->analogIn[(int)n/2*8 + 0];
50 float chn6 = context->analogIn[(int)n/2*8 + 1]; 54 float chn5 = context->analogIn[(int)n/2*8 + 1];
51 if((n&1)==0) 55 scope.log(0, chn0);
52 scope.log(0, chn1); 56 scope.log(1, chn1);
57 scope.log(2, chn2);
58 scope.log(3, chn3);
59 scope.log(4, chn4);
60 scope.log(5, chn5);
53 61
54 // scope.log(chn1, chn2, chn3, chn4, chn5, chn6); 62 // scope.log(chn1, chn2, chn3, chn4, chn5, chn6);
55 //call this once every audio frame 63 //call this once every audio frame
56 //takes six or fewer floats as parameters 64 //takes six or fewer floats as parameters
57 //first parameter becomes channel 1 etc 65 //first parameter becomes channel 1 etc