| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | // Copyright (C) 2015 F4EXB                                                      //
 | 
					
						
							|  |  |  | // written by Edouard Griffiths                                                  //
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01: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 14:32:15 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01: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-15 04:05:19 +02:00
										 |  |  | #include <QGlobalStatic>
 | 
					
						
							|  |  |  | #include <QThread>
 | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  | #include "dsp/dspdevicesourceengine.h"
 | 
					
						
							|  |  |  | #include "dsp/dspdevicesinkengine.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-18 11:59:56 +02:00
										 |  |  | #include "dsp/dspdevicemimoengine.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-12 06:27:38 +01:00
										 |  |  | #include "dsp/fftfactory.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | DSPEngine::DSPEngine() : | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |     m_deviceSourceEnginesUIDSequence(0), | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  |     m_deviceSinkEnginesUIDSequence(0), | 
					
						
							| 
									
										
										
										
											2019-05-18 11:59:56 +02:00
										 |  |  |     m_deviceMIMOEnginesUIDSequence(0), | 
					
						
							| 
									
										
										
										
											2017-01-06 16:04:32 +01:00
										 |  |  |     m_audioInputDeviceIndex(-1),    // default device
 | 
					
						
							| 
									
										
										
										
											2020-03-12 06:27:38 +01:00
										 |  |  |     m_audioOutputDeviceIndex(-1),   // default device
 | 
					
						
							|  |  |  |     m_fftFactory(nullptr) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-09 01:26:39 +02:00
										 |  |  | 	m_dvSerialSupport = false; | 
					
						
							| 
									
										
										
										
											2019-05-12 10:25:55 +02:00
										 |  |  |     m_mimoSupport = false; | 
					
						
							| 
									
										
										
										
											2017-10-24 16:45:47 +02:00
										 |  |  |     m_masterTimer.start(50); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DSPEngine::~DSPEngine() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     QList<DSPDeviceSourceEngine*>::iterator it = m_deviceSourceEngines.begin(); | 
					
						
							| 
									
										
										
										
											2016-05-11 11:34:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |     while (it != m_deviceSourceEngines.end()) | 
					
						
							| 
									
										
										
										
											2016-05-11 11:34:44 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         delete *it; | 
					
						
							|  |  |  |         ++it; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-12 06:27:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_fftFactory) { | 
					
						
							|  |  |  |         delete m_fftFactory; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-09 04:09:05 +02:00
										 |  |  | Q_GLOBAL_STATIC(DSPEngine, dspEngine) | 
					
						
							|  |  |  | DSPEngine *DSPEngine::instance() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return dspEngine; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  | DSPDeviceSourceEngine *DSPEngine::addDeviceSourceEngine() | 
					
						
							| 
									
										
										
										
											2016-05-13 09:23:33 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |     m_deviceSourceEngines.push_back(new DSPDeviceSourceEngine(m_deviceSourceEnginesUIDSequence)); | 
					
						
							|  |  |  |     m_deviceSourceEnginesUIDSequence++; | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     m_deviceEngineReferences.push_back(DeviceEngineReference{0, m_deviceSourceEngines.size() - 1}); | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |     return m_deviceSourceEngines.back(); | 
					
						
							| 
									
										
										
										
											2016-05-13 09:23:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  | void DSPEngine::removeLastDeviceSourceEngine() | 
					
						
							| 
									
										
										
										
											2016-05-13 09:23:33 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |     if (m_deviceSourceEngines.size() > 0) | 
					
						
							| 
									
										
										
										
											2016-05-13 09:23:33 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |         DSPDeviceSourceEngine *lastDeviceEngine = m_deviceSourceEngines.back(); | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |         int lastSourceDeviceEngineIndex = m_deviceSourceEngines.size() - 1; | 
					
						
							| 
									
										
										
										
											2016-05-13 09:23:33 +02:00
										 |  |  |         delete lastDeviceEngine; | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |         m_deviceSourceEngines.pop_back(); | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i < m_deviceEngineReferences.size(); i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (m_deviceEngineReferences[i].deviceEngineIndex == lastSourceDeviceEngineIndex) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 m_deviceEngineReferences.removeAt(i); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-12 00:35:39 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  | DSPDeviceSinkEngine *DSPEngine::addDeviceSinkEngine() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_deviceSinkEngines.push_back(new DSPDeviceSinkEngine(m_deviceSinkEnginesUIDSequence)); | 
					
						
							|  |  |  |     m_deviceSinkEnginesUIDSequence++; | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     m_deviceEngineReferences.push_back(DeviceEngineReference{1, m_deviceSinkEngines.size() - 1}); | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  |     return m_deviceSinkEngines.back(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::removeLastDeviceSinkEngine() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_deviceSinkEngines.size() > 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DSPDeviceSinkEngine *lastDeviceEngine = m_deviceSinkEngines.back(); | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |         int lastSinkDeviceEngineIndex = m_deviceSinkEngines.size() - 1; | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  |         delete lastDeviceEngine; | 
					
						
							|  |  |  |         m_deviceSinkEngines.pop_back(); | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i < m_deviceEngineReferences.size(); i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (m_deviceEngineReferences[i].deviceEngineIndex == lastSinkDeviceEngineIndex) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 m_deviceEngineReferences.removeAt(i); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-18 11:59:56 +02:00
										 |  |  | DSPDeviceMIMOEngine *DSPEngine::addDeviceMIMOEngine() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_deviceMIMOEngines.push_back(new DSPDeviceMIMOEngine(m_deviceMIMOEnginesUIDSequence)); | 
					
						
							|  |  |  |     m_deviceMIMOEnginesUIDSequence++; | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     m_deviceEngineReferences.push_back(DeviceEngineReference{2, m_deviceMIMOEngines.size() - 1}); | 
					
						
							| 
									
										
										
										
											2019-05-18 11:59:56 +02:00
										 |  |  |     return m_deviceMIMOEngines.back(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::removeLastDeviceMIMOEngine() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_deviceMIMOEngines.size() > 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DSPDeviceMIMOEngine *lastDeviceEngine = m_deviceMIMOEngines.back(); | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |         int lastMIMODeviceEngineIndex = m_deviceMIMOEngines.size() - 1; | 
					
						
							| 
									
										
										
										
											2019-05-18 11:59:56 +02:00
										 |  |  |         delete lastDeviceEngine; | 
					
						
							|  |  |  |         m_deviceMIMOEngines.pop_back(); | 
					
						
							| 
									
										
										
										
											2016-05-11 19:14:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |         for (int i = 0; i < m_deviceEngineReferences.size(); i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (m_deviceEngineReferences[i].deviceEngineIndex == lastMIMODeviceEngineIndex) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 m_deviceEngineReferences.removeAt(i); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-05-11 19:14:23 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  | void DSPEngine::removeDeviceEngineAt(int deviceIndex) | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     if (deviceIndex >= m_deviceEngineReferences.size()) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     if (m_deviceEngineReferences[deviceIndex].deviceEngineTYpe == 0) // source
 | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |         DSPDeviceSourceEngine *deviceEngine = m_deviceSourceEngines[m_deviceEngineReferences[deviceIndex].deviceEngineIndex]; | 
					
						
							|  |  |  |         delete deviceEngine; | 
					
						
							|  |  |  |         m_deviceSourceEngines.removeAt(m_deviceEngineReferences[deviceIndex].deviceEngineIndex); | 
					
						
							| 
									
										
										
										
											2019-05-18 11:59:56 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     else if (m_deviceEngineReferences[deviceIndex].deviceEngineTYpe == 1) // sink
 | 
					
						
							| 
									
										
										
										
											2019-05-18 11:59:56 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |         DSPDeviceSinkEngine *deviceEngine = m_deviceSinkEngines[m_deviceEngineReferences[deviceIndex].deviceEngineIndex]; | 
					
						
							|  |  |  |         delete deviceEngine; | 
					
						
							|  |  |  |         m_deviceSinkEngines.removeAt(m_deviceEngineReferences[deviceIndex].deviceEngineIndex); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (m_deviceEngineReferences[deviceIndex].deviceEngineTYpe == 2) // MIMO
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DSPDeviceMIMOEngine *deviceEngine = m_deviceMIMOEngines[m_deviceEngineReferences[deviceIndex].deviceEngineIndex]; | 
					
						
							|  |  |  |         delete deviceEngine; | 
					
						
							|  |  |  |         m_deviceMIMOEngines.removeAt(m_deviceEngineReferences[deviceIndex].deviceEngineIndex); | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     m_deviceEngineReferences.removeAt(deviceIndex); | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-20 23:25:00 +02:00
										 |  |  | bool DSPEngine::hasDVSerialSupport() | 
					
						
							| 
									
										
										
										
											2016-05-08 06:00:37 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-20 23:25:00 +02:00
										 |  |  |     return m_ambeEngine.getNbDevices() > 0; | 
					
						
							| 
									
										
										
										
											2017-10-22 12:01:04 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-07-20 23:25:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  | void DSPEngine::setDVSerialSupport(bool support) | 
					
						
							|  |  |  | { (void) support; } | 
					
						
							| 
									
										
										
										
											2017-10-22 12:01:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::getDVSerialNames(std::vector<std::string>& deviceNames) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-20 23:25:00 +02:00
										 |  |  |     std::vector<QString> qDeviceRefs; | 
					
						
							|  |  |  |     m_ambeEngine.getDeviceRefs(qDeviceRefs); | 
					
						
							|  |  |  |     deviceNames.clear(); | 
					
						
							| 
									
										
										
										
											2017-10-22 12:01:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-20 23:25:00 +02:00
										 |  |  |     for (std::vector<QString>::const_iterator it = qDeviceRefs.begin(); it != qDeviceRefs.end(); ++it) { | 
					
						
							|  |  |  |         deviceNames.push_back(it->toStdString()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-22 12:01:04 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-07-20 23:25:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-22 12:01:04 +02:00
										 |  |  | void DSPEngine::pushMbeFrame( | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         const unsigned char *mbeFrame, | 
					
						
							|  |  |  |         int mbeRateIndex, | 
					
						
							|  |  |  |         int mbeVolumeIndex, | 
					
						
							|  |  |  |         unsigned char channels, | 
					
						
							|  |  |  |         bool useHP, | 
					
						
							|  |  |  |         int upsampling, | 
					
						
							|  |  |  |         AudioFifo *audioFifo) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-20 23:25:00 +02:00
										 |  |  |     m_ambeEngine.pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, useHP, upsampling, audioFifo); | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-03-12 06:27:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::createFFTFactory(const QString& fftWisdomFileName) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_fftFactory = new FFTFactory(fftWisdomFileName); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::preAllocateFFTs() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-15 19:59:56 +01:00
										 |  |  |     m_fftFactory->preallocate(7, 10, 1, 0); // pre-acllocate forward FFT only 1 per size from 128 to 1024
 | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  | } |