mirror of https://github.com/f4exb/sdrangel.git
CW transition smoother: use smootherstep function. See: https://en.wikipedia.org/wiki/Smoothstep
This commit is contained in:
parent
98b9e20392
commit
0a7e9261e2
|
@ -484,8 +484,11 @@ void CWSmoother::setNbFadeSamples(unsigned int nbFadeSamples)
|
||||||
|
|
||||||
for (int i = 0; i < m_nbFadeSamples; i++)
|
for (int i = 0; i < m_nbFadeSamples; i++)
|
||||||
{
|
{
|
||||||
m_fadeInSamples[i] = sin((i/ (float) m_nbFadeSamples) * M_PI_2);
|
float x = i/ (float) m_nbFadeSamples;
|
||||||
m_fadeOutSamples[i] = cos((i/ (float) m_nbFadeSamples) * M_PI_2);
|
float y = 1.0f -x;
|
||||||
|
|
||||||
|
m_fadeInSamples[i] = smootherstep(x);
|
||||||
|
m_fadeOutSamples[i] = smootherstep(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_fadeInCounter = 0;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -118,6 +118,8 @@ private:
|
||||||
unsigned int m_nbFadeSamples;
|
unsigned int m_nbFadeSamples;
|
||||||
float *m_fadeInSamples;
|
float *m_fadeInSamples;
|
||||||
float *m_fadeOutSamples;
|
float *m_fadeOutSamples;
|
||||||
|
|
||||||
|
float smootherstep(float x);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SDRBASE_DSP_CWKEYER_H_ */
|
#endif /* SDRBASE_DSP_CWKEYER_H_ */
|
||||||
|
|
Loading…
Reference in New Issue