giuliomoro@24
|
1 /*
|
giuliomoro@24
|
2 * render.cpp
|
giuliomoro@24
|
3 *
|
giuliomoro@24
|
4 * Created on: Oct 24, 2014
|
giuliomoro@24
|
5 * Author: parallels
|
giuliomoro@24
|
6 */
|
giuliomoro@24
|
7
|
andrewm@56
|
8 #include <BeagleRT.h>
|
giuliomoro@92
|
9 //#include <rtdk.h>
|
giuliomoro@24
|
10 #include <cmath>
|
giuliomoro@221
|
11 #include <NetworkSend.h>
|
giuliomoro@92
|
12 #include <Utilities.h>
|
giuliomoro@92
|
13
|
andrewm@56
|
14 // setup() is called once before the audio rendering starts.
|
giuliomoro@24
|
15 // Use it to perform any initialisation and allocation which is dependent
|
giuliomoro@24
|
16 // on the period size or sample rate.
|
giuliomoro@24
|
17 //
|
giuliomoro@24
|
18 // userData holds an opaque pointer to a data structure that was passed
|
giuliomoro@24
|
19 // in from the call to initAudio().
|
giuliomoro@24
|
20 //
|
giuliomoro@24
|
21 // Return true on success; returning false halts the program.
|
giuliomoro@221
|
22
|
giuliomoro@221
|
23 NetworkSend networkSend;
|
giuliomoro@221
|
24 float gFrequency;
|
giuliomoro@221
|
25 float gInverseSampleRate;
|
giuliomoro@221
|
26 float gPhase;
|
andrewm@56
|
27 bool setup(BeagleRTContext *context, void *userData)
|
giuliomoro@24
|
28 {
|
giuliomoro@24
|
29 // Retrieve a parameter passed in from the initAudio() call
|
giuliomoro@24
|
30 gFrequency = *(float *)userData;
|
giuliomoro@24
|
31
|
giuliomoro@221
|
32 networkSend.setup(context->audioSampleRate, context->audioFrames, 3, 9999, "192.168.7.1");
|
andrewm@56
|
33 gInverseSampleRate = 1.0 / context->audioSampleRate;
|
giuliomoro@221
|
34 gPhase = 0.2132;
|
giuliomoro@24
|
35 return true;
|
giuliomoro@24
|
36 }
|
giuliomoro@24
|
37
|
giuliomoro@24
|
38 // render() is called regularly at the highest priority by the audio engine.
|
giuliomoro@24
|
39 // Input and output are given from the audio hardware and the other
|
giuliomoro@24
|
40 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
|
giuliomoro@24
|
41 // will be 0.
|
giuliomoro@24
|
42
|
andrewm@56
|
43 void render(BeagleRTContext *context, void *userData)
|
giuliomoro@221
|
44 {
|
andrewm@56
|
45 for(unsigned int n = 0; n < context->audioFrames; n++) {
|
giuliomoro@24
|
46 float out = 0.7f * sinf(gPhase);
|
giuliomoro@24
|
47 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate;
|
giuliomoro@24
|
48 if(gPhase > 2.0 * M_PI)
|
giuliomoro@24
|
49 gPhase -= 2.0 * M_PI;
|
giuliomoro@24
|
50
|
giuliomoro@221
|
51 for(unsigned int channel = 0; channel < context->audioChannels; channel++){
|
andrewm@56
|
52 context->audioOut[n * context->audioChannels + channel] = out;
|
giuliomoro@24
|
53 }
|
giuliomoro@221
|
54 networkSend.log(out);
|
giuliomoro@92
|
55 }
|
giuliomoro@24
|
56 }
|
giuliomoro@24
|
57
|
andrewm@56
|
58 // cleanup() is called once at the end, after the audio has stopped.
|
andrewm@56
|
59 // Release any resources that were allocated in setup().
|
giuliomoro@24
|
60
|
andrewm@56
|
61 void cleanup(BeagleRTContext *context, void *userData)
|
giuliomoro@24
|
62 {
|
giuliomoro@24
|
63 }
|