diff --git a/sdrbase/dsp/cwkeyer.cpp b/sdrbase/dsp/cwkeyer.cpp index 8ea6f95e2..76b2cce0f 100644 --- a/sdrbase/dsp/cwkeyer.cpp +++ b/sdrbase/dsp/cwkeyer.cpp @@ -484,8 +484,11 @@ void CWSmoother::setNbFadeSamples(unsigned int nbFadeSamples) for (int i = 0; i < m_nbFadeSamples; i++) { - m_fadeInSamples[i] = sin((i/ (float) m_nbFadeSamples) * M_PI_2); - m_fadeOutSamples[i] = cos((i/ (float) m_nbFadeSamples) * M_PI_2); + float x = i/ (float) m_nbFadeSamples; + float y = 1.0f -x; + + m_fadeInSamples[i] = smootherstep(x); + m_fadeOutSamples[i] = smootherstep(y); } m_fadeInCounter = 0; @@ -530,3 +533,12 @@ 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 7fcca31b0..a35dbf042 100644 --- a/sdrbase/dsp/cwkeyer.h +++ b/sdrbase/dsp/cwkeyer.h @@ -118,6 +118,8 @@ private: unsigned int m_nbFadeSamples; float *m_fadeInSamples; float *m_fadeOutSamples; + + float smootherstep(float x); }; #endif /* SDRBASE_DSP_CWKEYER_H_ */