comparison examples/basic_passthru/render.cpp @ 372:db2fe4e1b88e prerelease

Doxygen content added to each example render.cpp. References to AnalogReadFrame etc. removed from doxygen content.
author Robert Jack <robert.h.jack@gmail.com>
date Thu, 09 Jun 2016 18:16:05 +0100
parents 1feb9c23ac57
children 9dc5a0ccad25
comparison
equal deleted inserted replaced
371:361d0c2335cf 372:db2fe4e1b88e
1 /* 1 /*
2 ____ _____ _ _
3 | __ )| ____| | / \
4 | _ \| _| | | / _ \
5 | |_) | |___| |___ / ___ \
6 |____/|_____|_____/_/ \_\.io
7
8 */
9
10 /*
2 * render.cpp 11 * render.cpp
3 * 12 *
4 * Created on: Oct 24, 2014 13 * Created on: Oct 24, 2014
5 * Author: parallels 14 * Author: parallels
6 */ 15 */
7 16
17 /**
18 \example 1_basic_audio_analog_passthrough
19
20 Audio and analog passthrough: input to output
21 -----------------------------------------
22
23 This sketch demonstrates how to read from and write to the audio and analog input and output buffers.
24
25 In `render()` you'll see a nested for loop structure. You'll see this in all Bela projects.
26 The first for loop cycles through `audioFrames`, the second through
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 `audioRead()` which we pass three arguments: context, current audio
41 frame and current channel. In this example we have
42 `audioRead(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 `audioWrite()`. This has a fourth argument which is the value of the output.
47 For example `audioWrite(context, n, ch, value_to_output)`.
48
49 Reading and writing from the analog buffers
50 -------------------------------------------
51
52 The same is true for `analogRead()` and `analogWrite()`.
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 `analogWrite(context, n, ch, analogReadFrame(context, n, ch))` we have a simple
61 passthrough of audio input to output and analog input to output.
62
63
64 It is also possible to address the buffers directly, for example:
65 `context->audioOut[n * context->audioChannels + ch]`.
66 */
8 67
9 #include <Bela.h> 68 #include <Bela.h>
10 #include <Utilities.h> 69 #include <Utilities.h>
11 #include <rtdk.h> 70 #include <rtdk.h>
12 71