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.
Classes | Public Slots | Signals | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
AMBEWorker Class Reference

#include <ambeworker.h>

Inherits QObject.

+ Collaboration diagram for AMBEWorker:

Classes

class  MsgMbeDecode
 
class  MsgTest
 

Public Slots

void handleInputMessages ()
 

Signals

void finished ()
 

Public Member Functions

 AMBEWorker ()
 
 ~AMBEWorker ()
 
void pushMbeFrame (const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, unsigned char channels, bool useHP, int upsampling, AudioFifo *audioFifo)
 
bool open (const std::string &deviceRef)
 Either serial device or ip:port. More...
 
void close ()
 
void process ()
 
void stop ()
 
bool isAvailable ()
 
bool hasFifo (AudioFifo *audioFifo)
 
void postTest ()
 

Public Attributes

MessageQueue m_inputMessageQueue
 Queue for asynchronous inbound communication. More...
 

Private Member Functions

void upsample (int upsampling, short *in, int nbSamplesIn, unsigned char channels)
 
void noUpsample (short *in, int nbSamplesIn, unsigned char channels)
 
void setVolumeFactors ()
 

Private Attributes

SerialDV::DVController m_dvController
 
AudioFifom_audioFifo
 
QDateTime m_timestamp
 
volatile bool m_running
 
int m_currentGainIn
 
int m_currentGainOut
 
short m_dvAudioSamples [SerialDV::MBE_AUDIO_BLOCK_SIZE]
 
AudioVector m_audioBuffer
 
uint m_audioBufferFill
 
float m_upsamplerLastValue
 
float m_phase
 
MBEAudioInterpolatorFilter m_upsampleFilter
 
int m_upsampling
 
float m_volume
 
float m_upsamplingFactors [7]
 
AudioCompressor m_compressor
 

Detailed Description

Definition at line 37 of file ambeworker.h.

Constructor & Destructor Documentation

◆ AMBEWorker()

AMBEWorker::AMBEWorker ( )

Definition at line 29 of file ambeworker.cpp.

29  :
30  m_running(false),
31  m_currentGainIn(0),
34  m_phase(0),
35  m_upsampling(1),
36  m_volume(1.0f)
37 {
38  m_audioBuffer.resize(48000);
40  m_audioFifo = 0;
41  std::fill(m_dvAudioSamples, m_dvAudioSamples+SerialDV::MBE_AUDIO_BLOCK_SIZE, 0);
43 }
float m_phase
Definition: ambeworker.h:148
float m_volume
Definition: ambeworker.h:151
int m_currentGainOut
Definition: ambeworker.h:143
float m_upsamplerLastValue
Definition: ambeworker.h:147
void setVolumeFactors()
Definition: ambeworker.cpp:225
short m_dvAudioSamples[SerialDV::MBE_AUDIO_BLOCK_SIZE]
Definition: ambeworker.h:144
volatile bool m_running
Definition: ambeworker.h:141
uint m_audioBufferFill
Definition: ambeworker.h:146
AudioVector m_audioBuffer
Definition: ambeworker.h:145
int m_upsampling
Definition: ambeworker.h:150
int m_currentGainIn
Definition: ambeworker.h:142
AudioFifo * m_audioFifo
Definition: ambeworker.h:139

◆ ~AMBEWorker()

AMBEWorker::~AMBEWorker ( )

Definition at line 45 of file ambeworker.cpp.

46 {}

Member Function Documentation

◆ close()

void AMBEWorker::close ( )

Definition at line 53 of file ambeworker.cpp.

References m_dvController.

Referenced by AMBEEngine::scan().

54 {
55  m_dvController.close();
56 }
SerialDV::DVController m_dvController
Definition: ambeworker.h:138
+ Here is the caller graph for this function:

◆ finished

void AMBEWorker::finished ( )
signal

Referenced by process().

+ Here is the caller graph for this function:

◆ handleInputMessages

void AMBEWorker::handleInputMessages ( )
slot

Definition at line 77 of file ambeworker.cpp.

