diff --git a/CMakeLists.txt b/CMakeLists.txt index 783821c..0b1d193 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ list(APPEND inspectrum_sources memory_sink_impl.cc memory_source_impl.cc plot.cpp + plots.cpp plotview.cpp samplebuffer.cpp samplesource.cpp diff --git a/plots.cpp b/plots.cpp new file mode 100644 index 0000000..2459140 --- /dev/null +++ b/plots.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016, Mike Walters + * + * This file is part of inspectrum. + * + * 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, either 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "grsamplebuffer.h" +#include "memory_sink.h" +#include "memory_source.h" +#include "traceplot.h" + +#include "plots.h" + +Plot* Plots::samplePlot(std::shared_ptr source) +{ + return new TracePlot(source); +} + +Plot* Plots::frequencyPlot(std::shared_ptr source) +{ + gr::top_block_sptr quad_demod_tb = gr::make_top_block("quad_demod"); + auto quad_demod_mem_source = gr::blocks::memory_source::make(8); + auto quad_demod_mem_sink = gr::blocks::memory_sink::make(4); + auto quad_demod = gr::analog::quadrature_demod_cf::make(5); + quad_demod_tb->connect(quad_demod_mem_source, 0, quad_demod, 0); + quad_demod_tb->connect(quad_demod, 0, quad_demod_mem_sink, 0); + + return new TracePlot( + std::make_shared, float>>( + std::dynamic_pointer_cast>>(source).get(), quad_demod_tb, quad_demod_mem_source, quad_demod_mem_sink + ) + ); +} diff --git a/plots.h b/plots.h new file mode 100644 index 0000000..c7eeb37 --- /dev/null +++ b/plots.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2016, Mike Walters + * + * This file is part of inspectrum. + * + * 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, either 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include "plot.h" +#include "samplesource.h" + +class Plots +{ + +public: + static Plot* samplePlot(std::shared_ptr source); + static Plot* frequencyPlot(std::shared_ptr source); +}; \ No newline at end of file diff --git a/plotview.cpp b/plotview.cpp index 426f1e2..1d990f8 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -22,12 +22,7 @@ #include #include #include -#include -#include -#include -#include "grsamplebuffer.h" -#include "memory_sink.h" -#include "memory_source.h" +#include "plots.h" PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0}) { @@ -37,13 +32,11 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0}) connect(&cursors, SIGNAL(cursorsMoved()), this, SLOT(cursorsMoved())); spectrogramPlot = new SpectrogramPlot(std::shared_ptr>>(mainSampleSource)); - auto tunerOutput = std::dynamic_pointer_cast>>(spectrogramPlot->output()).get(); - iqPlot = createIQPlot(tunerOutput); - auto quadDemodPlot = createQuadratureDemodPlot(tunerOutput); + auto tunerOutput = std::dynamic_pointer_cast>>(spectrogramPlot->output()); addPlot(spectrogramPlot); - addPlot(iqPlot); - addPlot(quadDemodPlot); + addPlot(Plots::samplePlot(tunerOutput)); + addPlot(Plots::frequencyPlot(tunerOutput)); viewport()->installEventFilter(this); mainSampleSource->subscribe(this); @@ -55,36 +48,6 @@ void PlotView::addPlot(Plot *plot) connect(plot, &Plot::repaint, this, &PlotView::repaint); } -TracePlot* PlotView::createIQPlot(SampleSource> *src) -{ - gr::top_block_sptr iq_tb = gr::make_top_block("multiply"); - auto iq_mem_source = gr::blocks::memory_source::make(8); - auto iq_mem_sink = gr::blocks::memory_sink::make(8); - auto multiply = gr::blocks::multiply_const_cc::make(20); - - iq_tb->connect(iq_mem_source, 0, multiply, 0); - iq_tb->connect(multiply, 0, iq_mem_sink, 0); - - auto iq_src = std::make_shared, std::complex>>(src, iq_tb, iq_mem_source, iq_mem_sink); - return new TracePlot(iq_src); -} - -TracePlot* PlotView::createQuadratureDemodPlot(SampleSource> *src) -{ - gr::top_block_sptr quad_demod_tb = gr::make_top_block("quad_demod"); - auto quad_demod_mem_source = gr::blocks::memory_source::make(8); - auto quad_demod_mem_sink = gr::blocks::memory_sink::make(4); - auto quad_demod = gr::analog::quadrature_demod_cf::make(5); - quad_demod_tb->connect(quad_demod_mem_source, 0, quad_demod, 0); - quad_demod_tb->connect(quad_demod, 0, quad_demod_mem_sink, 0); - - return new TracePlot( - std::make_shared, float>>( - dynamic_cast>*>(src), quad_demod_tb, quad_demod_mem_source, quad_demod_mem_sink - ) - ); -} - void PlotView::cursorsMoved() { selectedSamples = { diff --git a/plotview.h b/plotview.h index f99b0ad..8a2d908 100644 --- a/plotview.h +++ b/plotview.h @@ -61,7 +61,6 @@ private: Cursors cursors; SampleSource> *mainSampleSource = nullptr; SpectrogramPlot *spectrogramPlot = nullptr; - TracePlot *iqPlot = nullptr; std::vector> plots; range_t viewRange; range_t selectedSamples; @@ -74,8 +73,6 @@ private: bool cursorsEnabled; void addPlot(Plot *plot); - TracePlot* createIQPlot(SampleSource> *src); - TracePlot* createQuadratureDemodPlot(SampleSource> *src); int plotsHeight(); off_t samplesPerLine(); void updateView(bool reCenter = false);