Mercurial > hg > beaglert
comparison projects/samples/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: Andrew McPherson and Victor Zappi | 5 * Author: Andrew McPherson and Victor Zappi |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "../../include/render.h" | 9 #include "../../include/BeagleRT.h" // to schedule lower prio parallel process |
10 #include "../../include/RTAudio.h" // to schedule lower prio parallel process | |
11 #include <rtdk.h> | 10 #include <rtdk.h> |
12 #include <cmath> | 11 #include <cmath> |
13 #include <stdio.h> | 12 #include <stdio.h> |
14 #include "SampleData.h" | 13 #include "SampleData.h" |
15 | 14 |
29 // userData holds an opaque pointer to a data structure that was passed | 28 // userData holds an opaque pointer to a data structure that was passed |
30 // in from the call to initAudio(). | 29 // in from the call to initAudio(). |
31 // | 30 // |
32 // Return true on success; returning false halts the program. | 31 // Return true on success; returning false halts the program. |
33 | 32 |
34 bool initialise_render(int numMatrixChannels, int numAudioChannels, | 33 bool initialise_render(BeagleRTContext *context, void *userData) |
35 int numMatrixFramesPerPeriod, | |
36 int numAudioFramesPerPeriod, | |
37 float matrixSampleRate, float audioSampleRate, | |
38 void *userData) | |
39 { | 34 { |
40 | 35 |
41 // Retrieve a parameter passed in from the initAudio() call | 36 // Retrieve a parameter passed in from the initAudio() call |
42 gSampleData = *(SampleData *)userData; | 37 gSampleData = *(SampleData *)userData; |
43 | 38 |
53 // render() is called regularly at the highest priority by the audio engine. | 48 // render() is called regularly at the highest priority by the audio engine. |
54 // Input and output are given from the audio hardware and the other | 49 // Input and output are given from the audio hardware and the other |
55 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | 50 // ADCs and DACs (if available). If only audio is available, numMatrixFrames |
56 // will be 0. | 51 // will be 0. |
57 | 52 |
58 void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, | 53 void render(BeagleRTContext *context, void *userData) |
59 uint16_t *matrixIn, uint16_t *matrixOut) | |
60 { | 54 { |
61 for(int n = 0; n < numAudioFrames; n++) { | 55 for(int n = 0; n < context->audioFrames; n++) { |
62 float out = 0; | 56 float out = 0; |
63 | 57 |
64 // If triggered... | 58 // If triggered... |
65 if(gReadPtr != -1) | 59 if(gReadPtr != -1) |
66 out += gSampleData.samples[gReadPtr++]; // ...read each sample... | 60 out += gSampleData.samples[gReadPtr++]; // ...read each sample... |
67 | 61 |
68 if(gReadPtr >= gSampleData.sampleLen) | 62 if(gReadPtr >= gSampleData.sampleLen) |
69 gReadPtr = -1; | 63 gReadPtr = -1; |
70 | 64 |
71 for(int channel = 0; channel < gNumAudioChannels; channel++) | 65 for(int channel = 0; channel < context->audioChannels; channel++) |
72 audioOut[n * gNumAudioChannels + channel] = out; // ...and put it in both left and right channel | 66 context->audioOut[n * context->audioChannels + channel] = out; // ...and put it in both left and right channel |
73 } | 67 } |
74 | 68 |
75 // Request that the lower-priority task run at next opportunity | 69 // Request that the lower-priority task run at next opportunity |
76 scheduleAuxiliaryTask(gTriggerSamplesTask); | 70 BeagleRT_scheduleAuxiliaryTask(gTriggerSamplesTask); |
77 } | 71 } |
78 | 72 |
79 // Initialise the auxiliary task | 73 // Initialise the auxiliary task |
80 // and print info | 74 // and print info |
81 | 75 |
82 bool initialise_trigger() | 76 bool initialise_trigger() |
83 { | 77 { |
84 if((gTriggerSamplesTask = createAuxiliaryTaskLoop(&trigger_samples, 50, "beaglert-trigger-samples")) == 0) | 78 if((gTriggerSamplesTask = BeagleRT_createAuxiliaryTask(&trigger_samples, 50, "beaglert-trigger-samples")) == 0) |
85 return false; | 79 return false; |
86 | 80 |
87 rt_printf("Press 'a' to trigger sample, 's' to stop\n"); | 81 rt_printf("Press 'a' to trigger sample, 's' to stop\n"); |
88 rt_printf("Press 'q' to quit\n"); | 82 rt_printf("Press 'q' to quit\n"); |
89 | 83 |
125 | 119 |
126 | 120 |
127 // cleanup_render() is called once at the end, after the audio has stopped. | 121 // cleanup_render() is called once at the end, after the audio has stopped. |
128 // Release any resources that were allocated in initialise_render(). | 122 // Release any resources that were allocated in initialise_render(). |
129 | 123 |
130 void cleanup_render() | 124 void cleanup_render(BeagleRTContext *context, void *userData) |
131 { | 125 { |
132 delete[] gSampleData.samples; | 126 delete[] gSampleData.samples; |
133 } | 127 } |