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