comparison include/ReceiveAudioThread.h @ 128:2696a7f00053 scope-refactoring

ReceiveAudioThread is now the same with/without JUCE
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 24 Aug 2015 18:55:19 +0100
parents 850a4a9bd832
children ff28e56e5b7e
comparison
equal deleted inserted replaced
127:6c8fb6f07b47 128:2696a7f00053
1 #ifndef RECEIVEAUDIOTHREAD_H_INCLUDED 1 #ifndef RECEIVEAUDIOTHREAD_H_INCLUDED
2 #define RECEIVEAUDIOTHREAD_H_INCLUDED 2 #define RECEIVEAUDIOTHREAD_H_INCLUDED
3 #ifdef JUCE 3
4 #ifdef USE_JUCE
5 #include <JuceHeader.h>
4 #else 6 #else
5 #include <vector> 7 #include <vector>
6 #include <iostream> 8 #include <iostream>
7 #include <UdpServer.h> 9 #include <UdpServer.h>
8 #include <BeagleRT.h> 10 #include <BeagleRT.h>
9 #include <native/task.h> 11 #include <native/task.h>
10 #endif /*JUCE*/ 12 #endif /*USE_JUCE*/
11 13
12 #ifdef JUCE 14 #ifdef USE_JUCE
13 class ReceiveAudioThread : public Thread { 15 class ReceiveAudioThread : public Thread {
14 #else 16 #else
15 class ReceiveAudioThread{ 17 class ReceiveAudioThread{
16 #endif /* JUCE */ 18 #endif /* USE_JUCE */
17 private: 19 private:
18 // FILE *fd; //DEBUG 20 // FILE *fd; //DEBUG
19 // FILE *fd2; //DEBUG 21 // FILE *fd2; //DEBUG
20 #ifdef JUCE 22 #ifdef USE_JUCE
21 DatagramSocket socket; 23 DatagramSocket socket;
22 #else 24 #else
23 UdpServer socket; 25 UdpServer socket;
24 #endif /* JUCE */ 26 #endif /* USE_JUCE */
25 bool listening; 27 bool listening;
26 bool bufferReady; 28 bool bufferReady;
27 #ifdef JUCE 29 #ifdef USE_JUCE
28 bool threadRunning; //do we really need this ? 30 bool threadRunning; //do we really need this ?
29 #else 31 #else
30 static bool threadRunning; 32 static bool threadRunning;
31 static bool threadIsExiting; 33 static bool threadIsExiting;
32 #endif 34 #endif
34 float *stackBuffer; 36 float *stackBuffer;
35 int bufferLength; 37 int bufferLength;
36 float readPointer; 38 float readPointer;
37 int writePointer; 39 int writePointer;
38 int lastValidPointer; 40 int lastValidPointer;
39 #ifdef JUCE 41 #ifdef USE_JUCE
40 int sleepTime; 42 int sleepTime;
41 #else 43 #else
42 static int sleepTime; 44 static int sleepTime;
43 #endif 45 #endif
44 int waitForSocketTime; 46 int waitForSocketTime;
50 void dealloc(); 52 void dealloc();
51 void wrapWritePointer(); 53 void wrapWritePointer();
52 void pushPayload(int startIndex); 54 void pushPayload(int startIndex);
53 void popPayload(int startIndex); 55 void popPayload(int startIndex);
54 int readUdpToBuffer(); 56 int readUdpToBuffer();
55 #ifdef JUCE 57 #ifdef USE_JUCE
56 #else 58 #else
57 static bool threadShouldExit(); 59 static bool threadShouldExit();
58 static bool staticConstructed; 60 static bool staticConstructed;
59 static void staticConstructor(); 61 static void staticConstructor();
60 static AuxiliaryTask receiveDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) 62 static AuxiliaryTask receiveDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope)
61 static std::vector<ReceiveAudioThread *> objAddrs; 63 static std::vector<ReceiveAudioThread *> objAddrs;
62 #endif 64 #endif
63 public: 65 public:
64 #ifdef JUCE 66 #ifdef USE_JUCE
65 ReceiveAudioThread(const String &threadName); 67 ReceiveAudioThread(const String &threadName);
66 #else 68 #else
67 ReceiveAudioThread(); 69 ReceiveAudioThread();
68 #endif 70 #endif
69 ~ReceiveAudioThread(); 71 ~ReceiveAudioThread();
80 */ 82 */
81 int getSamplesSrc(float *destination, int length, 83 int getSamplesSrc(float *destination, int length,
82 float samplingRateRatio, int numChannelsInDestination, 84 float samplingRateRatio, int numChannelsInDestination,
83 int channelToWriteTo); 85 int channelToWriteTo);
84 bool isBufferReady(); 86 bool isBufferReady();
85 #ifdef JUCE // if we are in Juce, then we run a separate thread for each receiver 87 #ifdef USE_JUCE // if we are in Juce, then we run a separate thread for each receiver
86 // (as each of them are typically receiving on a mono or stereo track) 88 // (as each of them are typically receiving on a mono or stereo track)
87 void run(); 89 void run();
88 #else 90 #else
89 void static run(); //while in BeagleRT we have a single thread that receives for all the instances. 91 void static run(); //while in BeagleRT we have a single thread that receives for all the instances.
90 //TODO: make run() private in BeagleRT 92 //TODO: make run() private in BeagleRT
91 static void startThread(); 93 static void startThread();
92 static void stopThread(); 94 static void stopThread();
93 static int getNumInstances(); 95 static int getNumInstances();
94 #endif // JUCE 96 #endif // USE_JUCE
95 }; 97 };
96 #endif // RECEIVEAUDIOTHREAD_H_INCLUDED 98 #endif // RECEIVEAUDIOTHREAD_H_INCLUDED