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.
amdemod.h
Go to the documentation of this file.
1 // Copyright (C) 2015-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 #ifndef INCLUDE_AMDEMOD_H
19 #define INCLUDE_AMDEMOD_H
20 
21 #include <vector>
22 
23 #include <QNetworkRequest>
24 #include <QMutex>
25 
26 #include "dsp/basebandsamplesink.h"
27 #include "channel/channelapi.h"
28 #include "dsp/nco.h"
29 #include "dsp/interpolator.h"
30 #include "util/movingaverage.h"
31 #include "dsp/agc.h"
32 #include "dsp/bandpass.h"
33 #include "dsp/lowpass.h"
34 #include "dsp/phaselockcomplex.h"
35 #include "audio/audiofifo.h"
36 #include "util/message.h"
37 #include "util/doublebufferfifo.h"
38 
39 #include "amdemodsettings.h"
40 
41 class QNetworkAccessManager;
42 class QNetworkReply;
43 class DeviceAPI;
44 class DownChannelizer;
46 class fftfilt;
47 
48 class AMDemod : public BasebandSampleSink, public ChannelAPI {
49  Q_OBJECT
50 public:
51  class MsgConfigureAMDemod : public Message {
53 
54  public:
55  const AMDemodSettings& getSettings() const { return m_settings; }
56  bool getForce() const { return m_force; }
57 
58  static MsgConfigureAMDemod* create(const AMDemodSettings& settings, bool force)
59  {
60  return new MsgConfigureAMDemod(settings, force);
61  }
62 
63  private:
65  bool m_force;
66 
67  MsgConfigureAMDemod(const AMDemodSettings& 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  AMDemod(DeviceAPI *deviceAPI);
98  ~AMDemod();
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  virtual int webapiSettingsGet(
125  QString& errorMessage);
126 
127  virtual int webapiSettingsPutPatch(
128  bool force,
129  const QStringList& channelSettingsKeys,
131  QString& errorMessage);
132 
133  virtual int webapiReportGet(
135  QString& errorMessage);
136 
138  double getMagSq() const { return m_magsq; }
139  bool getSquelchOpen() const { return m_squelchOpen; }
140  bool getPllLocked() const { return m_settings.m_pll && m_pll.locked(); }
141  Real getPllFrequency() const { return m_pll.getFreq(); }
142 
143  void getMagSqLevels(double& avg, double& peak, int& nbSamples)
144  {
145  if (m_magsqCount > 0)
146  {
150  }
151 
154  nbSamples = m_magsqCount == 0 ? 1 : m_magsqCount;
155 
156  m_magsqSum = 0.0f;
157  m_magsqPeak = 0.0f;
158  m_magsqCount = 0;
159  }
160 
162 
163  static const QString m_channelIdURI;
164  static const QString m_channelId;
165 
166 private:
168  {
170  m_magsq(1e-12),
171  m_magsqPeak(1e-12)
172  {}
173  double m_magsq;
174  double m_magsqPeak;
175  };
176 
177  enum RateState {
180  };
181 
185 
190  bool m_running;
191 
196 
201  double m_magsq;
202  double m_magsqSum;
203  double m_magsqPeak;
206 
218 
222 
223  static const int m_udpBlockSize;
224 
225  QNetworkAccessManager *m_networkManager;
226  QNetworkRequest m_networkRequest;
227 
229 
230  void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false);
231  void applySettings(const AMDemodSettings& settings, bool force = false);
232  void applyAudioSampleRate(int sampleRate);
235  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const AMDemodSettings& settings, bool force);
236 
237  void processOneSample(Complex &ci);
238 
239 private slots:
240  void networkManagerFinished(QNetworkReply *reply);
241 
242 };
243 
244 #endif // INCLUDE_AMDEMOD_H
Real m_syncAMBuff[2 *1024]
Definition: amdemod.h:215
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: amdemod.h:116
void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force=false)
Definition: amdemod.cpp:410
virtual void start()
Definition: amdemod.cpp:295
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const AMDemodSettings &settings, bool force)
Definition: amdemod.cpp:748
double getMagSq() const
Definition: amdemod.h:138
int m_magsqCount
Definition: amdemod.h:204
uint32_t getNumberOfDeviceStreams() const
Definition: amdemod.cpp:111
QNetworkAccessManager * m_networkManager
Definition: amdemod.h:225
MagAGC m_syncAMAGC
Definition: amdemod.h:217
double m_magsqSum
Definition: amdemod.h:202
void getMagSqLevels(double &avg, double &peak, int &nbSamples)
Definition: amdemod.h:143
AMDemodSettings m_settings
Definition: amdemod.h:188
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const AMDemodSettings &settings)
Definition: amdemod.cpp:698
static MsgConfigureAMDemod * create(const AMDemodSettings &settings, bool force)
Definition: amdemod.h:58
DeviceAPI * m_deviceAPI
Definition: amdemod.h:182
virtual QByteArray serialize() const
Definition: amdemod.cpp:562
virtual bool deserialize(const QByteArray &data)
Definition: amdemod.cpp:567
double m_magsq
Definition: amdemod.h:201
uint32_t m_squelchCount
Definition: amdemod.h:198
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Definition: amdemod.cpp:736
Definition: agc.h:36
fftfilt * SSBFilter
Definition: amdemod.h:214
bool m_running
Definition: amdemod.h:190
AudioFifo m_audioFifo
Definition: amdemod.h:221
fftfilt * DSBFilter
Definition: amdemod.h:213
virtual void getIdentifier(QString &id)
Definition: amdemod.h:106
unsigned int uint32_t
Definition: rtptypes_win.h:46
float getFreq() const
MovingAverageUtil< Real, double, 16 > m_movingAverage
Definition: amdemod.h:207
Real getPllFrequency() const
Definition: amdemod.h:141
virtual int getNbSinkStreams() const
Definition: amdemod.h:113
Definition: nco.h:25
Real m_interpolatorDistance
Definition: amdemod.h:194
QMutex m_settingsMutex
Definition: amdemod.h:228
Lowpass< Real > m_lowpass
Definition: amdemod.h:210
AMDemod(DeviceAPI *deviceAPI)
Definition: amdemod.cpp:52
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
const AMDemodSettings & getSettings() const
Definition: amdemod.h:55
virtual void destroy()
Definition: amdemod.h:99
int m_inputFrequencyOffset
Definition: amdemod.h:187
AMDemodSettings m_settings
Definition: amdemod.h:64
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: amdemod.cpp:310
Interpolator m_interpolator
Definition: amdemod.h:193
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
Definition: amdemod.cpp:687
uint32_t m_audioSampleRate
Definition: amdemod.h:189
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool po)
Definition: amdemod.cpp:116
ThreadedBasebandSampleSink * m_threadedChannelizer
Definition: amdemod.h:183
virtual void getTitle(QString &title)
Definition: amdemod.h:107
DoubleBufferFIFO< Real > m_squelchDelayLine
Definition: amdemod.h:200
DownChannelizer * m_channelizer
Definition: amdemod.h:184
virtual int getNbSourceStreams() const
Definition: amdemod.h:114
RateState
Definition: amdemod.h:177
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: amdemod.cpp:595
int m_inputSampleRate
Definition: amdemod.h:186
double m_magsqPeak
Definition: amdemod.h:203
void applySettings(const AMDemodSettings &settings, bool force=false)
Definition: amdemod.cpp:436
static const QString m_channelId
Definition: amdemod.h:164
void processOneSample(Complex &ci)
Definition: amdemod.cpp:165
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: amdemod.h:90
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: amdemod.h:81
uint32_t getAudioSampleRate() const
Definition: amdemod.h:137
void applyAudioSampleRate(int sampleRate)
Definition: amdemod.cpp:377
Lowpass< std::complex< float > > m_pllFilt
Definition: amdemod.h:211
AudioVector m_audioBuffer
Definition: amdemod.h:219
uint32_t m_audioBufferFill
Definition: amdemod.h:220
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: amdemod.cpp:584
PhaseLockComplex m_pll
Definition: amdemod.h:212
bool getSquelchOpen() const
Definition: amdemod.h:139
virtual void stop()
Definition: amdemod.cpp:304
~AMDemod()
Definition: amdemod.cpp:98
MsgConfigureAMDemod(const AMDemodSettings &settings, bool force)
Definition: amdemod.h:67
void networkManagerFinished(QNetworkReply *reply)
Definition: amdemod.cpp:816
qint32 m_inputFrequencyOffset
Real m_squelchLevel
Definition: amdemod.h:197
NCO m_nco
Definition: amdemod.h:192
Bandpass< Real > m_bandpass
Definition: amdemod.h:209
Real m_interpolatorDistanceRemain
Definition: amdemod.h:195
QNetworkRequest m_networkRequest
Definition: amdemod.h:226
bool locked() const
uint32_t m_syncAMBuffIndex
Definition: amdemod.h:216
bool getPllLocked() const
Definition: amdemod.h:140
MagSqLevelsStore m_magSqLevelStore
Definition: amdemod.h:205
std::complex< Real > Complex
Definition: dsptypes.h:43
static const QString m_channelIdURI
Definition: amdemod.h:163
float Real
Definition: dsptypes.h:42
bool m_squelchOpen
Definition: amdemod.h:199
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: amdemod.h:108
SimpleAGC< 4800 > m_volumeAGC
Definition: amdemod.h:208
static const int m_udpBlockSize
Definition: amdemod.h:223