| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2019 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                  //
 | 
					
						
							|  |  |  | // (at your option) any later version.                                           //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 <QString>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "inthalfbandfilter.h"
 | 
					
						
							|  |  |  | #include "dspcommands.h"
 | 
					
						
							|  |  |  | #include "hbfilterchainconverter.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | #include "upchannelizer.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | UpChannelizer::UpChannelizer(ChannelSampleSource* sampleSource) : | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |     m_filterChainSetMode(false), | 
					
						
							|  |  |  |     m_sampleSource(sampleSource), | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_basebandSampleRate(0), | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |     m_requestedInputSampleRate(0), | 
					
						
							|  |  |  |     m_requestedCenterFrequency(0), | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_channelSampleRate(0), | 
					
						
							|  |  |  |     m_channelFrequencyOffset(0), | 
					
						
							|  |  |  |     m_log2Interp(0), | 
					
						
							|  |  |  |     m_filterChainHash(0) | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | UpChannelizer::~UpChannelizer() | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     freeFilterChain(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | void UpChannelizer::pullOne(Sample& sample) | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_sampleSource == nullptr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_sampleBuffer.clear(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unsigned int log2Interp = m_filterStages.size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (log2Interp == 0) // optimization when no downsampling is done anyway
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_sampleSource->pullOne(sample); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         FilterStages::iterator stage = m_filterStages.begin(); | 
					
						
							|  |  |  |         std::vector<Sample>::iterator stageSample = m_stageSamples.begin(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (; stage != m_filterStages.end(); ++stage, ++stageSample) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if(stage == m_filterStages.end() - 1) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if ((*stage)->work(&m_sampleIn, &(*stageSample))) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     m_sampleSource->pullOne(m_sampleIn); // get new input sample
 | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (!(*stage)->work(&(*(stageSample+1)), &(*stageSample))) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         sample = *m_stageSamples.begin(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | void UpChannelizer::pull(SampleVector::iterator begin, unsigned int nbSamples) | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_sampleSource == nullptr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_sampleBuffer.clear(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unsigned int log2Interp = m_filterStages.size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (log2Interp == 0) // optimization when no downsampling is done anyway
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_sampleSource->pull(begin, nbSamples); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         std::for_each( | 
					
						
							|  |  |  |             begin, | 
					
						
							|  |  |  |             begin + nbSamples, | 
					
						
							|  |  |  |             [this](Sample& s) { | 
					
						
							|  |  |  |                 pullOne(s); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | void UpChannelizer::prefetch(unsigned int nbSamples) | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     unsigned int log2Interp = m_filterStages.size(); | 
					
						
							|  |  |  |     m_sampleSource->prefetch(nbSamples/(1<<log2Interp)); // 2^n less samples will be produced by the source
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | void UpChannelizer::setChannelization(int requestedSampleRate, qint64 requestedCenterFrequency) | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     m_requestedInputSampleRate = requestedSampleRate; | 
					
						
							|  |  |  |     m_requestedCenterFrequency = requestedCenterFrequency; | 
					
						
							|  |  |  |     applyChannelization(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | void UpChannelizer::setBasebandSampleRate(int basebandSampleRate, bool interp) | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     m_basebandSampleRate = basebandSampleRate; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (interp) { | 
					
						
							|  |  |  |         applyInterpolation(); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         applyChannelization(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | void UpChannelizer::applyChannelization() | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_filterChainSetMode = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     if (m_basebandSampleRate == 0) | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |         qDebug() << "UpChannelizer::applyConfiguration: aborting (out=0):" | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |                 << " out:" << m_basebandSampleRate | 
					
						
							| 
									
										
										
										
											2019-11-01 10:26:40 +01:00
										 |  |  |                 << " req:" << m_requestedInputSampleRate | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |                 << " in:" << m_channelSampleRate | 
					
						
							|  |  |  |                 << " fc:" << m_channelFrequencyOffset; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     freeFilterChain(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_channelFrequencyOffset = createFilterChain( | 
					
						
							|  |  |  |         m_basebandSampleRate / -2, m_basebandSampleRate / 2, | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |         m_requestedCenterFrequency - m_requestedInputSampleRate / 2, m_requestedCenterFrequency + m_requestedInputSampleRate / 2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_channelSampleRate = m_basebandSampleRate / (1 << m_filterStages.size()); | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |     qDebug() << "UpChannelizer::applyConfiguration: done: " | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |             << " out:" << m_basebandSampleRate | 
					
						
							| 
									
										
										
										
											2019-11-01 10:26:40 +01:00
										 |  |  |             << " req:" << m_requestedInputSampleRate | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |             << " in:" << m_channelSampleRate | 
					
						
							|  |  |  |             << " fc:" << m_channelFrequencyOffset; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | void UpChannelizer::setInterpolation(unsigned int log2Interp, unsigned int filterChainHash) | 
					
						
							| 
									
										
										
										
											2019-10-24 18:29:45 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_log2Interp = log2Interp; | 
					
						
							|  |  |  |     m_filterChainHash = filterChainHash; | 
					
						
							|  |  |  |     applyInterpolation(); | 
					
						
							| 
									
										
										
										
											2019-10-24 18:29:45 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | void UpChannelizer::applyInterpolation() | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_filterChainSetMode = true; | 
					
						
							|  |  |  |     std::vector<unsigned int> stageIndexes; | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_channelFrequencyOffset = m_basebandSampleRate * HBFilterChainConverter::convertToIndexes(m_log2Interp, m_filterChainHash, stageIndexes); | 
					
						
							|  |  |  |     m_requestedCenterFrequency = m_channelFrequencyOffset; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     freeFilterChain(); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_channelFrequencyOffset = m_basebandSampleRate * setFilterChain(stageIndexes); | 
					
						
							|  |  |  |     m_channelSampleRate = m_basebandSampleRate / (1 << m_filterStages.size()); | 
					
						
							|  |  |  |     m_requestedInputSampleRate = m_channelSampleRate; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | 	qDebug() << "UpChannelizer::applyInterpolation:" | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |             << " m_log2Interp:" << m_log2Interp | 
					
						
							|  |  |  |             << " m_filterChainHash:" << m_filterChainHash | 
					
						
							|  |  |  |             << " out:" << m_basebandSampleRate | 
					
						
							|  |  |  | 			<< " in:" << m_channelSampleRate | 
					
						
							|  |  |  | 			<< " fc:" << m_channelFrequencyOffset; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef USE_SSE4_1
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | UpChannelizer::FilterStage::FilterStage(Mode mode) : | 
					
						
							|  |  |  |     m_filter(new IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>), | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |     m_workFunction(0) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     switch(mode) { | 
					
						
							|  |  |  |         case ModeCenter: | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |             m_workFunction = &IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateCenter; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case ModeLowerHalf: | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |             m_workFunction = &IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateLowerHalf; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case ModeUpperHalf: | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |             m_workFunction = &IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateUpperHalf; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |             break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | UpChannelizer::FilterStage::FilterStage(Mode mode) : | 
					
						
							|  |  |  |     m_filter(new IntHalfbandFilterDB<qint32, UPCHANNELIZER_HB_FILTER_ORDER>), | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |     m_workFunction(0) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     switch(mode) { | 
					
						
							|  |  |  |         case ModeCenter: | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |             m_workFunction = &IntHalfbandFilterDB<qint32, UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateCenter; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case ModeLowerHalf: | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |             m_workFunction = &IntHalfbandFilterDB<qint32, UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateLowerHalf; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case ModeUpperHalf: | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |             m_workFunction = &IntHalfbandFilterDB<qint32, UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateUpperHalf; | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |             break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | UpChannelizer::FilterStage::~FilterStage() | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     delete m_filter; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | bool UpChannelizer::signalContainsChannel(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd) const | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     //qDebug("   testing signal [%f, %f], channel [%f, %f]", sigStart, sigEnd, chanStart, chanEnd);
 | 
					
						
							|  |  |  |     if(sigEnd <= sigStart) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     if(chanEnd <= chanStart) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     return (sigStart <= chanStart) && (sigEnd >= chanEnd); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | Real UpChannelizer::createFilterChain(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd) | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     Real sigBw = sigEnd - sigStart; | 
					
						
							|  |  |  |     Real rot = sigBw / 4; | 
					
						
							|  |  |  |     Sample s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |     qDebug() << "UpChannelizer::createFilterChain: start:" | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |             << " sig: ["  << sigStart << ":" << sigEnd << "]" | 
					
						
							|  |  |  |             << " BW: " << sigBw | 
					
						
							|  |  |  |             << " chan: [" << chanStart << ":" << chanEnd << "]" | 
					
						
							|  |  |  |             << " rot: " << rot; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // check if it fits into the left half
 | 
					
						
							|  |  |  |     if(signalContainsChannel(sigStart, sigStart + sigBw / 2.0, chanStart, chanEnd)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |         qDebug() << "UpChannelizer::createFilterChain: take left half (rotate by +1/4 and decimate by 2):" | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |                 << " [" << m_filterStages.size() << "]" | 
					
						
							|  |  |  |                 << " sig: ["  << sigStart << ":" << sigStart + sigBw / 2.0 << "]"; | 
					
						
							|  |  |  |         m_filterStages.push_back(new FilterStage(FilterStage::ModeLowerHalf)); | 
					
						
							|  |  |  |         m_stageSamples.push_back(s); | 
					
						
							|  |  |  |         return createFilterChain(sigStart, sigStart + sigBw / 2.0, chanStart, chanEnd); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // check if it fits into the right half
 | 
					
						
							|  |  |  |     if(signalContainsChannel(sigEnd - sigBw / 2.0f, sigEnd, chanStart, chanEnd)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |         qDebug() << "UpChannelizer::createFilterChain: take right half (rotate by -1/4 and decimate by 2):" | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |                 << " [" << m_filterStages.size() << "]" | 
					
						
							|  |  |  |                 << " sig: ["  << sigEnd - sigBw / 2.0f << ":" << sigEnd << "]"; | 
					
						
							|  |  |  |         m_filterStages.push_back(new FilterStage(FilterStage::ModeUpperHalf)); | 
					
						
							|  |  |  |         m_stageSamples.push_back(s); | 
					
						
							|  |  |  |         return createFilterChain(sigEnd - sigBw / 2.0f, sigEnd, chanStart, chanEnd); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // check if it fits into the center
 | 
					
						
							|  |  |  |     // Was: if(signalContainsChannel(sigStart + rot + safetyMargin, sigStart + rot + sigBw / 2.0f - safetyMargin, chanStart, chanEnd)) {
 | 
					
						
							|  |  |  |     if(signalContainsChannel(sigStart + rot, sigEnd - rot, chanStart, chanEnd)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |         qDebug() << "UpChannelizer::createFilterChain: take center half (decimate by 2):" | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |                 << " [" << m_filterStages.size() << "]" | 
					
						
							|  |  |  |                 << " sig: ["  << sigStart + rot << ":" << sigEnd - rot << "]"; | 
					
						
							|  |  |  |         m_filterStages.push_back(new FilterStage(FilterStage::ModeCenter)); | 
					
						
							|  |  |  |         m_stageSamples.push_back(s); | 
					
						
							|  |  |  |         // Was: return createFilterChain(sigStart + rot, sigStart + sigBw / 2.0f + rot, chanStart, chanEnd);
 | 
					
						
							|  |  |  |         return createFilterChain(sigStart + rot, sigEnd - rot, chanStart, chanEnd); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Real ofs = ((chanEnd - chanStart) / 2.0 + chanStart) - ((sigEnd - sigStart) / 2.0 + sigStart); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |     qDebug() << "UpChannelizer::createFilterChain: complete:" | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |             << " #stages: " << m_filterStages.size() | 
					
						
							|  |  |  |             << " BW: "  << sigBw | 
					
						
							|  |  |  |             << " ofs: " << ofs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ofs; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | double UpChannelizer::setFilterChain(const std::vector<unsigned int>& stageIndexes) | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     // filters are described from lower to upper level but the chain is constructed the other way round
 | 
					
						
							|  |  |  |     std::vector<unsigned int>::const_reverse_iterator rit = stageIndexes.rbegin(); | 
					
						
							|  |  |  |     double ofs = 0.0, ofs_stage = 0.25; | 
					
						
							|  |  |  |     Sample s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Each index is a base 3 number with 0 = low, 1 = center, 2 = high
 | 
					
						
							|  |  |  |     // Functions at upper level will convert a number to base 3 to describe the filter chain. Common converting
 | 
					
						
							|  |  |  |     // algorithms will go from LSD to MSD. This explains the reverse order.
 | 
					
						
							|  |  |  |     for (; rit != stageIndexes.rend(); ++rit) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (*rit == 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_filterStages.push_back(new FilterStage(FilterStage::ModeLowerHalf)); | 
					
						
							|  |  |  |             m_stageSamples.push_back(s); | 
					
						
							|  |  |  |             ofs -= ofs_stage; | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |             qDebug("UpChannelizer::setFilterChain: lower half: ofs: %f", ofs); | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else if (*rit == 1) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_filterStages.push_back(new FilterStage(FilterStage::ModeCenter)); | 
					
						
							|  |  |  |             m_stageSamples.push_back(s); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |             qDebug("UpChannelizer::setFilterChain: center: ofs: %f", ofs); | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else if (*rit == 2) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_filterStages.push_back(new FilterStage(FilterStage::ModeUpperHalf)); | 
					
						
							|  |  |  |             m_stageSamples.push_back(s); | 
					
						
							|  |  |  |             ofs += ofs_stage; | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |             qDebug("UpChannelizer::setFilterChain: upper half: ofs: %f", ofs); | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ofs_stage /= 2; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  |     qDebug() << "UpChannelizer::setFilterChain: complete:" | 
					
						
							| 
									
										
										
										
											2019-11-01 10:26:40 +01:00
										 |  |  |             << " #stages: " << m_filterStages.size() | 
					
						
							|  |  |  |             << " ofs: " << ofs; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  |     return ofs; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:38:19 +01:00
										 |  |  | void UpChannelizer::freeFilterChain() | 
					
						
							| 
									
										
										
										
											2019-10-23 18:34:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     for(FilterStages::iterator it = m_filterStages.begin(); it != m_filterStages.end(); ++it) | 
					
						
							|  |  |  |         delete *it; | 
					
						
							|  |  |  |     m_filterStages.clear(); | 
					
						
							|  |  |  |     m_stageSamples.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |