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.
ssbdemod.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_SSBDEMOD_H
20 #define INCLUDE_SSBDEMOD_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/ncof.h"
30 #include "dsp/interpolator.h"
31 #include "dsp/fftfilt.h"
32 #include "dsp/agc.h"
33 #include "audio/audiofifo.h"
34 #include "util/message.h"
35 #include "util/doublebufferfifo.h"
36 
37 #include "ssbdemodsettings.h"
38 
39 #define ssbFftLen 1024
40 #define agcTarget 3276.8 // -10 dB amplitude => -20 dB power: center of normal signal
41 
42 class QNetworkAccessManager;
43 class QNetworkReply;
44 class DeviceAPI;
46 class DownChannelizer;
47 
48 class SSBDemod : public BasebandSampleSink, public ChannelAPI {
49  Q_OBJECT
50 public:
51  class MsgConfigureSSBDemod : public Message {
53 
54  public:
55  const SSBDemodSettings& getSettings() const { return m_settings; }
56  bool getForce() const { return m_force; }
57 
58  static MsgConfigureSSBDemod* create(const SSBDemodSettings& settings, bool force)
59  {
60  return new MsgConfigureSSBDemod(settings, force);
61  }
62 
63  private:
65  bool m_force;
66 
67  MsgConfigureSSBDemod(const SSBDemodSettings& 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  SSBDemod(DeviceAPI *deviceAPI);
98  virtual ~SSBDemod();
99  virtual void destroy() { delete this; }
100  void setSampleSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; }
101 
102  void configure(MessageQueue* messageQueue,
103  Real Bandwidth,
104  Real LowCutoff,
105  Real volume,
106  int spanLog2,
107  bool audioBinaural,
108  bool audioFlipChannels,
109  bool dsb,
110  bool audioMute,
111  bool agc,
112  bool agcClamping,
113  int agcTimeLog2,
114  int agcPowerThreshold,
115  int agcThresholdGate);
116 
117  virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
118  virtual void start();
119  virtual void stop();
120  virtual bool handleMessage(const Message& cmd);
121 
122  virtual void getIdentifier(QString& id) { id = objectName(); }
123  virtual void getTitle(QString& title) { title = m_settings.m_title; }
124  virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
125 
126  virtual QByteArray serialize() const;
127  virtual bool deserialize(const QByteArray& data);
128 
129  virtual int getNbSinkStreams() const { return 1; }
130  virtual int getNbSourceStreams() const { return 0; }
131 
132  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
133  {
134  (void) streamIndex;
135  (void) sinkElseSource;
137  }
138 
141  double getMagSq() const { return m_magsq; }
142  bool getAudioActive() const { return m_audioActive; }
143 
144  void getMagSqLevels(double& avg, double& peak, int& nbSamples)
145  {
146  if (m_magsqCount > 0)
147  {
151  }
152 
155  nbSamples = m_magsqCount == 0 ? 1 : m_magsqCount;
156 
157  m_magsqSum = 0.0f;
158  m_magsqPeak = 0.0f;
159  m_magsqCount = 0;
160  }
161 
162  virtual int webapiSettingsGet(
164  QString& errorMessage);
165 
166  virtual int webapiSettingsPutPatch(
167  bool force,
168  const QStringList& channelSettingsKeys,
170  QString& errorMessage);
171 
172  virtual int webapiReportGet(
174  QString& errorMessage);
175 
176  static const QString m_channelIdURI;
177  static const QString m_channelId;
178 
179 private:
181  {
183  m_magsq(1e-12),
184  m_magsqPeak(1e-12)
185  {}
186  double m_magsq;
187  double m_magsqPeak;
188  };
189 
192 
193  public:
194  Real getBandwidth() const { return m_Bandwidth; }
195  Real getLoCutoff() const { return m_LowCutoff; }
196  Real getVolume() const { return m_volume; }
197  int getSpanLog2() const { return m_spanLog2; }
198  bool getAudioBinaural() const { return m_audioBinaural; }
199  bool getAudioFlipChannels() const { return m_audioFlipChannels; }
200  bool getDSB() const { return m_dsb; }
201  bool getAudioMute() const { return m_audioMute; }
202  bool getAGC() const { return m_agc; }
203  bool getAGCClamping() const { return m_agcClamping; }
204  int getAGCTimeLog2() const { return m_agcTimeLog2; }
206  int getAGCThersholdGate() const { return m_agcThresholdGate; }
207 
209  Real LowCutoff,
210  Real volume,
211  int spanLog2,
212  bool audioBinaural,
213  bool audioFlipChannels,
214  bool dsb,
215  bool audioMute,
216  bool agc,
217  bool agcClamping,
218  int agcTimeLog2,
219  int agcPowerThreshold,
220  int agcThresholdGate)
221  {
222  return new MsgConfigureSSBDemodPrivate(
223  Bandwidth,
224  LowCutoff,
225  volume,
226  spanLog2,
227  audioBinaural,
228  audioFlipChannels,
229  dsb,
230  audioMute,
231  agc,
232  agcClamping,
233  agcTimeLog2,
234  agcPowerThreshold,
235  agcThresholdGate);
236  }
237 
238  private:
245  bool m_dsb;
247  bool m_agc;
252 
254  Real LowCutoff,
255  Real volume,
256  int spanLog2,
257  bool audioBinaural,
258  bool audioFlipChannels,
259  bool dsb,
260  bool audioMute,
261  bool agc,
262  bool agcClamping,
263  int agcTimeLog2,
264  int agcPowerThreshold,
265  int agcThresholdGate) :
266  Message(),
267  m_Bandwidth(Bandwidth),
268  m_LowCutoff(LowCutoff),
269  m_volume(volume),
270  m_spanLog2(spanLog2),
271  m_audioBinaural(audioBinaural),
272  m_audioFlipChannels(audioFlipChannels),
273  m_dsb(dsb),
274  m_audioMute(audioMute),
275  m_agc(agc),
276  m_agcClamping(agcClamping),
277  m_agcTimeLog2(agcTimeLog2),
278  m_agcPowerThreshold(agcPowerThreshold),
279  m_agcThresholdGate(agcThresholdGate)
280  { }
281  };
282 
287 
298  bool m_usb;
299  bool m_dsb;
301  double m_magsq;
302  double m_magsqSum;
303  double m_magsqPeak;
314 
321 
324 
329 
330  QNetworkAccessManager *m_networkManager;
331  QNetworkRequest m_networkRequest;
332 
334 
335  void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false);
336  void applySettings(const SSBDemodSettings& settings, bool force = false);
337  void applyAudioSampleRate(int sampleRate);
340  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const SSBDemodSettings& settings, bool force);
341 
342  void processOneSample(Complex &ci);
343 
344 private slots:
345  void networkManagerFinished(QNetworkReply *reply);
346 };
347 
348 #endif // INCLUDE_SSBDEMOD_H
static MsgConfigureSSBDemodPrivate * create(Real Bandwidth, Real LowCutoff, Real volume, int spanLog2, bool audioBinaural, bool audioFlipChannels, bool dsb, bool audioMute, bool agc, bool agcClamping, int agcTimeLog2, int agcPowerThreshold, int agcThresholdGate)
Definition: ssbdemod.h:208
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const SSBDemodSettings &settings, bool force)
Definition: ssbdemod.cpp:848
static const QString m_channelId
Definition: ssbdemod.h:177
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: ssbdemod.h:124
int m_agcThresholdGate
Gate length in number of samples befor threshold triggers.
Definition: ssbdemod.h:311
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
bool m_audioBinaual
Definition: ssbdemod.h:296
void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force=false)
Definition: ssbdemod.cpp:385
fftfilt * SSBFilter
Definition: ssbdemod.h:319
virtual void getIdentifier(QString &id)
Definition: ssbdemod.h:122
bool m_dsb
Definition: ssbdemod.h:299
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Definition: ssbdemod.cpp:836
double m_magsqPeak
Definition: ssbdemod.h:303
Real m_interpolatorDistance
Definition: ssbdemod.h:317
SSBDemodSettings m_settings
Definition: ssbdemod.h:64
virtual int getNbSinkStreams() const
Definition: ssbdemod.h:129
Definition: ncof.h:24
static const QString m_channelIdURI
Definition: ssbdemod.h:176
NCOF m_nco
Definition: ssbdemod.h:315
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: ssbdemod.h:81
Real m_Bandwidth
Definition: ssbdemod.h:288
double m_magsq
Definition: ssbdemod.h:301
Definition: agc.h:36
int m_magsqCount
Definition: ssbdemod.h:304
void getMagSqLevels(double &avg, double &peak, int &nbSamples)
Definition: ssbdemod.h:144
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: ssbdemod.cpp:669
Real m_LowCutoff
Definition: ssbdemod.h:289
std::complex< float > cmplx
Definition: fftfilt.h:21
unsigned int uint32_t
Definition: rtptypes_win.h:46
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: ssbdemod.cpp:680
void networkManagerFinished(QNetworkReply *reply)
Definition: ssbdemod.cpp:931
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const SSBDemodSettings &settings)
Definition: ssbdemod.cpp:792
QMutex m_settingsMutex
Definition: ssbdemod.h:333
BasebandSampleSink * m_sampleSink
Definition: ssbdemod.h:322
void applyAudioSampleRate(int sampleRate)
Definition: ssbdemod.cpp:411
bool m_audioMute
Definition: ssbdemod.h:300
void setSampleSink(BasebandSampleSink *sampleSink)
Definition: ssbdemod.h:100
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual void start()
Definition: ssbdemod.cpp:306
fftfilt * DSBFilter
Definition: ssbdemod.h:320
const SSBDemodSettings & getSettings() const
Definition: ssbdemod.h:55
fftfilt::cmplx m_sum
Definition: ssbdemod.h:292
SSBDemod(DeviceAPI *deviceAPI)
Definition: ssbdemod.cpp:51
double getMagSq() const
Definition: ssbdemod.h:141
int m_undersampleCount
Definition: ssbdemod.h:293
bool m_agcClamping
Definition: ssbdemod.h:308
double m_magsqSum
Definition: ssbdemod.h:302
int m_agcNbSamples
number of audio (48 kHz) samples for AGC averaging
Definition: ssbdemod.h:309
int m_inputFrequencyOffset
Definition: ssbdemod.h:295
bool m_audioActive
True if an audio signal is produced (no AGC or AGC and above threshold)
Definition: ssbdemod.h:313
int m_inputSampleRate
Definition: ssbdemod.h:294
DeviceAPI * m_deviceAPI
Definition: ssbdemod.h:283
MsgConfigureSSBDemod(const SSBDemodSettings &settings, bool force)
Definition: ssbdemod.h:67
bool m_usb
Definition: ssbdemod.h:298
DoubleBufferFIFO< fftfilt::cmplx > m_squelchDelayLine
Definition: ssbdemod.h:312
int m_spanLog2
Definition: ssbdemod.h:291
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool positiveOnly)
Definition: ssbdemod.cpp:157
MagAGC m_agc
Definition: ssbdemod.h:306
virtual bool deserialize(const QByteArray &data)
Definition: ssbdemod.cpp:652
SSBDemodSettings m_settings
Definition: ssbdemod.h:286
uint32_t getAudioSampleRate() const
Definition: ssbdemod.h:139
AudioVector m_audioBuffer
Definition: ssbdemod.h:325
DownChannelizer * m_channelizer
Definition: ssbdemod.h:285
MsgConfigureSSBDemodPrivate(Real Bandwidth, Real LowCutoff, Real volume, int spanLog2, bool audioBinaural, bool audioFlipChannels, bool dsb, bool audioMute, bool agc, bool agcClamping, int agcTimeLog2, int agcPowerThreshold, int agcThresholdGate)
Definition: ssbdemod.h:253
virtual void stop()
Definition: ssbdemod.cpp:311
qint32 m_inputFrequencyOffset
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
Definition: ssbdemod.cpp:781
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: ssbdemod.h:132
Real m_volume
Definition: ssbdemod.h:290
virtual void destroy()
Definition: ssbdemod.h:99
bool m_agcActive
Definition: ssbdemod.h:307
uint32_t getInputSampleRate() const
Definition: ssbdemod.h:140
void applySettings(const SSBDemodSettings &settings, bool force=false)
Definition: ssbdemod.cpp:458
ThreadedBasebandSampleSink * m_threadedChannelizer
Definition: ssbdemod.h:284
virtual void getTitle(QString &title)
Definition: ssbdemod.h:123
bool getAudioActive() const
Definition: ssbdemod.h:142
double m_agcPowerThreshold
AGC power threshold (linear)
Definition: ssbdemod.h:310
SampleVector m_sampleBuffer
Definition: ssbdemod.h:323
virtual ~SSBDemod()
Definition: ssbdemod.cpp:111
QNetworkAccessManager * m_networkManager
Definition: ssbdemod.h:330
AudioFifo m_audioFifo
Definition: ssbdemod.h:327
bool m_audioFlipChannels
Definition: ssbdemod.h:297
MagSqLevelsStore m_magSqLevelStore
Definition: ssbdemod.h:305
quint32 m_audioSampleRate
Definition: ssbdemod.h:328
void processOneSample(Complex &ci)
Definition: ssbdemod.cpp:189
static MsgConfigureSSBDemod * create(const SSBDemodSettings &settings, bool force)
Definition: ssbdemod.h:58
std::complex< Real > Complex
Definition: dsptypes.h:43
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: ssbdemod.cpp:315
uint m_audioBufferFill
Definition: ssbdemod.h:326
Real m_interpolatorDistanceRemain
Definition: ssbdemod.h:318
float Real
Definition: dsptypes.h:42
virtual int getNbSourceStreams() const
Definition: ssbdemod.h:130
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: ssbdemod.h:90
Interpolator m_interpolator
Definition: ssbdemod.h:316
QNetworkRequest m_networkRequest
Definition: ssbdemod.h:331
void configure(MessageQueue *messageQueue, Real Bandwidth, Real LowCutoff, Real volume, int spanLog2, bool audioBinaural, bool audioFlipChannels, bool dsb, bool audioMute, bool agc, bool agcClamping, int agcTimeLog2, int agcPowerThreshold, int agcThresholdGate)
Definition: ssbdemod.cpp:125
virtual QByteArray serialize() const
Definition: ssbdemod.cpp:647