24 constexpr mono_float kExpConversionMult = 1.44269504089f;
25 constexpr mono_float kLogConversionMult = 0.69314718056f;
46 static constexpr mono_float kCoefficient0 = 1.0f;
47 static constexpr mono_float kCoefficient1 = 16970.0 / 24483.0;
48 static constexpr mono_float kCoefficient2 = 1960.0 / 8161.0;
49 static constexpr mono_float kCoefficient3 = 1360.0 / 24483.0;
50 static constexpr mono_float kCoefficient4 = 80.0 / 8161.0;
51 static constexpr mono_float kCoefficient5 = 32.0 / 24483.0;
57 poly_float cubic = t * (t * (t * kCoefficient5 + kCoefficient4) + kCoefficient3) + kCoefficient2;
58 poly_float interpolate = t * (t * cubic + kCoefficient1) + kCoefficient0;
59 return int_pow * interpolate;
69 static constexpr mono_float kCoefficient0 = -1819.0 / 651.0;
70 static constexpr mono_float kCoefficient1 = 5.0;
71 static constexpr mono_float kCoefficient2 = -10.0 / 3.0;
72 static constexpr mono_float kCoefficient3 = 10.0 / 7.0;
73 static constexpr mono_float kCoefficient4 = -1.0 / 3.0;
74 static constexpr mono_float kCoefficient5 = 1.0 / 31.0;
77 poly_float t = (value & 0x7fffff) | (0x7f << 23);
79 poly_float cubic = t * (t * (t * kCoefficient5 + kCoefficient4) + kCoefficient3) + kCoefficient2;
80 poly_float interpolate = t * (t * cubic + kCoefficient1) + kCoefficient0;
91 static constexpr mono_float kCoefficient0 = 1.0f;
92 static constexpr mono_float kCoefficient1 = 12.0 / 17.0;
93 static constexpr mono_float kCoefficient2 = 4.0 / 17.0;
99 poly_float interpolate = t * (t * kCoefficient2 + kCoefficient1) + kCoefficient0;
100 return int_pow * interpolate;
110 static constexpr mono_float kCoefficient0 = -5.0 / 3.0;
111 static constexpr mono_float kCoefficient1 = 2.0;
112 static constexpr mono_float kCoefficient2 = -1.0 / 3.0;
115 poly_float t = (value & 0x7fffff) | (0x7f << 23);
117 poly_float interpolate = t * (t * kCoefficient2 + kCoefficient1) + kCoefficient0;
133 return exp2(exponent * kExpConversionMult);
136 return log2(value) * kLogConversionMult;
139 return exp2(-exponent);
152 template<mono_
float(*func)(mono_
float)>
155 int size = poly_float::kSize;
156 for (
int i = 0; i < size; ++i)
157 result.
set(i, func(value[i]));
163 return exp2(exponent * kExpConversionMult);
166 return log2(value) * kLogConversionMult;
169 return exp2(-exponent);
205 return log2(magnitude) * kDbGainConversionMult;
208 return log2(magnitude) * kDbGainConversionMult;
218 return exp(decibels * kDbMagnitudeConversionMult);
221 return exp2(decibels * kDbMagnitudeConversionMult);
242 return value / (square / (3.0f + square * 0.2f) + 1.0f);
246 return value / (square /
mulAdd(3.0f, square, 0.2f) + 1.0f);
267 mono_float num = square * -1.25f + fourth * 0.166667f + 6.25f;
282 return -1.42f * (1.0f / (value + sign) - sign);
295 return value - value * square * 0.9f / (square + 3.0f);
299 return value * square * -0.9f / (square + 3.0f) + value;
306 return value / (value * value * 0.25f + 1.0f);
315 return value / (pow_four * 0.1f + 1.0f);
320 return (value + square * value * 3.0f) / (pow_four * 20.0f + 1.0f);
329 mono_float num = fourth * 0.1f + square * -2.1f + 9.0f;
351 poly_float part_num1 = abs_value * 0.821226666969744f + 0.893229853513558f;
352 poly_float part_num2 = square * part_num1 + 2.45550750702956f;
353 poly_float num = value * (abs_value * 2.45550750702956f + part_num2);
356 poly_float den = part_den * (square + 2.44506634652299f) + 2.44506634652299f;
363 mono_float num = value * (2.45550750702956f + 2.45550750702956f * abs_value +
364 square * (0.893229853513558f + 0.821226666969744f * abs_value));
365 mono_float den = 2.44506634652299f + (2.44506634652299f + square) *
366 fabsf(value + 0.814642734961073f * value * abs_value);
374 static constexpr mono_float kHardnessConstant = 0.66f;
375 static constexpr mono_float kHardnessConstantInv = 1.0f - kHardnessConstant;
376 static constexpr mono_float kHardnessConstantInvRec = 1.0f / kHardnessConstantInv;
379 return clamped +
tanh((value - clamped) * kHardnessConstantInvRec) * (1.0f - kHardnessConstant);
396 return phase * (8.0f - 16.0f * fabsf(phase));
403 return approx * (0.776f + 0.224f * fabsf(approx));
412 return from + (to - from) * sin_t;
417 phase = 0.5f - phase;
418 return phase * (8.0f - 16.0f * fabsf(phase));
426 return approx * (0.776f + 0.224f * fabsf(approx));
437 return sin1(t * 0.25f);
440 static constexpr float kScale = 1.41421356237f;
442 return sin1(eighth_phase - utils::kStereoSplit * pan * eighth_phase) * kScale;
449 return sin1((t + 1.0f) * 0.25f);
456 static constexpr mono_float kMinPower = 0.01f;
458 if (fabsf(power) < kMinPower)
463 return numerator / denominator;
466 static constexpr mono_float kMinPowerMag = 0.005f;
#define force_inline
Definition common.h:23
force_inline poly_float bumpSat2(poly_float value)
Definition futils.h:317
force_inline mono_float quickSin(mono_float phase)
Quick approximations of sine functions assuming limited phase input ranges.
Definition futils.h:394
force_inline mono_float algebraicSat(mono_float value)
Algebraic saturation approximation.
Definition futils.h:291
force_inline mono_float quickSin1(mono_float phase)
Definition futils.h:416
force_inline poly_float hardTanh(poly_float value)
Another saturation function using half-range tanh.
Definition futils.h:373
force_inline mono_float quickTanh(mono_float value)
A quick approximation of the tanh function.
Definition futils.h:240
force_inline poly_float equalPowerFadeInverse(poly_float t)
The inverse equal-power fade from t to t+1.0.
Definition futils.h:448
force_inline mono_float algebraicSatDerivative(mono_float value)
Derivative of algebraic saturation approximation.
Definition futils.h:326
force_inline poly_float exp2(poly_float exponent)
Approximates 2^exponent for poly_float values using a polynomial approximation.
Definition futils.h:45
force_inline poly_float cheapExp2(poly_float exponent)
A cheaper but less accurate version of exp2 approximation.
Definition futils.h:90
force_inline poly_float equalPowerFade(poly_float t)
Produces an equal-power crossfade (sin-based) between 0.0 and 1.0.
Definition futils.h:436
force_inline mono_float reciprocalSat(mono_float value)
Saturation approximation using 1/x function.
Definition futils.h:278
force_inline mono_float sin(mono_float phase)
Definition futils.h:401
force_inline poly_float log2(poly_float value)
Approximates log2(value) for poly_float values using a polynomial approximation.
Definition futils.h:68
force_inline poly_float quickTanhDerivative(poly_float value)
Derivative of the quick tanh approximation.
Definition futils.h:255
force_inline poly_float map(poly_float value)
Applies a scalar function to each element of a poly_float.
Definition futils.h:153
force_inline mono_float exp_half(mono_float exponent)
Definition futils.h:138
force_inline poly_float cheapLog2(poly_float value)
A cheaper but less accurate version of log2 approximation.
Definition futils.h:109
force_inline poly_float cheapPow(poly_float base, poly_float exponent)
Definition futils.h:174
force_inline mono_float powerScale(mono_float value, mono_float power)
A power-scaling function to map a linear range to a curved response.
Definition futils.h:455
force_inline poly_float midiOffsetToRatio(poly_float note_offset)
Converts a MIDI note offset to a frequency ratio.
Definition futils.h:184
force_inline poly_float tanh(poly_float value)
Approximates tanh function using a complex polynomial.
Definition futils.h:347
force_inline poly_float sinInterpolate(poly_float from, poly_float to, poly_float t)
Definition futils.h:409
force_inline poly_float tanhDerivativeFast(poly_float value)
A fast approximation for the derivative of tanh.
Definition futils.h:386
force_inline mono_float magnitudeToDb(mono_float magnitude)
Converts a magnitude (linear) to decibels (dB).
Definition futils.h:204
force_inline poly_float bumpSat(poly_float value)
Bump saturation approximations.
Definition futils.h:312
force_inline mono_float sin1(mono_float phase)
Definition futils.h:424
force_inline poly_float quadraticInvSat(poly_float value)
Quadratic inverse saturation approximation.
Definition futils.h:305
force_inline poly_float mulAdd(poly_float a, poly_float b, poly_float c)
A fused multiply-add function: result = a * b + c.
Definition futils.h:230
force_inline mono_float exp(mono_float exponent)
Definition futils.h:132
force_inline mono_float log(mono_float value)
Definition futils.h:135
force_inline mono_float pow(mono_float base, mono_float exponent)
Definition futils.h:141
force_inline mono_float dbToMagnitude(mono_float decibels)
Converts decibels (dB) to magnitude (linear).
Definition futils.h:217
force_inline poly_float midiNoteToFrequency(poly_float note)
Converts a MIDI note number to frequency (in Hz).
Definition futils.h:194
force_inline poly_float panAmplitude(poly_float pan)
Definition futils.h:439
force_inline poly_float pow2ToFloat(poly_int value)
Definition poly_utils.h:866
constexpr mono_float kDbGainConversionMult
Multiplicative factor for converting dB <-> magnitude using dB = 20*log10(magnitude).
Definition utils.h:25
force_inline poly_int reinterpretToInt(poly_float value)
Reinterprets a poly_float as a poly_int (bitcast).
Definition poly_utils.h:834
force_inline poly_float toFloat(poly_int integers)
Casts a poly_int to poly_float lane-by-lane.
Definition poly_utils.h:733
force_inline poly_int roundToInt(poly_float value)
Rounds each lane to the nearest integer.
Definition poly_utils.h:792
force_inline poly_int shiftRight(poly_int integer)
Definition poly_utils.h:845
force_inline poly_float maskLoad(poly_float zero_value, poly_float one_value, poly_mask reset_mask)
Selects between two values (zero_value or one_value) based on a mask in each lane.
Definition poly_utils.h:351
Contains classes and functions used within the Vital synthesizer framework.
constexpr mono_float kMidi0Frequency
Frequency of MIDI note 0 (C-1).
Definition common.h:47
constexpr int kNotesPerOctave
Number of semitones per octave.
Definition common.h:51
float mono_float
Definition common.h:33
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
static force_inline poly_mask vector_call lessThan(poly_float one, poly_float two)
Definition poly_values.h:1105
static force_inline simd_type vector_call min(simd_type one, simd_type two)
Returns the element-wise minimum of two SIMD float registers.
Definition poly_values.h:920
static force_inline simd_type vector_call max(simd_type one, simd_type two)
Returns the element-wise maximum of two SIMD float registers.
Definition poly_values.h:904
static force_inline simd_type vector_call abs(simd_type value)
Computes the absolute value of each element in the SIMD float register.
Definition poly_values.h:935
static force_inline simd_type vector_call mulAdd(simd_type one, simd_type two, simd_type three)
Fused multiply-add operation: one = one + (two * three).
Definition poly_values.h:779
force_inline void vector_call set(size_t index, float new_value) noexcept
Sets a specific element in the SIMD register.
Definition poly_values.h:1182
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56