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: giuliomoro@301: #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: giuliomoro@301: bool setup(BelaContext *context, void *userData) andrewm@13: { andrewm@13: // Nothing to do here... 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: giuliomoro@301: void render(BelaContext *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++) { giuliomoro@180: for(unsigned int ch = 0; ch < context->audioChannels; ch++){ giuliomoro@180: // Two equivalent ways to write this code giuliomoro@180: giuliomoro@180: // The long way, using the buffers directly: giuliomoro@180: // context->audioOut[n * context->audioChannels + ch] = giuliomoro@180: // context->audioIn[n * context->audioChannels + ch]; giuliomoro@180: giuliomoro@180: // Or using the macros: andrewm@308: audioWrite(context, n, ch, audioRead(context, n, ch)); giuliomoro@180: } andrewm@13: } andrewm@13: giuliomoro@180: // Same with analog channelss giuliomoro@180: for(unsigned int n = 0; n < context->analogFrames; n++) { giuliomoro@180: for(unsigned int ch = 0; ch < context->analogChannels; ch++) { giuliomoro@180: // Two equivalent ways to write this code giuliomoro@180: giuliomoro@180: // The long way, using the buffers directly: giuliomoro@180: // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch]; giuliomoro@180: giuliomoro@180: // Or using the macros: andrewm@308: analogWrite(context, n, ch, analogRead(context, n, ch)); giuliomoro@180: } giuliomoro@180: } 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: giuliomoro@301: void cleanup(BelaContext *context, void *userData) andrewm@13: { andrewm@13: andrewm@13: }