2014-05-18 11:52:39 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-19 00:43:20 -05:00
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// written by Christian Daniel //
|
|
|
|
// Copyright (C) 2014 John Greb <hexameron@spam.no> //
|
|
|
|
// Copyright (C) 2015-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
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 //
|
2019-04-11 08:32:15 -04:00
|
|
|
// (at your option) any later version. //
|
2014-05-18 11:52:39 -04: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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-10-14 22:05:19 -04:00
|
|
|
#include <QGlobalStatic>
|
|
|
|
#include <QThread>
|
2016-10-19 08:29:23 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
#include "dsp/dspengine.h"
|
2016-10-19 08:29:23 -04:00
|
|
|
#include "dsp/dspdevicesourceengine.h"
|
|
|
|
#include "dsp/dspdevicesinkengine.h"
|
2019-05-18 05:59:56 -04:00
|
|
|
#include "dsp/dspdevicemimoengine.h"
|
2020-03-12 01:27:38 -04:00
|
|
|
#include "dsp/fftfactory.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-10-14 22:05:19 -04:00
|
|
|
DSPEngine::DSPEngine() :
|
2016-10-10 19:11:32 -04:00
|
|
|
m_deviceSourceEnginesUIDSequence(0),
|
2016-10-19 08:29:23 -04:00
|
|
|
m_deviceSinkEnginesUIDSequence(0),
|
2019-05-18 05:59:56 -04:00
|
|
|
m_deviceMIMOEnginesUIDSequence(0),
|
2017-01-06 10:04:32 -05:00
|
|
|
m_audioInputDeviceIndex(-1), // default device
|
2020-03-12 01:27:38 -04:00
|
|
|
m_audioOutputDeviceIndex(-1), // default device
|
|
|
|
m_fftFactory(nullptr)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-05-08 19:26:39 -04:00
|
|
|
m_dvSerialSupport = false;
|
2019-05-12 04:25:55 -04:00
|
|
|
m_mimoSupport = false;
|
2017-10-24 10:45:47 -04:00
|
|
|
m_masterTimer.start(50);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DSPEngine::~DSPEngine()
|
|
|
|
{
|
2024-08-14 16:08:49 -04:00
|
|
|
auto it = m_deviceSourceEngines.begin();
|
2016-05-11 05:34:44 -04:00
|
|
|
|
2016-10-10 19:11:32 -04:00
|
|
|
while (it != m_deviceSourceEngines.end())
|
2016-05-11 05:34:44 -04:00
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
++it;
|
|
|
|
}
|
2020-03-12 01:27:38 -04:00
|
|
|
|
|
|
|
if (m_fftFactory) {
|
|
|
|
delete m_fftFactory;
|
|
|
|
}
|
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-10-10 19:11:32 -04:00
|
|
|
DSPDeviceSourceEngine *DSPEngine::addDeviceSourceEngine()
|
2016-05-13 03:23:33 -04:00
|
|
|
{
|
2024-08-14 11:24:21 -04:00
|
|
|
auto *deviceSourceEngine = new DSPDeviceSourceEngine(m_deviceSourceEnginesUIDSequence);
|
2024-08-14 16:08:49 -04:00
|
|
|
auto *deviceThread = new QThread();
|
2016-10-10 19:11:32 -04:00
|
|
|
m_deviceSourceEnginesUIDSequence++;
|
2024-08-14 11:24:21 -04:00
|
|
|
m_deviceSourceEngines.push_back(deviceSourceEngine);
|
2024-08-14 16:08:49 -04:00
|
|
|
m_deviceEngineReferences.push_back(DeviceEngineReference{0, m_deviceSourceEngines.back(), nullptr, nullptr, deviceThread});
|
|
|
|
deviceSourceEngine->moveToThread(deviceThread);
|
|
|
|
|
|
|
|
QObject::connect(
|
|
|
|
deviceThread,
|
|
|
|
&QThread::finished,
|
|
|
|
deviceThread,
|
|
|
|
&QThread::deleteLater
|
|
|
|
);
|
|
|
|
|
|
|
|
deviceThread->start();
|
|
|
|
|
2024-08-14 11:24:21 -04:00
|
|
|
return deviceSourceEngine;
|
2016-05-13 03:23:33 -04:00
|
|
|
}
|
|
|
|
|
2016-10-10 19:11:32 -04:00
|
|
|
void DSPEngine::removeLastDeviceSourceEngine()
|
2016-05-13 03:23:33 -04:00
|
|
|
{
|
2024-08-14 16:08:49 -04:00
|
|
|
if (!m_deviceSourceEngines.empty())
|
2016-05-13 03:23:33 -04:00
|
|
|
{
|
2024-08-14 16:08:49 -04:00
|
|
|
const DSPDeviceSourceEngine *lastDeviceEngine = m_deviceSourceEngines.back();
|
2016-10-10 19:11:32 -04:00
|
|
|
m_deviceSourceEngines.pop_back();
|
2022-04-12 10:20:45 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < m_deviceEngineReferences.size(); i++)
|
|
|
|
{
|
2022-04-24 19:18:07 -04:00
|
|
|
if (m_deviceEngineReferences[i].m_deviceSourceEngine == lastDeviceEngine)
|
2022-04-12 10:20:45 -04:00
|
|
|
{
|
2024-08-14 16:08:49 -04:00
|
|
|
QThread* deviceThread = m_deviceEngineReferences[i].m_thread;
|
|
|
|
deviceThread->exit();
|
|
|
|
deviceThread->wait();
|
2022-04-12 10:20:45 -04:00
|
|
|
m_deviceEngineReferences.removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-11 18:35:39 -04:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-10-19 08:29:23 -04:00
|
|
|
DSPDeviceSinkEngine *DSPEngine::addDeviceSinkEngine()
|
|
|
|
{
|
2024-08-18 07:37:27 -04:00
|
|
|
auto *deviceSinkEngine = new DSPDeviceSinkEngine(m_deviceSinkEnginesUIDSequence);
|
|
|
|
auto *deviceThread = new QThread();
|
2016-10-19 08:29:23 -04:00
|
|
|
m_deviceSinkEnginesUIDSequence++;
|
2024-08-18 07:37:27 -04:00
|
|
|
m_deviceSinkEngines.push_back(deviceSinkEngine);
|
|
|
|
m_deviceEngineReferences.push_back(DeviceEngineReference{1, nullptr, m_deviceSinkEngines.back(), nullptr, deviceThread});
|
|
|
|
deviceSinkEngine->moveToThread(deviceThread);
|
|
|
|
|
|
|
|
QObject::connect(
|
|
|
|
deviceThread,
|
|
|
|
&QThread::finished,
|
|
|
|
deviceThread,
|
|
|
|
&QThread::deleteLater
|
|
|
|
);
|
|
|
|
|
|
|
|
deviceThread->start();
|
|
|
|
|
|
|
|
return deviceSinkEngine;
|
2016-10-19 08:29:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPEngine::removeLastDeviceSinkEngine()
|
|
|
|
{
|
2024-08-18 07:37:27 -04:00
|
|
|
if (!m_deviceSinkEngines.empty())
|
2016-10-19 08:29:23 -04:00
|
|
|
{
|
2024-08-18 07:37:27 -04:00
|
|
|
const DSPDeviceSinkEngine *lastDeviceEngine = m_deviceSinkEngines.back();
|
2016-10-19 08:29:23 -04:00
|
|
|
m_deviceSinkEngines.pop_back();
|
2022-04-12 10:20:45 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < m_deviceEngineReferences.size(); i++)
|
|
|
|
{
|
2022-04-24 19:18:07 -04:00
|
|
|
if (m_deviceEngineReferences[i].m_deviceSinkEngine == lastDeviceEngine)
|
2022-04-12 10:20:45 -04:00
|
|
|
{
|
2024-08-18 07:37:27 -04:00
|
|
|
QThread* deviceThread = m_deviceEngineReferences[i].m_thread;
|
|
|
|
deviceThread->exit();
|
|
|
|
deviceThread->wait();
|
2022-04-12 10:20:45 -04:00
|
|
|
m_deviceEngineReferences.removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-19 08:29:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-18 05:59:56 -04:00
|
|
|
DSPDeviceMIMOEngine *DSPEngine::addDeviceMIMOEngine()
|
|
|
|
{
|
2024-08-17 05:24:19 -04:00
|
|
|
auto *deviceMIMOEngine = new DSPDeviceMIMOEngine(m_deviceMIMOEnginesUIDSequence);
|
|
|
|
auto *deviceThread = new QThread();
|
2019-05-18 05:59:56 -04:00
|
|
|
m_deviceMIMOEnginesUIDSequence++;
|
2024-08-17 05:24:19 -04:00
|
|
|
m_deviceMIMOEngines.push_back(deviceMIMOEngine);
|
|
|
|
m_deviceEngineReferences.push_back(DeviceEngineReference{2, nullptr, nullptr, m_deviceMIMOEngines.back(), deviceThread});
|
|
|
|
deviceMIMOEngine->moveToThread(deviceThread);
|
|
|
|
|
|
|
|
QObject::connect(
|
|
|
|
deviceThread,
|
|
|
|
&QThread::finished,
|
|
|
|
deviceThread,
|
|
|
|
&QThread::deleteLater
|
|
|
|
);
|
|
|
|
|
|
|
|
deviceThread->start();
|
|
|
|
|
|
|
|
return deviceMIMOEngine;
|
2019-05-18 05:59:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPEngine::removeLastDeviceMIMOEngine()
|
|
|
|
{
|
2024-08-17 05:24:19 -04:00
|
|
|
if (!m_deviceMIMOEngines.empty())
|
2019-05-18 05:59:56 -04:00
|
|
|
{
|
2024-08-17 05:24:19 -04:00
|
|
|
const DSPDeviceMIMOEngine *lastDeviceEngine = m_deviceMIMOEngines.back();
|
2019-05-18 05:59:56 -04:00
|
|
|
m_deviceMIMOEngines.pop_back();
|
2016-05-11 13:14:23 -04:00
|
|
|
|
2022-04-12 10:20:45 -04:00
|
|
|
for (int i = 0; i < m_deviceEngineReferences.size(); i++)
|
|
|
|
{
|
2022-04-24 19:18:07 -04:00
|
|
|
if (m_deviceEngineReferences[i].m_deviceMIMOEngine == lastDeviceEngine)
|
2022-04-12 10:20:45 -04:00
|
|
|
{
|
2024-08-17 05:24:19 -04:00
|
|
|
QThread* deviceThread = m_deviceEngineReferences[i].m_thread;
|
|
|
|
deviceThread->exit();
|
|
|
|
deviceThread->wait();
|
2022-04-12 10:20:45 -04:00
|
|
|
m_deviceEngineReferences.removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
2016-05-11 13:14:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-10 08:57:11 -04:00
|
|
|
QThread * DSPEngine::removeDeviceEngineAt(int deviceIndex)
|
2016-10-19 08:29:23 -04:00
|
|
|
{
|
2022-04-12 10:20:45 -04:00
|
|
|
if (deviceIndex >= m_deviceEngineReferences.size()) {
|
2024-10-10 08:57:11 -04:00
|
|
|
return nullptr;
|
2022-04-12 10:20:45 -04:00
|
|
|
}
|
2016-10-19 08:29:23 -04:00
|
|
|
|
2024-10-10 08:57:11 -04:00
|
|
|
QThread *deviceThread = nullptr;
|
|
|
|
|
2022-04-24 19:18:07 -04:00
|
|
|
if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 0) // source
|
2016-10-19 08:29:23 -04:00
|
|
|
{
|
2022-04-24 19:18:07 -04:00
|
|
|
DSPDeviceSourceEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSourceEngine;
|
2024-10-10 08:57:11 -04:00
|
|
|
deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
|
2024-08-14 16:08:49 -04:00
|
|
|
deviceThread->exit();
|
2022-04-24 19:18:07 -04:00
|
|
|
m_deviceSourceEngines.removeAll(deviceEngine);
|
2019-05-18 05:59:56 -04:00
|
|
|
}
|
2022-04-24 19:18:07 -04:00
|
|
|
else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 1) // sink
|
2019-05-18 05:59:56 -04:00
|
|
|
{
|
2022-04-24 19:18:07 -04:00
|
|
|
DSPDeviceSinkEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSinkEngine;
|
2024-10-10 08:57:11 -04:00
|
|
|
deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
|
2024-08-18 07:37:27 -04:00
|
|
|
deviceThread->exit();
|
2022-04-24 19:18:07 -04:00
|
|
|
m_deviceSinkEngines.removeAll(deviceEngine);
|
2022-04-12 10:20:45 -04:00
|
|
|
}
|
2022-04-24 19:18:07 -04:00
|
|
|
else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 2) // MIMO
|
2022-04-12 10:20:45 -04:00
|
|
|
{
|
2022-04-24 19:18:07 -04:00
|
|
|
DSPDeviceMIMOEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceMIMOEngine;
|
2024-10-10 08:57:11 -04:00
|
|
|
deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
|
2024-08-17 05:24:19 -04:00
|
|
|
deviceThread->exit();
|
2022-04-24 19:18:07 -04:00
|
|
|
m_deviceMIMOEngines.removeAll(deviceEngine);
|
2016-10-19 08:29:23 -04:00
|
|
|
}
|
|
|
|
|
2022-04-12 10:20:45 -04:00
|
|
|
m_deviceEngineReferences.removeAt(deviceIndex);
|
2024-10-10 08:57:11 -04:00
|
|
|
|
|
|
|
return deviceThread;
|
2016-10-19 08:29:23 -04:00
|
|
|
}
|
|
|
|
|
2020-03-12 01:27:38 -04:00
|
|
|
void DSPEngine::createFFTFactory(const QString& fftWisdomFileName)
|
|
|
|
{
|
|
|
|
m_fftFactory = new FFTFactory(fftWisdomFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPEngine::preAllocateFFTs()
|
|
|
|
{
|
2020-03-15 14:59:56 -04:00
|
|
|
m_fftFactory->preallocate(7, 10, 1, 0); // pre-acllocate forward FFT only 1 per size from 128 to 1024
|
2022-04-12 10:20:45 -04:00
|
|
|
}
|