2019-12-08 04:09:24 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2019 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// 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 //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// 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 <boost/crc.hpp>
|
|
|
|
#include <boost/cstdint.hpp>
|
|
|
|
#include "dsp/devicesamplesource.h"
|
|
|
|
#include "dsp/hbfilterchainconverter.h"
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
#include "localsinkworker.h"
|
2019-12-08 04:09:24 -05:00
|
|
|
#include "localsinksink.h"
|
|
|
|
|
|
|
|
LocalSinkSink::LocalSinkSink() :
|
2020-07-11 04:37:33 -04:00
|
|
|
m_sinkWorker(nullptr),
|
2019-12-08 04:09:24 -05:00
|
|
|
m_running(false),
|
|
|
|
m_centerFrequency(0),
|
|
|
|
m_frequencyOffset(0),
|
|
|
|
m_sampleRate(48000),
|
|
|
|
m_deviceSampleRate(48000)
|
|
|
|
{
|
2020-06-24 19:14:24 -04:00
|
|
|
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(4000000));
|
2019-12-08 04:09:24 -05:00
|
|
|
applySettings(m_settings, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalSinkSink::~LocalSinkSink()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSinkSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end)
|
|
|
|
{
|
2020-06-24 18:16:01 -04:00
|
|
|
m_sampleFifo.write(begin, end);
|
2019-12-08 04:09:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSinkSink::start(DeviceSampleSource *deviceSource)
|
|
|
|
{
|
|
|
|
qDebug("LocalSinkSink::start");
|
|
|
|
|
|
|
|
if (m_running) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
m_sinkWorker = new LocalSinkWorker();
|
|
|
|
m_sinkWorker->moveToThread(&m_sinkWorkerThread);
|
|
|
|
m_sinkWorker->setSampleFifo(&m_sampleFifo);
|
2019-12-08 04:09:24 -05:00
|
|
|
|
|
|
|
if (deviceSource) {
|
2020-07-11 04:37:33 -04:00
|
|
|
m_sinkWorker->setDeviceSampleFifo(deviceSource->getSampleFifo());
|
2019-12-08 04:09:24 -05:00
|
|
|
}
|
|
|
|
|
2020-06-24 18:16:01 -04:00
|
|
|
QObject::connect(
|
|
|
|
&m_sampleFifo,
|
|
|
|
&SampleSinkFifo::dataReady,
|
2020-07-11 04:37:33 -04:00
|
|
|
m_sinkWorker,
|
|
|
|
&LocalSinkWorker::handleData,
|
2020-06-24 18:16:01 -04:00
|
|
|
Qt::QueuedConnection
|
|
|
|
);
|
2019-12-08 04:09:24 -05:00
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
startWorker();
|
2019-12-08 04:09:24 -05:00
|
|
|
m_running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSinkSink::stop()
|
|
|
|
{
|
|
|
|
qDebug("LocalSinkSink::stop");
|
|
|
|
|
2020-06-24 18:16:01 -04:00
|
|
|
QObject::disconnect(
|
|
|
|
&m_sampleFifo,
|
|
|
|
&SampleSinkFifo::dataReady,
|
2020-07-11 04:37:33 -04:00
|
|
|
m_sinkWorker,
|
|
|
|
&LocalSinkWorker::handleData
|
2020-06-24 18:16:01 -04:00
|
|
|
);
|
2019-12-08 04:09:24 -05:00
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
if (m_sinkWorker != 0)
|
2019-12-08 04:09:24 -05:00
|
|
|
{
|
2020-07-11 04:37:33 -04:00
|
|
|
stopWorker();
|
|
|
|
m_sinkWorker->deleteLater();
|
|
|
|
m_sinkWorker = nullptr;
|
2019-12-08 04:09:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
m_running = false;
|
|
|
|
}
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
void LocalSinkSink::startWorker()
|
|
|
|
{
|
|
|
|
m_sinkWorker->startStop(true);
|
|
|
|
m_sinkWorkerThread.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSinkSink::stopWorker()
|
|
|
|
{
|
|
|
|
m_sinkWorker->startStop(false);
|
|
|
|
m_sinkWorkerThread.quit();
|
|
|
|
m_sinkWorkerThread.wait();
|
|
|
|
}
|
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
void LocalSinkSink::applySettings(const LocalSinkSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "LocalSinkSink::applySettings:"
|
|
|
|
<< " m_localDeviceIndex: " << settings.m_localDeviceIndex
|
|
|
|
<< " m_streamIndex: " << settings.m_streamIndex
|
|
|
|
<< " force: " << force;
|
|
|
|
|
|
|
|
m_settings = settings;
|
|
|
|
}
|
2020-06-26 22:59:40 -04:00
|
|
|
|
|
|
|
void LocalSinkSink::setSampleRate(int sampleRate)
|
|
|
|
{
|
|
|
|
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(sampleRate));
|
|
|
|
}
|