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.
fcdprothread.cpp
Go to the documentation of this file.
1 // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
3 // written by Christian Daniel //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <QDebug>
20 #include <stdio.h>
21 #include <errno.h>
22 #include <chrono>
23 #include <thread>
24 
25 #include "dsp/samplesinkfifo.h"
26 #include "audio/audiofifo.h"
27 
28 #include "fcdprothread.h"
29 
30 FCDProThread::FCDProThread(SampleSinkFifo* sampleFifo, AudioFifo *fcdFIFO, QObject* parent) :
31  QThread(parent),
32  m_fcdFIFO(fcdFIFO),
33  m_running(false),
34  m_log2Decim(0),
35  m_fcPos(2),
36  m_convertBuffer(fcd_traits<Pro>::convBufSize), // nb samples
37  m_sampleFifo(sampleFifo)
38 {
39  start();
40 }
41 
43 {
44 }
45 
47 {
48  m_startWaitMutex.lock();
49 
50  start();
51 
52  while(!m_running)
53  {
54  m_startWaiter.wait(&m_startWaitMutex, 100);
55  }
56 
57  m_startWaitMutex.unlock();
58 }
59 
61 {
62  m_running = false;
63  wait();
64 }
65 
66 void FCDProThread::setLog2Decimation(unsigned int log2_decim)
67 {
68  m_log2Decim = log2_decim;
69 }
70 
71 void FCDProThread::setFcPos(int fcPos)
72 {
73  m_fcPos = fcPos;
74 }
75 
77 {
78  m_running = true;
79  qDebug("FCDProThread::run: start running loop");
80 
81  while (m_running)
82  {
84  std::this_thread::sleep_for(std::chrono::microseconds(200));
85  }
86 
87  qDebug("FCDProThread::run: running loop stopped");
88  m_running = false;
89 }
90 
91 void FCDProThread::work(unsigned int n_items)
92 {
93  uint32_t nbRead = m_fcdFIFO->read((unsigned char *) m_buf, n_items); // number of samples
94  SampleVector::iterator it = m_convertBuffer.begin();
95 
96  if (m_log2Decim == 0)
97  {
98  m_decimators.decimate1(&it, m_buf, 2*nbRead);
99  }
100  else
101  {
102  if (m_fcPos == 0) // Infradyne
103  {
104  switch (m_log2Decim)
105  {
106  case 1:
107  m_decimators.decimate2_inf(&it, m_buf, 2*nbRead);
108  break;
109  case 2:
110  m_decimators.decimate4_inf(&it, m_buf, 2*nbRead);
111  break;
112  case 3:
113  m_decimators.decimate8_inf(&it, m_buf, 2*nbRead);
114  break;
115  case 4:
116  m_decimators.decimate16_inf(&it, m_buf, 2*nbRead);
117  break;
118  case 5:
119  m_decimators.decimate32_inf(&it, m_buf, 2*nbRead);
120  break;
121  case 6:
122  m_decimators.decimate64_inf(&it, m_buf, 2*nbRead);
123  break;
124  default:
125  break;
126  }
127  }
128  else if (m_fcPos == 1) // Supradyne
129  {
130  switch (m_log2Decim)
131  {
132  case 1:
133  m_decimators.decimate2_sup(&it, m_buf, 2*nbRead);
134  break;
135  case 2:
136  m_decimators.decimate4_sup(&it, m_buf, 2*nbRead);
137  break;
138  case 3:
139  m_decimators.decimate8_sup(&it, m_buf, 2*nbRead);
140  break;
141  case 4:
142  m_decimators.decimate16_sup(&it, m_buf, 2*nbRead);
143  break;
144  case 5:
145  m_decimators.decimate32_sup(&it, m_buf, 2*nbRead);
146  break;
147  case 6:
148  m_decimators.decimate64_sup(&it, m_buf, 2*nbRead);
149  break;
150  default:
151  break;
152  }
153  }
154  else // Centered
155  {
156  switch (m_log2Decim)
157  {
158  case 1:
159  m_decimators.decimate2_cen(&it, m_buf, 2*nbRead);
160  break;
161  case 2:
162  m_decimators.decimate4_cen(&it, m_buf, 2*nbRead);
163  break;
164  case 3:
165  m_decimators.decimate8_cen(&it, m_buf, 2*nbRead);
166  break;
167  case 4:
168  m_decimators.decimate16_cen(&it, m_buf, 2*nbRead);
169  break;
170  case 5:
171  m_decimators.decimate32_cen(&it, m_buf, 2*nbRead);
172  break;
173  case 6:
174  m_decimators.decimate64_cen(&it, m_buf, 2*nbRead);
175  break;
176  default:
177  break;
178  }
179  }
180  }
181 
182  m_sampleFifo->write(m_convertBuffer.begin(), it);
183 }
void setLog2Decimation(unsigned int log2_decim)
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
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 work(unsigned int n_items)
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
SampleSinkFifo * m_sampleFifo
Definition: fcdprothread.h:54
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 m_log2Decim
Definition: fcdprothread.h:49
unsigned int uint32_t
Definition: rtptypes_win.h:46
void decimate4_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:682
QMutex m_startWaitMutex
Definition: fcdprothread.h:46
void decimate8_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1057
SampleVector m_convertBuffer
Definition: fcdprothread.h:53
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
QWaitCondition m_startWaiter
Definition: fcdprothread.h:47
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 setFcPos(int fcPos)
FCDProThread(SampleSinkFifo *sampleFifo, AudioFifo *fcdFIFO, QObject *parent=nullptr)
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 16 > m_decimators
Definition: fcdprothread.h:55
Definition: fcdtraits.h:25
void decimate16_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1117
void startWork()
AudioFifo * m_fcdFIFO
Definition: fcdprothread.h:44
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
void decimate1(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:462
qint16 m_buf[fcd_traits< Pro >::convBufSize *2]
Definition: fcdprothread.h:52