Mercurial > hg > beaglert
comparison projects/basic_analog_input/render.cpp @ 269:ac8eb07afcf5
Oxygen text added to each render.cpp file for the default projects. Text includes project explanation from Wiki, edited in places.
Empty project added as a default project.
Doxyfile updated. Each of the project locations added to INPUT configuration option. Consider just watching the whole project file so all new projects are automatically pulled through.
| author | Robert Jack <robert.h.jack@gmail.com> |
|---|---|
| date | Tue, 17 May 2016 15:40:16 +0100 |
| parents | 72726dd4f66c |
| children | 5433c83ce04e |
comparison
equal
deleted
inserted
replaced
| 252:381f352c44eb | 269:ac8eb07afcf5 |
|---|---|
| 1 /* | |
| 2 ____ _____ _ _ | |
| 3 | __ )| ____| | / \ | |
| 4 | _ \| _| | | / _ \ | |
| 5 | |_) | |___| |___ / ___ \ | |
| 6 |____/|_____|_____/_/ \_\.io | |
| 7 | |
| 8 */ | |
| 9 | |
| 1 /* | 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 3_analog_input | |
| 19 | |
| 20 Connecting potentiometers | |
| 21 ------------------------- | |
| 22 | |
| 23 This sketch produces a sine tone, the frequency and amplitude of which are | |
| 24 affected by data received on the analog pins. Before looping through each audio | |
| 25 frame, we declare a value for the frequency and amplitude of our sine tone | |
| 26 (line 55); we adjust these values by taking in data from analog sensors | |
| 27 (for example, a potentiometer). | |
| 28 | |
| 29 The important thing to notice is that audio is sampled twice as often as analog | |
| 30 data. The audio sampling rate is 44.1kHz (44100 frames per second) and the | |
| 31 analog sampling rate is 22.05kHz (22050 frames per second). On line 62 you might | |
| 32 notice that we are processing the analog data and updating frequency and | |
| 33 amplitude only on every second audio sample, since the analog sampling rate is | |
| 34 half that of the audio. | |
| 35 | |
| 36 Note that the pin numbers are stored in the variables `gAnalogInputFrequency` and | |
| 37 `gAnalogInputAmplitude`. These are declared in the main.cpp file; if you look in | |
| 38 that file you will see that they have the values of 0 and 1. Bear in mind that | |
| 39 these are analog input pins which is a specific header! | |
| 40 */ | |
| 8 | 41 |
| 9 #include <BeagleRT.h> | 42 #include <BeagleRT.h> |
| 10 #include <Utilities.h> | 43 #include <Utilities.h> |
| 11 #include <rtdk.h> | 44 #include <rtdk.h> |
| 12 #include <cmath> | 45 #include <cmath> |
| 28 // | 61 // |
| 29 // userData holds an opaque pointer to a data structure that was passed | 62 // userData holds an opaque pointer to a data structure that was passed |
| 30 // in from the call to initAudio(). | 63 // in from the call to initAudio(). |
| 31 // | 64 // |
| 32 // Return true on success; returning false halts the program. | 65 // Return true on success; returning false halts the program. |
| 66 | |
| 33 | 67 |
| 34 bool setup(BeagleRTContext *context, void *userData) | 68 bool setup(BeagleRTContext *context, void *userData) |
| 35 { | 69 { |
| 36 if(context->analogFrames == 0 || context->analogFrames > context->audioFrames) { | 70 if(context->analogFrames == 0 || context->analogFrames > context->audioFrames) { |
| 37 rt_printf("Error: this example needs analog enabled, with 4 or 8 channels\n"); | 71 rt_printf("Error: this example needs analog enabled, with 4 or 8 channels\n"); |
