Mercurial > hg > beaglert
comparison core/NetworkSend.cpp @ 116:8341df5e404b scope-refactoring
Refactoring
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 19 Aug 2015 23:22:39 +0100 |
parents | a0e24514fc97 |
children | c692827083e1 |
comparison
equal
deleted
inserted
replaced
115:a0e24514fc97 | 116:8341df5e404b |
---|---|
5 #define NETWORK_AUDIO_BUFFER_SIZE 302 | 5 #define NETWORK_AUDIO_BUFFER_SIZE 302 |
6 | 6 |
7 //initialize the static members of NetworkSend | 7 //initialize the static members of NetworkSend |
8 bool NetworkSend::staticConstructed=false; | 8 bool NetworkSend::staticConstructed=false; |
9 std::vector<NetworkSend*> NetworkSend::objAddrs(0); | 9 std::vector<NetworkSend*> NetworkSend::objAddrs(0); |
10 AuxiliaryTask NetworkSend::transmitAudioTask=NULL; | 10 AuxiliaryTask NetworkSend::sendDataTask=NULL; |
11 | 11 |
12 void transmitAudio(){ | 12 void transmitAudio(){ |
13 NetworkSend::sendAllData(); | 13 NetworkSend::sendAllData(); |
14 } | 14 } |
15 | 15 |
21 | 21 |
22 void NetworkSend::staticConstructor(){ | 22 void NetworkSend::staticConstructor(){ |
23 if(staticConstructed==true) | 23 if(staticConstructed==true) |
24 return; | 24 return; |
25 staticConstructed=true; | 25 staticConstructed=true; |
26 transmitAudioTask = BeagleRT_createAuxiliaryTask(transmitAudio, 95, "transmitAudioTask"); //TODO: allow variable priority | 26 sendDataTask = BeagleRT_createAuxiliaryTask(transmitAudio, 95, "sendDataTask"); //TODO: allow variable priority |
27 }; | 27 }; |
28 | 28 |
29 NetworkSend::NetworkSend() | 29 NetworkSend::NetworkSend() |
30 { | 30 { |
31 sampleCount = 0; | 31 sampleCount = 0; |
32 channel.doneOnTime=true; | 32 channel.doneOnTime=true; |
33 channel.index=channel.headerLength; //leave space for the heading message (channel, timestamp) | 33 channel.index=channel.headerLength; //leave space for the heading message (channel, timestamp) |
34 channel.activeBuffer=0; | 34 channel.activeBuffer=0; |
35 channel.readyToBeSent=false; | 35 channel.readyToBeSent=false; |
36 } | 36 } |
37 | |
37 NetworkSend::~NetworkSend(){ | 38 NetworkSend::~NetworkSend(){ |
38 for(unsigned int n=0; n<objAddrs.size(); n++){ //keep track of deleted instances; | 39 for(unsigned int n=0; n<objAddrs.size(); n++){ //keep track of deleted instances; |
39 if(objAddrs[n]==this){ | 40 if(objAddrs[n]==this){ |
40 objAddrs.erase(objAddrs.begin()+n); | 41 objAddrs.erase(objAddrs.begin()+n); |
41 break; | 42 break; |
59 setPort(aPort); | 60 setPort(aPort); |
60 setServer(aServer); | 61 setServer(aServer); |
61 printf("Channel %d is sending messages to : %s:%d at %fHz\n", getChannelNumber(), aServer, aPort, aSampleRate); | 62 printf("Channel %d is sending messages to : %s:%d at %fHz\n", getChannelNumber(), aServer, aPort, aSampleRate); |
62 } | 63 } |
63 | 64 |
64 | |
65 void NetworkSend::log(float value){ //TODO: add a vectorized version of this method | 65 void NetworkSend::log(float value){ //TODO: add a vectorized version of this method |
66 if(channel.index==(NETWORK_AUDIO_BUFFER_SIZE)){ // when the buffer is ready ... | 66 if(channel.index==(NETWORK_AUDIO_BUFFER_SIZE)){ // when the buffer is ready ... |
67 channel.readyToBeSent=true; | 67 channel.readyToBeSent=true; |
68 channel.index=channel.headerLength; //reset the counter | 68 channel.index=channel.headerLength; //reset the counter |
69 if(channel.doneOnTime==false){ | 69 if(channel.doneOnTime==false){ |
70 printf("Network buffer underrun. timestamp: %d :-{\n", (int)channel.buffers[!channel.activeBuffer][1]); | 70 printf("Network buffer underrun. timestamp: %d :-{\n", (int)channel.buffers[!channel.activeBuffer][1]); |
71 } | 71 } |
72 channel.activeBuffer=!channel.activeBuffer; //switch buffer | 72 channel.activeBuffer=!channel.activeBuffer; //switch buffer |
73 channel.doneOnTime=false; | 73 channel.doneOnTime=false; |
74 BeagleRT_scheduleAuxiliaryTask(NetworkSend::transmitAudioTask); //send the buffer | 74 BeagleRT_scheduleAuxiliaryTask(NetworkSend::sendDataTask); //send the buffer |
75 //TODO: maybe we should have transmitAudioTask running in a loop instead of scheduling it multiple times? | 75 //TODO: maybe we should have transmitAudioTask running in a loop instead of scheduling it multiple times? |
76 } | 76 } |
77 if(channel.index==channel.headerLength){ | 77 if(channel.index==channel.headerLength){ |
78 channel.buffers[channel.activeBuffer][0] = (float)channel.channelNumber; //TODO: this could actually be done just once in setup() | 78 channel.buffers[channel.activeBuffer][0] = (float)channel.channelNumber; //TODO: this could actually be done just once in setup() |
79 channel.buffers[channel.activeBuffer][1]=(float)sampleCount; //timestamp | 79 channel.buffers[channel.activeBuffer][1]=(float)sampleCount; //timestamp |