CW transition smoother: use smootherstep function. See: https://en.wikipedia.org/wiki/Smoothstep

This commit is contained in:
f4exb 2016-12-14 23:23:58 +01:00
parent 98b9e20392
commit 0a7e9261e2
2 changed files with 16 additions and 2 deletions

View File

@ -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);
}

View File

@ -118,6 +118,8 @@ private:
unsigned int m_nbFadeSamples;
float *m_fadeInSamples;
float *m_fadeOutSamples;
float smootherstep(float x);
};
#endif /* SDRBASE_DSP_CWKEYER_H_ */