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>
|
2016-10-19 12:29:23 +00:00
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
#include "dsp/dspengine.h"
|
2016-10-19 12:29:23 +00:00
|
|
|
#include "dsp/dspdevicesourceengine.h"
|
|
|
|
#include "dsp/dspdevicesinkengine.h"
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2015-10-15 02:05:19 +00:00
|
|
|
DSPEngine::DSPEngine() :
|
2016-10-10 23:11:32 +00:00
|
|
|
m_deviceSourceEnginesUIDSequence(0),
|
2016-10-19 12:29:23 +00:00
|
|
|
m_deviceSinkEnginesUIDSequence(0),
|
2017-01-06 15:04:32 +00:00
|
|
|
m_audioInputDeviceIndex(-1), // default device
|
|
|
|
m_audioOutputDeviceIndex(-1) // default device
|
2014-05-18 15:52:39 +00:00
|
|
|
{
|
2016-05-08 23:26:39 +00:00
|
|
|
m_dvSerialSupport = false;
|
2017-10-24 14:45:47 +00:00
|
|
|
m_masterTimer.start(50);
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DSPEngine::~DSPEngine()
|
|
|
|
{
|
2016-10-10 23:11:32 +00:00
|
|
|
std::vector<DSPDeviceSourceEngine*>::iterator it = m_deviceSourceEngines.begin();
|
2016-05-11 09:34:44 +00:00
|
|
|
|
2016-10-10 23:11:32 +00:00
|
|
|
while (it != m_deviceSourceEngines.end())
|
2016-05-11 09:34:44 +00:00
|
|
|
{
|
|
|
|
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-10 23:11:32 +00:00
|
|
|
DSPDeviceSourceEngine *DSPEngine::addDeviceSourceEngine()
|
2016-05-13 07:23:33 +00:00
|
|
|
{
|
2016-10-10 23:11:32 +00:00
|
|
|
m_deviceSourceEngines.push_back(new DSPDeviceSourceEngine(m_deviceSourceEnginesUIDSequence));
|
|
|
|
m_deviceSourceEnginesUIDSequence++;
|
|
|
|
return m_deviceSourceEngines.back();
|
2016-05-13 07:23:33 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 23:11:32 +00:00
|
|
|
void DSPEngine::removeLastDeviceSourceEngine()
|
2016-05-13 07:23:33 +00:00
|
|
|
{
|
2016-10-10 23:11:32 +00:00
|
|
|
if (m_deviceSourceEngines.size() > 0)
|
2016-05-13 07:23:33 +00:00
|
|
|
{
|
2016-10-10 23:11:32 +00:00
|
|
|
DSPDeviceSourceEngine *lastDeviceEngine = m_deviceSourceEngines.back();
|
2016-05-13 07:23:33 +00:00
|
|
|
delete lastDeviceEngine;
|
2016-10-10 23:11:32 +00:00
|
|
|
m_deviceSourceEngines.pop_back();
|
|
|
|
m_deviceSourceEnginesUIDSequence--;
|
2016-05-11 22:35:39 +00:00
|
|
|
}
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 12:29:23 +00:00
|
|
|
DSPDeviceSinkEngine *DSPEngine::addDeviceSinkEngine()
|
|
|
|
{
|
|
|
|
m_deviceSinkEngines.push_back(new DSPDeviceSinkEngine(m_deviceSinkEnginesUIDSequence));
|
|
|
|
m_deviceSinkEnginesUIDSequence++;
|
|
|
|
return m_deviceSinkEngines.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPEngine::removeLastDeviceSinkEngine()
|
|
|
|
{
|
|
|
|
if (m_deviceSinkEngines.size() > 0)
|
|
|
|
{
|
|
|
|
DSPDeviceSinkEngine *lastDeviceEngine = m_deviceSinkEngines.back();
|
|
|
|
delete lastDeviceEngine;
|
|
|
|
m_deviceSinkEngines.pop_back();
|
|
|
|
m_deviceSinkEnginesUIDSequence--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-10 23:11:32 +00:00
|
|
|
DSPDeviceSourceEngine *DSPEngine::getDeviceSourceEngineByUID(uint uid)
|
2016-05-11 17:14:23 +00:00
|
|
|
{
|
2016-10-10 23:11:32 +00:00
|
|
|
std::vector<DSPDeviceSourceEngine*>::iterator it = m_deviceSourceEngines.begin();
|
2016-05-11 17:14:23 +00:00
|
|
|
|
2016-10-10 23:11:32 +00:00
|
|
|
while (it != m_deviceSourceEngines.end())
|
2016-05-11 17:14:23 +00:00
|
|
|
{
|
|
|
|
if ((*it)->getUID() == uid)
|
|
|
|
{
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-19 12:29:23 +00:00
|
|
|
DSPDeviceSinkEngine *DSPEngine::getDeviceSinkEngineByUID(uint uid)
|
|
|
|
{
|
|
|
|
std::vector<DSPDeviceSinkEngine*>::iterator it = m_deviceSinkEngines.begin();
|
|
|
|
|
|
|
|
while (it != m_deviceSinkEngines.end())
|
|
|
|
{
|
|
|
|
if ((*it)->getUID() == uid)
|
|
|
|
{
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-22 10:01:04 +00:00
|
|
|
#ifdef DSD_USE_SERIALDV
|
2016-05-08 04:00:37 +00:00
|
|
|
void DSPEngine::setDVSerialSupport(bool support)
|
|
|
|
{
|
|
|
|
if (support)
|
|
|
|
{
|
|
|
|
m_dvSerialSupport = m_dvSerialEngine.scan();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dvSerialEngine.release();
|
|
|
|
m_dvSerialSupport = false;
|
|
|
|
}
|
2017-10-22 10:01:04 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void DSPEngine::setDVSerialSupport(bool support __attribute__((unused)))
|
|
|
|
{}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool DSPEngine::hasDVSerialSupport()
|
|
|
|
{
|
|
|
|
#ifdef DSD_USE_SERIALDV
|
|
|
|
return m_dvSerialSupport;
|
|
|
|
#else
|
|
|
|
return false;
|
2016-05-08 04:00:37 +00:00
|
|
|
#endif
|
|
|
|
}
|
2017-10-22 10:01:04 +00:00
|
|
|
|
|
|
|
#ifdef DSD_USE_SERIALDV
|
|
|
|
void DSPEngine::getDVSerialNames(std::vector<std::string>& deviceNames)
|
|
|
|
{
|
|
|
|
m_dvSerialEngine.getDevicesNames(deviceNames);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void DSPEngine::getDVSerialNames(std::vector<std::string>& deviceNames __attribute((unused)))
|
|
|
|
{}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DSD_USE_SERIALDV
|
2017-12-26 19:29:23 +00:00
|
|
|
void DSPEngine::pushMbeFrame(
|
|
|
|
const unsigned char *mbeFrame,
|
|
|
|
int mbeRateIndex,
|
|
|
|
int mbeVolumeIndex,
|
|
|
|
unsigned char channels,
|
|
|
|
bool useHP,
|
2018-04-22 23:04:47 +00:00
|
|
|
int upsampling,
|
2017-12-26 19:29:23 +00:00
|
|
|
AudioFifo *audioFifo)
|
2017-10-22 10:01:04 +00:00
|
|
|
{
|
2018-04-22 23:04:47 +00:00
|
|
|
m_dvSerialEngine.pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, useHP, upsampling, audioFifo);
|
2017-10-22 10:01:04 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void DSPEngine::pushMbeFrame(
|
|
|
|
const unsigned char *mbeFrame __attribute((unused)),
|
|
|
|
int mbeRateIndex __attribute((unused)),
|
|
|
|
int mbeVolumeIndex __attribute((unused)),
|
|
|
|
unsigned char channels __attribute((unused)),
|
2017-12-26 19:29:23 +00:00
|
|
|
bool useHP __attribute((unused)),
|
2018-04-22 23:04:47 +00:00
|
|
|
int upsampling __attribute((unused)),
|
2017-10-22 10:01:04 +00:00
|
|
|
AudioFifo *audioFifo __attribute((unused)))
|
|
|
|
{}
|
|
|
|
#endif
|