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