giuliomoro@24: /* giuliomoro@24: * render.cpp giuliomoro@24: * giuliomoro@24: * Created on: Oct 24, 2014 giuliomoro@24: * Author: parallels giuliomoro@24: */ giuliomoro@24: giuliomoro@24: #include "../../include/RTAudioSettings.h" giuliomoro@24: #include "../../include/render.h" giuliomoro@24: #include giuliomoro@54: //#include "../../include/client.h" giuliomoro@24: #include "../../include/RTAudio.h" // to schedule lower prio parallel process giuliomoro@24: #include giuliomoro@41: #include giuliomoro@41: #include "../../include/PRU.h" giuliomoro@54: #include "../../include/UdpClient.h" giuliomoro@54: giuliomoro@54: #define NETWORK_AUDIO_BUFFER_SIZE 400 //1400/4 //maximum payload for a UDP datagram over ethernet is 1472 bytes, I leave some headroom and divide by 4 to get the number of floats giuliomoro@54: struct networkAudio{ giuliomoro@54: int timestamp; giuliomoro@54: int currentBuffer; giuliomoro@54: int index; giuliomoro@54: float buffers[2][NETWORK_AUDIO_BUFFER_SIZE]; giuliomoro@54: int doneOnTime; giuliomoro@54: bool toBeSent; giuliomoro@54: UdpClient udpClient; giuliomoro@54: }; giuliomoro@54: giuliomoro@24: float gFrequency; giuliomoro@24: float gPhase; giuliomoro@24: float gInverseSampleRate; giuliomoro@24: int gCount=0; giuliomoro@54: //networkData networkObject; giuliomoro@54: #define numNetAudio 3 giuliomoro@54: networkAudio netAudio[numNetAudio]; giuliomoro@41: extern PRU *gPRU; giuliomoro@41: AuxiliaryTask printIntervalTask; giuliomoro@41: AuxiliaryTask transmitReceiveAudioTask; giuliomoro@41: void transmitReceiveData(){ //transmit and receive asynchronous messages giuliomoro@41: // printf("transmitReceiveData auxiliary task has started\n"); giuliomoro@41: // while(!gShouldStop){ giuliomoro@41: // sendMessage(&networkObject); giuliomoro@41: // receiveMessage(networkObject); giuliomoro@41: // usleep(1000); giuliomoro@41: // } giuliomoro@41: // closeSockets(); giuliomoro@41: } giuliomoro@24: giuliomoro@41: void transmitReceiveAudio(){ //transmit and receive audio buffers giuliomoro@54: for(int n=0;ntransmitPort+n); giuliomoro@54: netAudio[n].udpClient.setServer(settings->serverName); giuliomoro@54: } giuliomoro@41: // setupSockets(settings->receivePort, settings->transmitPort, settings->serverName); giuliomoro@54: giuliomoro@54: // transmitReceiveDataTask=createAuxiliaryTaskLoop(*transmitReceiveData, 10, "transmit-receive-data"); giuliomoro@54: // scheduleAuxiliaryTask(transmitReceiveDataTask); //here it does not work giuliomoro@54: transmitReceiveAudioTask=createAuxiliaryTaskLoop(*transmitReceiveAudio, 98, "transmit-receive-audio"); 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: giuliomoro@24: void render(int numAnalogFrames, int numAudioFrames, int numDigitalFrames, float *audioIn, float *audioOut, giuliomoro@24: float *analogIn, float *analogOut, uint32_t *digital) giuliomoro@24: { giuliomoro@24: for(int n = 0; n < numAudioFrames; 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@41: // for(int channel = 0; channel < gNumAudioChannels; channel++) giuliomoro@41: // audioOut[n * gNumAudioChannels + channel] = audioIn[n * gNumAudioChannels + 0]+audioIn[n * gNumAudioChannels + 1]; giuliomoro@54: audioOut[n * gNumAudioChannels] = audioIn[n*gNumAudioChannels+0]; giuliomoro@41: audioOut[n * gNumAudioChannels+1]=out; giuliomoro@41: if(0==gCount){ giuliomoro@41: // scheduleAuxiliaryTask(transmitReceiveDataTask); giuliomoro@24: } giuliomoro@54: for(int j=0; j