References MessageQueue::clear(), AMBEWorker::MsgMbeDecode::getAudioFifo(), AMBEWorker::MsgMbeDecode::getChannels(), AMBEWorker::MsgMbeDecode::getMbeFrame(), AMBEWorker::MsgMbeDecode::getMbeRate(), AMBEWorker::MsgMbeDecode::getUpsampling(), AMBEWorker::MsgMbeDecode::getUseHP(), AMBEWorker::MsgMbeDecode::getVolumeIndex(), m_audioBuffer, m_audioBufferFill, m_dvAudioSamples, m_dvController, m_inputMessageQueue, m_timestamp, m_upsampleFilter, m_upsampling, m_volume, Message::match(), noUpsample(), MessageQueue::pop(), setVolumeFactors(), MessageQueue::size(), upsample(), MBEAudioInterpolatorFilter::useHP(), and AudioFifo::write().

78 {
79  Message* message;
81  AudioFifo *audioFifo = 0;
82 
83  while ((message = m_inputMessageQueue.pop()) != 0)
84  {
85  if (MsgMbeDecode::match(*message))
86  {
87  MsgMbeDecode *decodeMsg = (MsgMbeDecode *) message;
88  int dBVolume = (decodeMsg->getVolumeIndex() - 30) / 4;
89  float volume = pow(10.0, dBVolume / 10.0f);
90  int upsampling = decodeMsg->getUpsampling();
91  upsampling = upsampling > 6 ? 6 : upsampling < 1 ? 1 : upsampling;
92 
93  if ((volume != m_volume) || (upsampling != m_upsampling))
94  {
95  m_volume = volume;
96  m_upsampling = upsampling;
98  }
99 
100  m_upsampleFilter.useHP(decodeMsg->getUseHP());
101 
102  if (m_dvController.decode(m_dvAudioSamples, decodeMsg->getMbeFrame(), decodeMsg->getMbeRate()))
103  {
104  if (upsampling > 1) {
105  upsample(upsampling, m_dvAudioSamples, SerialDV::MBE_AUDIO_BLOCK_SIZE, decodeMsg->getChannels());
106  } else {
107  noUpsample(m_dvAudioSamples, SerialDV::MBE_AUDIO_BLOCK_SIZE, decodeMsg->getChannels());
108  }
109 
110  audioFifo = decodeMsg->getAudioFifo();
111 
112  if (audioFifo && (m_audioBufferFill >= m_audioBuffer.size() - 960))
113  {
114  uint res = audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
115 
116  if (res != m_audioBufferFill) {
117  qDebug("AMBEWorker::handleInputMessages: %u/%u audio samples written", res, m_audioBufferFill);
118  }
119 
120  m_audioBufferFill = 0;
121  }
122  }
123  else
124  {
125  qDebug("AMBEWorker::handleInputMessages: MsgMbeDecode: decode failed");
126  }
127  }
128 
129  delete message;
130 
131  if (m_inputMessageQueue.size() > 100)
132  {
133  qDebug("AMBEWorker::handleInputMessages: MsgMbeDecode: too many messages in queue. Flushing...");
135  break;
136  }
137  }
138 
139  if (audioFifo)
140  {
141  uint res = audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
142 
143  if (res != m_audioBufferFill) {
144  qDebug("AMBEWorker::handleInputMessages: %u/%u audio samples written", res, m_audioBufferFill);
145  }
146 
147  m_audioBufferFill = 0;
148  }
149 
150  m_timestamp = QDateTime::currentDateTime();
151 }
MBEAudioInterpolatorFilter m_upsampleFilter
Definition: ambeworker.h:149
Message * pop()
Pop message from queue.
int size()
Returns queue size.
void clear()
Empty queue.
SerialDV::DVController m_dvController
Definition: ambeworker.h:138
float m_volume
Definition: ambeworker.h:151
void setVolumeFactors()
Definition: ambeworker.cpp:225
short m_dvAudioSamples[SerialDV::MBE_AUDIO_BLOCK_SIZE]
Definition: ambeworker.h:144
void noUpsample(short *in, int nbSamplesIn, unsigned char channels)
Definition: ambeworker.cpp:207
static bool match(const Message *message)
Definition: message.cpp:45
QDateTime m_timestamp
Definition: ambeworker.h:140
uint m_audioBufferFill
Definition: ambeworker.h:146
void useHP(bool useHP)
Definition: filtermbe.h:70
void upsample(int upsampling, short *in, int nbSamplesIn, unsigned char channels)
Definition: ambeworker.cpp:179
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
uint32_t write(const quint8 *data, uint32_t numSamples)
Definition: audiofifo.cpp:66
+ Here is the call graph for this function:

