Mercurial > hg > beaglert
view include/ReceiveAudioThread.h @ 125:850a4a9bd832 scope-refactoring
Added ifdefs and unified the code with udpioplugin ... the latter has not been tested (or committed). TODO: still it hangs after ctrl-c BeagleRT (auxiliary tasks do not terminate). TODO: sometimes you can hear dropouts in the transmission. Maybe it is due to pointer drifting. Rebooting BBB fixes/affects this issue.
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sat, 22 Aug 2015 02:53:36 +0100 |
parents | cdd441a304a9 |
children | 2696a7f00053 |
line wrap: on
line source
#ifndef RECEIVEAUDIOTHREAD_H_INCLUDED #define RECEIVEAUDIOTHREAD_H_INCLUDED #ifdef JUCE #else #include <vector> #include <iostream> #include <UdpServer.h> #include <BeagleRT.h> #include <native/task.h> #endif /*JUCE*/ #ifdef JUCE class ReceiveAudioThread : public Thread { #else class ReceiveAudioThread{ #endif /* JUCE */ private: // FILE *fd; //DEBUG // FILE *fd2; //DEBUG #ifdef JUCE DatagramSocket socket; #else UdpServer socket; #endif /* JUCE */ bool listening; bool bufferReady; #ifdef JUCE bool threadRunning; //do we really need this ? #else static bool threadRunning; static bool threadIsExiting; #endif float *buffer; float *stackBuffer; int bufferLength; float readPointer; int writePointer; int lastValidPointer; #ifdef JUCE int sleepTime; #else static int sleepTime; #endif int waitForSocketTime; int payloadLength; //size of the payload of each datagram int headerLength; //size of the header of each datagram int bytesToRead; int threadPriority; int channel; void dealloc(); void wrapWritePointer(); void pushPayload(int startIndex); void popPayload(int startIndex); int readUdpToBuffer(); #ifdef JUCE #else static bool threadShouldExit(); static bool staticConstructed; static void staticConstructor(); static AuxiliaryTask receiveDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) static std::vector<ReceiveAudioThread *> objAddrs; #endif public: #ifdef JUCE ReceiveAudioThread(const String &threadName); #else ReceiveAudioThread(); #endif ~ReceiveAudioThread(); void init(int port, int aSamplesPerBlock, int channel); void bindToPort(int aPort); bool isListening(); float* getCurrentBuffer(int length); /** * Copies the samples to a non-interleaved buffer. */ int getSamplesSrc(float *destination, int length, float samplingRateRatio); /** * Copies the samples to an interleaved buffer. */ int getSamplesSrc(float *destination, int length, float samplingRateRatio, int numChannelsInDestination, int channelToWriteTo); bool isBufferReady(); #ifdef JUCE // if we are in Juce, then we run a separate thread for each receiver // (as each of them are typically receiving on a mono or stereo track) void run(); #else void static run(); //while in BeagleRT we have a single thread that receives for all the instances. //TODO: make run() private in BeagleRT static void startThread(); static void stopThread(); static int getNumInstances(); #endif // JUCE }; #endif // RECEIVEAUDIOTHREAD_H_INCLUDED