Mercurial > hg > beaglert
comparison examples/01-Basics/passthrough/render.cpp @ 543:8f8809c77dda prerelease
updated basics, digital, instruments, extras examples
author | chnrx <chris.heinrichs@gmail.com> |
---|---|
date | Fri, 24 Jun 2016 13:19:52 +0100 |
parents | bfcbeb437869 |
children |
comparison
equal
deleted
inserted
replaced
542:3016638b4da2 | 543:8f8809c77dda |
---|---|
23 | 23 |
24 #include <Bela.h> | 24 #include <Bela.h> |
25 | 25 |
26 bool setup(BelaContext *context, void *userData) | 26 bool setup(BelaContext *context, void *userData) |
27 { | 27 { |
28 // Nothing to do here... | 28 // For this example we need the same amount of audio and analog input and output channels |
29 if(context->audioInChannels != context->audioOutChannels || | 29 if(context->audioInChannels != context->audioOutChannels || |
30 context->analogInChannels != context-> analogOutChannels){ | 30 context->analogInChannels != context-> analogOutChannels){ |
31 printf("Error: for this project, you need the same number of input and output channels.\n"); | 31 printf("Error: for this project, you need the same number of input and output channels.\n"); |
32 return false; | 32 return false; |
33 } | 33 } |
80 | 80 |
81 This sketch demonstrates how to read from and write to the audio and analog input and output buffers. | 81 This sketch demonstrates how to read from and write to the audio and analog input and output buffers. |
82 | 82 |
83 In `render()` you'll see a nested for loop structure. You'll see this in all Bela projects. | 83 In `render()` you'll see a nested for loop structure. You'll see this in all Bela projects. |
84 The first for loop cycles through `audioFrames`, the second through | 84 The first for loop cycles through `audioFrames`, the second through |
85 `audioChannels` (in this case left 0 and right 1). | 85 `audioInChannels` (in this case left 0 and right 1). |
86 | 86 |
87 You can access any information about current audio and sensor settings you can do the following: | 87 You can access any information about current audio and sensor settings you can do the following: |
88 `context->name_of_item`. For example `context->audioChannels` returns current number of channels, | 88 `context->name_of_item`. For example `context->audioInChannels` returns current number of input channels, |
89 `context->audioFrames` returns the current number of audio frames, | 89 `context->audioFrames` returns the current number of audio frames, |
90 `context->audioSampleRate` returns the audio sample rate. | 90 `context->audioSampleRate` returns the audio sample rate. |
91 | 91 |
92 You can look at all the information you can access in ::BelaContext. | 92 You can look at all the information you can access in ::BelaContext. |
93 | 93 |
110 The same is true for `analogRead()` and `analogWrite()`. | 110 The same is true for `analogRead()` and `analogWrite()`. |
111 | 111 |
112 Note that for the analog channels we write to and read from the buffers in a separate set | 112 Note that for the analog channels we write to and read from the buffers in a separate set |
113 of nested for loops. This is because the they are sampled at half audio rate by default. | 113 of nested for loops. This is because the they are sampled at half audio rate by default. |
114 The first of these for loops cycles through `analogFrames`, the second through | 114 The first of these for loops cycles through `analogFrames`, the second through |
115 `analogChannels`. | 115 `analogInChannels`. |
116 | 116 |
117 By setting `audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch))` and | 117 By setting `audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch))` and |
118 `analogWrite(context, n, ch, analogReadFrame(context, n, ch))` we have a simple | 118 `analogWrite(context, n, ch, analogReadFrame(context, n, ch))` we have a simple |
119 passthrough of audio input to output and analog input to output. | 119 passthrough of audio input to output and analog input to output. |
120 | 120 |
121 | 121 |
122 It is also possible to address the buffers directly, for example: | 122 It is also possible to address the buffers directly, for example: |
123 `context->audioOut[n * context->audioChannels + ch]`. | 123 `context->audioOut[n * context->audioOutChannels + ch]`. |
124 */ | 124 */ |