robert@269: /* robert@269: ____ _____ _ _ robert@269: | __ )| ____| | / \ robert@269: | _ \| _| | | / _ \ robert@269: | |_) | |___| |___ / ___ \ robert@269: |____/|_____|_____/_/ \_\.io robert@269: robert@269: */ robert@269: robert@269: /** robert@269: \example 1_empty_project robert@269: robert@269: The bare bones robert@269: ---------------------- robert@269: robert@269: The structure of a render.cpp file robert@269: ---------------------------------- robert@269: A render.cpp file has three functions: `setup()`, `render()` and `cleanup()`. robert@269: robert@269: `setup()` is an initialisation function which runs before audio rendering begins. robert@269: It is called once when the project starts. Use it to prepare any memory or robert@269: resources that will be needed in `render()`. robert@269: robert@269: `render()` is a function that is regularly called, over and over continuously, at robert@269: the highest priority by the audio engine. It is used to process audio and robert@269: sensor data. This function is called regularly by the system every time there robert@269: is a new block of audio and/or sensor data to process. robert@269: robert@269: `cleanup()` is a function that is called when the program stops, to finish up any robert@269: processes that might still be running. robert@269: robert@269: Here we will briefly explain each function and the structure of the render.cpp robert@269: robert@269: Before any of the functions robert@269: --------------------------- robert@269: At the top of the file, include any libraries you might need. robert@269: robert@269: Additionally, declare any global variables. In these tutorial sketches, all robert@269: global variables are preceded by a `g` so we always know which variables are robert@269: global - `gSampleData`, for example. It's not mandatory but is a really good way robert@269: of keeping track of what's global and what's not. robert@269: robert@269: Sometimes it's necessary to access a variable from another file, such as robert@269: main.cpp. In this case, precede this variable with the keyword `extern`. robert@269: robert@269: Function arguments robert@269: ------------------ robert@269: `setup()`, `render()` and `cleanup()` each take the same arguments. These are: robert@269: robert@269: `0ext *context` robert@269: `void *userData` robert@269: robert@269: These arguments are pointers to data structures. The main one that's used is robert@269: `context`, which is a pointer to a data structure containing lots of information robert@269: you need. robert@269: robert@269: Take a look at what's in the data structure [here] robert@269: (https://code.soundsoftware.ac.uk/projects/beaglert/embedded/structBeagleRTContext.html). robert@269: robert@269: You can access any of these bits of information about current audio and sensor robert@269: settings and pointers to data buffers that are contained in the data structure robert@269: like this: `context->name_of_item`. robert@269: robert@269: For example, `context->audioChannels` returns the number of audio channels. robert@269: `context->audioSampleRate` returns the audio sample rate. robert@269: `context->audioIn[n]` would give you the current input sample (assuming that robert@269: your input is mono - if it's not you will have to account for multiple channels). robert@269: robert@269: Note that `audioIn`, `audioOut`, `analogIn`, `analogOut` are all arrays (buffers). robert@269: robert@269: */ robert@269: robert@269: robert@269: robert@269: robert@269: #include robert@269: #include robert@269: #include robert@269: #include robert@269: robert@269: // setup() is called once before the audio rendering starts. robert@269: // Use it to perform any initialisation and allocation which is dependent robert@269: // on the period size or sample rate. robert@269: // robert@269: // userData holds an opaque pointer to a data structure that was passed robert@269: // in from the call to initAudio(). robert@269: // robert@269: // Return true on success; returning false halts the program. robert@269: robert@269: bool setup(BeagleRTContext *context, void *userData) robert@269: { robert@269: robert@269: return true; robert@269: } robert@269: robert@269: // render() is called regularly at the highest priority by the audio engine. robert@269: // Input and output are given from the audio hardware and the other robert@269: // ADCs and DACs (if available). If only audio is available, numMatrixFrames robert@269: // will be 0. robert@269: robert@269: void render(BeagleRTContext *context, void *userData) robert@269: { robert@269: robert@269: } robert@269: robert@269: // cleanup() is called once at the end, after the audio has stopped. robert@269: // Release any resources that were allocated in setup(). robert@269: robert@269: void cleanup(BeagleRTContext *context, void *userData) robert@269: { robert@269: robert@269: }