Mercurial > hg > beaglert
comparison projects/scope/render.cpp @ 218:a94c8e0f4ec7 mergingClockSync
Restored last working scope/render.cpp from --rev 122
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sat, 13 Feb 2016 05:00:02 +0000 |
parents | 2fe6690fcab7 |
children |
comparison
equal
deleted
inserted
replaced
217:c42a6b4dc2d4 | 218:a94c8e0f4ec7 |
---|---|
1 #include <BeagleRT.h> | 1 #include <BeagleRT.h> |
2 #include <Scope.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; |
8 | 9 |
9 Scope scope; //create a scope object | 10 Scope scope(2); //create a scope object with 2 channels |
11 NetworkSend networkSend; | |
10 | 12 |
11 // initialise_render() is called once before the audio rendering starts. | 13 // initialise_render() is called once before the audio rendering starts. |
12 // Use it to perform any initialisation and allocation which is dependent | 14 // Use it to perform any initialisation and allocation which is dependent |
13 // on the period size or sample rate. | 15 // on the period size or sample rate. |
14 // | 16 // |
15 // 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 |
16 // in from the call to initAudio(). | 18 // in from the call to initAudio(). |
17 // | 19 // |
18 // Return true on success; returning false halts the program. | 20 // Return true on success; returning false halts the program. |
21 ReceiveAudioThread receiveAudio0; | |
22 ReceiveAudioThread receiveAudio1; | |
19 bool setup(BeagleRTContext *context, void *userData) | 23 bool setup(BeagleRTContext *context, void *userData) |
20 { | 24 { |
21 scope.setup(context->audioSampleRate); //call this once in setup to initialise the scope | 25 receiveAudio0.init(9999, context->audioFrames, 0); |
26 receiveAudio1.init(10000, context->audioFrames, 1); | |
27 | |
28 scope.setup(); //call this once in setup to initialise the scope | |
29 scope.setPort(0, 9999); | |
30 scope.setPort(1, 10000); | |
31 // networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1"); | |
22 | 32 |
23 gInverseSampleRate = 1.0/context->audioSampleRate; | 33 gInverseSampleRate = 1.0/context->audioSampleRate; |
24 | 34 |
25 gPhase1 = 0.0; | 35 gPhase1 = 0.0; |
26 gPhase2 = 0.0; | 36 gPhase2 = 0.0; |
27 | 37 |
28 gFrequency1 = 200.0; | 38 gFrequency1 = 200.0; |
29 gFrequency2 = 201.0; | 39 gFrequency2 = 201.0; |
40 | |
30 return true; | 41 return true; |
31 } | 42 } |
32 | 43 |
33 // render() is called regularly at the highest priority by the audio engine. | 44 // 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 | 45 // Input and output are given from the audio hardware and the other |
35 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | 46 // ADCs and DACs (if available). If only audio is available, numMatrixFrames |
36 // will be 0. | 47 // will be 0. |
37 | 48 |
38 void render(BeagleRTContext *context, void *userData) | 49 void render(BeagleRTContext *context, void *userData) |
39 { | 50 { |
51 static int count=0; | |
52 if(count==0){ | |
53 printf("startHread\n"); | |
54 ReceiveAudioThread::startThread(); | |
55 } | |
40 for(unsigned int n = 0; n < context->audioFrames; n++) { | 56 for(unsigned int n = 0; n < context->audioFrames; n++) { |
41 | 57 |
42 float chn1 = sinf(gPhase1); | 58 float chn0 = sinf(gPhase1); |
43 float chn2 = sinf(gPhase2); | 59 float chn1 = sinf(gPhase2); |
44 | 60 |
45 float chn3 = context->audioIn[n*2 + 0]; | 61 // float chn2 = context->audioIn[n*2 + 0]; |
46 float chn4 = context->audioIn[n*2 + 1]; | 62 // float chn3 = context->audioIn[n*2 + 1]; |
47 | 63 |
48 float chn5 = context->analogIn[(int)n/2*8 + 0]; | 64 // float chn4 = context->analogIn[(int)n/2*8 + 0]; |
49 float chn6 = context->analogIn[(int)n/2*8 + 1]; | 65 // float chn5 = context->analogIn[(int)n/2*8 + 1]; |
66 scope.log(0, chn0); | |
67 scope.log(1, chn1); | |
68 // scope.log(2, chn2); | |
69 // scope.log(3, chn3); | |
70 // scope.log(4, chn4); | |
71 // scope.log(5, chn5); | |
50 | 72 |
51 // scope.log(chn1, chn2, chn3, chn4, chn5, chn6); | 73 // scope.log(chn1, chn2, chn3, chn4, chn5, chn6); |
52 scope.log(chn1); | |
53 //call this once every audio frame | 74 //call this once every audio frame |
54 //takes six or fewer floats as parameters | 75 //takes six or fewer floats as parameters |
55 //first parameter becomes channel 1 etc | 76 //first parameter becomes channel 1 etc |
56 //to view, click the 'oscilloscope' button on the toolbar while BeagleRT is NOT running | 77 //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 | 78 //then click the big red button on the toolbar on this page |
58 | 79 |
59 gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate; | 80 gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate * ((count&4095)/4096.0+1); |
60 gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; | 81 gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; |
61 if(gPhase1 > 2.0 * M_PI) | 82 if(gPhase1 > 2.0 * M_PI) |
62 gPhase1 -= 2.0 * M_PI; | 83 gPhase1 -= 2.0 * M_PI; |
63 if(gPhase2 > 2.0 * M_PI) | 84 if(gPhase2 > 2.0 * M_PI) |
64 gPhase2 -= 2.0 * M_PI; | 85 gPhase2 -= 2.0 * M_PI; |
65 | 86 |
66 } | 87 } |
88 if(count>0){ | |
89 int readPointer0=receiveAudio0.getSamplesSrc(context->audioOut, context->audioFrames, 1, 2, 0); | |
90 int readPointer1=receiveAudio1.getSamplesSrc(context->audioOut, context->audioFrames, 1, 2, 1); | |
91 } | |
92 count++; | |
67 } | 93 } |
68 | 94 |
69 // cleanup_render() is called once at the end, after the audio has stopped. | 95 // cleanup_render() is called once at the end, after the audio has stopped. |
70 // Release any resources that were allocated in initialise_render(). | 96 // Release any resources that were allocated in initialise_render(). |
71 | 97 |