Mercurial > hg > beaglert
comparison projects/empty_project/render.cpp @ 269:ac8eb07afcf5
Oxygen text added to each render.cpp file for the default projects. Text includes project explanation from Wiki, edited in places.
Empty project added as a default project.
Doxyfile updated. Each of the project locations added to INPUT configuration option. Consider just watching the whole project file so all new projects are automatically pulled through.
author | Robert Jack <robert.h.jack@gmail.com> |
---|---|
date | Tue, 17 May 2016 15:40:16 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
252:381f352c44eb | 269:ac8eb07afcf5 |
---|---|
1 /* | |
2 ____ _____ _ _ | |
3 | __ )| ____| | / \ | |
4 | _ \| _| | | / _ \ | |
5 | |_) | |___| |___ / ___ \ | |
6 |____/|_____|_____/_/ \_\.io | |
7 | |
8 */ | |
9 | |
10 /** | |
11 \example 1_empty_project | |
12 | |
13 The bare bones | |
14 ---------------------- | |
15 | |
16 The structure of a render.cpp file | |
17 ---------------------------------- | |
18 A render.cpp file has three functions: `setup()`, `render()` and `cleanup()`. | |
19 | |
20 `setup()` is an initialisation function which runs before audio rendering begins. | |
21 It is called once when the project starts. Use it to prepare any memory or | |
22 resources that will be needed in `render()`. | |
23 | |
24 `render()` is a function that is regularly called, over and over continuously, at | |
25 the highest priority by the audio engine. It is used to process audio and | |
26 sensor data. This function is called regularly by the system every time there | |
27 is a new block of audio and/or sensor data to process. | |
28 | |
29 `cleanup()` is a function that is called when the program stops, to finish up any | |
30 processes that might still be running. | |
31 | |
32 Here we will briefly explain each function and the structure of the render.cpp | |
33 | |
34 Before any of the functions | |
35 --------------------------- | |
36 At the top of the file, include any libraries you might need. | |
37 | |
38 Additionally, declare any global variables. In these tutorial sketches, all | |
39 global variables are preceded by a `g` so we always know which variables are | |
40 global - `gSampleData`, for example. It's not mandatory but is a really good way | |
41 of keeping track of what's global and what's not. | |
42 | |
43 Sometimes it's necessary to access a variable from another file, such as | |
44 main.cpp. In this case, precede this variable with the keyword `extern`. | |
45 | |
46 Function arguments | |
47 ------------------ | |
48 `setup()`, `render()` and `cleanup()` each take the same arguments. These are: | |
49 | |
50 `0ext *context` | |
51 `void *userData` | |
52 | |
53 These arguments are pointers to data structures. The main one that's used is | |
54 `context`, which is a pointer to a data structure containing lots of information | |
55 you need. | |
56 | |
57 Take a look at what's in the data structure [here] | |
58 (https://code.soundsoftware.ac.uk/projects/beaglert/embedded/structBeagleRTContext.html). | |
59 | |
60 You can access any of these bits of information about current audio and sensor | |
61 settings and pointers to data buffers that are contained in the data structure | |
62 like this: `context->name_of_item`. | |
63 | |
64 For example, `context->audioChannels` returns the number of audio channels. | |
65 `context->audioSampleRate` returns the audio sample rate. | |
66 `context->audioIn[n]` would give you the current input sample (assuming that | |
67 your input is mono - if it's not you will have to account for multiple channels). | |
68 | |
69 Note that `audioIn`, `audioOut`, `analogIn`, `analogOut` are all arrays (buffers). | |
70 | |
71 */ | |
72 | |
73 | |
74 | |
75 | |
76 #include <BeagleRT.h> | |
77 #include <Utilities.h> | |
78 #include <rtdk.h> | |
79 #include <cmath> | |
80 | |
81 // setup() is called once before the audio rendering starts. | |
82 // Use it to perform any initialisation and allocation which is dependent | |
83 // on the period size or sample rate. | |
84 // | |
85 // userData holds an opaque pointer to a data structure that was passed | |
86 // in from the call to initAudio(). | |
87 // | |
88 // Return true on success; returning false halts the program. | |
89 | |
90 bool setup(BeagleRTContext *context, void *userData) | |
91 { | |
92 | |
93 return true; | |
94 } | |
95 | |
96 // render() is called regularly at the highest priority by the audio engine. | |
97 // Input and output are given from the audio hardware and the other | |
98 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | |
99 // will be 0. | |
100 | |
101 void render(BeagleRTContext *context, void *userData) | |
102 { | |
103 | |
104 } | |
105 | |
106 // cleanup() is called once at the end, after the audio has stopped. | |
107 // Release any resources that were allocated in setup(). | |
108 | |
109 void cleanup(BeagleRTContext *context, void *userData) | |
110 { | |
111 | |
112 } |