2019-05-01 22:02:40 -04: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 "dsp/samplesinkfifo.h"
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
#include "localsinkworker.h"
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(LocalSinkWorker::MsgStartStop, Message)
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
LocalSinkWorker::LocalSinkWorker(QObject* parent) :
|
|
|
|
QObject(parent),
|
2019-05-01 22:02:40 -04:00
|
|
|
m_running(false),
|
|
|
|
m_sampleFifo(0)
|
|
|
|
{
|
|
|
|
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
LocalSinkWorker::~LocalSinkWorker()
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
2020-07-11 04:37:33 -04:00
|
|
|
qDebug("LocalSinkWorker::~LocalSinkWorker");
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
void LocalSinkWorker::startStop(bool start)
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
|
|
|
MsgStartStop *msg = MsgStartStop::create(start);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
}
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
void LocalSinkWorker::startWork()
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
2020-07-11 04:37:33 -04:00
|
|
|
qDebug("LocalSinkWorker::startWork");
|
|
|
|
m_running = true;
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
void LocalSinkWorker::stopWork()
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
|
|
|
m_running = false;
|
|
|
|
}
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
void LocalSinkWorker::handleData()
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
2020-06-24 18:16:01 -04:00
|
|
|
while ((m_sampleFifo->fill() > 0) && (m_inputMessageQueue.size() == 0))
|
|
|
|
{
|
|
|
|
SampleVector::iterator part1begin;
|
|
|
|
SampleVector::iterator part1end;
|
|
|
|
SampleVector::iterator part2begin;
|
|
|
|
SampleVector::iterator part2end;
|
|
|
|
|
|
|
|
std::size_t count = m_sampleFifo->readBegin(m_sampleFifo->fill(), &part1begin, &part1end, &part2begin, &part2end);
|
|
|
|
|
|
|
|
if (m_deviceSampleFifo && m_running)
|
|
|
|
{
|
|
|
|
// first part of FIFO data
|
|
|
|
if (part1begin != part1end) {
|
|
|
|
m_deviceSampleFifo->write(part1begin,part1end);
|
|
|
|
}
|
|
|
|
|
|
|
|
// second part of FIFO data (used when block wraps around)
|
|
|
|
if(part2begin != part2end) {
|
|
|
|
m_deviceSampleFifo->write(part2begin, part2end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sampleFifo->readCommit((unsigned int) count);
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-11 04:37:33 -04:00
|
|
|
void LocalSinkWorker::handleInputMessages()
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = m_inputMessageQueue.pop()) != 0)
|
|
|
|
{
|
|
|
|
if (MsgStartStop::match(*message))
|
|
|
|
{
|
|
|
|
MsgStartStop* notif = (MsgStartStop*) message;
|
2020-07-11 04:37:33 -04:00
|
|
|
qDebug("LocalSinkWorker::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
if (notif->getStartStop()) {
|
|
|
|
startWork();
|
|
|
|
} else {
|
|
|
|
stopWork();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|