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.
datvdemod.h
Go to the documentation of this file.
1 // Copyright (C) 2018 F4HKW //
3 // for F4EXB / SDRAngel //
4 // using LeanSDR Framework (C) 2016 F4DAV //
5 // //
6 // This program is free software; you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation as version 3 of the License, or //
9 // (at your option) any later version. //
10 // //
11 // This program is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License V3 for more details. //
15 // //
16 // You should have received a copy of the GNU General Public License //
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
19 
20 #ifndef INCLUDE_DATVDEMOD_H
21 #define INCLUDE_DATVDEMOD_H
22 
23 class DeviceAPI;
25 class DownChannelizer;
26 
27 #define rfFilterFftLength 1024
28 
29 //LeanSDR
30 #include "leansdr/framework.h"
31 #include "leansdr/generic.h"
32 #include "leansdr/dvb.h"
33 #include "leansdr/filtergen.h"
34 
35 #include "leansdr/hdlc.h"
36 #include "leansdr/iess.h"
37 
38 #include "datvconstellation.h"
39 #include "datvdvbs2constellation.h"
40 #include "datvvideoplayer.h"
41 #include "datvideostream.h"
42 #include "datvudpstream.h"
43 #include "datvideorender.h"
44 #include "datvdemodsettings.h"
45 
46 #include "channel/channelapi.h"
47 #include "dsp/basebandsamplesink.h"
48 #include "dsp/devicesamplesource.h"
49 #include "dsp/dspcommands.h"
50 #include "dsp/downchannelizer.h"
51 #include "dsp/fftfilt.h"
52 #include "dsp/nco.h"
53 #include "dsp/interpolator.h"
54 #include "dsp/movingaverage.h"
55 #include "dsp/agc.h"
56 #include "audio/audiofifo.h"
57 #include "util/message.h"
58 #include "util/movingaverage.h"
59 
60 #include <QMutex>
61 
62 // enum DATVModulation { BPSK, QPSK, PSK8, APSK16, APSK32, APSK64E, QAM16, QAM64, QAM256 };
63 // enum dvb_version { DVB_S, DVB_S2 };
64 // enum dvb_sampler { SAMP_NEAREST, SAMP_LINEAR, SAMP_RRC };
65 
66 inline int decimation(float Fin, float Fout) { int d = Fin / Fout; return std::max(d, 1); }
67 
68 struct config
69 {
72 
73  int buf_factor; // Buffer sizing
74  float Fs; // Sampling frequency (Hz)
75  float Fderot; // Shift the signal (Hz). Note: Ftune is faster
76  int anf; // Number of auto notch filters
77  bool cnr; // Measure CNR
78  unsigned int decim; // Decimation, 0=auto
79  float Fm; // QPSK symbol rate (Hz)
82  float Ftune; // Bias frequency for the QPSK demodulator (Hz)
84  bool fastlock;
85  bool viterbi;
87  bool resample;
88  float resample_rej; // Approx. filter rejection in dB
89  int rrc_steps; // Discrete steps between symbols, 0=auto
90  float rrc_rej; // Approx. RRC filter rejection in dB
91  float rolloff; // Roll-off 0..1
92  bool hdlc; // Expect HDLC frames instead of MPEG packets
93  bool packetized; // Output frames with 16-bit BE length
94  float Finfo; // Desired refresh rate on fd_info (Hz)
95 
96  config() :
97  standard(DATVDemodSettings::DVB_S),
98  sampler(DATVDemodSettings::SAMP_LINEAR),
99  buf_factor(4),
100  Fs(2.4e6),
101  Fderot(0),
102  anf(0),
103  cnr(false),
104  decim(0),
105  Fm(2e6),
106  constellation(leansdr::cstln_lut<leansdr::eucl_ss, 256>::QPSK),
107  fec(leansdr::FEC12),
108  Ftune(0),
109  allow_drift(false),
110  fastlock(true),
111  viterbi(false),
112  hard_metric(false),
113  resample(false),
114  resample_rej(10),
115  rrc_steps(0),
116  rrc_rej(10),
117  rolloff(0.35),
118  hdlc(false),
119  packetized(false),
120  Finfo(5)
121  {
122  }
123 };
124 
126 {
127  Q_OBJECT
128 
129 public:
130 
131  DATVDemod(DeviceAPI *);
132  ~DATVDemod();
133 
134  virtual void destroy() { delete this; }
135  virtual void getIdentifier(QString& id) { id = objectName(); }
136  virtual void getTitle(QString& title) { title = objectName(); }
137  virtual qint64 getCenterFrequency() const { return m_settings.m_centerFrequency; }
138 
139  virtual QByteArray serialize() const { return QByteArray(); }
140  virtual bool deserialize(const QByteArray& data) { (void) data; return false; }
141 
142  virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
143  virtual void start();
144  virtual void stop();
145  virtual bool handleMessage(const Message& cmd);
146 
147  virtual int getNbSinkStreams() const { return 1; }
148  virtual int getNbSourceStreams() const { return 0; }
149 
150  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
151  {
152  (void) streamIndex;
153  (void) sinkElseSource;
154  return m_settings.m_centerFrequency;
155  }
156 
157  bool SetTVScreen(TVScreen *objScreen);
158  DATVideostream * SetVideoRender(DATVideoRender *objScreen);
159  bool audioActive();
160  bool audioDecodeOK();
161  bool videoActive();
162  bool videoDecodeOK();
163 
164  bool PlayVideo(bool blnStartStop);
165 
166  void InitDATVParameters(
167  int intMsps,
168  int intRFBandwidth,
169  int intCenterFrequency,
170  DATVDemodSettings::dvb_version enmStandard,
171  DATVDemodSettings::DATVModulation enmModulation,
172  leansdr::code_rate enmFEC,
173  int intSampleRate,
174  int intSymbolRate,
175  int intNotchFilters,
176  bool blnAllowDrift,
177  bool blnFastLock,
179  bool blnHardMetric,
180  float fltRollOff,
181  bool blnViterbi,
182  int intEExcursion);
183 
184  void CleanUpDATVFramework(bool blnRelease);
185  int GetSampleRate();
186  void InitDATVFramework();
187  void InitDATVS2Framework();
188  double getMagSq() const { return m_objMagSqAverage; }
189  int getModcodModulation() const { return m_modcodModulation; }
190  int getModcodCodeRate() const { return m_modcodCodeRate; }
191  bool isCstlnSetByModcod() const { return m_cstlnSetByModcod; }
192  static DATVDemodSettings::DATVCodeRate getCodeRateFromLeanDVBCode(int leanDVBCodeRate);
193  static DATVDemodSettings::DATVModulation getModulationFromLeanDVBCode(int leanDVBModulation);
194  static int getLeanDVBCodeRateFromDATV(DATVDemodSettings::DATVCodeRate datvCodeRate);
195  static int getLeanDVBModulationFromDATV(DATVDemodSettings::DATVModulation datvModulation);
196 
197  static const QString m_channelIdURI;
198  static const QString m_channelId;
199 
201  {
203 
204  public:
205  int getCenterFrequency() const { return m_centerFrequency; }
206 
207  static MsgConfigureChannelizer* create(int centerFrequency) {
208  return new MsgConfigureChannelizer(centerFrequency);
209  }
210 
211  private:
213 
214  MsgConfigureChannelizer(int centerFrequency) :
215  Message(),
216  m_centerFrequency(centerFrequency)
217  {}
218  };
219 
222 
223  public:
224  const DATVDemodSettings& getSettings() const { return m_settings; }
225  bool getForce() const { return m_force; }
226 
227  static MsgConfigureDATVDemod* create(const DATVDemodSettings& settings, bool force)
228  {
229  return new MsgConfigureDATVDemod(settings, force);
230  }
231 
232  private:
234  bool m_force;
235 
236  MsgConfigureDATVDemod(const DATVDemodSettings& settings, bool force) :
237  Message(),
238  m_settings(settings),
239  m_force(force)
240  { }
241  };
242 
245 
246  public:
247  DATVDemodSettings::DATVModulation getModulation() const { return m_modulation; }
248  DATVDemodSettings::DATVCodeRate getCodeRate() const { return m_codeRate; }
249 
251  const DATVDemodSettings::DATVCodeRate& codeRate)
252  {
253  return new MsgReportModcodCstlnChange(modulation, codeRate);
254  }
255 
256  private:
259 
261  const DATVDemodSettings::DATVModulation& modulation,
262  const DATVDemodSettings::DATVCodeRate& codeRate
263  ) :
264  Message(),
265  m_modulation(modulation),
266  m_codeRate(codeRate)
267  { }
268  };
269 
270 private:
271  unsigned long m_lngExpectedReadIQ;
273 
274  //************** LEANDBV Parameters **************
275 
276  unsigned long BUF_BASEBAND;
277  unsigned long BUF_SYMBOLS;
278  unsigned long BUF_BYTES;
279  unsigned long BUF_MPEGBYTES;
280  unsigned long BUF_PACKETS;
281  unsigned long BUF_SLOW;
282 
283 
284  //dvbs2
285  unsigned long BUF_SLOTS;
286  unsigned long BUF_FRAMES;
287  unsigned long BUF_S2PACKETS;
288  unsigned long S2_MAX_SYMBOLS;
289 
290  //************** LEANDBV Scheduler ***************
291 
293  struct config m_objCfg;
294 
297 
298  //LeanSDR Pipe Buffer
299  // INPUT
300 
304 
305  // NOTCH FILTER
308 
309  // FREQUENCY CORRECTION : DEROTATOR
312 
313  // CNR ESTIMATION
316 
317  //FILTERING
320  float *coeffs;
321  int ncoeffs;
322 
323  // OUTPUT PREPROCESSED DATA
327 
333 
334  //dvb-s2
340  void *p_fecframes;
341  void *p_bbframes;
343  void *r_fecdec;
344  void *p_deframer;
345 
346  //DECIMATION
349 
350  //PROCESSED DATA MONITORING
352 
353  //GENERIC CONSTELLATION RECEIVER
355 
356  // DECONVOLUTION AND SYNCHRONIZATION
362 
365 
370 
371 
372  // DEINTERLEAVING
375 
376  // REED-SOLOMON
381 
382  // BER ESTIMATION
385 
386  // DERANDOMIZATION
389 
390 
391  //OUTPUT
394 
395  //CONSTELLATION
398 
400 
403 
404  //*************** DATV PARAMETERS ***************
410 
411  // Audio
413 
416 
423 
425 
426  //DATVConfig m_objRunning;
431 
433 
434  //void ApplySettings();
435  void applySettings(const DATVDemodSettings& settings, bool force = false);
436  void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false);
437 };
438 
439 #endif // INCLUDE_DATVDEMOD_H
leansdr::pipebuf< leansdr::u8 > * p_bytes
Definition: datvdemod.h:357
leansdr::pipebuf< leansdr::f32 > * p_ss
Definition: datvdemod.h:330
leansdr::code_rate fec
Definition: datvdemod.h:81
int buf_factor
Definition: datvdemod.h:73
int getModcodModulation() const
Definition: datvdemod.h:189
bool isCstlnSetByModcod() const
Definition: datvdemod.h:191
leansdr::pipebuf< int > * p_lock
Definition: datvdemod.h:367
leansdr::rs_decoder< leansdr::u8, 0 > * r_rsdec
Definition: datvdemod.h:380
void * p_deframer
Definition: datvdemod.h:344
unsigned int decim
Definition: datvdemod.h:78
leansdr::pipebuf< leansdr::u32 > * p_locktime
Definition: datvdemod.h:368
DATVDemodSettings::DATVCodeRate getCodeRate() const
Definition: datvdemod.h:248
bool resample
Definition: datvdemod.h:87
void * p_fecframes
Definition: datvdemod.h:340
leansdr::pipebuf< leansdr::u8 > * p_mpegbytes
Definition: datvdemod.h:366
bool viterbi
Definition: datvdemod.h:85
leansdr::pipebuf< leansdr::tspacket > * p_rtspackets
Definition: datvdemod.h:379
bool m_cstlnSetByModcod
Definition: datvdemod.h:420
leansdr::pipebuf< int > * p_vbitcount
Definition: datvdemod.h:377
config()
Definition: datvdemod.h:96
leansdr::pipebuf< leansdr::rspacket< leansdr::u8 > > * p_rspackets
Definition: datvdemod.h:373
leansdr::rotator< leansdr::f32 > * r_derot
Definition: datvdemod.h:311
unsigned long BUF_PACKETS
Definition: datvdemod.h:280
void * m_objDemodulatorDVBS2
Definition: datvdemod.h:339
leansdr::datvdvbs2constellation< leansdr::f32 > * r_scope_symbols_dvbs2
Definition: datvdemod.h:397
leansdr::pipebuf< leansdr::f32 > * p_cnr
Definition: datvdemod.h:314
MsgConfigureDATVDemod(const DATVDemodSettings &settings, bool force)
Definition: datvdemod.h:236
leansdr::pipewriter< leansdr::cf32 > * p_rawiq_writer
Definition: datvdemod.h:302
float resample_rej
Definition: datvdemod.h:88
int decimation(float Fin, float Fout)
Definition: datvdemod.h:66
leansdr::pipebuf< leansdr::u8 > * p_descrambled
Definition: datvdemod.h:360
unsigned long BUF_MPEGBYTES
Definition: datvdemod.h:279
leansdr::pipebuf< leansdr::f32 > * p_freq
Definition: datvdemod.h:329
leansdr::pipebuf< leansdr::eucl_ss > * p_symbols
Definition: datvdemod.h:328
leansdr::datvvideoplayer< leansdr::tspacket > * r_videoplayer
Definition: datvdemod.h:393
bool allow_drift
Definition: datvdemod.h:83
leansdr::decimator< leansdr::cf32 > * p_decim
Definition: datvdemod.h:348
bool m_blnNeedConfigUpdate
Definition: datvdemod.h:296
int ncoeffs_sampler
Definition: datvdemod.h:326
unsigned long BUF_SLOW
Definition: datvdemod.h:281
static const QString m_channelIdURI
Definition: datvdemod.h:197
unsigned long BUF_FRAMES
Definition: datvdemod.h:286
float Ftune
Definition: datvdemod.h:82
float rrc_rej
Definition: datvdemod.h:90
leansdr::pipebuf< leansdr::cf32 > * p_autonotched
Definition: datvdemod.h:307
leansdr::cnr_fft< leansdr::f32 > * r_cnr
Definition: datvdemod.h:315
static const QString m_channelId
Definition: datvdemod.h:198
bool m_blnRenderingVideo
Definition: datvdemod.h:418
leansdr::mpeg_sync< leansdr::u8, 0 > * r_sync_mpeg
Definition: datvdemod.h:369
DATVDemodSettings::dvb_sampler sampler
Definition: datvdemod.h:71
bool m_blnDVBInitialized
Definition: datvdemod.h:295
int ncoeffs
Definition: datvdemod.h:321
DATVideoRender * m_objRegisteredVideoRender
Definition: datvdemod.h:406
bool cnr
Definition: datvdemod.h:77
leansdr::viterbi_sync * r
Definition: datvdemod.h:359
bool m_blnInitialized
Definition: datvdemod.h:417
leansdr::etr192_descrambler * r_etr192_descrambler
Definition: datvdemod.h:363
leansdr::deinterleaver< leansdr::u8 > * r_deinter
Definition: datvdemod.h:374
double getMagSq() const
Beware this is scaled to 2^30.
Definition: datvdemod.h:188
int rrc_steps
Definition: datvdemod.h:89
const DATVDemodSettings & getSettings() const
Definition: datvdemod.h:224
bool packetized
Definition: datvdemod.h:93
leansdr::pipebuf< int > * p_framelock
Definition: datvdemod.h:338
leansdr::auto_notch< leansdr::f32 > * r_auto_notch
Definition: datvdemod.h:306
code_rate
Definition: dvb.h:41
leansdr::pipebuf< leansdr::cf32 > * p_rawiq
Definition: datvdemod.h:301
leansdr::deconvol_sync_simple * r_deconv
Definition: datvdemod.h:358
unsigned long BUF_SYMBOLS
Definition: datvdemod.h:277
float rolloff
Definition: datvdemod.h:91
Definition: nco.h:25
virtual int getNbSinkStreams() const
Definition: datvdemod.h:147
DeviceAPI * m_deviceAPI
Definition: datvdemod.h:399
leansdr::file_writer< leansdr::cf32 > * r_ppout
Definition: datvdemod.h:351
MsgReportModcodCstlnChange(const DATVDemodSettings::DATVModulation &modulation, const DATVDemodSettings::DATVCodeRate &codeRate)
Definition: datvdemod.h:260
static MsgConfigureChannelizer * create(int centerFrequency)
Definition: datvdemod.h:207
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
int m_modcodCodeRate
Definition: datvdemod.h:422
unsigned long S2_MAX_SYMBOLS
Definition: datvdemod.h:288
DATVUDPStream m_udpStream
Definition: datvdemod.h:408
static MsgConfigureDATVDemod * create(const DATVDemodSettings &settings, bool force)
Definition: datvdemod.h:227
long m_lngReadIQ
Definition: datvdemod.h:272
bool hdlc
Definition: datvdemod.h:92
leansdr::pipebuf< leansdr::cf32 > * p_cstln
Definition: datvdemod.h:336
leansdr::datvconstellation< leansdr::f32 > * r_scope_symbols
Definition: datvdemod.h:396
QMutex m_objSettingsMutex
Definition: datvdemod.h:432
void * p_s2_deinterleaver
Definition: datvdemod.h:342
unsigned long BUF_BASEBAND
Definition: datvdemod.h:276
unsigned long m_lngExpectedReadIQ
Definition: datvdemod.h:271
unsigned long BUF_BYTES
Definition: datvdemod.h:278
leansdr::pipebuf< float > * p_vber
Definition: datvdemod.h:383
leansdr::rate_estimator< float > * r_vber
Definition: datvdemod.h:384
void * r_fecdec
Definition: datvdemod.h:343
leansdr::pipebuf< int > * p_verrcount
Definition: datvdemod.h:378
NCO m_objNCO
Definition: datvdemod.h:415
static MsgReportModcodCstlnChange * create(const DATVDemodSettings::DATVModulation &modulation, const DATVDemodSettings::DATVCodeRate &codeRate)
Definition: datvdemod.h:250
leansdr::scheduler * m_objScheduler
Definition: datvdemod.h:292
DATVideostream * m_objVideoStream
Definition: datvdemod.h:407
bool m_blnStartStopVideo
Definition: datvdemod.h:419
DATVDemodSettings::DATVModulation m_enmModulation
Definition: datvdemod.h:424
leansdr::cstln_lut< leansdr::eucl_ss, 256 >::predef constellation
Definition: datvdemod.h:80
void * p_slots_dvbs2
Definition: datvdemod.h:335
leansdr::pipebuf< leansdr::cf32 > * p_resampled
Definition: datvdemod.h:319
DATVideoRenderThread * m_objRenderThread
Definition: datvdemod.h:409
unsigned long BUF_SLOTS
Definition: datvdemod.h:285
MovingAverageUtil< double, double, 32 > m_objMagSqAverage
Definition: datvdemod.h:430
leansdr::hdlc_sync * r_sync
Definition: datvdemod.h:364
virtual void getIdentifier(QString &id)
Definition: datvdemod.h:135
virtual int getNbSourceStreams() const
Definition: datvdemod.h:148
leansdr::pipebuf< leansdr::u8 > * p_frames
Definition: datvdemod.h:361
virtual void getTitle(QString &title)
Definition: datvdemod.h:136
DownChannelizer * m_channelizer
Definition: datvdemod.h:402
DATVDemodSettings::DATVModulation m_modulation
Definition: datvdemod.h:257
fftfilt * m_objRFFilter
Definition: datvdemod.h:414
DATVDemodSettings::dvb_version standard
Definition: datvdemod.h:70
leansdr::pipebuf< leansdr::cf32 > * p_preprocessed
Definition: datvdemod.h:303
leansdr::pipebuf< leansdr::tspacket > * p_tspackets
Definition: datvdemod.h:387
bool hard_metric
Definition: datvdemod.h:86
DATVDemodSettings m_settings
Definition: datvdemod.h:233
leansdr::pipebuf< leansdr::cf32 > * p_cstln_pls
Definition: datvdemod.h:337
unsigned long BUF_S2PACKETS
Definition: datvdemod.h:287
leansdr::file_writer< leansdr::tspacket > * r_stdout
Definition: datvdemod.h:392
virtual bool deserialize(const QByteArray &data)
Definition: datvdemod.h:140
float Finfo
Definition: datvdemod.h:94
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: datvdemod.h:150
MsgConfigureChannelizer(int centerFrequency)
Definition: datvdemod.h:214
float Fm
Definition: datvdemod.h:79
float * coeffs
Definition: datvdemod.h:320
leansdr::sampler_interface< leansdr::f32 > * sampler
Definition: datvdemod.h:324
ThreadedBasebandSampleSink * m_threadedChannelizer
Definition: datvdemod.h:401
int anf
Definition: datvdemod.h:76
int m_sampleRate
Definition: datvdemod.h:428
virtual void destroy()
Definition: datvdemod.h:134
DATVDemodSettings m_settings
Definition: datvdemod.h:427
leansdr::derandomizer * r_derand
Definition: datvdemod.h:388
bool fastlock
Definition: datvdemod.h:84
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: datvdemod.h:137
TVScreen * m_objRegisteredTVScreen
Definition: datvdemod.h:405
leansdr::pipebuf< leansdr::f32 > * p_mer
Definition: datvdemod.h:331
leansdr::fir_filter< leansdr::cf32, float > * r_resample
Definition: datvdemod.h:318
leansdr::pipebuf< leansdr::cf32 > * p_decimated
Definition: datvdemod.h:347
DATVDemodSettings::DATVModulation getModulation() const
Definition: datvdemod.h:247
int m_modcodModulation
Definition: datvdemod.h:421
float Fderot
Definition: datvdemod.h:75
int getModcodCodeRate() const
Definition: datvdemod.h:190
leansdr::cstln_receiver< leansdr::f32, leansdr::eucl_ss > * m_objDemodulator
Definition: datvdemod.h:354
AudioFifo m_audioFifo
Definition: datvdemod.h:412
DATVDemodSettings::DATVCodeRate m_codeRate
Definition: datvdemod.h:258
leansdr::pipebuf< leansdr::cf32 > * p_sampled
Definition: datvdemod.h:332
float * coeffs_sampler
Definition: datvdemod.h:325
T max(const T &x, const T &y)
Definition: framework.h:446
leansdr::pipebuf< leansdr::cf32 > * p_derot
Definition: datvdemod.h:310
void * p_bbframes
Definition: datvdemod.h:341
int m_inputFrequencyOffset
Definition: datvdemod.h:429
float Fs
Definition: datvdemod.h:74
virtual QByteArray serialize() const
Definition: datvdemod.h:139