giuliomoro@117: #ifndef RECEIVEAUDIOTHREAD_H_INCLUDED giuliomoro@117: #define RECEIVEAUDIOTHREAD_H_INCLUDED giuliomoro@117: #include giuliomoro@117: #include giuliomoro@117: #include giuliomoro@117: #include giuliomoro@117: #include giuliomoro@117: giuliomoro@117: class ReceiveAudioThread{ giuliomoro@117: private: giuliomoro@117: // FILE *fd; //DEBUG giuliomoro@117: // FILE *fd2; //DEBUG giuliomoro@117: UdpServer socket; giuliomoro@117: //JUCE DatagramSocket socket; giuliomoro@117: bool listening; giuliomoro@117: bool bufferReady; giuliomoro@117: bool threadIsExiting; giuliomoro@117: bool threadRunning; giuliomoro@117: float *buffer; giuliomoro@117: float *stackBuffer; giuliomoro@117: int bufferLength; giuliomoro@117: float readPointer; giuliomoro@117: int writePointer; giuliomoro@117: int lastValidPointer; giuliomoro@117: int sleepTime; giuliomoro@117: int waitForSocketTime; giuliomoro@117: int payloadLength; //size of the payload of each datagram giuliomoro@117: int headerLength; //size of the header of each datagram giuliomoro@117: int bytesToRead; giuliomoro@117: int threadPriority; giuliomoro@117: void dealloc(); giuliomoro@117: void wrapWritePointer(); giuliomoro@117: void pushPayload(int startIndex); giuliomoro@117: void popPayload(int startIndex); giuliomoro@117: int readUdpToBuffer(); giuliomoro@117: bool threadShouldExit(); giuliomoro@117: static AuxiliaryTask receiveDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) giuliomoro@117: // static std::vector objAddrs; giuliomoro@117: public: giuliomoro@117: ReceiveAudioThread(); giuliomoro@117: ~ReceiveAudioThread(); giuliomoro@117: void init(int aSamplesPerBlock); giuliomoro@117: void setup(); giuliomoro@117: void bindToPort(int aPort); giuliomoro@117: bool isListening(); giuliomoro@117: float* getCurrentBuffer(int length); giuliomoro@117: int getSamplesSrc(float *destination, int length, float samplingRateRatio); giuliomoro@117: bool isBufferReady(); giuliomoro@117: void run(); giuliomoro@117: void startThread(); giuliomoro@117: void stopThread(); giuliomoro@117: // static int getNumInstances(); giuliomoro@117: // static void receiveAllData(); giuliomoro@117: }; giuliomoro@117: #endif // RECEIVEAUDIOTHREAD_H_INCLUDED