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@56: #include andrewm@56: #include andrewm@13: #include andrewm@13: andrewm@56: // setup() 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@56: bool setup(BeagleRTContext *context, 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@52: void render(BeagleRTContext *context, void *userData) andrewm@13: { andrewm@13: // Simplest possible case: pass inputs through to outputs andrewm@52: for(unsigned int n = 0; n < context->audioFrames; n++) { andrewm@52: for(unsigned int ch = 0; ch < context->audioChannels; ch++) andrewm@52: context->audioOut[n * context->audioChannels + ch] = context->audioIn[n * context->audioChannels + ch]; andrewm@13: } andrewm@13: andrewm@13: // Same with matrix, only if matrix is enabled andrewm@52: if(context->analogFrames != 0) { andrewm@52: for(unsigned int n = 0; n < context->analogFrames; n++) { andrewm@52: for(unsigned int ch = 0; ch < context->analogChannels; ch++) { andrewm@13: // Two equivalent ways to write this code andrewm@13: // The long way, using the buffers directly: andrewm@52: // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch]; andrewm@13: andrewm@13: // Or using the macros: andrewm@52: analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch)); andrewm@13: } andrewm@13: } andrewm@13: } andrewm@13: } andrewm@13: andrewm@56: // cleanup() is called once at the end, after the audio has stopped. andrewm@56: // Release any resources that were allocated in setup(). andrewm@13: andrewm@56: void cleanup(BeagleRTContext *context, void *userData) andrewm@13: { andrewm@13: andrewm@13: }