robert@464: /* robert@464: ____ _____ _ _ robert@464: | __ )| ____| | / \ robert@464: | _ \| _| | | / _ \ robert@464: | |_) | |___| |___ / ___ \ robert@464: |____/|_____|_____/_/ \_\ robert@464: robert@464: The platform for ultra-low latency audio and sensor processing robert@464: robert@464: http://bela.io robert@464: robert@464: A project of the Augmented Instruments Laboratory within the robert@464: Centre for Digital Music at Queen Mary University of London. robert@464: http://www.eecs.qmul.ac.uk/~andrewm robert@464: robert@464: (c) 2016 Augmented Instruments Laboratory: Andrew McPherson, robert@464: Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack, robert@464: Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved. robert@464: robert@464: The Bela software is distributed under the GNU Lesser General Public License robert@464: (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt robert@464: */ robert@464: robert@464: #include robert@464: robert@464: robert@464: // setup() is called once before the audio rendering starts. robert@464: // Use it to perform any initialisation and allocation which is dependent robert@464: // on the period size or sample rate. robert@464: // robert@464: // userData holds an opaque pointer to a data structure that was passed robert@464: // in from the call to initAudio(). robert@464: // robert@464: // Return true on success; returning false halts the program. robert@464: bool setup(BelaContext *context, void *userData) robert@464: { robert@464: return true; robert@464: } robert@464: robert@464: // render() is called regularly at the highest priority by the audio engine. robert@464: // Input and output are given from the audio hardware and the other robert@464: // ADCs and DACs (if available). If only audio is available, numMatrixFrames robert@464: // will be 0. robert@464: void render(BelaContext *context, void *userData) robert@464: { robert@464: robert@464: } robert@464: robert@464: // cleanup() is called once at the end, after the audio has stopped. robert@464: // Release any resources that were allocated in setup(). robert@464: void cleanup(BelaContext *context, void *userData) robert@464: { robert@464: robert@464: } robert@464: robert@464: /* ------------ Project Explantation ------------ */ robert@464: robert@464: /** robert@464: robert@464: \example 01-minimal robert@464: robert@464: The bare bones robert@464: ---------------------- robert@464: robert@464: The structure of a render.cpp file robert@464: ---------------------------------- robert@464: A render.cpp file has three functions: `setup()`, `render()` and `cleanup()`. robert@464: robert@464: `setup()` is an initialisation function which runs before audio rendering begins. robert@464: It is called once when the project starts. Use it to prepare any memory or robert@464: resources that will be needed in `render()`. robert@464: robert@464: `render()` is a function that is regularly called, over and over continuously, at robert@464: the highest priority by the audio engine. It is used to process audio and robert@464: sensor data. This function is called regularly by the system every time there robert@464: is a new block of audio and/or sensor data to process. robert@464: robert@464: `cleanup()` is a function that is called when the program stops, to finish up any robert@464: processes that might still be running. robert@464: robert@464: Here we will briefly explain each function and the structure of the render.cpp robert@464: robert@464: Before any of the functions robert@464: --------------------------- robert@464: At the top of the file, include any libraries you might need. robert@464: robert@464: Additionally, declare any global variables. In these tutorial sketches, all robert@464: global variables are preceded by a `g` so we always know which variables are robert@464: global - `gSampleData`, for example. It's not mandatory but is a really good way robert@464: of keeping track of what's global and what's not. robert@464: robert@464: Sometimes it's necessary to access a variable from another file, such as robert@464: main.cpp. In this case, precede this variable with the keyword `extern`. robert@464: robert@464: Function arguments robert@464: ------------------ robert@464: `setup()`, `render()` and `cleanup()` each take the same arguments. These are: robert@464: robert@464: `0ext *context` robert@464: `void *userData` robert@464: robert@464: These arguments are pointers to data structures. The main one that's used is robert@464: `context`, which is a pointer to a data structure containing lots of information robert@464: you need. robert@464: robert@464: Take a look at what's in the data structure [here] robert@464: (https://code.soundsoftware.ac.uk/projects/beaglert/embedded/structBeagleRTContext.html). robert@464: robert@464: You can access any of these bits of information about current audio and sensor robert@464: settings and pointers to data buffers that are contained in the data structure robert@464: like this: `context->name_of_item`. robert@464: robert@464: For example, `context->audioChannels` returns the number of audio channels. robert@464: `context->audioSampleRate` returns the audio sample rate. robert@464: `context->audioIn[n]` would give you the current input sample (assuming that robert@464: your input is mono - if it's not you will have to account for multiple channels). robert@464: robert@464: Note that `audioIn`, `audioOut`, `analogIn`, `analogOut` are all arrays (buffers). robert@464: robert@464: */