Mercurial > hg > beaglert
comparison examples/01-Basics/passthrough/render.cpp @ 528:5c8f46fcd4d0 API-update
Updated BelaContext to use separate values for in/ou channels
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Thu, 23 Jun 2016 18:17:35 +0100 |
parents | 1cec96845a23 |
children | bfcbeb437869 |
comparison
equal
deleted
inserted
replaced
527:1c68ad13bbe4 | 528:5c8f46fcd4d0 |
---|---|
20 The Bela software is distributed under the GNU Lesser General Public License | 20 The Bela software is distributed under the GNU Lesser General Public License |
21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt | 21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt |
22 */ | 22 */ |
23 | 23 |
24 #include <Bela.h> | 24 #include <Bela.h> |
25 #include <rtdk.h> | 25 #include <Scope.h> |
26 | |
27 Scope scope; | |
26 | 28 |
27 bool setup(BelaContext *context, void *userData) | 29 bool setup(BelaContext *context, void *userData) |
28 { | 30 { |
29 // Nothing to do here... | 31 // Nothing to do here... |
32 printf("%d %d\n", context->audioInChannels, context->audioOutChannels); | |
33 scope.setup(8, 44100); | |
30 return true; | 34 return true; |
31 } | 35 } |
32 | 36 |
33 void render(BelaContext *context, void *userData) | 37 void render(BelaContext *context, void *userData) |
34 { | 38 { |
39 static const unsigned int audioChannels = min(context->audioInChannels, context->audioOutChannels); | |
40 static const unsigned int analogChannels = min(context->analogInChannels, context->analogOutChannels); | |
41 | |
35 // Simplest possible case: pass inputs through to outputs | 42 // Simplest possible case: pass inputs through to outputs |
36 for(unsigned int n = 0; n < context->audioFrames; n++) { | 43 for(unsigned int n = 0; n < context->audioFrames; n++) { |
37 for(unsigned int ch = 0; ch < context->audioChannels; ch++){ | 44 for(unsigned int ch = 0; ch < audioChannels; ch++){ |
38 // Two equivalent ways to write this code | 45 // Two equivalent ways to write this code |
39 | 46 |
40 // The long way, using the buffers directly: | 47 // The long way, using the buffers directly: |
41 // context->audioOut[n * context->audioChannels + ch] = | 48 // context->audioOut[n * context->audioOutChannels + ch] = |
42 // context->audioIn[n * context->audioChannels + ch]; | 49 // context->audioIn[n * context->audioInChannels + ch]; |
43 | 50 |
44 // Or using the macros: | 51 // Or using the macros: |
45 audioWrite(context, n, ch, audioRead(context, n, ch)); | 52 audioWrite(context, n, ch, audioRead(context, n, ch)); |
46 } | 53 } |
47 } | 54 } |
48 | 55 |
49 // Same with analog channelss | 56 // Same with analog channels |
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 < analogChannels; ch++) { |
52 // Two equivalent ways to write this code | 59 // Two equivalent ways to write this code |
53 | 60 |
54 // The long way, using the buffers directly: | 61 // The long way, using the buffers directly: |
55 // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch]; | 62 // context->analogOut[n * context->analogOutChannels + ch] = |
63 // context->analogIn[n * context->analogInChannels + ch]; | |
56 | 64 |
57 // Or using the macros: | 65 // Or using the macros: |
58 analogWrite(context, n, ch, analogRead(context, n, ch)); | 66 analogWrite(context, n, ch, analogRead(context, n, ch)); |
59 } | 67 } |
60 } | 68 } |