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
|
andrewm@56
|
9 #include <BeagleRT.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@174
|
22 AuxiliaryTask taskOne;
|
giuliomoro@174
|
23 AuxiliaryTask taskTwo;
|
giuliomoro@174
|
24 void funOne(){
|
giuliomoro@174
|
25 rt_printf("setup\n");
|
giuliomoro@174
|
26 }
|
giuliomoro@174
|
27 void funTwo(){
|
giuliomoro@174
|
28 rt_printf("render\n");
|
giuliomoro@174
|
29 }
|
andrewm@56
|
30 bool setup(BeagleRTContext *context, void *userData)
|
andrewm@13
|
31 {
|
andrewm@13
|
32 // Nothing to do here...
|
giuliomoro@174
|
33 // taskOne = BeagleRT_createAuxiliaryTask(funOne, 1, "funOne");
|
giuliomoro@174
|
34 // taskTwo = BeagleRT_createAuxiliaryTask(funTwo, 99, "funTwo");
|
giuliomoro@174
|
35 // BeagleRT_scheduleAuxiliaryTask(taskOne);
|
andrewm@13
|
36 return true;
|
andrewm@13
|
37 }
|
andrewm@13
|
38
|
andrewm@13
|
39 // render() is called regularly at the highest priority by the audio engine.
|
andrewm@13
|
40 // Input and output are given from the audio hardware and the other
|
andrewm@13
|
41 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
|
andrewm@13
|
42 // will be 0.
|
andrewm@13
|
43
|
andrewm@52
|
44 void render(BeagleRTContext *context, void *userData)
|
andrewm@13
|
45 {
|
giuliomoro@174
|
46 // if(context->audioSampleCount % 16384 == 0)
|
giuliomoro@174
|
47 // BeagleRT_scheduleAuxiliaryTask(taskTwo);
|
andrewm@13
|
48 // Simplest possible case: pass inputs through to outputs
|
andrewm@52
|
49 for(unsigned int n = 0; n < context->audioFrames; n++) {
|
andrewm@52
|
50 for(unsigned int ch = 0; ch < context->audioChannels; ch++)
|
giuliomoro@174
|
51 context->audioOut[n * context->audioChannels + ch] =
|
giuliomoro@174
|
52 context->audioIn[n * context->audioChannels + ch];
|
andrewm@13
|
53 }
|
andrewm@13
|
54
|
andrewm@13
|
55 // Same with matrix, only if matrix is enabled
|
giuliomoro@174
|
56 // if(context->analogFrames != 0) {
|
giuliomoro@174
|
57 // for(unsigned int n = 0; n < context->analogFrames; n++) {
|
giuliomoro@174
|
58 // for(unsigned int ch = 0; ch < context->analogChannels; ch++) {
|
giuliomoro@174
|
59 // // Two equivalent ways to write this code
|
giuliomoro@174
|
60 // // The long way, using the buffers directly:
|
giuliomoro@174
|
61 // // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch];
|
giuliomoro@174
|
62 //
|
giuliomoro@174
|
63 // // Or using the macros:
|
giuliomoro@174
|
64 // analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch));
|
giuliomoro@174
|
65 // }
|
giuliomoro@174
|
66 // }
|
giuliomoro@174
|
67 // }
|
andrewm@13
|
68 }
|
andrewm@13
|
69
|
andrewm@56
|
70 // cleanup() is called once at the end, after the audio has stopped.
|
andrewm@56
|
71 // Release any resources that were allocated in setup().
|
andrewm@13
|
72
|
andrewm@56
|
73 void cleanup(BeagleRTContext *context, void *userData)
|
andrewm@13
|
74 {
|
andrewm@13
|
75
|
andrewm@13
|
76 }
|