Tutorial Sketches - Explanations » History » Version 3
Version 2 (Astrid Bin, 2015-07-17 01:44 PM) → Version 3/45 (Astrid Bin, 2015-07-17 02:20 PM)
h1. Tutorial Sketches - Explanations
Find the tutorial sketches in Respository > Projects, or click this link: https://code.soundsoftware.ac.uk/projects/beaglert/repository/show/projects
Below is a list of the sample sketches, and what they do.
h2. Basic sketch structure
A collection of BeagleRT files are called a "project".
h3. The structure of a BeagleRT project
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.
h3. The structure of a render.cpp file
A render.cpp file has three functions: setup(), render() and cleanup().
setup() is a function that runs at the beginning when the project starts.
render() is a function that is regularly called, over and over continuously, at the highest priority by the audio engine.
cleanup() is a function that is called when the program stops, to finish up any processes that might still be running.
Here we will briefly explain each function and the structure of the render.cpp document
h3. Before any functions
At the top of the file, include any libraries you might need.
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.
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.
h3. Function arguments
setup(), render() and cleanup() each take the same arguments. These are:
BeagleRTContext *context
void *userData
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.
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
You can access any of those bits of information contained in the data structure like this: context->[item in struct]
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).
Note that every audioIn, audioOut, analogIn, analogOut and digital are all buffers.
h2. analogDigitalDemo
h2. audio_in_FFT
h2. basic
h2. basic_analog_input
h2. basic_analog_output
h2. basic_network
h2. basic_passthru
h2. cape_test
h2. d-box
h2. filter_FIR
h2. filter_IIR
h2. oscillator_bank\
h2. samples
h2. tank_wars
Find the tutorial sketches in Respository > Projects, or click this link: https://code.soundsoftware.ac.uk/projects/beaglert/repository/show/projects
Below is a list of the sample sketches, and what they do.
h2. Basic sketch structure
A collection of BeagleRT files are called a "project".
h3. The structure of a BeagleRT project
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.
h3. The structure of a render.cpp file
A render.cpp file has three functions: setup(), render() and cleanup().
setup() is a function that runs at the beginning when the project starts.
render() is a function that is regularly called, over and over continuously, at the highest priority by the audio engine.
cleanup() is a function that is called when the program stops, to finish up any processes that might still be running.
Here we will briefly explain each function and the structure of the render.cpp document
h3. Before any functions
At the top of the file, include any libraries you might need.
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.
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.
h3. Function arguments
setup(), render() and cleanup() each take the same arguments. These are:
BeagleRTContext *context
void *userData
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.
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
You can access any of those bits of information contained in the data structure like this: context->[item in struct]
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).
Note that every audioIn, audioOut, analogIn, analogOut and digital are all buffers.
h2. analogDigitalDemo
h2. audio_in_FFT
h2. basic
h2. basic_analog_input
h2. basic_analog_output
h2. basic_network
h2. basic_passthru
h2. cape_test
h2. d-box
h2. filter_FIR
h2. filter_IIR
h2. oscillator_bank\
h2. samples
h2. tank_wars