annotate projects/basic_passthru/render.cpp @ 37:b3661e68918c bbb_network

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