diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-10-08 06:49:33 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-10-08 07:21:37 +0200 |
| commit | a5af9c3d351085f4005a949f8c382a3aad4e0b29 (patch) | |
| tree | 0ad133d931553e68a68588e983976a66b3309083 /rfft.h | |
| download | svad-0.1.0.tar.gz svad-0.1.0.zip | |
initv0.1.0
Diffstat (limited to 'rfft.h')
| -rw-r--r-- | rfft.h | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -0,0 +1,49 @@ +/* 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 <stdint.h> + +#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 */ |
