comparison examples/filter_FIR/render.cpp @ 301:e4392164b458 prerelease

RENAMED BeagleRT to Bela AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, scripts probably not working
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 27 May 2016 14:34:41 +0100
parents dbeed520b014
children 421a69d42943
comparison
equal deleted inserted replaced
300:dbeed520b014 301:e4392164b458
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 <BeagleRT.h> 9 #include <Bela.h>
10 #include <cmath> 10 #include <cmath>
11 #include <NE10.h> // neon library 11 #include <NE10.h> // neon library
12 #include "SampleData.h" 12 #include "SampleData.h"
13 #include "FIRfilter.h" 13 #include "FIRfilter.h"
14 14
20 ne10_float32_t *gFIRfilterIn; 20 ne10_float32_t *gFIRfilterIn;
21 ne10_float32_t *gFIRfilterOut; 21 ne10_float32_t *gFIRfilterOut;
22 ne10_uint32_t blockSize; 22 ne10_uint32_t blockSize;
23 ne10_float32_t *gFIRfilterState; 23 ne10_float32_t *gFIRfilterState;
24 24
25 void initialise_filter(BeagleRTContext *context); 25 void initialise_filter(BelaContext *context);
26 26
27 // Task for handling the update of the frequencies using the matrix 27 // Task for handling the update of the frequencies using the matrix
28 AuxiliaryTask gTriggerSamplesTask; 28 AuxiliaryTask gTriggerSamplesTask;
29 29
30 bool initialise_trigger(); 30 bool initialise_trigger();
37 // userData holds an opaque pointer to a data structure that was passed 37 // userData holds an opaque pointer to a data structure that was passed
38 // in from the call to initAudio(). 38 // in from the call to initAudio().
39 // 39 //
40 // Return true on success; returning false halts the program. 40 // Return true on success; returning false halts the program.
41 41
42 bool setup(BeagleRTContext *context, void *userData) 42 bool setup(BelaContext *context, void *userData)
43 { 43 {
44 44
45 // Retrieve a parameter passed in from the initAudio() call 45 // Retrieve a parameter passed in from the initAudio() call
46 gSampleData = *(SampleData *)userData; 46 gSampleData = *(SampleData *)userData;
47 47
59 // render() is called regularly at the highest priority by the audio engine. 59 // render() is called regularly at the highest priority by the audio engine.
60 // Input and output are given from the audio hardware and the other 60 // Input and output are given from the audio hardware and the other
61 // ADCs and DACs (if available). If only audio is available, numMatrixFrames 61 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
62 // will be 0. 62 // will be 0.
63 63
64 void render(BeagleRTContext *context, void *userData) 64 void render(BelaContext *context, void *userData)
65 { 65 {
66 for(unsigned int n = 0; n < context->audioFrames; n++) { 66 for(unsigned int n = 0; n < context->audioFrames; n++) {
67 float in = 0; 67 float in = 0;
68 68
69 // If triggered... 69 // If triggered...
83 context->audioOut[n * context->audioChannels + channel] = gFIRfilterOut[n]; // ...and put it in both left and right channel 83 context->audioOut[n * context->audioChannels + channel] = gFIRfilterOut[n]; // ...and put it in both left and right channel
84 } 84 }
85 85
86 86
87 // Request that the lower-priority task run at next opportunity 87 // Request that the lower-priority task run at next opportunity
88 BeagleRT_scheduleAuxiliaryTask(gTriggerSamplesTask); 88 Bela_scheduleAuxiliaryTask(gTriggerSamplesTask);
89 } 89 }
90 90
91 // Initialise NE10 data structures to define FIR filter 91 // Initialise NE10 data structures to define FIR filter
92 92
93 void initialise_filter(BeagleRTContext *context) 93 void initialise_filter(BelaContext *context)
94 { 94 {
95 blockSize = context->audioFrames; 95 blockSize = context->audioFrames;
96 gFIRfilterState = (ne10_float32_t *) NE10_MALLOC ((FILTER_TAP_NUM+blockSize-1) * sizeof (ne10_float32_t)); 96 gFIRfilterState = (ne10_float32_t *) NE10_MALLOC ((FILTER_TAP_NUM+blockSize-1) * sizeof (ne10_float32_t));
97 gFIRfilterIn = (ne10_float32_t *) NE10_MALLOC (blockSize * sizeof (ne10_float32_t)); 97 gFIRfilterIn = (ne10_float32_t *) NE10_MALLOC (blockSize * sizeof (ne10_float32_t));
98 gFIRfilterOut = (ne10_float32_t *) NE10_MALLOC (blockSize * sizeof (ne10_float32_t)); 98 gFIRfilterOut = (ne10_float32_t *) NE10_MALLOC (blockSize * sizeof (ne10_float32_t));
103 // Initialise the auxiliary task 103 // Initialise the auxiliary task
104 // and print info 104 // and print info
105 105
106 bool initialise_trigger() 106 bool initialise_trigger()
107 { 107 {
108 if((gTriggerSamplesTask = BeagleRT_createAuxiliaryTask(&trigger_samples, 50, "beaglert-trigger-samples")) == 0) 108 if((gTriggerSamplesTask = Bela_createAuxiliaryTask(&trigger_samples, 50, "beaglert-trigger-samples")) == 0)
109 return false; 109 return false;
110 110
111 rt_printf("Press 'a' to trigger sample, 's' to stop\n"); 111 rt_printf("Press 'a' to trigger sample, 's' to stop\n");
112 rt_printf("Press 'q' to quit\n"); 112 rt_printf("Press 'q' to quit\n");
113 113
149 149
150 150
151 // cleanup() is called once at the end, after the audio has stopped. 151 // cleanup() is called once at the end, after the audio has stopped.
152 // Release any resources that were allocated in setup(). 152 // Release any resources that were allocated in setup().
153 153
154 void cleanup(BeagleRTContext *context, void *userData) 154 void cleanup(BelaContext *context, void *userData)
155 { 155 {
156 delete[] gSampleData.samples; 156 delete[] gSampleData.samples;
157 157
158 NE10_FREE(gFIRfilterState); 158 NE10_FREE(gFIRfilterState);
159 NE10_FREE(gFIRfilterIn); 159 NE10_FREE(gFIRfilterIn);