From 38318577de1d6e1895de88a5eb2730ff9104986c Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 27 Jul 2017 11:24:01 +0200 Subject: [PATCH] Put smootherstep function code in one place --- plugins/channelrx/demodnfm/nfmdemod.cpp | 3 +- plugins/channelrx/demodnfm/nfmdemod.h | 15 ---------- plugins/channelrx/demodssb/ssbdemod.cpp | 2 +- sdrbase/dsp/agc.cpp | 3 +- sdrbase/dsp/cwkeyer.cpp | 14 ++------- sdrbase/dsp/cwkeyer.h | 2 -- sdrbase/util/smootherstep.h | 30 ------------------- sdrbase/util/stepfunctions.h | 39 +++++++++++++++++++++++++ 8 files changed, 47 insertions(+), 61 deletions(-) delete mode 100644 sdrbase/util/smootherstep.h create mode 100644 sdrbase/util/stepfunctions.h diff --git a/plugins/channelrx/demodnfm/nfmdemod.cpp b/plugins/channelrx/demodnfm/nfmdemod.cpp index d5c20147a..328edd4aa 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.cpp +++ b/plugins/channelrx/demodnfm/nfmdemod.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "util/stepfunctions.h" #include "audio/audiooutput.h" #include "dsp/pidcontroller.h" #include "dsp/dspengine.h" @@ -285,7 +286,7 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto else { demod = m_bandpass.filter(demod); - Real squelchFactor = smootherstep((Real) (m_squelchCount - m_squelchGate) / 480.0f); + Real squelchFactor = StepFunctions::smootherstep((Real) (m_squelchCount - m_squelchGate) / 480.0f); sample = demod * m_running.m_volume * squelchFactor; } } diff --git a/plugins/channelrx/demodnfm/nfmdemod.h b/plugins/channelrx/demodnfm/nfmdemod.h index 77367717e..da3c41cc3 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.h +++ b/plugins/channelrx/demodnfm/nfmdemod.h @@ -250,21 +250,6 @@ private: PhaseDiscriminators m_phaseDiscri; void apply(bool force = false); - - float smootherstep(float x) - { - if (x == 1.0f) { - return 1.0f; - } else if (x == 0.0f) { - return 0.0f; - } - - double x3 = x * x * x; - double x4 = x * x3; - double x5 = x * x4; - - return (float) (6.0*x5 - 15.0*x4 + 10.0*x3); - } }; #endif // INCLUDE_NFMDEMOD_H diff --git a/plugins/channelrx/demodssb/ssbdemod.cpp b/plugins/channelrx/demodssb/ssbdemod.cpp index 1d2f5f815..416091a42 100644 --- a/plugins/channelrx/demodssb/ssbdemod.cpp +++ b/plugins/channelrx/demodssb/ssbdemod.cpp @@ -16,7 +16,7 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include "../../channelrx/demodssb/ssbdemod.h" +#include "ssbdemod.h" #include #include diff --git a/sdrbase/dsp/agc.cpp b/sdrbase/dsp/agc.cpp index f745c8311..bfffeee69 100644 --- a/sdrbase/dsp/agc.cpp +++ b/sdrbase/dsp/agc.cpp @@ -7,7 +7,8 @@ #include #include "dsp/agc.h" -#include "util/smootherstep.h" + +#include "util/stepfunctions.h" #define StepLengthMax 2400 // 50ms diff --git a/sdrbase/dsp/cwkeyer.cpp b/sdrbase/dsp/cwkeyer.cpp index 78f1589aa..8357ab16d 100644 --- a/sdrbase/dsp/cwkeyer.cpp +++ b/sdrbase/dsp/cwkeyer.cpp @@ -19,6 +19,7 @@ #include #include #include "cwkeyer.h" +#include "util/stepfunctions.h" /** * 0: dot @@ -488,8 +489,8 @@ void CWSmoother::setNbFadeSamples(unsigned int nbFadeSamples) float x = i/ (float) m_nbFadeSamples; float y = 1.0f -x; - m_fadeInSamples[i] = smootherstep(x); - m_fadeOutSamples[i] = smootherstep(y); + m_fadeInSamples[i] = StepFunctions::smootherstep(x); + m_fadeOutSamples[i] = StepFunctions::smootherstep(y); } m_fadeInCounter = 0; @@ -534,12 +535,3 @@ bool CWSmoother::getFadeSample(bool on, float& sample) } } } - -float CWSmoother::smootherstep(float x) -{ - double x3 = x * x * x; - double x4 = x * x3; - double x5 = x * x4; - - return (float) (6.0*x5 - 15.0*x4 + 10.0*x3); -} diff --git a/sdrbase/dsp/cwkeyer.h b/sdrbase/dsp/cwkeyer.h index 421a86c8e..d52a82ef9 100644 --- a/sdrbase/dsp/cwkeyer.h +++ b/sdrbase/dsp/cwkeyer.h @@ -119,8 +119,6 @@ private: unsigned int m_nbFadeSamples; float *m_fadeInSamples; float *m_fadeOutSamples; - - float smootherstep(float x); }; #endif /* SDRBASE_DSP_CWKEYER_H_ */ diff --git a/sdrbase/util/smootherstep.h b/sdrbase/util/smootherstep.h deleted file mode 100644 index ceaea6d6b..000000000 --- a/sdrbase/util/smootherstep.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * smootherstep.h - * - * Created on: Jul 25, 2017 - * Author: f4exb - */ - -#ifndef SDRBASE_UTIL_SMOOTHERSTEP_H_ -#define SDRBASE_UTIL_SMOOTHERSTEP_H_ - -class StepFunctions -{ -public: - static float smootherstep(float x) - { - if (x == 1.0f) { - return 1.0f; - } else if (x == 0.0f) { - return 0.0f; - } - - double x3 = x * x * x; - double x4 = x * x3; - double x5 = x * x4; - - return (float) (6.0*x5 - 15.0*x4 + 10.0*x3); - } -}; - -#endif /* SDRBASE_UTIL_SMOOTHERSTEP_H_ */ diff --git a/sdrbase/util/stepfunctions.h b/sdrbase/util/stepfunctions.h new file mode 100644 index 000000000..0429aafd3 --- /dev/null +++ b/sdrbase/util/stepfunctions.h @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 Edouard Griffiths, F4EXB // +// // +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRBASE_UTIL_STEPFUNCTIONS_H_ +#define SDRBASE_UTIL_STEPFUNCTIONS_H_ + +class StepFunctions +{ +public: + static float smootherstep(float x) + { + if (x == 1.0f) { + return 1.0f; + } else if (x == 0.0f) { + return 0.0f; + } + + double x3 = x * x * x; + double x4 = x * x3; + double x5 = x * x4; + + return (float) (6.0*x5 - 15.0*x4 + 10.0*x3); + } +}; + +#endif /* SDRBASE_UTIL_STEPFUNCTIONS_H_ */