UNPKG

meyda

Version:

Real-time feature extraction for the web audio api

21 lines (18 loc) 530 B
import { mu } from "./extractorUtilities"; export default function ({ ampSpectrum, }: { ampSpectrum: Float32Array; }): number { if (typeof ampSpectrum !== "object") { throw new TypeError(); } var ampspec = ampSpectrum; var mu1 = mu(1, ampspec); var mu2 = mu(2, ampspec); var mu3 = mu(3, ampspec); var mu4 = mu(4, ampspec); var numerator = -3 * Math.pow(mu1, 4) + 6 * mu1 * mu2 - 4 * mu1 * mu3 + mu4; var denominator = Math.pow(Math.sqrt(mu2 - Math.pow(mu1, 2)), 4); return numerator / denominator; }