11namespace tracktion {
inline namespace engine
19 inline static double preadjust (
double alpha)
noexcept {
return alpha; }
20 inline static float get (
float alpha)
noexcept {
return alpha; }
27 inline static float get (
float alpha)
noexcept {
return std::sin (alpha); }
34 inline static float get (
float alpha)
noexcept {
return 1.0f -
std::cos (alpha); }
40 inline static double preadjust (
double alpha)
noexcept {
return alpha; }
55 template <
typename CurveClass>
58 jassert (alpha >= 0 && alpha <= 1.0f);
59 return CurveClass::get ((
float) CurveClass::preadjust (alpha));
65 if (type == convex)
return alphaToGain<Convex> (alpha);
66 if (type == concave)
return alphaToGain<Concave> (alpha);
67 if (type == sCurve)
return alphaToGain<SCurve> (alpha);
77 template <
typename CurveClass,
typename DestSamplePo
inter>
78 static void renderBlock (DestSamplePointer& dest,
int numSamples,
79 float startAlpha,
float endAlpha)
noexcept
83 const double a1 = CurveClass::preadjust (startAlpha);
84 const double a2 = CurveClass::preadjust (endAlpha);
85 const double delta = (a2 - a1) / numSamples;
88 while (--numSamples >= 0)
90 dest.apply (CurveClass::get ((
float) alpha));
99 template <
typename DestSamplePo
inter>
101 float startAlpha,
float endAlpha,
Type type)
noexcept
107 case linear: renderBlock<Linear> (dest, numSamples, startAlpha, endAlpha);
break;
108 case convex: renderBlock<Convex> (dest, numSamples, startAlpha, endAlpha);
break;
109 case concave: renderBlock<Concave> (dest, numSamples, startAlpha, endAlpha);
break;
110 case sCurve: renderBlock<SCurve> (dest, numSamples, startAlpha, endAlpha);
break;
128 : gain1 (alphaToGain<AudioFadeCurve::Convex> (alpha)),
129 gain2 (alphaToGain<AudioFadeCurve::Convex> (1.0f - alpha))
137 int startSample,
int numSamples,
143 int startSample,
int numSamples,
150 int destChannel,
int destStartIndex,
151 int sourceChannel,
int sourceStartIndex,
A concave sine-shaped curve.
A convex sine-shaped curve.
Calculates the two gain multipliers to use for mixing between two sources, given a position alpha fro...
CrossfadeLevels(float alpha) noexcept
Creates the object and calculates the two gain levels.
static float alphaToGain(float alpha) noexcept
Converts an alpha position along the curve (0 to 1.0) into the gain at that point.
Type
A enumeration of the curve classes available.
static void renderBlockForType(DestSamplePointer &dest, int numSamples, float startAlpha, float endAlpha, Type type) noexcept
Multiplies a block of samples by the curve shape between two alpha-positions.
static float alphaToGainForType(Type type, float alpha) noexcept
Converts an alpha position along the curve (0 to 1.0) into the gain at that point.
static void renderBlock(DestSamplePointer &dest, int numSamples, float startAlpha, float endAlpha) noexcept
Multiplies a block of samples by the curve shape between two alpha-positions.