andrewm@71: //scope.cpp giuliomoro@109: #ifndef SCOPE_H_ giuliomoro@109: #define SCOPE_H_ giuliomoro@109: andrewm@71: #include andrewm@71: #include andrewm@71: #include andrewm@71: #include giuliomoro@111: #include andrewm@71: giuliomoro@107: #define NETWORK_AUDIO_BUFFER_SIZE 302 giuliomoro@109: giuliomoro@109: struct NetworkBuffer{ giuliomoro@109: int channelNumber; giuliomoro@109: int activeBuffer; andrewm@71: int index; giuliomoro@113: float buffers[2][NETWORK_AUDIO_BUFFER_SIZE]; giuliomoro@109: bool doneOnTime; giuliomoro@109: bool readyToBeSent; giuliomoro@111: static const int headerLength=2; andrewm@71: }; andrewm@71: giuliomoro@111: class NetworkSend { andrewm@71: int sampleCount; andrewm@71: float sampleRate; giuliomoro@111: UdpClient udpClient; giuliomoro@111: static bool staticConstructed; giuliomoro@111: static void staticConstructor(); giuliomoro@111: static AuxiliaryTask transmitAudioTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) giuliomoro@111: static std::vector objAddrs; andrewm@71: public: giuliomoro@109: NetworkBuffer channel; giuliomoro@111: NetworkSend(); giuliomoro@111: ~NetworkSend(); giuliomoro@109: void setup(float aSampleRate); giuliomoro@111: void setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer); giuliomoro@109: void sendData(); giuliomoro@109: void log(float value); giuliomoro@109: void setPort(int aPort); giuliomoro@111: void setServer(const char* aServer); giuliomoro@109: void setChannelNumber(int aChannelNumber); giuliomoro@109: int getChannelNumber(); giuliomoro@111: static int getNumInstances(); giuliomoro@111: static void sendAllData(); andrewm@71: }; andrewm@71: giuliomoro@111: /** giuliomoro@111: * An array of NetworkSend objects with some default parameters giuliomoro@111: * giuliomoro@111: * All sending on the same port (defaults to 9999) giuliomoro@111: * All sending to the same server (defaults to 127.0.0.1) giuliomoro@111: */ giuliomoro@109: class Scope { giuliomoro@111: std::vector channels; giuliomoro@109: void deallocate(); giuliomoro@109: public: giuliomoro@109: Scope(int aNumChannels); giuliomoro@109: ~Scope(); giuliomoro@109: void log(int channel, float value); giuliomoro@111: void setup(); giuliomoro@111: void setup(float sampleRate, int aPort, const char* aServer); giuliomoro@109: void sendData(); giuliomoro@111: void setPort(); giuliomoro@111: int getNumChannels(); giuliomoro@109: }; giuliomoro@109: #endif /* SCOPE_H */