SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
testsourcethread.h
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef _TESTSOURCE_TESTSOURCETHREAD_H_
19 #define _TESTSOURCE_TESTSOURCETHREAD_H_
20 
21 #include <map>
22 
23 #include <QThread>
24 #include <QMutex>
25 #include <QWaitCondition>
26 #include <QTimer>
27 #include <QElapsedTimer>
28 #include <QDebug>
29 
30 #include "dsp/samplesinkfifo.h"
31 #include "dsp/decimators.h"
32 #include "dsp/ncof.h"
33 #include "util/message.h"
34 #include "util/messagequeue.h"
35 
36 #include "testsourcesettings.h"
37 
38 #define TESTSOURCE_THROTTLE_MS 50
39 
40 class TestSourceThread : public QThread {
41  Q_OBJECT
42 
43 public:
44  class MsgStartStop : public Message {
46 
47  public:
48  bool getStartStop() const { return m_startStop; }
49 
50  static MsgStartStop* create(bool startStop) {
51  return new MsgStartStop(startStop);
52  }
53 
54  protected:
56 
58  Message(),
59  m_startStop(startStop)
60  { }
61  };
62 
63  TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent = 0);
65 
66  void startStop(bool start);
67  void setSamplerate(int samplerate);
68  void setLog2Decimation(unsigned int log2_decim);
69  void setFcPos(int fcPos);
70  void setBitSize(uint32_t bitSizeIndex);
71  void setAmplitudeBits(int32_t amplitudeBits);
72  void setDCFactor(float iFactor);
73  void setIFactor(float iFactor);
74  void setQFactor(float qFactor);
75  void setPhaseImbalance(float phaseImbalance);
76  void setFrequencyShift(int shift);
77  void setToneFrequency(int toneFrequency);
79  void setAMModulation(float amModulation);
80  void setFMDeviation(float deviation);
81  void setPattern0();
82  void setPattern1();
83  void setPattern2();
84 
85 private:
87  QWaitCondition m_startWaiter;
88  volatile bool m_running;
89 
90  qint16 *m_buf;
91  quint32 m_bufsize;
92  quint32 m_chunksize;
102  float m_fmPhasor;
108 
110  unsigned int m_log2Decim;
111  int m_fcPos;
115  float m_dcBias;
116  float m_iBias;
117  float m_qBias;
122 
125 
127  QTimer m_timer;
128  QElapsedTimer m_elapsedTimer;
130  QMutex m_mutex;
131 
133 
137 
138  std::map<int, int> m_timerHistogram;
140 
141  void startWork();
142  void stopWork();
143  void run();
144  void callback(const qint16* buf, qint32 len);
145  void setBuffers(quint32 chunksize);
146  void generate(quint32 chunksize);
147  void pullAF(Real& afSample);
148 
149  // Decimate according to specified log2 (ex: log2=4 => decim=16)
150  inline void convert_8(SampleVector::iterator* it, const qint16* buf, qint32 len)
151  {
152  if (m_log2Decim == 0) {
153  m_decimators_8.decimate1(it, buf, len);
154  } else {
155  if (m_fcPos == 0) { // Infradyne
156  switch (m_log2Decim) {
157  case 1:
158  m_decimators_8.decimate2_inf(it, buf, len);
159  break;
160  case 2:
161  m_decimators_8.decimate4_inf(it, buf, len);
162  break;
163  case 3:
164  m_decimators_8.decimate8_inf(it, buf, len);
165  break;
166  case 4:
167  m_decimators_8.decimate16_inf(it, buf, len);
168  break;
169  case 5:
170  m_decimators_8.decimate32_inf(it, buf, len);
171  break;
172  case 6:
173  m_decimators_8.decimate64_inf(it, buf, len);
174  break;
175  default:
176  break;
177  }
178  } else if (m_fcPos == 1) {// Supradyne
179  switch (m_log2Decim) {
180  case 1:
181  m_decimators_8.decimate2_sup(it, buf, len);
182  break;
183  case 2:
184  m_decimators_8.decimate4_sup(it, buf, len);
185  break;
186  case 3:
187  m_decimators_8.decimate8_sup(it, buf, len);
188  break;
189  case 4:
190  m_decimators_8.decimate16_sup(it, buf, len);
191  break;
192  case 5:
193  m_decimators_8.decimate32_sup(it, buf, len);
194  break;
195  case 6:
196  m_decimators_8.decimate64_sup(it, buf, len);
197  break;
198  default:
199  break;
200  }
201  } else { // Centered
202  switch (m_log2Decim) {
203  case 1:
204  m_decimators_8.decimate2_cen(it, buf, len);
205  break;
206  case 2:
207  m_decimators_8.decimate4_cen(it, buf, len);
208  break;
209  case 3:
210  m_decimators_8.decimate8_cen(it, buf, len);
211  break;
212  case 4:
213  m_decimators_8.decimate16_cen(it, buf, len);
214  break;
215  case 5:
216  m_decimators_8.decimate32_cen(it, buf, len);
217  break;
218  case 6:
219  m_decimators_8.decimate64_cen(it, buf, len);
220  break;
221  default:
222  break;
223  }
224  }
225  }
226  }
227 
228  void convert_12(SampleVector::iterator* it, const qint16* buf, qint32 len)
229  {
230  if (m_log2Decim == 0) {
231  m_decimators_12.decimate1(it, buf, len);
232  } else {
233  if (m_fcPos == 0) { // Infradyne
234  switch (m_log2Decim) {
235  case 1:
236  m_decimators_12.decimate2_inf(it, buf, len);
237  break;
238  case 2:
239  m_decimators_12.decimate4_inf(it, buf, len);
240  break;
241  case 3:
242  m_decimators_12.decimate8_inf(it, buf, len);
243  break;
244  case 4:
245  m_decimators_12.decimate16_inf(it, buf, len);
246  break;
247  case 5:
248  m_decimators_12.decimate32_inf(it, buf, len);
249  break;
250  case 6:
251  m_decimators_12.decimate64_inf(it, buf, len);
252  break;
253  default:
254  break;
255  }
256  } else if (m_fcPos == 1) {// Supradyne
257  switch (m_log2Decim) {
258  case 1:
259  m_decimators_12.decimate2_sup(it, buf, len);
260  break;
261  case 2:
262  m_decimators_12.decimate4_sup(it, buf, len);
263  break;
264  case 3:
265  m_decimators_12.decimate8_sup(it, buf, len);
266  break;
267  case 4:
268  m_decimators_12.decimate16_sup(it, buf, len);
269  break;
270  case 5:
271  m_decimators_12.decimate32_sup(it, buf, len);
272  break;
273  case 6:
274  m_decimators_12.decimate64_sup(it, buf, len);
275  break;
276  default:
277  break;
278  }
279  } else { // Centered
280  switch (m_log2Decim) {
281  case 1:
282  m_decimators_12.decimate2_cen(it, buf, len);
283  break;
284  case 2:
285  m_decimators_12.decimate4_cen(it, buf, len);
286  break;
287  case 3:
288  m_decimators_12.decimate8_cen(it, buf, len);
289  break;
290  case 4:
291  m_decimators_12.decimate16_cen(it, buf, len);
292  break;
293  case 5:
294  m_decimators_12.decimate32_cen(it, buf, len);
295  break;
296  case 6:
297  m_decimators_12.decimate64_cen(it, buf, len);
298  break;
299  default:
300  break;
301  }
302  }
303  }
304  }
305 
306  void convert_16(SampleVector::iterator* it, const qint16* buf, qint32 len)
307  {
308  if (m_log2Decim == 0) {
309  m_decimators_16.decimate1(it, buf, len);
310  } else {
311  if (m_fcPos == 0) { // Infradyne
312  switch (m_log2Decim) {
313  case 1:
314  m_decimators_16.decimate2_inf(it, buf, len);
315  break;
316  case 2:
317  m_decimators_16.decimate4_inf(it, buf, len);
318  break;
319  case 3:
320  m_decimators_16.decimate8_inf(it, buf, len);
321  break;
322  case 4:
323  m_decimators_16.decimate16_inf(it, buf, len);
324  break;
325  case 5:
326  m_decimators_16.decimate32_inf(it, buf, len);
327  break;
328  case 6:
329  m_decimators_16.decimate64_inf(it, buf, len);
330  break;
331  default:
332  break;
333  }
334  } else if (m_fcPos == 1) {// Supradyne
335  switch (m_log2Decim) {
336  case 1:
337  m_decimators_16.decimate2_sup(it, buf, len);
338  break;
339  case 2:
340  m_decimators_16.decimate4_sup(it, buf, len);
341  break;
342  case 3:
343  m_decimators_16.decimate8_sup(it, buf, len);
344  break;
345  case 4:
346  m_decimators_16.decimate16_sup(it, buf, len);
347  break;
348  case 5:
349  m_decimators_16.decimate32_sup(it, buf, len);
350  break;
351  case 6:
352  m_decimators_16.decimate64_sup(it, buf, len);
353  break;
354  default:
355  break;
356  }
357  } else { // Centered
358  switch (m_log2Decim) {
359  case 1:
360  m_decimators_16.decimate2_cen(it, buf, len);
361  break;
362  case 2:
363  m_decimators_16.decimate4_cen(it, buf, len);
364  break;
365  case 3:
366  m_decimators_16.decimate8_cen(it, buf, len);
367  break;
368  case 4:
369  m_decimators_16.decimate16_cen(it, buf, len);
370  break;
371  case 5:
372  m_decimators_16.decimate32_cen(it, buf, len);
373  break;
374  case 6:
375  m_decimators_16.decimate64_cen(it, buf, len);
376  break;
377  default:
378  break;
379  }
380  }
381  }
382  }
383 
384 
385 private slots:
386  void tick();
387  void handleInputMessages();
388 };
389 
390 #endif // _TESTSOURCE_TESTSOURCETHREAD_H_
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 16 > m_decimators_16
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
uint32_t m_pulsePatternPlaces
void decimate2_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:498
void decimate64_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2975
static MsgStartStop * create(bool startStop)
void decimate64_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:3040
uint32_t m_pulseWidth
pulse width in number of samples
void decimate2_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:526
uint32_t m_pulsePatternCount
void setPhaseImbalance(float phaseImbalance)
void setSamplerate(int samplerate)
void decimate2_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:554
uint32_t m_pulseSampleCount
void setIFactor(float iFactor)
void setLog2Decimation(unsigned int log2_decim)
void startStop(bool start)
TestSourceThread(SampleSinkFifo *sampleFifo, QObject *parent=0)
void setAMModulation(float amModulation)
void setBitSize(uint32_t bitSizeIndex)
void decimate8_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:941
Definition: ncof.h:24
void convert_12(SampleVector::iterator *it, const qint16 *buf, qint32 len)
void decimate64_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2418
void decimate32_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1592
void decimate32_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1902
SampleVector m_convertBuffer
void setModulation(TestSourceSettings::Modulation modulation)
void convert_8(SampleVector::iterator *it, const qint16 *buf, qint32 len)
SampleSinkFifo * m_sampleFifo
QWaitCondition m_startWaiter
unsigned int uint32_t
Definition: rtptypes_win.h:46
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 8 > m_decimators_8
void decimate4_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:682
void setToneFrequency(int toneFrequency)
void setFrequencyShift(int shift)
void decimate8_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1057
void decimate8_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:825
void decimate16_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1300
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
volatile bool m_running
uint32_t m_pulsePatternCycle
void generate(quint32 chunksize)
void setAmplitudeBits(int32_t amplitudeBits)
int int32_t
Definition: rtptypes_win.h:45
void callback(const qint16 *buf, qint32 len)
void decimate4_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:782
void setFMDeviation(float deviation)
void pullAF(Real &afSample)
void setDCFactor(float iFactor)
void decimate4_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:582
void setBuffers(quint32 chunksize)
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 12 > m_decimators_12
unsigned int m_log2Decim
void convert_16(SampleVector::iterator *it, const qint16 *buf, qint32 len)
TestSourceSettings::Modulation m_modulation
MessageQueue m_inputMessageQueue
void decimate16_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1117
std::map< int, int > m_timerHistogram
void setQFactor(float qFactor)
float Real
Definition: dsptypes.h:42
void decimate16_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1483
void decimate32_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2212
QElapsedTimer m_elapsedTimer
void decimate1(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:462
void setFcPos(int fcPos)
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48