andrewm@13: /* andrewm@13: * render.cpp andrewm@13: * andrewm@13: * Created on: Oct 24, 2014 andrewm@13: * Author: parallels andrewm@13: */ andrewm@13: andrewm@13: andrewm@13: #include "../../include/render.h" andrewm@13: #include "../../include/Utilities.h" andrewm@13: #include andrewm@13: andrewm@13: // initialise_render() is called once before the audio rendering starts. andrewm@13: // Use it to perform any initialisation and allocation which is dependent andrewm@13: // on the period size or sample rate. andrewm@13: // andrewm@13: // userData holds an opaque pointer to a data structure that was passed andrewm@13: // in from the call to initAudio(). andrewm@13: // andrewm@13: // Return true on success; returning false halts the program. andrewm@13: andrewm@13: bool initialise_render(int numMatrixChannels, int numAudioChannels, andrewm@13: int numMatrixFramesPerPeriod, andrewm@13: int numAudioFramesPerPeriod, andrewm@13: float matrixSampleRate, float audioSampleRate, andrewm@13: void *userData) andrewm@13: { andrewm@13: // Nothing to do here... andrewm@13: andrewm@13: return true; andrewm@13: } andrewm@13: andrewm@13: // render() is called regularly at the highest priority by the audio engine. andrewm@13: // Input and output are given from the audio hardware and the other andrewm@13: // ADCs and DACs (if available). If only audio is available, numMatrixFrames andrewm@13: // will be 0. andrewm@13: andrewm@13: void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, andrewm@13: uint16_t *matrixIn, uint16_t *matrixOut) andrewm@13: { andrewm@13: // Simplest possible case: pass inputs through to outputs andrewm@13: for(int n = 0; n < numAudioFrames; n++) { andrewm@13: for(int ch = 0; ch < gNumAudioChannels; ch++) andrewm@13: audioOut[n * gNumAudioChannels + ch] = audioIn[n * gNumAudioChannels + ch]; andrewm@13: } andrewm@13: andrewm@13: // Same with matrix, only if matrix is enabled andrewm@13: if(numMatrixFrames != 0) { andrewm@13: for(int n = 0; n < numMatrixFrames; n++) { andrewm@13: for(int ch = 0; ch < gNumMatrixChannels; ch++) { andrewm@13: // Two equivalent ways to write this code andrewm@13: // The long way, using the buffers directly: andrewm@13: // matrixOut[n * gNumMatrixChannels + ch] = matrixIn[n * gNumMatrixChannels + ch]; andrewm@13: andrewm@13: // Or using the macros: andrewm@13: analogWrite(ch, n, analogRead(ch, n)); andrewm@13: } andrewm@13: } andrewm@13: } andrewm@13: } andrewm@13: andrewm@13: // cleanup_render() is called once at the end, after the audio has stopped. andrewm@13: // Release any resources that were allocated in initialise_render(). andrewm@13: andrewm@13: void cleanup_render() andrewm@13: { andrewm@13: andrewm@13: }