| 
									
										
										
										
											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>
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | DSPEngine::DSPEngine() : | 
					
						
							|  |  |  | 	m_audioSampleRate(48000) // Use default output device at 48 kHz
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	m_deviceEngine = new DSPDeviceEngine(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DSPEngine::~DSPEngine() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	delete m_deviceEngine; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | MessageQueue* DSPEngine::getInputMessageQueue() | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	return m_deviceEngine->getInputMessageQueue(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | MessageQueue* DSPEngine::getOutputMessageQueue() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_deviceEngine->getOutputMessageQueue(); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void DSPEngine::start() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::start"); | 
					
						
							|  |  |  | 	m_deviceEngine->start(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::stop() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::stop"); | 
					
						
							|  |  |  | 	m_audioOutput.stop(); | 
					
						
							|  |  |  | 	m_deviceEngine->stop(); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool DSPEngine::initAcquisition() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::initAcquisition"); | 
					
						
							|  |  |  | 	return m_deviceEngine->initAcquisition(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool DSPEngine::startAcquisition() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::startAcquisition"); | 
					
						
							|  |  |  | 	bool started = m_deviceEngine->startAcquisition(); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	if (started) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_audioOutput.start(-1, m_audioSampleRate); | 
					
						
							|  |  |  | 		m_audioSampleRate = m_audioOutput.getRate(); // update with actual rate
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return started; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::stopAcquistion() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::stopAcquistion"); | 
					
						
							|  |  |  | 	m_audioOutput.stop(); | 
					
						
							|  |  |  | 	m_deviceEngine->stopAcquistion(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::setSource(SampleSource* source) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::setSource"); | 
					
						
							|  |  |  | 	m_deviceEngine->setSource(source); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-03 23:59:02 +02:00
										 |  |  | void DSPEngine::setSourceSequence(int sequence) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::setSource"); | 
					
						
							|  |  |  | 	m_deviceEngine->setSourceSequence(sequence); | 
					
						
							| 
									
										
										
										
											2015-10-03 23:59:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void DSPEngine::addSink(SampleSink* sink) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::setSource"); | 
					
						
							|  |  |  | 	m_deviceEngine->addSink(sink); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::removeSink(SampleSink* sink) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::removeSink"); | 
					
						
							|  |  |  | 	m_deviceEngine->removeSink(sink); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-21 08:54:28 +02:00
										 |  |  | void DSPEngine::addThreadedSink(ThreadedSampleSink* sink) | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::addThreadedSink"); | 
					
						
							|  |  |  | 	m_deviceEngine->addThreadedSink(sink); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-21 08:54:28 +02:00
										 |  |  | void DSPEngine::removeThreadedSink(ThreadedSampleSink* sink) | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::addThreadedSink"); | 
					
						
							|  |  |  | 	m_deviceEngine->removeThreadedSink(sink); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPEngine::configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	qDebug("DSPEngine::configureCorrections"); | 
					
						
							|  |  |  | 	m_deviceEngine->configureCorrections(dcOffsetCorrection, iqImbalanceCorrection); | 
					
						
							| 
									
										
										
										
											2015-08-13 01:14:21 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | DSPDeviceEngine::State DSPEngine::state() const | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	return m_deviceEngine->state(); | 
					
						
							| 
									
										
										
										
											2015-08-14 05:00:28 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-13 01:14:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | QString DSPEngine::errorMessage() | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	return m_deviceEngine->errorMessage(); | 
					
						
							| 
									
										
										
										
											2015-08-14 09:02:10 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | QString DSPEngine::sourceDeviceDescription() | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-15 04:05:19 +02:00
										 |  |  | 	return m_deviceEngine->sourceDeviceDescription(); | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | } |