comparison projects/basic_passthru/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 6adb088196a7
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 "../../include/Utilities.h" 10 #include "../../include/Utilities.h"
11 #include <rtdk.h> 11 #include <rtdk.h>
12 12
13 // initialise_render() is called once before the audio rendering starts. 13 // initialise_render() is called once before the audio rendering starts.
14 // Use it to perform any initialisation and allocation which is dependent 14 // Use it to perform any initialisation and allocation which is dependent
17 // userData holds an opaque pointer to a data structure that was passed 17 // userData holds an opaque pointer to a data structure that was passed
18 // in from the call to initAudio(). 18 // in from the call to initAudio().
19 // 19 //
20 // Return true on success; returning false halts the program. 20 // Return true on success; returning false halts the program.
21 21
22 bool initialise_render(int numMatrixChannels, int numAudioChannels, 22 bool initialise_render(BeagleRTContext *context, void *userData)
23 int numMatrixFramesPerPeriod,
24 int numAudioFramesPerPeriod,
25 float matrixSampleRate, float audioSampleRate,
26 void *userData)
27 { 23 {
28 // Nothing to do here... 24 // Nothing to do here...
29 25
30 return true; 26 return true;
31 } 27 }
33 // render() is called regularly at the highest priority by the audio engine. 29 // render() is called regularly at the highest priority by the audio engine.
34 // Input and output are given from the audio hardware and the other 30 // Input and output are given from the audio hardware and the other
35 // ADCs and DACs (if available). If only audio is available, numMatrixFrames 31 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
36 // will be 0. 32 // will be 0.
37 33
38 void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, 34 void render(BeagleRTContext *context, void *userData)
39 uint16_t *matrixIn, uint16_t *matrixOut)
40 { 35 {
41 // Simplest possible case: pass inputs through to outputs 36 // Simplest possible case: pass inputs through to outputs
42 for(int n = 0; n < numAudioFrames; n++) { 37 for(unsigned int n = 0; n < context->audioFrames; n++) {
43 for(int ch = 0; ch < gNumAudioChannels; ch++) 38 for(unsigned int ch = 0; ch < context->audioChannels; ch++)
44 audioOut[n * gNumAudioChannels + ch] = audioIn[n * gNumAudioChannels + ch]; 39 context->audioOut[n * context->audioChannels + ch] = context->audioIn[n * context->audioChannels + ch];
45 } 40 }
46 41
47 // Same with matrix, only if matrix is enabled 42 // Same with matrix, only if matrix is enabled
48 if(numMatrixFrames != 0) { 43 if(context->analogFrames != 0) {
49 for(int n = 0; n < numMatrixFrames; n++) { 44 for(unsigned int n = 0; n < context->analogFrames; n++) {
50 for(int ch = 0; ch < gNumMatrixChannels; ch++) { 45 for(unsigned int ch = 0; ch < context->analogChannels; ch++) {
51 // Two equivalent ways to write this code 46 // Two equivalent ways to write this code
52 // The long way, using the buffers directly: 47 // The long way, using the buffers directly:
53 // matrixOut[n * gNumMatrixChannels + ch] = matrixIn[n * gNumMatrixChannels + ch]; 48 // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch];
54 49
55 // Or using the macros: 50 // Or using the macros:
56 analogWrite(ch, n, analogRead(ch, n)); 51 analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch));
57 } 52 }
58 } 53 }
59 } 54 }
60 } 55 }
61 56
62 // cleanup_render() is called once at the end, after the audio has stopped. 57 // cleanup_render() is called once at the end, after the audio has stopped.
63 // Release any resources that were allocated in initialise_render(). 58 // Release any resources that were allocated in initialise_render().
64 59
65 void cleanup_render() 60 void cleanup_render(BeagleRTContext *context, void *userData)
66 { 61 {
67 62
68 } 63 }