comparison projects/samples/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: Andrew McPherson and Victor Zappi 5 * Author: Andrew McPherson and Victor Zappi
6 */ 6 */
7 7
8 8
9 #include "../../include/BeagleRT.h" // to schedule lower prio parallel process 9 #include <BeagleRT.h>
10 #include <rtdk.h>
11 #include <cmath> 10 #include <cmath>
12 #include <stdio.h>
13 #include "SampleData.h" 11 #include "SampleData.h"
14 12
15 SampleData gSampleData; // User defined structure to get complex data from main 13 SampleData gSampleData; // User defined structure to get complex data from main
16 int gReadPtr; // Position of last read sample from file 14 int gReadPtr; // Position of last read sample from file
17 15
19 AuxiliaryTask gTriggerSamplesTask; 17 AuxiliaryTask gTriggerSamplesTask;
20 18
21 bool initialise_trigger(); 19 bool initialise_trigger();
22 void trigger_samples(); 20 void trigger_samples();
23 21
24 // initialise_render() is called once before the audio rendering starts. 22 // setup() is called once before the audio rendering starts.
25 // Use it to perform any initialisation and allocation which is dependent 23 // Use it to perform any initialisation and allocation which is dependent
26 // on the period size or sample rate. 24 // on the period size or sample rate.
27 // 25 //
28 // 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
29 // in from the call to initAudio(). 27 // in from the call to initAudio().
30 // 28 //
31 // Return true on success; returning false halts the program. 29 // Return true on success; returning false halts the program.
32 30
33 bool initialise_render(BeagleRTContext *context, void *userData) 31 bool setup(BeagleRTContext *context, void *userData)
34 { 32 {
35 33
36 // Retrieve a parameter passed in from the initAudio() call 34 // Retrieve a parameter passed in from the initAudio() call
37 gSampleData = *(SampleData *)userData; 35 gSampleData = *(SampleData *)userData;
38 36
50 // ADCs and DACs (if available). If only audio is available, numMatrixFrames 48 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
51 // will be 0. 49 // will be 0.
52 50
53 void render(BeagleRTContext *context, void *userData) 51 void render(BeagleRTContext *context, void *userData)
54 { 52 {
55 for(int n = 0; n < context->audioFrames; n++) { 53 for(unsigned int n = 0; n < context->audioFrames; n++) {
56 float out = 0; 54 float out = 0;
57 55
58 // If triggered... 56 // If triggered...
59 if(gReadPtr != -1) 57 if(gReadPtr != -1)
60 out += gSampleData.samples[gReadPtr++]; // ...read each sample... 58 out += gSampleData.samples[gReadPtr++]; // ...read each sample...
61 59
62 if(gReadPtr >= gSampleData.sampleLen) 60 if(gReadPtr >= gSampleData.sampleLen)
63 gReadPtr = -1; 61 gReadPtr = -1;
64 62
65 for(int channel = 0; channel < context->audioChannels; channel++) 63 for(unsigned int channel = 0; channel < context->audioChannels; channel++)
66 context->audioOut[n * context->audioChannels + channel] = out; // ...and put it in both left and right channel 64 context->audioOut[n * context->audioChannels + channel] = out; // ...and put it in both left and right channel
67 } 65 }
68 66
69 // Request that the lower-priority task run at next opportunity 67 // Request that the lower-priority task run at next opportunity
70 BeagleRT_scheduleAuxiliaryTask(gTriggerSamplesTask); 68 BeagleRT_scheduleAuxiliaryTask(gTriggerSamplesTask);
116 } 114 }
117 } 115 }
118 116
119 117
120 118
121 // cleanup_render() is called once at the end, after the audio has stopped. 119 // cleanup() is called once at the end, after the audio has stopped.
122 // Release any resources that were allocated in initialise_render(). 120 // Release any resources that were allocated in setup().
123 121
124 void cleanup_render(BeagleRTContext *context, void *userData) 122 void cleanup(BeagleRTContext *context, void *userData)
125 { 123 {
126 delete[] gSampleData.samples; 124 delete[] gSampleData.samples;
127 } 125 }