From d69c6cc417795485e4c8122ab3a3883a1695477d Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 29 Jan 2017 22:52:38 +0100 Subject: [PATCH] New scope: pass sample rate --- .../channelrx/chanalyzerng/chanalyzernggui.cpp | 2 +- sdrbase/dsp/scopevisng.cpp | 13 ++++++++++++- sdrbase/dsp/scopevisng.h | 15 +++++++++++++++ sdrbase/gui/glscopeng.cpp | 1 + sdrbase/gui/glscopeng.h | 5 +++++ sdrbase/gui/glscopenggui.cpp | 9 +++++++++ sdrbase/gui/glscopenggui.h | 2 ++ 7 files changed, 45 insertions(+), 2 deletions(-) diff --git a/plugins/channelrx/chanalyzerng/chanalyzernggui.cpp b/plugins/channelrx/chanalyzerng/chanalyzernggui.cpp index affaa6a85..bd357c545 100644 --- a/plugins/channelrx/chanalyzerng/chanalyzernggui.cpp +++ b/plugins/channelrx/chanalyzerng/chanalyzernggui.cpp @@ -437,7 +437,7 @@ bool ChannelAnalyzerNGGUI::setNewRate(int spanLog2) } ui->glScope->setSampleRate(m_rate); - //m_scopeVis->setSampleRate(m_rate); TODO: not needed anymore? + m_scopeVis->setSampleRate(m_rate); return true; } diff --git a/sdrbase/dsp/scopevisng.cpp b/sdrbase/dsp/scopevisng.cpp index b2a78d20f..47caee80e 100644 --- a/sdrbase/dsp/scopevisng.cpp +++ b/sdrbase/dsp/scopevisng.cpp @@ -36,7 +36,9 @@ ScopeVisNG::ScopeVisNG(GLScopeNG* glScope) : m_traceStart(true), m_traceFill(0), m_zTraceIndex(-1), - m_traceCompleteCount(0) + m_traceCompleteCount(0), + m_timeOfsProMill(0), + m_sampleRate(0) { setObjectName("ScopeVisNG"); m_tracebackBuffers.resize(1); @@ -53,6 +55,15 @@ ScopeVisNG::~ScopeVisNG() } } +void ScopeVisNG::setSampleRate(int sampleRate) +{ + if (sampleRate != m_sampleRate) + { + m_sampleRate = sampleRate; + if (m_glScope) m_glScope->setSampleRate(m_sampleRate); + } +} + void ScopeVisNG::configure(MessageQueue* msgQueue, uint traceSize) { diff --git a/sdrbase/dsp/scopevisng.h b/sdrbase/dsp/scopevisng.h index 0bd4bde9f..c575cc33e 100644 --- a/sdrbase/dsp/scopevisng.h +++ b/sdrbase/dsp/scopevisng.h @@ -58,6 +58,7 @@ public: ScopeVisNG(GLScopeNG* glScope = 0); virtual ~ScopeVisNG(); + void setSampleRate(int sampleRate); void configure(MessageQueue* msgQueue, uint32_t traceSize); @@ -70,6 +71,8 @@ public: private: typedef DoubleBufferSimple TraceBuffer; + // === messages === + // --------------------------------------------- class MsgConfigureScopeVisNG : public Message { MESSAGE_CLASS_DECLARATION @@ -88,6 +91,7 @@ private: {} }; + // --------------------------------------------- class MsgScopeVisNGAddTrigger : public Message { MESSAGE_CLASS_DECLARATION @@ -106,6 +110,7 @@ private: {} }; + // --------------------------------------------- class MsgScopeVisNGRemoveTrigger : public Message { MESSAGE_CLASS_DECLARATION @@ -124,6 +129,8 @@ private: {} }; + // === projectors === + // --------------------------------------------- class Projector { public: @@ -135,6 +142,7 @@ private: ProjectionType m_projectionType; }; + // --------------------------------------------- class ProjectorReal : public Projector { public: @@ -142,6 +150,7 @@ private: virtual Real run(const Sample& s) { return s.m_real / 32768.0f; } }; + // --------------------------------------------- class ProjectorImag : public Projector { public: @@ -149,6 +158,7 @@ private: virtual Real run(const Sample& s) { return s.m_imag / 32768.0f; } }; + // --------------------------------------------- class ProjectorMagLin : public Projector { public: @@ -160,6 +170,7 @@ private: } }; + // --------------------------------------------- class ProjectorMagDB : public Projector { public: @@ -173,6 +184,7 @@ private: static const Real mult; }; + // --------------------------------------------- class ProjectorPhase : public Projector { public: @@ -180,6 +192,7 @@ private: virtual Real run(const Sample& s) { return std::atan2((float) s.m_imag, (float) s.m_real) / M_PI; } }; + // --------------------------------------------- class ProjectorDPhase : public Projector { public: @@ -203,6 +216,7 @@ private: Real m_prevArg; }; + enum TriggerState { TriggerFreeRun, //!< Trigger is disabled @@ -276,6 +290,7 @@ private: int m_zTraceIndex; //!< Index of the trace used for Z input (luminance or false colors) int m_traceCompleteCount; //!< Count of completed traces SampleVector::const_iterator m_triggerPoint; //!< Trigger start location in the samples vector + int m_sampleRate; void processPrevTrace(SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, std::vector::iterator& trace); }; diff --git a/sdrbase/gui/glscopeng.cpp b/sdrbase/gui/glscopeng.cpp index 7f2f4c6ae..008152f32 100644 --- a/sdrbase/gui/glscopeng.cpp +++ b/sdrbase/gui/glscopeng.cpp @@ -290,6 +290,7 @@ void GLScopeNG::setSampleRate(int sampleRate) m_sampleRate = sampleRate; m_configChanged = true; update(); + emit sampleRateChanged(m_sampleRate); } void GLScopeNG::setTimeBase(int timeBase) diff --git a/sdrbase/gui/glscopeng.h b/sdrbase/gui/glscopeng.h index 67b7d401b..e1bd2610a 100644 --- a/sdrbase/gui/glscopeng.h +++ b/sdrbase/gui/glscopeng.h @@ -54,6 +54,8 @@ public: void setTraces(const ScopeVisNG::DisplayTraces *traces) { m_traces = traces; m_configChanged = true; } void newTraces(); + int getSampleRate() const { return m_sampleRate; } + void setTriggerPre(Real triggerPre); void setTimeOfsProMill(int timeOfsProMill); void setSampleRate(int sampleRate); @@ -62,6 +64,9 @@ public: void setDisplayMode(DisplayMode displayMode); void setTraceSize(int trceSize); +signals: + void sampleRateChanged(int); + private: DisplayMode m_displayMode; QTimer m_timer; diff --git a/sdrbase/gui/glscopenggui.cpp b/sdrbase/gui/glscopenggui.cpp index 2ebe6d041..ebc21edae 100644 --- a/sdrbase/gui/glscopenggui.cpp +++ b/sdrbase/gui/glscopenggui.cpp @@ -16,6 +16,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include "glscopenggui.h" +#include "glscopeng.h" #include "ui_glscopenggui.h" #include "util/simpleserializer.h" @@ -40,6 +41,7 @@ void GLScopeNGGUI::setBuddies(MessageQueue* messageQueue, ScopeVisNG* scopeVis, m_messageQueue = messageQueue; m_scopeVis = scopeVis; m_glScope = glScope; + connect(m_glScope, SIGNAL(sampleRateChanged(int)), this, SLOT(on_scope_sampleRateChanged(int))); applySettings(); } @@ -48,6 +50,13 @@ void GLScopeNGGUI::setSampleRate(int sampleRate) m_sampleRate = sampleRate; } +void GLScopeNGGUI::on_scope_sampleRateChanged(int sampleRate) +{ + //m_sampleRate = m_glScope->getSampleRate(); + m_sampleRate = sampleRate; + ui->sampleRateText->setText(tr("%1\nkS/s").arg(m_sampleRate / 1000.0f, 0, 'f', 2)); +} + void GLScopeNGGUI::resetToDefaults() { } diff --git a/sdrbase/gui/glscopenggui.h b/sdrbase/gui/glscopenggui.h index b5bbceeed..5af47b1ae 100644 --- a/sdrbase/gui/glscopenggui.h +++ b/sdrbase/gui/glscopenggui.h @@ -58,6 +58,8 @@ private: void applySettings(); +private slots: + void on_scope_sampleRateChanged(int value); };