Mercurial > hg > beaglert
comparison projects/scope/render.cpp @ 94:2fe6690fcab7
Added scope project, copied and edited from nodejsbeaglert
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 22 Jul 2015 11:38:41 +0100 |
parents | |
children | ad8a93cd7c39 a94c8e0f4ec7 |
comparison
equal
deleted
inserted
replaced
93:8c7f537d0a21 | 94:2fe6690fcab7 |
---|---|
1 #include <BeagleRT.h> | |
2 #include <Scope.h> | |
3 #include <cmath> | |
4 | |
5 float gPhase1, gPhase2; | |
6 float gFrequency1, gFrequency2; | |
7 float gInverseSampleRate; | |
8 | |
9 Scope scope; //create a scope object | |
10 | |
11 // initialise_render() is called once before the audio rendering starts. | |
12 // Use it to perform any initialisation and allocation which is dependent | |
13 // on the period size or sample rate. | |
14 // | |
15 // userData holds an opaque pointer to a data structure that was passed | |
16 // in from the call to initAudio(). | |
17 // | |
18 // Return true on success; returning false halts the program. | |
19 bool setup(BeagleRTContext *context, void *userData) | |
20 { | |
21 scope.setup(context->audioSampleRate); //call this once in setup to initialise the scope | |
22 | |
23 gInverseSampleRate = 1.0/context->audioSampleRate; | |
24 | |
25 gPhase1 = 0.0; | |
26 gPhase2 = 0.0; | |
27 | |
28 gFrequency1 = 200.0; | |
29 gFrequency2 = 201.0; | |
30 return true; | |
31 } | |
32 | |
33 // 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 | |
35 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | |
36 // will be 0. | |
37 | |
38 void render(BeagleRTContext *context, void *userData) | |
39 { | |
40 for(unsigned int n = 0; n < context->audioFrames; n++) { | |
41 | |
42 float chn1 = sinf(gPhase1); | |
43 float chn2 = sinf(gPhase2); | |
44 | |
45 float chn3 = context->audioIn[n*2 + 0]; | |
46 float chn4 = context->audioIn[n*2 + 1]; | |
47 | |
48 float chn5 = context->analogIn[(int)n/2*8 + 0]; | |
49 float chn6 = context->analogIn[(int)n/2*8 + 1]; | |
50 | |
51 // scope.log(chn1, chn2, chn3, chn4, chn5, chn6); | |
52 scope.log(chn1); | |
53 //call this once every audio frame | |
54 //takes six or fewer floats as parameters | |
55 //first parameter becomes channel 1 etc | |
56 //to view, click the 'oscilloscope' button on the toolbar while BeagleRT is NOT running | |
57 //then click the big red button on the toolbar on this page | |
58 | |
59 gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate; | |
60 gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; | |
61 if(gPhase1 > 2.0 * M_PI) | |
62 gPhase1 -= 2.0 * M_PI; | |
63 if(gPhase2 > 2.0 * M_PI) | |
64 gPhase2 -= 2.0 * M_PI; | |
65 | |
66 } | |
67 } | |
68 | |
69 // cleanup_render() is called once at the end, after the audio has stopped. | |
70 // Release any resources that were allocated in initialise_render(). | |
71 | |
72 void cleanup(BeagleRTContext *context, void *userData) | |
73 { | |
74 | |
75 } |