2014-05-18 15:52:39 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2015-08-12 07:03:02 +00:00
|
|
|
// Copyright (C) 2015 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
2014-05-18 15:52:39 +00: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-15 02:05:19 +00:00
|
|
|
#include <QGlobalStatic>
|
|
|
|
#include <QThread>
|
2014-05-18 15:52:39 +00:00
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
|
2015-10-15 02:05:19 +00:00
|
|
|
DSPEngine::DSPEngine() :
|
2016-05-13 07:23:33 +00:00
|
|
|
m_deviceEnginesUIDSequence(0),
|
2016-05-18 09:32:19 +00:00
|
|
|
m_audioSampleRate(48000) // Use default output device at 48 kHz
|
2014-05-18 15:52:39 +00:00
|
|
|
{
|
2016-05-08 23:26:39 +00:00
|
|
|
m_dvSerialSupport = false;
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DSPEngine::~DSPEngine()
|
|
|
|
{
|
2016-10-03 16:29:05 +00:00
|
|
|
std::vector<DSPDeviceSourceEngine*>::iterator it = m_deviceEngines.begin();
|
2016-05-11 09:34:44 +00:00
|
|
|
|
|
|
|
while (it != m_deviceEngines.end())
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
++it;
|
|
|
|
}
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2015-08-09 02:09:05 +00:00
|
|
|
Q_GLOBAL_STATIC(DSPEngine, dspEngine)
|
|
|
|
DSPEngine *DSPEngine::instance()
|
|
|
|
{
|
|
|
|
return dspEngine;
|
|
|
|
}
|
|
|
|
|
2016-10-03 16:29:05 +00:00
|
|
|
DSPDeviceSourceEngine *DSPEngine::addDeviceEngine()
|
2016-05-13 07:23:33 +00:00
|
|
|
{
|
2016-10-03 16:29:05 +00:00
|
|
|
m_deviceEngines.push_back(new DSPDeviceSourceEngine(m_deviceEnginesUIDSequence));
|
2016-05-13 07:23:33 +00:00
|
|
|
m_deviceEnginesUIDSequence++;
|
|
|
|
return m_deviceEngines.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPEngine::removeLastDeviceEngine()
|
|
|
|
{
|
|
|
|
if (m_deviceEngines.size() > 0)
|
|
|
|
{
|
2016-10-03 16:29:05 +00:00
|
|
|
DSPDeviceSourceEngine *lastDeviceEngine = m_deviceEngines.back();
|
2016-05-13 07:23:33 +00:00
|
|
|
delete lastDeviceEngine;
|
|
|
|
m_deviceEngines.pop_back();
|
2016-05-13 09:42:03 +00:00
|
|
|
m_deviceEnginesUIDSequence--;
|
2016-05-13 07:23:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 22:35:39 +00:00
|
|
|
void DSPEngine::stopAllAcquisitions()
|
2015-08-12 07:03:02 +00:00
|
|
|
{
|
2016-10-03 16:29:05 +00:00
|
|
|
std::vector<DSPDeviceSourceEngine*>::iterator it = m_deviceEngines.begin();
|
2016-05-11 22:35:39 +00:00
|
|
|
|
|
|
|
while (it != m_deviceEngines.end())
|
|
|
|
{
|
|
|
|
(*it)->stopAcquistion();
|
2016-05-11 23:04:40 +00:00
|
|
|
stopAudio();
|
2016-05-11 22:35:39 +00:00
|
|
|
++it;
|
|
|
|
}
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 22:35:39 +00:00
|
|
|
void DSPEngine::stopAllDeviceEngines()
|
2014-05-18 15:52:39 +00:00
|
|
|
{
|
2016-10-03 16:29:05 +00:00
|
|
|
std::vector<DSPDeviceSourceEngine*>::iterator it = m_deviceEngines.begin();
|
2015-10-15 02:05:19 +00:00
|
|
|
|
2016-05-11 22:35:39 +00:00
|
|
|
while (it != m_deviceEngines.end())
|
|
|
|
{
|
|
|
|
(*it)->stop();
|
|
|
|
++it;
|
|
|
|
}
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:35:16 +00:00
|
|
|
void DSPEngine::startAudio()
|
|
|
|
{
|
2016-05-18 09:32:19 +00:00
|
|
|
m_audioOutput.start(-1, m_audioSampleRate);
|
|
|
|
m_audioSampleRate = m_audioOutput.getRate(); // update with actual rate
|
2016-05-11 21:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPEngine::stopAudio()
|
|
|
|
{
|
2016-05-18 09:32:19 +00:00
|
|
|
m_audioOutput.stop();
|
2016-05-11 21:35:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 08:51:42 +00:00
|
|
|
void DSPEngine::startAudioImmediate()
|
|
|
|
{
|
|
|
|
m_audioOutput.start(-1, m_audioSampleRate);
|
|
|
|
m_audioSampleRate = m_audioOutput.getRate(); // update with actual rate
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPEngine::stopAudioImmediate()
|
|
|
|
{
|
|
|
|
m_audioOutput.stop();
|
|
|
|
}
|
|
|
|
|
2015-08-12 07:03:02 +00:00
|
|
|
void DSPEngine::addAudioSink(AudioFifo* audioFifo)
|
2014-05-18 15:52:39 +00:00
|
|
|
{
|
2015-10-15 02:05:19 +00:00
|
|
|
qDebug("DSPEngine::addAudioSink");
|
|
|
|
m_audioOutput.addFifo(audioFifo);
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 07:03:02 +00:00
|
|
|
void DSPEngine::removeAudioSink(AudioFifo* audioFifo)
|
2014-05-18 15:52:39 +00:00
|
|
|
{
|
2015-10-15 02:05:19 +00:00
|
|
|
qDebug("DSPEngine::removeAudioSink");
|
|
|
|
m_audioOutput.removeFifo(audioFifo);
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 16:29:05 +00:00
|
|
|
DSPDeviceSourceEngine *DSPEngine::getDeviceEngineByUID(uint uid)
|
2016-05-11 17:14:23 +00:00
|
|
|
{
|
2016-10-03 16:29:05 +00:00
|
|
|
std::vector<DSPDeviceSourceEngine*>::iterator it = m_deviceEngines.begin();
|
2016-05-11 17:14:23 +00:00
|
|
|
|
|
|
|
while (it != m_deviceEngines.end())
|
|
|
|
{
|
|
|
|
if ((*it)->getUID() == uid)
|
|
|
|
{
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-08 04:00:37 +00: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
|
|
|
|
}
|