Mercurial > hg > beaglert
changeset 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 | 7bfb25a2e158 |
children | 634c1d1f37bc |
files | projects/basic/render.cpp projects/basic_analog_input/render.cpp projects/basic_analog_output/render.cpp projects/basic_blink/render.cpp projects/basic_button/render.cpp projects/basic_passthru/render.cpp projects/filter_FIR/render.cpp projects/filter_IIR/render.cpp projects/osc/render.cpp projects/scope_analogue/render.cpp projects/scope_basic/render.cpp |
diffstat | 11 files changed, 206 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/projects/basic/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/basic/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -27,11 +27,9 @@ (line 12). The sine tone is produced by incrementing the phase of a sin function on every audio frame. -The important thing to notice is the nested `for` loop structure. You will see -this in all Bela projects and in most digital audio applications. The first `for` -loop cycles through the audio frames, the second through each of the audio -channels (in this case left 0 and right 1). It is good to familiarise yourself -with this structure as it is fundamental to producing sound with the system. +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). +It is good to familiarise yourself with this structure as it is fundamental to producing sound with the system. */
--- a/projects/basic_analog_input/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/basic_analog_input/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -26,6 +26,10 @@ (line 55); we adjust these values by taking in data from analog sensors (for example, a potentiometer). +- connect a 10K pot to 3.3V and GND on its 1st and 3rd pins. +- connect the 2nd middle pin of the pot to analogIn 0. +- connect another 10K pot in the same way but with the middle pin connected to analogIn 1. + The important thing to notice is that audio is sampled twice as often as analog data. The audio sampling rate is 44.1kHz (44100 frames per second) and the analog sampling rate is 22.05kHz (22050 frames per second). On line 62 you might
--- a/projects/basic_analog_output/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/basic_analog_output/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -23,13 +23,15 @@ connected to the eight analog out pins. Again you can see the nested `for` loop structure but this time for the analog output channels rather than the audio. -Within the first `for` loop in render we cycle through each frame in the analog +- connect an LED in series with a 470ohm resistor between each of the analogOut pins and ground. + +Within the first for loop in render we cycle through each frame in the analog output matrix. At each frame we then cycle through the analog output channels -with another `for` loop and set the output voltage according to the phase of a +with another for loop and set the output voltage according to the phase of a sine tone that acts as an LFO. The analog output pins can provide a voltage of ~4.092V. -The output on each pin is set with `analogWriteFrame` within the `for` loop that +The output on each pin is set with `analogWriteFrame()` within the for loop that cycles through the analog output channels. This needs to be provided with arguments as follows `analogWriteFrame(context, n, channel, out)`. Channel is where the you give the address of the analog output pin (in this case we cycle
--- a/projects/basic_blink/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/basic_blink/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -19,15 +19,17 @@ Blinking an LED --------------- -This sketch shows the simplest case of digital out. Connect an LED in series with -a 470ohm resistor between P8_07 and ground. The led is blinked on and off by -setting the digital pin `HIGH` and `LOW` every interval seconds (set it in the -`render()` function). +This sketch shows the simplest case of digital out. -Firstly the pin mode must be set to output mode: -`pinModeFrame(context, 0, P8_07, OUTPUT);` in the `setup()` function. The output -of the digital pins is set by the following code: -`digitalWriteFrame(context, n, P8_07, status);` where status can be equal to +- Connect an LED in series with a 470ohm resistor between P8_07 and ground. + +The led is blinked on and off by setting the digital pin `HIGH` and `LOW` every interval seconds which is set in +`render()`. + +In `setup()` the pin mode must be set to output mode via `pinModeFrame()`. For example: +`pinModeFrame(context, 0, P8_07, OUTPUT)`. +In `render()` the output of the digital pins is set by `digitalWriteFrame()`. For example: +`digitalWriteFrame(context, n, P8_07, status)` where `status` can be equal to either `HIGH` or `LOW`. When set `HIGH` the pin will give 3.3V, when set to `LOW` 0V.
--- a/projects/basic_button/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/basic_button/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -19,7 +19,7 @@ Switching an LED on and off --------------------------- -This sketch brings together digital out with digital in. The program will read +This example brings together digital input and digital output. The program will read a button and turn the LED on and off according to the state of the button. - connect an LED in series with a 470ohm resistor between P8_07 and ground. @@ -34,7 +34,7 @@ the button is pressed, P8_08 goes `LOW` and P8_07 is set to `LOW`, turning off the LED. As an exercise try and change the code so that the LED only turns on when -the button is pressed +the button is pressed. */
--- a/projects/basic_passthru/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/basic_passthru/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -15,29 +15,54 @@ */ /** -\example 1_basic_audio_passthrough +\example 1_basic_audio_analog_passthrough -Audio passthrough: input to output +Audio and analog passthrough: input to output ----------------------------------------- -This sketch demonstrates the simplest possible case of using audio: it passes -audio input straight to audio output. +This sketch demonstrates how to read from and write to the audio and analog input and output buffers. -Note the nested `for` loop structure. You will see this in all Bela projects. The -first `for` loop cycles through the audio frames, the second through each of the -audio channels (in this case left 0 and right 1). +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. -We write samples to the audio output buffer like this: -`context->audioOut[n * context->audioChannels + ch]` where `n` is the current audio -frame and `ch` is the current channel, both provided by the nested for loop structure. +You can look at all the information you can access in ::BeagleRTContext. -We can access samples in the audio input buffer in a similar way, like this: -`context->audioIn[n * context->audioChannels + ch]`. +Reading and writing from the audio buffers +------------------------------------------ -So a simple audio pass through is achieved by setting output buffer equal to -input buffer: -`context->audioOut[n * context->audioChannels + ch] = context->audioIn[n * context->audioChannels + ch]`. +The simplest way to read samples from the audio input buffer is with +`audioReadFrame()` which we pass three arguments context, current audio +frame and current channel. In this example we have +`audioReadFrame(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 +`audioWriteFrame()`. This has a fourth argument which is the value of the output. +For example `audioWriteFrame(context, n, ch, value_to_output)`. + +Reading and writing from the analog buffers +------------------------------------------- + +The same is true for `analogReadFrame()` and `analogWriteFrame()`. + +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 +`analogWriteFrame(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 like this: +`context->audioOut[n * context->audioChannels + ch]`. */ @@ -86,7 +111,7 @@ } } - // Same with analog channelss + // Same with analog channels for(unsigned int n = 0; n < context->analogFrames; n++) { for(unsigned int ch = 0; ch < context->analogChannels; ch++) { // Two equivalent ways to write this code
--- a/projects/filter_FIR/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/filter_FIR/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -1,3 +1,12 @@ +/* + ____ _____ _ _ +| __ )| ____| | / \ +| _ \| _| | | / _ \ +| |_) | |___| |___ / ___ \ +|____/|_____|_____/_/ \_\.io + +*/ + /* * render.cpp * @@ -5,6 +14,16 @@ * Author: Andrew McPherson and Victor Zappi */ +/** +\example 4_filter_FIR + +Finite Impulse Response Filter +------------------------------ + +This is an example of a finite impulse response filter implementation. + +*/ + #include <BeagleRT.h> #include <cmath>
--- a/projects/filter_IIR/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/filter_IIR/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -1,3 +1,12 @@ +/* + ____ _____ _ _ +| __ )| ____| | / \ +| _ \| _| | | / _ \ +| |_) | |___| |___ / ___ \ +|____/|_____|_____/_/ \_\.io + +*/ + /* * render.cpp * @@ -5,6 +14,16 @@ * Author: Andrew McPherson and Victor Zappi */ +/** +\example 4_filter_IIR + +Infinite Impulse Response Filter +------------------------------ + +This is an example of a infinite impulse response filter implementation. + +*/ + #include <BeagleRT.h> // to schedule lower prio parallel process #include <rtdk.h>
--- a/projects/osc/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/osc/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -1,3 +1,37 @@ +/* + ____ _____ _ _ +| __ )| ____| | / \ +| _ \| _| | | / _ \ +| |_) | |___| |___ / ___ \ +|____/|_____|_____/_/ \_\.io + + */ + +/** +\example 5_osc + +Open Sound Control +------------------ + +This example shows an implementation of OSC (Open Sound Control) which was +developed at UC Berkeley Center for New Music and Audio Technology (CNMAT). + +It is designed to be run alongside resources/osc/osc.js + +The OSC server port on which to receive is set in `setup()` +via `oscServer.setup()`. Likewise the OSC client port on which to +send is set in `oscClient.setup()`. + +In `setup()` an OSC message to address `/osc-setup`, it then waits +1 second for a reply on `/osc-setup-reply`. + +in `render()` the code receives OSC messages, parses them, and sends +back an acknowledgment. + + +*/ + + #include <BeagleRT.h> #include <OSCServer.h> #include <OSCClient.h>
--- a/projects/scope_analogue/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/scope_analogue/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -1,7 +1,38 @@ -// this example reads the analogue inputs 0 and 1 -// and generates a sine wave with an amplitude and -// frequency determined by their values -// it then plots these on the oscilloscope +/* + ____ _____ _ _ +| __ )| ____| | / \ +| _ \| _| | | / _ \ +| |_) | |___| |___ / ___ \ +|____/|_____|_____/_/ \_\.io + + */ + +/** +\example 3_scope_analog + +Connecting potentiometers +------------------------- + +This example reads from analogue inputs 0 and 1 via `analogReadFrame()` and +generates a sine wave with amplitude and frequency determined by their values. +It's best to connect a 10K potentiometer to each of these analog inputs. Far +left and far right pins of the pot go to 3.3V and GND, the middle should be +connected to the analog in pins. + +The sine wave is then plotted on the oscilloscope. Click the Open Scope button to +view the results. As you turn the potentiometers you will see the amplitude and +frequency of the sine wave change. + +This project also shows as example of `map()` which allows you to re-scale a number +from one range to another. Note that `map()` does not constrain your variable +within the upper and lower limits. If you want to do this use the `constrain()` +function. + +*/ + + + + #include <BeagleRT.h> #include <cmath>
--- a/projects/scope_basic/render.cpp Tue May 17 15:53:24 2016 +0100 +++ b/projects/scope_basic/render.cpp Tue May 17 18:46:55 2016 +0100 @@ -1,3 +1,37 @@ +/* + ____ _____ _ _ +| __ )| ____| | / \ +| _ \| _| | | / _ \ +| |_) | |___| |___ / ___ \ +|____/|_____|_____/_/ \_\.io + + */ + +/** +\example 1_scope_basic + +Oscilloscope in-browser +----------------------- + +This example demonstrates the scope feature of the IDE. + +The scope is instantiated at the top of the file via `Scope scope;` + +In `setup()` we define how many channels the scope should have and the sample +rate that it should run at via `scope.setup(3, context->audioSampleRate)`. + +In `render()` we choose what the scope log via `scope.log(out, out2, out3)`. +In this example the scope is logging three sine waves with different phases. To see +the output click on the <b>Open Scope</b> button. + +An additional option is to set the trigger of the oscilloscope from within `render()`. +In this example we are triggering the scope when oscillator 1 becomes less than +oscillator 2 via `scope.trigger()`. Note that this functionality only takes effect +when the triggering mode is set to custom in the scope UI. + +*/ + + #include <BeagleRT.h> #include <Scope.h> #include <cmath>