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.
ambeworker.h
Go to the documentation of this file.
1 // Copyright (C) 2019 F4EXB //
3 // written by Edouard Griffiths //
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 SDRBASE_AMBE_AMBEWORKER_H_
20 #define SDRBASE_AMBE_AMBEWORKER_H_
21 
22 #include <QObject>
23 #include <QDebug>
24 #include <QDateTime>
25 
26 #include "export.h"
27 #include "dvcontroller.h"
28 
29 #include "util/messagequeue.h"
30 #include "util/message.h"
31 #include "dsp/filtermbe.h"
32 #include "dsp/dsptypes.h"
33 #include "audio/audiocompressor.h"
34 
35 class AudioFifo;
36 
37 class SDRBASE_API AMBEWorker : public QObject {
38  Q_OBJECT
39 public:
40  class MsgTest : public Message
41  {
43  public:
44  static MsgTest* create() { return new MsgTest(); }
45  private:
46  MsgTest() {}
47  };
48 
49  class MsgMbeDecode : public Message
50  {
52  public:
53  const unsigned char *getMbeFrame() const { return m_mbeFrame; }
54  SerialDV::DVRate getMbeRate() const { return m_mbeRate; }
55  int getVolumeIndex() const { return m_volumeIndex; }
56  unsigned char getChannels() const { return m_channels % 4; }
57  bool getUseHP() const { return m_useHP; }
58  int getUpsampling() const { return m_upsampling; }
59  AudioFifo *getAudioFifo() { return m_audioFifo; }
60 
62  const unsigned char *mbeFrame,
63  int mbeRateIndex,
64  int volumeIndex,
65  unsigned char channels,
66  bool useHP,
67  int upsampling,
68  AudioFifo *audioFifo)
69  {
70  return new MsgMbeDecode(mbeFrame, (SerialDV::DVRate) mbeRateIndex, volumeIndex, channels, useHP, upsampling, audioFifo);
71  }
72 
73  private:
74  unsigned char m_mbeFrame[SerialDV::MBE_FRAME_MAX_LENGTH_BYTES];
75  SerialDV::DVRate m_mbeRate;
77  unsigned char m_channels;
78  bool m_useHP;
81 
82  MsgMbeDecode(const unsigned char *mbeFrame,
83  SerialDV::DVRate mbeRate,
84  int volumeIndex,
85  unsigned char channels,
86  bool useHP,
87  int upsampling,
88  AudioFifo *audioFifo) :
89  Message(),
90  m_mbeRate(mbeRate),
91  m_volumeIndex(volumeIndex),
92  m_channels(channels),
93  m_useHP(useHP),
94  m_upsampling(upsampling),
95  m_audioFifo(audioFifo)
96  {
97  memcpy((void *) m_mbeFrame, (const void *) mbeFrame, SerialDV::DVController::getNbMbeBytes(m_mbeRate));
98  }
99  };
100 
101  AMBEWorker();
102  ~AMBEWorker();
103 
104  void pushMbeFrame(const unsigned char *mbeFrame,
105  int mbeRateIndex,
106  int mbeVolumeIndex,
107  unsigned char channels,
108  bool useHP,
109  int upsampling,
110  AudioFifo *audioFifo);
111 
112  bool open(const std::string& deviceRef);
113  void close();
114  void process();
115  void stop();
116  bool isAvailable();
117  bool hasFifo(AudioFifo *audioFifo);
118 
119  void postTest()
120  {
121  //emit inputMessageReady();
122  m_inputMessageQueue.push(MsgTest::create());
123  }
124 
126 
127 signals:
128  void finished();
129 
130 public slots:
131  void handleInputMessages();
132 
133 private:
134  void upsample(int upsampling, short *in, int nbSamplesIn, unsigned char channels);
135  void noUpsample(short *in, int nbSamplesIn, unsigned char channels);
136  void setVolumeFactors();
137 
138  SerialDV::DVController m_dvController;
140  QDateTime m_timestamp;
141  volatile bool m_running;
144  short m_dvAudioSamples[SerialDV::MBE_AUDIO_BLOCK_SIZE];
148  float m_phase;
151  float m_volume;
152  float m_upsamplingFactors[7];
154 };
155 
156 #endif // SDRBASE_AMBE_AMBEWORKER_H_
float m_phase
Definition: ambeworker.h:148
AudioFifo * m_audioFifo
Definition: ambeworker.h:80
MBEAudioInterpolatorFilter m_upsampleFilter
Definition: ambeworker.h:149
AudioCompressor m_compressor
Definition: ambeworker.h:153
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
AudioFifo * getAudioFifo()
Definition: ambeworker.h:59
void postTest()
Definition: ambeworker.h:119
bool getUseHP() const
Definition: ambeworker.h:57
static MsgTest * create()
Definition: ambeworker.h:44
SerialDV::DVController m_dvController
Definition: ambeworker.h:138
static MsgMbeDecode * create(const unsigned char *mbeFrame, int mbeRateIndex, int volumeIndex, unsigned char channels, bool useHP, int upsampling, AudioFifo *audioFifo)
Definition: ambeworker.h:61
float m_volume
Definition: ambeworker.h:151
int m_currentGainOut
Definition: ambeworker.h:143
float m_upsamplerLastValue
Definition: ambeworker.h:147
void * create(QString type)
int getUpsampling() const
Definition: ambeworker.h:58
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
unsigned char getChannels() const
Definition: ambeworker.h:56
volatile bool m_running
Definition: ambeworker.h:141
MsgMbeDecode(const unsigned char *mbeFrame, SerialDV::DVRate mbeRate, int volumeIndex, unsigned char channels, bool useHP, int upsampling, AudioFifo *audioFifo)
Definition: ambeworker.h:82
SerialDV::DVRate getMbeRate() const
Definition: ambeworker.h:54
QDateTime m_timestamp
Definition: ambeworker.h:140
SerialDV::DVRate m_mbeRate
Definition: ambeworker.h:75
uint m_audioBufferFill
Definition: ambeworker.h:146
unsigned char m_channels
Definition: ambeworker.h:77
AudioVector m_audioBuffer
Definition: ambeworker.h:145
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
Definition: ambeworker.h:125
int m_upsampling
Definition: ambeworker.h:150
#define SDRBASE_API
Definition: export.h:40
const unsigned char * getMbeFrame() const
Definition: ambeworker.h:53
int m_currentGainIn
Definition: ambeworker.h:142
AudioFifo * m_audioFifo
Definition: ambeworker.h:139
int getVolumeIndex() const
Definition: ambeworker.h:55