2014-05-18 11:52:39 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2015-08-12 03:03:02 -04:00
|
|
|
// Copyright (C) 2015 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
2014-05-18 11:52:39 -04:00
|
|
|
// //
|
|
|
|
// 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 //
|
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-10-14 22:05:19 -04:00
|
|
|
#include <QGlobalStatic>
|
|
|
|
#include <QThread>
|
2014-05-18 11:52:39 -04:00
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
|
2015-10-14 22:05:19 -04:00
|
|
|
DSPEngine::DSPEngine() :
|
|
|
|
m_audioSampleRate(48000) // Use default output device at 48 kHz
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 13:14:23 -04:00
|
|
|
m_deviceEngines.push_back(new DSPDeviceEngine(0)); // TODO: multi device support
|
2016-05-08 19:26:39 -04:00
|
|
|
m_dvSerialSupport = false;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DSPEngine::~DSPEngine()
|
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
std::vector<DSPDeviceEngine*>::iterator it = m_deviceEngines.begin();
|
|
|
|
|
|
|
|
while (it != m_deviceEngines.end())
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
++it;
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-08 22:09:05 -04:00
|
|
|
Q_GLOBAL_STATIC(DSPEngine, dspEngine)
|
|
|
|
DSPEngine *DSPEngine::instance()
|
|
|
|
{
|
|
|
|
return dspEngine;
|
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
MessageQueue* DSPEngine::getInputMessageQueue(uint deviceIndex)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
return m_deviceEngines[deviceIndex]->getInputMessageQueue();
|
2015-10-14 22:05:19 -04:00
|
|
|
}
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
MessageQueue* DSPEngine::getOutputMessageQueue(uint deviceIndex)
|
2015-10-14 22:05:19 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
return m_deviceEngines[deviceIndex]->getOutputMessageQueue();
|
2015-08-12 03:03:02 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::start(uint deviceIndex)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::start(%d)", deviceIndex);
|
|
|
|
m_deviceEngines[deviceIndex]->start();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::stop(uint deviceIndex)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::stop(%d)", deviceIndex);
|
|
|
|
m_audioOutput.stop(); // FIXME: do not stop here since it is global
|
|
|
|
m_deviceEngines[deviceIndex]->stop();
|
2015-08-12 03:03:02 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
bool DSPEngine::initAcquisition(uint deviceIndex)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::initAcquisition(%d)", deviceIndex);
|
|
|
|
return m_deviceEngines[deviceIndex]->initAcquisition();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
bool DSPEngine::startAcquisition(uint deviceIndex)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::startAcquisition(%d)", deviceIndex);
|
|
|
|
bool started = m_deviceEngines[deviceIndex]->startAcquisition();
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-10-14 22:05:19 -04:00
|
|
|
if (started)
|
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
m_audioOutput.start(-1, m_audioSampleRate); // FIXME: do not start here since it is global
|
2015-10-14 22:05:19 -04:00
|
|
|
m_audioSampleRate = m_audioOutput.getRate(); // update with actual rate
|
|
|
|
}
|
|
|
|
|
|
|
|
return started;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::stopAcquistion(uint deviceIndex)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::stopAcquistion(%d)", deviceIndex);
|
2015-10-14 22:05:19 -04:00
|
|
|
m_audioOutput.stop();
|
2016-05-11 05:34:44 -04:00
|
|
|
m_deviceEngines[deviceIndex]->stopAcquistion();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::setSource(SampleSource* source, uint deviceIndex)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::setSource(%d)", deviceIndex);
|
|
|
|
m_deviceEngines[deviceIndex]->setSource(source);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::setSourceSequence(int sequence, uint deviceIndex)
|
2015-10-03 17:59:02 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::setSource(%d)", deviceIndex);
|
|
|
|
m_deviceEngines[deviceIndex]->setSourceSequence(sequence);
|
2015-10-03 17:59:02 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::addSink(SampleSink* sink, uint deviceIndex)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::setSource(%d)", deviceIndex);
|
|
|
|
m_deviceEngines[deviceIndex]->addSink(sink);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::removeSink(SampleSink* sink, uint deviceIndex)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::removeSink(%d)", deviceIndex);
|
|
|
|
m_deviceEngines[deviceIndex]->removeSink(sink);
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::addThreadedSink(ThreadedSampleSink* sink, uint deviceIndex)
|
2015-08-17 02:29:34 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::addThreadedSink(%d)", deviceIndex);
|
|
|
|
m_deviceEngines[deviceIndex]->addThreadedSink(sink);
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::removeThreadedSink(ThreadedSampleSink* sink, uint deviceIndex)
|
2015-08-17 02:29:34 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::removeThreadedSink(%d)", deviceIndex);
|
|
|
|
m_deviceEngines[deviceIndex]->removeThreadedSink(sink);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
void DSPEngine::addAudioSink(AudioFifo* audioFifo)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-10-14 22:05:19 -04:00
|
|
|
qDebug("DSPEngine::addAudioSink");
|
|
|
|
m_audioOutput.addFifo(audioFifo);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
void DSPEngine::removeAudioSink(AudioFifo* audioFifo)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-10-14 22:05:19 -04:00
|
|
|
qDebug("DSPEngine::removeAudioSink");
|
|
|
|
m_audioOutput.removeFifo(audioFifo);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
void DSPEngine::configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, uint deviceIndex)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
qDebug("DSPEngine::configureCorrections(%d)", deviceIndex);
|
|
|
|
m_deviceEngines[deviceIndex]->configureCorrections(dcOffsetCorrection, iqImbalanceCorrection);
|
2015-08-12 19:14:21 -04:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
DSPDeviceEngine::State DSPEngine::state(uint deviceIndex) const
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
return m_deviceEngines[deviceIndex]->state();
|
2015-08-13 23:00:28 -04:00
|
|
|
}
|
2015-08-12 19:14:21 -04:00
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
QString DSPEngine::errorMessage(uint deviceIndex)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
return m_deviceEngines[deviceIndex]->errorMessage();
|
2015-08-14 03:02:10 -04:00
|
|
|
}
|
2015-08-23 18:51:27 -04:00
|
|
|
|
2016-05-11 13:14:23 -04:00
|
|
|
DSPDeviceEngine *DSPEngine::getDeviceEngineByUID(uint uid)
|
|
|
|
{
|
|
|
|
std::vector<DSPDeviceEngine*>::iterator it = m_deviceEngines.begin();
|
|
|
|
|
|
|
|
while (it != m_deviceEngines.end())
|
|
|
|
{
|
|
|
|
if ((*it)->getUID() == uid)
|
|
|
|
{
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-11 05:34:44 -04:00
|
|
|
QString DSPEngine::sourceDeviceDescription(uint deviceIndex)
|
2015-08-23 18:51:27 -04:00
|
|
|
{
|
2016-05-11 05:34:44 -04:00
|
|
|
return m_deviceEngines[deviceIndex]->sourceDeviceDescription();
|
2015-08-23 18:51:27 -04:00
|
|
|
}
|
2016-05-08 00:00:37 -04:00
|
|
|
|
|
|
|
void DSPEngine::setDVSerialSupport(bool support)
|
|
|
|
{
|
|
|
|
#ifdef DSD_USE_SERIALDV
|
|
|
|
if (support)
|
|
|
|
{
|
|
|
|
m_dvSerialSupport = m_dvSerialEngine.scan();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dvSerialEngine.release();
|
|
|
|
m_dvSerialSupport = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|