◆ hasFifo()

bool AMBEWorker::hasFifo ( AudioFifo audioFifo)

Definition at line 174 of file ambeworker.cpp.

References m_audioFifo.

175 {
176  return m_audioFifo == audioFifo;
177 }
AudioFifo * m_audioFifo
Definition: ambeworker.h:139

◆ isAvailable()

bool AMBEWorker::isAvailable ( )

Definition at line 165 of file ambeworker.cpp.

References m_audioFifo, and m_timestamp.

166 {
167  if (m_audioFifo == 0) {
168  return true;
169  }
170 
171  return m_timestamp.time().msecsTo(QDateTime::currentDateTime().time()) > 1000; // 1 second inactivity timeout
172 }
QDateTime m_timestamp
Definition: ambeworker.h:140
AudioFifo * m_audioFifo
Definition: ambeworker.h:139

◆ noUpsample()

void AMBEWorker::noUpsample ( short *  in,
int  nbSamplesIn,
unsigned char  channels 
)
private

Definition at line 207 of file ambeworker.cpp.

References i, m_audioBuffer, m_audioBufferFill, m_upsampleFilter, m_upsamplingFactors, MBEAudioInterpolatorFilter::runHP(), and MBEAudioInterpolatorFilter::usesHP().

Referenced by handleInputMessages().

208 {
209  for (int i = 0; i < nbSamplesIn; i++)
210  {
211  float cur = m_upsampleFilter.usesHP() ? m_upsampleFilter.runHP((float) in[i]) : (float) in[i];
212  m_audioBuffer[m_audioBufferFill].l = channels & 1 ? cur*m_upsamplingFactors[0] : 0;
213  m_audioBuffer[m_audioBufferFill].r = (channels>>1) & 1 ? cur*m_upsamplingFactors[0] : 0;
214 
215  if (m_audioBufferFill < m_audioBuffer.size() - 1) {
217  }
218  }
219 
220  if (m_audioBufferFill >= m_audioBuffer.size() - 1) {
221  qDebug("AMBEWorker::noUpsample: audio buffer is full check its size");
222  }
223 }
MBEAudioInterpolatorFilter m_upsampleFilter
Definition: ambeworker.h:149
float runHP(const float &sample)
Definition: filtermbe.cpp:42
int32_t i
Definition: decimators.h:244
uint m_audioBufferFill
Definition: ambeworker.h:146
float m_upsamplingFactors[7]
Definition: ambeworker.h:152
AudioVector m_audioBuffer
Definition: ambeworker.h:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ open()

bool AMBEWorker::open ( const std::string &  deviceRef)

Either serial device or ip:port.

Definition at line 48 of file ambeworker.cpp.

References m_dvController.

Referenced by AMBEEngine::registerController(), and AMBEEngine::scan().

49 {
50  return m_dvController.open(deviceRef);
51 }
SerialDV::DVController m_dvController
Definition: ambeworker.h:138
+ Here is the caller graph for this function:

◆ postTest()

void AMBEWorker::postTest ( )
inline

Definition at line 119 of file ambeworker.h.

References SWGSDRangel::create().

120  {
121  //emit inputMessageReady();
123  }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgTest * create()
Definition: ambeworker.h:44
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
Definition: ambeworker.h:125
+ Here is the call graph for this function:

◆ process()

void AMBEWorker::process ( )

Definition at line 58 of file ambeworker.cpp.

References finished(), and m_running.

