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

#include <plutosdroutputthread.h>

+ Inheritance diagram for PlutoSDROutputThread:
+ Collaboration diagram for PlutoSDROutputThread:

Public Member Functions

 PlutoSDROutputThread (uint32_t blocksize, DevicePlutoSDRBox *plutoBox, SampleSourceFifo *sampleFifo, QObject *parent=0)
 
 ~PlutoSDROutputThread ()
 
virtual void startWork ()
 
virtual void stopWork ()
 
virtual void setDeviceSampleRate (int sampleRate)
 
virtual bool isRunning ()
 
void setLog2Interpolation (unsigned int log2_interp)
 

Private Member Functions

void run ()
 
void convert (qint16 *buf, qint32 len)
 

Private Attributes

QMutex m_startWaitMutex
 
QWaitCondition m_startWaiter
 
bool m_running
 
DevicePlutoSDRBoxm_plutoBox
 
int16_tm_buf
 holds I+Q values of each sample from devce More...
 
uint32_t m_blockSizeSamples
 buffer sizes in number of (I,Q) samples More...
 
SampleSourceFifom_sampleFifo
 DSP sample FIFO (I,Q) More...
 
unsigned int m_log2Interp
 
Interpolators< qint16, SDR_TX_SAMP_SZ, 16 > m_interpolators
 Pluto is on 12 bit but iio_channel_convert_inverse converts from 16 to 12 bits. More...
 

Detailed Description

Definition at line 31 of file plutosdroutputthread.h.

Constructor & Destructor Documentation

◆ PlutoSDROutputThread()

PlutoSDROutputThread::PlutoSDROutputThread ( uint32_t  blocksize,
DevicePlutoSDRBox plutoBox,
SampleSourceFifo sampleFifo,
QObject *  parent = 0 
)

Definition at line 23 of file plutosdroutputthread.cpp.

References m_buf.

23  :
24  QThread(parent),
25  m_running(false),
26  m_plutoBox(plutoBox),
27  m_blockSizeSamples(blocksizeSamples),
28  m_sampleFifo(sampleFifo),
29  m_log2Interp(0)
30 {
31  m_buf = new qint16[blocksizeSamples*2];
32 // m_bufConv = new qint16[blocksizeSamples*(sizeof(Sample)/sizeof(qint16))];
33 }
DevicePlutoSDRBox * m_plutoBox
int16_t * m_buf
holds I+Q values of each sample from devce
uint32_t m_blockSizeSamples
buffer sizes in number of (I,Q) samples
SampleSourceFifo * m_sampleFifo
DSP sample FIFO (I,Q)

◆ ~PlutoSDROutputThread()

PlutoSDROutputThread::~PlutoSDROutputThread ( )

Definition at line 35 of file plutosdroutputthread.cpp.

References m_buf, and stopWork().

36 {
37  stopWork();
38  delete[] m_buf;
39 }
int16_t * m_buf
holds I+Q values of each sample from devce
+ Here is the call graph for this function:

Member Function Documentation

◆ convert()

void PlutoSDROutputThread::convert ( qint16 *  buf,
qint32  len 
)
private

Definition at line 115 of file plutosdroutputthread.cpp.

References Interpolators< T, SdrBits, OutputBits >::interpolate1(), Interpolators< T, SdrBits, OutputBits >::interpolate16_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate2_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate32_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate4_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate64_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate8_cen(), m_interpolators, m_log2Interp, m_sampleFifo, and SampleSourceFifo::readAdvance().

Referenced by run().

