annotate projects/empty_project/render.cpp @ 316:18996c7dfac1

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