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.
ssbmod.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_MODSSB_SSBMOD_H_
19 #define PLUGINS_CHANNELTX_MODSSB_SSBMOD_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/basebandsamplesink.h"
31 #include "dsp/ncof.h"
32 #include "dsp/interpolator.h"
33 #include "util/movingaverage.h"
34 #include "dsp/agc.h"
35 #include "dsp/fftfilt.h"
36 #include "dsp/cwkeyer.h"
37 #include "audio/audiofifo.h"
39 #include "util/message.h"
40 
41 #include "ssbmodsettings.h"
42 
43 class QNetworkAccessManager;
44 class QNetworkReply;
45 class DeviceAPI;
47 class UpChannelizer;
48 
49 class SSBMod : public BasebandSampleSource, public ChannelAPI {
50  Q_OBJECT
51 
52 public:
53  class MsgConfigureSSBMod : public Message {
55 
56  public:
57  const SSBModSettings& getSettings() const { return m_settings; }
58  bool getForce() const { return m_force; }
59 
60  static MsgConfigureSSBMod* create(const SSBModSettings& settings, bool force)
61  {
62  return new MsgConfigureSSBMod(settings, force);
63  }
64 
65  private:
67  bool m_force;
68 
69  MsgConfigureSSBMod(const SSBModSettings& 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  SSBMod(DeviceAPI *deviceAPI);
207  ~SSBMod();
208  virtual void destroy() { delete this; }
209 
210  void setSpectrumSampleSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; }
211 
212  virtual void pull(Sample& sample);
213  virtual void pullAudio(int nbSamples);
214  virtual void start();
215  virtual void stop();
216  virtual bool handleMessage(const Message& cmd);
217 
218  virtual void getIdentifier(QString& id) { id = objectName(); }
219  virtual void getTitle(QString& title) { title = m_settings.m_title; }
220  virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
221 
222  virtual QByteArray serialize() const;
223  virtual bool deserialize(const QByteArray& data);
224 
225  virtual int getNbSinkStreams() const { return 1; }
226  virtual int getNbSourceStreams() const { return 0; }
227 
228  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
229  {
230  (void) streamIndex;
231  (void) sinkElseSource;
233  }
234 
235  virtual int webapiSettingsGet(
237  QString& errorMessage);
238 
239  virtual int webapiSettingsPutPatch(
240  bool force,
241  const QStringList& channelSettingsKeys,
243  QString& errorMessage);
244 
245  virtual int webapiReportGet(
247  QString& errorMessage);
248 
250  double getMagSq() const { return m_magsq; }
251 
252  CWKeyer *getCWKeyer() { return &m_cwKeyer; }
253 
254  static const QString m_channelIdURI;
255  static const QString m_channelId;
256 
257 signals:
264  void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples);
265 
266 
267 private:
268  enum RateState {
271  };
272 
276 
281 
285 
290 
295 
302  static const int m_ssbFftLen;
303 
306 
310 
311  double m_magsq;
313 
318 
323 
325 
326  std::ifstream m_ifstream;
327  QString m_fileName;
328  quint64 m_fileSize;
329  quint32 m_recordLength;
331 
336 
339 
340  QNetworkAccessManager *m_networkManager;
341  QNetworkRequest m_networkRequest;
342 
343  static const int m_levelNbSamples;
344 
345  void applyAudioSampleRate(int sampleRate);
346  void applyFeedbackAudioSampleRate(unsigned int sampleRate);
347  void processOneSample(Complex& ci);
348  void applyChannelSettings(int basebandSampleRate, int outputSampleRate, int inputFrequencyOffset, bool force = false);
349  void applySettings(const SSBModSettings& settings, bool force = false);
350  void pullAF(Complex& sample);
351  void pushFeedback(Complex sample);
352  void calculateLevel(Complex& sample);
353  void modulateSample();
354  void openFileStream();
355  void seekFileStream(int seekPercentage);
358  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const SSBModSettings& settings, bool force);
359  void webapiReverseSendCWSettings(const CWKeyerSettings& settings);
360 
361 private slots:
362  void networkManagerFinished(QNetworkReply *reply);
363 };
364 
365 
366 #endif /* PLUGINS_CHANNELTX_MODSSB_SSBMOD_H_ */
virtual void getTitle(QString &title)
Definition: ssbmod.h:219
quint32 m_levelCalcCount
Definition: ssbmod.h:332
void calculateLevel(Complex &sample)
Definition: ssbmod.cpp:555
int m_outputSampleRate
Definition: ssbmod.h:278
static MsgConfigureSSBMod * create(const SSBModSettings &settings, bool force)
Definition: ssbmod.h:60
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Definition: ssbmod.cpp:1200
int m_basebandSampleRate
Definition: ssbmod.h:277
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
MsgReportFileSourceStreamTiming(std::size_t samplesCount)
Definition: ssbmod.h:173
Complex * m_SSBFilterBuffer
Definition: ssbmod.h:298
Definition: ssbmod.h:49
Interpolator m_interpolator
Definition: ssbmod.h:286
int m_inputFrequencyOffset
Definition: ssbmod.h:279
const QString & getFileName() const
Definition: ssbmod.h:104
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const SSBModSettings &settings, bool force)
Definition: ssbmod.cpp:1207
void networkManagerFinished(QNetworkReply *reply)
Definition: ssbmod.cpp:1329
int m_sampleRate
Definition: ssbmod.h:330
void openFileStream()
Definition: ssbmod.cpp:700
void applyFeedbackAudioSampleRate(unsigned int sampleRate)
Definition: ssbmod.cpp:794
DeviceAPI * m_deviceAPI
Definition: ssbmod.h:273
MsgConfigureSSBMod(const SSBModSettings &settings, bool force)
Definition: ssbmod.h:69
QMutex m_settingsMutex
Definition: ssbmod.h:324
void pullAF(Complex &sample)
Definition: ssbmod.cpp:219
quint64 m_fileSize
raw file size (bytes)
Definition: ssbmod.h:328
quint32 m_audioSampleRate
Definition: ssbmod.h:314
Definition: ncof.h:24
static MsgConfigureFileSourceSeek * create(int seekPercentage)
Definition: ssbmod.h:127
qint64 m_inputFrequencyOffset
Complex * m_DSBFilterBuffer
Definition: ssbmod.h:299
~SSBMod()
Definition: ssbmod.cpp:136
bool m_feedbackInterpolatorConsumed
Definition: ssbmod.h:294
void applySettings(const SSBModSettings &settings, bool force=false)
Definition: ssbmod.cpp:841
void seekFileStream(int seekPercentage)
Definition: ssbmod.cpp:725
std::size_t getSamplesCount() const
Definition: ssbmod.h:163
AudioVector m_audioBuffer
Definition: ssbmod.h:315
MovingAverageUtil< double, double, 16 > m_movingAverage
Definition: ssbmod.h:312
uint m_feedbackAudioBufferFill
Definition: ssbmod.h:321
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: ssbmod.h:92
virtual int getNbSourceStreams() const
Definition: ssbmod.h:226
QString m_fileName
Definition: ssbmod.h:327
Real m_levelSum
Definition: ssbmod.h:334
SampleVector m_sampleBuffer
Definition: ssbmod.h:305
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: ssbmod.h:228
AudioFifo m_feedbackAudioFifo
Definition: ssbmod.h:322
fftfilt * m_SSBFilter
Definition: ssbmod.h:296
Interpolator m_feedbackInterpolator
Definition: ssbmod.h:291
MsgReportFileSourceStreamData(int sampleRate, quint32 recordLength)
Definition: ssbmod.h:196
std::complex< float > cmplx
Definition: fftfilt.h:21
int m_sumCount
Definition: ssbmod.h:309
virtual QByteArray serialize() const
Definition: ssbmod.cpp:988
const SSBModSettings & getSettings() const
Definition: ssbmod.h:57
unsigned int uint32_t
Definition: rtptypes_win.h:46
virtual void getIdentifier(QString &id)
Definition: ssbmod.h:218
virtual int getNbSinkStreams() const
Definition: ssbmod.h:225
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: ssbmod.h:83
virtual void pullAudio(int nbSamples)
Definition: ssbmod.cpp:194
static const QString m_channelId
Definition: ssbmod.h:255
fftfilt::cmplx m_sum
Definition: ssbmod.h:307
Real m_interpolatorDistance
Definition: ssbmod.h:287
int m_agcStepLength
Definition: ssbmod.h:338
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
void processOneSample(Complex &ci)
Definition: ssbmod.cpp:534
double m_magsq
Definition: ssbmod.h:311
QNetworkRequest m_networkRequest
Definition: ssbmod.h:341
static MsgConfigureFileSourceStreamTiming * create()
Definition: ssbmod.h:146
Real m_feedbackInterpolatorDistance
Definition: ssbmod.h:292
Real m_interpolatorDistanceRemain
Definition: ssbmod.h:288
SSBMod(DeviceAPI *deviceAPI)
Definition: ssbmod.cpp:55
void webapiReverseSendCWSettings(const CWKeyerSettings &settings)
Definition: ssbmod.cpp:1298
void pushFeedback(Complex sample)
Definition: ssbmod.cpp:512
double getMagSq() const
Definition: ssbmod.h:250
AudioVector m_feedbackAudioBuffer
Definition: ssbmod.h:320
std::ifstream m_ifstream
Definition: ssbmod.h:326
static MsgConfigureFileSourceName * create(const QString &fileName)
Definition: ssbmod.h:106
CWKeyer m_cwKeyer
Definition: ssbmod.h:335
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const SSBModSettings &settings)
Definition: ssbmod.cpp:1148
virtual bool deserialize(const QByteArray &data)
Definition: ssbmod.cpp:993
SSBModSettings m_settings
Definition: ssbmod.h:280
static MsgReportFileSourceStreamData * create(int sampleRate, quint32 recordLength)
Definition: ssbmod.h:186
quint32 m_recordLength
record length in seconds computed from file size
Definition: ssbmod.h:329
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: ssbmod.cpp:1010
AudioCompressorSnd m_audioCompressor
Definition: ssbmod.h:337
NCOF m_carrierNco
Definition: ssbmod.h:282
void modulateSample()
Definition: ssbmod.cpp:207
int m_undersampleCount
Definition: ssbmod.h:308
virtual void destroy()
Definition: ssbmod.h:208
void applyAudioSampleRate(int sampleRate)
Definition: ssbmod.cpp:738
RateState
Definition: ssbmod.h:268
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: ssbmod.h:220
uint m_audioBufferFill
Definition: ssbmod.h:316
CWKeyer * getCWKeyer()
Definition: ssbmod.h:252
int m_DSBFilterBufferIndex
Definition: ssbmod.h:301
int getCenterFrequency() const
Definition: ssbmod.h:81
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: ssbmod.cpp:1021
static const int m_ssbFftLen
Definition: ssbmod.h:302
bool m_interpolatorConsumed
Definition: ssbmod.h:289
BasebandSampleSink * m_sampleSink
Definition: ssbmod.h:304
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: ssbmod.cpp:589
AudioFifo m_audioFifo
Definition: ssbmod.h:317
int m_SSBFilterBufferIndex
Definition: ssbmod.h:300
Real m_feedbackInterpolatorDistanceRemain
Definition: ssbmod.h:293
virtual void start()
Definition: ssbmod.cpp:576
QNetworkAccessManager * m_networkManager
Definition: ssbmod.h:340
static MsgReportFileSourceStreamTiming * create(std::size_t samplesCount)
Definition: ssbmod.h:165
virtual void stop()
Definition: ssbmod.cpp:585
void applyChannelSettings(int basebandSampleRate, int outputSampleRate, int inputFrequencyOffset, bool force=false)
Definition: ssbmod.cpp:811
virtual void pull(Sample &sample)
Definition: ssbmod.cpp:155
MsgConfigureFileSourceName(const QString &fileName)
Definition: ssbmod.h:114
void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples)
NCOF m_toneNco
Definition: ssbmod.h:283
uint32_t getAudioSampleRate() const
Definition: ssbmod.h:249
UpChannelizer * m_channelizer
Definition: ssbmod.h:275
SSBModSettings m_settings
Definition: ssbmod.h:66
std::complex< Real > Complex
Definition: dsptypes.h:43
static const int m_levelNbSamples
Definition: ssbmod.h:343
Complex m_modSample
Definition: ssbmod.h:284
float Real
Definition: dsptypes.h:42
MsgConfigureFileSourceSeek(int seekPercentage)
Definition: ssbmod.h:135
Real m_peakLevel
Definition: ssbmod.h:333
ThreadedBasebandSampleSource * m_threadedChannelizer
Definition: ssbmod.h:274
quint32 m_feedbackAudioSampleRate
Definition: ssbmod.h:319
int m_seekPercentage
percentage of seek position from the beginning 0..100
Definition: ssbmod.h:133
bool getForce() const
Definition: ssbmod.h:58
static const QString m_channelIdURI
Definition: ssbmod.h:254
void setSpectrumSampleSink(BasebandSampleSink *sampleSink)
Definition: ssbmod.h:210
fftfilt * m_DSBFilter
Definition: ssbmod.h:297
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
Definition: ssbmod.cpp:1137