Mercurial > hg > beaglert
comparison projects/scope/render.cpp @ 119:c692827083e1 scope-refactoring
Enabled multi channel audio receive
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 21 Aug 2015 15:21:34 +0100 |
parents | 26ad97b8aa9e |
children | cdd441a304a9 |
comparison
equal
deleted
inserted
replaced
118:26ad97b8aa9e | 119:c692827083e1 |
---|---|
5 | 5 |
6 float gPhase1, gPhase2; | 6 float gPhase1, gPhase2; |
7 float gFrequency1, gFrequency2; | 7 float gFrequency1, gFrequency2; |
8 float gInverseSampleRate; | 8 float gInverseSampleRate; |
9 | 9 |
10 Scope scope(6); //create a scope object with 6 channels | 10 Scope scope(2); //create a scope object with 2 channels |
11 NetworkSend networkSend; | 11 NetworkSend networkSend; |
12 | 12 |
13 // initialise_render() is called once before the audio rendering starts. | 13 // initialise_render() is called once before the audio rendering starts. |
14 // Use it to perform any initialisation and allocation which is dependent | 14 // Use it to perform any initialisation and allocation which is dependent |
15 // on the period size or sample rate. | 15 // on the period size or sample rate. |
16 // | 16 // |
17 // 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 |
18 // in from the call to initAudio(). | 18 // in from the call to initAudio(). |
19 // | 19 // |
20 // Return true on success; returning false halts the program. | 20 // Return true on success; returning false halts the program. |
21 ReceiveAudioThread receiveAudio; | 21 ReceiveAudioThread receiveAudio0; |
22 ReceiveAudioThread receiveAudio1; | |
22 bool setup(BeagleRTContext *context, void *userData) | 23 bool setup(BeagleRTContext *context, void *userData) |
23 { | 24 { |
24 receiveAudio.bindToPort(9999); | 25 receiveAudio0.init(9999, context->audioFrames, 0); |
25 receiveAudio.init(context->audioFrames); | 26 receiveAudio1.init(10000, context->audioFrames, 1); |
27 | |
26 scope.setup(); //call this once in setup to initialise the scope | 28 scope.setup(); //call this once in setup to initialise the scope |
29 scope.setPort(0, 9999); | |
30 scope.setPort(1, 10000); | |
27 // networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1"); | 31 // networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1"); |
28 | 32 |
29 gInverseSampleRate = 1.0/context->audioSampleRate; | 33 gInverseSampleRate = 1.0/context->audioSampleRate; |
30 | 34 |
31 gPhase1 = 0.0; | 35 gPhase1 = 0.0; |
44 | 48 |
45 void render(BeagleRTContext *context, void *userData) | 49 void render(BeagleRTContext *context, void *userData) |
46 { | 50 { |
47 static int count=0; | 51 static int count=0; |
48 if(count==0) | 52 if(count==0) |
49 receiveAudio.startThread(); | 53 ReceiveAudioThread::startThread(); |
50 | 54 |
51 for(unsigned int n = 0; n < context->audioFrames; n++) { | 55 for(unsigned int n = 0; n < context->audioFrames; n++) { |
52 | 56 |
53 float chn0 = sinf(gPhase1); | 57 float chn0 = sinf(gPhase1); |
54 // float chn1 = sinf(gPhase2); | 58 float chn1 = sinf(gPhase2); |
55 | 59 |
56 // float chn2 = context->audioIn[n*2 + 0]; | 60 // float chn2 = context->audioIn[n*2 + 0]; |
57 // float chn3 = context->audioIn[n*2 + 1]; | 61 // float chn3 = context->audioIn[n*2 + 1]; |
58 | 62 |
59 // float chn4 = context->analogIn[(int)n/2*8 + 0]; | 63 // float chn4 = context->analogIn[(int)n/2*8 + 0]; |
60 // float chn5 = context->analogIn[(int)n/2*8 + 1]; | 64 // float chn5 = context->analogIn[(int)n/2*8 + 1]; |
61 scope.log(0, chn0); | 65 scope.log(0, chn0); |
62 // scope.log(1, chn1); | 66 scope.log(1, chn1); |
63 // scope.log(2, chn2); | 67 // scope.log(2, chn2); |
64 // scope.log(3, chn3); | 68 // scope.log(3, chn3); |
65 // scope.log(4, chn4); | 69 // scope.log(4, chn4); |
66 // scope.log(5, chn5); | 70 // scope.log(5, chn5); |
67 | 71 |
78 gPhase1 -= 2.0 * M_PI; | 82 gPhase1 -= 2.0 * M_PI; |
79 if(gPhase2 > 2.0 * M_PI) | 83 if(gPhase2 > 2.0 * M_PI) |
80 gPhase2 -= 2.0 * M_PI; | 84 gPhase2 -= 2.0 * M_PI; |
81 | 85 |
82 } | 86 } |
83 static float buffer[32]; //this should be context->audioFrames | 87 static float buffer[2][32]; //this should be context->audioFrames |
84 if(count==0){ | 88 if(count==0){ |
85 for(int n=0; n<32; n++) | 89 memset(buffer,2*32*sizeof(float),0); |
86 buffer[n]=0; | |
87 } | 90 } |
88 if(count>0){ | 91 if(count>0){ |
89 int readPointer=receiveAudio.getSamplesSrc(buffer, context->audioFrames, 1); | 92 int readPointer0=receiveAudio0.getSamplesSrc(buffer[0], context->audioFrames, 1); |
90 for(int n=0; n<context->audioFrames; n++){ | 93 int readPointer1=receiveAudio1.getSamplesSrc(buffer[1], context->audioFrames, 1); |
91 context->audioOut[n*2]=buffer[n]; | 94 for(unsigned int n=0; n<context->audioFrames; n++){ |
92 context->audioOut[n*2+1]=buffer[n]; | 95 context->audioOut[n*2]=buffer[0][n]; |
93 } | 96 context->audioOut[n*2+1]=buffer[1][n]; |
94 } | 97 } |
98 } | |
95 count++; | 99 count++; |
96 } | 100 } |
97 | 101 |
98 // cleanup_render() is called once at the end, after the audio has stopped. | 102 // cleanup_render() is called once at the end, after the audio has stopped. |
99 // Release any resources that were allocated in initialise_render(). | 103 // Release any resources that were allocated in initialise_render(). |