comparison projects/basic_passthru/render.cpp @ 180:07cfd337ad18

Updated examples with new audioWrite macros
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 02 Jan 2016 13:55:01 +0100
parents 1e629f126322
children ac8eb07afcf5
comparison
equal deleted inserted replaced
179:f1012082f142 180:07cfd337ad18
17 // userData holds an opaque pointer to a data structure that was passed 17 // userData holds an opaque pointer to a data structure that was passed
18 // in from the call to initAudio(). 18 // in from the call to initAudio().
19 // 19 //
20 // Return true on success; returning false halts the program. 20 // Return true on success; returning false halts the program.
21 21
22 AuxiliaryTask taskOne;
23 AuxiliaryTask taskTwo;
24 void funOne(){
25 rt_printf("setup\n");
26 }
27 void funTwo(){
28 rt_printf("render\n");
29 }
30 bool setup(BeagleRTContext *context, void *userData) 22 bool setup(BeagleRTContext *context, void *userData)
31 { 23 {
32 // Nothing to do here... 24 // Nothing to do here...
33 // taskOne = BeagleRT_createAuxiliaryTask(funOne, 1, "funOne");
34 // taskTwo = BeagleRT_createAuxiliaryTask(funTwo, 99, "funTwo");
35 // BeagleRT_scheduleAuxiliaryTask(taskOne);
36 return true; 25 return true;
37 } 26 }
38 27
39 // render() is called regularly at the highest priority by the audio engine. 28 // render() is called regularly at the highest priority by the audio engine.
40 // Input and output are given from the audio hardware and the other 29 // Input and output are given from the audio hardware and the other
41 // ADCs and DACs (if available). If only audio is available, numMatrixFrames 30 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
42 // will be 0. 31 // will be 0.
43 32
44 void render(BeagleRTContext *context, void *userData) 33 void render(BeagleRTContext *context, void *userData)
45 { 34 {
46 // if(context->audioSampleCount % 16384 == 0)
47 // BeagleRT_scheduleAuxiliaryTask(taskTwo);
48 // Simplest possible case: pass inputs through to outputs 35 // Simplest possible case: pass inputs through to outputs
49 for(unsigned int n = 0; n < context->audioFrames; n++) { 36 for(unsigned int n = 0; n < context->audioFrames; n++) {
50 for(unsigned int ch = 0; ch < context->audioChannels; ch++) 37 for(unsigned int ch = 0; ch < context->audioChannels; ch++){
51 context->audioOut[n * context->audioChannels + ch] = 38 // Two equivalent ways to write this code
52 context->audioIn[n * context->audioChannels + ch]; 39
40 // The long way, using the buffers directly:
41 // context->audioOut[n * context->audioChannels + ch] =
42 // context->audioIn[n * context->audioChannels + ch];
43
44 // Or using the macros:
45 audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch));
46 }
53 } 47 }
54 48
55 // Same with matrix, only if matrix is enabled 49 // Same with analog channelss
56 // if(context->analogFrames != 0) { 50 for(unsigned int n = 0; n < context->analogFrames; n++) {
57 // for(unsigned int n = 0; n < context->analogFrames; n++) { 51 for(unsigned int ch = 0; ch < context->analogChannels; ch++) {
58 // for(unsigned int ch = 0; ch < context->analogChannels; ch++) { 52 // Two equivalent ways to write this code
59 // // Two equivalent ways to write this code 53
60 // // The long way, using the buffers directly: 54 // The long way, using the buffers directly:
61 // // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch]; 55 // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch];
62 // 56
63 // // Or using the macros: 57 // Or using the macros:
64 // analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch)); 58 analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch));
65 // } 59 }
66 // } 60 }
67 // }
68 } 61 }
69 62
70 // cleanup() is called once at the end, after the audio has stopped. 63 // cleanup() is called once at the end, after the audio has stopped.
71 // Release any resources that were allocated in setup(). 64 // Release any resources that were allocated in setup().
72 65