Skip to main content

Module simd

Module simd 

Source
Expand description

Portable SIMD helper routines for buffer math.

Uses runtime CPU feature detection to dispatch:

  • AVX (f32x8) on x86_64/x86 when available
  • SSE (wide::f32x4) as fallback on x86_64/x86
  • Scalar loops on all other architectures

Functions§

add_inplace
dst[i] += src[i]
add_sanitized_inplace
dst[i] += sanitize_finite(src[i])
add_scaled_inplace
dst[i] += src[i] * gain
apply_fade_in_inplace
Apply a sine-based fade-in gain ramp in place: gain = sin(t * π/2). t for sample i is (start_t + i as f32 * dt).clamp(0.0, 1.0).
apply_fade_out_inplace
Apply a cosine-based fade-out gain ramp in place: gain = cos(t * π/2). t for sample i is (start_t + i as f32 * dt).clamp(0.0, 1.0).
clamp_inplace
Clamp every element to [min, max].
convert_f32_to_i8
Convert f32 samples to i8 and scale by gain. Uses truncation toward zero (matching Rust as i8). dst must be at least as long as src.
convert_f32_to_i16
Convert f32 samples to i16 and scale by gain. Uses truncation toward zero (matching Rust as i16). dst must be at least as long as src.
convert_f32_to_i24
Convert f32 samples to i32 and scale by gain, masking to lower 24 bits. Uses truncation toward zero (matching Rust as i32). dst must be at least as long as src.
convert_f32_to_i32
Convert f32 samples to i32 and scale by gain. Uses truncation toward zero (matching Rust as i32). dst must be at least as long as src.
convert_i8_to_f32
Convert i8 samples to f32 and scale by gain. dst must be at least as long as src.
convert_i16_to_f32
Convert i16 samples to f32 and scale by gain. dst must be at least as long as src.
convert_i24_to_f32
Convert i32 samples with lower 24 bits valid to f32 and scale by gain. Sign-extends the lower 24 bits of each i32 before conversion. dst must be at least as long as src.
convert_i32_to_f32
Convert i32 samples to f32 and scale by gain. dst must be at least as long as src.
copy_sanitized_inplace
dst[i] = sanitize_finite(src[i])
copy_scaled_inplace
dst[i] = src[i] * gain
mul_inplace
dst[i] *= gain
peak_abs
Horizontal max of abs(buf[i]).
sanitize_finite_inplace
Replace NaN / ±Inf with 0.0 in place.