2015-09-03 01:57:54 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// written by Christian Daniel //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 04:57:41 +00:00
|
|
|
// (at your option) any later version. //
|
2015-09-03 01:57:54 +00:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2018-11-20 00:48:17 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
2016-10-06 17:18:02 +00:00
|
|
|
|
2017-10-22 17:12:43 +00:00
|
|
|
#include "dsp/samplesinkfifo.h"
|
2018-11-20 00:48:17 +00:00
|
|
|
#include "audio/audiofifo.h"
|
|
|
|
|
|
|
|
#include "fcdprothread.h"
|
2015-09-03 01:57:54 +00:00
|
|
|
|
2018-11-20 00:48:17 +00:00
|
|
|
FCDProThread::FCDProThread(SampleSinkFifo* sampleFifo, AudioFifo *fcdFIFO, QObject* parent) :
|
2015-09-03 01:57:54 +00:00
|
|
|
QThread(parent),
|
2018-11-20 00:48:17 +00:00
|
|
|
m_fcdFIFO(fcdFIFO),
|
2015-09-03 01:57:54 +00:00
|
|
|
m_running(false),
|
2019-01-04 23:31:16 +00:00
|
|
|
m_log2Decim(0),
|
|
|
|
m_fcPos(2),
|
2020-11-14 04:51:19 +00:00
|
|
|
m_iqOrder(true),
|
2018-11-20 00:48:17 +00:00
|
|
|
m_convertBuffer(fcd_traits<Pro>::convBufSize), // nb samples
|
2020-11-14 04:51:19 +00:00
|
|
|
m_sampleFifo(sampleFifo)
|
2015-09-03 01:57:54 +00:00
|
|
|
{
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2015-09-04 02:10:38 +00:00
|
|
|
FCDProThread::~FCDProThread()
|
2015-09-03 01:57:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-04 02:10:38 +00:00
|
|
|
void FCDProThread::startWork()
|
2015-09-03 06:39:57 +00:00
|
|
|
{
|
|
|
|
m_startWaitMutex.lock();
|
|
|
|
|
|
|
|
start();
|
|
|
|
|
|
|
|
while(!m_running)
|
|
|
|
{
|
|
|
|
m_startWaiter.wait(&m_startWaitMutex, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_startWaitMutex.unlock();
|
|
|
|
}
|
|
|
|
|
2015-09-04 02:10:38 +00:00
|
|
|
void FCDProThread::stopWork()
|
2015-09-03 01:57:54 +00:00
|
|
|
{
|
|
|
|
m_running = false;
|
|
|
|
wait();
|
|
|
|
}
|
|
|
|
|
2019-01-04 14:12:35 +00:00
|
|
|
void FCDProThread::setLog2Decimation(unsigned int log2_decim)
|
|
|
|
{
|
|
|
|
m_log2Decim = log2_decim;
|
|
|
|
}
|
|
|
|
|
2019-01-04 23:31:16 +00:00
|
|
|
void FCDProThread::setFcPos(int fcPos)
|
|
|
|
{
|
|
|
|
m_fcPos = fcPos;
|
|
|
|
}
|
|
|
|
|
2015-09-04 02:10:38 +00:00
|
|
|
void FCDProThread::run()
|
2015-09-03 01:57:54 +00:00
|
|
|
{
|
2018-11-20 00:48:17 +00:00
|
|
|
m_running = true;
|
|
|
|
qDebug("FCDProThread::run: start running loop");
|
2015-09-03 01:57:54 +00:00
|
|
|
|
2018-11-20 00:48:17 +00:00
|
|
|
while (m_running)
|
|
|
|
{
|
2020-06-21 09:46:08 +00:00
|
|
|
if (m_iqOrder) {
|
|
|
|
workIQ(fcd_traits<Pro>::convBufSize);
|
|
|
|
} else {
|
|
|
|
workQI(fcd_traits<Pro>::convBufSize);
|
|
|
|
}
|
|
|
|
|
2018-11-20 00:48:17 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(200));
|
|
|
|
}
|
2015-09-03 01:57:54 +00:00
|
|
|
|
2018-11-20 00:48:17 +00:00
|
|
|
qDebug("FCDProThread::run: running loop stopped");
|
|
|
|
m_running = false;
|
2015-09-03 01:57:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 09:46:08 +00:00
|
|
|
void FCDProThread::workIQ(unsigned int n_items)
|
|
|
|
{
|
|
|
|
uint32_t nbRead = m_fcdFIFO->read((unsigned char *) m_buf, n_items); // number of samples
|
|
|
|
SampleVector::iterator it = m_convertBuffer.begin();
|
|
|
|
|
|
|
|
if (m_log2Decim == 0)
|
|
|
|
{
|
|
|
|
m_decimatorsIQ.decimate1(&it, m_buf, 2*nbRead);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_fcPos == 0) // Infradyne
|
|
|
|
{
|
|
|
|
switch (m_log2Decim)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
m_decimatorsIQ.decimate2_inf(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
m_decimatorsIQ.decimate4_inf(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
m_decimatorsIQ.decimate8_inf(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
m_decimatorsIQ.decimate16_inf(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
m_decimatorsIQ.decimate32_inf(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
m_decimatorsIQ.decimate64_inf(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (m_fcPos == 1) // Supradyne
|
|
|
|
{
|
|
|
|
switch (m_log2Decim)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
m_decimatorsIQ.decimate2_sup(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
m_decimatorsIQ.decimate4_sup(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
m_decimatorsIQ.decimate8_sup(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
m_decimatorsIQ.decimate16_sup(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
m_decimatorsIQ.decimate32_sup(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
m_decimatorsIQ.decimate64_sup(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Centered
|
|
|
|
{
|
|
|
|
switch (m_log2Decim)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
m_decimatorsIQ.decimate2_cen(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
m_decimatorsIQ.decimate4_cen(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
m_decimatorsIQ.decimate8_cen(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
m_decimatorsIQ.decimate16_cen(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
m_decimatorsIQ.decimate32_cen(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
m_decimatorsIQ.decimate64_cen(&it, m_buf, 2*nbRead);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FCDProThread::workQI(unsigned int n_items)
|
2015-09-03 01:57:54 +00:00
|
|
|
{
|
2018-11-20 00:48:17 +00:00
|
|
|
uint32_t nbRead = m_fcdFIFO->read((unsigned char *) m_buf, n_items); // number of samples
|
|
|
|
SampleVector::iterator it = m_convertBuffer.begin();
|
2019-01-04 14:12:35 +00:00
|
|
|
|
2019-01-04 23:31:16 +00:00
|
|
|
if (m_log2Decim == 0)
|
|
|
|
{
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate1(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
}
|
|
|
|
else
|
2019-01-04 14:12:35 +00:00
|
|
|
{
|
2019-01-04 23:31:16 +00:00
|
|
|
if (m_fcPos == 0) // Infradyne
|
|
|
|
{
|
|
|
|
switch (m_log2Decim)
|
|
|
|
{
|
|
|
|
case 1:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate2_inf(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate4_inf(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate8_inf(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate16_inf(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate32_inf(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate64_inf(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (m_fcPos == 1) // Supradyne
|
|
|
|
{
|
|
|
|
switch (m_log2Decim)
|
|
|
|
{
|
|
|
|
case 1:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate2_sup(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate4_sup(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate8_sup(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate16_sup(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate32_sup(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate64_sup(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Centered
|
|
|
|
{
|
|
|
|
switch (m_log2Decim)
|
|
|
|
{
|
|
|
|
case 1:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate2_cen(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate4_cen(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate8_cen(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate16_cen(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate32_cen(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2020-06-21 09:46:08 +00:00
|
|
|
m_decimatorsQI.decimate64_cen(&it, m_buf, 2*nbRead);
|
2019-01-04 23:31:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-01-04 14:12:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 00:48:17 +00:00
|
|
|
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
2015-09-03 01:57:54 +00:00
|
|
|
}
|