9#ifndef SBL_DSP_MATH_CROSSFADE_HPP_
10#define SBL_DSP_MATH_CROSSFADE_HPP_
49 const float x =
sbl::math::clamp((t - end_zone) / (1.0f - 2.0f * end_zone), 0.0f, 1.0f);
51 gain_a = x < 1.0f ? std::cos(angle) : 0.0f;
52 gain_b = x > 0.0f ? std::sin(angle) : 0.0f;
69inline void crossfade(
const float* a,
const float* b,
float* out,
float mix, uint16_t frames) {
70 const float ga = 1.0f - mix;
71 for (uint16_t i = 0; i < frames; ++i) {
72 out[i] = a[i] * ga + b[i] * mix;
90 const float ga = sqrtf(1.0f - mix);
91 const float gb = sqrtf(mix);
92 for (uint16_t i = 0; i < frames; ++i) {
93 out[i] = a[i] * ga + b[i] * gb;
The numbers every layer reaches for.
Math for the audio stack.
float crossfade_equal_power(float a, float b, float t)
Equal-power crossfade between two values.
void crossfade_gains_equal_power(float t, float end_zone, float &gain_a, float &gain_b)
Equal-power gains for a crossfade with a zone at each end.
void crossfade(const float *a, const float *b, float *out, float mix, uint16_t frames)
Linear crossfade over a buffer with constant mix.
constexpr T clamp(T x, T lo, T hi)
x held to [lo, hi]; a NaN goes to lo.