giuliomoro@94: /* giuliomoro@94: * render.cpp giuliomoro@94: * giuliomoro@94: * Created on: Oct 24, 2014 giuliomoro@94: * Author: parallels giuliomoro@94: */ giuliomoro@94: giuliomoro@94: #include giuliomoro@94: #include giuliomoro@94: #include giuliomoro@94: giuliomoro@94: float gFrequency; giuliomoro@94: float gPhase; giuliomoro@94: float gInverseSampleRate; giuliomoro@94: int gCount=0; giuliomoro@94: networkData networkObject; giuliomoro@94: AuxiliaryTask transmitReceiveDataTask; giuliomoro@94: giuliomoro@94: void transmitReceiveData(){ giuliomoro@94: printf("transmitReceiveData auxiliary task has started\n"); giuliomoro@94: while(!gShouldStop){ giuliomoro@94: sendMessage(networkObject); giuliomoro@94: receiveMessage(networkObject); giuliomoro@94: usleep(1000); giuliomoro@94: } giuliomoro@94: closeSockets(); giuliomoro@94: } giuliomoro@94: giuliomoro@94: // setup() is called once before the audio rendering starts. giuliomoro@94: // Use it to perform any initialisation and allocation which is dependent giuliomoro@94: // on the period size or sample rate. giuliomoro@94: // giuliomoro@94: // userData holds an opaque pointer to a data structure that was passed giuliomoro@94: // in from the call to initAudio(). giuliomoro@94: // giuliomoro@94: // Return true on success; returning false halts the program. giuliomoro@94: bool setup(BeagleRTContext *context, void *userData) giuliomoro@94: { giuliomoro@94: // Retrieve a parameter passed in from the initAudio() call giuliomoro@94: gFrequency = *(float *)userData; giuliomoro@94: giuliomoro@94: gInverseSampleRate = 1.0 / context->audioSampleRate; giuliomoro@94: gPhase = 0.0; giuliomoro@94: giuliomoro@94: networkObject.counter=&gCount; giuliomoro@94: networkObject.variables[0]=&gFrequency; giuliomoro@94: networkObject.variables[1]=&gPhase; giuliomoro@94: networkObject.numVariables=2; giuliomoro@94: giuliomoro@94: setupSockets(settings->receivePort, settings->transmitPort, settings->serverName); giuliomoro@94: transmitReceiveDataTask= BeagleRT_createAuxiliaryTask(*transmitReceiveData, 80, "transmit-receive-data"); giuliomoro@94: //scheduleAuxiliaryTask(transmitReceiveDataTask); //here it does not work giuliomoro@94: return true; giuliomoro@94: } giuliomoro@94: giuliomoro@94: // render() is called regularly at the highest priority by the audio engine. giuliomoro@94: // Input and output are given from the audio hardware and the other giuliomoro@94: // ADCs and DACs (if available). If only audio is available, numMatrixFrames giuliomoro@94: // will be 0. giuliomoro@94: giuliomoro@94: void render(BeagleRTContext *context, void *userData) giuliomoro@94: { giuliomoro@94: for(unsigned int n = 0; n < context->audioFrames; n++) { giuliomoro@94: float out = 0.7f * sinf(gPhase); giuliomoro@94: gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; giuliomoro@94: if(gPhase > 2.0 * M_PI) giuliomoro@94: gPhase -= 2.0 * M_PI; giuliomoro@94: giuliomoro@94: for(unsigned int channel = 0; channel < context->audioChannels; channel++) giuliomoro@94: context->audioOut[n * context->audioChannels + channel] = out; giuliomoro@94: giuliomoro@94: if(gCount == 0){ giuliomoro@94: BeagleRT_scheduleAuxiliaryTask(transmitReceiveDataTask); giuliomoro@94: } giuliomoro@94: gCount++; giuliomoro@94: } giuliomoro@94: } giuliomoro@94: giuliomoro@94: // cleanup() is called once at the end, after the audio has stopped. giuliomoro@94: // Release any resources that were allocated in setup(). giuliomoro@94: giuliomoro@94: void cleanup(BeagleRTContext *context, void *userData) giuliomoro@94: { giuliomoro@94: }