robert@464
|
1 /*
|
robert@464
|
2 ____ _____ _ _
|
robert@464
|
3 | __ )| ____| | / \
|
robert@464
|
4 | _ \| _| | | / _ \
|
robert@464
|
5 | |_) | |___| |___ / ___ \
|
robert@464
|
6 |____/|_____|_____/_/ \_\
|
robert@464
|
7
|
robert@464
|
8 The platform for ultra-low latency audio and sensor processing
|
robert@464
|
9
|
robert@464
|
10 http://bela.io
|
robert@464
|
11
|
robert@464
|
12 A project of the Augmented Instruments Laboratory within the
|
robert@464
|
13 Centre for Digital Music at Queen Mary University of London.
|
robert@464
|
14 http://www.eecs.qmul.ac.uk/~andrewm
|
robert@464
|
15
|
robert@464
|
16 (c) 2016 Augmented Instruments Laboratory: Andrew McPherson,
|
robert@464
|
17 Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack,
|
robert@464
|
18 Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved.
|
robert@464
|
19
|
robert@464
|
20 The Bela software is distributed under the GNU Lesser General Public License
|
robert@464
|
21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt
|
robert@464
|
22 */
|
robert@464
|
23
|
robert@464
|
24 #include <Bela.h>
|
robert@464
|
25
|
robert@464
|
26
|
robert@464
|
27 // setup() is called once before the audio rendering starts.
|
robert@464
|
28 // Use it to perform any initialisation and allocation which is dependent
|
robert@464
|
29 // on the period size or sample rate.
|
robert@464
|
30 //
|
robert@464
|
31 // userData holds an opaque pointer to a data structure that was passed
|
robert@464
|
32 // in from the call to initAudio().
|
robert@464
|
33 //
|
robert@464
|
34 // Return true on success; returning false halts the program.
|
robert@464
|
35 bool setup(BelaContext *context, void *userData)
|
robert@464
|
36 {
|
robert@464
|
37 return true;
|
robert@464
|
38 }
|
robert@464
|
39
|
robert@464
|
40 // render() is called regularly at the highest priority by the audio engine.
|
robert@464
|
41 // Input and output are given from the audio hardware and the other
|
robert@464
|
42 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
|
robert@464
|
43 // will be 0.
|
robert@464
|
44 void render(BelaContext *context, void *userData)
|
robert@464
|
45 {
|
robert@464
|
46
|
robert@464
|
47 }
|
robert@464
|
48
|
robert@464
|
49 // cleanup() is called once at the end, after the audio has stopped.
|
robert@464
|
50 // Release any resources that were allocated in setup().
|
robert@464
|
51 void cleanup(BelaContext *context, void *userData)
|
robert@464
|
52 {
|
robert@464
|
53
|
robert@464
|
54 }
|
robert@464
|
55
|
robert@464
|
56
|
robert@464
|
57 /**
|
robert@464
|
58
|
robert@500
|
59 \example minimal/render.cpp
|
robert@464
|
60
|
robert@464
|
61 The bare bones
|
robert@464
|
62 ----------------------
|
robert@464
|
63
|
robert@464
|
64 The structure of a render.cpp file
|
robert@464
|
65 ----------------------------------
|
robert@464
|
66 A render.cpp file has three functions: `setup()`, `render()` and `cleanup()`.
|
robert@464
|
67
|
robert@464
|
68 `setup()` is an initialisation function which runs before audio rendering begins.
|
robert@464
|
69 It is called once when the project starts. Use it to prepare any memory or
|
robert@464
|
70 resources that will be needed in `render()`.
|
robert@464
|
71
|
robert@464
|
72 `render()` is a function that is regularly called, over and over continuously, at
|
robert@464
|
73 the highest priority by the audio engine. It is used to process audio and
|
robert@464
|
74 sensor data. This function is called regularly by the system every time there
|
robert@464
|
75 is a new block of audio and/or sensor data to process.
|
robert@464
|
76
|
robert@464
|
77 `cleanup()` is a function that is called when the program stops, to finish up any
|
robert@464
|
78 processes that might still be running.
|
robert@464
|
79
|
robert@464
|
80 Here we will briefly explain each function and the structure of the render.cpp
|
robert@464
|
81
|
robert@464
|
82 Before any of the functions
|
robert@464
|
83 ---------------------------
|
robert@464
|
84 At the top of the file, include any libraries you might need.
|
robert@464
|
85
|
robert@464
|
86 Additionally, declare any global variables. In these tutorial sketches, all
|
robert@464
|
87 global variables are preceded by a `g` so we always know which variables are
|
robert@464
|
88 global - `gSampleData`, for example. It's not mandatory but is a really good way
|
robert@464
|
89 of keeping track of what's global and what's not.
|
robert@464
|
90
|
robert@464
|
91 Sometimes it's necessary to access a variable from another file, such as
|
robert@464
|
92 main.cpp. In this case, precede this variable with the keyword `extern`.
|
robert@464
|
93
|
robert@464
|
94 Function arguments
|
robert@464
|
95 ------------------
|
robert@464
|
96 `setup()`, `render()` and `cleanup()` each take the same arguments. These are:
|
robert@464
|
97
|
robert@464
|
98 `0ext *context`
|
robert@464
|
99 `void *userData`
|
robert@464
|
100
|
robert@464
|
101 These arguments are pointers to data structures. The main one that's used is
|
robert@464
|
102 `context`, which is a pointer to a data structure containing lots of information
|
robert@464
|
103 you need.
|
robert@464
|
104
|
robert@464
|
105 Take a look at what's in the data structure [here]
|
robert@464
|
106 (https://code.soundsoftware.ac.uk/projects/beaglert/embedded/structBeagleRTContext.html).
|
robert@464
|
107
|
robert@464
|
108 You can access any of these bits of information about current audio and sensor
|
robert@464
|
109 settings and pointers to data buffers that are contained in the data structure
|
robert@464
|
110 like this: `context->name_of_item`.
|
robert@464
|
111
|
robert@464
|
112 For example, `context->audioChannels` returns the number of audio channels.
|
robert@464
|
113 `context->audioSampleRate` returns the audio sample rate.
|
robert@464
|
114 `context->audioIn[n]` would give you the current input sample (assuming that
|
robert@464
|
115 your input is mono - if it's not you will have to account for multiple channels).
|
robert@464
|
116
|
robert@464
|
117 Note that `audioIn`, `audioOut`, `analogIn`, `analogOut` are all arrays (buffers).
|
robert@464
|
118
|
giuliomoro@507
|
119 */
|