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.
basebandsamplesource.cpp
Go to the documentation of this file.
1 // Copyright (C) 2016 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 
20 #include "util/message.h"
21 
23  m_guiMessageQueue(0),
24  m_sampleFifo(48000), // arbitrary, will be adjusted to match device sink FIFO size
25  m_deviceSampleFifo(0)
26 {
27  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
28  connect(&m_sampleFifo, SIGNAL(dataWrite(int)), this, SLOT(handleWriteToFifo(int)));
29 }
30 
32 {
33 }
34 
36 {
37  Message* message;
38 
39  while ((message = m_inputMessageQueue.pop()) != 0)
40  {
41  if (handleMessage(*message))
42  {
43  delete message;
44  }
45  }
46 }
47 
49 {
50  handleWriteToFifo(&m_sampleFifo, nbSamples);
51 }
52 
54 {
56 }
57 
59 {
60  SampleVector::iterator writeAt;
61  sampleFifo->getWriteIterator(writeAt);
62  pullAudio(nbSamples); // Pre-fetch input audio samples this is mandatory to keep things running smoothly
63 
64  for (int i = 0; i < nbSamples; i++)
65  {
66  pull((*writeAt));
67  sampleFifo->bumpIndex(writeAt);
68  }
69 }
70 
71 
73 {
74  if (m_deviceSampleFifo != deviceSampleFifo)
75  {
76  if (m_deviceSampleFifo) {
77  qDebug("BasebandSampleSource::setDeviceSampleSourceFifo: disconnect device FIFO %p", m_deviceSampleFifo);
78  disconnect(m_deviceSampleFifo, SIGNAL(dataWrite(int)), this, SLOT(handleWriteToDeviceFifo(int)));
79  }
80 
81  if (deviceSampleFifo) {
82  qDebug("BasebandSampleSource::setDeviceSampleSourceFifo: connect device FIFO %p", deviceSampleFifo);
83  connect(deviceSampleFifo, SIGNAL(dataWrite(int)), this, SLOT(handleWriteToDeviceFifo(int)));
84  }
85 
86  m_deviceSampleFifo = deviceSampleFifo;
87  }
88 }
void handleWriteToDeviceFifo(int nbSamples)
virtual void pullAudio(int nbSamples)
Message * pop()
Pop message from queue.
virtual bool handleMessage(const Message &cmd)=0
Processing of a message. Returns true if message has actually been processed.
void bumpIndex(SampleVector::iterator &writeAt)
copy current item to second buffer and bump write index - write phase 2
void handleWriteToFifo(SampleSourceFifo *sampleFifo, int nbSamples)
virtual void pull(Sample &sample)=0
int32_t i
Definition: decimators.h:244
SampleSourceFifo * m_deviceSampleFifo
Reference to the device FIFO for single channel processing.
SampleSourceFifo m_sampleFifo
Internal FIFO for multi-channel processing.
void setDeviceSampleSourceFifo(SampleSourceFifo *deviceSampleFifo)
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
void getWriteIterator(SampleVector::iterator &writeAt)
get iterator to current item for update - write phase 1