Expand description
Vectorized transcendentals at audio-grade precision.
Each *_block op mirrors the shape of crate::ops: takes a
mutable output slice and a read-only input slice, writes
element-wise. Lengths are taken to min(out, src). Scalar
fallback is identical math; the SIMD path uses wide’s
sleef-derived approximations.
Why these and not a full math library: every truce plugin
converts dB to linear (gain, mix, send, peak) and most
waveshapers want a fast tanh. The rest (exp2, log2) come
along for free since they’re the building blocks of the first
two. We do not ship the wider set (sin, cos, erf,
lgamma); plugins that need those pull wide directly or use
simdeez / sleef.
§Error bounds
db_to_linear_block,linear_to_db_block: < 0.1 dB across the audio range[-120, +24]dB. Round-trip through linear→dB→linear stays within 1 part in 10^6 (verified by the fuzz test).exp2_block,log2_block: < 1 ULP for inputs in[-126, +127](exp2) and[2^-126, 2^127](log2). NaN / negative log2 inputs return NaN.tanh_block: exp-identity form viawide::exp, < 5e-6 absolute error vsf32::tanhacross[-10, +10]. Inputs outside that range clamp first; at|x| = 10, truetanhis already within 5e-9 of±1.
Functions§
- db_
to_ linear_ block out[i] = 10^(src[i] / 20). The dB → linear conversion every gain knob needs.- db_
to_ linear_ block_ scalar - Scalar fallback for
db_to_linear_block. Keptpubso Criterion benches can hand the same inputs to the scalar and vector paths. - exp2_
block out[i] = 2^src[i]. The building block forexpanddb_to_linear.- exp2_
block_ scalar - Scalar fallback for
exp2_block. - linear_
to_ db_ block out[i] = 20 * log10(src[i]). Linear → dB. Returns-f32::INFINITYfor zero input (matchesf32::log10).- linear_
to_ db_ block_ scalar - Scalar fallback for
linear_to_db_block. - log2_
block out[i] = log2(src[i]). Building block for log10 andlinear_to_db.- log2_
block_ scalar - Scalar fallback for
log2_block. - tanh_
block out[i] = tanh(src[i]). For soft-clipping waveshapers and any other DSP that wants a bounded sigmoid.- tanh_
block_ scalar - Scalar fallback for
tanh_block. Uses libm’stanh(full precision) rather than the Padé approximant; the SIMD path’s approximation is the cost of vector throughput, and the scalar path doesn’t pay that cost.