Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
crossfade.hpp
Go to the documentation of this file.
1#pragma once
2
35
36#include <cmath>
37
38namespace pulp::signal {
39
45
49template <typename T>
50constexpr T crossfade_smoothstep(T t) noexcept {
51 if (t < T{0}) t = T{0};
52 else if (t > T{1}) t = T{1};
53 return t * t * (T{3} - T{2} * t);
54}
55
60template <typename T>
62 T& old_gain, T& new_gain) noexcept {
64 // π/2 to full double precision; `u * kHalfPi` reproduces the callers'
65 // `u * 0.5 * π` (u·0.5 is exact, so the single rounding is identical).
66 constexpr T kHalfPi = T{1.57079632679489661923};
67 const T theta = u * kHalfPi;
68 old_gain = std::cos(theta);
69 new_gain = std::sin(theta);
70 } else {
71 old_gain = T{1} - u;
72 new_gain = u;
73 }
74}
75
76} // namespace pulp::signal
Definition additive_bank.hpp:218
CrossfadeGainLaw
The old→new gain split applied to a shaped progress u ∈ [0,1].
Definition crossfade.hpp:41
@ EqualPower
(cos(u·π/2), sin(u·π/2)) — power sum == 1.
Definition crossfade.hpp:43
@ EqualGain
(1−u, u) — amplitude sum == 1.
Definition crossfade.hpp:42
constexpr T crossfade_smoothstep(T t) noexcept
Smoothstep progress shaping: cubic 3u²−2u³ with zero slope at both ends, clamped to [0,...
Definition crossfade.hpp:50
@ u
Definition formant_filter_bank.hpp:20
void crossfade_gains(T u, CrossfadeGainLaw law, T &old_gain, T &new_gain) noexcept
Old/new blend gains for an ALREADY-SHAPED progress u (the caller applies any smoothstep/clamp first).
Definition crossfade.hpp:61