Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637/** * fft.js, typed. * * The package ships `lib/fft.d.ts`, and it is `size: any`, `createComplexArray(): any[]` * — generated from the JS rather than written against it, so it permits anything and * describes nothing. That matters more here than it usually would: `realTransform` will * only accept `Float64Array` storage (the arrays it reads are indexed as doubles, and * handing it the plain `Array` from `createComplexArray` would make the innermost loop of * the fingerprint the slowest thing in it), and an `any` signature is exactly what lets * that mistake compile, run, and show up only as a number that looks a bit slow. * * So: fifteen lines for the three members actually used, and they are checked by the * tone-vs-direct-DFT test in detect.test.ts rather than by confidence. fft.js is verified * against the definition on pure tones; the hand-rolled radix-2 that predates it ran at a * plausible 26 ms, printed plausible peaks, and was wrong by up to 400× — nothing about * its output said so. That is the argument for the dependency, and it is also the * argument for the test being in the repo whichever transform is in use. * * An ambient declaration wins over the package's own for `import FFT from "fft.js"`, so * this is the whole of the typing, and there is no `@ts-expect-error` anywhere near it. */declare module "fft.js" { /** Radix-4 FFT over a power-of-two length; frozen since Jan 2021, which for this is * not the alarm it usually is. MIT, no dependencies, ~500 lines. */ export default class FFT { /** throws unless `size` is a power of two ≥ 2 */ constructor(size: number); readonly size: number; /** * The real-signal transform: `size` samples in, `size` complex values (2·size * interleaved re/im doubles) out — which is all of a one-sided spectrum, so the * upper half of `out` is not written and must not be read. */ realTransform(out: Float64Array, data: Float64Array): void; }}