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.
wfmdemod.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_WFMDEMOD_H
20 #define INCLUDE_WFMDEMOD_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/nco.h"
30 #include "dsp/interpolator.h"
31 #include "dsp/lowpass.h"
32 #include "util/movingaverage.h"
33 #include "dsp/fftfilt.h"
34 #include "dsp/phasediscri.h"
35 #include "audio/audiofifo.h"
36 #include "util/message.h"
37 
38 #include "wfmdemodsettings.h"
39 
40 #define rfFilterFftLength 1024
41 
42 class QNetworkAccessManager;
43 class QNetworkReply;
45 class DownChannelizer;
46 class DeviceAPI;
47 
48 class WFMDemod : public BasebandSampleSink, public ChannelAPI {
49  Q_OBJECT
50 public:
51  class MsgConfigureWFMDemod : public Message {
53 
54  public:
55  const WFMDemodSettings& getSettings() const { return m_settings; }
56  bool getForce() const { return m_force; }
57 
58  static MsgConfigureWFMDemod* create(const WFMDemodSettings& settings, bool force)
59  {
60  return new MsgConfigureWFMDemod(settings, force);
61  }
62 
63  private:
65  bool m_force;
66 
67  MsgConfigureWFMDemod(const WFMDemodSettings& settings, bool force) :
68  Message(),
69  m_settings(settings),
70  m_force(force)
71  { }
72  };
73 
76 
77  public:
78  int getSampleRate() const { return m_sampleRate; }
79  int getCenterFrequency() const { return m_centerFrequency; }
80 
81  static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency)
82  {
83  return new MsgConfigureChannelizer(sampleRate, centerFrequency);
84  }
85 
86  private:
89 
90  MsgConfigureChannelizer(int sampleRate, int centerFrequency) :
91  Message(),
92  m_sampleRate(sampleRate),
93  m_centerFrequency(centerFrequency)
94  { }
95  };
96 
97  WFMDemod(DeviceAPI *deviceAPI);
98  virtual ~WFMDemod();
99  virtual void destroy() { delete this; }
100 
101  virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
102  virtual void start();
103  virtual void stop();
104  virtual bool handleMessage(const Message& cmd);
105 
106  virtual void getIdentifier(QString& id) { id = objectName(); }
107  virtual void getTitle(QString& title) { title = m_settings.m_title; }
108  virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
109 
110  virtual QByteArray serialize() const;
111  virtual bool deserialize(const QByteArray& data);
112 
113  virtual int getNbSinkStreams() const { return 1; }
114  virtual int getNbSourceStreams() const { return 0; }
115 
116  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
117  {
118  (void) streamIndex;
119  (void) sinkElseSource;
121  }
122 
123  double getMagSq() const { return m_movingAverage.asDouble(); }
124  bool getSquelchOpen() const { return m_squelchOpen; }
125 
126  void getMagSqLevels(double& avg, double& peak, int& nbSamples)
127  {
128  if (m_magsqCount > 0)
129  {
133  }
134 
137  nbSamples = m_magsqCount == 0 ? 1 : m_magsqCount;
138 
139  m_magsqSum = 0.0f;
140  m_magsqPeak = 0.0f;
141  m_magsqCount = 0;
142  }
143 
144  virtual int webapiSettingsGet(
146  QString& errorMessage);
147 
148  virtual int webapiSettingsPutPatch(
149  bool force,
150  const QStringList& channelSettingsKeys,
152  QString& errorMessage);
153 
154  virtual int webapiReportGet(
156  QString& errorMessage);
157 
158  static int requiredBW(int rfBW)
159  {
160  if (rfBW <= 48000) {
161  return 48000;
162  } else {
163  return (3*rfBW)/2;
164  }
165  }
166 
167  static const QString m_channelIdURI;
168  static const QString m_channelId;
169 
170 private:
172  {
174  m_magsq(1e-12),
175  m_magsqPeak(1e-12)
176  {}
177  double m_magsq;
178  double m_magsqPeak;
179  };
180 
181  enum RateState {
184  };
185 
189 
194 
200 
204  double m_magsq;
205  double m_magsqSum;
206  double m_magsqPeak;
209 
212 
215 
219 
221 
222  QNetworkAccessManager *m_networkManager;
223  QNetworkRequest m_networkRequest;
224 
225  static const int m_udpBlockSize;
226 
227  void applyAudioSampleRate(int sampleRate);
228  void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false);
229  void applySettings(const WFMDemodSettings& settings, bool force = false);
230 
233  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const WFMDemodSettings& settings, bool force);
234 
235 private slots:
236  void networkManagerFinished(QNetworkReply *reply);
237 };
238 
239 #endif // INCLUDE_WFMDEMOD_H
virtual void destroy()
Definition: wfmdemod.h:99
qint64 m_inputFrequencyOffset
void networkManagerFinished(QNetworkReply *reply)
Definition: wfmdemod.cpp:645
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
ThreadedBasebandSampleSink * m_threadedChannelizer
Definition: wfmdemod.h:187
virtual void start()
Definition: wfmdemod.cpp:196
virtual QByteArray serialize() const
Definition: wfmdemod.cpp:418
WFMDemodSettings m_settings
Definition: wfmdemod.h:192
double getMagSq() const
Definition: wfmdemod.h:123
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
Definition: wfmdemod.cpp:528
int m_inputSampleRate
Definition: wfmdemod.h:190
MsgConfigureWFMDemod(const WFMDemodSettings &settings, bool force)
Definition: wfmdemod.h:67
Real m_fmExcursion
Definition: wfmdemod.h:211
virtual ~WFMDemod()
Definition: wfmdemod.cpp:87
DeviceAPI * m_deviceAPI
Definition: wfmdemod.h:186
virtual int getNbSinkStreams() const
Definition: wfmdemod.h:113
bool m_squelchOpen
Definition: wfmdemod.h:203
int m_squelchState
Definition: wfmdemod.h:202
virtual void getTitle(QString &title)
Definition: wfmdemod.h:107
const WFMDemodSettings & getSettings() const
Definition: wfmdemod.h:55
Real m_squelchLevel
Definition: wfmdemod.h:201
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: wfmdemod.cpp:451
WFMDemodSettings m_settings
Definition: wfmdemod.h:64
Definition: nco.h:25
bool getSquelchOpen() const
Definition: wfmdemod.h:124
AudioVector m_audioBuffer
Definition: wfmdemod.h:213
double m_magsqPeak
Definition: wfmdemod.h:206
static int requiredBW(int rfBW)
Definition: wfmdemod.h:158
void getMagSqLevels(double &avg, double &peak, int &nbSamples)
Definition: wfmdemod.h:126
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
fftfilt * m_rfFilter
Definition: wfmdemod.h:199
QNetworkRequest m_networkRequest
Definition: wfmdemod.h:223
static const int m_udpBlockSize
Definition: wfmdemod.h:225
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: wfmdemod.h:90
Real m_interpolatorDistance
Definition: wfmdemod.h:197
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: wfmdemod.h:108
Interpolator m_interpolator
Interpolator between sample rate sent from DSP engine and requested RF bandwidth (rational) ...
Definition: wfmdemod.h:196
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: wfmdemod.h:81
virtual int getNbSourceStreams() const
Definition: wfmdemod.h:114
quint32 m_audioSampleRate
Definition: wfmdemod.h:193
void applyAudioSampleRate(int sampleRate)
Definition: wfmdemod.cpp:273
void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force=false)
Definition: wfmdemod.cpp:288
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool po)
Definition: wfmdemod.cpp:100
QNetworkAccessManager * m_networkManager
Definition: wfmdemod.h:222
double m_magsq
displayed averaged value
Definition: wfmdemod.h:204
static const QString m_channelIdURI
Definition: wfmdemod.h:167
void applySettings(const WFMDemodSettings &settings, bool force=false)
Definition: wfmdemod.cpp:321
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const WFMDemodSettings &settings, bool force)
Definition: wfmdemod.cpp:586
MagSqLevelsStore m_magSqLevelStore
Definition: wfmdemod.h:208
MovingAverageUtil< Real, double, 16 > m_movingAverage
Definition: wfmdemod.h:210
static const QString m_channelId
Definition: wfmdemod.h:168
static MsgConfigureWFMDemod * create(const WFMDemodSettings &settings, bool force)
Definition: wfmdemod.h:58
WFMDemod(DeviceAPI *deviceAPI)
Definition: wfmdemod.cpp:51
uint m_audioBufferFill
Definition: wfmdemod.h:214
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Definition: wfmdemod.cpp:574
QMutex m_settingsMutex
Definition: wfmdemod.h:218
NCO m_nco
Definition: wfmdemod.h:195
SampleVector m_sampleBuffer
Definition: wfmdemod.h:217
int m_inputFrequencyOffset
Definition: wfmdemod.h:191
Real m_interpolatorDistanceRemain
Definition: wfmdemod.h:198
int m_magsqCount
Definition: wfmdemod.h:207
virtual void getIdentifier(QString &id)
Definition: wfmdemod.h:106
DownChannelizer * m_channelizer
Definition: wfmdemod.h:188
double m_magsqSum
Definition: wfmdemod.h:205
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: wfmdemod.h:116
AudioFifo m_audioFifo
Definition: wfmdemod.h:216
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const WFMDemodSettings &settings)
Definition: wfmdemod.cpp:539
virtual void stop()
Definition: wfmdemod.cpp:204
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: wfmdemod.cpp:440
double asDouble() const
Definition: movingaverage.h:57
float Real
Definition: dsptypes.h:42
PhaseDiscriminators m_phaseDiscri
Definition: wfmdemod.h:220
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: wfmdemod.cpp:208
virtual bool deserialize(const QByteArray &data)
Definition: wfmdemod.cpp:423