/** * Fast Fourier Transform using Cooley-Tukey algorithm (radix-2, iterative). * * Zero-padding contract: this is a radix-2 transform, so inputs whose length * is not already a power of 2 are zero-padded UP to the next power of 2. The * returned spectrum therefore has `2**ceil(log2(N))` bins, which for a * non-power-of-2 input is LONGER than the input. This padding is intentional * (not a silent best-guess): pass a power-of-2-length signal to get a spectrum * of exactly that length, or account for the padded length in the caller. * * Non-finite policy: NaN/Infinity in the input throws with the offending * index — corrupted audio is never laundered into a plausible spectrum. * * @param {Float32Array|Array} signal - Input signal * @returns {Array} FFT result as complex numbers; length = next power of 2 >= N */ export function fft(signal: Float32Array | any[]): any[]; /** * Inverse Fast Fourier Transform (complex input preserved — no component discarded) * ifft(X) = conj(fft(conj(X))) / N * * Non-finite policy: a missing bin or a bin with NaN/Infinity components * throws with the offending index (the old recursive implementation silently * treated missing bins as 0). * * @param {Array<{real: number, imag: number}>} spectrum - Complex spectrum (power-of-2 length) * @returns {Array<{real: number, imag: number}>} IFFT result */ export function ifft(spectrum: Array<{ real: number; imag: number; }>): Array<{ real: number; imag: number; }>; /** * Short-Time Fourier Transform * @param {Float32Array} y - Audio signal * @param {number} n_fft - FFT window size * @param {number} hop_length - Hop length (default: n_fft/4) * @param {number} win_length - Window length (default: n_fft) * @param {string} window - Window type * @param {boolean} center - Whether to center the signal * @param {string} pad_mode - Padding mode ('reflect', 'constant', 'edge') * @returns {Array} STFT matrix [freq, time] */ export function stft(y: Float32Array, n_fft?: number, hop_length?: number, win_length?: number, window?: string, center?: boolean, pad_mode?: string): any[]; /** * Power spectrogram computed frame-by-frame on flat arrays — the memory-lean * path for feature extractors (melspectrogram, onset strength, beat tracking) * that only need |STFT|^power. Unlike stft(), no per-bin {real, imag} objects * are ever created: a 10-minute 44.1 kHz track yields ~53M bins, and boxing * them costs ~4 GB of heap that feature pipelines never look at. * * Same framing, windowing, padding, and numerics as stft(). * * @param {Float32Array} y - Audio signal * @param {number} n_fft - FFT window size * @param {number} hop_length - Hop length (default: n_fft/4) * @param {number} win_length - Window length (default: n_fft) * @param {string} window - Window type * @param {boolean} center - Whether to center the signal * @param {string} pad_mode - Padding mode ('reflect', 'constant', 'edge') * @param {number} power - Exponent applied to the magnitude (2.0 = power) * @returns {Array} Power spectrogram [freq][time] */ export function stft_power(y: Float32Array, n_fft?: number, hop_length?: number, win_length?: number, window?: string, center?: boolean, pad_mode?: string, power?: number): Array; /** * Inverse Short-Time Fourier Transform * @param {Array} D - STFT matrix [freq, time] * @param {number} hop_length - Hop length (default: n_fft/4) * @param {number} win_length - Window length (default: n_fft) * @param {string} window - Window type * @param {boolean} center - Whether signal was centered * @param {number} length - Expected output length (optional) * @returns {Float32Array} Reconstructed signal */ export function istft(D: any[], hop_length?: number, win_length?: number, window?: string, center?: boolean, length?: number): Float32Array; /** * Get window function * @param {string} window_type - Window type (one of SUPPORTED_WINDOWS) * @param {number} n_fft - Window length * @returns {Float32Array} Window function * @throws {Error} if window_type is not supported (no silent fallback to hann) */ export function get_window(window_type: string, n_fft: number): Float32Array; /** * Hann window * @param {number} n - Window length * @returns {Float32Array} Hann window */ export function hann_window(n: number): Float32Array; /** * Hamming window * @param {number} n - Window length * @returns {Float32Array} Hamming window */ export function hamming_window(n: number): Float32Array; /** * Blackman window * @param {number} n - Window length * @returns {Float32Array} Blackman window */ export function blackman_window(n: number): Float32Array; /** * Magnitude of complex spectrum * @param {Array} spectrum - Complex spectrum * @returns {Float32Array} Magnitude spectrum */ export function magnitude(spectrum: any[]): Float32Array; /** * Phase of complex spectrum * @param {Array} spectrum - Complex spectrum * @returns {Float32Array} Phase spectrum */ export function phase(spectrum: any[]): Float32Array; /** * Power spectrum * @param {Array} spectrum - Complex spectrum * @returns {Float32Array} Power spectrum */ export function power(spectrum: any[]): Float32Array; /** * Convert magnitude and phase to complex spectrum * @param {Array} magnitude - Magnitude spectrum * @param {Array} phase - Phase spectrum * @returns {Array} Complex spectrum */ export function polar_to_complex(magnitude: any[], phase: any[]): any[]; /** * FFT frequencies * @param {number} sr - Sample rate * @param {number} n_fft - FFT size * @returns {Float32Array} Frequency bins */ export function fft_frequencies(sr: number, n_fft: number): Float32Array; /** * Simple spectrogram computation * @param {Float32Array} y - Audio signal * @param {number} n_fft - FFT size * @param {number} hop_length - Hop length * @returns {Array} Magnitude spectrogram */ export function spectrogram(y: Float32Array, n_fft?: number, hop_length?: number): any[];