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.
fcdproplusthread.cpp
Go to the documentation of this file.
1 // Copyright (C) 2016-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 #include <QDebug>
19 #include <stdio.h>
20 #include <errno.h>
21 #include <chrono>
22 #include <thread>
23 
24 #include "dsp/samplesinkfifo.h"
25 #include "audio/audiofifo.h"
26 
27 #include "fcdproplusthread.h"
28 
29 FCDProPlusThread::FCDProPlusThread(SampleSinkFifo* sampleFifo, AudioFifo *fcdFIFO, QObject* parent) :
30  QThread(parent),
31  m_fcdFIFO(fcdFIFO),
32  m_running(false),
33  m_log2Decim(0),
34  m_fcPos(2),
35  m_convertBuffer(fcd_traits<ProPlus>::convBufSize), // nb samples
36  m_sampleFifo(sampleFifo)
37 {
38  start();
39 }
40 
42 {
43 }
44 
46 {
47  m_startWaitMutex.lock();
48 
49  start();
50 
51  while(!m_running)
52  {
53  m_startWaiter.wait(&m_startWaitMutex, 100);
54  }
55 
56  m_startWaitMutex.unlock();
57 }
58 
60 {
61  m_running = false;
62  wait();
63 }
64 
65 void FCDProPlusThread::setLog2Decimation(unsigned int log2_decim)
66 {
67  m_log2Decim = log2_decim;
68 }
69 
71 {
72  m_fcPos = fcPos;
73 }
74 
76 {
77  m_running = true;
78  qDebug("FCDThread::run: start running loop");
79 
80  while (m_running)
81  {
83  std::this_thread::sleep_for(std::chrono::microseconds(100));
84  }
85 
86  qDebug("FCDThread::run: running loop stopped");
87  m_running = false;
88 }
89 
90 void FCDProPlusThread::work(unsigned int n_items)
91 {
92  uint32_t nbRead = m_fcdFIFO->read((unsigned char *) m_buf, n_items); // number of samples
93  SampleVector::iterator it = m_convertBuffer.begin();
94 
95  if (m_log2Decim == 0)
96  {
97  m_decimators.decimate1(&it, m_buf, 2*nbRead);
98  }
99  else
100  {
101  if (m_fcPos == 0) // Infradyne
102  {
103  switch (m_log2Decim)
104  {
105  case 1:
106  m_decimators.decimate2_inf(&it, m_buf, 2*nbRead);
107  break;
108  case 2:
109  m_decimators.decimate4_inf(&it, m_buf, 2*nbRead);
110  break;
111  case 3:
112  m_decimators.decimate8_inf(&it, m_buf, 2*nbRead);
113  break;
114  case 4:
115  m_decimators.decimate16_inf(&it, m_buf, 2*nbRead);
116  break;
117  case 5:
118  m_decimators.decimate32_inf(&it, m_buf, 2*nbRead);
119  break;
120  case 6:
121  m_decimators.decimate64_inf(&it, m_buf, 2*nbRead);
122  break;
123  default:
124  break;
125  }
126  }
127  else if (m_fcPos == 1) // Supradyne
128  {
129  switch (m_log2Decim)
130  {
131  case 1:
132  m_decimators.decimate2_sup(&it, m_buf, 2*nbRead);
133  break;
134  case 2:
135  m_decimators.decimate4_sup(&it, m_buf, 2*nbRead);
136  break;
137  case 3:
138  m_decimators.decimate8_sup(&it, m_buf, 2*nbRead);
139  break;
140  case 4:
141  m_decimators.decimate16_sup(&it, m_buf, 2*nbRead);
142  break;
143  case 5:
144  m_decimators.decimate32_sup(&it, m_buf, 2*nbRead);
145  break;
146  case 6:
147  m_decimators.decimate64_sup(&it, m_buf, 2*nbRead);
148  break;
149  default:
150  break;
151  }
152  }
153  else // Centered
154  {
155  switch (m_log2Decim)
156  {
157  case 1:
158  m_decimators.decimate2_cen(&it, m_buf, 2*nbRead);
159  break;
160  case 2:
161  m_decimators.decimate4_cen(&it, m_buf, 2*nbRead);
162  break;
163  case 3:
164  m_decimators.decimate8_cen(&it, m_buf, 2*nbRead);
165  break;
166  case 4:
167  m_decimators.decimate16_cen(&it, m_buf, 2*nbRead);
168  break;
169  case 5:
170  m_decimators.decimate32_cen(&it, m_buf, 2*nbRead);
171  break;
172  case 6:
173  m_decimators.decimate64_cen(&it, m_buf, 2*nbRead);
174  break;
175  default:
176  break;
177  }
178  }
179  }
180 
181  m_sampleFifo->write(m_convertBuffer.begin(), it);
182 }
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 16 > m_decimators
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
SampleVector m_convertBuffer
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
uint write(const quint8 *data, uint count)
void decimate8_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:941
FCDProPlusThread(SampleSinkFifo *sampleFifo, AudioFifo *fcdFIFO, QObject *parent=nullptr)
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
unsigned int uint32_t
Definition: rtptypes_win.h:46
void setFcPos(int fcPos)
void decimate4_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:682
AudioFifo * m_fcdFIFO
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 setLog2Decimation(unsigned int log2_decim)
void decimate16_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1300
qint16 m_buf[fcd_traits< ProPlus >::convBufSize *2]
void decimate4_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:782
uint32_t read(quint8 *data, uint32_t numSamples)
Definition: audiofifo.cpp:103
void decimate4_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:582
void work(unsigned int n_items)
void decimate16_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1117
unsigned int m_log2Decim
void decimate16_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1483
QWaitCondition m_startWaiter
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
SampleSinkFifo * m_sampleFifo