giuliomoro@94
|
1 #include <BeagleRT.h>
|
giuliomoro@112
|
2 #include <NetworkSend.h>
|
giuliomoro@94
|
3 #include <cmath>
|
giuliomoro@94
|
4
|
giuliomoro@94
|
5 float gPhase1, gPhase2;
|
giuliomoro@94
|
6 float gFrequency1, gFrequency2;
|
giuliomoro@94
|
7 float gInverseSampleRate;
|
giuliomoro@94
|
8
|
giuliomoro@111
|
9 Scope scope(6); //create a scope object with 6 channels
|
giuliomoro@111
|
10 NetworkSend networkSend;
|
giuliomoro@94
|
11
|
giuliomoro@94
|
12 // initialise_render() is called once before the audio rendering starts.
|
giuliomoro@94
|
13 // Use it to perform any initialisation and allocation which is dependent
|
giuliomoro@94
|
14 // on the period size or sample rate.
|
giuliomoro@94
|
15 //
|
giuliomoro@94
|
16 // userData holds an opaque pointer to a data structure that was passed
|
giuliomoro@94
|
17 // in from the call to initAudio().
|
giuliomoro@94
|
18 //
|
giuliomoro@94
|
19 // Return true on success; returning false halts the program.
|
giuliomoro@111
|
20
|
giuliomoro@94
|
21 bool setup(BeagleRTContext *context, void *userData)
|
giuliomoro@94
|
22 {
|
giuliomoro@111
|
23 scope.setup(); //call this once in setup to initialise the scope
|
giuliomoro@111
|
24 // networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1");
|
giuliomoro@94
|
25
|
giuliomoro@94
|
26 gInverseSampleRate = 1.0/context->audioSampleRate;
|
giuliomoro@94
|
27
|
giuliomoro@94
|
28 gPhase1 = 0.0;
|
giuliomoro@94
|
29 gPhase2 = 0.0;
|
giuliomoro@94
|
30
|
giuliomoro@94
|
31 gFrequency1 = 200.0;
|
giuliomoro@94
|
32 gFrequency2 = 201.0;
|
giuliomoro@111
|
33
|
giuliomoro@94
|
34 return true;
|
giuliomoro@94
|
35 }
|
giuliomoro@94
|
36
|
giuliomoro@94
|
37 // render() is called regularly at the highest priority by the audio engine.
|
giuliomoro@94
|
38 // Input and output are given from the audio hardware and the other
|
giuliomoro@94
|
39 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
|
giuliomoro@94
|
40 // will be 0.
|
giuliomoro@94
|
41
|
giuliomoro@94
|
42 void render(BeagleRTContext *context, void *userData)
|
giuliomoro@94
|
43 {
|
giuliomoro@109
|
44 static int count=0;
|
giuliomoro@94
|
45 for(unsigned int n = 0; n < context->audioFrames; n++) {
|
giuliomoro@94
|
46
|
giuliomoro@111
|
47 float chn0 = sinf(gPhase1);
|
giuliomoro@111
|
48 float chn1 = sinf(gPhase2);
|
giuliomoro@111
|
49
|
giuliomoro@111
|
50 float chn2 = context->audioIn[n*2 + 0];
|
giuliomoro@111
|
51 float chn3 = context->audioIn[n*2 + 1];
|
giuliomoro@111
|
52
|
giuliomoro@111
|
53 float chn4 = context->analogIn[(int)n/2*8 + 0];
|
giuliomoro@111
|
54 float chn5 = context->analogIn[(int)n/2*8 + 1];
|
giuliomoro@111
|
55 scope.log(0, chn0);
|
giuliomoro@111
|
56 scope.log(1, chn1);
|
giuliomoro@111
|
57 scope.log(2, chn2);
|
giuliomoro@111
|
58 scope.log(3, chn3);
|
giuliomoro@111
|
59 scope.log(4, chn4);
|
giuliomoro@111
|
60 scope.log(5, chn5);
|
giuliomoro@94
|
61
|
giuliomoro@94
|
62 // scope.log(chn1, chn2, chn3, chn4, chn5, chn6);
|
giuliomoro@94
|
63 //call this once every audio frame
|
giuliomoro@94
|
64 //takes six or fewer floats as parameters
|
giuliomoro@94
|
65 //first parameter becomes channel 1 etc
|
giuliomoro@94
|
66 //to view, click the 'oscilloscope' button on the toolbar while BeagleRT is NOT running
|
giuliomoro@94
|
67 //then click the big red button on the toolbar on this page
|
giuliomoro@94
|
68
|
giuliomoro@109
|
69 gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate * ((count&4095)/4096.0+1);
|
giuliomoro@94
|
70 gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate;
|
giuliomoro@94
|
71 if(gPhase1 > 2.0 * M_PI)
|
giuliomoro@94
|
72 gPhase1 -= 2.0 * M_PI;
|
giuliomoro@94
|
73 if(gPhase2 > 2.0 * M_PI)
|
giuliomoro@94
|
74 gPhase2 -= 2.0 * M_PI;
|
giuliomoro@94
|
75
|
giuliomoro@94
|
76 }
|
giuliomoro@109
|
77 count++;
|
giuliomoro@94
|
78 }
|
giuliomoro@94
|
79
|
giuliomoro@94
|
80 // cleanup_render() is called once at the end, after the audio has stopped.
|
giuliomoro@94
|
81 // Release any resources that were allocated in initialise_render().
|
giuliomoro@94
|
82
|
giuliomoro@94
|
83 void cleanup(BeagleRTContext *context, void *userData)
|
giuliomoro@94
|
84 {
|
giuliomoro@94
|
85
|
giuliomoro@94
|
86 }
|