Mercurial > hg > beaglert
comparison include/ReceiveAudioThread.h @ 217:c42a6b4dc2d4 mergingClockSync
Recovered some files from ClockSync
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sat, 13 Feb 2016 04:09:12 +0000 |
parents | |
children | e4392164b458 |
comparison
equal
deleted
inserted
replaced
216:869f5e703844 | 217:c42a6b4dc2d4 |
---|---|
1 #ifndef RECEIVEAUDIOTHREAD_H_INCLUDED | |
2 #define RECEIVEAUDIOTHREAD_H_INCLUDED | |
3 | |
4 #ifdef USE_JUCE | |
5 #include <JuceHeader.h> | |
6 #else | |
7 #include <BeagleRT.h> | |
8 #include <UdpServer.h> | |
9 #include <vector> | |
10 #include <iostream> | |
11 #include <native/task.h> | |
12 #include <native/timer.h> | |
13 #include <math.h> | |
14 | |
15 #endif /*USE_JUCE*/ | |
16 | |
17 #ifdef USE_JUCE | |
18 class ReceiveAudioThread : public Thread { | |
19 #else | |
20 class ReceiveAudioThread{ | |
21 #endif /* USE_JUCE */ | |
22 private: | |
23 // FILE *fd; //DEBUG | |
24 // FILE *fd2; //DEBUG | |
25 #ifdef USE_JUCE | |
26 DatagramSocket socket; | |
27 #else | |
28 UdpServer socket; | |
29 #endif /* USE_JUCE */ | |
30 bool listening; | |
31 bool bufferReady; | |
32 #ifdef USE_JUCE | |
33 bool threadRunning; //do we really need this ? | |
34 #else | |
35 static bool threadRunning; | |
36 static bool threadIsExiting; | |
37 #endif | |
38 float *buffer; | |
39 float *stackBuffer; | |
40 int bufferLength; | |
41 float readPointer; | |
42 int writePointer; | |
43 int lastValidPointer; | |
44 #ifdef USE_JUCE | |
45 int sleepTime; | |
46 #else | |
47 static int sleepTime; | |
48 #endif | |
49 int waitForSocketTime; | |
50 int payloadLength; //size of the payload of each datagram | |
51 int headerLength; //size of the header of each datagram | |
52 int bytesToRead; | |
53 int threadPriority; | |
54 int channel; | |
55 int timestamp; | |
56 void dealloc(); | |
57 void wrapWritePointer(); | |
58 void pushPayload(int startIndex); | |
59 void popPayload(int startIndex); | |
60 int readUdpToBuffer(); | |
61 #ifdef USE_JUCE | |
62 #else | |
63 RTIME lastTime; // Used for clock synchronization | |
64 static bool threadShouldExit(); | |
65 static bool staticConstructed; | |
66 static void staticConstructor(); | |
67 static AuxiliaryTask receiveDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) | |
68 static std::vector<ReceiveAudioThread *> objAddrs; | |
69 #endif | |
70 public: | |
71 #ifdef USE_JUCE | |
72 ReceiveAudioThread(const String &threadName); | |
73 #else | |
74 ReceiveAudioThread(); | |
75 #endif | |
76 ~ReceiveAudioThread(); | |
77 void init(int port, int aSamplesPerBlock, int channel); | |
78 void bindToPort(int aPort); | |
79 bool isListening(); | |
80 float* getCurrentBuffer(int length); | |
81 /** | |
82 * Copies the samples to a non-interleaved buffer. | |
83 */ | |
84 int getSamplesSrc(float *destination, int length, float samplingRateRatio); | |
85 /** | |
86 * Copies the samples to an interleaved buffer. | |
87 */ | |
88 int getSamplesSrc(float *destination, int length, | |
89 float samplingRateRatio, int numChannelsInDestination, | |
90 int channelToWriteTo); | |
91 bool isBufferReady(); | |
92 int getTimestamp(); | |
93 #ifdef USE_JUCE // if we are in Juce, then we run a separate thread for each receiver | |
94 // (as each of them are typically receiving on a mono or stereo track) | |
95 void run(); | |
96 #else | |
97 RTIME getLastTime(); | |
98 void static run(); //while in BeagleRT we have a single thread that receives for all the instances. | |
99 //TODO: make run() private in BeagleRT | |
100 static void startThread(); | |
101 static void stopThread(); | |
102 static int getNumInstances(); | |
103 #endif // USE_JUCE | |
104 }; | |
105 #endif // RECEIVEAUDIOTHREAD_H_INCLUDED |