annotate include/Scope.h @ 105:39962292dfb4

Removed old client.? entries from Makefile
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 27 Jul 2015 18:53:00 +0100
parents 8c7f537d0a21
children 836052c86e1e
rev   line source
andrewm@71 1 //scope.cpp
andrewm@71 2 #include <BeagleRT.h>
andrewm@71 3 #include <rtdk.h>
andrewm@71 4 #include <cmath>
andrewm@71 5 #include <UdpClient.h>
andrewm@71 6
giuliomoro@93 7 #define NETWORK_AUDIO_BUFFER_SIZE 400
andrewm@71 8 struct networkAudio{
andrewm@71 9 int timestamp;
andrewm@71 10 int currentBuffer;
andrewm@71 11 int index;
andrewm@71 12 float buffers[2][NETWORK_AUDIO_BUFFER_SIZE];
andrewm@71 13 int doneOnTime;
andrewm@71 14 bool toBeSent;
andrewm@71 15 UdpClient udpClient;
andrewm@71 16 };
andrewm@71 17
andrewm@71 18 #define NUM_SCOPE_CHANNELS 6
andrewm@71 19
andrewm@71 20 static void SendScopeData();
andrewm@71 21
andrewm@71 22 class Scope {
andrewm@71 23 int sampleCount;
andrewm@71 24 float sampleRate;
andrewm@71 25 AuxiliaryTask scopeTask;
andrewm@71 26 public:
andrewm@71 27 int numChannels;
andrewm@71 28 networkAudio channel[NUM_SCOPE_CHANNELS];
andrewm@71 29 Scope(){
andrewm@71 30 numChannels = NUM_SCOPE_CHANNELS;
andrewm@71 31 sampleCount = 0;
andrewm@71 32
andrewm@71 33 for(int n=0; n<numChannels; n++){
andrewm@71 34 channel[n].doneOnTime=1;
giuliomoro@93 35 channel[n].index=2; //leave space for the heading message (channel, timestamp)
andrewm@71 36 channel[n].timestamp=0;
andrewm@71 37 channel[n].currentBuffer=0;
andrewm@71 38 channel[n].toBeSent=false;
giuliomoro@93 39 #ifdef BUILD_FOR_UDPRECEIVE_PLUGIN
giuliomoro@93 40 channel[n].udpClient.setPort(9999+n);
giuliomoro@93 41 channel[n].udpClient.setServer("192.168.7.1");
giuliomoro@93 42 #else
andrewm@71 43 channel[n].udpClient.setPort(9999);
andrewm@71 44 channel[n].udpClient.setServer("127.0.0.1");
giuliomoro@93 45 #endif /* BUILD_FOR_UDPRECEIVE_PLUGIN */
andrewm@71 46 }
andrewm@71 47 }
andrewm@71 48 void setup(float _sampleRate);
andrewm@71 49 void log(float channel1=0.0, float channel2=0.0, float channel3=0.0, float channel4=0.0, float channel5=0.0, float channel6=0.0){
andrewm@71 50
andrewm@71 51 for(int j=0; j<numChannels; j++){
andrewm@71 52 if(channel[j].index==(NETWORK_AUDIO_BUFFER_SIZE)){ // when the buffer is ready ...
andrewm@71 53 channel[j].buffers[channel[j].currentBuffer][0] = (float)j;
andrewm@71 54 channel[j].buffers[channel[j].currentBuffer][1] = (float)channel[j].timestamp;
andrewm@71 55 channel[j].toBeSent=true;
andrewm@71 56 channel[j].index=2; //reset the counter
andrewm@71 57 if(channel[j].doneOnTime==0)
andrewm@71 58 rt_printf("Network buffer underrun :-{\n");
andrewm@71 59 channel[j].timestamp=sampleCount;
andrewm@71 60 channel[j].currentBuffer=!channel[j].currentBuffer; //switch buffer
andrewm@71 61 channel[j].doneOnTime=0;
andrewm@71 62 BeagleRT_scheduleAuxiliaryTask(scopeTask); //send the buffer
andrewm@71 63 }
andrewm@71 64 }
andrewm@71 65
andrewm@71 66 channel[0].buffers[channel[0].currentBuffer][channel[0].index++]=channel1;
andrewm@71 67 channel[1].buffers[channel[1].currentBuffer][channel[1].index++]=channel2;
andrewm@71 68 channel[2].buffers[channel[2].currentBuffer][channel[2].index++]=channel3;
andrewm@71 69 channel[3].buffers[channel[3].currentBuffer][channel[3].index++]=channel4;
andrewm@71 70 channel[4].buffers[channel[4].currentBuffer][channel[4].index++]=channel5;
andrewm@71 71 channel[5].buffers[channel[5].currentBuffer][channel[5].index++]=channel6;
andrewm@71 72
andrewm@71 73 sampleCount++;
andrewm@71 74 }
andrewm@71 75 };
andrewm@71 76
andrewm@71 77 Scope* gOscilloscopeInstance;
andrewm@71 78
andrewm@71 79 void Scope::setup(float _sampleRate){
andrewm@71 80 sampleRate = _sampleRate;
andrewm@71 81 gOscilloscopeInstance = this;
andrewm@71 82 scopeTask = BeagleRT_createAuxiliaryTask(*SendScopeData, 98, "transmit-receive-audio");
andrewm@71 83 }
andrewm@71 84
andrewm@71 85 //Scope scope;
andrewm@71 86
andrewm@71 87 static void SendScopeData(){
andrewm@71 88 for(int n=0; n<gOscilloscopeInstance->numChannels; n++){
andrewm@71 89 if(gOscilloscopeInstance->channel[n].toBeSent){
andrewm@71 90 gOscilloscopeInstance->channel[n].toBeSent=false;
giuliomoro@93 91 gOscilloscopeInstance->channel[n].udpClient.send(
giuliomoro@93 92 gOscilloscopeInstance->channel[n].buffers[!gOscilloscopeInstance->channel[n].currentBuffer],
giuliomoro@93 93 NETWORK_AUDIO_BUFFER_SIZE*sizeof(float)
giuliomoro@93 94 );
andrewm@71 95 gOscilloscopeInstance->channel[n].doneOnTime=1;
andrewm@71 96 }
andrewm@71 97 }
andrewm@71 98 }