diff --git a/plotview.cpp b/plotview.cpp index cc19a8e..27b660c 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -26,18 +26,19 @@ #include #include #include -#include #include "grsamplebuffer.h" #include "memory_sink.h" #include "memory_source.h" -PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0}) +PlotView::PlotView(InputSource *input) : cursors(this), tuner(this), viewRange({0, 0}) { mainSampleSource = input; setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); enableCursors(false); viewport()->installEventFilter(&cursors); connect(&cursors, SIGNAL(cursorsMoved()), this, SLOT(cursorsMoved())); + viewport()->installEventFilter(&tuner); + connect(&tuner, &Tuner::tunerMoved, this, &PlotView::tunerMoved); spectrogramPlot = new SpectrogramPlot(mainSampleSource); plots.emplace_back(spectrogramPlot); @@ -59,10 +60,10 @@ TracePlot* PlotView::createIQPlot(SampleSource> *src) float centre = -0.05; //(selectionFreq.first + selectionFreq.second) / 2; float cutoff = 0.02; //std::abs(selectionFreq.first - centre); auto lp_taps = gr::filter::firdes::low_pass(1.0, 1.0, cutoff, cutoff / 2); - auto filter = gr::filter::freq_xlating_fir_filter_ccf::make(1, lp_taps, centre, 1.0); + plotFilter = gr::filter::freq_xlating_fir_filter_ccf::make(1, lp_taps, centre, 1.0); - iq_tb->connect(iq_mem_source, 0, filter, 0); - iq_tb->connect(filter, 0, multiply, 0); + iq_tb->connect(iq_mem_source, 0, plotFilter, 0); + iq_tb->connect(plotFilter, 0, multiply, 0); iq_tb->connect(multiply, 0, iq_mem_sink, 0); } else { iq_tb->connect(iq_mem_source, 0, multiply, 0); @@ -200,6 +201,7 @@ void PlotView::paintEvent(QPaintEvent *event) PLOT_LAYER(paintFront); if (cursorsEnabled) cursors.paintFront(painter, rect, viewRange); + tuner.paintFront(painter, rect, viewRange); #undef PLOT_LAYER } @@ -228,6 +230,18 @@ void PlotView::scrollContentsBy(int dx, int dy) updateView(); } +void PlotView::tunerMoved() +{ + float centre = 0.5f - tuner.centre() / (float)fftSize; + float cutoff = tuner.deviation() / (float)fftSize; + qDebug() << "centre: " << centre << " cutoff: " << cutoff; + auto lp_taps = gr::filter::firdes::low_pass(1.0, 1.0, cutoff, cutoff / 2); + plotFilter->set_center_freq(centre); + plotFilter->set_taps(lp_taps); + + viewport()->update(); +} + void PlotView::updateView(bool reCenter) { // Store old view for recentering diff --git a/plotview.h b/plotview.h index 16e0db2..6096713 100644 --- a/plotview.h +++ b/plotview.h @@ -19,6 +19,7 @@ #pragma once +#include #include #include @@ -28,6 +29,7 @@ #include "samplesource.h" #include "spectrogramplot.h" #include "traceplot.h" +#include "tuner.h" class PlotView : public QAbstractScrollArea, Subscriber { @@ -49,6 +51,7 @@ public slots: void setFFTAndZoom(int fftSize, int zoomLevel); void setPowerMin(int power); void setPowerMax(int power); + void tunerMoved(); protected: bool eventFilter(QObject * obj, QEvent *event) override; @@ -58,9 +61,11 @@ protected: private: Cursors cursors; + Tuner tuner; SampleSource> *mainSampleSource = nullptr; SpectrogramPlot *spectrogramPlot = nullptr; TracePlot *iqPlot = nullptr; + gr::filter::freq_xlating_fir_filter_ccf::sptr plotFilter = nullptr; std::vector> plots; range_t viewRange; bool selection = false; diff --git a/tuner.cpp b/tuner.cpp index 3a5622b..aed5b2e 100644 --- a/tuner.cpp +++ b/tuner.cpp @@ -42,7 +42,7 @@ void Tuner::cursorMoved() { Cursor *sender = static_cast(QObject::sender()); if (sender != cfCursor) { - _deviation = std::max(10, std::abs(sender->pos() - cfCursor->pos())); + _deviation = std::max(2, std::abs(sender->pos() - cfCursor->pos())); } updateCursors();