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

#include <samplesourcefifo.h>

Inherits QObject.

Signals

void dataWrite (int nbSamples)
 
void dataRead (int nbSamples)
 

Public Member Functions

 SampleSourceFifo (uint32_t size, QObject *parent=nullptr)
 
 SampleSourceFifo (const SampleSourceFifo &other)
 
 ~SampleSourceFifo ()
 
void resize (uint32_t size)
 
uint32_t size () const
 
void init ()
 
void readAdvance (SampleVector::iterator &readUntil, unsigned int nbSamples)
 
void getReadIterator (SampleVector::iterator &readUntil)
 get iterator past the last sample of a read advance operation (i.e. current read iterator) More...
 
void getWriteIterator (SampleVector::iterator &writeAt)
 get iterator to current item for update - write phase 1 More...
 
void bumpIndex (SampleVector::iterator &writeAt)
 copy current item to second buffer and bump write index - write phase 2 More...
 
int getIteratorOffset (const SampleVector::iterator &iterator)
 
void setIteratorFromOffset (SampleVector::iterator &iterator, int offset)
 
void write (const Sample &sample)
 write directly - phase 1 + phase 2 More...
 
float getRWBalance () const
 

Private Attributes

uint32_t m_size
 
SampleVector m_data
 
uint32_t m_iw
 
uint32_t m_ir
 
bool m_init
 
QMutex m_mutex
 

Detailed Description

Definition at line 28 of file samplesourcefifo.h.

Constructor & Destructor Documentation

◆ SampleSourceFifo() [1/2]

SampleSourceFifo::SampleSourceFifo ( uint32_t  size,
QObject *  parent = nullptr 
)

Definition at line 22 of file samplesourcefifo.cpp.

References init(), m_data, and m_size.

22  :
23  QObject(parent),
24  m_size(size),
25  m_init(false)
26 {
27  m_data.resize(2*m_size);
28  init();
29 }
uint32_t size() const
SampleVector m_data
+ Here is the call graph for this function:

◆ SampleSourceFifo() [2/2]

SampleSourceFifo::SampleSourceFifo ( const SampleSourceFifo other)

Definition at line 31 of file samplesourcefifo.cpp.

References init().

31  :
32  QObject(other.parent()),
33  m_size(other.m_size),
34  m_data(other.m_data)
35 {
36  init();
37 }
SampleVector m_data
+ Here is the call graph for this function:

◆ ~SampleSourceFifo()

SampleSourceFifo::~SampleSourceFifo ( )

Definition at line 39 of file samplesourcefifo.cpp.

40 {}

Member Function Documentation

◆ bumpIndex()

void SampleSourceFifo::bumpIndex ( SampleVector::iterator &  writeAt)

copy current item to second buffer and bump write index - write phase 2

Definition at line 92 of file samplesourcefifo.cpp.

References m_data, m_iw, and m_size.

Referenced by BasebandSampleSource::feed(), BasebandSampleSource::handleWriteToFifo(), and DSPDeviceSinkEngine::work().

93 {
95 
96  {
97 // QMutexLocker mutexLocker(&m_mutex);
98  m_iw = (m_iw+1) % m_size;
99  }
100 
101  writeAt = m_data.begin() + m_iw;
102 }
SampleVector m_data
+ Here is the caller graph for this function:

◆ dataRead

void SampleSourceFifo::dataRead ( int  nbSamples)
signal

Referenced by readAdvance().

+ Here is the caller graph for this function:

◆ dataWrite

void SampleSourceFifo::dataWrite ( int  nbSamples)
signal

Referenced by readAdvance().

+ Here is the caller graph for this function:

◆ getIteratorOffset()

int SampleSourceFifo::getIteratorOffset ( const SampleVector::iterator &  iterator)

Definition at line 104 of file samplesourcefifo.cpp.

References m_data.

Referenced by LocalSourceThread::pullSamples().

105 {
106  return iterator - m_data.begin();
107 }
SampleVector m_data
+ Here is the caller graph for this function:

◆ getReadIterator()

void SampleSourceFifo::getReadIterator ( SampleVector::iterator &  readUntil)

get iterator past the last sample of a read advance operation (i.e. current read iterator)

Definition at line 82 of file samplesourcefifo.cpp.

References m_data, m_ir, and m_size.

Referenced by DSPDeviceSinkEngine::handleForwardToSpectrumSink(), and DSPDeviceMIMOEngine::handleForwardToSpectrumSink().

83 {
84  readUntil = m_data.begin() + m_size + m_ir;
85 }
SampleVector m_data
+ Here is the caller graph for this function:

◆ getRWBalance()

float SampleSourceFifo::getRWBalance ( ) const
inline

returns ratio of off center over buffer size with sign: negative read lags and positive read leads

Definition at line 51 of file samplesourcefifo.h.

