Mercurial > hg > beaglert
comparison core/NetworkSend.cpp @ 120:cdd441a304a9 scope-refactoring
Added read to interleaved buffer
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 21 Aug 2015 15:52:37 +0100 |
parents | c692827083e1 |
children | cce58e6ec2a2 |
comparison
equal
deleted
inserted
replaced
119:c692827083e1 | 120:cdd441a304a9 |
---|---|
45 } | 45 } |
46 | 46 |
47 void NetworkSend::setup(float aSampleRate){ | 47 void NetworkSend::setup(float aSampleRate){ |
48 setup(aSampleRate, 0, 9999, "192.168.7.1");//channelNumber=0 | 48 setup(aSampleRate, 0, 9999, "192.168.7.1");//channelNumber=0 |
49 } | 49 } |
50 | |
51 void NetworkSend::setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer){ | 50 void NetworkSend::setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer){ |
52 staticConstructor(); //FIXME: ideally this should be in the constructor, but this is not currently possible | 51 staticConstructor(); //FIXME: ideally this should be in the constructor, but this is not currently possible |
53 //because of limitations in BeagleRT_createAuxiliaryTask() | 52 //because of limitations in BeagleRT_createAuxiliaryTask() |
54 //keep track of added active instances | 53 //keep track of added active instances |
55 objAddrs.push_back(this);//TODO: this line should be in the constructor, but something weird happens if | 54 objAddrs.push_back(this);//TODO: this line should be in the constructor, but something weird happens if |
57 // and objAddrs.size()==1 but when you get to setup, objAddrs.size() has reverted back to 0, without | 56 // and objAddrs.size()==1 but when you get to setup, objAddrs.size() has reverted back to 0, without |
58 // any destructor being called in between ... | 57 // any destructor being called in between ... |
59 setChannelNumber(aChannelNumber); | 58 setChannelNumber(aChannelNumber); |
60 setPort(aPort); | 59 setPort(aPort); |
61 setServer(aServer); | 60 setServer(aServer); |
62 printf("Channel %d is sending messages to : %s:%d at %fHz\n", getChannelNumber(), aServer, aPort, aSampleRate); | 61 printf("Channel %d is sending messages to: %s:%d at %fHz\n", getChannelNumber(), aServer, aPort, aSampleRate); |
63 } | 62 } |
64 | 63 |
65 void NetworkSend::log(float value){ //TODO: add a vectorized version of this method | 64 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 ... | 65 if(channel.index==(NETWORK_AUDIO_BUFFER_SIZE)){ // when the buffer is ready ... |
67 channel.readyToBeSent=true; | 66 channel.readyToBeSent=true; |
70 printf("Network buffer underrun. timestamp: %d :-{\n", (int)channel.buffers[!channel.activeBuffer][1]); | 69 printf("Network buffer underrun. timestamp: %d :-{\n", (int)channel.buffers[!channel.activeBuffer][1]); |
71 } | 70 } |
72 channel.activeBuffer=!channel.activeBuffer; //switch buffer | 71 channel.activeBuffer=!channel.activeBuffer; //switch buffer |
73 channel.doneOnTime=false; | 72 channel.doneOnTime=false; |
74 BeagleRT_scheduleAuxiliaryTask(NetworkSend::sendDataTask); //send the buffer | 73 BeagleRT_scheduleAuxiliaryTask(NetworkSend::sendDataTask); //send the buffer |
75 //TODO: maybe we should have transmitAudioTask running in a loop instead of scheduling it multiple times? | 74 // TODO: maybe we should have transmitAudioTask running in a loop instead of scheduling it multiple times? |
75 // The current solution allows to minimize latency when a single channel is used, as there is no inherent | |
76 // rt_task_sleep in the thread, as we are signaling it every time. | |
77 // Although, there is a possible race condition: if the auxiliaryTask is scheduled by channel 0, | |
78 // it might still be executing when channel 1 schedules it. But if the AuxTask has already skipped | |
79 // over channel 1, then we are at risk that channel 1 never gets sent. | |
76 } | 80 } |
77 if(channel.index==channel.headerLength){ | 81 if(channel.index==channel.headerLength){ |
78 channel.buffers[channel.activeBuffer][0] = (float)channel.channelNumber; //TODO: this could actually be done just once in setup() | 82 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 | 83 channel.buffers[channel.activeBuffer][1]=(float)sampleCount; //timestamp |
80 //add here more header fields | 84 //add here more header fields |
136 void Scope::setPort(int port){ | 140 void Scope::setPort(int port){ |
137 for(int n=0; n<getNumChannels(); n++){ | 141 for(int n=0; n<getNumChannels(); n++){ |
138 channels[n].setPort(port); | 142 channels[n].setPort(port); |
139 } | 143 } |
140 } | 144 } |
141 void Scope::setPort(int channel, int port){ | 145 void Scope::setPort(int channel, int aPort){ |
142 channels[channel].setPort(port); | 146 channels[channel].setPort(aPort); |
147 printf("Channel %d is now sending to port %d\n", channel, aPort); | |
143 } | 148 } |
144 | 149 |
145 int Scope::getNumChannels(){ | 150 int Scope::getNumChannels(){ |
146 return channels.size(); | 151 return channels.size(); |
147 } | 152 } |