comparison projects/basic_passthru/render.cpp @ 13:6adb088196a7

Fixed ADC bug; added a simple passthrough test
author andrewm
date Fri, 23 Jan 2015 15:17:09 +0000
parents
children a6d223473ea2
comparison
equal deleted inserted replaced
12:a6beeba3a648 13:6adb088196a7
1 /*
2 * render.cpp
3 *
4 * Created on: Oct 24, 2014
5 * Author: parallels
6 */
7
8
9 #include "../../include/render.h"
10 #include "../../include/Utilities.h"
11 #include <rtdk.h>
12
13 // initialise_render() is called once before the audio rendering starts.
14 // Use it to perform any initialisation and allocation which is dependent
15 // on the period size or sample rate.
16 //
17 // userData holds an opaque pointer to a data structure that was passed
18 // in from the call to initAudio().
19 //
20 // Return true on success; returning false halts the program.
21
22 bool initialise_render(int numMatrixChannels, int numAudioChannels,
23 int numMatrixFramesPerPeriod,
24 int numAudioFramesPerPeriod,
25 float matrixSampleRate, float audioSampleRate,
26 void *userData)
27 {
28 // Nothing to do here...
29
30 return true;
31 }
32
33 // 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
35 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
36 // will be 0.
37
38 void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut,
39 uint16_t *matrixIn, uint16_t *matrixOut)
40 {
41 // Simplest possible case: pass inputs through to outputs
42 for(int n = 0; n < numAudioFrames; n++) {
43 for(int ch = 0; ch < gNumAudioChannels; ch++)
44 audioOut[n * gNumAudioChannels + ch] = audioIn[n * gNumAudioChannels + ch];
45 }
46
47 // Same with matrix, only if matrix is enabled
48 if(numMatrixFrames != 0) {
49 for(int n = 0; n < numMatrixFrames; n++) {
50 for(int ch = 0; ch < gNumMatrixChannels; ch++) {
51 // Two equivalent ways to write this code
52 // The long way, using the buffers directly:
53 // matrixOut[n * gNumMatrixChannels + ch] = matrixIn[n * gNumMatrixChannels + ch];
54
55 // Or using the macros:
56 analogWrite(ch, n, analogRead(ch, n));
57 }
58 }
59 }
60 }
61
62 // cleanup_render() is called once at the end, after the audio has stopped.
63 // Release any resources that were allocated in initialise_render().
64
65 void cleanup_render()
66 {
67
68 }