andrewm@13
|
1 /*
|
andrewm@13
|
2 * render.cpp
|
andrewm@13
|
3 *
|
andrewm@13
|
4 * Created on: Oct 24, 2014
|
andrewm@13
|
5 * Author: parallels
|
andrewm@13
|
6 */
|
andrewm@13
|
7
|
andrewm@13
|
8
|
giuliomoro@301
|
9 #include <Bela.h>
|
andrewm@56
|
10 #include <Utilities.h>
|
andrewm@13
|
11 #include <rtdk.h>
|
andrewm@13
|
12
|
andrewm@56
|
13 // setup() is called once before the audio rendering starts.
|
andrewm@13
|
14 // Use it to perform any initialisation and allocation which is dependent
|
andrewm@13
|
15 // on the period size or sample rate.
|
andrewm@13
|
16 //
|
andrewm@13
|
17 // userData holds an opaque pointer to a data structure that was passed
|
andrewm@13
|
18 // in from the call to initAudio().
|
andrewm@13
|
19 //
|
andrewm@13
|
20 // Return true on success; returning false halts the program.
|
andrewm@13
|
21
|
giuliomoro@301
|
22 bool setup(BelaContext *context, void *userData)
|
andrewm@13
|
23 {
|
andrewm@13
|
24 // Nothing to do here...
|
andrewm@13
|
25 return true;
|
andrewm@13
|
26 }
|
andrewm@13
|
27
|
andrewm@13
|
28 // render() is called regularly at the highest priority by the audio engine.
|
andrewm@13
|
29 // Input and output are given from the audio hardware and the other
|
andrewm@13
|
30 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
|
andrewm@13
|
31 // will be 0.
|
andrewm@13
|
32
|
giuliomoro@301
|
33 void render(BelaContext *context, void *userData)
|
andrewm@13
|
34 {
|
andrewm@13
|
35 // Simplest possible case: pass inputs through to outputs
|
andrewm@52
|
36 for(unsigned int n = 0; n < context->audioFrames; n++) {
|
giuliomoro@180
|
37 for(unsigned int ch = 0; ch < context->audioChannels; ch++){
|
giuliomoro@180
|
38 // Two equivalent ways to write this code
|
giuliomoro@180
|
39
|
giuliomoro@180
|
40 // The long way, using the buffers directly:
|
giuliomoro@180
|
41 // context->audioOut[n * context->audioChannels + ch] =
|
giuliomoro@180
|
42 // context->audioIn[n * context->audioChannels + ch];
|
giuliomoro@180
|
43
|
giuliomoro@180
|
44 // Or using the macros:
|
giuliomoro@180
|
45 audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch));
|
giuliomoro@180
|
46 }
|
andrewm@13
|
47 }
|
andrewm@13
|
48
|
giuliomoro@180
|
49 // Same with analog channelss
|
giuliomoro@180
|
50 for(unsigned int n = 0; n < context->analogFrames; n++) {
|
giuliomoro@180
|
51 for(unsigned int ch = 0; ch < context->analogChannels; ch++) {
|
giuliomoro@180
|
52 // Two equivalent ways to write this code
|
giuliomoro@180
|
53
|
giuliomoro@180
|
54 // The long way, using the buffers directly:
|
giuliomoro@180
|
55 // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch];
|
giuliomoro@180
|
56
|
giuliomoro@180
|
57 // Or using the macros:
|
giuliomoro@180
|
58 analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch));
|
giuliomoro@180
|
59 }
|
giuliomoro@180
|
60 }
|
andrewm@13
|
61 }
|
andrewm@13
|
62
|
andrewm@56
|
63 // cleanup() is called once at the end, after the audio has stopped.
|
andrewm@56
|
64 // Release any resources that were allocated in setup().
|
andrewm@13
|
65
|
giuliomoro@301
|
66 void cleanup(BelaContext *context, void *userData)
|
andrewm@13
|
67 {
|
andrewm@13
|
68
|
andrewm@13
|
69 }
|