comparison projects/basic_passthru/render.cpp @ 285:5433c83ce04e Doxy prerelease

Doxygen content added to more project render.cpp files and amended in others.
author Robert Jack <robert.h.jack@gmail.com>
date Tue, 17 May 2016 18:46:55 +0100
parents ac8eb07afcf5
children
comparison
equal deleted inserted replaced
284:7bfb25a2e158 285:5433c83ce04e
13 * Created on: Oct 24, 2014 13 * Created on: Oct 24, 2014
14 * Author: parallels 14 * Author: parallels
15 */ 15 */
16 16
17 /** 17 /**
18 \example 1_basic_audio_passthrough 18 \example 1_basic_audio_analog_passthrough
19 19
20 Audio passthrough: input to output 20 Audio and analog passthrough: input to output
21 ----------------------------------------- 21 -----------------------------------------
22 22
23 This sketch demonstrates the simplest possible case of using audio: it passes 23 This sketch demonstrates how to read from and write to the audio and analog input and output buffers.
24 audio input straight to audio output.
25 24
26 Note the nested `for` loop structure. You will see this in all Bela projects. The 25 In `render()` you'll see a nested for loop structure. You'll see this in all Bela projects.
27 first `for` loop cycles through the audio frames, the second through each of the 26 The first for loop cycles through `audioFrames`, the second through
28 audio channels (in this case left 0 and right 1). 27 `audioChannels` (in this case left 0 and right 1).
28
29 You can access any information about current audio and sensor settings you can do the following:
30 `context->name_of_item`. For example `context->audioChannels` returns current number of channels,
31 `context->audioFrames` returns the current number of audio frames,
32 `context->audioSampleRate` returns the audio sample rate.
33
34 You can look at all the information you can access in ::BeagleRTContext.
35
36 Reading and writing from the audio buffers
37 ------------------------------------------
38
39 The simplest way to read samples from the audio input buffer is with
40 `audioReadFrame()` which we pass three arguments context, current audio
41 frame and current channel. In this example we have
42 `audioReadFrame(context, n, ch)` where both `n` and `ch` are provided by
43 the nested for loop structure.
44
45 We can write samples to the audio output buffer in a similar way using
46 `audioWriteFrame()`. This has a fourth argument which is the value of the output.
47 For example `audioWriteFrame(context, n, ch, value_to_output)`.
48
49 Reading and writing from the analog buffers
50 -------------------------------------------
51
52 The same is true for `analogReadFrame()` and `analogWriteFrame()`.
53
54 Note that for the analog channels we write to and read from the buffers in a separate set
55 of nested for loops. This is because the they are sampled at half audio rate by default.
56 The first of these for loops cycles through `analogFrames`, the second through
57 `analogChannels`.
58
59 By setting `audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch))` and
60 `analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch))` we have a simple
61 passthrough of audio input to output and analog input to output.
29 62
30 63
31 We write samples to the audio output buffer like this: 64 It is also possible to address the buffers directly like this:
32 `context->audioOut[n * context->audioChannels + ch]` where `n` is the current audio 65 `context->audioOut[n * context->audioChannels + ch]`.
33 frame and `ch` is the current channel, both provided by the nested for loop structure.
34
35 We can access samples in the audio input buffer in a similar way, like this:
36 `context->audioIn[n * context->audioChannels + ch]`.
37
38 So a simple audio pass through is achieved by setting output buffer equal to
39 input buffer:
40 `context->audioOut[n * context->audioChannels + ch] = context->audioIn[n * context->audioChannels + ch]`.
41 66
42 67
43 */ 68 */
44 69
45 70
84 // Or using the macros: 109 // Or using the macros:
85 audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch)); 110 audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch));
86 } 111 }
87 } 112 }
88 113
89 // Same with analog channelss 114 // Same with analog channels
90 for(unsigned int n = 0; n < context->analogFrames; n++) { 115 for(unsigned int n = 0; n < context->analogFrames; n++) {
91 for(unsigned int ch = 0; ch < context->analogChannels; ch++) { 116 for(unsigned int ch = 0; ch < context->analogChannels; ch++) {
92 // Two equivalent ways to write this code 117 // Two equivalent ways to write this code
93 118
94 // The long way, using the buffers directly: 119 // The long way, using the buffers directly: