Tutorial Sketches - Explanations » History » Version 5

Astrid Bin, 2015-07-17 02:43 PM

1 1 Astrid Bin
h1.  Tutorial Sketches - Explanations 
2 1 Astrid Bin
3 2 Astrid Bin
Find the tutorial sketches in Respository > Projects, or click this link: https://code.soundsoftware.ac.uk/projects/beaglert/repository/show/projects
4 1 Astrid Bin
5 1 Astrid Bin
Below is a list of the sample sketches, and what they do.
6 1 Astrid Bin
7 3 Astrid Bin
h2. Basic sketch structure
8 3 Astrid Bin
9 3 Astrid Bin
A collection of BeagleRT files are called a "project".
10 3 Astrid Bin
11 3 Astrid Bin
h3. The structure of a BeagleRT project
12 3 Astrid Bin
13 3 Astrid Bin
If you open a project folder in the above repository, you'll see that each of these BeagleRT project contains two files: main.cpp and render.cpp (some projects have additional files, but every project has at least these two). The main.cpp file you don't really have to worry about; it contains helper functions and things that run command line arguments. Most work is done in the render.cpp file.
14 3 Astrid Bin
15 3 Astrid Bin
h3. The structure of a render.cpp file
16 3 Astrid Bin
17 3 Astrid Bin
A render.cpp file has three functions: setup(), render() and cleanup().
18 3 Astrid Bin
19 3 Astrid Bin
setup() is a function that runs at the beginning when the project starts. 
20 3 Astrid Bin
21 3 Astrid Bin
render() is a function that is regularly called, over and over continuously, at the highest priority by the audio engine. 
22 3 Astrid Bin
23 3 Astrid Bin
cleanup() is a function that is called when the program stops, to finish up any processes that might still be running.
24 3 Astrid Bin
25 3 Astrid Bin
Here we will briefly explain each function and the structure of the render.cpp document
26 3 Astrid Bin
27 3 Astrid Bin
h3. Before any functions
28 3 Astrid Bin
29 3 Astrid Bin
At the top of the file, include any libraries you might need.
30 3 Astrid Bin
31 3 Astrid Bin
Additionally, declare any global variables. In these tutorial sketches, all global variables are preceded by a g so we always know which variables are global - gSampleData, for instance. It's not mandatory but is a really good way of keeping track of what's global and what isn't.
32 3 Astrid Bin
33 3 Astrid Bin
Sometimes it's necessary to access a variable from another file, such as main.cpp. In this case, precede this variable with the keyword extern.
34 3 Astrid Bin
35 3 Astrid Bin
h3. Function arguments
36 3 Astrid Bin
37 3 Astrid Bin
setup(), render() and cleanup() each take the same arguments. These are:
38 3 Astrid Bin
39 3 Astrid Bin
BeagleRTContext *context
40 3 Astrid Bin
void *userData
41 3 Astrid Bin
42 3 Astrid Bin
These arguments are pointers to data structures. The main one that's used is context, which is a pointer to a data structure containing lots of information you need. 
43 3 Astrid Bin
44 3 Astrid Bin
Take a look at what's in the data structure here: https://code.soundsoftware.ac.uk/projects/beaglert/embedded/structBeagleRTContext.html In that link there is also a 
45 3 Astrid Bin
46 3 Astrid Bin
You can access any of those bits of information contained in the data structure like this: context->[item in struct] 
47 3 Astrid Bin
48 3 Astrid Bin
For example, context->audioChannels returns the number of audioChannels. context->audioIn[n] would give you the current input sample (assuming that your input is mono - if it's not you will have to account for multiple channels). 
49 3 Astrid Bin
50 4 Astrid Bin
Note that every audioIn, audioOut, analogIn, analogOut and digital are buffers.
51 3 Astrid Bin
52 1 Astrid Bin
h2. analogDigitalDemo
53 1 Astrid Bin
54 1 Astrid Bin
h2. audio_in_FFT
55 1 Astrid Bin
56 5 Astrid Bin
This sketch performs an FFT (Fast Fourier Transform) on incoming audio. It uses the NE10 library, included at the top of the file (line 11).
57 5 Astrid Bin
58 5 Astrid Bin
Read the documentation on the NE10 library here: http://projectne10.github.io/Ne10/doc/annotated.html
59 5 Astrid Bin
60 5 Astrid Bin
The variables timeDomainIn, timeDomainOut and frequencyDomain are variables of the struct <a href="ne10_fft_cpx_float32_t">ne10_fft_cpx_float32_t</a>
61 5 Astrid Bin
62 1 Astrid Bin
h2. basic
63 1 Astrid Bin
64 1 Astrid Bin
h2. basic_analog_input
65 1 Astrid Bin
66 1 Astrid Bin
h2. basic_analog_output
67 1 Astrid Bin
68 1 Astrid Bin
h2. basic_network
69 1 Astrid Bin
70 1 Astrid Bin
h2. basic_passthru
71 1 Astrid Bin
72 1 Astrid Bin
h2. cape_test
73 1 Astrid Bin
74 1 Astrid Bin
h2. d-box
75 1 Astrid Bin
76 1 Astrid Bin
h2. filter_FIR
77 1 Astrid Bin
78 1 Astrid Bin
h2. filter_IIR
79 1 Astrid Bin
80 1 Astrid Bin
h2. oscillator_bank\
81 1 Astrid Bin
82 1 Astrid Bin
h2. samples
83 1 Astrid Bin
84 1 Astrid Bin
h2. tank_wars