mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-03-11 23:09:37 -04:00
Tx ph.1: new classes (1)
This commit is contained in:
parent
52b618469c
commit
b56c2d9a2c
@ -96,6 +96,7 @@ set(sdrbase_SOURCES
|
||||
sdrbase/dsp/afsquelch.cpp
|
||||
sdrbase/dsp/agc.cpp
|
||||
sdrbase/dsp/downchannelizer.cpp
|
||||
sdrbase/dsp/upchannelizer.cpp
|
||||
sdrbase/dsp/channelmarker.cpp
|
||||
sdrbase/dsp/ctcssdetector.cpp
|
||||
sdrbase/dsp/dspcommands.cpp
|
||||
@ -124,6 +125,7 @@ set(sdrbase_SOURCES
|
||||
sdrbase/dsp/scopevis.cpp
|
||||
sdrbase/dsp/spectrumvis.cpp
|
||||
sdrbase/dsp/threadedbasebandsamplesink.cpp
|
||||
sdrbase/dsp/threadedbasebandsamplesource.cpp
|
||||
|
||||
sdrbase/gui/aboutdialog.cpp
|
||||
sdrbase/gui/addpresetdialog.cpp
|
||||
@ -182,6 +184,7 @@ set(sdrbase_HEADERS
|
||||
|
||||
sdrbase/dsp/afsquelch.h
|
||||
sdrbase/dsp/downchannelizer.h
|
||||
sdrbase/dsp/upchannelizer.h
|
||||
sdrbase/dsp/channelmarker.h
|
||||
sdrbase/dsp/complex.h
|
||||
sdrbase/dsp/decimators.h
|
||||
@ -218,6 +221,7 @@ set(sdrbase_HEADERS
|
||||
sdrbase/dsp/scopevis.h
|
||||
sdrbase/dsp/spectrumvis.h
|
||||
sdrbase/dsp/threadedbasebandsamplesink.h
|
||||
sdrbase/dsp/threadedbasebandsamplesource.h
|
||||
|
||||
sdrbase/gui/aboutdialog.h
|
||||
sdrbase/gui/addpresetdialog.h
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -33,7 +33,7 @@ public:
|
||||
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) = 0;
|
||||
virtual void pull(Sample& sample) = 0;
|
||||
virtual bool handleMessage(const Message& cmd) = 0; //!< Processing of a message. Returns true if message has actually been processed
|
||||
|
||||
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "dsp/devicesamplesink.h"
|
||||
|
||||
DeviceSampleSink::DeviceSampleSink() :
|
||||
m_sampleSourceFifo(1<<19, 1<<16)
|
||||
m_sampleSourceFifo(1<<19, 1<<17)
|
||||
{
|
||||
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
|
||||
}
|
||||
|
@ -1,3 +1,20 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <dsp/downchannelizer.h>
|
||||
#include "dsp/inthalfbandfilter.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
|
@ -1,5 +1,22 @@
|
||||
#ifndef INCLUDE_CHANNELIZER_H
|
||||
#define INCLUDE_CHANNELIZER_H
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
#include <dsp/basebandsamplesink.h>
|
||||
#include <list>
|
||||
@ -64,7 +81,7 @@ protected:
|
||||
};
|
||||
typedef std::list<FilterStage*> FilterStages;
|
||||
FilterStages m_filterStages;
|
||||
BasebandSampleSink* m_sampleSink;
|
||||
BasebandSampleSink* m_sampleSink; //!< Demodulator
|
||||
int m_inputSampleRate;
|
||||
int m_requestedOutputSampleRate;
|
||||
int m_requestedCenterFrequency;
|
||||
@ -82,4 +99,4 @@ signals:
|
||||
void inputSampleRateChanged();
|
||||
};
|
||||
|
||||
#endif // INCLUDE_CHANNELIZER_H
|
||||
#endif // SDRBASE_DSP_DOWNCHANNELIZER_H
|
||||
|
@ -51,6 +51,47 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// upsample by 2, return center part of original spectrum
|
||||
bool workInterpolateCenter(Sample* sampleIn, Sample *SampleOut)
|
||||
{
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = 0;
|
||||
m_samples[m_ptr][1] = 0;
|
||||
|
||||
// save result
|
||||
doFIR(SampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = sampleIn->real();
|
||||
m_samples[m_ptr][1] = sampleIn->imag();
|
||||
|
||||
// save result
|
||||
doFIR(SampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool workDecimateCenter(qint32 *x, qint32 *y)
|
||||
{
|
||||
// insert sample into ring-buffer
|
||||
@ -84,43 +125,43 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// downsample by 2, return edges of spectrum rotated into center
|
||||
bool workDecimateFullRotate(Sample* sample)
|
||||
{
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = sample->real();
|
||||
m_samples[m_ptr][1] = sample->imag();
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = -sample->real();
|
||||
m_samples[m_ptr][1] = sample->imag();
|
||||
|
||||
// save result
|
||||
doFIR(sample);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// downsample by 2, return edges of spectrum rotated into center - unused
|
||||
// bool workDecimateFullRotate(Sample* sample)
|
||||
// {
|
||||
// switch(m_state)
|
||||
// {
|
||||
// case 0:
|
||||
// // insert sample into ring-buffer
|
||||
// m_samples[m_ptr][0] = sample->real();
|
||||
// m_samples[m_ptr][1] = sample->imag();
|
||||
//
|
||||
// // advance write-pointer
|
||||
// m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
//
|
||||
// // next state
|
||||
// m_state = 1;
|
||||
//
|
||||
// // tell caller we don't have a new sample
|
||||
// return false;
|
||||
//
|
||||
// default:
|
||||
// // insert sample into ring-buffer
|
||||
// m_samples[m_ptr][0] = -sample->real();
|
||||
// m_samples[m_ptr][1] = sample->imag();
|
||||
//
|
||||
// // save result
|
||||
// doFIR(sample);
|
||||
//
|
||||
// // advance write-pointer
|
||||
// m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
//
|
||||
// // next state
|
||||
// m_state = 0;
|
||||
//
|
||||
// // tell caller we have a new sample
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// downsample by 2, return lower half of original spectrum
|
||||
bool workDecimateLowerHalf(Sample* sample)
|
||||
@ -191,6 +232,81 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// upsample by 2, from lower half of original spectrum
|
||||
bool workInterpolateLowerHalf(Sample* sampleIn, Sample *sampleOut)
|
||||
{
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = 0;
|
||||
m_samples[m_ptr][1] = 0;
|
||||
|
||||
// save result
|
||||
doFIR(sampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = -sampleIn->real();
|
||||
m_samples[m_ptr][1] = -sampleIn->imag();
|
||||
|
||||
// save result
|
||||
doFIR(sampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 2;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = 0;
|
||||
m_samples[m_ptr][1] = 0;
|
||||
|
||||
// save result
|
||||
doFIR(sampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 3;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = sampleIn->real();
|
||||
m_samples[m_ptr][1] = sampleIn->imag();
|
||||
|
||||
// save result
|
||||
doFIR(sampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// downsample by 2, return upper half of original spectrum
|
||||
bool workDecimateUpperHalf(Sample* sample)
|
||||
{
|
||||
@ -260,7 +376,82 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void myDecimate(const Sample* sample1, Sample* sample2)
|
||||
// upsample by 2, from upper half of original spectrum
|
||||
bool workInterpolateUpperHalf(Sample* sampleIn, Sample *sampleOut)
|
||||
{
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = 0;
|
||||
m_samples[m_ptr][1] = 0;
|
||||
|
||||
// save result
|
||||
doFIR(sampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = -sampleIn->real();
|
||||
m_samples[m_ptr][1] = -sampleIn->imag();
|
||||
|
||||
// save result
|
||||
doFIR(sampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 2;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = 0;
|
||||
m_samples[m_ptr][1] = 0;
|
||||
|
||||
// save result
|
||||
doFIR(sampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 3;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
m_samples[m_ptr][0] = sampleIn->real();
|
||||
m_samples[m_ptr][1] = sampleIn->imag();
|
||||
|
||||
// save result
|
||||
doFIR(sampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + HB_FILTERORDER) % (HB_FILTERORDER + 1);
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void myDecimate(const Sample* sample1, Sample* sample2)
|
||||
{
|
||||
static const qint16 mod33[38] = { 31,32,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
|
||||
20,21,22,23,24,25,26,27,28,29,30,31,32,0,1,2};
|
||||
|
101
sdrbase/dsp/threadedbasebandsamplesource.cpp
Normal file
101
sdrbase/dsp/threadedbasebandsamplesource.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
|
||||
#include "dsp/threadedbasebandsamplesource.h"
|
||||
|
||||
ThreadedBasebandSampleSourceFifo::ThreadedBasebandSampleSourceFifo(BasebandSampleSource* sampleSource) :
|
||||
m_sampleSource(sampleSource),
|
||||
m_sampleSourceFifo(1<<19, 1<<17)
|
||||
{
|
||||
m_samplesChunkSize = m_sampleSourceFifo.getChunkSize();
|
||||
connect(&m_sampleSourceFifo, SIGNAL(dataWrite()), this, SLOT(handleFifoData()));
|
||||
}
|
||||
|
||||
ThreadedBasebandSampleSourceFifo::~ThreadedBasebandSampleSourceFifo()
|
||||
{
|
||||
}
|
||||
|
||||
void ThreadedBasebandSampleSourceFifo::readFromFifo(SampleVector::iterator& beginRead, unsigned int nbSamples)
|
||||
{
|
||||
m_sampleSourceFifo.read(beginRead, nbSamples);
|
||||
}
|
||||
|
||||
void ThreadedBasebandSampleSourceFifo::handleFifoData()
|
||||
{
|
||||
for (int i = 0; i < m_samplesChunkSize; i++)
|
||||
{
|
||||
SampleVector::iterator sampleIt;
|
||||
m_sampleSourceFifo.getWriteIterator(sampleIt);
|
||||
m_sampleSource->pull(*sampleIt);
|
||||
m_sampleSourceFifo.bumpIndex();
|
||||
}
|
||||
}
|
||||
|
||||
ThreadedBasebandSampleSource::ThreadedBasebandSampleSource(BasebandSampleSource* sampleSource, QObject *parent) :
|
||||
m_basebandSampleSource(sampleSource)
|
||||
{
|
||||
QString name = "ThreadedBasebandSampleSource(" + m_basebandSampleSource->objectName() + ")";
|
||||
setObjectName(name);
|
||||
|
||||
qDebug() << "ThreadedBasebandSampleSource::ThreadedBasebandSampleSource: " << name;
|
||||
|
||||
m_thread = new QThread(parent);
|
||||
m_threadedBasebandSampleSourceFifo = new ThreadedBasebandSampleSourceFifo(m_basebandSampleSource);
|
||||
m_basebandSampleSource->moveToThread(m_thread);
|
||||
m_threadedBasebandSampleSourceFifo->moveToThread(m_thread);
|
||||
|
||||
qDebug() << "ThreadedBasebandSampleSource::ThreadedBasebandSampleSource: thread: " << thread() << " m_thread: " << m_thread;
|
||||
}
|
||||
|
||||
ThreadedBasebandSampleSource::~ThreadedBasebandSampleSource()
|
||||
{
|
||||
delete m_threadedBasebandSampleSourceFifo;
|
||||
delete m_thread;
|
||||
}
|
||||
|
||||
void ThreadedBasebandSampleSource::start()
|
||||
{
|
||||
qDebug() << "ThreadedBasebandSampleSource::start";
|
||||
m_thread->start();
|
||||
m_basebandSampleSource->start();
|
||||
}
|
||||
|
||||
void ThreadedBasebandSampleSource::stop()
|
||||
{
|
||||
qDebug() << "ThreadedBasebandSampleSource::stop";
|
||||
m_basebandSampleSource->stop();
|
||||
m_thread->exit();
|
||||
m_thread->wait();
|
||||
}
|
||||
|
||||
void ThreadedBasebandSampleSource::pull(SampleVector::iterator& beginRead, unsigned int nbSamples)
|
||||
{
|
||||
m_threadedBasebandSampleSourceFifo->readFromFifo(beginRead, nbSamples);
|
||||
}
|
||||
|
||||
bool ThreadedBasebandSampleSource::handleSourceMessage(const Message& cmd)
|
||||
{
|
||||
return m_basebandSampleSource->handleMessage(cmd);
|
||||
}
|
||||
|
||||
QString ThreadedBasebandSampleSource::getSampleSourceObjectName() const
|
||||
{
|
||||
return m_basebandSampleSource->objectName();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2015 F4EXB //
|
||||
// Copyright (C) 2016 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
@ -36,15 +36,18 @@ class ThreadedBasebandSampleSourceFifo : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ThreadedBasebandSampleSourceFifo(BasebandSampleSource* sampleSource, std::size_t size = 1<<18);
|
||||
ThreadedBasebandSampleSourceFifo(BasebandSampleSource* sampleSource);
|
||||
~ThreadedBasebandSampleSourceFifo();
|
||||
void writeToFifo(SampleVector::const_iterator& begin, SampleVector::const_iterator& end);
|
||||
void readFromFifo(SampleVector::iterator& beginRead, unsigned int nbSamples);
|
||||
|
||||
BasebandSampleSource* m_sampleSource;
|
||||
SampleSourceFifo m_sampleSourceFifo;
|
||||
|
||||
public slots:
|
||||
void handleFifoData();
|
||||
|
||||
private:
|
||||
unsigned int m_samplesChunkSize;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -58,21 +61,20 @@ public:
|
||||
~ThreadedBasebandSampleSource();
|
||||
|
||||
const BasebandSampleSource *getSource() const { return m_basebandSampleSource; }
|
||||
MessageQueue* getInputMessageQueue() { return m_basebandSampleSource->getInputMessageQueue(); } //!< Return pointer to sample source's input message queue
|
||||
MessageQueue* getInputMessageQueue() { return m_basebandSampleSource->getInputMessageQueue(); } //!< Return pointer to sample source's input message queue
|
||||
MessageQueue* getOutputMessageQueue() { return m_basebandSampleSource->getOutputMessageQueue(); } //!< Return pointer to sample source's output message queue
|
||||
|
||||
void start(); //!< this thread start()
|
||||
void stop(); //!< this thread exit() and wait()
|
||||
|
||||
bool handleSourceMessage(const Message& cmd); //!< Send message to source synchronously
|
||||
void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); //!< Feed source with samples
|
||||
bool handleSourceMessage(const Message& cmd); //!< Send message to source synchronously
|
||||
void pull(SampleVector::iterator& beginRead, unsigned int nbSamples); //!< Pull samples from source
|
||||
|
||||
QString getSampleSourceObjectName() const;
|
||||
|
||||
protected:
|
||||
|
||||
QThread *m_thread; //!< The thead object
|
||||
ThreadedBasebandSampleSinkFifo *m_threadedBasebandSampleSourceFifo;
|
||||
ThreadedBasebandSampleSourceFifo *m_threadedBasebandSampleSourceFifo;
|
||||
BasebandSampleSource* m_basebandSampleSource;
|
||||
};
|
||||
|
||||
|
259
sdrbase/dsp/upchannelizer.cpp
Normal file
259
sdrbase/dsp/upchannelizer.cpp
Normal file
@ -0,0 +1,259 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <dsp/upchannelizer.h>
|
||||
#include "dsp/inthalfbandfilter.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(UpChannelizer::MsgChannelizerNotification, Message)
|
||||
|
||||
UpChannelizer::UpChannelizer(BasebandSampleSource* sampleSource) :
|
||||
m_sampleSource(sampleSource),
|
||||
m_outputSampleRate(0),
|
||||
m_requestedInputSampleRate(0),
|
||||
m_requestedCenterFrequency(0),
|
||||
m_currentInputSampleRate(0),
|
||||
m_currentCenterFrequency(0)
|
||||
{
|
||||
QString name = "UpChannelizer(" + m_sampleSource->objectName() + ")";
|
||||
setObjectName(name);
|
||||
}
|
||||
|
||||
UpChannelizer::~UpChannelizer()
|
||||
{
|
||||
freeFilterChain();
|
||||
}
|
||||
|
||||
void UpChannelizer::configure(MessageQueue* messageQueue, int sampleRate, int centerFrequency)
|
||||
{
|
||||
Message* cmd = new DSPConfigureChannelizer(sampleRate, centerFrequency);
|
||||
messageQueue->push(cmd);
|
||||
}
|
||||
|
||||
void UpChannelizer::pull(Sample& sample)
|
||||
{
|
||||
if(m_sampleSource == 0) {
|
||||
m_sampleBuffer.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_filterStages.size() == 0) // optimization when no downsampling is done anyway
|
||||
{
|
||||
m_sampleSource->pull(sample);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mutex.lock();
|
||||
|
||||
// TODO: handle multiple stages
|
||||
|
||||
FilterStages::iterator stage = m_filterStages.begin();
|
||||
|
||||
if ((*stage)->work(&m_sampleIn, &sample))
|
||||
{
|
||||
m_sampleSource->pull(m_sampleIn);
|
||||
}
|
||||
|
||||
m_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void UpChannelizer::start()
|
||||
{
|
||||
if (m_sampleSource != 0)
|
||||
{
|
||||
qDebug() << "UpChannelizer::start: thread: " << thread()
|
||||
<< " m_outputSampleRate: " << m_outputSampleRate
|
||||
<< " m_requestedInputSampleRate: " << m_requestedInputSampleRate
|
||||
<< " m_requestedCenterFrequency: " << m_requestedCenterFrequency;
|
||||
m_sampleSource->start();
|
||||
}
|
||||
}
|
||||
|
||||
void UpChannelizer::stop()
|
||||
{
|
||||
if(m_sampleSource != 0)
|
||||
m_sampleSource->stop();
|
||||
}
|
||||
|
||||
bool UpChannelizer::handleMessage(const Message& cmd)
|
||||
{
|
||||
qDebug() << "UpChannelizer::handleMessage: " << cmd.getIdentifier();
|
||||
|
||||
// TODO: apply changes only if input sample rate or requested output sample rate change. Change of center frequency has no impact.
|
||||
|
||||
if (DSPSignalNotification::match(cmd))
|
||||
{
|
||||
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
||||
m_outputSampleRate = notif.getSampleRate();
|
||||
qDebug() << "UpChannelizer::handleMessage: DSPSignalNotification: m_outputSampleRate: " << m_outputSampleRate;
|
||||
applyConfiguration();
|
||||
|
||||
if (m_sampleSource != 0)
|
||||
{
|
||||
m_sampleSource->handleMessage(notif);
|
||||
}
|
||||
|
||||
emit outputSampleRateChanged();
|
||||
return true;
|
||||
}
|
||||
else if (DSPConfigureChannelizer::match(cmd))
|
||||
{
|
||||
DSPConfigureChannelizer& chan = (DSPConfigureChannelizer&) cmd;
|
||||
m_requestedInputSampleRate = chan.getSampleRate();
|
||||
m_requestedCenterFrequency = chan.getCenterFrequency();
|
||||
|
||||
qDebug() << "UpChannelizer::handleMessage: DSPConfigureChannelizer:"
|
||||
<< " m_requestedInputSampleRate: " << m_requestedInputSampleRate
|
||||
<< " m_requestedCenterFrequency: " << m_requestedCenterFrequency;
|
||||
|
||||
applyConfiguration();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_sampleSource != 0)
|
||||
{
|
||||
return m_sampleSource->handleMessage(cmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpChannelizer::applyConfiguration()
|
||||
{
|
||||
if (m_outputSampleRate == 0)
|
||||
{
|
||||
qDebug() << "UpChannelizer::applyConfiguration: m_outputSampleRate=0 aborting";
|
||||
return;
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
|
||||
freeFilterChain();
|
||||
|
||||
m_currentCenterFrequency = createFilterChain(
|
||||
m_outputSampleRate / -2, m_outputSampleRate / 2,
|
||||
m_requestedCenterFrequency - m_requestedInputSampleRate / 2, m_requestedCenterFrequency + m_requestedInputSampleRate / 2);
|
||||
|
||||
m_mutex.unlock();
|
||||
|
||||
m_currentInputSampleRate = m_outputSampleRate / (1 << m_filterStages.size());
|
||||
|
||||
qDebug() << "UpChannelizer::applyConfiguration in=" << m_outputSampleRate
|
||||
<< ", req=" << m_requestedInputSampleRate
|
||||
<< ", out=" << m_requestedInputSampleRate
|
||||
<< ", fc=" << m_currentCenterFrequency;
|
||||
|
||||
if (m_sampleSource != 0)
|
||||
{
|
||||
MsgChannelizerNotification notif(m_currentInputSampleRate, m_currentCenterFrequency);
|
||||
m_sampleSource->handleMessage(notif);
|
||||
}
|
||||
}
|
||||
|
||||
UpChannelizer::FilterStage::FilterStage(Mode mode) :
|
||||
m_filter(new IntHalfbandFilter),
|
||||
m_workFunction(0)
|
||||
{
|
||||
switch(mode) {
|
||||
case ModeCenter:
|
||||
m_workFunction = &IntHalfbandFilter::workInterpolateCenter;
|
||||
break;
|
||||
|
||||
case ModeLowerHalf:
|
||||
m_workFunction = &IntHalfbandFilter::workInterpolateLowerHalf;
|
||||
break;
|
||||
|
||||
case ModeUpperHalf:
|
||||
m_workFunction = &IntHalfbandFilter::workInterpolateUpperHalf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UpChannelizer::FilterStage::~FilterStage()
|
||||
{
|
||||
delete m_filter;
|
||||
}
|
||||
|
||||
bool UpChannelizer::signalContainsChannel(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd) const
|
||||
{
|
||||
//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);
|
||||
}
|
||||
|
||||
Real UpChannelizer::createFilterChain(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd)
|
||||
{
|
||||
Real sigBw = sigEnd - sigStart;
|
||||
Real safetyMargin = sigBw / 20;
|
||||
Real rot = sigBw / 4;
|
||||
|
||||
safetyMargin = 0;
|
||||
|
||||
//fprintf(stderr, "Channelizer::createFilterChain: ");
|
||||
//fprintf(stderr, "Signal [%.1f, %.1f] (BW %.1f), Channel [%.1f, %.1f], Rot %.1f, Safety %.1f\n", sigStart, sigEnd, sigBw, chanStart, chanEnd, rot, safetyMargin);
|
||||
#if 1
|
||||
// check if it fits into the left half
|
||||
if(signalContainsChannel(sigStart + safetyMargin, sigStart + sigBw / 2.0 - safetyMargin, chanStart, chanEnd)) {
|
||||
//fprintf(stderr, "-> take left half (rotate by +1/4 and decimate by 2)\n");
|
||||
m_filterStages.push_back(new FilterStage(FilterStage::ModeLowerHalf));
|
||||
return createFilterChain(sigStart, sigStart + sigBw / 2.0, chanStart, chanEnd);
|
||||
}
|
||||
|
||||
// check if it fits into the right half
|
||||
if(signalContainsChannel(sigEnd - sigBw / 2.0f + safetyMargin, sigEnd - safetyMargin, chanStart, chanEnd)) {
|
||||
//fprintf(stderr, "-> take right half (rotate by -1/4 and decimate by 2)\n");
|
||||
m_filterStages.push_back(new FilterStage(FilterStage::ModeUpperHalf));
|
||||
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 + safetyMargin, sigEnd - rot - safetyMargin, chanStart, chanEnd)) {
|
||||
//fprintf(stderr, "-> take center half (decimate by 2)\n");
|
||||
m_filterStages.push_back(new FilterStage(FilterStage::ModeCenter));
|
||||
// Was: return createFilterChain(sigStart + rot, sigStart + sigBw / 2.0f + rot, chanStart, chanEnd);
|
||||
return createFilterChain(sigStart + rot, sigEnd - rot, chanStart, chanEnd);
|
||||
}
|
||||
#endif
|
||||
Real ofs = ((chanEnd - chanStart) / 2.0 + chanStart) - ((sigEnd - sigStart) / 2.0 + sigStart);
|
||||
//fprintf(stderr, "-> complete (final BW %.1f, frequency offset %.1f)\n", sigBw, ofs);
|
||||
return ofs;
|
||||
}
|
||||
|
||||
void UpChannelizer::freeFilterChain()
|
||||
{
|
||||
for(FilterStages::iterator it = m_filterStages.begin(); it != m_filterStages.end(); ++it)
|
||||
delete *it;
|
||||
m_filterStages.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
103
sdrbase/dsp/upchannelizer.h
Normal file
103
sdrbase/dsp/upchannelizer.h
Normal file
@ -0,0 +1,103 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_UPCHANNELIZER_H_
|
||||
#define SDRBASE_DSP_UPCHANNELIZER_H_
|
||||
|
||||
#include <dsp/basebandsamplesource.h>
|
||||
#include <list>
|
||||
#include <QMutex>
|
||||
#include "util/export.h"
|
||||
#include "util/message.h"
|
||||
|
||||
class MessageQueue;
|
||||
class IntHalfbandFilter;
|
||||
|
||||
class SDRANGEL_API UpChannelizer : public BasebandSampleSource {
|
||||
Q_OBJECT
|
||||
public:
|
||||
class SDRANGEL_API MsgChannelizerNotification : public Message {
|
||||
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; }
|
||||
|
||||
private:
|
||||
int m_sampleRate;
|
||||
qint64 m_frequencyOffset;
|
||||
};
|
||||
|
||||
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);
|
||||
virtual bool handleMessage(const Message& cmd);
|
||||
|
||||
protected:
|
||||
struct FilterStage {
|
||||
enum Mode {
|
||||
ModeCenter,
|
||||
ModeLowerHalf,
|
||||
ModeUpperHalf
|
||||
};
|
||||
|
||||
typedef bool (IntHalfbandFilter::*WorkFunction)(Sample* sIn, Sample *sOut);
|
||||
IntHalfbandFilter* m_filter;
|
||||
WorkFunction m_workFunction;
|
||||
|
||||
FilterStage(Mode mode);
|
||||
~FilterStage();
|
||||
|
||||
bool work(Sample* sampleIn, Sample *sampleOut)
|
||||
{
|
||||
return (m_filter->*m_workFunction)(sampleIn, sampleOut);
|
||||
}
|
||||
};
|
||||
typedef std::list<FilterStage*> FilterStages;
|
||||
FilterStages m_filterStages;
|
||||
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();
|
||||
bool signalContainsChannel(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd) const;
|
||||
Real createFilterChain(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd);
|
||||
void freeFilterChain();
|
||||
|
||||
signals:
|
||||
void outputSampleRateChanged();
|
||||
};
|
||||
|
||||
#endif /* SDRBASE_DSP_UPCHANNELIZER_H_ */
|
@ -34,6 +34,7 @@ SOURCES += mainwindow.cpp\
|
||||
dsp/afsquelch.cpp\
|
||||
dsp/agc.cpp\
|
||||
dsp/downchannelizer.cpp\
|
||||
dsp/upchannelizer.cpp\
|
||||
dsp/channelmarker.cpp\
|
||||
dsp/ctcssdetector.cpp\
|
||||
dsp/dspcommands.cpp\
|
||||
@ -65,6 +66,7 @@ SOURCES += mainwindow.cpp\
|
||||
dsp/scopevis.cpp\
|
||||
dsp/spectrumvis.cpp\
|
||||
dsp/threadedbasebandsamplesink.cpp\
|
||||
dsp/threadedbasebandsamplesource.cpp\
|
||||
gui/aboutdialog.cpp\
|
||||
gui/addpresetdialog.cpp\
|
||||
gui/basicchannelsettingswidget.cpp\
|
||||
@ -111,6 +113,7 @@ HEADERS += mainwindow.h\
|
||||
device/devicesourceapi.h\
|
||||
dsp/afsquelch.h\
|
||||
dsp/downchannelizer.h\
|
||||
dsp/upchannelizer.h\
|
||||
dsp/channelmarker.h\
|
||||
dsp/complex.h\
|
||||
dsp/decimators.h\
|
||||
@ -149,6 +152,7 @@ HEADERS += mainwindow.h\
|
||||
dsp/scopevis.h\
|
||||
dsp/spectrumvis.h\
|
||||
dsp/threadedbasebandsamplesink.h\
|
||||
dsp/threadedbasebandsamplesource.h\
|
||||
gui/aboutdialog.h\
|
||||
gui/addpresetdialog.h\
|
||||
gui/audiodialog.h\
|
||||
|
Loading…
Reference in New Issue
Block a user