/** * Trim leading and trailing silence from an audio signal. * * @param {Float32Array} y - Mono audio signal * @param {Object} [options] * @param {number} [options.top_db=60] - Threshold (dB) below reference to call silence * @param {number|Function|null} [options.ref=null] - Reference amplitude; default max frame RMS * @param {number} [options.frame_length=2048] * @param {number} [options.hop_length=512] * @returns {[Float32Array, number[]]} [y_trimmed, [start, end]] with * y_trimmed === y.slice(start, end). All-silent input yields an EMPTY * slice ([0, 0]). */ export function trim(y: Float32Array, { top_db, ref, frame_length, hop_length }?: { top_db?: number; ref?: number | Function | null; frame_length?: number; hop_length?: number; }): [Float32Array, number[]]; /** * Split an audio signal into non-silent intervals. * Frame-edge sample indices, capped to y.length. * * @param {Float32Array} y - Mono audio signal * @param {Object} [options] - Same options as trim() * @returns {Array} Array of [start, end) sample intervals; [] when all-silent */ export function split(y: Float32Array, { top_db, ref, frame_length, hop_length }?: any): Array; /** * Pre-emphasis filter y[n] = x[n] - coef*x[n-1], including its exact zi * handling: zi is the raw lfilter delay state, so out[0] = x[0] + zi, and the * default zi = 2*x[0] - x[1] (verified against the fixture). * * @param {Float32Array} y - Audio signal (>= 2 samples when zi is defaulted) * @param {Object} [options] * @param {number} [options.coef=0.97] * @param {number|null} [options.zi=null] - Initial filter state; chain blocks by passing the previous zf * @param {boolean} [options.return_zf=false] * @returns {Float32Array|[Float32Array, number]} Filtered signal, or [signal, zf] */ export function preemphasis(y: Float32Array, { coef, zi, return_zf }?: { coef?: number; zi?: number | null; return_zf?: boolean; }): Float32Array | [Float32Array, number]; /** * De-emphasis filter x[n] = y[n] + coef*x[n-1] — exact inverse of * preemphasis() including the default-zi extrapolation correction, * so deemphasis(preemphasis(x)) round-trips to x. * * @param {Float32Array} y - Pre-emphasized signal * @param {Object} [options] - Same options as preemphasis() * @returns {Float32Array|[Float32Array, number]} Filtered signal, or [signal, zf] */ export function deemphasis(y: Float32Array, { coef, zi, return_zf }?: any): Float32Array | [Float32Array, number]; /** * Remix an audio signal by re-ordering time intervals. * Intervals are concatenated in CALLER ORDER * (no sorting — reordering, e.g. beat reversal, is the whole point) and, by * default, interval boundaries snap to the nearest zero crossing of the * whole signal (match_events semantics), never shrinking segments * to their internal crossings. * * @param {Float32Array} y - Mono audio signal * @param {Array} intervals - [start, end) sample intervals, any order * @param {Object} [options] * @param {boolean} [options.align_zeros=true] - Snap boundaries to zero crossings of y * @returns {Float32Array} Concatenation of the (aligned) segments in caller order * @throws {Error} On out-of-bounds or non-finite interval endpoints */ export function remix(y: Float32Array, intervals: Array, { align_zeros }?: { align_zeros?: boolean; }): Float32Array; /** * Phase vocoder: time-stretch an STFT matrix by `rate`. * Ellis 2002 formulation: * phi_advance = linspace(0, π*hop_length, 1 + n_fft/2); phase accumulates * from column 0's phase; the DEVIATION (dphase - phi_advance) is wrapped to * (-π, π]; input is padded with 2 zero columns for the boundary. * * @param {Array>} D - STFT matrix [freq][time] * @param {number} rate - Speed-up factor (> 1 faster, < 1 slower) * @param {Object} [options] * @param {number|null} [options.hop_length=null] - Defaults to n_fft/4 * @param {number|null} [options.n_fft=null] - Defaults to 2*(D.length - 1) * @returns {Array>} Stretched STFT [freq][ceil(time/rate)] * @throws {Error} When rate <= 0 or D is empty */ export function phase_vocoder(D: Array>, rate: number, { hop_length, n_fft }?: { hop_length?: number | null; n_fft?: number | null; }): Array>; /** * Time-stretch an audio series by a fixed rate (pitch-preserving). * Pipeline: stft → phase_vocoder → istft with * output length round(n / rate). * * @param {Float32Array} y - Audio signal * @param {number} rate - Stretch factor (> 1 speeds up, < 1 slows down) * @param {Object} [options] - STFT parameters * @param {number} [options.n_fft=2048] * @param {number|null} [options.hop_length=null] - Defaults to n_fft/4 * @param {number|null} [options.win_length=null] * @param {string} [options.window='hann'] * @param {boolean} [options.center=true] * @param {string} [options.pad_mode='constant'] * @returns {Float32Array} Stretched audio, length round(y.length / rate) * @throws {Error} When rate <= 0 */ export function time_stretch(y: Float32Array, rate: number, { n_fft, hop_length, win_length, window, center, pad_mode, }?: { n_fft?: number; hop_length?: number | null; win_length?: number | null; window?: string; center?: boolean; pad_mode?: string; }): Float32Array; /** * Shift the pitch of a waveform by n_steps steps (duration preserved). * Recipe: * rate = 2^(-n_steps/bins_per_octave); resample(time_stretch(y, rate), * sr/rate → sr); fix_length to the input size. * * QUALITY NOTE: the resampling stage uses pleco's linear-interpolation * resample (xa-audioio.js) — no high-quality anti-aliasing filter. Downward * shifts (upsampling) are clean; upward shifts * can alias above ~sr/(2*rate). This is a documented fidelity limit of the * current resampler, not a silent fallback. * * @param {Float32Array} y - Audio signal * @param {number} sr - Sample rate of y * @param {number} n_steps - Steps to shift (may be fractional; 12 steps = 1 octave by default) * @param {Object} [options] * @param {number} [options.bins_per_octave=12] - Positive integer * @param {number} [options.n_fft=2048] - And the other time_stretch STFT options * @returns {Float32Array} Pitch-shifted audio, same length as y * @throws {Error} When bins_per_octave is not a positive integer */ export function pitch_shift(y: Float32Array, sr: number, n_steps: number, { bins_per_octave, ...stretchOptions }?: { bins_per_octave?: number; n_fft?: number; }): Float32Array; /** * Decompose an audio time series into harmonic and percussive components. * Pipeline: stft → decompose.hpss (masked components) * → istft with length matched to the input, so harmonic + percussive ≈ y * at margin=1. * * @param {Float32Array} y - Audio signal * @param {Object} [options] * @param {number|Array} [options.kernel_size=31] * @param {number} [options.power=2.0] * @param {number|Array} [options.margin=1.0] * @param {number} [options.n_fft=2048] * @param {number|null} [options.hop_length=null] - defaults to n_fft/4 * @param {number|null} [options.win_length=null] - defaults to n_fft * @param {string} [options.window='hann'] * @param {boolean} [options.center=true] * @param {string} [options.pad_mode='constant'] * @returns {{harmonic: Float32Array, percussive: Float32Array}} Both length y.length */ export function hpss(y: Float32Array, { kernel_size, power, margin, n_fft, hop_length, win_length, window, center, pad_mode, }?: { kernel_size?: number | Array; power?: number; margin?: number | Array; n_fft?: number; hop_length?: number | null; win_length?: number | null; window?: string; center?: boolean; pad_mode?: string; }): { harmonic: Float32Array; percussive: Float32Array; }; /** * Extract only the harmonic component of a waveform. * @param {Float32Array} y - Audio signal * @param {Object} [options] - Same options as hpss() * @returns {Float32Array} Harmonic component, length y.length */ export function harmonic(y: Float32Array, options?: any): Float32Array; /** * Extract only the percussive component of a waveform. * @param {Float32Array} y - Audio signal * @param {Object} [options] - Same options as hpss() * @returns {Float32Array} Percussive component, length y.length */ export function percussive(y: Float32Array, options?: any): Float32Array;