Mercurial > hg > beaglert
comparison include/NetworkSend.h @ 217:c42a6b4dc2d4 mergingClockSync
Recovered some files from ClockSync
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sat, 13 Feb 2016 04:09:12 +0000 |
parents | include/Scope.h@836052c86e1e |
children | 18d03901f866 |
comparison
equal
deleted
inserted
replaced
216:869f5e703844 | 217:c42a6b4dc2d4 |
---|---|
1 //scope.cpp | |
2 #ifndef SCOPE_H_ | |
3 #define SCOPE_H_ | |
4 | |
5 #ifdef USE_JUCE | |
6 #include <JuceHeader.h> | |
7 #else | |
8 #include <BeagleRT.h> | |
9 #include <rtdk.h> | |
10 #include <cmath> | |
11 #include <UdpClient.h> | |
12 #include <vector> | |
13 #include <string> | |
14 extern bool gShouldStop; | |
15 #endif /* USE_JUCE */ | |
16 | |
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 | |
21 | |
22 struct NetworkBuffer{ | |
23 int channelNumber; | |
24 int numBuffers; | |
25 int writeBuffer; | |
26 int readBuffer; | |
27 int writePointer; | |
28 float** buffers; | |
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; | |
37 }; | |
38 | |
39 #ifdef USE_JUCE | |
40 class NetworkSend: public Thread { | |
41 #else | |
42 class NetworkSend { | |
43 #endif /* USE_JUCE */ | |
44 float sampleRate; | |
45 #ifdef USE_JUCE | |
46 DatagramSocket udpClient; | |
47 int sleepTimeMs; | |
48 String remoteHostname; | |
49 int remotePortNumber; | |
50 #else | |
51 UdpClient udpClient; | |
52 bool isThreadRunning(); | |
53 static int sleepTimeMs; | |
54 static bool threadShouldExit(); | |
55 static bool threadIsExiting; | |
56 static bool threadRunning; | |
57 static bool staticConstructed; | |
58 static void staticConstructor(); | |
59 static AuxiliaryTask sendDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) | |
60 static std::vector<NetworkSend *> objAddrs; | |
61 #endif /* USE_JUCE */ | |
62 void dealloc(); | |
63 public: | |
64 NetworkBuffer channel; | |
65 #ifdef USE_JUCE | |
66 NetworkSend(const String &threadName); | |
67 #else | |
68 NetworkSend(); | |
69 #endif | |
70 ~NetworkSend(); | |
71 void setup(float aSampleRate, int blockSize, int aChannelNumber, int aPort, const char *aServer); | |
72 void cleanup(); | |
73 void sendData(); | |
74 void log(float value); | |
75 void setPort(int aPort); | |
76 void setServer(const char* aServer); | |
77 void setChannelNumber(int aChannelNumber); | |
78 int getChannelNumber(); | |
79 int getTimestamp(); | |
80 #ifdef USE_JUCE | |
81 void run(); | |
82 #else | |
83 static int getNumInstances(); | |
84 static void sendAllData(); | |
85 static void startThread(); | |
86 static void stopThread(); | |
87 static void run(); | |
88 #endif /* USE_JUCE */ | |
89 }; | |
90 | |
91 #ifdef USE_JUCE | |
92 #else | |
93 /** | |
94 * An array of NetworkSend objects with some default parameters | |
95 * | |
96 * All sending on the same port (defaults to 9999) | |
97 * All sending to the same server (defaults to 127.0.0.1) | |
98 */ | |
99 class Scope { | |
100 std::vector<NetworkSend> channels; | |
101 void deallocate(); | |
102 public: | |
103 Scope(int aNumChannels); | |
104 ~Scope(); | |
105 void log(int channel, float value); | |
106 void setup(); | |
107 void setup(float sampleRate, int aPort, const char* aServer); | |
108 void sendData(); | |
109 void setPort(int port); | |
110 void setPort(int channel, int port); | |
111 int getNumChannels(); | |
112 }; | |
113 #endif /* USE_JUCE */ | |
114 | |
115 #endif /* SCOPE_H */ |