Mercurial > hg > beaglert
comparison projects/audio_in_FFT/render.cpp @ 108:3068421c0737 ultra-staging
Merged default into ultra-staging
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 18 Aug 2015 00:35:15 +0100 |
parents | 3c3a1357657d |
children | ac8eb07afcf5 |
comparison
equal
deleted
inserted
replaced
54:d3f869b98147 | 108:3068421c0737 |
---|---|
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/render.h" | 9 #include <BeagleRT.h> |
10 #include <rtdk.h> | 10 #include <rtdk.h> |
11 #include <NE10.h> // neon library | 11 #include <NE10.h> // neon library |
12 #include <cmath> | 12 #include <cmath> |
13 | 13 |
14 int gFFTSize; | 14 int gFFTSize; |
21 ne10_fft_cpx_float32_t* timeDomainIn; | 21 ne10_fft_cpx_float32_t* timeDomainIn; |
22 ne10_fft_cpx_float32_t* timeDomainOut; | 22 ne10_fft_cpx_float32_t* timeDomainOut; |
23 ne10_fft_cpx_float32_t* frequencyDomain; | 23 ne10_fft_cpx_float32_t* frequencyDomain; |
24 ne10_fft_cfg_float32_t cfg; | 24 ne10_fft_cfg_float32_t cfg; |
25 | 25 |
26 // initialise_render() is called once before the audio rendering starts. | 26 // setup() is called once before the audio rendering starts. |
27 // Use it to perform any initialisation and allocation which is dependent | 27 // Use it to perform any initialisation and allocation which is dependent |
28 // on the period size or sample rate. | 28 // on the period size or sample rate. |
29 // | 29 // |
30 // userData holds an opaque pointer to a data structure that was passed | 30 // userData holds an opaque pointer to a data structure that was passed |
31 // in from the call to initAudio(). | 31 // in from the call to initAudio(). |
32 // | 32 // |
33 // Return true on success; returning false halts the program. | 33 // Return true on success; returning false halts the program. |
34 | 34 |
35 bool initialise_render(int numMatrixChannels, int numAudioChannels, | 35 bool setup(BeagleRTContext *context, void *userData) |
36 int numMatrixFramesPerPeriod, | |
37 int numAudioFramesPerPeriod, | |
38 float matrixSampleRate, float audioSampleRate, | |
39 void *userData) | |
40 { | 36 { |
41 // Retrieve a parameter passed in from the initAudio() call | 37 // Retrieve a parameter passed in from the initAudio() call |
42 gFFTSize = *(int *)userData; | 38 gFFTSize = *(int *)userData; |
43 gFFTScaleFactor = 1.0f / (float)gFFTSize; | 39 gFFTScaleFactor = 1.0f / (float)gFFTSize; |
44 | 40 |
55 // render() is called regularly at the highest priority by the audio engine. | 51 // render() is called regularly at the highest priority by the audio engine. |
56 // Input and output are given from the audio hardware and the other | 52 // Input and output are given from the audio hardware and the other |
57 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | 53 // ADCs and DACs (if available). If only audio is available, numMatrixFrames |
58 // will be 0. | 54 // will be 0. |
59 | 55 |
60 void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, | 56 void render(BeagleRTContext *context, void *userData) |
61 uint16_t *matrixIn, uint16_t *matrixOut) | |
62 { | 57 { |
63 for(int n = 0; n < numAudioFrames; n++) { | 58 for(unsigned int n = 0; n < context->audioFrames; n++) { |
64 timeDomainIn[gReadPointer].r = (ne10_float32_t) ((audioIn[n*gNumAudioChannels] + audioIn[n*gNumAudioChannels+1]) * 0.5); | 59 timeDomainIn[gReadPointer].r = (ne10_float32_t) ((context->audioIn[n*context->audioChannels] + |
60 context->audioIn[n*context->audioChannels+1]) * 0.5); | |
65 timeDomainIn[gReadPointer].i = 0; | 61 timeDomainIn[gReadPointer].i = 0; |
66 | 62 |
67 if(++gReadPointer >= gFFTSize) | 63 if(++gReadPointer >= gFFTSize) |
68 { | 64 { |
69 //FFT | 65 //FFT |
76 | 72 |
77 gReadPointer = 0; | 73 gReadPointer = 0; |
78 gWritePointer = 0; | 74 gWritePointer = 0; |
79 } | 75 } |
80 | 76 |
81 for(int channel = 0; channel < gNumAudioChannels; channel++) | 77 for(unsigned int channel = 0; channel < context->audioChannels; channel++) |
82 audioOut[n * gNumAudioChannels + channel] = (float) timeDomainOut[gWritePointer].r * gFFTScaleFactor; | 78 context->audioOut[n * context->audioChannels + channel] = (float) timeDomainOut[gWritePointer].r * gFFTScaleFactor; |
83 gWritePointer++; | 79 gWritePointer++; |
84 } | 80 } |
85 } | 81 } |
86 | 82 |
87 // cleanup_render() is called once at the end, after the audio has stopped. | 83 // cleanup() is called once at the end, after the audio has stopped. |
88 // Release any resources that were allocated in initialise_render(). | 84 // Release any resources that were allocated in setup(). |
89 | 85 |
90 void cleanup_render() | 86 void cleanup(BeagleRTContext *context, void *userData) |
91 { | 87 { |
92 NE10_FREE(timeDomainIn); | 88 NE10_FREE(timeDomainIn); |
93 NE10_FREE(timeDomainOut); | 89 NE10_FREE(timeDomainOut); |
94 NE10_FREE(frequencyDomain); | 90 NE10_FREE(frequencyDomain); |
95 NE10_FREE(cfg); | 91 NE10_FREE(cfg); |