59 {
60  m_running = true;
61  qDebug("AMBEWorker::process: started");
62 
63  while (m_running)
64  {
65  std::this_thread::sleep_for(std::chrono::seconds(1));
66  }
67 
68  qDebug("AMBEWorker::process: stopped");
69  emit finished();
70 }
volatile bool m_running
Definition: ambeworker.h:141
void finished()

◆ pushMbeFrame()

void AMBEWorker::pushMbeFrame ( const unsigned char *  mbeFrame,
int  mbeRateIndex,
int  mbeVolumeIndex,
unsigned char  channels,
bool  useHP,
int  upsampling,
AudioFifo audioFifo 
)

Definition at line 153 of file ambeworker.cpp.

References AMBEWorker::MsgMbeDecode::create(), m_audioFifo, m_inputMessageQueue, and MessageQueue::push().

160 {
161  m_audioFifo = audioFifo;
162  m_inputMessageQueue.push(MsgMbeDecode::create(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, useHP, upsampling, audioFifo));
163 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgMbeDecode * create(const unsigned char *mbeFrame, int mbeRateIndex, int volumeIndex, unsigned char channels, bool useHP, int upsampling, AudioFifo *audioFifo)
Definition: ambeworker.h:61
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
Definition: ambeworker.h:125
AudioFifo * m_audioFifo
Definition: ambeworker.h:139
+ Here is the call graph for this function:

◆ setVolumeFactors()

void AMBEWorker::setVolumeFactors ( )
private

Definition at line 225 of file ambeworker.cpp.

References i, m_upsampling, m_upsamplingFactors, and m_volume.

Referenced by handleInputMessages().

226 {
228 
229  for (int i = 1; i <= m_upsampling; i++) {
231  }
232 }
float m_volume
Definition: ambeworker.h:151
int32_t i
Definition: decimators.h:244
float m_upsamplingFactors[7]
Definition: ambeworker.h:152
int m_upsampling
Definition: ambeworker.h:150
+ Here is the caller graph for this function:

◆ stop()

void AMBEWorker::stop ( )

Definition at line 72 of file ambeworker.cpp.

References m_running.

73 {
74  m_running = false;
75 }
volatile bool m_running
Definition: ambeworker.h:141

◆ upsample()

void AMBEWorker::upsample ( int  upsampling,
short *  in,
int  nbSamplesIn,
unsigned char  channels 
)
private

Definition at line 179 of file ambeworker.cpp.

References AudioCompressor::compress(), i, m_audioBuffer, m_audioBufferFill, m_compressor, m_upsampleFilter, m_upsamplerLastValue, m_upsamplingFactors, MBEAudioInterpolatorFilter::runHP(), MBEAudioInterpolatorFilter::runLP(), and MBEAudioInterpolatorFilter::usesHP().

Referenced by handleInputMessages().

180 {
181  for (int i = 0; i < nbSamplesIn; i++)
182  {
183  //float cur = m_upsampleFilter.usesHP() ? m_upsampleFilter.runHP((float) m_compressor.compress(in[i])) : (float) m_compressor.compress(in[i]);
184  float cur = m_upsampleFilter.usesHP() ? m_upsampleFilter.runHP((float) in[i]) : (float) in[i];
185  float prev = m_upsamplerLastValue;
186  qint16 upsample;
187 
188  for (int j = 1; j <= upsampling; j++)
189  {
190  upsample = (qint16) m_upsampleFilter.runLP(cur*m_upsamplingFactors[j] + prev*m_upsamplingFactors[upsampling-j]);
191  m_audioBuffer[m_audioBufferFill].l = channels & 1 ? m_compressor.compress(upsample) : 0;
192  m_audioBuffer[m_audioBufferFill].r = (channels>>1) & 1 ? m_compressor.compress(upsample) : 0;
193 
194  if (m_audioBufferFill < m_audioBuffer.size() - 1) {
196  }
197  }
198 
199  m_upsamplerLastValue = cur;
200  }
201 
202  if (m_audioBufferFill >= m_audioBuffer.size() - 1) {
203  qDebug("AMBEWorker::upsample(%d): audio buffer is full check its size", upsampling);
204  }
205 }
MBEAudioInterpolatorFilter m_upsampleFilter
Definition: ambeworker.h:149
AudioCompressor m_compressor
Definition: ambeworker.h:153
float runHP(const float &sample)
Definition: filtermbe.cpp:42
float runLP(const float &sample)
Definition: filtermbe.cpp:47
float m_upsamplerLastValue
Definition: ambeworker.h:147
int32_t i
Definition: decimators.h:244
uint m_audioBufferFill
Definition: ambeworker.h:146
float m_upsamplingFactors[7]
Definition: ambeworker.h:152
void upsample(int upsampling, short *in, int nbSamplesIn, unsigned char channels)
Definition: ambeworker.cpp:179
AudioVector m_audioBuffer
Definition: ambeworker.h:145
int16_t compress(int16_t sample)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_audioBuffer

AudioVector AMBEWorker::m_audioBuffer
private

Definition at line 145 of file ambeworker.h.

Referenced by handleInputMessages(), noUpsample(), and upsample().

◆ m_audioBufferFill

uint AMBEWorker::m_audioBufferFill
private

Definition at line 146 of file ambeworker.h.

Referenced by handleInputMessages(), noUpsample(), and upsample().

◆ m_audioFifo

AudioFifo* AMBEWorker::m_audioFifo
private

Definition at line 139 of file ambeworker.h.

Referenced by hasFifo(), isAvailable(), and pushMbeFrame().

◆ m_compressor

AudioCompressor AMBEWorker::m_compressor
private

Definition at line 153 of file ambeworker.h.

Referenced by upsample().

◆ m_currentGainIn

int AMBEWorker::m_currentGainIn
private

Definition at line 142 of file ambeworker.h.

◆ m_currentGainOut

int AMBEWorker::m_currentGainOut
private

Definition at line 143 of file ambeworker.h.

◆ m_dvAudioSamples

short AMBEWorker::m_dvAudioSamples[SerialDV::MBE_AUDIO_BLOCK_SIZE]
private

Definition at line 144 of file ambeworker.h.

Referenced by handleInputMessages().

◆ m_dvController

SerialDV::DVController AMBEWorker::m_dvController
private

Definition at line 138 of file ambeworker.h.

Referenced by close(), handleInputMessages(), and open().

◆ m_inputMessageQueue

MessageQueue AMBEWorker::m_inputMessageQueue

Queue for asynchronous inbound communication.

Definition at line 125 of file ambeworker.h.

Referenced by handleInputMessages(), and pushMbeFrame().

◆ m_phase

float AMBEWorker::m_phase
private

Definition at line 148 of file ambeworker.h.

◆ m_running

volatile bool AMBEWorker::m_running
private

Definition at line 141 of file ambeworker.h.

Referenced by process(), and stop().

◆ m_timestamp

QDateTime AMBEWorker::m_timestamp
private

Definition at line 140 of file ambeworker.h.

Referenced by handleInputMessages(), and isAvailable().

◆ m_upsampleFilter

MBEAudioInterpolatorFilter AMBEWorker::m_upsampleFilter
private

Definition at line 149 of file ambeworker.h.

Referenced by handleInputMessages(), noUpsample(), and upsample().

◆ m_upsamplerLastValue

float AMBEWorker::m_upsamplerLastValue
private

Definition at line 147 of file ambeworker.h.

Referenced by upsample().

◆ m_upsampling

int AMBEWorker::m_upsampling
private

Definition at line 150 of file ambeworker.h.

Referenced by handleInputMessages(), and setVolumeFactors().

◆ m_upsamplingFactors

float AMBEWorker::m_upsamplingFactors[7]
private

Definition at line 152 of file ambeworker.h.

Referenced by noUpsample(), setVolumeFactors(), and upsample().

◆ m_volume

float AMBEWorker::m_volume
private

Definition at line 151 of file ambeworker.h.

Referenced by handleInputMessages(), and setVolumeFactors().


The documentation for this class was generated from the following files: