| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  | // Copyright (C) 2016-2018 Edouard Griffiths, F4EXB                              //
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02: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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2018-11-20 01:48:17 +01:00
										 |  |  | #include <chrono>
 | 
					
						
							|  |  |  | #include <thread>
 | 
					
						
							| 
									
										
										
										
											2016-10-06 19:18:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-22 19:12:43 +02:00
										 |  |  | #include "dsp/samplesinkfifo.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  | #include "audio/audiofifo.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 01:48:17 +01:00
										 |  |  | #include "fcdproplusthread.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  | FCDProPlusThread::FCDProPlusThread(SampleSinkFifo* sampleFifo, AudioFifo *fcdFIFO, QObject* parent) : | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	QThread(parent), | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  | 	m_fcdFIFO(fcdFIFO), | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	m_running(false), | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  | 	m_convertBuffer(fcd_traits<ProPlus>::convBufSize), // nb samples
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	m_sampleFifo(sampleFifo) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	start(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | FCDProPlusThread::~FCDProPlusThread() | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | void FCDProPlusThread::startWork() | 
					
						
							| 
									
										
										
										
											2015-09-03 08:39:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	m_startWaitMutex.lock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	start(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while(!m_running) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_startWaiter.wait(&m_startWaitMutex, 100); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_startWaitMutex.unlock(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | void FCDProPlusThread::stopWork() | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	m_running = false; | 
					
						
							|  |  |  | 	wait(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | void FCDProPlusThread::run() | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	m_running = true; | 
					
						
							| 
									
										
										
										
											2018-11-18 21:56:33 +01:00
										 |  |  | 	qDebug("FCDThread::run: start running loop"); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 01:48:17 +01:00
										 |  |  | 	while (m_running) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  | 	    work(fcd_traits<ProPlus>::convBufSize); | 
					
						
							| 
									
										
										
										
											2018-11-20 01:48:17 +01:00
										 |  |  | 	    std::this_thread::sleep_for(std::chrono::microseconds(100)); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-18 21:56:33 +01:00
										 |  |  | 	qDebug("FCDThread::run: running loop stopped"); | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  | 	m_running = false; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  | void FCDProPlusThread::work(unsigned int n_items) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  |     uint32_t nbRead = m_fcdFIFO->read((unsigned char *) m_buf, n_items); // number of samples
 | 
					
						
							|  |  |  |     SampleVector::iterator it = m_convertBuffer.begin(); | 
					
						
							|  |  |  |     m_decimators.decimate1(&it, m_buf, 2*nbRead); | 
					
						
							|  |  |  |     m_sampleFifo->write(m_convertBuffer.begin(), it); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | } |