Added SpectrumProvider interface and fixed some minors.

master
Hannes Matuschek 12 years ago
parent ea3968e516
commit b5d07817f7

@ -4,6 +4,7 @@
#include "config.hh" #include "config.hh"
#include "traits.hh" #include "traits.hh"
#include "node.hh" #include "node.hh"
#include "operators.hh"
namespace sdr { namespace sdr {
@ -95,7 +96,7 @@ protected:
protected: protected:
/** The size of the LUT. */ /** The size of the LUT. */
static const size_t _lut_size = 127; static const size_t _lut_size = 128;
}; };

@ -5,8 +5,25 @@ using namespace sdr;
using namespace sdr::gui; using namespace sdr::gui;
/* ********************************************************************************************* *
* SpectrumProvider
* ********************************************************************************************* */
SpectrumProvider::SpectrumProvider(QObject *parent)
: QObject(parent)
{
// pass...
}
SpectrumProvider::~SpectrumProvider() {
// pass...
}
/* ********************************************************************************************* *
* Spectrum
* ********************************************************************************************* */
Spectrum::Spectrum(double rrate, size_t fftsize, size_t max_avg, QObject *parent) : Spectrum::Spectrum(double rrate, size_t fftsize, size_t max_avg, QObject *parent) :
QObject(parent), _rrate(rrate), _fft_size(fftsize), _fft_buffer(fftsize), SpectrumProvider(parent), _rrate(rrate), _fft_size(fftsize), _fft_buffer(fftsize),
_compute(fftsize), _spectrum(fftsize), _sample_count(0), _N_samples(0), _compute(fftsize), _spectrum(fftsize), _sample_count(0), _N_samples(0),
_trafo_count(0), _Ntrafo(max_avg), _trafo_count(0), _Ntrafo(max_avg),
_samples_left(0), _input_type(Config::Type_UNDEFINED), _sample_rate(0) _samples_left(0), _input_type(Config::Type_UNDEFINED), _sample_rate(0)
@ -69,6 +86,20 @@ Spectrum::isInputReal() const {
return false; return false;
} }
double
Spectrum::sampleRate() const {
return _sample_rate;
}
size_t
Spectrum::fftSize() const {
return _fft_size;
}
const Buffer<double> &
Spectrum::spectrum() const {
return _spectrum;
}
void void
Spectrum::handleBuffer(const RawBuffer &buffer, bool allow_overwrite) Spectrum::handleBuffer(const RawBuffer &buffer, bool allow_overwrite)

