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.
bladerf1outputthread.cpp
Go to the documentation of this file.
1 // Copyright (C) 2015 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 #include "bladerf1outputthread.h"
19 
20 #include <stdio.h>
21 #include <errno.h>
22 #include <algorithm>
23 
24 
25 
26 Bladerf1OutputThread::Bladerf1OutputThread(struct bladerf* dev, SampleSourceFifo* sampleFifo, QObject* parent) :
27  QThread(parent),
28  m_running(false),
29  m_dev(dev),
30  m_sampleFifo(sampleFifo),
31  m_log2Interp(0)
32 {
33  std::fill(m_buf, m_buf + 2*BLADERFOUTPUT_BLOCKSIZE, 0);
34 }
35 
37 {
38  stopWork();
39 }
40 
42 {
43  m_startWaitMutex.lock();
44  start();
45  while(!m_running)
46  m_startWaiter.wait(&m_startWaitMutex, 100);
47  m_startWaitMutex.unlock();
48 }
49 
51 {
52  m_running = false;
53  wait();
54 }
55 
56 void Bladerf1OutputThread::setLog2Interpolation(unsigned int log2_interp)
57 {
58  m_log2Interp = log2_interp;
59 }
60 
62 {
63  int res;
64 
65  m_running = true;
66  m_startWaiter.wakeAll();
67 
68  while (m_running)
69  {
71 
72  if((res = bladerf_sync_tx(m_dev, m_buf, BLADERFOUTPUT_BLOCKSIZE, NULL, 10000)) < 0)
73  {
74  qCritical("BladerdOutputThread:run: sync error: %s", strerror(errno));
75  break;
76  }
77  }
78 
79  m_running = false;
80 }
81 
82 // Interpolate according to specified log2 (ex: log2=4 => decim=16)
83 void Bladerf1OutputThread::callback(qint16* buf, qint32 len)
84 {
85  SampleVector::iterator beginRead;
86  m_sampleFifo->readAdvance(beginRead, len/(1<<m_log2Interp));
87  beginRead -= len;
88 
89  if (m_log2Interp == 0)
90  {
91  m_interpolators.interpolate1(&beginRead, buf, len*2);
92  }
93  else
94  {
95  switch (m_log2Interp)
96  {
97  case 1:
98  m_interpolators.interpolate2_cen(&beginRead, buf, len*2, true);
99  break;
100  case 2:
101  m_interpolators.interpolate4_cen(&beginRead, buf, len*2, true);
102  break;
103  case 3:
104  m_interpolators.interpolate8_cen(&beginRead, buf, len*2, true);
105  break;
106  case 4:
107  m_interpolators.interpolate16_cen(&beginRead, buf, len*2, true);
108  break;
109  case 5:
110  m_interpolators.interpolate32_cen(&beginRead, buf, len*2, true);
111  break;
112  case 6:
113  m_interpolators.interpolate64_cen(&beginRead, buf, len*2, true);
114  break;
115  default:
116  break;
117  }
118  }
119 }
QWaitCondition m_startWaiter
#define BLADERFOUTPUT_BLOCKSIZE
qint16 m_buf[2 *BLADERFOUTPUT_BLOCKSIZE]
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)
SampleSourceFifo * m_sampleFifo
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 setLog2Interpolation(unsigned int log2_interp)
Bladerf1OutputThread(struct bladerf *dev, SampleSourceFifo *sampleFifo, QObject *parent=NULL)
void readAdvance(SampleVector::iterator &readUntil, unsigned int nbSamples)
void interpolate1(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
Interpolators< qint16, SDR_TX_SAMP_SZ, 12 > m_interpolators
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)
void callback(qint16 *buf, qint32 len)