annotate projects/basic_passthru/render.cpp @ 68:59edd5780fef

Changed d-box code to run cleanly when built on board. Updated Makefile to add ne10 include path on board. Some extra docs in Utilities.h
author andrewm
date Fri, 17 Jul 2015 16:57:08 +0100
parents 3c3a1357657d
children 1e629f126322
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@56 9 #include <BeagleRT.h>
andrewm@56 10 #include <Utilities.h>
andrewm@13 11 #include <rtdk.h>
andrewm@13 12
andrewm@56 13 // setup() 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@56 22 bool setup(BeagleRTContext *context, void *userData)
andrewm@13 23 {
andrewm@13 24 // Nothing to do here...
andrewm@13 25
andrewm@13 26 return true;
andrewm@13 27 }
andrewm@13 28
andrewm@13 29 // render() is called regularly at the highest priority by the audio engine.
andrewm@13 30 // Input and output are given from the audio hardware and the other
andrewm@13 31 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
andrewm@13 32 // will be 0.
andrewm@13 33
andrewm@52 34 void render(BeagleRTContext *context, void *userData)
andrewm@13 35 {
andrewm@13 36 // Simplest possible case: pass inputs through to outputs
andrewm@52 37 for(unsigned int n = 0; n < context->audioFrames; n++) {
andrewm@52 38 for(unsigned int ch = 0; ch < context->audioChannels; ch++)
andrewm@52 39 context->audioOut[n * context->audioChannels + ch] = context->audioIn[n * context->audioChannels + ch];
andrewm@13 40 }
andrewm@13 41
andrewm@13 42 // Same with matrix, only if matrix is enabled
andrewm@52 43 if(context->analogFrames != 0) {
andrewm@52 44 for(unsigned int n = 0; n < context->analogFrames; n++) {
andrewm@52 45 for(unsigned int ch = 0; ch < context->analogChannels; ch++) {
andrewm@13 46 // Two equivalent ways to write this code
andrewm@13 47 // The long way, using the buffers directly:
andrewm@52 48 // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch];
andrewm@13 49
andrewm@13 50 // Or using the macros:
andrewm@52 51 analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch));
andrewm@13 52 }
andrewm@13 53 }
andrewm@13 54 }
andrewm@13 55 }
andrewm@13 56
andrewm@56 57 // cleanup() is called once at the end, after the audio has stopped.
andrewm@56 58 // Release any resources that were allocated in setup().
andrewm@13 59
andrewm@56 60 void cleanup(BeagleRTContext *context, void *userData)
andrewm@13 61 {
andrewm@13 62
andrewm@13 63 }