@ -9,9 +9,39 @@
namespace sdr { namespace sdr {
namespace gui { namespace gui {
class SpectrumProvider: public QObject
{
Q_OBJECT
public:
SpectrumProvider(QObject *parent=0);
virtual ~SpectrumProvider();
/** Returns true if the input is real. */
virtual bool isInputReal() const = 0;
/** Retunrs the sample rate. */
virtual double sampleRate() const = 0;
/** Returns the FFT size. */
virtual size_t fftSize() const = 0;
/** Returns the current spectrum. */
virtual const Buffer<double> &spectrum() const = 0;
signals:
/** Gets emitted once the spectrum was updated. */
void spectrumUpdated();
/** Gets emitted once the spectrum was reconfigured. */
void spectrumConfigured();
};
/** Calculates the power spectrum of a singnal. The spectrum gets updated with a specified /** Calculates the power spectrum of a singnal. The spectrum gets updated with a specified
* rate (if possible). */ * rate (if possible). */
class Spectrum : public QObject, public SinkBase class Spectrum : public SpectrumProvider, public SinkBase
{ {
Q_OBJECT Q_OBJECT
@ -36,20 +66,13 @@ public:
bool isInputReal() const; bool isInputReal() const;
/** Retunrs the sample rate. */ /** Retunrs the sample rate. */
inline double sampleRate() const { return _sample_rate; } double sampleRate() const;
/** Returns the FFT size. */ /** Returns the FFT size. */
inline size_t fftSize() const { return _fft_size; } size_t fftSize() const;
/** Returns the current spectrum. */ /** Returns the current spectrum. */
inline const Buffer<double> &spectrum() const { return _spectrum; } const Buffer<double> &spectrum() const;
signals:
/** Gets emitted once the spectrum was updated. */
void spectrumUpdated();
/** Gets emitted once the spectrum was reconfigured. */
void spectrumConfigured();
protected: protected:
/** Updates the FFT in the _compute buffer. */ /** Updates the FFT in the _compute buffer. */

@ -8,7 +8,7 @@
using namespace sdr; using namespace sdr;
using namespace sdr::gui; using namespace sdr::gui;
SpectrumView::SpectrumView(Spectrum *spectrum, QWidget *parent) SpectrumView::SpectrumView(SpectrumProvider *spectrum, QWidget *parent)
: QWidget(parent), _spectrum(spectrum), _numXTicks(11), _numYTicks(6), : QWidget(parent), _spectrum(spectrum), _numXTicks(11), _numYTicks(6),
_maxF(std::numeric_limits<double>::infinity()), _mindB(-60) _maxF(std::numeric_limits<double>::infinity()), _mindB(-60)
{ {

@ -18,7 +18,7 @@ Q_OBJECT
public: public:
/** @param rrate Specifies the (approx) refreshrate of the FFT plot. */ /** @param rrate Specifies the (approx) refreshrate of the FFT plot. */
explicit SpectrumView(Spectrum *spectrum, QWidget *parent=0); explicit SpectrumView(SpectrumProvider *spectrum, QWidget *parent=0);
inline size_t numXTicks() const { return _numXTicks; } inline size_t numXTicks() const { return _numXTicks; }
inline void setNumXTicks(size_t N) { _numXTicks=N; update(); } inline void setNumXTicks(size_t N) { _numXTicks=N; update(); }
@ -51,7 +51,7 @@ protected:
protected: protected:
/** Holds a weak reference to the spectrum recorder object. */ /** Holds a weak reference to the spectrum recorder object. */
Spectrum *_spectrum; SpectrumProvider *_spectrum;
/// The font being used for axis labels /// The font being used for axis labels
QFont _axisFont; QFont _axisFont;
/// The plot area /// The plot area

@ -73,7 +73,7 @@ LinearColorMap::map(const double &value) {
/* ****************************************************************************************** * /* ****************************************************************************************** *
* Implementation of WaterFallView * Implementation of WaterFallView
* ****************************************************************************************** */ * ****************************************************************************************** */
WaterFallView::WaterFallView(Spectrum *spectrum, size_t height, QWidget *parent) WaterFallView::WaterFallView(SpectrumProvider *spectrum, size_t height, QWidget *parent)
: QWidget(parent), _spectrum(spectrum), _N(_spectrum->fftSize()), _M(height), _waterfall(_N,_M) : QWidget(parent), _spectrum(spectrum), _N(_spectrum->fftSize()), _M(height), _waterfall(_N,_M)
{ {
setMinimumHeight(height); setMinimumHeight(height);

@ -75,7 +75,7 @@ public:
* @param spectrum Specifies the spectrum sink. * @param spectrum Specifies the spectrum sink.
* @param height Specifies the number of PSDs to display. * @param height Specifies the number of PSDs to display.
* @param parent The parent widget. */ * @param parent The parent widget. */
explicit WaterFallView(Spectrum *spectrum, size_t height=100, QWidget *parent = 0); explicit WaterFallView(SpectrumProvider *spectrum, size_t height=100, QWidget *parent = 0);
signals: signals:
void click(double f); void click(double f);
@ -93,7 +93,7 @@ protected slots:
protected: protected:
/** The spectrum sink. */ /** The spectrum sink. */
Spectrum *_spectrum; SpectrumProvider *_spectrum;
/** The size of the spectrum. */ /** The size of the spectrum. */
size_t _N; size_t _N;
/** "Height of the spectrum. */ /** "Height of the spectrum. */

@ -247,11 +247,18 @@ public:
} }
/** Performs the sub-sampling. */ /** Performs the sub-sampling. */
virtual void process(const Buffer<iScalar> &buffer, bool allow_overwrite) { virtual void process(const Buffer<iScalar> &buffer, bool allow_overwrite)
{
// Short cut
if (1 == _frac) {
this->send(buffer, allow_overwrite);
return;
}
size_t i=0, o=0; size_t i=0, o=0;
while (i<buffer.size()) { while (i<buffer.size()) {
// First, fill sampler... // First, fill sampler...
while ( (_mu > 1) && (i<buffer.size()) ) { while ( (_mu >= 1) && (i<buffer.size()) ) {
_dl[_dl_idx] = _dl[_dl_idx+8] = buffer[i]; i++; _dl[_dl_idx] = _dl[_dl_idx+8] = buffer[i]; i++;
_dl_idx = (_dl_idx + 1) % 8; _mu -= 1; _dl_idx = (_dl_idx + 1) % 8; _mu -= 1;
} }

@ -203,9 +203,7 @@ WavSource::next()
if ((0 == _frames_left)) { if ((0 == _frames_left)) {
// Close file // Close file
_file.close(); _file.close();
Logger::get().log(LogMessage(LOG_DEBUG, "WavSource: End of file -> stop queue.")); signalEOS();
// and signal queue to stop
Queue::get().stop();
return; return;
} }

Loading…
Cancel
Save