1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-01 21:54:55 -04:00

SampleSourceFifo refactoring and Tx code reorganization

This commit is contained in:
f4exb
2019-11-15 01:04:24 +01:00
parent 246ff824af
commit 3b74153ec6
198 changed files with 13267 additions and 7750 deletions
@@ -20,7 +20,7 @@
#include <thread>
#include "xtrx/devicextrx.h"
#include "dsp/samplesourcefifodb.h"
#include "dsp/samplesourcefifo.h"
#include "xtrxoutputthread.h"
@@ -94,14 +94,14 @@ unsigned int XTRXOutputThread::getLog2Interpolation(unsigned int channel) const
}
}
void XTRXOutputThread::setFifo(unsigned int channel, SampleSourceFifoDB *sampleFifo)
void XTRXOutputThread::setFifo(unsigned int channel, SampleSourceFifo *sampleFifo)
{
if (channel < 2) {
m_channels[channel].m_sampleFifo = sampleFifo;
}
}
SampleSourceFifoDB *XTRXOutputThread::getFifo(unsigned int channel)
SampleSourceFifo *XTRXOutputThread::getFifo(unsigned int channel)
{
if (channel < 2) {
return m_channels[channel].m_sampleFifo;
@@ -222,56 +222,40 @@ void XTRXOutputThread::run()
m_running = false;
}
void XTRXOutputThread::callback(qint16* buf, qint32 len)
void XTRXOutputThread::callbackPart(qint16* buf, SampleVector& data, unsigned int iBegin, unsigned int iEnd)
{
if (m_channels[m_uniqueChannelIndex].m_sampleFifo)
SampleVector::iterator beginRead = data.begin() + iBegin;
int len = 2*(iEnd - iBegin)*(1<<m_channels[m_uniqueChannelIndex].m_log2Interp);
if (m_channels[m_uniqueChannelIndex].m_log2Interp == 0)
{
float bal = m_channels[m_uniqueChannelIndex].m_sampleFifo->getRWBalance();
if (bal < -0.25) {
qDebug("XTRXOutputThread::callbackSO: read lags: %f", bal);
} else if (bal > 0.25) {
qDebug("XTRXOutputThread::callbackSO: read leads: %f", bal);
}
SampleVector::iterator beginRead;
m_channels[m_uniqueChannelIndex].m_sampleFifo->readAdvance(beginRead, len/(1<<m_channels[m_uniqueChannelIndex].m_log2Interp));
beginRead -= len/(1<<m_channels[m_uniqueChannelIndex].m_log2Interp);
if (m_channels[m_uniqueChannelIndex].m_log2Interp == 0)
{
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate1(&beginRead, buf, len*2);
}
else
{
switch (m_channels[m_uniqueChannelIndex].m_log2Interp)
{
case 1:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate2_cen(&beginRead, buf, len*2);
break;
case 2:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate4_cen(&beginRead, buf, len*2);
break;
case 3:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate8_cen(&beginRead, buf, len*2);
break;
case 4:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate16_cen(&beginRead, buf, len*2);
break;
case 5:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate32_cen(&beginRead, buf, len*2);
break;
case 6:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate64_cen(&beginRead, buf, len*2);
break;
default:
break;
}
}
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate1(&beginRead, buf, len*2);
}
else
{
std::fill(buf, buf+2*len, 0);
switch (m_channels[m_uniqueChannelIndex].m_log2Interp)
{
case 1:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate2_cen(&beginRead, buf, len*2);
break;
case 2:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate4_cen(&beginRead, buf, len*2);
break;
case 3:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate8_cen(&beginRead, buf, len*2);
break;
case 4:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate16_cen(&beginRead, buf, len*2);
break;
case 5:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate32_cen(&beginRead, buf, len*2);
break;
case 6:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate64_cen(&beginRead, buf, len*2);
break;
default:
break;
}
}
}
@@ -279,47 +263,18 @@ void XTRXOutputThread::callbackSO(qint16* buf, qint32 len)
{
if (m_channels[m_uniqueChannelIndex].m_sampleFifo)
{
float bal = m_channels[m_uniqueChannelIndex].m_sampleFifo->getRWBalance();
SampleVector& data = m_channels[m_uniqueChannelIndex].m_sampleFifo->getData();
unsigned int iPart1Begin, iPart1End, iPart2Begin, iPart2End;
m_channels[m_uniqueChannelIndex].m_sampleFifo->read(len/(1<<m_channels[m_uniqueChannelIndex].m_log2Interp), iPart1Begin, iPart1End, iPart2Begin, iPart2End);
if (bal < -0.25) {
qDebug("XTRXOutputThread::callbackSO: read lags: %f", bal);
} else if (bal > 0.25) {
qDebug("XTRXOutputThread::callbackSO: read leads: %f", bal);
if (iPart1Begin != iPart1End) {
callbackPart(buf, data, iPart1Begin, iPart1End);
}
SampleVector::iterator beginRead;
m_channels[m_uniqueChannelIndex].m_sampleFifo->readAdvance(beginRead, len/(1<<m_channels[m_uniqueChannelIndex].m_log2Interp));
beginRead -= len/(1<<m_channels[m_uniqueChannelIndex].m_log2Interp);
unsigned int shift = (iPart1End - iPart1Begin)*(1<<m_channels[m_uniqueChannelIndex].m_log2Interp);
if (m_channels[m_uniqueChannelIndex].m_log2Interp == 0)
{
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate1(&beginRead, buf, len*2);
}
else
{
switch (m_channels[m_uniqueChannelIndex].m_log2Interp)
{
case 1:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate2_cen(&beginRead, buf, len*2);
break;
case 2:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate4_cen(&beginRead, buf, len*2);
break;
case 3:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate8_cen(&beginRead, buf, len*2);
break;
case 4:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate16_cen(&beginRead, buf, len*2);
break;
case 5:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate32_cen(&beginRead, buf, len*2);
break;
case 6:
m_channels[m_uniqueChannelIndex].m_interpolators.interpolate64_cen(&beginRead, buf, len*2);
break;
default:
break;
}
if (iPart2Begin != iPart2End) {
callbackPart(buf + 2*shift, data, iPart2Begin, iPart2End);
}
}
else