Mercurial > hg > beaglert
comparison examples/basic_network/render.cpp @ 300:dbeed520b014 prerelease
Renamed projects to examples
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 27 May 2016 13:58:20 +0100 |
parents | projects/basic_network/render.cpp@6a23c07d0fbb |
children | e4392164b458 |
comparison
equal
deleted
inserted
replaced
297:a3d83ebdf49b | 300:dbeed520b014 |
---|---|
1 /* | |
2 * render.cpp | |
3 * | |
4 * Created on: Oct 24, 2014 | |
5 * Author: parallels | |
6 */ | |
7 | |
8 #include <BeagleRT.h> | |
9 //#include <rtdk.h> | |
10 #include <cmath> | |
11 #include <NetworkSend.h> | |
12 #include <ReceiveAudioThread.h> | |
13 #include <Utilities.h> | |
14 | |
15 // setup() is called once before the audio rendering starts. | |
16 // Use it to perform any initialisation and allocation which is dependent | |
17 // on the period size or sample rate. | |
18 // | |
19 // userData holds an opaque pointer to a data structure that was passed | |
20 // in from the call to initAudio(). | |
21 // | |
22 // Return true on success; returning false halts the program. | |
23 | |
24 NetworkSend networkSend; | |
25 ReceiveAudioThread receive; | |
26 float gFrequency; | |
27 float gInverseSampleRate; | |
28 float gPhase; | |
29 bool setup(BeagleRTContext *context, void *userData) | |
30 { | |
31 // Retrieve a parameter passed in from the initAudio() call | |
32 gFrequency = *(float *)userData; | |
33 | |
34 networkSend.setup(context->audioSampleRate, context->audioFrames, 0, 9999, "192.168.7.1"); | |
35 receive.init(10000, context->audioFrames, 0); | |
36 receive.startThread(); | |
37 gInverseSampleRate = 1.0 / context->audioSampleRate; | |
38 gPhase = 0; | |
39 return true; | |
40 } | |
41 | |
42 // render() is called regularly at the highest priority by the audio engine. | |
43 // Input and output are given from the audio hardware and the other | |
44 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | |
45 // will be 0. | |
46 | |
47 void render(BeagleRTContext *context, void *userData) | |
48 { | |
49 for(unsigned int n = 0; n < context->audioFrames; n++) { | |
50 float out = 0.7f * sinf(gPhase); | |
51 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; | |
52 if(gPhase > 2.0 * M_PI) | |
53 gPhase -= 2.0 * M_PI; | |
54 | |
55 networkSend.log(out); | |
56 float in; | |
57 int ret = receive.getSamplesSrc(&in, 1, 1); | |
58 for(unsigned int channel = 0; channel < context->audioChannels; channel++){ | |
59 audioWriteFrame(context, n, channel, in); | |
60 } | |
61 } | |
62 } | |
63 | |
64 // cleanup() is called once at the end, after the audio has stopped. | |
65 // Release any resources that were allocated in setup(). | |
66 | |
67 void cleanup(BeagleRTContext *context, void *userData) | |
68 { | |
69 } |