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: giuliomoro@174: AuxiliaryTask taskOne; giuliomoro@174: AuxiliaryTask taskTwo; giuliomoro@174: void funOne(){ giuliomoro@174: rt_printf("setup\n"); giuliomoro@174: } giuliomoro@174: void funTwo(){ giuliomoro@174: rt_printf("render\n"); giuliomoro@174: } andrewm@56: bool setup(BeagleRTContext *context, void *userData) andrewm@13: { andrewm@13: // Nothing to do here... giuliomoro@174: // taskOne = BeagleRT_createAuxiliaryTask(funOne, 1, "funOne"); giuliomoro@174: // taskTwo = BeagleRT_createAuxiliaryTask(funTwo, 99, "funTwo"); giuliomoro@174: // BeagleRT_scheduleAuxiliaryTask(taskOne); 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: { giuliomoro@174: // if(context->audioSampleCount % 16384 == 0) giuliomoro@174: // BeagleRT_scheduleAuxiliaryTask(taskTwo); 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++) giuliomoro@174: context->audioOut[n * context->audioChannels + ch] = giuliomoro@174: context->audioIn[n * context->audioChannels + ch]; andrewm@13: } andrewm@13: andrewm@13: // Same with matrix, only if matrix is enabled giuliomoro@174: // if(context->analogFrames != 0) { giuliomoro@174: // for(unsigned int n = 0; n < context->analogFrames; n++) { giuliomoro@174: // for(unsigned int ch = 0; ch < context->analogChannels; ch++) { giuliomoro@174: // // Two equivalent ways to write this code giuliomoro@174: // // The long way, using the buffers directly: giuliomoro@174: // // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch]; giuliomoro@174: // giuliomoro@174: // // Or using the macros: giuliomoro@174: // analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch)); giuliomoro@174: // } giuliomoro@174: // } giuliomoro@174: // } 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: }