| 
									
										
										
										
											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                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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), | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  | 	m_audioOutputSampleRate(48000), // Use default output device at 48 kHz
 | 
					
						
							|  |  |  |     m_audioInputSampleRate(48000)   // Use default input device at 48 kHz
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-09 01:26:39 +02:00
										 |  |  | 	m_dvSerialSupport = false; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DSPEngine::~DSPEngine() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-08 06:54:49 +02:00
										 |  |  |     m_audioOutput.setOnExit(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |     std::vector<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; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											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++; | 
					
						
							|  |  |  |     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(); | 
					
						
							| 
									
										
										
										
											2016-05-13 09:23:33 +02:00
										 |  |  |         delete lastDeviceEngine; | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |         m_deviceSourceEngines.pop_back(); | 
					
						
							|  |  |  |         m_deviceSourceEnginesUIDSequence--; | 
					
						
							| 
									
										
										
										
											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++; | 
					
						
							|  |  |  |     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-11-29 01:09:06 +01:00
										 |  |  | void DSPEngine::startAudioOutput() | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  |     m_audioOutput.start(-1, m_audioOutputSampleRate); | 
					
						
							|  |  |  |     m_audioOutputSampleRate = m_audioOutput.getRate(); // update with actual rate
 | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  | void DSPEngine::stopAudioOutput() | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-18 11:32:19 +02:00
										 |  |  |     m_audioOutput.stop(); | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  | void DSPEngine::startAudioOutputImmediate() | 
					
						
							| 
									
										
										
										
											2016-05-18 10:51:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  |     m_audioOutput.start(-1, m_audioOutputSampleRate); | 
					
						
							|  |  |  |     m_audioOutputSampleRate = m_audioOutput.getRate(); // update with actual rate
 | 
					
						
							| 
									
										
										
										
											2016-05-18 10:51:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  | void DSPEngine::stopAudioOutputImmediate() | 
					
						
							| 
									
										
										
										
											2016-05-18 10:51:42 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_audioOutput.stop(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  | void DSPEngine::startAudioInput() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_audioInput.start(-1, m_audioInputSampleRate); | 
					
						
							|  |  |  |     m_audioInputSampleRate = m_audioInput.getRate(); // update with actual rate
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::stopAudioInput() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_audioInput.stop(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::startAudioInputImmediate() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_audioInput.start(-1, m_audioInputSampleRate); | 
					
						
							|  |  |  |     m_audioInputSampleRate = m_audioInput.getRate(); // update with actual rate
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::stopAudioInputImmediate() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_audioInput.stop(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | void DSPEngine::addAudioSink(AudioFifo* audioFifo) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::addAudioSink"); | 
					
						
							|  |  |  | 	m_audioOutput.addFifo(audioFifo); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | void DSPEngine::removeAudioSink(AudioFifo* audioFifo) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::removeAudioSink"); | 
					
						
							|  |  |  | 	m_audioOutput.removeFifo(audioFifo); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  | void DSPEngine::addAudioSource(AudioFifo* audioFifo) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     qDebug("DSPEngine::addAudioSource"); | 
					
						
							|  |  |  |     m_audioInput.addFifo(audioFifo); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::removeAudioSource(AudioFifo* audioFifo) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     qDebug("DSPEngine::removeAudioSource"); | 
					
						
							|  |  |  |     m_audioInput.removeFifo(audioFifo); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  | DSPDeviceSourceEngine *DSPEngine::getDeviceSourceEngineByUID(uint uid) | 
					
						
							| 
									
										
										
										
											2016-05-11 19:14:23 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |     std::vector<DSPDeviceSourceEngine*>::iterator it = m_deviceSourceEngines.begin(); | 
					
						
							| 
									
										
										
										
											2016-05-11 19:14:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:11:32 +02:00
										 |  |  |     while (it != m_deviceSourceEngines.end()) | 
					
						
							| 
									
										
										
										
											2016-05-11 19:14:23 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         if ((*it)->getUID() == uid) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return *it; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ++it; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 14:29:23 +02: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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 06:00:37 +02: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
 | 
					
						
							|  |  |  | } |