Mercurial > hg > beaglert
comparison examples/audio_in_FFT/render.cpp @ 373:3bed6b09223c prerelease
Updated NE10 library to the latest version; needs a corresponding update to the /usr/include/ne10 header files on the SD image. Updated examples to compile against new version, and reordered D-Box channels to account for new PRU-based DAC channel reordering.
author | andrewm |
---|---|
date | Thu, 09 Jun 2016 20:03:09 +0100 |
parents | db2fe4e1b88e |
children | 24c3a0663d54 |
comparison
equal
deleted
inserted
replaced
372:db2fe4e1b88e | 373:3bed6b09223c |
---|---|
9 | 9 |
10 /* | 10 /* |
11 * render.cpp | 11 * render.cpp |
12 * | 12 * |
13 * Created on: Oct 24, 2014 | 13 * Created on: Oct 24, 2014 |
14 * Author: parallels | 14 * Author: Andrew McPherson, C4DM, QMUL |
15 */ | 15 */ |
16 | 16 |
17 /** | 17 /** |
18 \example 4_audio_FFT | 18 \example 4_audio_FFT |
19 | 19 |
38 #include <rtdk.h> | 38 #include <rtdk.h> |
39 #include <NE10.h> // neon library | 39 #include <NE10.h> // neon library |
40 #include <cmath> | 40 #include <cmath> |
41 | 41 |
42 int gFFTSize; | 42 int gFFTSize; |
43 float gFFTScaleFactor = 0; | |
44 | 43 |
45 int gReadPointer = 0; | 44 int gReadPointer = 0; |
46 int gWritePointer = 0; | 45 int gWritePointer = 0; |
47 | 46 |
48 // FFT vars | 47 // FFT vars |
49 ne10_fft_cpx_float32_t* timeDomainIn; | 48 static ne10_fft_cpx_float32_t* timeDomainIn; |
50 ne10_fft_cpx_float32_t* timeDomainOut; | 49 static ne10_fft_cpx_float32_t* timeDomainOut; |
51 ne10_fft_cpx_float32_t* frequencyDomain; | 50 static ne10_fft_cpx_float32_t* frequencyDomain; |
52 ne10_fft_cfg_float32_t cfg; | 51 static ne10_fft_cfg_float32_t cfg; |
53 | 52 |
54 // setup() is called once before the audio rendering starts. | 53 // setup() is called once before the audio rendering starts. |
55 // Use it to perform any initialisation and allocation which is dependent | 54 // Use it to perform any initialisation and allocation which is dependent |
56 // on the period size or sample rate. | 55 // on the period size or sample rate. |
57 // | 56 // |
62 | 61 |
63 bool setup(BelaContext *context, void *userData) | 62 bool setup(BelaContext *context, void *userData) |
64 { | 63 { |
65 // Retrieve a parameter passed in from the initAudio() call | 64 // Retrieve a parameter passed in from the initAudio() call |
66 gFFTSize = *(int *)userData; | 65 gFFTSize = *(int *)userData; |
67 gFFTScaleFactor = 1.0f / (float)gFFTSize; | |
68 | 66 |
69 timeDomainIn = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); | 67 timeDomainIn = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); |
70 timeDomainOut = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); | 68 timeDomainOut = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); |
71 frequencyDomain = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); | 69 frequencyDomain = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); |
72 cfg = ne10_fft_alloc_c2c_float32 (gFFTSize); | 70 cfg = ne10_fft_alloc_c2c_float32_neon (gFFTSize); |
73 | 71 |
74 memset(timeDomainOut, 0, gFFTSize * sizeof (ne10_fft_cpx_float32_t)); | 72 memset(timeDomainOut, 0, gFFTSize * sizeof (ne10_fft_cpx_float32_t)); |
75 | 73 |
76 return true; | 74 return true; |
77 } | 75 } |
89 timeDomainIn[gReadPointer].i = 0; | 87 timeDomainIn[gReadPointer].i = 0; |
90 | 88 |
91 if(++gReadPointer >= gFFTSize) | 89 if(++gReadPointer >= gFFTSize) |
92 { | 90 { |
93 //FFT | 91 //FFT |
94 ne10_fft_c2c_1d_float32_neon (frequencyDomain, timeDomainIn, cfg->twiddles, cfg->factors, gFFTSize, 0); | 92 ne10_fft_c2c_1d_float32_neon (frequencyDomain, timeDomainIn, cfg, 0); |
95 | 93 |
96 //Do frequency domain stuff | 94 //Do frequency domain stuff |
97 | 95 |
98 //IFFT | 96 //IFFT |
99 ne10_fft_c2c_1d_float32_neon (timeDomainOut, frequencyDomain, cfg->twiddles, cfg->factors, gFFTSize, 1); | 97 ne10_fft_c2c_1d_float32_neon (timeDomainOut, frequencyDomain, cfg, 1); |
100 | 98 |
101 gReadPointer = 0; | 99 gReadPointer = 0; |
102 gWritePointer = 0; | 100 gWritePointer = 0; |
103 } | 101 } |
104 | 102 |
105 for(unsigned int channel = 0; channel < context->audioChannels; channel++) | 103 for(unsigned int channel = 0; channel < context->audioChannels; channel++) |
106 context->audioOut[n * context->audioChannels + channel] = (float) timeDomainOut[gWritePointer].r * gFFTScaleFactor; | 104 context->audioOut[n * context->audioChannels + channel] = (float) timeDomainOut[gWritePointer].r; |
107 gWritePointer++; | 105 gWritePointer++; |
108 } | 106 } |
109 } | 107 } |
110 | 108 |
111 // cleanup() is called once at the end, after the audio has stopped. | 109 // cleanup() is called once at the end, after the audio has stopped. |