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@24: #include andrewm@56: #include andrewm@56: giuliomoro@24: float gFrequency; giuliomoro@24: float gPhase; giuliomoro@24: float gInverseSampleRate; giuliomoro@24: int gCount=0; giuliomoro@24: networkData networkObject; giuliomoro@24: AuxiliaryTask transmitReceiveDataTask; giuliomoro@24: giuliomoro@24: void transmitReceiveData(){ giuliomoro@25: printf("transmitReceiveData auxiliary task has started\n"); giuliomoro@24: while(!gShouldStop){ giuliomoro@25: sendMessage(networkObject); giuliomoro@25: receiveMessage(networkObject); giuliomoro@25: usleep(1000); giuliomoro@24: } giuliomoro@24: closeSockets(); giuliomoro@24: } giuliomoro@24: 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. 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: andrewm@56: gInverseSampleRate = 1.0 / context->audioSampleRate; giuliomoro@24: gPhase = 0.0; giuliomoro@24: giuliomoro@24: networkObject.counter=&gCount; giuliomoro@24: networkObject.variables[0]=&gFrequency; giuliomoro@24: networkObject.variables[1]=&gPhase; giuliomoro@24: networkObject.numVariables=2; andrewm@56: giuliomoro@24: setupSockets(settings->receivePort, settings->transmitPort, settings->serverName); andrewm@56: transmitReceiveDataTask= BeagleRT_createAuxiliaryTask(*transmitReceiveData, 80, "transmit-receive-data"); giuliomoro@24: //scheduleAuxiliaryTask(transmitReceiveDataTask); //here it does not work 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@24: { 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: andrewm@56: for(unsigned int channel = 0; channel < context->audioChannels; channel++) andrewm@56: context->audioOut[n * context->audioChannels + channel] = out; andrewm@56: andrewm@56: if(gCount == 0){ andrewm@56: BeagleRT_scheduleAuxiliaryTask(transmitReceiveDataTask); giuliomoro@24: } giuliomoro@24: gCount++; giuliomoro@24: } 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: }