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.
nfmdemod.h
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 #ifndef INCLUDE_NFMDEMOD_H
20 #define INCLUDE_NFMDEMOD_H
21 
22 #include <vector>
23 
24 #include <QMutex>
25 #include <QNetworkRequest>
26 
27 #include "dsp/basebandsamplesink.h"
28 #include "channel/channelapi.h"
29 #include "dsp/phasediscri.h"
30 #include "dsp/nco.h"
31 #include "dsp/interpolator.h"
32 #include "dsp/lowpass.h"
33 #include "dsp/bandpass.h"
34 #include "dsp/afsquelch.h"
35 #include "dsp/agc.h"
36 #include "dsp/ctcssdetector.h"
37 #include "audio/audiofifo.h"
38 #include "util/message.h"
39 #include "util/movingaverage.h"
40 #include "util/doublebufferfifo.h"
41 
42 #include "nfmdemodsettings.h"
43 
44 class QNetworkAccessManager;
45 class QNetworkReply;
46 class DeviceAPI;
48 class DownChannelizer;
49 
50 class NFMDemod : public BasebandSampleSink, public ChannelAPI {
51  Q_OBJECT
52 public:
53  class MsgConfigureNFMDemod : public Message {
55 
56  public:
57  const NFMDemodSettings& getSettings() const { return m_settings; }
58  bool getForce() const { return m_force; }
59 
60  static MsgConfigureNFMDemod* create(const NFMDemodSettings& settings, bool force)
61  {
62  return new MsgConfigureNFMDemod(settings, force);
63  }
64 
65  private:
67  bool m_force;
68 
69  MsgConfigureNFMDemod(const NFMDemodSettings& settings, bool force) :
70  Message(),
71  m_settings(settings),
72  m_force(force)
73  { }
74  };
75 
78 
79  public:
80  int getSampleRate() const { return m_sampleRate; }
81  int getCenterFrequency() const { return m_centerFrequency; }
82 
83  static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency)
84  {
85  return new MsgConfigureChannelizer(sampleRate, centerFrequency);
86  }
87 
88  private:
91 
92  MsgConfigureChannelizer(int sampleRate, int centerFrequency) :
93  Message(),
94  m_sampleRate(sampleRate),
95  m_centerFrequency(centerFrequency)
96  { }
97  };
98 
99  class MsgReportCTCSSFreq : public Message {
101 
102  public:
103  Real getFrequency() const { return m_freq; }
104 
106  {
107  return new MsgReportCTCSSFreq(freq);
108  }
109 
110  private:
112 
114  Message(),
115  m_freq(freq)
116  { }
117  };
118 
119  NFMDemod(DeviceAPI *deviceAPI);
120  ~NFMDemod();
121  virtual void destroy() { delete this; }
122 
123  virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
124  virtual void start();
125  virtual void stop();
126  virtual bool handleMessage(const Message& cmd);
127 
128  virtual void getIdentifier(QString& id) { id = objectName(); }
129  virtual void getTitle(QString& title) { title = m_settings.m_title; }
130  virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
131 
132  virtual QByteArray serialize() const;
133  virtual bool deserialize(const QByteArray& data);
134 
135  virtual int getNbSinkStreams() const { return 1; }
136  virtual int getNbSourceStreams() const { return 0; }
137 
138  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
139  {
140  (void) streamIndex;
141  (void) sinkElseSource;
143  }
144 
145  virtual int webapiSettingsGet(
147  QString& errorMessage);
148 
149  virtual int webapiSettingsPutPatch(
150  bool force,
151  const QStringList& channelSettingsKeys,
153  QString& errorMessage);
154 
155  virtual int webapiReportGet(
157  QString& errorMessage);
158 
159  const Real *getCtcssToneSet(int& nbTones) const {
160  nbTones = m_ctcssDetector.getNTones();
161  return m_ctcssDetector.getToneSet();
162  }
163 
164  void setSelectedCtcssIndex(int selectedCtcssIndex) {
165  m_ctcssIndexSelected = selectedCtcssIndex;
166  }
167 
168  Real getMag() { return m_magsq; }
169  bool getSquelchOpen() const { return m_squelchOpen; }
170 
171  void getMagSqLevels(double& avg, double& peak, int& nbSamples)
172  {
173  if (m_magsqCount > 0)
174  {
178  }
179 
182  nbSamples = m_magsqCount == 0 ? 1 : m_magsqCount;
183 
184  m_magsqSum = 0.0f;
185  m_magsqPeak = 0.0f;
186  m_magsqCount = 0;
187  }
188 
189  static const QString m_channelIdURI;
190  static const QString m_channelId;
191 
192 private:
194  {
196  m_magsq(1e-12),
197  m_magsqPeak(1e-12)
198  {}
199  double m_magsq;
200  double m_magsqPeak;
201  };
202 
203  enum RateState {
206  };
207 
211 
217  bool m_running;
218 
227  int m_ctcssIndex; // 0 for nothing detected
232 
236  double m_magsq;
237  double m_magsqSum;
238  double m_magsqPeak;
241 
244  Real m_agcLevel; // AGC will aim to this level
246 
250 
252 
254 
255  QNetworkAccessManager *m_networkManager;
256  QNetworkRequest m_networkRequest;
257 
258  static const int m_udpBlockSize;
259 
260 // void apply(bool force = false);
261  void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false);
262  void applySettings(const NFMDemodSettings& settings, bool force = false);
263  void applyAudioSampleRate(int sampleRate);
266  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const NFMDemodSettings& settings, bool force);
267 
268  void processOneSample(Complex &ci);
269 
270 private slots:
271  void networkManagerFinished(QNetworkReply *reply);
272 };
273 
274 #endif // INCLUDE_NFMDEMOD_H
Real m_interpolatorDistanceRemain
Definition: nfmdemod.h:222
uint m_audioBufferFill
Definition: nfmdemod.h:248
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: nfmdemod.h:138
virtual void stop()
Definition: nfmdemod.cpp:373
double m_magsq
displayed averaged value
Definition: nfmdemod.h:236
QNetworkRequest m_networkRequest
Definition: nfmdemod.h:256
void getMagSqLevels(double &avg, double &peak, int &nbSamples)
Definition: nfmdemod.h:171
virtual void destroy()
Definition: nfmdemod.h:121
int m_sampleCount
Definition: nfmdemod.h:229
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
float m_discriCompensation
compensation factor that depends on audio rate (1 for 48 kS/s)
Definition: nfmdemod.h:216
PhaseDiscriminators m_phaseDiscri
Definition: nfmdemod.h:253
QMutex m_settingsMutex
Definition: nfmdemod.h:251
const Real * getCtcssToneSet(int &nbTones) const
Definition: nfmdemod.h:159
const Real * getToneSet() const
Definition: ctcssdetector.h:45
void processOneSample(Complex &ci)
Definition: nfmdemod.cpp:187
bool m_running
Definition: nfmdemod.h:217
double m_magsqSum
Definition: nfmdemod.h:237
AFSquelch m_afSquelch
Definition: nfmdemod.h:243
MovingAverageUtil< Real, double, 32 > m_movingAverage
Definition: nfmdemod.h:242
bool getSquelchOpen() const
Definition: nfmdemod.h:169
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: nfmdemod.h:83
uint32_t m_audioSampleRate
Definition: nfmdemod.h:215
ThreadedBasebandSampleSink * m_threadedChannelizer
Definition: nfmdemod.h:209
static MsgConfigureNFMDemod * create(const NFMDemodSettings &settings, bool force)
Definition: nfmdemod.h:60
virtual QByteArray serialize() const
Definition: nfmdemod.cpp:646
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: nfmdemod.h:130
void setSelectedCtcssIndex(int selectedCtcssIndex)
Definition: nfmdemod.h:164
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: nfmdemod.cpp:682
NFMDemodSettings m_settings
Definition: nfmdemod.h:66
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool po)
Definition: nfmdemod.cpp:150
NCO m_nco
Definition: nfmdemod.h:219
unsigned int uint32_t
Definition: rtptypes_win.h:46
Interpolator m_interpolator
Definition: nfmdemod.h:220
int m_squelchCount
Definition: nfmdemod.h:230
static const QString m_channelIdURI
Definition: nfmdemod.h:189
MsgConfigureNFMDemod(const NFMDemodSettings &settings, bool force)
Definition: nfmdemod.h:69
Definition: nco.h:25
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
MagSqLevelsStore m_magSqLevelStore
Definition: nfmdemod.h:240
static const int m_udpBlockSize
Definition: nfmdemod.h:258
AudioFifo m_audioFifo
Definition: nfmdemod.h:249
Real m_interpolatorDistance
Definition: nfmdemod.h:221
int getNTones() const
Definition: ctcssdetector.h:40
bool m_squelchOpen
Definition: nfmdemod.h:234
int m_magsqCount
Definition: nfmdemod.h:239
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: nfmdemod.h:92
DeviceAPI * m_deviceAPI
Definition: nfmdemod.h:208
bool m_afSquelchOpen
Definition: nfmdemod.h:235
int m_ctcssIndexSelected
Definition: nfmdemod.h:228
Lowpass< Real > m_lowpass
Definition: nfmdemod.h:225
virtual void getIdentifier(QString &id)
Definition: nfmdemod.h:128
Real m_squelchLevel
Definition: nfmdemod.h:233
Real m_agcLevel
Definition: nfmdemod.h:244
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Definition: nfmdemod.cpp:828
QNetworkAccessManager * m_networkManager
Definition: nfmdemod.h:255
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const NFMDemodSettings &settings)
Definition: nfmdemod.cpp:787
virtual void start()
Definition: nfmdemod.cpp:363
double m_magsqPeak
Definition: nfmdemod.h:238
Real getMag()
Definition: nfmdemod.h:168
Lowpass< Real > m_ctcssLowpass
Definition: nfmdemod.h:223
void applyAudioSampleRate(int sampleRate)
Definition: nfmdemod.cpp:444
void applySettings(const NFMDemodSettings &settings, bool force=false)
Definition: nfmdemod.cpp:508
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: nfmdemod.cpp:379
virtual void getTitle(QString &title)
Definition: nfmdemod.h:129
virtual int getNbSinkStreams() const
Definition: nfmdemod.h:135
void networkManagerFinished(QNetworkReply *reply)
Definition: nfmdemod.cpp:918
NFMDemodSettings m_settings
Definition: nfmdemod.h:214
int m_ctcssIndex
Definition: nfmdemod.h:227
virtual int getNbSourceStreams() const
Definition: nfmdemod.h:136
int m_inputSampleRate
Definition: nfmdemod.h:212
DownChannelizer * m_channelizer
Definition: nfmdemod.h:210
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
Definition: nfmdemod.cpp:776
int32_t m_inputFrequencyOffset
AudioVector m_audioBuffer
Definition: nfmdemod.h:247
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const NFMDemodSettings &settings, bool force)
Definition: nfmdemod.cpp:841
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: nfmdemod.cpp:671
std::complex< Real > Complex
Definition: dsptypes.h:43
virtual bool deserialize(const QByteArray &data)
Definition: nfmdemod.cpp:651
NFMDemod(DeviceAPI *deviceAPI)
Definition: nfmdemod.cpp:55
CTCSSDetector m_ctcssDetector
Definition: nfmdemod.h:226
int m_squelchGate
Definition: nfmdemod.h:231
const NFMDemodSettings & getSettings() const
Definition: nfmdemod.h:57
float Real
Definition: dsptypes.h:42
Bandpass< Real > m_bandpass
Definition: nfmdemod.h:224
void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force=false)
Definition: nfmdemod.cpp:483
static const QString m_channelId
Definition: nfmdemod.h:190
DoubleBufferFIFO< Real > m_squelchDelayLine
Definition: nfmdemod.h:245
int m_inputFrequencyOffset
Definition: nfmdemod.h:213
static MsgReportCTCSSFreq * create(Real freq)
Definition: nfmdemod.h:105