2016-10-17 02:58:49 -04: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 //
|
2019-04-11 08:32:15 -04:00
|
|
|
// (at your option) any later version. //
|
2016-10-17 02:58:49 -04: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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef SDRBASE_DSP_UPCHANNELIZER_H_
|
|
|
|
#define SDRBASE_DSP_UPCHANNELIZER_H_
|
|
|
|
|
|
|
|
#include <dsp/basebandsamplesource.h>
|
2016-10-30 13:22:33 -04:00
|
|
|
#include <vector>
|
2016-10-17 02:58:49 -04:00
|
|
|
#include <QMutex>
|
2018-03-20 08:49:21 -04:00
|
|
|
#include "export.h"
|
2016-10-17 02:58:49 -04:00
|
|
|
#include "util/message.h"
|
2016-11-06 18:42:57 -05:00
|
|
|
#ifdef USE_SSE4_1
|
2016-11-06 22:16:02 -05:00
|
|
|
#include "dsp/inthalfbandfiltereo1.h"
|
2016-11-04 17:47:09 -04:00
|
|
|
#else
|
|
|
|
#include "dsp/inthalfbandfilterdb.h"
|
|
|
|
#endif
|
2016-10-29 11:01:02 -04:00
|
|
|
|
2016-11-01 00:54:25 -04:00
|
|
|
#define UPCHANNELIZER_HB_FILTER_ORDER 96
|
2016-10-17 02:58:49 -04:00
|
|
|
|
|
|
|
class MessageQueue;
|
|
|
|
|
2018-03-03 14:23:38 -05:00
|
|
|
class SDRBASE_API UpChannelizer : public BasebandSampleSource {
|
2016-10-17 02:58:49 -04:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-13 11:29:34 -05:00
|
|
|
class SDRBASE_API MsgChannelizerNotification : public Message {
|
2016-10-17 02:58:49 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
2017-08-06 11:10:29 -04:00
|
|
|
MsgChannelizerNotification(int basebandSampleRate, int samplerate, qint64 frequencyOffset) :
|
2016-10-17 02:58:49 -04:00
|
|
|
Message(),
|
2017-08-06 11:10:29 -04:00
|
|
|
m_basebandSampleRate(basebandSampleRate),
|
2016-10-17 02:58:49 -04:00
|
|
|
m_sampleRate(samplerate),
|
|
|
|
m_frequencyOffset(frequencyOffset)
|
|
|
|
{ }
|
|
|
|
|
2017-08-06 11:10:29 -04:00
|
|
|
int getBasebandSampleRate() const { return m_basebandSampleRate; }
|
2016-10-17 02:58:49 -04:00
|
|
|
int getSampleRate() const { return m_sampleRate; }
|
|
|
|
qint64 getFrequencyOffset() const { return m_frequencyOffset; }
|
|
|
|
|
2017-12-28 23:14:40 -05:00
|
|
|
static MsgChannelizerNotification* create(int basebandSampleRate, int samplerate, qint64 frequencyOffset)
|
|
|
|
{
|
|
|
|
return new MsgChannelizerNotification(basebandSampleRate, samplerate, frequencyOffset);
|
|
|
|
}
|
|
|
|
|
2016-10-17 02:58:49 -04:00
|
|
|
private:
|
2017-08-06 11:10:29 -04:00
|
|
|
int m_basebandSampleRate;
|
2016-10-17 02:58:49 -04:00
|
|
|
int m_sampleRate;
|
|
|
|
qint64 m_frequencyOffset;
|
|
|
|
};
|
|
|
|
|
2019-04-25 03:26:03 -04:00
|
|
|
class SDRBASE_API MsgSetChannelizer : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
MsgSetChannelizer() :
|
|
|
|
Message()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
std::vector<unsigned int>& getStageIndexes() { return m_stageIndexes; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<unsigned int> m_stageIndexes;
|
|
|
|
};
|
|
|
|
|
2016-10-17 02:58:49 -04:00
|
|
|
UpChannelizer(BasebandSampleSource* sampleSink);
|
|
|
|
virtual ~UpChannelizer();
|
|
|
|
|
|
|
|
void configure(MessageQueue* messageQueue, int sampleRate, int centerFrequency);
|
|
|
|
int getOutputSampleRate() const { return m_outputSampleRate; }
|
|
|
|
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual void pull(Sample& sample);
|
2016-12-25 19:39:34 -05:00
|
|
|
virtual void pullAudio(int nbSamples) { if (m_sampleSource) m_sampleSource->pullAudio(nbSamples); }
|
2016-12-22 17:39:06 -05:00
|
|
|
|
2016-10-17 02:58:49 -04:00
|
|
|
virtual bool handleMessage(const Message& cmd);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
struct FilterStage {
|
|
|
|
enum Mode {
|
|
|
|
ModeCenter,
|
|
|
|
ModeLowerHalf,
|
|
|
|
ModeUpperHalf
|
|
|
|
};
|
|
|
|
|
2016-11-06 18:42:57 -05:00
|
|
|
#ifdef USE_SSE4_1
|
2016-11-06 22:16:02 -05:00
|
|
|
typedef bool (IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>::*WorkFunction)(Sample* sIn, Sample *sOut);
|
|
|
|
IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>* m_filter;
|
2016-11-04 17:47:09 -04:00
|
|
|
#else
|
2018-01-21 13:39:51 -05:00
|
|
|
typedef bool (IntHalfbandFilterDB<qint32, UPCHANNELIZER_HB_FILTER_ORDER>::*WorkFunction)(Sample* sIn, Sample *sOut);
|
|
|
|
IntHalfbandFilterDB<qint32, UPCHANNELIZER_HB_FILTER_ORDER>* m_filter;
|
2016-11-04 17:47:09 -04:00
|
|
|
#endif
|
2016-10-17 02:58:49 -04:00
|
|
|
WorkFunction m_workFunction;
|
|
|
|
|
|
|
|
FilterStage(Mode mode);
|
|
|
|
~FilterStage();
|
|
|
|
|
|
|
|
bool work(Sample* sampleIn, Sample *sampleOut)
|
|
|
|
{
|
|
|
|
return (m_filter->*m_workFunction)(sampleIn, sampleOut);
|
|
|
|
}
|
|
|
|
};
|
2016-10-30 13:22:33 -04:00
|
|
|
typedef std::vector<FilterStage*> FilterStages;
|
2016-10-17 02:58:49 -04:00
|
|
|
FilterStages m_filterStages;
|
2016-10-30 17:01:20 -04:00
|
|
|
std::vector<Sample> m_stageSamples;
|
2016-10-17 02:58:49 -04:00
|
|
|
BasebandSampleSource* m_sampleSource; //!< Modulator
|
|
|
|
int m_outputSampleRate;
|
|
|
|
int m_requestedInputSampleRate;
|
|
|
|
int m_requestedCenterFrequency;
|
|
|
|
int m_currentInputSampleRate;
|
|
|
|
int m_currentCenterFrequency;
|
|
|
|
SampleVector m_sampleBuffer;
|
|
|
|
Sample m_sampleIn;
|
|
|
|
QMutex m_mutex;
|
|
|
|
|
|
|
|
void applyConfiguration();
|
2019-04-25 03:26:03 -04:00
|
|
|
void applySetting(const std::vector<unsigned int>& stageIndexes);
|
2016-10-17 02:58:49 -04:00
|
|
|
bool signalContainsChannel(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd) const;
|
|
|
|
Real createFilterChain(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd);
|
2019-04-25 03:26:03 -04:00
|
|
|
double setFilterChain(const std::vector<unsigned int>& stageIndexes); //!< returns offset in ratio of sample rate
|
2016-10-17 02:58:49 -04:00
|
|
|
void freeFilterChain();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void outputSampleRateChanged();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SDRBASE_DSP_UPCHANNELIZER_H_ */
|