/* Windowed real FFT for the short-time transform stage. * * The model's stored transform is a dense [2*bins][n_fft] basis whose rows are * w[n]cos(2*pi*f*n/n_fft) and -w[n]sin(2*pi*f*n/n_fft) with w the periodic Hann * window (tools/export_weights.py verifies this on every export). The stage * therefore computes exactly the magnitude spectrum of the windowed frame, and * an FFT computes the same quantity in O(n log n) instead of O(n * bins): * 264K multiply-accumulates per 16 kHz chunk become about 24K floating point * operations. It is the same transform, not an approximation of it, so only * rounding differs. * * A real transform of length n_fft is evaluated as a complex transform of * length n_fft/2 over the even/odd split, followed by the standard untangle * step. Only magnitudes are returned, so the sign convention of the imaginary * part is irrelevant. */ #ifndef SVAD_RFFT_H #define SVAD_RFFT_H #include #define SVAD_RFFT_MAX_N 128 /* complex length, = max n_fft / 2 */ /* Scratch floats svad_rfft_mag needs; sized for the batched SIMD path. */ #define SVAD_RFFT_SCRATCH (8 * SVAD_RFFT_MAX_N) typedef struct { int n; /* complex transform length, n_fft / 2 */ int simd; /* use the batched SIMD path when available */ uint16_t rev[SVAD_RFFT_MAX_N]; /* bit-reversal permutation */ float tw[2 * SVAD_RFFT_MAX_N]; /* per-stage butterfly twiddles */ float post[2 * (SVAD_RFFT_MAX_N + 1)]; /* untangle twiddles */ } svad_rfft; void svad_rfft_init(svad_rfft *f, int n_fft, int simd); /* Magnitude spectra of `frames` windows taken from x at the given hop, each * multiplied by `window` first. Writes frames * (n_fft/2 + 1) magnitudes as * out[t * out_stride + bin]. */ void svad_rfft_mag(const svad_rfft *f, const float *x, int hop, int frames, const float *window, float *out, int out_stride, float *scratch); #endif /* SVAD_RFFT_H */