comparison projects/basic/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 579c86316008
children 07cfd337ad18
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 <cmath> 10 #include <cmath>
11 11
12 float gFrequency; 12 float gFrequency = 440.0;
13 float gPhase; 13 float gPhase;
14 float gInverseSampleRate; 14 float gInverseSampleRate;
15 15
16 // initialise_render() is called once before the audio rendering starts. 16 // setup() is called once before the audio rendering starts.
17 // Use it to perform any initialisation and allocation which is dependent 17 // Use it to perform any initialisation and allocation which is dependent
18 // on the period size or sample rate. 18 // on the period size or sample rate.
19 // 19 //
20 // userData holds an opaque pointer to a data structure that was passed 20 // userData holds an opaque pointer to a data structure that was passed
21 // in from the call to initAudio(). 21 // in from the call to initAudio().
22 // 22 //
23 // Return true on success; returning false halts the program. 23 // Return true on success; returning false halts the program.
24 24
25 bool initialise_render(BeagleRTContext *context, void *userData) 25 bool setup(BeagleRTContext *context, void *userData)
26 { 26 {
27 // Retrieve a parameter passed in from the initAudio() call 27 // Retrieve a parameter passed in from the initAudio() call
28 gFrequency = *(float *)userData; 28 if(userData != 0)
29 gFrequency = *(float *)userData;
29 30
30 gInverseSampleRate = 1.0 / context->audioSampleRate; 31 gInverseSampleRate = 1.0 / context->audioSampleRate;
31 gPhase = 0.0; 32 gPhase = 0.0;
32 33
33 return true; 34 return true;
49 for(unsigned int channel = 0; channel < context->audioChannels; channel++) 50 for(unsigned int channel = 0; channel < context->audioChannels; channel++)
50 context->audioOut[n * context->audioChannels + channel] = out; 51 context->audioOut[n * context->audioChannels + channel] = out;
51 } 52 }
52 } 53 }
53 54
54 // cleanup_render() is called once at the end, after the audio has stopped. 55 // cleanup() is called once at the end, after the audio has stopped.
55 // Release any resources that were allocated in initialise_render(). 56 // Release any resources that were allocated in setup().
56 57
57 void cleanup_render(BeagleRTContext *context, void *userData) 58 void cleanup(BeagleRTContext *context, void *userData)
58 { 59 {
59 60
60 } 61 }