Mercurial > hg > beaglert
comparison projects/basic/render.cpp @ 45:579c86316008 newapi
Major API overhaul. Moved to a single data structure for handling render functions. Functionally, generally similar except for scheduling within PRU loop function, which now uses interrupts from the PRU rather than polling. This requires an updated kernel.
author | andrewm |
---|---|
date | Thu, 28 May 2015 14:35:55 -0400 |
parents | ad5cd8dd99b3 |
children | 3c3a1357657d |
comparison
equal
deleted
inserted
replaced
40:419ce4ebfc4c | 45:579c86316008 |
---|---|
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 <cmath> | 10 #include <cmath> |
11 | 11 |
12 float gFrequency; | 12 float gFrequency; |
13 float gPhase; | 13 float gPhase; |
14 float gInverseSampleRate; | 14 float gInverseSampleRate; |
20 // userData holds an opaque pointer to a data structure that was passed | 20 // userData holds an opaque pointer to a data structure that was passed |
21 // in from the call to initAudio(). | 21 // in from the call to initAudio(). |
22 // | 22 // |
23 // Return true on success; returning false halts the program. | 23 // Return true on success; returning false halts the program. |
24 | 24 |
25 bool initialise_render(int numMatrixChannels, int numDigitalChannels, int numAudioChannels, | 25 bool initialise_render(BeagleRTContext *context, void *userData) |
26 int numMatrixFramesPerPeriod, | |
27 int numAudioFramesPerPeriod, | |
28 float matrixSampleRate, float audioSampleRate, | |
29 void *userData, RTAudioSettings* settings) | |
30 { | 26 { |
31 // Retrieve a parameter passed in from the initAudio() call | 27 // Retrieve a parameter passed in from the initAudio() call |
32 gFrequency = *(float *)userData; | 28 gFrequency = *(float *)userData; |
33 | 29 |
34 gInverseSampleRate = 1.0 / audioSampleRate; | 30 gInverseSampleRate = 1.0 / context->audioSampleRate; |
35 gPhase = 0.0; | 31 gPhase = 0.0; |
36 | 32 |
37 return true; | 33 return true; |
38 } | 34 } |
39 | 35 |
40 // render() is called regularly at the highest priority by the audio engine. | 36 // render() is called regularly at the highest priority by the audio engine. |
41 // Input and output are given from the audio hardware and the other | 37 // Input and output are given from the audio hardware and the other |
42 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | 38 // ADCs and DACs (if available). If only audio is available, numMatrixFrames |
43 // will be 0. | 39 // will be 0. |
44 | 40 |
45 void render(int numAnalogFrames, int numAudioFrames, int numDigitalFrames, float *audioIn, float *audioOut, | 41 void render(BeagleRTContext *context, void *userData) |
46 float *analogIn, float *analogOut, uint32_t *digital) | |
47 { | 42 { |
48 for(int n = 0; n < numAudioFrames; n++) { | 43 for(unsigned int n = 0; n < context->audioFrames; n++) { |
49 float out = 0.8f * sinf(gPhase); | 44 float out = 0.8f * sinf(gPhase); |
50 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; | 45 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; |
51 if(gPhase > 2.0 * M_PI) | 46 if(gPhase > 2.0 * M_PI) |
52 gPhase -= 2.0 * M_PI; | 47 gPhase -= 2.0 * M_PI; |
53 | 48 |
54 for(int channel = 0; channel < gNumAudioChannels; channel++) | 49 for(unsigned int channel = 0; channel < context->audioChannels; channel++) |
55 audioOut[n * gNumAudioChannels + channel] = out; | 50 context->audioOut[n * context->audioChannels + channel] = out; |
56 } | 51 } |
57 } | 52 } |
58 | 53 |
59 // cleanup_render() is called once at the end, after the audio has stopped. | 54 // cleanup_render() is called once at the end, after the audio has stopped. |
60 // Release any resources that were allocated in initialise_render(). | 55 // Release any resources that were allocated in initialise_render(). |
61 | 56 |
62 void cleanup_render() | 57 void cleanup_render(BeagleRTContext *context, void *userData) |
63 { | 58 { |
64 | 59 |
65 } | 60 } |