Mercurial > hg > beaglert
comparison include/NetworkSend.h @ 131:ff28e56e5b7e scope-refactoring
Updated Network files to match Udpioplugin 18:fb5a61b10223
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 26 Aug 2015 02:02:10 +0100 |
parents | cce58e6ec2a2 |
children | e24c531220ee |
comparison
equal
deleted
inserted
replaced
130:da1c61aa97ea | 131:ff28e56e5b7e |
---|---|
1 //scope.cpp | 1 //scope.cpp |
2 #ifndef SCOPE_H_ | 2 #ifndef SCOPE_H_ |
3 #define SCOPE_H_ | 3 #define SCOPE_H_ |
4 | 4 |
5 #ifdef USE_JUCE | 5 #ifdef USE_JUCE |
6 #include <JuceHeader.h> | |
6 #else | 7 #else |
7 #include <BeagleRT.h> | 8 #include <BeagleRT.h> |
8 #include <rtdk.h> | 9 #include <rtdk.h> |
9 #include <cmath> | 10 #include <cmath> |
10 #include <UdpClient.h> | 11 #include <UdpClient.h> |
11 #include <vector> | 12 #include <vector> |
13 #include <string> | |
14 extern bool gShouldStop; | |
12 #endif /* USE_JUCE */ | 15 #endif /* USE_JUCE */ |
13 | 16 |
14 #define NETWORK_AUDIO_BUFFER_SIZE 302 | 17 #define NETWORK_AUDIO_BUFFER_SIZE 302 |
18 #define UDP_BUFFER_HEADER_CHANNEL_INDEX 0 | |
19 #define UDP_BUFFER_HEADER_TIMESTAMP_INDEX 1 | |
20 #define UDP_BUFFER_HEADER_LENGTH 2 | |
15 | 21 |
16 struct NetworkBuffer{ | 22 struct NetworkBuffer{ |
17 int channelNumber; | 23 int channelNumber; |
18 int activeBuffer; | 24 int numBuffers; |
19 int index; | 25 int writeBuffer; |
20 float buffers[2][NETWORK_AUDIO_BUFFER_SIZE]; | 26 int readBuffer; |
21 bool doneOnTime; | 27 int writePointer; |
22 bool readyToBeSent; | 28 float** buffers; |
23 static const int headerLength=2; | 29 bool* doneOnTime; |
30 bool* readyToBeSent; | |
31 bool enabled; | |
32 int sampleCount; | |
33 static const int bufferLength=NETWORK_AUDIO_BUFFER_SIZE; | |
34 static const int headerLength=UDP_BUFFER_HEADER_LENGTH; | |
35 static const int headerChannelIndex=UDP_BUFFER_HEADER_CHANNEL_INDEX; | |
36 static const int headerTimestampIndex=UDP_BUFFER_HEADER_TIMESTAMP_INDEX; | |
24 }; | 37 }; |
25 | 38 |
26 #ifdef USE_JUCE | 39 #ifdef USE_JUCE |
27 class NetworkSend: public Thread { | 40 class NetworkSend: public Thread { |
28 #else | 41 #else |
29 class NetworkSend { | 42 class NetworkSend { |
30 #endif /* USE_JUCE */ | 43 #endif /* USE_JUCE */ |
31 int sampleCount; | |
32 float sampleRate; | 44 float sampleRate; |
33 #ifdef USE_JUCE | 45 #ifdef USE_JUCE |
34 DatagramSocket udpClient; | 46 DatagramSocket udpClient; |
47 int sleepTimeMs; | |
48 String remoteHostname; | |
49 int remotePortNumber; | |
35 #else | 50 #else |
36 UdpClient udpClient; | 51 UdpClient udpClient; |
52 bool isThreadRunning(); | |
53 static int sleepTimeMs; | |
54 static bool threadShouldExit(); | |
55 static bool threadIsExiting; | |
56 static bool threadRunning; | |
37 static bool staticConstructed; | 57 static bool staticConstructed; |
38 static void staticConstructor(); | 58 static void staticConstructor(); |
39 static AuxiliaryTask sendDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) | 59 static AuxiliaryTask sendDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) |
40 static std::vector<NetworkSend *> objAddrs; | 60 static std::vector<NetworkSend *> objAddrs; |
41 #endif /* USE_JUCE */ | 61 #endif /* USE_JUCE */ |
42 public: | 62 void dealloc(); |
63 public: | |
43 NetworkBuffer channel; | 64 NetworkBuffer channel; |
65 #ifdef USE_JUCE | |
66 NetworkSend(const String &threadName); | |
67 #else | |
44 NetworkSend(); | 68 NetworkSend(); |
69 #endif | |
45 ~NetworkSend(); | 70 ~NetworkSend(); |
46 void setup(float aSampleRate); | 71 void setup(float aSampleRate, int blockSize, int aChannelNumber, int aPort, const char *aServer); |
47 void setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer); | 72 void cleanup(); |
48 void sendData(); | 73 void sendData(); |
49 void log(float value); | 74 void log(float value); |
50 void setPort(int aPort); | 75 void setPort(int aPort); |
51 void setServer(const char* aServer); | 76 void setServer(const char* aServer); |
52 void setChannelNumber(int aChannelNumber); | 77 void setChannelNumber(int aChannelNumber); |
54 #ifdef USE_JUCE | 79 #ifdef USE_JUCE |
55 void run(); | 80 void run(); |
56 #else | 81 #else |
57 static int getNumInstances(); | 82 static int getNumInstances(); |
58 static void sendAllData(); | 83 static void sendAllData(); |
84 static void startThread(); | |
85 static void stopThread(); | |
59 static void run(); | 86 static void run(); |
60 #endif /* USE_JUCE */ | 87 #endif /* USE_JUCE */ |
61 }; | 88 }; |
62 | 89 |
63 #ifdef USE_JUCE | 90 #ifdef USE_JUCE |