fftw
fftw copied to clipboard
Planer: non-mutable reference enables threading
The plan is not modified by ..._execute_dft
and alike (see https://www.fftw.org/fftw3_doc/Thread-safety.html)
Thus we can pass the plan &self
by constant reference.
This enables multiple threaded ffts from the same plan.
let mut fft2_r2c = R2CPlan32::aligned(&[window_size, window_size], Flag::ESTIMATE).unwrap();
let mut fft2_c2r = C2RPlan32::aligned(&[window_size, window_size], Flag::ESTIMATE).unwrap();
frames
.par_iter_mut()
.for_each(|(_frame, window_data)| unsafe {
let frame_shape = [window_data.shape()[0], window_data.shape()[1]];
let mut window_data_fft = AlignedVec::new((window_size / 2 + 1) * window_size);
let mut window_data_slice = window_data.as_slice_mut().unwrap();
fft2_r2c
.r2c(&mut window_data_slice, &mut window_data_fft)
.unwrap();
});