Referenced by XTRXOutputThread::callback(), BladeRF2OutputThread::callbackSO(), XTRXOutputThread::callbackSO(), SoapySDROutputThread::callbackSO12(), SoapySDROutputThread::callbackSO16(), SoapySDROutputThread::callbackSO8(), SoapySDROutputThread::callbackSOIF(), and RemoteOutput::webapiFormatDeviceReport().

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  }
+ Here is the caller graph for this function:

◆ getWriteIterator()

void SampleSourceFifo::getWriteIterator ( SampleVector::iterator &  writeAt)

get iterator to current item for update - write phase 1

Definition at line 87 of file samplesourcefifo.cpp.

References m_data, and m_iw.

Referenced by BasebandSampleSource::feed(), BasebandSampleSource::handleWriteToFifo(), and DSPDeviceSinkEngine::work().

88 {
89  writeAt = m_data.begin() + m_iw;
90 }
SampleVector m_data
+ Here is the caller graph for this function:

◆ init()

void SampleSourceFifo::init ( )

Definition at line 51 of file samplesourcefifo.cpp.

References m_data, m_init, m_ir, m_iw, and m_size.

Referenced by resize(), and SampleSourceFifo().

52 {
53  static Sample zero = {0,0};
54  std::fill(m_data.begin(), m_data.end(), zero);
55  m_ir = 0;
56  m_iw = m_size/2;
57  m_init = true;
58 }
SampleVector m_data
+ Here is the caller graph for this function:

◆ readAdvance()

void SampleSourceFifo::readAdvance ( SampleVector::iterator &  readUntil,
unsigned int  nbSamples 
)

advance read pointer for the given length and activate R/W signals

Definition at line 60 of file samplesourcefifo.cpp.

References dataRead(), dataWrite(), m_data, m_ir, and m_size.

Referenced by Bladerf1OutputThread::callback(), HackRFOutputThread::callback(), LimeSDROutputThread::callback(), XTRXOutputThread::callback(), BladeRF2OutputThread::callbackSO(), XTRXOutputThread::callbackSO(), SoapySDROutputThread::callbackSO12(), SoapySDROutputThread::callbackSO16(), SoapySDROutputThread::callbackSO8(), SoapySDROutputThread::callbackSOIF(), PlutoSDROutputThread::convert(), LocalSourceThread::pullSamples(), FileSinkThread::tick(), and RemoteOutputThread::tick().

61 {
62 // QMutexLocker mutexLocker(&m_mutex);
63  assert(nbSamples <= m_size/2);
64  emit dataWrite(nbSamples);
65 
66  m_ir = (m_ir + nbSamples) % m_size;
67  readUntil = m_data.begin() + m_size + m_ir;
68  emit dataRead(nbSamples);
69 }
SampleVector m_data
void dataRead(int nbSamples)
void dataWrite(int nbSamples)
+ Here is the caller graph for this function:

◆ resize()

void SampleSourceFifo::resize ( uint32_t  size)

◆ setIteratorFromOffset()

void SampleSourceFifo::setIteratorFromOffset ( SampleVector::iterator &  iterator,
int  offset 
)

Definition at line 109 of file samplesourcefifo.cpp.

References m_data.

Referenced by LocalSource::processSamples().

110 {
111  iterator = m_data.begin() + offset;
112 }
SampleVector m_data
+ Here is the caller graph for this function:

◆ size()

uint32_t SampleSourceFifo::size ( ) const
inline

Definition at line 37 of file samplesourcefifo.h.

Referenced by resize(), and LocalSource::start().

37 { return m_size; }
+ Here is the caller graph for this function:

◆ write()

void SampleSourceFifo::write ( const Sample sample)

write directly - phase 1 + phase 2

Definition at line 71 of file samplesourcefifo.cpp.

References m_data, m_iw, and m_size.

72 {
73  m_data[m_iw] = sample;
74  m_data[m_iw+m_size] = sample;
75 
76  {
77 // QMutexLocker mutexLocker(&m_mutex);
78  m_iw = (m_iw+1) % m_size;
79  }
80 }
SampleVector m_data

Member Data Documentation

◆ m_data

SampleVector SampleSourceFifo::m_data
private

◆ m_init

bool SampleSourceFifo::m_init
private

Definition at line 67 of file samplesourcefifo.h.

Referenced by init().

◆ m_ir

uint32_t SampleSourceFifo::m_ir
private

Definition at line 66 of file samplesourcefifo.h.

Referenced by getReadIterator(), init(), and readAdvance().

◆ m_iw

uint32_t SampleSourceFifo::m_iw
private

Definition at line 65 of file samplesourcefifo.h.

Referenced by bumpIndex(), getWriteIterator(), init(), and write().

◆ m_mutex

QMutex SampleSourceFifo::m_mutex
private

Definition at line 68 of file samplesourcefifo.h.

◆ m_size

uint32_t SampleSourceFifo::m_size
private

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