Skip to main content

Crate rill_fft

Crate rill_fft 

Source
Expand description

§Rill FFT

Fast Fourier Transform and frequency-domain signal processing for the Rill ecosystem.

§Modules

ModuleKey typesPurpose
complex_fftComplexFft<T>Radix-2 DIT complex FFT (forward + inverse)
real_fftRealFft<T>Real-valued FFT via half-size complex packing
overlap_addOverlapAddConvolver<T, BUF>Frequency‑domain convolution (medium IRs)
partitioned_convPartitionedConvolver<T, BUF>Partitioned convolution (long IRs)
spectrumFftSpectrumAnalyzer<T>FFT‑based spectrum analyser
effectsSpectralGate, SpectralDelayFrequency‑domain effects
nodesConvolverNodeGraph‑node wrappers

§RT safety

All scratch buffers (twiddle tables, delay lines, overlap buffers) are pre‑allocated in constructors. process() methods perform zero heap allocations — verified by a custom panic‑on‑alloc tests in tests/rt_safety.rs.

§Performance (f32, x86_64, release profile)

OperationSizeTimeThroughput
ComplexFft::forward10246.7 µs153 Melem/s
RealFft::forward10246.2 µs165 Melem/s
ComplexFft::forward16384177 µs92 Melem/s
OverlapAddConvolverIR 2048, BUF 12861 µs/block~2100 blocks/s
PartitionedConvolverIR 65536, BUF 128104 µs/block~9600 blocks/s
DirectConvolver128 taps, BUF 12810 µs/block12.7 Melem/s

§f64 precision

OperationSizeTimeThroughput
ComplexFft::forward10247.9 µs129 Melem/s
ComplexFft::forward409639.7 µs103 Melem/s
ComplexFft::forward819293.5 µs88 Melem/s

f64 is ~15–20 % slower than f32, consistent with double‑width memory and cache pressure. 64‑bit transforms are still well within the real‑time budget for typical block sizes.

At 44.1 kHz with block size 128 the per‑block budget is ~2.9 ms. All operations fit comfortably within the real‑time budget.

§Examples

§Complex FFT

use rill_fft::complex_fft::ComplexFft;
use num_complex::Complex;

let fft = ComplexFft::<f32>::new(1024);
let mut data: Vec<Complex<f32>> = (0..1024)
    .map(|i| Complex::new((i as f32 * 0.1).sin(), 0.0))
    .collect();

fft.forward(&mut data);
// ... manipulate spectrum ...
fft.inverse(&mut data);

§Convolution

use rill_fft::partitioned_conv::PartitionedConvolver;

// IR length 16384 samples, BUF_SIZE = 128
let mut conv = PartitionedConvolver::<f32, 128>::new(16384);

// Load impulse response (e.g., from a WAV file)
let ir: Vec<f32> = vec![0.0; 16384];
conv.set_ir(&ir);

// Process audio blocks in the signal thread
let input = [0.5f32; 128];
let mut output = [0.0f32; 128];
conv.process(&input, &mut output);

§Spectral gate

use rill_fft::effects::spectral_gate::SpectralGate;

let mut gate = SpectralGate::<f32, 128>::new();
gate.set_threshold(0.01);
gate.set_ratio(0.0);  // hard gate below threshold

let input = [0.5f32; 128];
let mut output = [0.0f32; 128];
gate.process(&input, &mut output);

§Features

  • Generic over T: Transcendental (f32, f64)
  • SIMD acceleration behind simd feature flag (via rill-core/wide)
  • #![deny(unsafe_code)] — pure safe Rust

Modules§

complex_fft
Radix-2 complex FFT (forward and inverse) using Decimation-In-Time (DIT).
effects
Frequency-domain effects built on real FFT.
overlap_add
Overlap-add convolution using real FFT.
partitioned_conv
Partitioned frequency-domain convolution for long impulse responses.
prelude
Prelude for convenient imports.
real_fft
Real-valued FFT using a complex FFT with packing/unpacking.
register
Register graph nodes and lang builtins for FFT.
spectrum
FFT-based spectrum analyzer.