diff 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
line wrap: on
line diff
--- a/examples/basic_passthru/render.cpp	Thu Jun 09 17:31:44 2016 +0100
+++ b/examples/basic_passthru/render.cpp	Thu Jun 09 18:16:05 2016 +0100
@@ -1,10 +1,69 @@
 /*
+ ____  _____ _        _    
+| __ )| ____| |      / \   
+|  _ \|  _| | |     / _ \  
+| |_) | |___| |___ / ___ \ 
+|____/|_____|_____/_/   \_\.io
+
+ */
+
+ /*
  * render.cpp
  *
  *  Created on: Oct 24, 2014
  *      Author: parallels
  */
 
+/**
+\example 1_basic_audio_analog_passthrough
+
+Audio and analog passthrough: input to output
+-----------------------------------------
+
+This sketch demonstrates how to read from and write to the audio and analog input and output buffers.
+
+In `render()` you'll see a nested for loop structure. You'll see this in all Bela projects. 
+The first for loop cycles through `audioFrames`, the second through 
+`audioChannels` (in this case left 0 and right 1).
+
+You can access any information about current audio and sensor settings you can do the following: 
+`context->name_of_item`. For example `context->audioChannels` returns current number of channels,
+`context->audioFrames` returns the current number of audio frames, 
+`context->audioSampleRate` returns the audio sample rate.
+
+You can look at all the information you can access in ::BeagleRTContext.
+
+Reading and writing from the audio buffers
+------------------------------------------
+
+The simplest way to read samples from the audio input buffer is with
+`audioRead()` which we pass three arguments: context, current audio 
+frame and current channel. In this example we have 
+`audioRead(context, n, ch)` where both `n` and `ch` are provided by 
+the nested for loop structure.
+
+We can write samples to the audio output buffer in a similar way using 
+`audioWrite()`. This has a fourth argument which is the value of the output.
+For example `audioWrite(context, n, ch, value_to_output)`.
+
+Reading and writing from the analog buffers
+-------------------------------------------
+
+The same is true for `analogRead()` and `analogWrite()`.
+
+Note that for the analog channels we write to and read from the buffers in a separate set 
+of nested for loops. This is because the they are sampled at half audio rate by default. 
+The first of these for loops cycles through `analogFrames`, the second through
+`analogChannels`.
+
+By setting `audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch))` and
+`analogWrite(context, n, ch, analogReadFrame(context, n, ch))` we have a simple 
+passthrough of audio input to output and analog input to output.
+
+
+It is also possible to address the buffers directly, for example: 
+`context->audioOut[n * context->audioChannels + ch]`.
+*/
 
 #include <Bela.h>
 #include <Utilities.h>