giuliomoro@24: /* giuliomoro@24: * render.cpp giuliomoro@24: * giuliomoro@24: * Created on: Oct 24, 2014 giuliomoro@24: * Author: parallels giuliomoro@24: */ giuliomoro@24: andrewm@56: #include giuliomoro@92: //#include giuliomoro@24: #include giuliomoro@221: #include giuliomoro@92: #include giuliomoro@92: andrewm@56: // setup() is called once before the audio rendering starts. giuliomoro@24: // Use it to perform any initialisation and allocation which is dependent giuliomoro@24: // on the period size or sample rate. giuliomoro@24: // giuliomoro@24: // userData holds an opaque pointer to a data structure that was passed giuliomoro@24: // in from the call to initAudio(). giuliomoro@24: // giuliomoro@24: // Return true on success; returning false halts the program. giuliomoro@221: giuliomoro@221: NetworkSend networkSend; giuliomoro@221: float gFrequency; giuliomoro@221: float gInverseSampleRate; giuliomoro@221: float gPhase; andrewm@56: bool setup(BeagleRTContext *context, void *userData) giuliomoro@24: { giuliomoro@24: // Retrieve a parameter passed in from the initAudio() call giuliomoro@24: gFrequency = *(float *)userData; giuliomoro@24: giuliomoro@221: networkSend.setup(context->audioSampleRate, context->audioFrames, 3, 9999, "192.168.7.1"); andrewm@56: gInverseSampleRate = 1.0 / context->audioSampleRate; giuliomoro@221: gPhase = 0.2132; giuliomoro@24: return true; giuliomoro@24: } giuliomoro@24: giuliomoro@24: // render() is called regularly at the highest priority by the audio engine. giuliomoro@24: // Input and output are given from the audio hardware and the other giuliomoro@24: // ADCs and DACs (if available). If only audio is available, numMatrixFrames giuliomoro@24: // will be 0. giuliomoro@24: andrewm@56: void render(BeagleRTContext *context, void *userData) giuliomoro@221: { andrewm@56: for(unsigned int n = 0; n < context->audioFrames; n++) { giuliomoro@24: float out = 0.7f * sinf(gPhase); giuliomoro@24: gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; giuliomoro@24: if(gPhase > 2.0 * M_PI) giuliomoro@24: gPhase -= 2.0 * M_PI; giuliomoro@24: giuliomoro@221: for(unsigned int channel = 0; channel < context->audioChannels; channel++){ andrewm@56: context->audioOut[n * context->audioChannels + channel] = out; giuliomoro@24: } giuliomoro@221: networkSend.log(out); giuliomoro@92: } giuliomoro@24: } giuliomoro@24: andrewm@56: // cleanup() is called once at the end, after the audio has stopped. andrewm@56: // Release any resources that were allocated in setup(). giuliomoro@24: andrewm@56: void cleanup(BeagleRTContext *context, void *userData) giuliomoro@24: { giuliomoro@24: }