| 
									
										
										
										
											2016-10-17 08:58:49 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2016 F4EXB                                                      //
 | 
					
						
							|  |  |  | // written by Edouard Griffiths                                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef SDRBASE_DSP_DOWNCHANNELIZER_H
 | 
					
						
							|  |  |  | #define SDRBASE_DSP_DOWNCHANNELIZER_H
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-02 22:29:04 +02:00
										 |  |  | #include <dsp/basebandsamplesink.h>
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include <list>
 | 
					
						
							| 
									
										
										
										
											2015-09-06 10:21:06 +02:00
										 |  |  | #include <QMutex>
 | 
					
						
							| 
									
										
										
										
											2018-03-20 13:49:21 +01:00
										 |  |  | #include "export.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-19 22:12:52 +02:00
										 |  |  | #include "util/message.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-08 01:35:08 +02:00
										 |  |  | #include "dsp/inthalfbandfiltereo.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-29 17:01:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define DOWNCHANNELIZER_HB_FILTER_ORDER 48
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class MessageQueue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-03 20:23:38 +01:00
										 |  |  | class SDRBASE_API DownChannelizer : public BasebandSampleSink { | 
					
						
							| 
									
										
										
										
											2015-07-12 09:32:54 +02:00
										 |  |  | 	Q_OBJECT | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-11-13 16:02:26 +01:00
										 |  |  |     class SDRBASE_API MsgChannelizerNotification : public Message { | 
					
						
							| 
									
										
										
										
											2015-08-19 22:12:52 +02:00
										 |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		MsgChannelizerNotification(int samplerate, qint64 frequencyOffset) : | 
					
						
							|  |  |  | 			Message(), | 
					
						
							|  |  |  | 			m_sampleRate(samplerate), | 
					
						
							|  |  |  | 			m_frequencyOffset(frequencyOffset) | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int getSampleRate() const { return m_sampleRate; } | 
					
						
							|  |  |  | 		qint64 getFrequencyOffset() const { return m_frequencyOffset; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-29 05:14:40 +01:00
										 |  |  |         static MsgChannelizerNotification* create(int samplerate, qint64 frequencyOffset) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return new MsgChannelizerNotification(samplerate, frequencyOffset); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-19 22:12:52 +02:00
										 |  |  | 	private: | 
					
						
							|  |  |  | 		int m_sampleRate; | 
					
						
							|  |  |  | 		qint64 m_frequencyOffset; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-02 22:29:04 +02:00
										 |  |  | 	DownChannelizer(BasebandSampleSink* sampleSink); | 
					
						
							| 
									
										
										
										
											2016-10-02 21:52:39 +02:00
										 |  |  | 	virtual ~DownChannelizer(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void configure(MessageQueue* messageQueue, int sampleRate, int centerFrequency); | 
					
						
							| 
									
										
										
										
											2015-07-12 09:32:54 +02:00
										 |  |  | 	int getInputSampleRate() const { return m_inputSampleRate; } | 
					
						
							| 
									
										
										
										
											2018-02-25 03:22:30 +01:00
										 |  |  | 	int getRequestedCenterFrequency() const { return m_requestedCenterFrequency; } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 05:00:28 +02:00
										 |  |  | 	virtual void start(); | 
					
						
							|  |  |  | 	virtual void stop(); | 
					
						
							| 
									
										
										
										
											2015-08-25 08:24:23 +02:00
										 |  |  | 	virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); | 
					
						
							| 
									
										
										
										
											2015-08-14 05:00:28 +02:00
										 |  |  | 	virtual bool handleMessage(const Message& cmd); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	struct FilterStage { | 
					
						
							|  |  |  | 		enum Mode { | 
					
						
							|  |  |  | 			ModeCenter, | 
					
						
							|  |  |  | 			ModeLowerHalf, | 
					
						
							|  |  |  | 			ModeUpperHalf | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 08:46:05 +01:00
										 |  |  | #ifdef SDR_RX_SAMPLE_24BIT
 | 
					
						
							| 
									
										
										
										
											2018-05-08 01:35:08 +02:00
										 |  |  |         typedef bool (IntHalfbandFilterEO<qint64, qint64, DOWNCHANNELIZER_HB_FILTER_ORDER>::*WorkFunction)(Sample* s); | 
					
						
							|  |  |  |         IntHalfbandFilterEO<qint64, qint64, DOWNCHANNELIZER_HB_FILTER_ORDER>* m_filter; | 
					
						
							| 
									
										
										
										
											2016-11-07 18:51:32 +01:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2018-05-08 01:35:08 +02:00
										 |  |  |         typedef bool (IntHalfbandFilterEO<qint32, qint32, DOWNCHANNELIZER_HB_FILTER_ORDER>::*WorkFunction)(Sample* s); | 
					
						
							|  |  |  |         IntHalfbandFilterEO<qint32, qint32, DOWNCHANNELIZER_HB_FILTER_ORDER>* m_filter; | 
					
						
							| 
									
										
										
										
											2016-11-07 18:51:32 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-05-01 22:02:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		WorkFunction m_workFunction; | 
					
						
							| 
									
										
										
										
											2017-05-12 02:41:51 +02:00
										 |  |  | 		Mode m_mode; | 
					
						
							|  |  |  | 		bool m_sse; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		FilterStage(Mode mode); | 
					
						
							|  |  |  | 		~FilterStage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool work(Sample* sample) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return (m_filter->*m_workFunction)(sample); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	typedef std::list<FilterStage*> FilterStages; | 
					
						
							|  |  |  | 	FilterStages m_filterStages; | 
					
						
							| 
									
										
										
										
											2016-10-17 08:58:49 +02:00
										 |  |  | 	BasebandSampleSink* m_sampleSink; //!< Demodulator
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	int m_inputSampleRate; | 
					
						
							|  |  |  | 	int m_requestedOutputSampleRate; | 
					
						
							|  |  |  | 	int m_requestedCenterFrequency; | 
					
						
							|  |  |  | 	int m_currentOutputSampleRate; | 
					
						
							|  |  |  | 	int m_currentCenterFrequency; | 
					
						
							|  |  |  | 	SampleVector m_sampleBuffer; | 
					
						
							| 
									
										
										
										
											2015-09-06 10:21:06 +02:00
										 |  |  | 	QMutex m_mutex; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void applyConfiguration(); | 
					
						
							|  |  |  | 	bool signalContainsChannel(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd) const; | 
					
						
							|  |  |  | 	Real createFilterChain(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd); | 
					
						
							|  |  |  | 	void freeFilterChain(); | 
					
						
							| 
									
										
										
										
											2017-05-12 02:41:51 +02:00
										 |  |  | 	void debugFilterChain(); | 
					
						
							| 
									
										
										
										
											2015-07-12 09:32:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | signals: | 
					
						
							|  |  |  | 	void inputSampleRateChanged(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-17 08:58:49 +02:00
										 |  |  | #endif // SDRBASE_DSP_DOWNCHANNELIZER_H
 |