| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2019-07-08 00:59:04 +02:00
										 |  |  | // Copyright (C) 2015-2019 Edouard Griffiths, F4EXB                              //
 | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +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                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 06:57:41 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02: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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-08 00:59:04 +02:00
										 |  |  | #ifndef INCLUDE_FILEINPUTTHREAD_H
 | 
					
						
							|  |  |  | #define INCLUDE_FILEINPUTTHREAD_H
 | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QThread>
 | 
					
						
							|  |  |  | #include <QMutex>
 | 
					
						
							|  |  |  | #include <QWaitCondition>
 | 
					
						
							|  |  |  | #include <QTimer>
 | 
					
						
							| 
									
										
										
										
											2016-03-14 01:43:21 +01:00
										 |  |  | #include <QElapsedTimer>
 | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							|  |  |  | #include <cstdlib>
 | 
					
						
							| 
									
										
										
										
											2016-10-06 19:18:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | #include "dsp/inthalfbandfilter.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-14 01:16:39 +02:00
										 |  |  | #include "util/message.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define FILESOURCE_THROTTLE_MS 50
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 18:07:27 +02:00
										 |  |  | class SampleSinkFifo; | 
					
						
							| 
									
										
										
										
											2018-10-14 01:16:39 +02:00
										 |  |  | class MessageQueue; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:07:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-08 00:59:04 +02:00
										 |  |  | class FileInputThread : public QThread { | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-10-14 01:16:39 +02:00
										 |  |  |     class MsgReportEOF : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							| 
									
										
										
										
											2019-07-08 00:59:04 +02:00
										 |  |  |         static MsgReportEOF* create() { | 
					
						
							| 
									
										
										
										
											2018-10-14 01:16:39 +02:00
										 |  |  |             return new MsgReportEOF(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         MsgReportEOF() : | 
					
						
							|  |  |  |             Message() | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-08 00:59:04 +02:00
										 |  |  | 	FileInputThread(std::ifstream *samplesStream, | 
					
						
							| 
									
										
										
										
											2018-10-14 01:16:39 +02:00
										 |  |  | 	        SampleSinkFifo* sampleFifo, | 
					
						
							|  |  |  | 	        const QTimer& timer, | 
					
						
							|  |  |  | 	        MessageQueue *fileInputMessageQueue, | 
					
						
							|  |  |  | 	        QObject* parent = NULL); | 
					
						
							| 
									
										
										
										
											2019-07-08 00:59:04 +02:00
										 |  |  | 	~FileInputThread(); | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void startWork(); | 
					
						
							|  |  |  | 	void stopWork(); | 
					
						
							| 
									
										
										
										
											2018-01-25 18:39:54 +01:00
										 |  |  | 	void setSampleRateAndSize(int samplerate, quint32 samplesize); | 
					
						
							|  |  |  |     void setBuffers(std::size_t chunksize); | 
					
						
							| 
									
										
										
										
											2015-08-03 09:25:38 +02:00
										 |  |  | 	bool isRunning() const { return m_running; } | 
					
						
							| 
									
										
										
										
											2018-10-14 01:16:39 +02:00
										 |  |  |     quint64 getSamplesCount() const { return m_samplesCount; } | 
					
						
							| 
									
										
										
										
											2018-10-12 17:05:03 +02:00
										 |  |  |     void setSamplesCount(quint64 samplesCount) { m_samplesCount = samplesCount; } | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	QMutex m_startWaitMutex; | 
					
						
							|  |  |  | 	QWaitCondition m_startWaiter; | 
					
						
							| 
									
										
										
										
											2018-02-21 18:54:59 +01:00
										 |  |  | 	volatile bool m_running; | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	std::ifstream* m_ifstream; | 
					
						
							| 
									
										
										
										
											2018-01-25 18:39:54 +01:00
										 |  |  | 	quint8  *m_fileBuf; | 
					
						
							|  |  |  | 	quint8  *m_convertBuf; | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | 	std::size_t m_bufsize; | 
					
						
							| 
									
										
										
										
											2018-10-12 17:05:03 +02:00
										 |  |  |     qint64 m_chunksize; | 
					
						
							| 
									
										
										
										
											2016-10-06 19:18:02 +02:00
										 |  |  | 	SampleSinkFifo* m_sampleFifo; | 
					
						
							| 
									
										
										
										
											2018-10-12 17:05:03 +02:00
										 |  |  |     quint64 m_samplesCount; | 
					
						
							| 
									
										
										
										
											2018-10-14 01:16:39 +02:00
										 |  |  |     const QTimer& m_timer; | 
					
						
							|  |  |  |     MessageQueue *m_fileInputMessageQueue; | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-25 18:39:54 +01:00
										 |  |  | 	int m_samplerate;      //!< File I/Q stream original sample rate
 | 
					
						
							| 
									
										
										
										
											2018-10-12 17:05:03 +02:00
										 |  |  |     quint64 m_samplesize;  //!< File effective sample size in bits (I or Q). Ex: 16, 24.
 | 
					
						
							|  |  |  |     quint64 m_samplebytes; //!< Number of bytes used to store a I or Q sample. Ex: 2. 4.
 | 
					
						
							|  |  |  |     qint64 m_throttlems; | 
					
						
							| 
									
										
										
										
											2016-03-14 01:43:21 +01:00
										 |  |  |     QElapsedTimer m_elapsedTimer; | 
					
						
							|  |  |  |     bool m_throttleToggle; | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void run(); | 
					
						
							|  |  |  | 	//void decimate1(SampleVector::iterator* it, const qint16* buf, qint32 len);
 | 
					
						
							| 
									
										
										
										
											2018-01-25 18:39:54 +01:00
										 |  |  | 	void writeToSampleFifo(const quint8* buf, qint32 nbBytes); | 
					
						
							| 
									
										
										
										
											2019-07-08 00:59:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 01:04:20 +02:00
										 |  |  | private slots: | 
					
						
							|  |  |  | 	void tick(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-08 00:59:04 +02:00
										 |  |  | #endif // INCLUDE_FILEINPUTTHREAD_H
 |