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.
samplesourcefifo.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 SDRBASE_DSP_SAMPLESOURCEFIFO_H_
19 #define SDRBASE_DSP_SAMPLESOURCEFIFO_H_
20 
21 #include <QObject>
22 #include <QMutex>
23 #include <stdint.h>
24 #include <assert.h>
25 #include "export.h"
26 #include "dsp/dsptypes.h"
27 
28 class SDRBASE_API SampleSourceFifo : public QObject {
29  Q_OBJECT
30 
31 public:
32  SampleSourceFifo(uint32_t size, QObject* parent = nullptr);
33  SampleSourceFifo(const SampleSourceFifo& other);
35 
36  void resize(uint32_t size);
37  uint32_t size() const { return m_size; }
38  void init();
40  void readAdvance(SampleVector::iterator& readUntil, unsigned int nbSamples);
41 
42  void getReadIterator(SampleVector::iterator& readUntil);
43  void getWriteIterator(SampleVector::iterator& writeAt);
44  void bumpIndex(SampleVector::iterator& writeAt);
45  int getIteratorOffset(const SampleVector::iterator& iterator);
46  void setIteratorFromOffset(SampleVector::iterator& iterator, int offset);
47 
48  void write(const Sample& sample);
49 
51  float getRWBalance() const
52  {
53  int delta;
54  if (m_iw > m_ir) {
55  delta = (m_size/2) - (m_iw - m_ir);
56  } else {
57  delta = (m_ir - m_iw) - (m_size/2);
58  }
59  return delta / (float) m_size;
60  }
61 
62 private:
67  bool m_init;
68  QMutex m_mutex;
69 
70 signals:
71  void dataWrite(int nbSamples); // signal data is read past a threshold and writing new samples to fill in is needed
72  void dataRead(int nbSamples); // signal a read has been done for a number of samples
73 };
74 
75 #endif /* SDRBASE_DSP_SAMPLESOURCEFIFO_H_ */
uint32_t size() const
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
float getRWBalance() const
SampleVector m_data
unsigned int uint32_t
Definition: rtptypes_win.h:46
#define SDRBASE_API
Definition: export.h:40