comparison projects/basic_network/render.cpp @ 222:6a23c07d0fbb mergingClockSync

Working with UdpIoPlugin
author Giulio Moro <giuliomoro@yahoo.it>
date Sun, 14 Feb 2016 01:09:23 +0000
parents dbff109f64c2
children ac8eb07afcf5
comparison
equal deleted inserted replaced
221:dbff109f64c2 222:6a23c07d0fbb
7 7
8 #include <BeagleRT.h> 8 #include <BeagleRT.h>
9 //#include <rtdk.h> 9 //#include <rtdk.h>
10 #include <cmath> 10 #include <cmath>
11 #include <NetworkSend.h> 11 #include <NetworkSend.h>
12 #include <ReceiveAudioThread.h>
12 #include <Utilities.h> 13 #include <Utilities.h>
13 14
14 // setup() is called once before the audio rendering starts. 15 // setup() is called once before the audio rendering starts.
15 // Use it to perform any initialisation and allocation which is dependent 16 // Use it to perform any initialisation and allocation which is dependent
16 // on the period size or sample rate. 17 // on the period size or sample rate.
19 // in from the call to initAudio(). 20 // in from the call to initAudio().
20 // 21 //
21 // Return true on success; returning false halts the program. 22 // Return true on success; returning false halts the program.
22 23
23 NetworkSend networkSend; 24 NetworkSend networkSend;
25 ReceiveAudioThread receive;
24 float gFrequency; 26 float gFrequency;
25 float gInverseSampleRate; 27 float gInverseSampleRate;
26 float gPhase; 28 float gPhase;
27 bool setup(BeagleRTContext *context, void *userData) 29 bool setup(BeagleRTContext *context, void *userData)
28 { 30 {
29 // Retrieve a parameter passed in from the initAudio() call 31 // Retrieve a parameter passed in from the initAudio() call
30 gFrequency = *(float *)userData; 32 gFrequency = *(float *)userData;
31 33
32 networkSend.setup(context->audioSampleRate, context->audioFrames, 3, 9999, "192.168.7.1"); 34 networkSend.setup(context->audioSampleRate, context->audioFrames, 0, 9999, "192.168.7.1");
35 receive.init(10000, context->audioFrames, 0);
36 receive.startThread();
33 gInverseSampleRate = 1.0 / context->audioSampleRate; 37 gInverseSampleRate = 1.0 / context->audioSampleRate;
34 gPhase = 0.2132; 38 gPhase = 0;
35 return true; 39 return true;
36 } 40 }
37 41
38 // render() is called regularly at the highest priority by the audio engine. 42 // render() is called regularly at the highest priority by the audio engine.
39 // Input and output are given from the audio hardware and the other 43 // Input and output are given from the audio hardware and the other
46 float out = 0.7f * sinf(gPhase); 50 float out = 0.7f * sinf(gPhase);
47 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; 51 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate;
48 if(gPhase > 2.0 * M_PI) 52 if(gPhase > 2.0 * M_PI)
49 gPhase -= 2.0 * M_PI; 53 gPhase -= 2.0 * M_PI;
50 54
55 networkSend.log(out);
56 float in;
57 int ret = receive.getSamplesSrc(&in, 1, 1);
51 for(unsigned int channel = 0; channel < context->audioChannels; channel++){ 58 for(unsigned int channel = 0; channel < context->audioChannels; channel++){
52 context->audioOut[n * context->audioChannels + channel] = out; 59 audioWriteFrame(context, n, channel, in);
53 } 60 }
54 networkSend.log(out);
55 } 61 }
56 } 62 }
57 63
58 // cleanup() is called once at the end, after the audio has stopped. 64 // cleanup() is called once at the end, after the audio has stopped.
59 // Release any resources that were allocated in setup(). 65 // Release any resources that were allocated in setup().