Mercurial > hg > beaglert
comparison projects/audio_in_FFT/render.cpp @ 52:a6d223473ea2 newapi
Updated examples for new API. tank_wars not yet updated; audio_in_FFT and oscillator_bank not working properly yet.
author | andrewm |
---|---|
date | Sun, 31 May 2015 02:13:39 -0500 |
parents | 06f93bef7dd2 |
children | 3c3a1357657d |
comparison
equal
deleted
inserted
replaced
51:4f8db16f17b5 | 52:a6d223473ea2 |
---|---|
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 "../../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; |
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 initialise_render(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(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_render() 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 initialise_render(). |
89 | 85 |
90 void cleanup_render() | 86 void cleanup_render(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); |