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