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.
testmithread.h
Go to the documentation of this file.
1 // Copyright (C) 2019 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 _TESTMI_TESTMITHREAD_H_
19 #define _TESTMI_TESTMITHREAD_H_
20 
21 #include <QThread>
22 #include <QMutex>
23 #include <QWaitCondition>
24 #include <QTimer>
25 #include <QElapsedTimer>
26 #include <QDebug>
27 
28 #include "dsp/samplesinkfifo.h"
29 #include "dsp/decimators.h"
30 #include "dsp/ncof.h"
31 #include "util/message.h"
32 #include "util/messagequeue.h"
33 
34 #include "testmisettings.h"
35 
36 #define TESTMI_THROTTLE_MS 50
37 
38 class TestMIThread : public QThread {
39  Q_OBJECT
40 
41 public:
42  class MsgStartStop : public Message {
44 
45  public:
46  bool getStartStop() const { return m_startStop; }
47 
48  static MsgStartStop* create(bool startStop) {
49  return new MsgStartStop(startStop);
50  }
51 
52  protected:
54 
56  Message(),
57  m_startStop(startStop)
58  { }
59  };
60 
61  TestMIThread(SampleSinkFifo* sampleFifo, int streamIndex, QObject* parent = 0);
62  ~TestMIThread();
63 
64  void startStop(bool start);
65  void setSamplerate(int samplerate);
66  void setLog2Decimation(unsigned int log2_decim);
67  void setFcPos(int fcPos);
68  void setBitSize(uint32_t bitSizeIndex);
69  void setAmplitudeBits(int32_t amplitudeBits);
70  void setDCFactor(float iFactor);
71  void setIFactor(float iFactor);
72  void setQFactor(float qFactor);
73  void setPhaseImbalance(float phaseImbalance);
74  void setFrequencyShift(int shift);
75  void setToneFrequency(int toneFrequency);
77  void setAMModulation(float amModulation);
78  void setFMDeviation(float deviation);
79  void setPattern0();
80  void setPattern1();
81  void setPattern2();
82 
83 private:
85  QWaitCondition m_startWaiter;
86  volatile bool m_running;
87 
88  qint16 *m_buf;
89  quint32 m_bufsize;
90  quint32 m_chunksize;
101  float m_fmPhasor;
107 
109  unsigned int m_log2Decim;
110  int m_fcPos;
114  float m_dcBias;
115  float m_iBias;
116  float m_qBias;
121 
124 
126  QTimer m_timer;
127  QElapsedTimer m_elapsedTimer;
129  QMutex m_mutex;
130 
132 
136 
137  void startWork();
138  void stopWork();
139  void run();
140  void callback(const qint16* buf, qint32 len);
141  void setBuffers(quint32 chunksize);
142  void generate(quint32 chunksize);
143  void pullAF(Real& afSample);
144 
145  // Decimate according to specified log2 (ex: log2=4 => decim=16)
146  inline void convert_8(SampleVector::iterator* it, const qint16* buf, qint32 len)
147  {
148  if (m_log2Decim == 0) {
149  m_decimators_8.decimate1(it, buf, len);
150  } else {
151  if (m_fcPos == 0) { // Infradyne
152  switch (m_log2Decim) {
153  case 1:
154  m_decimators_8.decimate2_inf(it, buf, len);
155  break;
156  case 2:
157  m_decimators_8.decimate4_inf(it, buf, len);
158  break;
159  case 3:
160  m_decimators_8.decimate8_inf(it, buf, len);
161  break;
162  case 4:
163  m_decimators_8.decimate16_inf(it, buf, len);
164  break;
165  case 5:
166  m_decimators_8.decimate32_inf(it, buf, len);
167  break;
168  case 6:
169  m_decimators_8.decimate64_inf(it, buf, len);
170  break;
171  default:
172  break;
173  }
174  } else if (m_fcPos == 1) {// Supradyne
175  switch (m_log2Decim) {
176  case 1:
177  m_decimators_8.decimate2_sup(it, buf, len);
178  break;
179  case 2:
180  m_decimators_8.decimate4_sup(it, buf, len);
181  break;
182  case 3:
183  m_decimators_8.decimate8_sup(it, buf, len);
184  break;
185  case 4:
186  m_decimators_8.decimate16_sup(it, buf, len);
187  break;
188  case 5:
189  m_decimators_8.decimate32_sup(it, buf, len);
190  break;
191  case 6:
192  m_decimators_8.decimate64_sup(it, buf, len);
193  break;
194  default:
195  break;
196  }
197  } else { // Centered
198  switch (m_log2Decim) {
199  case 1:
200  m_decimators_8.decimate2_cen(it, buf, len);
201  break;
202  case 2:
203  m_decimators_8.decimate4_cen(it, buf, len);
204  break;
205  case 3:
206  m_decimators_8.decimate8_cen(it, buf, len);
207  break;
208  case 4:
209  m_decimators_8.decimate16_cen(it, buf, len);
210  break;
211  case 5:
212  m_decimators_8.decimate32_cen(it, buf, len);
213  break;
214  case 6:
215  m_decimators_8.decimate64_cen(it, buf, len);
216  break;
217  default:
218  break;
219  }
220  }
221  }
222  }
223 
224  void convert_12(SampleVector::iterator* it, const qint16* buf, qint32 len)
225  {
226  if (m_log2Decim == 0) {
227  m_decimators_12.decimate1(it, buf, len);
228  } else {
229  if (m_fcPos == 0) { // Infradyne
230  switch (m_log2Decim) {
231  case 1:
232  m_decimators_12.decimate2_inf(it, buf, len);
233  break;
234  case 2:
235  m_decimators_12.decimate4_inf(it, buf, len);
236  break;
237  case 3:
238  m_decimators_12.decimate8_inf(it, buf, len);
239  break;
240  case 4:
241  m_decimators_12.decimate16_inf(it, buf, len);
242  break;
243  case 5:
244  m_decimators_12.decimate32_inf(it, buf, len);
245  break;
246  case 6:
247  m_decimators_12.decimate64_inf(it, buf, len);
248  break;
249  default:
250  break;
251  }
252  } else if (m_fcPos == 1) {// Supradyne
253  switch (m_log2Decim) {
254  case 1:
255  m_decimators_12.decimate2_sup(it, buf, len);
256  break;
257  case 2:
258  m_decimators_12.decimate4_sup(it, buf, len);
259  break;
260  case 3:
261  m_decimators_12.decimate8_sup(it, buf, len);
262  break;
263  case 4:
264  m_decimators_12.decimate16_sup(it, buf, len);
265  break;
266  case 5:
267  m_decimators_12.decimate32_sup(it, buf, len);
268  break;
269  case 6:
270  m_decimators_12.decimate64_sup(it, buf, len);
271  break;
272  default:
273  break;
274  }
275  } else { // Centered
276  switch (m_log2Decim) {
277  case 1:
278  m_decimators_12.decimate2_cen(it, buf, len);
279  break;
280  case 2:
281  m_decimators_12.decimate4_cen(it, buf, len);
282  break;
283  case 3:
284  m_decimators_12.decimate8_cen(it, buf, len);
285  break;
286  case 4:
287  m_decimators_12.decimate16_cen(it, buf, len);
288  break;
289  case 5:
290  m_decimators_12.decimate32_cen(it, buf, len);
291  break;
292  case 6:
293  m_decimators_12.decimate64_cen(it, buf, len);
294  break;
295  default:
296  break;
297  }
298  }
299  }
300  }
301 
302  void convert_16(SampleVector::iterator* it, const qint16* buf, qint32 len)
303  {
304  if (m_log2Decim == 0) {
305  m_decimators_16.decimate1(it, buf, len);
306  } else {
307  if (m_fcPos == 0) { // Infradyne
308  switch (m_log2Decim) {
309  case 1:
310  m_decimators_16.decimate2_inf(it, buf, len);
311  break;
312  case 2:
313  m_decimators_16.decimate4_inf(it, buf, len);
314  break;
315  case 3:
316  m_decimators_16.decimate8_inf(it, buf, len);
317  break;
318  case 4:
319  m_decimators_16.decimate16_inf(it, buf, len);
320  break;
321  case 5:
322  m_decimators_16.decimate32_inf(it, buf, len);
323  break;
324  case 6:
325  m_decimators_16.decimate64_inf(it, buf, len);
326  break;
327  default:
328  break;
329  }
330  } else if (m_fcPos == 1) {// Supradyne
331  switch (m_log2Decim) {
332  case 1:
333  m_decimators_16.decimate2_sup(it, buf, len);
334  break;
335  case 2:
336  m_decimators_16.decimate4_sup(it, buf, len);
337  break;
338  case 3:
339  m_decimators_16.decimate8_sup(it, buf, len);
340  break;
341  case 4:
342  m_decimators_16.decimate16_sup(it, buf, len);
343  break;
344  case 5:
345  m_decimators_16.decimate32_sup(it, buf, len);
346  break;
347  case 6:
348  m_decimators_16.decimate64_sup(it, buf, len);
349  break;
350  default:
351  break;
352  }
353  } else { // Centered
354  switch (m_log2Decim) {
355  case 1:
356  m_decimators_16.decimate2_cen(it, buf, len);
357  break;
358  case 2:
359  m_decimators_16.decimate4_cen(it, buf, len);
360  break;
361  case 3:
362  m_decimators_16.decimate8_cen(it, buf, len);
363  break;
364  case 4:
365  m_decimators_16.decimate16_cen(it, buf, len);
366  break;
367  case 5:
368  m_decimators_16.decimate32_cen(it, buf, len);
369  break;
370  case 6:
371  m_decimators_16.decimate64_cen(it, buf, len);
372  break;
373  default:
374  break;
375  }
376  }
377  }
378  }
379 
380 
381 private slots:
382  void tick();
383  void handleInputMessages();
384 };
385 
386 #endif // _TESTSOURCE_TESTSOURCETHREAD_H_
void setQFactor(float qFactor)
void setSamplerate(int samplerate)
SampleSinkFifo * m_sampleFifo
Definition: testmithread.h:92
void convert_16(SampleVector::iterator *it, const qint16 *buf, qint32 len)
Definition: testmithread.h:302
void setPattern2()
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
bool m_throttleToggle
Definition: testmithread.h:128
void decimate2_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:498
QElapsedTimer m_elapsedTimer
Definition: testmithread.h:127
void decimate64_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2975
int32_t m_amplitudeBitsDC
Definition: testmithread.h:118
void decimate64_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:3040
void decimate2_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:526
void decimate2_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:554
unsigned int m_log2Decim
Definition: testmithread.h:109
void decimate8_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:941
TestMIStreamSettings::Modulation m_modulation
Definition: testmithread.h:98
Definition: ncof.h:24
QWaitCondition m_startWaiter
Definition: testmithread.h:85
TestMIThread(SampleSinkFifo *sampleFifo, int streamIndex, QObject *parent=0)
static MsgStartStop * create(bool startStop)
Definition: testmithread.h:48
uint32_t m_pulseSampleCount
Definition: testmithread.h:103
void setFMDeviation(float deviation)
uint32_t m_bitSizeIndex
Definition: testmithread.h:111
void setIFactor(float iFactor)
float m_phaseImbalance
Definition: testmithread.h:117
uint32_t m_bitShift
Definition: testmithread.h:112
void setDCFactor(float iFactor)
void decimate64_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2418
void generate(quint32 chunksize)
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
uint32_t m_pulsePatternCycle
Definition: testmithread.h:105
int32_t m_amplitudeBitsQ
Definition: testmithread.h:120
uint32_t m_pulsePatternPlaces
Definition: testmithread.h:106
SampleVector m_convertBuffer
Definition: testmithread.h:91
unsigned int uint32_t
Definition: rtptypes_win.h:46
void decimate4_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:682
int32_t m_amplitudeBits
Definition: testmithread.h:113
uint32_t m_pulsePatternCount
Definition: testmithread.h:104
void decimate8_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1057
MessageQueue m_inputMessageQueue
Definition: testmithread.h:131
void handleInputMessages()
void decimate8_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:825
uint64_t m_frequency
Definition: testmithread.h:122
void decimate16_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1300
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
void convert_8(SampleVector::iterator *it, const qint16 *buf, qint32 len)
Definition: testmithread.h:146
void setBuffers(quint32 chunksize)
float m_fmPhasor
Definition: testmithread.h:101
void setBitSize(uint32_t bitSizeIndex)
void pullAF(Real &afSample)
int int32_t
Definition: rtptypes_win.h:45
void callback(const qint16 *buf, qint32 len)
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 16 > m_decimators_16
Definition: testmithread.h:135
void decimate4_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:782
void setModulation(TestMIStreamSettings::Modulation modulation)
volatile bool m_running
Definition: testmithread.h:86
QMutex m_mutex
Definition: testmithread.h:129
void setPattern1()
void decimate4_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:582
int m_toneFrequency
Definition: testmithread.h:97
QMutex m_startWaitMutex
Definition: testmithread.h:84
void startWork()
void setFcPos(int fcPos)
void setPattern0()
void setToneFrequency(int toneFrequency)
float m_amModulation
Definition: testmithread.h:99
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 12 > m_decimators_12
Definition: testmithread.h:134
QTimer m_timer
Definition: testmithread.h:126
uint32_t m_pulseWidth
pulse width in number of samples
Definition: testmithread.h:102
void decimate16_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1117
void setAmplitudeBits(int32_t amplitudeBits)
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 8 > m_decimators_8
Definition: testmithread.h:133
void startStop(bool start)
int32_t m_amplitudeBitsI
Definition: testmithread.h:119
quint32 m_chunksize
Definition: testmithread.h:90
void setLog2Decimation(unsigned int log2_decim)
qint16 * m_buf
Definition: testmithread.h:88
MsgStartStop(bool startStop)
Definition: testmithread.h:55
void convert_12(SampleVector::iterator *it, const qint16 *buf, qint32 len)
Definition: testmithread.h:224
void setPhaseImbalance(float phaseImbalance)
float Real
Definition: dsptypes.h:42
quint32 m_bufsize
Definition: testmithread.h:89
int m_frequencyShift
Definition: testmithread.h:96
void decimate16_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1483
void setAMModulation(float amModulation)
void decimate32_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2212
void decimate1(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:462
void setFrequencyShift(int shift)
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48
float m_fmDeviationUnit
Definition: testmithread.h:100