aboutsummaryrefslogtreecommitdiff
path: root/rfft.h
diff options
context:
space:
mode:
Diffstat (limited to 'rfft.h')
-rw-r--r--rfft.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/rfft.h b/rfft.h
new file mode 100644
index 0000000..7cb3c50
--- /dev/null
+++ b/rfft.h
@@ -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 */