|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
Math for the audio stack. More...
Math for the audio stack.
Namespaces | |
| namespace | sinc16 |
| Generated residual polynomials of the Sinc16 BLEP kernel. | |
Classes | |
| struct | BlepResidual |
| A kernel's corrections for the N frames it touches, oldest first. More... | |
| struct | Bspline4 |
| The cubic B-spline over four frames, two before the event and two after. More... | |
| struct | Linear2 |
| The triangular kernel over two frames, one before the event and one after: Plaits' polyBLEP. More... | |
| struct | Sinc16 |
| A Kaiser-windowed sinc over sixteen frames, eight before the event and eight after. More... | |
Functions | |
| 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. | |
| void | crossfade_equal_power (const float *a, const float *b, float *out, float mix, uint16_t frames) |
| Equal-power crossfade over a buffer with constant mix. | |
| float | exp_mod (float base, float mod, float depth, float lo=DEFAULT_LO_HZ, float hi=DEFAULT_HI_HZ) |
| Apply exponential modulation to a base frequency (scalar). | |
| void | exp_mod (const float *mod, float *freq_out, uint16_t frames, float base, float depth, float lo=DEFAULT_LO_HZ, float hi=DEFAULT_HI_HZ) |
| Apply exponential modulation to a buffer. | |
| float | fast_sinf (float x) |
| Fast sine approximation for x in [0, pi/2]. | |
| float | fast_tan_pif (float f) |
| Fast tan(pi f) for normalized frequency f in [0, 0.497]. | |
| float | fast_exp2f (float x) |
| Fast 2^x approximation for exponential modulation. | |
| float | fast_tanhf (float x) |
| Fast tanh approximation using a [3,2] Pade approximant. | |
| constexpr float | one_minus_exp_neg (float x) |
| 1 - e^(-x) by inverse Taylor, with no expf | |
| float | db_to_gain (float db) |
| Amplitude gain for a level in dB: 10^(db / 20). | |
| float | gain_to_db (float gain) |
| Level in dB for an amplitude gain. | |
| float | level_gain (float level, float range_db) |
| The level taper: a level in [0, 1] to a gain. | |
| float | ratio_from_octaves (float octaves) |
| The frequency ratio of an interval: 2^octaves. | |
| float | octaves_from_ratio (float ratio) |
| The interval of a frequency ratio, in octaves: log2(ratio). | |
| float | frequency (float reference, float octaves) |
| A reference frequency moved by an interval in octaves. | |
| constexpr float | polyblep_time (float before, float after, float threshold_before, float threshold_after) |
| Sub-frame time at which a linear segment crossed a moving threshold. | |
| constexpr float | polyblep_time (float before, float after, float threshold) |
| Sub-frame time at which a linear segment crossed a fixed threshold. | |
Variables | |
| constexpr float | DEFAULT_LO_HZ = 20.0f |
| constexpr float | DEFAULT_HI_HZ = 20000.0f |
| constexpr float | FAST_TAN_PIF_MAX_F = 0.497f |
| constexpr float | EXP2_MAX_ARG = 16.0f |
| constexpr int32_t | FLOAT_MANTISSA_BITS = 23 |
| constexpr float | TANH_SATURATE_X = 3.0f |
| constexpr float | DB_PER_DOUBLING = 6.0206f |
| constexpr float | POLYBLEP_T_MAX = 0.99999994f |
| The largest float below 1, the upper bound of a sub-frame time. | |
|
inline |
Equal-power crossfade between two values.
Maintains constant power across the fade (no dip at t=0.5). Returns a*sqrt(1-t) + b*sqrt(t), with sqrtf.
| a | Value at t=0 (dry) |
| b | Value at t=1 (wet) |
| t | Blend factor in [0, 1] (not clamped) |
Definition at line 33 of file crossfade.hpp.
|
inline |
Equal-power gains for a crossfade with a zone at each end.
The gains are the cosine and sine of a quarter turn, so their squares sum to 1. Within end_zone of either end of t's travel the nearer side's gain is exactly 1 and the other's exactly 0, so a control resting near an end, or a CV with a small offset, leaves none of the other side in.
| t | Blend factor in [0, 1]; the scaled position is clamped, and a NaN gives the t=0 side | |
| end_zone | The share of t's travel at each end held at one side, in [0, 0.5) | |
| [out] | gain_a | Gain of the side at t=0, in [0, 1] |
| [out] | gain_b | Gain of the side at t=1, in [0, 1] |
Definition at line 48 of file crossfade.hpp.
References sbl::math::clamp(), and sbl::math::PI.
|
inline |
Linear crossfade over a buffer with constant mix.
out[i] = a[i] * (1-mix) + b[i] * mix. In-place safe (out can alias a or b).
| a | Buffer at mix=0, frames long | |
| b | Buffer at mix=1, frames long | |
| [out] | out | Output buffer, frames long |
| mix | Blend factor in [0, 1] (not clamped) | |
| frames | Frame count |
Definition at line 69 of file crossfade.hpp.
|
inline |
Equal-power crossfade over a buffer with constant mix.
out[i] = a[i] * sqrt(1-mix) + b[i] * sqrt(mix). Gains computed once. In-place safe (out can alias a or b).
| a | Buffer at mix=0, frames long | |
| b | Buffer at mix=1, frames long | |
| [out] | out | Output buffer, frames long |
| mix | Blend factor in [0, 1] (not clamped) | |
| frames | Frame count |
Definition at line 89 of file crossfade.hpp.
|
inline |
Apply exponential modulation to a base frequency (scalar).
Converts a normalized modulation signal to a frequency via freq = base * 2^(mod * depth).
At depth = 2.0 and mod = 1.0, output is base * 4 (2 octaves up). At depth = 2.0 and mod = -1.0, output is base / 4 (2 octaves down). Equal steps in mod give equal intervals at any base frequency.
| base | Center frequency in Hz (e.g., filter cutoff) |
| mod | Normalized modulation value, typically [-1.0, 1.0] |
| depth | Modulation depth in octaves (e.g., 2.0 = +/-2 octaves) |
| lo | Minimum output frequency in Hz (default 20) |
| hi | Maximum output frequency in Hz (default 20000) |
Definition at line 49 of file exp_mod.hpp.
References fast_exp2f().
Referenced by exp_mod().
|
inline |
Apply exponential modulation to a buffer.
Writes the scalar exp_mod() of each frame's mod to freq_out[].
| mod | Normalized modulation signal buffer, typically [-1.0, 1.0] | |
| [out] | freq_out | Output frequency buffer (Hz) |
| frames | Frame count | |
| base | Center frequency in Hz | |
| depth | Modulation depth in octaves | |
| lo | Minimum output frequency in Hz (default 20) | |
| hi | Maximum output frequency in Hz (default 20000) |
Definition at line 74 of file exp_mod.hpp.
References exp_mod().
|
inline |
Fast sine approximation for x in [0, pi/2].
Uses the 5th-order Taylor series x - x^3/6 + x^5/120.
Absolute error, which grows with x:
| x | Input angle in radians, in [0, pi/2] (not checked) |
Definition at line 45 of file fast_math.hpp.
|
inline |
Fast tan(pi f) for normalized frequency f in [0, 0.497].
[5,4] Pade approximant of tan(x) evaluated at x = pi f:
Unlike a polynomial, the rational function models the pole at f = 0.5 (Nyquist): its denominator goes to zero near x = pi/2.
Relative error against tan(pi f), which grows with f:
| f | Normalized frequency (freq_hz / sample_rate), in [0, 0.497] (not checked) |
Definition at line 73 of file fast_math.hpp.
References sbl::math::PI.
Referenced by sbl::dsp::Svf::integrator_gain_for().
|
inline |
Fast 2^x approximation for exponential modulation.
Decomposes x into integer and fractional parts. The integer part is applied by shifting the IEEE 754 exponent field (exact). The fractional part uses a 4th-order polynomial.
Accuracy against std::exp2f:
| x | Exponent, e.g. +/-2.0 for +/-2 octaves of modulation |
Definition at line 101 of file fast_math.hpp.
References EXP2_MAX_ARG, and FLOAT_MANTISSA_BITS.
Referenced by exp_mod().
|
inline |
Fast tanh approximation using a [3,2] Pade approximant.
tanh(x) ~= x (27 + x^2) / (27 + 9 x^2) for |x| <= 3. Inputs outside +/-3 return +/-1, and a NaN returns 0. Max relative error 2.6%, near |x| = 1.45. SoftLimiter bends its excess over a knee with it.
| x | Input value, any range |
Definition at line 145 of file fast_math.hpp.
References TANH_SATURATE_X.
Referenced by sbl::dsp::SoftLimiter::limit().
|
inlineconstexpr |
1 - e^(-x) by inverse Taylor, with no expf
Gives a one-pole coefficient from a time constant or a cutoff.
| x | Argument, at or above 0 |
Definition at line 168 of file fast_math.hpp.
|
inline |
Amplitude gain for a level in dB: 10^(db / 20).
| db | Level in dB |
Definition at line 26 of file gain.hpp.
References DB_PER_DOUBLING.
Referenced by level_gain().
|
inline |
|
inline |
The level taper: a level in [0, 1] to a gain.
Exponential over range_db, shifted so 0 is silence and 1 is unity:
Halfway is close to -r/2 dB. A range of 0 or less is the linear taper.
| level | Level in [0, 1], clamped; a non-finite level counts as 0 |
| range_db | Range of the taper in dB; 0 or less selects the linear taper |
Definition at line 49 of file gain.hpp.
References db_to_gain().
Referenced by sbl::dsp::Vca::process().
|
inline |
|
inline |
The interval of a frequency ratio, in octaves: log2(ratio).
| ratio | Frequency ratio, above 0 |
Definition at line 43 of file pitch.hpp.
Referenced by sbl::dsp::PmPulse::set_tune().
|
inline |
A reference frequency moved by an interval in octaves.
| reference | Reference frequency, in Hz or cycles per frame |
| octaves | Interval in octaves |
Definition at line 52 of file pitch.hpp.
Referenced by sbl::dsp::pm_frequency().
|
constexpr |
Sub-frame time at which a linear segment crossed a moving threshold.
A value went from before to after over one frame while the threshold went from threshold_before to threshold_after; the caller knows the segment crossed. Returns the fraction of the frame elapsed since the crossing, read at after: t = (after - th_after) / ((after - before) - (th_after - th_before)). A moving threshold is a pulse edge under PWM.
| before | Value at the frame before |
| after | Value at the frame after |
| threshold_before | Threshold at the frame before |
| threshold_after | Threshold at the frame after |
Definition at line 242 of file polyblep.hpp.
References POLYBLEP_T_MAX.
Referenced by polyblep_time(), and sbl::dsp::BlepOsc< Kernel >::process().
|
constexpr |
Sub-frame time at which a linear segment crossed a fixed threshold.
For a phase wrap, pass the phase before the wrap less one cycle as before, the wrapped phase as after and 0 as the threshold.
| before | Value at the frame before |
| after | Value at the frame after |
| threshold | Threshold for both frames |
Definition at line 263 of file polyblep.hpp.
References polyblep_time().
|
inlineconstexpr |
Default low output bound, in Hz
Definition at line 28 of file exp_mod.hpp.
|
inlineconstexpr |
Default high output bound, in Hz
Definition at line 29 of file exp_mod.hpp.
|
inlineconstexpr |
fast_tan_pif is valid below this normalized frequency
Definition at line 25 of file fast_math.hpp.
|
inlineconstexpr |
|
inlineconstexpr |
Mantissa width of an IEEE 754 single
Definition at line 27 of file fast_math.hpp.
Referenced by fast_exp2f().
|
inlineconstexpr |
fast_tanhf returns +/-1 beyond this
Definition at line 28 of file fast_math.hpp.
Referenced by fast_tanhf().
|
inlineconstexpr |
|
inlineconstexpr |
The largest float below 1, the upper bound of a sub-frame time.
Definition at line 41 of file polyblep.hpp.
Referenced by polyblep_time().