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.
nfmmod.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_MODNFM_NFMMOD_H_
19 #define PLUGINS_CHANNELTX_MODNFM_NFMMOD_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/lowpass.h"
34 #include "dsp/bandpass.h"
35 #include "util/movingaverage.h"
36 #include "dsp/agc.h"
37 #include "dsp/cwkeyer.h"
38 #include "audio/audiofifo.h"
39 #include "util/message.h"
40 
41 #include "nfmmodsettings.h"
42 
43 class DeviceAPI;
45 class UpChannelizer;
46 class QNetworkAccessManager;
47 class QNetworkReply;
48 
49 class NFMMod : public BasebandSampleSource, public ChannelAPI {
50  Q_OBJECT
51 
52 public:
53  class MsgConfigureNFMMod : public Message {
55 
56  public:
57  const NFMModSettings& getSettings() const { return m_settings; }
58  bool getForce() const { return m_force; }
59 
60  static MsgConfigureNFMMod* create(const NFMModSettings& settings, bool force)
61  {
62  return new MsgConfigureNFMMod(settings, force);
63  }
64 
65  private:
67  bool m_force;
68 
69  MsgConfigureNFMMod(const NFMModSettings& 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 
100  {
102 
103  public:
104  const QString& getFileName() const { return m_fileName; }
105 
106  static MsgConfigureFileSourceName* create(const QString& fileName)
107  {
108  return new MsgConfigureFileSourceName(fileName);
109  }
110 
111  private:
112  QString m_fileName;
113 
114  MsgConfigureFileSourceName(const QString& fileName) :
115  Message(),
116  m_fileName(fileName)
117  { }
118  };
119 
121  {
123 
124  public:
125  int getPercentage() const { return m_seekPercentage; }
126 
127  static MsgConfigureFileSourceSeek* create(int seekPercentage)
128  {
129  return new MsgConfigureFileSourceSeek(seekPercentage);
130  }
131 
132  protected:
134 
135  MsgConfigureFileSourceSeek(int seekPercentage) :
136  Message(),
137  m_seekPercentage(seekPercentage)
138  { }
139  };
140 
143 
144  public:
145 
147  {
149  }
150 
151  private:
152 
154  Message()
155  { }
156  };
157 
159  {
161 
162  public:
163  std::size_t getSamplesCount() const { return m_samplesCount; }
164 
165  static MsgReportFileSourceStreamTiming* create(std::size_t samplesCount)
166  {
167  return new MsgReportFileSourceStreamTiming(samplesCount);
168  }
169 
170  protected:
171  std::size_t m_samplesCount;
172 
173  MsgReportFileSourceStreamTiming(std::size_t samplesCount) :
174  Message(),
175  m_samplesCount(samplesCount)
176  { }
177  };
178 
181 
182  public:
183  int getSampleRate() const { return m_sampleRate; }
184  quint32 getRecordLength() const { return m_recordLength; }
185 
186  static MsgReportFileSourceStreamData* create(int sampleRate,
187  quint32 recordLength)
188  {
189  return new MsgReportFileSourceStreamData(sampleRate, recordLength);
190  }
191 
192  protected:
194  quint32 m_recordLength;
195 
197  quint32 recordLength) :
198  Message(),
199  m_sampleRate(sampleRate),
200  m_recordLength(recordLength)
201  { }
202  };
203 
204  //=================================================================
205 
206  NFMMod(DeviceAPI *deviceAPI);
207  ~NFMMod();
208  virtual void destroy() { delete this; }
209 
210  virtual void pull(Sample& sample);
211  virtual void pullAudio(int nbSamples);
212  virtual void start();
213  virtual void stop();
214  virtual bool handleMessage(const Message& cmd);
215 
216  virtual void getIdentifier(QString& id) { id = objectName(); }
217  virtual void getTitle(QString& title) { title = m_settings.m_title; }
218  virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
219 
220  virtual QByteArray serialize() const;
221  virtual bool deserialize(const QByteArray& data);
222 
223  virtual int getNbSinkStreams() const { return 1; }
224  virtual int getNbSourceStreams() const { return 0; }
225 
226  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
227  {
228  (void) streamIndex;
229  (void) sinkElseSource;
231  }
232 
233  virtual int webapiSettingsGet(
235  QString& errorMessage);
236 
237  virtual int webapiSettingsPutPatch(
238  bool force,
239  const QStringList& channelSettingsKeys,
241  QString& errorMessage);
242 
243  virtual int webapiReportGet(
245  QString& errorMessage);
246 
247  double getMagSq() const { return m_magsq; }
248 
249  CWKeyer *getCWKeyer() { return &m_cwKeyer; }
250 
251  static const QString m_channelIdURI;
252  static const QString m_channelId;
253 
254 signals:
261  void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples);
262 
263 
264 private:
265  enum RateState {
268  };
269 
273 
278 
282  float m_modPhasor;
284 
289 
294 
297 
298  double m_magsq;
300 
305 
310 
313 
314  std::ifstream m_ifstream;
315  QString m_fileName;
316  quint64 m_fileSize;
317  quint32 m_recordLength;
319 
325 
326  QNetworkAccessManager *m_networkManager;
327  QNetworkRequest m_networkRequest;
328 
329  static const int m_levelNbSamples;
330 
331  void applyAudioSampleRate(int sampleRate);
332  void applyFeedbackAudioSampleRate(unsigned int sampleRate);
333  void processOneSample(Complex& ci);
334  void applyChannelSettings(int basebandSampleRate, int outputSampleRate, int inputFrequencyOffset, bool force = false);
335  void applySettings(const NFMModSettings& settings, bool force = false);
336  void pullAF(Real& sample);
337  void pushFeedback(Real sample);
338  void calculateLevel(Real& sample);
339  void modulateSample();
340  void openFileStream();
341  void seekFileStream(int seekPercentage);
344  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const NFMModSettings& settings, bool force);
345  void webapiReverseSendCWSettings(const CWKeyerSettings& settings);
346 
347 private slots:
348  void networkManagerFinished(QNetworkReply *reply);
349 };
350 
351 
352 #endif /* PLUGINS_CHANNELTX_MODNFM_NFMMOD_H_ */
NFMModSettings::NFMModInputAF m_afInput
Definition: nfmmod.h:320
NCOF m_toneNco
Definition: nfmmod.h:280
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const NFMModSettings &settings, bool force)
Definition: nfmmod.cpp:910
void processOneSample(Complex &ci)
Definition: nfmmod.cpp:294
static const int m_levelNbSamples
Definition: nfmmod.h:329
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Definition: nfmmod.cpp:903
void calculateLevel(Real &sample)
Definition: nfmmod.cpp:315
std::size_t getSamplesCount() const
Definition: nfmmod.h:163
static const QString m_channelIdURI
Definition: nfmmod.h:251
MsgConfigureFileSourceName(const QString &fileName)
Definition: nfmmod.h:114
uint m_feedbackAudioBufferFill
Definition: nfmmod.h:308
virtual int getNbSourceStreams() const
Definition: nfmmod.h:224
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
NFMModSettings m_settings
Definition: nfmmod.h:66
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
void networkManagerFinished(QNetworkReply *reply)
Definition: nfmmod.cpp:1023
void pushFeedback(Real sample)
Definition: nfmmod.cpp:271
void applyChannelSettings(int basebandSampleRate, int outputSampleRate, int inputFrequencyOffset, bool force=false)
Definition: nfmmod.cpp:538
double m_magsq
Definition: nfmmod.h:298
void pullAF(Real &sample)
Definition: nfmmod.cpp:204
CWKeyer m_cwKeyer
Definition: nfmmod.h:324
DeviceAPI * m_deviceAPI
Definition: nfmmod.h:270
void webapiReverseSendCWSettings(const CWKeyerSettings &settings)
Definition: nfmmod.cpp:992
Bandpass< Real > m_bandpass
Definition: nfmmod.h:296
Interpolator m_feedbackInterpolator
Definition: nfmmod.h:290
Real m_peakLevel
Definition: nfmmod.h:322
MsgReportFileSourceStreamData(int sampleRate, quint32 recordLength)
Definition: nfmmod.h:196
Definition: ncof.h:24
int getCenterFrequency() const
Definition: nfmmod.h:81
MsgConfigureNFMMod(const NFMModSettings &settings, bool force)
Definition: nfmmod.h:69
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const NFMModSettings &settings)
Definition: nfmmod.cpp:852
Interpolator m_interpolator
Definition: nfmmod.h:285
MsgConfigureFileSourceSeek(int seekPercentage)
Definition: nfmmod.h:135
Real m_levelSum
Definition: nfmmod.h:323
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: nfmmod.cpp:722
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: nfmmod.h:92
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: nfmmod.cpp:733
virtual int getNbSinkStreams() const
Definition: nfmmod.h:223
virtual void start()
Definition: nfmmod.cpp:334
static MsgReportFileSourceStreamData * create(int sampleRate, quint32 recordLength)
Definition: nfmmod.h:186
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: nfmmod.h:83
static MsgConfigureFileSourceSeek * create(int seekPercentage)
Definition: nfmmod.h:127
int m_sampleRate
Definition: nfmmod.h:318
virtual bool deserialize(const QByteArray &data)
Definition: nfmmod.cpp:702
int m_seekPercentage
percentage of seek position from the beginning 0..100
Definition: nfmmod.h:133
QString m_fileName
Definition: nfmmod.h:315
AudioFifo m_audioFifo
Definition: nfmmod.h:304
qint64 m_inputFrequencyOffset
AudioVector m_audioBuffer
Definition: nfmmod.h:302
Definition: nco.h:25
virtual void pullAudio(int nbSamples)
Definition: nfmmod.cpp:164
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
Definition: nfmmod.h:49
quint32 m_recordLength
record length in seconds computed from file size
Definition: nfmmod.h:317
AudioVector m_feedbackAudioBuffer
Definition: nfmmod.h:307
Real m_interpolatorDistanceRemain
Definition: nfmmod.h:287
virtual void pull(Sample &sample)
Definition: nfmmod.cpp:119
MovingAverageUtil< double, double, 16 > m_movingAverage
Definition: nfmmod.h:299
static MsgReportFileSourceStreamTiming * create(std::size_t samplesCount)
Definition: nfmmod.h:165
virtual void stop()
Definition: nfmmod.cpp:343
quint32 m_feedbackAudioSampleRate
Definition: nfmmod.h:306
virtual void getIdentifier(QString &id)
Definition: nfmmod.h:216
virtual QByteArray serialize() const
Definition: nfmmod.cpp:697
UpChannelizer * m_channelizer
Definition: nfmmod.h:272
RateState
Definition: nfmmod.h:265
SampleVector m_sampleBuffer
Definition: nfmmod.h:311
void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples)
NFMModSettings m_settings
Definition: nfmmod.h:277
NCOF m_ctcssNco
Definition: nfmmod.h:281
Real m_feedbackInterpolatorDistance
Definition: nfmmod.h:291
QNetworkRequest m_networkRequest
Definition: nfmmod.h:327
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: nfmmod.h:218
quint32 m_levelCalcCount
Definition: nfmmod.h:321
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: nfmmod.cpp:347
static MsgConfigureNFMMod * create(const NFMModSettings &settings, bool force)
Definition: nfmmod.h:60
void seekFileStream(int seekPercentage)
Definition: nfmmod.cpp:482
bool m_interpolatorConsumed
Definition: nfmmod.h:288
MsgReportFileSourceStreamTiming(std::size_t samplesCount)
Definition: nfmmod.h:173
void openFileStream()
Definition: nfmmod.cpp:460
int m_basebandSampleRate
Definition: nfmmod.h:274
uint m_audioBufferFill
Definition: nfmmod.h:303
Complex m_modSample
Definition: nfmmod.h:283
void applySettings(const NFMModSettings &settings, bool force=false)
Definition: nfmmod.cpp:568
void modulateSample()
Definition: nfmmod.cpp:177
virtual void destroy()
Definition: nfmmod.h:208
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: nfmmod.h:226
quint32 m_audioSampleRate
Definition: nfmmod.h:301
static MsgConfigureFileSourceStreamTiming * create()
Definition: nfmmod.h:146
Lowpass< Real > m_lowpass
Definition: nfmmod.h:295
QNetworkAccessManager * m_networkManager
Definition: nfmmod.h:326
NFMMod(DeviceAPI *deviceAPI)
Definition: nfmmod.cpp:55
void applyFeedbackAudioSampleRate(unsigned int sampleRate)
Definition: nfmmod.cpp:521
const QString & getFileName() const
Definition: nfmmod.h:104
static const QString m_channelId
Definition: nfmmod.h:252
ThreadedBasebandSampleSource * m_threadedChannelizer
Definition: nfmmod.h:271
quint64 m_fileSize
raw file size (bytes)
Definition: nfmmod.h:316
float m_modPhasor
baseband modulator phasor
Definition: nfmmod.h:282
~NFMMod()
Definition: nfmmod.cpp:107
AudioFifo m_feedbackAudioFifo
Definition: nfmmod.h:309
bool m_feedbackInterpolatorConsumed
Definition: nfmmod.h:293
bool getForce() const
Definition: nfmmod.h:58
const NFMModSettings & getSettings() const
Definition: nfmmod.h:57
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
Definition: nfmmod.cpp:841
NCO m_carrierNco
Definition: nfmmod.h:279
std::ifstream m_ifstream
Definition: nfmmod.h:314
double getMagSq() const
Definition: nfmmod.h:247
static MsgConfigureFileSourceName * create(const QString &fileName)
Definition: nfmmod.h:106
int m_outputSampleRate
Definition: nfmmod.h:275
std::complex< Real > Complex
Definition: dsptypes.h:43
virtual void getTitle(QString &title)
Definition: nfmmod.h:217
float Real
Definition: dsptypes.h:42
CWKeyer * getCWKeyer()
Definition: nfmmod.h:249
void applyAudioSampleRate(int sampleRate)
Definition: nfmmod.cpp:495
QMutex m_settingsMutex
Definition: nfmmod.h:312
int m_inputFrequencyOffset
Definition: nfmmod.h:276
Real m_interpolatorDistance
Definition: nfmmod.h:286
Real m_feedbackInterpolatorDistanceRemain
Definition: nfmmod.h:292