comparison projects/basic_analog_output/render.cpp @ 56:3c3a1357657d newapi

Further API update to name three primary functions setup(), render() and cleanup(). Changed include paths so now can #include <BeagleRT.h>. Removed stale pru_rtaudio.bin file as this is now done as pru_rtaudio_bin.h. Updated examples to new API and fixed minor compiler warnings along the way. Network example needs further attention to compile.
author andrewm
date Wed, 15 Jul 2015 12:10:51 +0100
parents a6d223473ea2
children ac8eb07afcf5
comparison
equal deleted inserted replaced
55:41d24dba6b74 56:3c3a1357657d
4 * Created on: Oct 24, 2014 4 * Created on: Oct 24, 2014
5 * Author: parallels 5 * Author: parallels
6 */ 6 */
7 7
8 8
9 #include "../../include/BeagleRT.h" 9 #include <BeagleRT.h>
10 #include "../../include/Utilities.h" 10 #include <Utilities.h>
11 #include <rtdk.h> 11 #include <rtdk.h>
12 #include <cmath> 12 #include <cmath>
13 13
14 // Set range for analog outputs designed for driving LEDs 14 // Set range for analog outputs designed for driving LEDs
15 const float kMinimumAmplitude = (1.5 / 5.0); 15 const float kMinimumAmplitude = (1.5 / 5.0);
17 17
18 float gFrequency; 18 float gFrequency;
19 float gPhase; 19 float gPhase;
20 float gInverseSampleRate; 20 float gInverseSampleRate;
21 21
22 // initialise_render() is called once before the audio rendering starts. 22 // setup() is called once before the audio rendering starts.
23 // Use it to perform any initialisation and allocation which is dependent 23 // Use it to perform any initialisation and allocation which is dependent
24 // on the period size or sample rate. 24 // on the period size or sample rate.
25 // 25 //
26 // userData holds an opaque pointer to a data structure that was passed 26 // userData holds an opaque pointer to a data structure that was passed
27 // in from the call to initAudio(). 27 // in from the call to initAudio().
28 // 28 //
29 // Return true on success; returning false halts the program. 29 // Return true on success; returning false halts the program.
30 30
31 bool initialise_render(BeagleRTContext *context, void *userData) 31 bool setup(BeagleRTContext *context, void *userData)
32 { 32 {
33 // Retrieve a parameter passed in from the initAudio() call 33 // Retrieve a parameter passed in from the initAudio() call
34 gFrequency = *(float *)userData; 34 gFrequency = *(float *)userData;
35 35
36 if(context->analogFrames == 0) { 36 if(context->analogFrames == 0) {
49 // ADCs and DACs (if available). If only audio is available, numMatrixFrames 49 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
50 // will be 0. 50 // will be 0.
51 51
52 void render(BeagleRTContext *context, void *userData) 52 void render(BeagleRTContext *context, void *userData)
53 { 53 {
54 for(int n = 0; n < context->analogFrames; n++) { 54 for(unsigned int n = 0; n < context->analogFrames; n++) {
55 // Set LED to different phase for each matrix channel 55 // Set LED to different phase for each matrix channel
56 float relativePhase = 0.0; 56 float relativePhase = 0.0;
57 for(int channel = 0; channel < context->analogChannels; channel++) { 57 for(unsigned int channel = 0; channel < context->analogChannels; channel++) {
58 float out = kMinimumAmplitude + kAmplitudeRange * 0.5f * (1.0f + sinf(gPhase + relativePhase)); 58 float out = kMinimumAmplitude + kAmplitudeRange * 0.5f * (1.0f + sinf(gPhase + relativePhase));
59 59
60 analogWriteFrame(context, n, channel, out); 60 analogWriteFrame(context, n, channel, out);
61 61
62 // Advance by pi/4 (1/8 of a full rotation) for each channel 62 // Advance by pi/4 (1/8 of a full rotation) for each channel
67 if(gPhase > 2.0 * M_PI) 67 if(gPhase > 2.0 * M_PI)
68 gPhase -= 2.0 * M_PI; 68 gPhase -= 2.0 * M_PI;
69 } 69 }
70 } 70 }
71 71
72 // cleanup_render() is called once at the end, after the audio has stopped. 72 // cleanup() is called once at the end, after the audio has stopped.
73 // Release any resources that were allocated in initialise_render(). 73 // Release any resources that were allocated in setup().
74 74
75 void cleanup_render(BeagleRTContext *context, void *userData) 75 void cleanup(BeagleRTContext *context, void *userData)
76 { 76 {
77 77
78 } 78 }