116 {
117  // pull samples from baseband generator
118  SampleVector::iterator beginRead;
119  m_sampleFifo->readAdvance(beginRead, len/(2*(1<<m_log2Interp)));
120  beginRead -= len/2;
121 
122  if (m_log2Interp == 0)
123  {
124  m_interpolators.interpolate1(&beginRead, buf, len);
125  }
126  else
127  {
128  switch (m_log2Interp)
129  {
130  case 1:
131  m_interpolators.interpolate2_cen(&beginRead, buf, len);
132  break;
133  case 2:
134  m_interpolators.interpolate4_cen(&beginRead, buf, len);
135  break;
136  case 3:
137  m_interpolators.interpolate8_cen(&beginRead, buf, len);
138  break;
139  case 4:
140  m_interpolators.interpolate16_cen(&beginRead, buf, len);
141  break;
142  case 5:
143  m_interpolators.interpolate32_cen(&beginRead, buf, len);
144  break;
145  case 6:
146  m_interpolators.interpolate64_cen(&beginRead, buf, len);
147  break;
148  default:
149  break;
150  }
151  }
152 }
void interpolate64_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate32_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate8_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate2_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void readAdvance(SampleVector::iterator &readUntil, unsigned int nbSamples)
SampleSourceFifo * m_sampleFifo
DSP sample FIFO (I,Q)
Interpolators< qint16, SDR_TX_SAMP_SZ, 16 > m_interpolators
Pluto is on 12 bit but iio_channel_convert_inverse converts from 16 to 12 bits.
void interpolate1(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate16_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate4_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRunning()

virtual bool PlutoSDROutputThread::isRunning ( )
inlinevirtual

Implements DevicePlutoSDRShared::ThreadInterface.

Definition at line 42 of file plutosdroutputthread.h.

References m_running, and setLog2Interpolation().

Referenced by PlutoSDROutput::applySettings().

42 { return m_running; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void PlutoSDROutputThread::run ( )
private

Definition at line 65 of file plutosdroutputthread.cpp.

References convert(), DevicePlutoSDRBox::getRxSampleSize(), DevicePlutoSDRBox::getTxSampleSize(), m_blockSizeSamples, m_buf, m_plutoBox, m_running, m_startWaiter, DevicePlutoSDRBox::txBufferEnd(), DevicePlutoSDRBox::txBufferFirst(), DevicePlutoSDRBox::txBufferPush(), DevicePlutoSDRBox::txBufferStep(), and DevicePlutoSDRBox::txChannelConvert().

66 {
67  std::ptrdiff_t p_inc = m_plutoBox->txBufferStep();
68 
69  qDebug("PlutoSDROutputThread::run: txBufferStep: %ld bytes", p_inc);
70  qDebug("PlutoSDROutputThread::run: Rx sample size is %ld bytes", m_plutoBox->getRxSampleSize());
71  qDebug("PlutoSDROutputThread::run: Tx sample size is %ld bytes", m_plutoBox->getTxSampleSize());
72  qDebug("PlutoSDROutputThread::run: nominal nbytes_tx is %d bytes", m_blockSizeSamples*4);
73 
74  m_running = true;
75  m_startWaiter.wakeAll();
76 
77  while (m_running)
78  {
79  ssize_t nbytes_tx;
80  char *p_dat, *p_end;
81  int ihs; // half sample index (I then Q to make a sample)
82 
83  convert(m_buf, 2*m_blockSizeSamples); // size given in number of int16_t (I and Q interleaved)
84 
85  // WRITE: Get pointers to TX buf and write IQ to TX buf port 0
86  p_end = m_plutoBox->txBufferEnd();
87  ihs = 0;
88 
89  // p_inc is 2 on a char* buffer therefore each iteration processes only the I or Q sample
90  // I and Q samples are processed one after the other
91  // conversion is not needed as samples are little endian
92 
93  for (p_dat = m_plutoBox->txBufferFirst(), ihs = 0; p_dat < p_end; p_dat += p_inc, ihs += 2)
94  {
95  m_plutoBox->txChannelConvert((int16_t*) p_dat, &m_buf[ihs]);
96  }
97 
98  // Schedule TX buffer for sending
99  nbytes_tx = m_plutoBox->txBufferPush();
100 
101  if (nbytes_tx != 4*m_blockSizeSamples)
102  {
103  qDebug("PlutoSDROutputThread::run: error pushing buf %d / %d", (int) nbytes_tx, (int) 4*m_blockSizeSamples);
104  usleep(200000);
105  continue;
106  }
107  }
108 
109  m_running = false;
110 }
short int16_t
Definition: rtptypes_win.h:43
DevicePlutoSDRBox * m_plutoBox
int16_t * m_buf
holds I+Q values of each sample from devce
uint32_t m_blockSizeSamples
buffer sizes in number of (I,Q) samples
std::ptrdiff_t txBufferStep()
void txChannelConvert(int16_t *dst, int16_t *src)
void convert(qint16 *buf, qint32 len)
QWaitCondition m_startWaiter
+ Here is the call graph for this function:

◆ setDeviceSampleRate()

virtual void PlutoSDROutputThread::setDeviceSampleRate ( int  sampleRate)
inlinevirtual

Implements DevicePlutoSDRShared::ThreadInterface.

Definition at line 41 of file plutosdroutputthread.h.

41 { (void) sampleRate; }

◆ setLog2Interpolation()

void PlutoSDROutputThread::setLog2Interpolation ( unsigned int  log2_interp)

Definition at line 60 of file plutosdroutputthread.cpp.

References m_log2Interp.

Referenced by PlutoSDROutput::applySettings(), isRunning(), and PlutoSDROutput::start().

61 {
62  m_log2Interp = log2_interp;
63 }
+ Here is the caller graph for this function:

◆ startWork()

void PlutoSDROutputThread::startWork ( )
virtual

Implements DevicePlutoSDRShared::ThreadInterface.

Definition at line 41 of file plutosdroutputthread.cpp.

References m_running, m_startWaiter, and m_startWaitMutex.

Referenced by PlutoSDROutput::applySettings(), and PlutoSDROutput::start().

42 {
43  if (m_running) return; // return if running already
44 
45  m_startWaitMutex.lock();
46  start();
47  while(!m_running)
48  m_startWaiter.wait(&m_startWaitMutex, 100);
49  m_startWaitMutex.unlock();
50 }
QWaitCondition m_startWaiter
+ Here is the caller graph for this function:

◆ stopWork()

void PlutoSDROutputThread::stopWork ( )
virtual

Implements DevicePlutoSDRShared::ThreadInterface.

Definition at line 52 of file plutosdroutputthread.cpp.

References m_running.

Referenced by PlutoSDROutput::applySettings(), PlutoSDROutput::stop(), and ~PlutoSDROutputThread().

53 {
54  if (!m_running) return; // return if not running
55 
56  m_running = false;
57  wait();
58 }
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_blockSizeSamples

uint32_t PlutoSDROutputThread::m_blockSizeSamples
private

buffer sizes in number of (I,Q) samples

Definition at line 53 of file plutosdroutputthread.h.

Referenced by run().

◆ m_buf

int16_t* PlutoSDROutputThread::m_buf
private

holds I+Q values of each sample from devce

Definition at line 51 of file plutosdroutputthread.h.

Referenced by PlutoSDROutputThread(), run(), and ~PlutoSDROutputThread().

◆ m_interpolators

Interpolators<qint16, SDR_TX_SAMP_SZ, 16> PlutoSDROutputThread::m_interpolators
private

Pluto is on 12 bit but iio_channel_convert_inverse converts from 16 to 12 bits.

Definition at line 58 of file plutosdroutputthread.h.

Referenced by convert().

◆ m_log2Interp

unsigned int PlutoSDROutputThread::m_log2Interp
private

Definition at line 56 of file plutosdroutputthread.h.

Referenced by convert(), and setLog2Interpolation().

◆ m_plutoBox

DevicePlutoSDRBox* PlutoSDROutputThread::m_plutoBox
private

Definition at line 50 of file plutosdroutputthread.h.

Referenced by run().

◆ m_running

bool PlutoSDROutputThread::m_running
private

Definition at line 48 of file plutosdroutputthread.h.

Referenced by isRunning(), run(), startWork(), and stopWork().

◆ m_sampleFifo

SampleSourceFifo* PlutoSDROutputThread::m_sampleFifo
private

DSP sample FIFO (I,Q)

Definition at line 54 of file plutosdroutputthread.h.

Referenced by convert().

◆ m_startWaiter

QWaitCondition PlutoSDROutputThread::m_startWaiter
private

Definition at line 47 of file plutosdroutputthread.h.

Referenced by run(), and startWork().

◆ m_startWaitMutex

QMutex PlutoSDROutputThread::m_startWaitMutex
private

Definition at line 46 of file plutosdroutputthread.h.

Referenced by startWork().


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