Mercurial > hg > beaglert
comparison projects/scope/render.cpp @ 109:ad8a93cd7c39 scope-refactoring
Working for single-channel scope, or NetworkIO
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 18 Aug 2015 14:53:16 +0100 |
parents | 2fe6690fcab7 |
children | 9928b6366227 |
comparison
equal
deleted
inserted
replaced
107:836052c86e1e | 109:ad8a93cd7c39 |
---|---|
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; //create a scope object | 9 Scope scope(1); //create a scope object with numChannels |
10 | 10 |
11 // initialise_render() is called once before the audio rendering starts. | 11 // initialise_render() is called once before the audio rendering starts. |
12 // Use it to perform any initialisation and allocation which is dependent | 12 // Use it to perform any initialisation and allocation which is dependent |
13 // on the period size or sample rate. | 13 // on the period size or sample rate. |
14 // | 14 // |
35 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | 35 // ADCs and DACs (if available). If only audio is available, numMatrixFrames |
36 // will be 0. | 36 // will be 0. |
37 | 37 |
38 void render(BeagleRTContext *context, void *userData) | 38 void render(BeagleRTContext *context, void *userData) |
39 { | 39 { |
40 static int count=0; | |
40 for(unsigned int n = 0; n < context->audioFrames; n++) { | 41 for(unsigned int n = 0; n < context->audioFrames; n++) { |
41 | 42 |
42 float chn1 = sinf(gPhase1); | 43 float chn1 = sinf(gPhase1); |
43 float chn2 = sinf(gPhase2); | 44 float chn2 = sinf(gPhase2); |
44 | 45 |
45 float chn3 = context->audioIn[n*2 + 0]; | 46 float chn3 = context->audioIn[n*2 + 0]; |
46 float chn4 = context->audioIn[n*2 + 1]; | 47 float chn4 = context->audioIn[n*2 + 1]; |
47 | 48 |
48 float chn5 = context->analogIn[(int)n/2*8 + 0]; | 49 float chn5 = context->analogIn[(int)n/2*8 + 0]; |
49 float chn6 = context->analogIn[(int)n/2*8 + 1]; | 50 float chn6 = context->analogIn[(int)n/2*8 + 1]; |
51 if((n&1)==0) | |
52 scope.log(0, chn1); | |
50 | 53 |
51 // scope.log(chn1, chn2, chn3, chn4, chn5, chn6); | 54 // scope.log(chn1, chn2, chn3, chn4, chn5, chn6); |
52 scope.log(chn1); | |
53 //call this once every audio frame | 55 //call this once every audio frame |
54 //takes six or fewer floats as parameters | 56 //takes six or fewer floats as parameters |
55 //first parameter becomes channel 1 etc | 57 //first parameter becomes channel 1 etc |
56 //to view, click the 'oscilloscope' button on the toolbar while BeagleRT is NOT running | 58 //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 | 59 //then click the big red button on the toolbar on this page |
58 | 60 |
59 gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate; | 61 gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate * ((count&4095)/4096.0+1); |
60 gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; | 62 gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; |
61 if(gPhase1 > 2.0 * M_PI) | 63 if(gPhase1 > 2.0 * M_PI) |
62 gPhase1 -= 2.0 * M_PI; | 64 gPhase1 -= 2.0 * M_PI; |
63 if(gPhase2 > 2.0 * M_PI) | 65 if(gPhase2 > 2.0 * M_PI) |
64 gPhase2 -= 2.0 * M_PI; | 66 gPhase2 -= 2.0 * M_PI; |
65 | 67 |
66 } | 68 } |
69 count++; | |
67 } | 70 } |
68 | 71 |
69 // cleanup_render() is called once at the end, after the audio has stopped. | 72 // cleanup_render() is called once at the end, after the audio has stopped. |
70 // Release any resources that were allocated in initialise_render(). | 73 // Release any resources that were allocated in initialise_render(). |
71 | 74 |