Mercurial > hg > beaglert
diff 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 |
line wrap: on
line diff
--- a/include/NetworkSend.h Tue Aug 25 11:14:25 2015 +0100 +++ b/include/NetworkSend.h Wed Aug 26 02:02:10 2015 +0100 @@ -3,24 +3,37 @@ #define SCOPE_H_ #ifdef USE_JUCE +#include <JuceHeader.h> #else #include <BeagleRT.h> #include <rtdk.h> #include <cmath> #include <UdpClient.h> #include <vector> +#include <string> +extern bool gShouldStop; #endif /* USE_JUCE */ #define NETWORK_AUDIO_BUFFER_SIZE 302 +#define UDP_BUFFER_HEADER_CHANNEL_INDEX 0 +#define UDP_BUFFER_HEADER_TIMESTAMP_INDEX 1 +#define UDP_BUFFER_HEADER_LENGTH 2 struct NetworkBuffer{ int channelNumber; - int activeBuffer; - int index; - float buffers[2][NETWORK_AUDIO_BUFFER_SIZE]; - bool doneOnTime; - bool readyToBeSent; - static const int headerLength=2; + int numBuffers; + int writeBuffer; + int readBuffer; + int writePointer; + float** buffers; + bool* doneOnTime; + bool* readyToBeSent; + bool enabled; + int sampleCount; + static const int bufferLength=NETWORK_AUDIO_BUFFER_SIZE; + static const int headerLength=UDP_BUFFER_HEADER_LENGTH; + static const int headerChannelIndex=UDP_BUFFER_HEADER_CHANNEL_INDEX; + static const int headerTimestampIndex=UDP_BUFFER_HEADER_TIMESTAMP_INDEX; }; #ifdef USE_JUCE @@ -28,23 +41,35 @@ #else class NetworkSend { #endif /* USE_JUCE */ - int sampleCount; float sampleRate; #ifdef USE_JUCE DatagramSocket udpClient; + int sleepTimeMs; + String remoteHostname; + int remotePortNumber; #else UdpClient udpClient; + bool isThreadRunning(); + static int sleepTimeMs; + static bool threadShouldExit(); + static bool threadIsExiting; + static bool threadRunning; static bool staticConstructed; static void staticConstructor(); static AuxiliaryTask sendDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) static std::vector<NetworkSend *> objAddrs; #endif /* USE_JUCE */ - public: + void dealloc(); +public: NetworkBuffer channel; +#ifdef USE_JUCE + NetworkSend(const String &threadName); +#else NetworkSend(); +#endif ~NetworkSend(); - void setup(float aSampleRate); - void setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer); + void setup(float aSampleRate, int blockSize, int aChannelNumber, int aPort, const char *aServer); + void cleanup(); void sendData(); void log(float value); void setPort(int aPort); @@ -56,6 +81,8 @@ #else static int getNumInstances(); static void sendAllData(); + static void startThread(); + static void stopThread(); static void run(); #endif /* USE_JUCE */ };