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.
wfmmod.h
Go to the documentation of this file.
1 // Copyright (C) 2016 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 PLUGINS_CHANNELTX_MODWFM_WFMMOD_H_
19 #define PLUGINS_CHANNELTX_MODWFM_WFMMOD_H_
20 
21 #include <vector>
22 #include <iostream>
23 #include <fstream>
24 
25 #include <QMutex>
26 #include <QNetworkRequest>
27 
29 #include "channel/channelapi.h"
30 #include "dsp/nco.h"
31 #include "dsp/ncof.h"
32 #include "dsp/interpolator.h"
33 #include "dsp/fftfilt.h"
34 #include "util/movingaverage.h"
35 #include "dsp/agc.h"
36 #include "dsp/cwkeyer.h"
37 #include "audio/audiofifo.h"
38 #include "util/message.h"
39 
40 #include "wfmmodsettings.h"
41 
42 class QNetworkAccessManager;
43 class QNetworkReply;
44 class DeviceAPI;
46 class UpChannelizer;
47 
48 class WFMMod : public BasebandSampleSource, public ChannelAPI {
49  Q_OBJECT
50 
51 public:
52  class MsgConfigureWFMMod : public Message {
54 
55  public:
56  const WFMModSettings& getSettings() const { return m_settings; }
57  bool getForce() const { return m_force; }
58 
59  static MsgConfigureWFMMod* create(const WFMModSettings& settings, bool force)
60  {
61  return new MsgConfigureWFMMod(settings, force);
62  }
63 
64  private:
66  bool m_force;
67 
68  MsgConfigureWFMMod(const WFMModSettings& settings, bool force) :
69  Message(),
70  m_settings(settings),
71  m_force(force)
72  { }
73  };
74 
77 
78  public:
79  int getSampleRate() const { return m_sampleRate; }
80  int getCenterFrequency() const { return m_centerFrequency; }
81 
82  static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency)
83  {
84  return new MsgConfigureChannelizer(sampleRate, centerFrequency);
85  }
86 
87  private:
90 
91  MsgConfigureChannelizer(int sampleRate, int centerFrequency) :
92  Message(),
93  m_sampleRate(sampleRate),
94  m_centerFrequency(centerFrequency)
95  { }
96  };
97 
99  {
101 
102  public:
103  const QString& getFileName() const { return m_fileName; }
104 
105  static MsgConfigureFileSourceName* create(const QString& fileName)
106  {
107  return new MsgConfigureFileSourceName(fileName);
108  }
109 
110  private:
111  QString m_fileName;
112 
113  MsgConfigureFileSourceName(const QString& fileName) :
114  Message(),
115  m_fileName(fileName)
116  { }
117  };
118 
120  {
122 
123  public:
124  int getPercentage() const { return m_seekPercentage; }
125 
126  static MsgConfigureFileSourceSeek* create(int seekPercentage)
127  {
128  return new MsgConfigureFileSourceSeek(seekPercentage);
129  }
130 
131  protected:
133 
134  MsgConfigureFileSourceSeek(int seekPercentage) :
135  Message(),
136  m_seekPercentage(seekPercentage)
137  { }
138  };
139 
142 
143  public:
144 
146  {
148  }
149 
150  private:
151 
153  Message()
154  { }
155  };
156 
158  {
160 
161  public:
162  std::size_t getSamplesCount() const { return m_samplesCount; }
163 
164  static MsgReportFileSourceStreamTiming* create(std::size_t samplesCount)
165  {
166  return new MsgReportFileSourceStreamTiming(samplesCount);
167  }
168 
169  protected:
170  std::size_t m_samplesCount;
171 
172  MsgReportFileSourceStreamTiming(std::size_t samplesCount) :
173  Message(),
174  m_samplesCount(samplesCount)
175  { }
176  };
177 
180 
181  public:
182  int getSampleRate() const { return m_sampleRate; }
183  quint32 getRecordLength() const { return m_recordLength; }
184 
185  static MsgReportFileSourceStreamData* create(int sampleRate,
186  quint32 recordLength)
187  {
188  return new MsgReportFileSourceStreamData(sampleRate, recordLength);
189  }
190 
191  protected:
193  quint32 m_recordLength;
194 
196  quint32 recordLength) :
197  Message(),
198  m_sampleRate(sampleRate),
199  m_recordLength(recordLength)
200  { }
201  };
202 
203  //=================================================================
204 
205  WFMMod(DeviceAPI *deviceAPI);
206  ~WFMMod();
207  virtual void destroy() { delete this; }
208 
209  virtual void pull(Sample& sample);
210  virtual void pullAudio(int nbSamples);
211  virtual void start();
212  virtual void stop();
213  virtual bool handleMessage(const Message& cmd);
214 
215  virtual void getIdentifier(QString& id) { id = objectName(); }
216  virtual void getTitle(QString& title) { title = m_settings.m_title; }
217  virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
218 
219  virtual QByteArray serialize() const;
220  virtual bool deserialize(const QByteArray& data);
221 
222  virtual int getNbSinkStreams() const { return 1; }
223  virtual int getNbSourceStreams() const { return 0; }
224 
225  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
226  {
227  (void) streamIndex;
228  (void) sinkElseSource;
230  }
231 
232  virtual int webapiSettingsGet(
234  QString& errorMessage);
235 
236  virtual int webapiSettingsPutPatch(
237  bool force,
238  const QStringList& channelSettingsKeys,
240  QString& errorMessage);
241 
242  virtual int webapiReportGet(
244  QString& errorMessage);
245 
246  double getMagSq() const { return m_magsq; }
247 
248  CWKeyer *getCWKeyer() { return &m_cwKeyer; }
249 
250  static const QString m_channelIdURI;
251  static const QString m_channelId;
252 
253 signals:
260  void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples);
261 
262 
263 private:
264  enum RateState {
267  };
268 
272 
277 
280  float m_modPhasor;
286 
288  static const int m_rfFilterFFTLength;
291 
292  double m_magsq;
294 
299 
302 
303  std::ifstream m_ifstream;
304  QString m_fileName;
305  quint64 m_fileSize;
306  quint32 m_recordLength;
308 
313 
314  QNetworkAccessManager *m_networkManager;
315  QNetworkRequest m_networkRequest;
316 
317  static const int m_levelNbSamples;
318 
319  void applyAudioSampleRate(int sampleRate);
320  void applyChannelSettings(int basebandSampleRate, int outputSampleRate, int inputFrequencyOffset, bool force = false);
321  void applySettings(const WFMModSettings& settings, bool force = false);
322  void pullAF(Complex& sample);
323  void calculateLevel(const Real& sample);
324  void openFileStream();
325  void seekFileStream(int seekPercentage);
328  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const WFMModSettings& settings, bool force);
329  void webapiReverseSendCWSettings(const CWKeyerSettings& settings);
330 
331 private slots:
332  void networkManagerFinished(QNetworkReply *reply);
333 };
334 
335 
336 #endif /* PLUGINS_CHANNELTX_MODWFM_WFMMOD_H_ */
double m_magsq
Definition: wfmmod.h:292
CWKeyer * getCWKeyer()
Definition: wfmmod.h:248
ThreadedBasebandSampleSource * m_threadedChannelizer
Definition: wfmmod.h:270
static const int m_levelNbSamples
Definition: wfmmod.h:317
void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples)
UpChannelizer * m_channelizer
Definition: wfmmod.h:271
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
CWKeyer m_cwKeyer
Definition: wfmmod.h:312
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
QNetworkAccessManager * m_networkManager
Definition: wfmmod.h:314
DeviceAPI * m_deviceAPI
Definition: wfmmod.h:269
fftfilt::cmplx * m_rfFilterBuffer
Definition: wfmmod.h:289
NCOF m_toneNcoRF
Definition: wfmmod.h:279
Complex m_modSample
Definition: wfmmod.h:281
RateState
Definition: wfmmod.h:264
fftfilt * m_rfFilter
Definition: wfmmod.h:287
void applyChannelSettings(int basebandSampleRate, int outputSampleRate, int inputFrequencyOffset, bool force=false)
Definition: wfmmod.cpp:449
int m_sampleRate
Definition: wfmmod.h:307
void calculateLevel(const Real &sample)
Definition: wfmmod.cpp:268
void seekFileStream(int seekPercentage)
Definition: wfmmod.cpp:422
Definition: ncof.h:24
virtual void getIdentifier(QString &id)
Definition: wfmmod.h:215
bool m_interpolatorConsumed
Definition: wfmmod.h:285
Real m_interpolatorDistance
Definition: wfmmod.h:283
virtual void pullAudio(int nbSamples)
Definition: wfmmod.cpp:176
MsgConfigureFileSourceName(const QString &fileName)
Definition: wfmmod.h:113
static MsgReportFileSourceStreamData * create(int sampleRate, quint32 recordLength)
Definition: wfmmod.h:185
void pullAF(Complex &sample)
Definition: wfmmod.cpp:189
WFMMod(DeviceAPI *deviceAPI)
Definition: wfmmod.cpp:55
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: wfmmod.h:82
QString m_fileName
Definition: wfmmod.h:304
AudioVector m_audioBuffer
Definition: wfmmod.h:296
Definition: wfmmod.h:48
static const QString m_channelIdURI
Definition: wfmmod.h:250
std::complex< float > cmplx
Definition: fftfilt.h:21
static MsgConfigureWFMMod * create(const WFMModSettings &settings, bool force)
Definition: wfmmod.h:59
virtual void pull(Sample &sample)
Definition: wfmmod.cpp:116
quint64 m_fileSize
raw file size (bytes)
Definition: wfmmod.h:305
quint32 m_levelCalcCount
Definition: wfmmod.h:309
void openFileStream()
Definition: wfmmod.cpp:400
double getMagSq() const
Definition: wfmmod.h:246
static const QString m_channelId
Definition: wfmmod.h:251
Definition: nco.h:25
virtual void stop()
Definition: wfmmod.cpp:296
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual void start()
Definition: wfmmod.cpp:287
static MsgReportFileSourceStreamTiming * create(std::size_t samplesCount)
Definition: wfmmod.h:164
int m_rfFilterBufferIndex
Definition: wfmmod.h:290
SampleVector m_sampleBuffer
Definition: wfmmod.h:300
int m_seekPercentage
percentage of seek position from the beginning 0..100
Definition: wfmmod.h:132
QNetworkRequest m_networkRequest
Definition: wfmmod.h:315
std::size_t getSamplesCount() const
Definition: wfmmod.h:162
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: wfmmod.h:91
virtual int getNbSourceStreams() const
Definition: wfmmod.h:223
MsgConfigureWFMMod(const WFMModSettings &settings, bool force)
Definition: wfmmod.h:68
MsgReportFileSourceStreamTiming(std::size_t samplesCount)
Definition: wfmmod.h:172
Real m_peakLevel
Definition: wfmmod.h:310
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: wfmmod.cpp:300
quint32 m_audioSampleRate
Definition: wfmmod.h:295
virtual void destroy()
Definition: wfmmod.h:207
~WFMMod()
Definition: wfmmod.cpp:103
void applySettings(const WFMModSettings &settings, bool force=false)
Definition: wfmmod.cpp:485
WFMModSettings m_settings
Definition: wfmmod.h:65
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: wfmmod.h:225
AudioFifo m_audioFifo
Definition: wfmmod.h:298
virtual QByteArray serialize() const
Definition: wfmmod.cpp:581
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
Definition: wfmmod.cpp:713
const QString & getFileName() const
Definition: wfmmod.h:103
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: wfmmod.cpp:603
MovingAverageUtil< double, double, 16 > m_movingAverage
Definition: wfmmod.h:293
int getCenterFrequency() const
Definition: wfmmod.h:80
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: wfmmod.h:217
std::ifstream m_ifstream
Definition: wfmmod.h:303
static const int m_rfFilterFFTLength
Definition: wfmmod.h:288
bool getForce() const
Definition: wfmmod.h:57
void networkManagerFinished(QNetworkReply *reply)
Definition: wfmmod.cpp:885
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Definition: wfmmod.cpp:771
static MsgConfigureFileSourceStreamTiming * create()
Definition: wfmmod.h:145
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: wfmmod.cpp:614
Real m_interpolatorDistanceRemain
Definition: wfmmod.h:284
quint32 m_recordLength
record length in seconds computed from file size
Definition: wfmmod.h:306
Real m_levelSum
Definition: wfmmod.h:311
void applyAudioSampleRate(int sampleRate)
Definition: wfmmod.cpp:435
static MsgConfigureFileSourceName * create(const QString &fileName)
Definition: wfmmod.h:105
int m_basebandSampleRate
Definition: wfmmod.h:273
WFMModSettings m_settings
Definition: wfmmod.h:276
int m_outputSampleRate
Definition: wfmmod.h:274
Interpolator m_interpolator
Definition: wfmmod.h:282
const WFMModSettings & getSettings() const
Definition: wfmmod.h:56
virtual void getTitle(QString &title)
Definition: wfmmod.h:216
std::complex< Real > Complex
Definition: dsptypes.h:43
float m_modPhasor
baseband modulator phasor
Definition: wfmmod.h:280
virtual int getNbSinkStreams() const
Definition: wfmmod.h:222
void webapiReverseSendCWSettings(const CWKeyerSettings &settings)
Definition: wfmmod.cpp:854
float Real
Definition: dsptypes.h:42
NCO m_carrierNco
Definition: wfmmod.h:278
qint64 m_inputFrequencyOffset
QMutex m_settingsMutex
Definition: wfmmod.h:301
static MsgConfigureFileSourceSeek * create(int seekPercentage)
Definition: wfmmod.h:126
int m_inputFrequencyOffset
Definition: wfmmod.h:275
virtual bool deserialize(const QByteArray &data)
Definition: wfmmod.cpp:586
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const WFMModSettings &settings)
Definition: wfmmod.cpp:724
MsgReportFileSourceStreamData(int sampleRate, quint32 recordLength)
Definition: wfmmod.h:195
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const WFMModSettings &settings, bool force)
Definition: wfmmod.cpp:778
uint m_audioBufferFill
Definition: wfmmod.h:297
MsgConfigureFileSourceSeek(int seekPercentage)
Definition: wfmmod.h:134