andrewm@71
|
1 //scope.cpp
|
giuliomoro@109
|
2 #ifndef SCOPE_H_
|
giuliomoro@109
|
3 #define SCOPE_H_
|
giuliomoro@109
|
4
|
giuliomoro@129
|
5 #ifdef USE_JUCE
|
giuliomoro@129
|
6 #else
|
andrewm@71
|
7 #include <BeagleRT.h>
|
andrewm@71
|
8 #include <rtdk.h>
|
andrewm@71
|
9 #include <cmath>
|
andrewm@71
|
10 #include <UdpClient.h>
|
giuliomoro@111
|
11 #include <vector>
|
giuliomoro@129
|
12 #endif /* USE_JUCE */
|
andrewm@71
|
13
|
giuliomoro@107
|
14 #define NETWORK_AUDIO_BUFFER_SIZE 302
|
giuliomoro@109
|
15
|
giuliomoro@109
|
16 struct NetworkBuffer{
|
giuliomoro@109
|
17 int channelNumber;
|
giuliomoro@109
|
18 int activeBuffer;
|
andrewm@71
|
19 int index;
|
giuliomoro@113
|
20 float buffers[2][NETWORK_AUDIO_BUFFER_SIZE];
|
giuliomoro@109
|
21 bool doneOnTime;
|
giuliomoro@109
|
22 bool readyToBeSent;
|
giuliomoro@111
|
23 static const int headerLength=2;
|
andrewm@71
|
24 };
|
andrewm@71
|
25
|
giuliomoro@129
|
26 #ifdef USE_JUCE
|
giuliomoro@129
|
27 class NetworkSend: public Thread {
|
giuliomoro@129
|
28 #else
|
giuliomoro@111
|
29 class NetworkSend {
|
giuliomoro@129
|
30 #endif /* USE_JUCE */
|
giuliomoro@129
|
31 int sampleCount;
|
giuliomoro@129
|
32 float sampleRate;
|
giuliomoro@129
|
33 #ifdef USE_JUCE
|
giuliomoro@129
|
34 DatagramSocket udpClient;
|
giuliomoro@129
|
35 #else
|
giuliomoro@111
|
36 UdpClient udpClient;
|
giuliomoro@111
|
37 static bool staticConstructed;
|
giuliomoro@129
|
38 static void staticConstructor();
|
giuliomoro@129
|
39 static AuxiliaryTask sendDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope)
|
giuliomoro@129
|
40 static std::vector<NetworkSend *> objAddrs;
|
giuliomoro@129
|
41 #endif /* USE_JUCE */
|
giuliomoro@129
|
42 public:
|
giuliomoro@129
|
43 NetworkBuffer channel;
|
giuliomoro@129
|
44 NetworkSend();
|
giuliomoro@129
|
45 ~NetworkSend();
|
giuliomoro@129
|
46 void setup(float aSampleRate);
|
giuliomoro@129
|
47 void setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer);
|
giuliomoro@129
|
48 void sendData();
|
giuliomoro@129
|
49 void log(float value);
|
giuliomoro@129
|
50 void setPort(int aPort);
|
giuliomoro@129
|
51 void setServer(const char* aServer);
|
giuliomoro@129
|
52 void setChannelNumber(int aChannelNumber);
|
giuliomoro@129
|
53 int getChannelNumber();
|
giuliomoro@129
|
54 #ifdef USE_JUCE
|
giuliomoro@129
|
55 void run();
|
giuliomoro@129
|
56 #else
|
giuliomoro@129
|
57 static int getNumInstances();
|
giuliomoro@129
|
58 static void sendAllData();
|
giuliomoro@129
|
59 static void run();
|
giuliomoro@129
|
60 #endif /* USE_JUCE */
|
andrewm@71
|
61 };
|
andrewm@71
|
62
|
giuliomoro@129
|
63 #ifdef USE_JUCE
|
giuliomoro@129
|
64 #else
|
giuliomoro@111
|
65 /**
|
giuliomoro@111
|
66 * An array of NetworkSend objects with some default parameters
|
giuliomoro@111
|
67 *
|
giuliomoro@111
|
68 * All sending on the same port (defaults to 9999)
|
giuliomoro@111
|
69 * All sending to the same server (defaults to 127.0.0.1)
|
giuliomoro@111
|
70 */
|
giuliomoro@109
|
71 class Scope {
|
giuliomoro@111
|
72 std::vector<NetworkSend> channels;
|
giuliomoro@109
|
73 void deallocate();
|
giuliomoro@109
|
74 public:
|
giuliomoro@109
|
75 Scope(int aNumChannels);
|
giuliomoro@109
|
76 ~Scope();
|
giuliomoro@109
|
77 void log(int channel, float value);
|
giuliomoro@111
|
78 void setup();
|
giuliomoro@111
|
79 void setup(float sampleRate, int aPort, const char* aServer);
|
giuliomoro@109
|
80 void sendData();
|
giuliomoro@119
|
81 void setPort(int port);
|
giuliomoro@119
|
82 void setPort(int channel, int port);
|
giuliomoro@111
|
83 int getNumChannels();
|
giuliomoro@109
|
84 };
|
giuliomoro@129
|
85 #endif /* USE_JUCE */
|
giuliomoro@129
|
86
|
giuliomoro@109
|
87 #endif /* SCOPE_H */
|