annotate include/NetworkSend.h @ 294:48d36405e987

Defaulting gcc for on-board compiling, see #1695
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 24 May 2016 23:46:21 +0100
parents 18d03901f866
children e4392164b458
rev   line source
andrewm@71 1 //scope.cpp
giuliomoro@217 2 #ifndef SCOPE_H_
giuliomoro@217 3 #define SCOPE_H_
giuliomoro@217 4
giuliomoro@217 5 #ifdef USE_JUCE
giuliomoro@217 6 #include <JuceHeader.h>
giuliomoro@217 7 #else
andrewm@71 8 #include <BeagleRT.h>
andrewm@71 9 #include <rtdk.h>
andrewm@71 10 #include <cmath>
andrewm@71 11 #include <UdpClient.h>
giuliomoro@217 12 #include <vector>
giuliomoro@217 13 #include <string>
giuliomoro@233 14 extern int gShouldStop;
giuliomoro@217 15 #endif /* USE_JUCE */
andrewm@71 16
giuliomoro@107 17 #define NETWORK_AUDIO_BUFFER_SIZE 302
giuliomoro@217 18 #define UDP_BUFFER_HEADER_CHANNEL_INDEX 0
giuliomoro@217 19 #define UDP_BUFFER_HEADER_TIMESTAMP_INDEX 1
giuliomoro@217 20 #define UDP_BUFFER_HEADER_LENGTH 2
giuliomoro@217 21
giuliomoro@217 22 struct NetworkBuffer{
giuliomoro@217 23 int channelNumber;
giuliomoro@217 24 int numBuffers;
giuliomoro@217 25 int writeBuffer;
giuliomoro@217 26 int readBuffer;
giuliomoro@217 27 int writePointer;
giuliomoro@217 28 float** buffers;
giuliomoro@217 29 bool* doneOnTime;
giuliomoro@217 30 bool* readyToBeSent;
giuliomoro@217 31 bool enabled;
giuliomoro@217 32 int sampleCount;
giuliomoro@217 33 static const int bufferLength=NETWORK_AUDIO_BUFFER_SIZE;
giuliomoro@217 34 static const int headerLength=UDP_BUFFER_HEADER_LENGTH;
giuliomoro@217 35 static const int headerChannelIndex=UDP_BUFFER_HEADER_CHANNEL_INDEX;
giuliomoro@217 36 static const int headerTimestampIndex=UDP_BUFFER_HEADER_TIMESTAMP_INDEX;
andrewm@71 37 };
andrewm@71 38
giuliomoro@217 39 #ifdef USE_JUCE
giuliomoro@217 40 class NetworkSend: public Thread {
giuliomoro@107 41 #else
giuliomoro@217 42 class NetworkSend {
giuliomoro@217 43 #endif /* USE_JUCE */
giuliomoro@217 44 float sampleRate;
giuliomoro@217 45 #ifdef USE_JUCE
giuliomoro@217 46 DatagramSocket udpClient;
giuliomoro@217 47 int sleepTimeMs;
giuliomoro@217 48 String remoteHostname;
giuliomoro@217 49 int remotePortNumber;
giuliomoro@93 50 #else
giuliomoro@217 51 UdpClient udpClient;
giuliomoro@217 52 bool isThreadRunning();
giuliomoro@217 53 static int sleepTimeMs;
giuliomoro@217 54 static bool threadShouldExit();
giuliomoro@217 55 static bool threadIsExiting;
giuliomoro@217 56 static bool threadRunning;
giuliomoro@217 57 static bool staticConstructed;
giuliomoro@217 58 static void staticConstructor();
giuliomoro@217 59 static AuxiliaryTask sendDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope)
giuliomoro@217 60 static std::vector<NetworkSend *> objAddrs;
giuliomoro@217 61 #endif /* USE_JUCE */
giuliomoro@217 62 void dealloc();
giuliomoro@217 63 public:
giuliomoro@217 64 NetworkBuffer channel;
giuliomoro@217 65 #ifdef USE_JUCE
giuliomoro@217 66 NetworkSend(const String &threadName);
giuliomoro@217 67 #else
giuliomoro@217 68 NetworkSend();
giuliomoro@217 69 #endif
giuliomoro@217 70 ~NetworkSend();
giuliomoro@217 71 void setup(float aSampleRate, int blockSize, int aChannelNumber, int aPort, const char *aServer);
giuliomoro@217 72 void cleanup();
giuliomoro@217 73 void sendData();
giuliomoro@217 74 void log(float value);
giuliomoro@217 75 void setPort(int aPort);
giuliomoro@217 76 void setServer(const char* aServer);
giuliomoro@217 77 void setChannelNumber(int aChannelNumber);
giuliomoro@217 78 int getChannelNumber();
giuliomoro@217 79 int getTimestamp();
giuliomoro@217 80 #ifdef USE_JUCE
giuliomoro@217 81 void run();
giuliomoro@217 82 #else
giuliomoro@217 83 static int getNumInstances();
giuliomoro@217 84 static void sendAllData();
giuliomoro@217 85 static void startThread();
giuliomoro@217 86 static void stopThread();
giuliomoro@217 87 static void run();
giuliomoro@217 88 #endif /* USE_JUCE */
andrewm@71 89 };
andrewm@71 90
giuliomoro@217 91 #ifdef USE_JUCE
giuliomoro@217 92 #else
giuliomoro@217 93 /**
giuliomoro@217 94 * An array of NetworkSend objects with some default parameters
giuliomoro@217 95 *
giuliomoro@217 96 * All sending on the same port (defaults to 9999)
giuliomoro@217 97 * All sending to the same server (defaults to 127.0.0.1)
giuliomoro@217 98 */
giuliomoro@217 99 class Scope {
giuliomoro@217 100 std::vector<NetworkSend> channels;
giuliomoro@217 101 void deallocate();
giuliomoro@217 102 public:
giuliomoro@217 103 Scope(int aNumChannels);
giuliomoro@217 104 ~Scope();
giuliomoro@217 105 void log(int channel, float value);
giuliomoro@217 106 void setup();
giuliomoro@217 107 void setup(float sampleRate, int aPort, const char* aServer);
giuliomoro@217 108 void sendData();
giuliomoro@217 109 void setPort(int port);
giuliomoro@217 110 void setPort(int channel, int port);
giuliomoro@217 111 int getNumChannels();
giuliomoro@217 112 };
giuliomoro@217 113 #endif /* USE_JUCE */
andrewm@71 114
giuliomoro@217 115 #endif /* SCOPE_H */