Comparing version 5.4.0-alpha.1 to 5.4.0
export default function ({ signal, previousSignal, bufferSize, }: { | ||
signal: Float32Array; | ||
previousSignal?: Float32Array; | ||
previousSignal: Float32Array; | ||
bufferSize: number; | ||
}): number; |
@@ -18,18 +18,6 @@ import rms from "./extractors/rms"; | ||
import spectralFlux from "./extractors/spectralFlux"; | ||
import { MeydaSignal } from "./main"; | ||
declare let buffer: (args: { | ||
signal: MeydaSignal; | ||
}) => MeydaSignal; | ||
declare let complexSpectrum: (args: { | ||
complexSpectrum: { | ||
real: number[]; | ||
imag: number[]; | ||
}; | ||
}) => { | ||
real: number[]; | ||
imag: number[]; | ||
}; | ||
declare let amplitudeSpectrum: (args: { | ||
ampSpectrum: Float32Array; | ||
}) => Float32Array; | ||
export { buffer, rms, energy, complexSpectrum, spectralSlope, spectralCentroid, spectralRolloff, spectralFlatness, spectralSpread, spectralSkewness, spectralKurtosis, amplitudeSpectrum, zcr, loudness, perceptualSpread, perceptualSharpness, powerSpectrum, mfcc, chroma, spectralFlux, }; | ||
import spectralCrest from "./extractors/spectralCrest"; | ||
declare let buffer: (args: any) => any; | ||
declare let complexSpectrum: (args: any) => any; | ||
declare let amplitudeSpectrum: (args: any) => any; | ||
export { buffer, rms, energy, complexSpectrum, spectralSlope, spectralCentroid, spectralRolloff, spectralFlatness, spectralSpread, spectralSkewness, spectralKurtosis, amplitudeSpectrum, zcr, loudness, perceptualSpread, perceptualSharpness, powerSpectrum, mfcc, chroma, spectralFlux, spectralCrest, }; |
@@ -18,2 +18,3 @@ import rms from "./extractors/rms"; | ||
import spectralFlux from "./extractors/spectralFlux"; | ||
import spectralCrest from "./extractors/spectralCrest"; | ||
var buffer = function (args) { | ||
@@ -28,2 +29,2 @@ return args.signal; | ||
}; | ||
export { buffer, rms, energy, complexSpectrum, spectralSlope, spectralCentroid, spectralRolloff, spectralFlatness, spectralSpread, spectralSkewness, spectralKurtosis, amplitudeSpectrum, zcr, loudness, perceptualSpread, perceptualSharpness, powerSpectrum, mfcc, chroma, spectralFlux, }; | ||
export { buffer, rms, energy, complexSpectrum, spectralSlope, spectralCentroid, spectralRolloff, spectralFlatness, spectralSpread, spectralSkewness, spectralKurtosis, amplitudeSpectrum, zcr, loudness, perceptualSpread, perceptualSharpness, powerSpectrum, mfcc, chroma, spectralFlux, spectralCrest, }; |
@@ -33,6 +33,7 @@ /** | ||
spectralSpread: number; | ||
spectralCrest: number; | ||
zcr: number; | ||
} | ||
export declare type MeydaWindowingFunction = "blackman" | "sine" | "hanning" | "hamming"; | ||
export declare type MeydaAudioFeature = "amplitudeSpectrum" | "chroma" | "complexSpectrum" | "energy" | "loudness" | "mfcc" | "perceptualSharpness" | "perceptualSpread" | "powerSpectrum" | "rms" | "spectralCentroid" | "spectralFlatness" | "spectralFlux" | "spectralKurtosis" | "spectralRolloff" | "spectralSkewness" | "spectralSlope" | "spectralSpread" | "zcr" | "buffer"; | ||
export declare type MeydaAudioFeature = "amplitudeSpectrum" | "chroma" | "complexSpectrum" | "energy" | "loudness" | "mfcc" | "perceptualSharpness" | "perceptualSpread" | "powerSpectrum" | "rms" | "spectralCentroid" | "spectralFlatness" | "spectralFlux" | "spectralKurtosis" | "spectralRolloff" | "spectralSkewness" | "spectralSlope" | "spectralSpread" | "spectralCrest" | "zcr" | "buffer"; | ||
/** | ||
@@ -43,3 +44,3 @@ * A type representing an audio signal. In general it should be an array of | ||
*/ | ||
export declare type MeydaSignal = number[] | Float32Array; | ||
export declare type MeydaSignal = SliceableArrayLike<number> | Float32Array; | ||
export interface SliceableArrayLike<T> extends ArrayLike<T> { | ||
@@ -199,2 +200,1 @@ slice(start: number, end: number): SliceableArrayLike<T>; | ||
export default Meyda; | ||
export * from "./new-extract"; |
@@ -205,2 +205,1 @@ /** | ||
window.Meyda = Meyda; | ||
export * from "./new-extract"; |
@@ -15,2 +15,8 @@ 'use strict'; | ||
function getDefaultExportFromCjs (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
var dct$2 = {exports: {}}; | ||
/*===========================================================================*\ | ||
@@ -59,4 +65,8 @@ * Discrete Cosine Transform | ||
var dct = dct_1; | ||
(function (module) { | ||
module.exports = dct_1; | ||
} (dct$2)); | ||
var dct = /*@__PURE__*/getDefaultExportFromCjs(dct$2.exports); | ||
function mfcc (_a) { | ||
@@ -63,0 +73,0 @@ var ampSpectrum = _a.ampSpectrum, melFilterBank = _a.melFilterBank, numberOfMFCCCoefficients = _a.numberOfMFCCCoefficients, bufferSize = _a.bufferSize; |
@@ -242,2 +242,8 @@ 'use strict'; | ||
function getDefaultExportFromCjs (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
var dct$2 = {exports: {}}; | ||
/*===========================================================================*\ | ||
@@ -286,4 +292,8 @@ * Discrete Cosine Transform | ||
var dct = dct_1; | ||
(function (module) { | ||
module.exports = dct_1; | ||
} (dct$2)); | ||
var dct = /*@__PURE__*/getDefaultExportFromCjs(dct$2.exports); | ||
function mfcc (_a) { | ||
@@ -358,2 +368,18 @@ var ampSpectrum = _a.ampSpectrum, melFilterBank = _a.melFilterBank, numberOfMFCCCoefficients = _a.numberOfMFCCCoefficients, bufferSize = _a.bufferSize; | ||
function spectralCrest (_a) { | ||
var ampSpectrum = _a.ampSpectrum; | ||
if (typeof ampSpectrum !== "object") { | ||
throw new TypeError(); | ||
} | ||
var rms = 0; | ||
var peak = -Infinity; | ||
ampSpectrum.forEach(function (x) { | ||
rms += Math.pow(x, 2); | ||
peak = x > peak ? x : peak; | ||
}); | ||
rms = rms / ampSpectrum.length; | ||
rms = Math.sqrt(rms); | ||
return peak / rms; | ||
} | ||
var buffer = function (args) { | ||
@@ -381,2 +407,3 @@ return args.signal; | ||
exports.spectralCentroid = spectralCentroid; | ||
exports.spectralCrest = spectralCrest; | ||
exports.spectralFlatness = spectralFlatness; | ||
@@ -383,0 +410,0 @@ exports.spectralFlux = spectralFlux; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
/*! ***************************************************************************** | ||
/****************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
@@ -20,13 +18,2 @@ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __spreadArray(to, from, pack) { | ||
@@ -500,2 +487,8 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
function getDefaultExportFromCjs (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
var dct$2 = {exports: {}}; | ||
/*===========================================================================*\ | ||
@@ -544,4 +537,8 @@ * Discrete Cosine Transform | ||
var dct = dct_1; | ||
(function (module) { | ||
module.exports = dct_1; | ||
} (dct$2)); | ||
var dct = /*@__PURE__*/getDefaultExportFromCjs(dct$2.exports); | ||
function mfcc (_a) { | ||
@@ -616,2 +613,18 @@ var ampSpectrum = _a.ampSpectrum, melFilterBank = _a.melFilterBank, numberOfMFCCCoefficients = _a.numberOfMFCCCoefficients, bufferSize = _a.bufferSize; | ||
function spectralCrest (_a) { | ||
var ampSpectrum = _a.ampSpectrum; | ||
if (typeof ampSpectrum !== "object") { | ||
throw new TypeError(); | ||
} | ||
var rms = 0; | ||
var peak = -Infinity; | ||
ampSpectrum.forEach(function (x) { | ||
rms += Math.pow(x, 2); | ||
peak = x > peak ? x : peak; | ||
}); | ||
rms = rms / ampSpectrum.length; | ||
rms = Math.sqrt(rms); | ||
return peak / rms; | ||
} | ||
var buffer = function (args) { | ||
@@ -648,3 +661,4 @@ return args.signal; | ||
chroma: chroma, | ||
spectralFlux: spectralFlux | ||
spectralFlux: spectralFlux, | ||
spectralCrest: spectralCrest | ||
}); | ||
@@ -1042,164 +1056,3 @@ | ||
function configure(options) { | ||
var _a = __assign({}, options), sampleRate = _a.sampleRate, bufferSize = _a.bufferSize, melBands = _a.melBands, mfccCoefficients = _a.mfccCoefficients, chromaBands = _a.chromaBands; | ||
return __assign(__assign({}, options), { barkScale: createBarkScale(bufferSize, sampleRate, bufferSize), melFilterBank: createMelFilterBank(Math.max(melBands || 0, mfccCoefficients), sampleRate, bufferSize), chromaFilterBank: createChromaFilterBank(chromaBands, sampleRate, bufferSize) }); | ||
} | ||
function prepareAmpSpectrum(complexSpectrum, bufferSize) { | ||
var ampSpectrum = new Float32Array(bufferSize / 2); | ||
for (var i = 0; i < bufferSize / 2; i++) { | ||
ampSpectrum[i] = Math.sqrt(Math.pow(complexSpectrum.real[i], 2) + | ||
Math.pow(complexSpectrum.imag[i], 2)); | ||
} | ||
return ampSpectrum; | ||
} | ||
function prepareSpectra(signal) { | ||
var complexSpectrum = fft_1.fft(signal); | ||
var ampSpectrum = prepareAmpSpectrum(complexSpectrum, signal.length); | ||
return { | ||
complexSpectrum: complexSpectrum, | ||
ampSpectrum: ampSpectrum | ||
}; | ||
} | ||
function prepareExtractorDependencies(features, signal, configuration | ||
// ): ExtractorParameters<T> { | ||
) { | ||
var bufferSize = configuration.bufferSize, sampleRate = configuration.sampleRate, melFilterBank = configuration.melFilterBank, chromaFilterBank = configuration.chromaFilterBank, barkBands = configuration.barkBands, barkScale = configuration.barkScale, mfccCoefficients = configuration.mfccCoefficients; | ||
var _a = prepareSpectra(signal), complexSpectrum = _a.complexSpectrum, ampSpectrum = _a.ampSpectrum; | ||
var previousSignal = undefined; | ||
return { | ||
signal: !(signal instanceof Float32Array) | ||
? Float32Array.from(signal) | ||
: signal, | ||
complexSpectrum: complexSpectrum, | ||
ampSpectrum: ampSpectrum, | ||
bufferSize: bufferSize, | ||
sampleRate: sampleRate, | ||
chromaFilterBank: chromaFilterBank, | ||
melFilterBank: melFilterBank, | ||
numberOfMFCCCoefficients: mfccCoefficients, | ||
numberOfBarkBands: barkBands, | ||
barkScale: barkScale, | ||
previousSignal: previousSignal | ||
}; | ||
} | ||
/** | ||
* # Configure an extractor | ||
* | ||
* Configure an extractor function with options that are shared throughout the | ||
* extractor function's lifetime. The options pertain to the type of audio that | ||
* the extractor expects - e.g. the sample rate, the consistent windowing | ||
* function to apply, etc. | ||
* | ||
* @param options Configuration used across all feature extractions made with | ||
* resulting interface | ||
* @returns A function that takes a set of requested audio features and one | ||
* buffer of audio, and returns the requested audio features extracted from that | ||
* audio. | ||
*/ | ||
function configureMeyda(options) { | ||
var defaults = { | ||
bufferSize: 512, | ||
sampleRate: 44100, | ||
melBands: 26, | ||
chromaBands: 12, | ||
windowingFunction: "hanning", | ||
mfccCoefficients: 13, | ||
barkBands: 24 | ||
}; | ||
var optionsAfterDefaults = __assign(__assign({}, defaults), options); | ||
var configuration = configure(optionsAfterDefaults); | ||
/** | ||
* ## Extract given audio features from given signal | ||
* | ||
* @param feature The audio feature(s) to extract. Can be single or an array | ||
* @param signal The audio signal to extract the feature(s) from. Can be an | ||
* array containing each channel of a frame of multi-channel audio. If signal | ||
* is multi-channel, the result will be an array. | ||
* | ||
* The signal should have the same sample rate as specified in the options in | ||
* the call to `configureMeyda`. Otherwise, the audio features will be wrong. | ||
* There is no way to validate the sample rate of the signal, so you will get | ||
* mangled output if you don't match it. | ||
* | ||
* @returns The audio feature(s) extracted from the signal. If the signal is | ||
* multi-channel, this will be an array of results for each channel in the | ||
* same order that the channels were passed in. | ||
* | ||
* *NB: Multi-Channel -* Meyda saves a portion of the history of each channel | ||
* of audio for subsequent feature extraction runs. We assume that the | ||
* channels are passed in in the same order for every call to extract. | ||
* Changing the order of the channels between calls will produce invalid | ||
* results. We have no way to detect or warn you about this, so please make | ||
* sure that your audio channels are passed in in the same order every time. | ||
*/ | ||
function extract(feature, signal) { | ||
// const features: readonly T[] = isReadonlyArray<T>(feature as readonly T[] | T) | ||
// ? feature | ||
// : [feature]; | ||
var features = (Array.isArray(feature) | ||
? feature | ||
: [feature]); | ||
var signals = Array.isArray(signal[0]) | ||
? signal | ||
: [signal]; | ||
var results = signals.map(function (signal) { | ||
// TODO: | ||
// apply windowing function | ||
// run fft on signal | ||
// cache previous (+?) signal, amp spectrum and complex spectrum per channel | ||
// run extractors with all deps | ||
// collect to MeydaExtractionResult | ||
var preparedExtractorDependencies = prepareExtractorDependencies(features, signal, configuration); | ||
var channelExtractionResult = Object.fromEntries(features.map(function (feature) { | ||
extractors[feature]; | ||
return [feature, extractors[feature](preparedExtractorDependencies)]; | ||
})); | ||
return channelExtractionResult; | ||
}); | ||
if (!Array.isArray(signal)) { | ||
return results[0]; | ||
} | ||
return results; | ||
} | ||
return extract; | ||
} | ||
/** | ||
* Returns a Meyda extractor function with configured audio features. | ||
* | ||
* @param features | ||
* @param extractor | ||
* @returns | ||
*/ | ||
function curryMeyda(features, extractor) { | ||
return function extract(signal) { | ||
var result = extractor(features, signal); | ||
return result; | ||
}; | ||
} | ||
/** | ||
* ### Configure an extractor with options and audio features | ||
* | ||
* Configure a Meyda extractor function with options and audio features at once. | ||
* | ||
* @param features | ||
* @param options | ||
* @returns | ||
*/ | ||
function configureMeydaWithExtractors(features, options) { | ||
return function extract(signal) { | ||
var extractor = configureMeyda(options); | ||
return curryMeyda(features, extractor)(signal); | ||
}; | ||
} | ||
// type FType< | ||
// T extends V extends readonly (infer K)[] ? K : V extends (infer K)[] ? K : V, | ||
// U extends readonly MeydaSignal[] | MeydaSignal, | ||
// V extends | ||
// | MeydaAudioFeature[] | ||
// | readonly MeydaAudioFeature[] | ||
// | MeydaAudioFeature | ||
// > = (feature: V, signal: U) => MaybePartialResult<T, U, V>; | ||
/** | ||
* This file contains the default export for Meyda, you probably want to check | ||
@@ -1398,5 +1251,2 @@ * out {@link default} | ||
exports.configureMeyda = configureMeyda; | ||
exports.configureMeydaWithExtractors = configureMeydaWithExtractors; | ||
exports.curryMeyda = curryMeyda; | ||
exports["default"] = Meyda; | ||
module.exports = Meyda; |
@@ -324,2 +324,8 @@ 'use strict'; | ||
function getDefaultExportFromCjs (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
var dct$2 = {exports: {}}; | ||
/*===========================================================================*\ | ||
@@ -368,4 +374,8 @@ * Discrete Cosine Transform | ||
var dct = dct_1; | ||
(function (module) { | ||
module.exports = dct_1; | ||
} (dct$2)); | ||
var dct = /*@__PURE__*/getDefaultExportFromCjs(dct$2.exports); | ||
function mfcc (_a) { | ||
@@ -440,2 +450,18 @@ var ampSpectrum = _a.ampSpectrum, melFilterBank = _a.melFilterBank, numberOfMFCCCoefficients = _a.numberOfMFCCCoefficients, bufferSize = _a.bufferSize; | ||
function spectralCrest (_a) { | ||
var ampSpectrum = _a.ampSpectrum; | ||
if (typeof ampSpectrum !== "object") { | ||
throw new TypeError(); | ||
} | ||
var rms = 0; | ||
var peak = -Infinity; | ||
ampSpectrum.forEach(function (x) { | ||
rms += Math.pow(x, 2); | ||
peak = x > peak ? x : peak; | ||
}); | ||
rms = rms / ampSpectrum.length; | ||
rms = Math.sqrt(rms); | ||
return peak / rms; | ||
} | ||
var buffer = function (args) { | ||
@@ -472,3 +498,4 @@ return args.signal; | ||
chroma: chroma, | ||
spectralFlux: spectralFlux | ||
spectralFlux: spectralFlux, | ||
spectralCrest: spectralCrest | ||
}); | ||
@@ -475,0 +502,0 @@ |
@@ -5,3 +5,3 @@ 'use strict'; | ||
/*! ***************************************************************************** | ||
/****************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
@@ -8,0 +8,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Meyda = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Meyda = factory()); | ||
})(this, (function () { 'use strict'; | ||
/*! ***************************************************************************** | ||
/****************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
@@ -22,13 +22,2 @@ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __spreadArray(to, from, pack) { | ||
@@ -502,2 +491,8 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
function getDefaultExportFromCjs (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
var dct$2 = {exports: {}}; | ||
/*===========================================================================*\ | ||
@@ -546,4 +541,8 @@ * Discrete Cosine Transform | ||
var dct = dct_1; | ||
(function (module) { | ||
module.exports = dct_1; | ||
} (dct$2)); | ||
var dct = /*@__PURE__*/getDefaultExportFromCjs(dct$2.exports); | ||
function mfcc (_a) { | ||
@@ -618,2 +617,18 @@ var ampSpectrum = _a.ampSpectrum, melFilterBank = _a.melFilterBank, numberOfMFCCCoefficients = _a.numberOfMFCCCoefficients, bufferSize = _a.bufferSize; | ||
function spectralCrest (_a) { | ||
var ampSpectrum = _a.ampSpectrum; | ||
if (typeof ampSpectrum !== "object") { | ||
throw new TypeError(); | ||
} | ||
var rms = 0; | ||
var peak = -Infinity; | ||
ampSpectrum.forEach(function (x) { | ||
rms += Math.pow(x, 2); | ||
peak = x > peak ? x : peak; | ||
}); | ||
rms = rms / ampSpectrum.length; | ||
rms = Math.sqrt(rms); | ||
return peak / rms; | ||
} | ||
var buffer = function (args) { | ||
@@ -650,3 +665,4 @@ return args.signal; | ||
chroma: chroma, | ||
spectralFlux: spectralFlux | ||
spectralFlux: spectralFlux, | ||
spectralCrest: spectralCrest | ||
}); | ||
@@ -1044,164 +1060,3 @@ | ||
function configure(options) { | ||
var _a = __assign({}, options), sampleRate = _a.sampleRate, bufferSize = _a.bufferSize, melBands = _a.melBands, mfccCoefficients = _a.mfccCoefficients, chromaBands = _a.chromaBands; | ||
return __assign(__assign({}, options), { barkScale: createBarkScale(bufferSize, sampleRate, bufferSize), melFilterBank: createMelFilterBank(Math.max(melBands || 0, mfccCoefficients), sampleRate, bufferSize), chromaFilterBank: createChromaFilterBank(chromaBands, sampleRate, bufferSize) }); | ||
} | ||
function prepareAmpSpectrum(complexSpectrum, bufferSize) { | ||
var ampSpectrum = new Float32Array(bufferSize / 2); | ||
for (var i = 0; i < bufferSize / 2; i++) { | ||
ampSpectrum[i] = Math.sqrt(Math.pow(complexSpectrum.real[i], 2) + | ||
Math.pow(complexSpectrum.imag[i], 2)); | ||
} | ||
return ampSpectrum; | ||
} | ||
function prepareSpectra(signal) { | ||
var complexSpectrum = fft_1.fft(signal); | ||
var ampSpectrum = prepareAmpSpectrum(complexSpectrum, signal.length); | ||
return { | ||
complexSpectrum: complexSpectrum, | ||
ampSpectrum: ampSpectrum | ||
}; | ||
} | ||
function prepareExtractorDependencies(features, signal, configuration | ||
// ): ExtractorParameters<T> { | ||
) { | ||
var bufferSize = configuration.bufferSize, sampleRate = configuration.sampleRate, melFilterBank = configuration.melFilterBank, chromaFilterBank = configuration.chromaFilterBank, barkBands = configuration.barkBands, barkScale = configuration.barkScale, mfccCoefficients = configuration.mfccCoefficients; | ||
var _a = prepareSpectra(signal), complexSpectrum = _a.complexSpectrum, ampSpectrum = _a.ampSpectrum; | ||
var previousSignal = undefined; | ||
return { | ||
signal: !(signal instanceof Float32Array) | ||
? Float32Array.from(signal) | ||
: signal, | ||
complexSpectrum: complexSpectrum, | ||
ampSpectrum: ampSpectrum, | ||
bufferSize: bufferSize, | ||
sampleRate: sampleRate, | ||
chromaFilterBank: chromaFilterBank, | ||
melFilterBank: melFilterBank, | ||
numberOfMFCCCoefficients: mfccCoefficients, | ||
numberOfBarkBands: barkBands, | ||
barkScale: barkScale, | ||
previousSignal: previousSignal | ||
}; | ||
} | ||
/** | ||
* # Configure an extractor | ||
* | ||
* Configure an extractor function with options that are shared throughout the | ||
* extractor function's lifetime. The options pertain to the type of audio that | ||
* the extractor expects - e.g. the sample rate, the consistent windowing | ||
* function to apply, etc. | ||
* | ||
* @param options Configuration used across all feature extractions made with | ||
* resulting interface | ||
* @returns A function that takes a set of requested audio features and one | ||
* buffer of audio, and returns the requested audio features extracted from that | ||
* audio. | ||
*/ | ||
function configureMeyda(options) { | ||
var defaults = { | ||
bufferSize: 512, | ||
sampleRate: 44100, | ||
melBands: 26, | ||
chromaBands: 12, | ||
windowingFunction: "hanning", | ||
mfccCoefficients: 13, | ||
barkBands: 24 | ||
}; | ||
var optionsAfterDefaults = __assign(__assign({}, defaults), options); | ||
var configuration = configure(optionsAfterDefaults); | ||
/** | ||
* ## Extract given audio features from given signal | ||
* | ||
* @param feature The audio feature(s) to extract. Can be single or an array | ||
* @param signal The audio signal to extract the feature(s) from. Can be an | ||
* array containing each channel of a frame of multi-channel audio. If signal | ||
* is multi-channel, the result will be an array. | ||
* | ||
* The signal should have the same sample rate as specified in the options in | ||
* the call to `configureMeyda`. Otherwise, the audio features will be wrong. | ||
* There is no way to validate the sample rate of the signal, so you will get | ||
* mangled output if you don't match it. | ||
* | ||
* @returns The audio feature(s) extracted from the signal. If the signal is | ||
* multi-channel, this will be an array of results for each channel in the | ||
* same order that the channels were passed in. | ||
* | ||
* *NB: Multi-Channel -* Meyda saves a portion of the history of each channel | ||
* of audio for subsequent feature extraction runs. We assume that the | ||
* channels are passed in in the same order for every call to extract. | ||
* Changing the order of the channels between calls will produce invalid | ||
* results. We have no way to detect or warn you about this, so please make | ||
* sure that your audio channels are passed in in the same order every time. | ||
*/ | ||
function extract(feature, signal) { | ||
// const features: readonly T[] = isReadonlyArray<T>(feature as readonly T[] | T) | ||
// ? feature | ||
// : [feature]; | ||
var features = (Array.isArray(feature) | ||
? feature | ||
: [feature]); | ||
var signals = Array.isArray(signal[0]) | ||
? signal | ||
: [signal]; | ||
var results = signals.map(function (signal) { | ||
// TODO: | ||
// apply windowing function | ||
// run fft on signal | ||
// cache previous (+?) signal, amp spectrum and complex spectrum per channel | ||
// run extractors with all deps | ||
// collect to MeydaExtractionResult | ||
var preparedExtractorDependencies = prepareExtractorDependencies(features, signal, configuration); | ||
var channelExtractionResult = Object.fromEntries(features.map(function (feature) { | ||
extractors[feature]; | ||
return [feature, extractors[feature](preparedExtractorDependencies)]; | ||
})); | ||
return channelExtractionResult; | ||
}); | ||
if (!Array.isArray(signal)) { | ||
return results[0]; | ||
} | ||
return results; | ||
} | ||
return extract; | ||
} | ||
/** | ||
* Returns a Meyda extractor function with configured audio features. | ||
* | ||
* @param features | ||
* @param extractor | ||
* @returns | ||
*/ | ||
function curryMeyda(features, extractor) { | ||
return function extract(signal) { | ||
var result = extractor(features, signal); | ||
return result; | ||
}; | ||
} | ||
/** | ||
* ### Configure an extractor with options and audio features | ||
* | ||
* Configure a Meyda extractor function with options and audio features at once. | ||
* | ||
* @param features | ||
* @param options | ||
* @returns | ||
*/ | ||
function configureMeydaWithExtractors(features, options) { | ||
return function extract(signal) { | ||
var extractor = configureMeyda(options); | ||
return curryMeyda(features, extractor)(signal); | ||
}; | ||
} | ||
// type FType< | ||
// T extends V extends readonly (infer K)[] ? K : V extends (infer K)[] ? K : V, | ||
// U extends readonly MeydaSignal[] | MeydaSignal, | ||
// V extends | ||
// | MeydaAudioFeature[] | ||
// | readonly MeydaAudioFeature[] | ||
// | MeydaAudioFeature | ||
// > = (feature: V, signal: U) => MaybePartialResult<T, U, V>; | ||
/** | ||
* This file contains the default export for Meyda, you probably want to check | ||
@@ -1400,10 +1255,5 @@ * out {@link default} | ||
exports.configureMeyda = configureMeyda; | ||
exports.configureMeydaWithExtractors = configureMeydaWithExtractors; | ||
exports.curryMeyda = curryMeyda; | ||
exports["default"] = Meyda; | ||
return Meyda; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
//# sourceMappingURL=meyda.js.map |
@@ -1,16 +0,2 @@ | ||
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r="undefined"!=typeof globalThis?globalThis:r||self).Meyda={})}(this,(function(r){"use strict"; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var t=function(){return(t=Object.assign||function(r){for(var t,e=1,a=arguments.length;e<a;e++)for(var n in t=arguments[e])Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n]);return r}).apply(this,arguments)};function e(r,t,e){if(e||2===arguments.length)for(var a,n=0,i=t.length;n<i;n++)!a&&n in t||(a||(a=Array.prototype.slice.call(t,0,n)),a[n]=t[n]);return r.concat(a||Array.prototype.slice.call(t))}var a=Object.freeze({__proto__:null,blackman:function(r){for(var t=new Float32Array(r),e=2*Math.PI/(r-1),a=2*e,n=0;n<r/2;n++)t[n]=.42-.5*Math.cos(n*e)+.08*Math.cos(n*a);for(n=Math.ceil(r/2);n>0;n--)t[r-n]=t[n-1];return t},sine:function(r){for(var t=Math.PI/(r-1),e=new Float32Array(r),a=0;a<r;a++)e[a]=Math.sin(t*a);return e},hanning:function(r){for(var t=new Float32Array(r),e=0;e<r;e++)t[e]=.5-.5*Math.cos(2*Math.PI*e/(r-1));return t},hamming:function(r){for(var t=new Float32Array(r),e=0;e<r;e++)t[e]=.54-.46*Math.cos(2*Math.PI*(e/r-1));return t}}),n={};function i(r){for(;r%2==0&&r>1;)r/=2;return 1===r}function o(r,t){if("rect"!==t){if(""!==t&&t||(t="hanning"),n[t]||(n[t]={}),!n[t][r.length])try{n[t][r.length]=a[t](r.length)}catch(r){throw new Error("Invalid windowing function")}r=function(r,t){for(var e=[],a=0;a<Math.min(r.length,t.length);a++)e[a]=r[a]*t[a];return e}(r,n[t][r.length])}return r}function u(r,t,e){for(var a=new Float32Array(r),n=0;n<a.length;n++)a[n]=n*t/e,a[n]=13*Math.atan(a[n]/1315.8)+3.5*Math.atan(Math.pow(a[n]/7518,2));return a}function f(r){return Float32Array.from(r)}function c(r){return 1125*Math.log(1+r/700)}function l(r,t,e){for(var a,n=new Float32Array(r+2),i=new Float32Array(r+2),o=t/2,u=c(0),f=(c(o)-u)/(r+1),l=new Array(r+2),s=0;s<n.length;s++)n[s]=s*f,i[s]=(a=n[s],700*(Math.exp(a/1125)-1)),l[s]=Math.floor((e+1)*i[s]/t);for(var m=new Array(r),p=0;p<m.length;p++){m[p]=new Array(e/2+1).fill(0);for(s=l[p];s<l[p+1];s++)m[p][s]=(s-l[p])/(l[p+1]-l[p]);for(s=l[p+1];s<l[p+2];s++)m[p][s]=(l[p+2]-s)/(l[p+2]-l[p+1])}return m}function s(r,t,a,n,i,o,u){void 0===n&&(n=5),void 0===i&&(i=2),void 0===o&&(o=!0),void 0===u&&(u=440);var f=Math.floor(a/2)+1,c=new Array(a).fill(0).map((function(e,n){return r*function(r,t){return Math.log2(16*r/t)}(t*n/a,u)}));c[0]=c[1]-1.5*r;var l,s,m,p=c.slice(1).map((function(r,t){return Math.max(r-c[t])}),1).concat([1]),h=Math.round(r/2),g=new Array(r).fill(0).map((function(t,e){return c.map((function(t){return(10*r+h+t-e)%r-h}))})),v=g.map((function(r,t){return r.map((function(r,e){return Math.exp(-.5*Math.pow(2*g[t][e]/p[e],2))}))}));if(s=(l=v)[0].map((function(){return 0})),m=l.reduce((function(r,t){return t.forEach((function(t,e){r[e]+=Math.pow(t,2)})),r}),s).map(Math.sqrt),v=l.map((function(r,t){return r.map((function(r,t){return r/(m[t]||1)}))})),i){var w=c.map((function(t){return Math.exp(-.5*Math.pow((t/r-n)/i,2))}));v=v.map((function(r){return r.map((function(r,t){return r*w[t]}))}))}return o&&(v=e(e([],v.slice(3),!0),v.slice(0,3),!0)),v.map((function(r){return r.slice(0,f)}))}function m(r,t){for(var e=0,a=0,n=0;n<t.length;n++)e+=Math.pow(n,r)*Math.abs(t[n]),a+=t[n];return e/a}function p(r){var t=r.ampSpectrum,e=r.barkScale,a=r.numberOfBarkBands,n=void 0===a?24:a;if("object"!=typeof t||"object"!=typeof e)throw new TypeError;var i=n,o=new Float32Array(i),u=0,f=t,c=new Int32Array(i+1);c[0]=0;for(var l=e[f.length-1]/i,s=1,m=0;m<f.length;m++)for(;e[m]>l;)c[s++]=m,l=s*e[f.length-1]/i;c[i]=f.length-1;for(m=0;m<i;m++){for(var p=0,h=c[m];h<c[m+1];h++)p+=f[h];o[m]=Math.pow(p,.23)}for(m=0;m<o.length;m++)u+=o[m];return{specific:o,total:u}}function h(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;for(var e=new Float32Array(t.length),a=0;a<e.length;a++)e[a]=Math.pow(t[a],2);return e}var g=null;var v=function(r,t){var e=r.length;return t=t||2,g&&g[e]||function(r){(g=g||{})[r]=new Array(r*r);for(var t=Math.PI/r,e=0;e<r;e++)for(var a=0;a<r;a++)g[r][a+e*r]=Math.cos(t*(a+.5)*e)}(e),r.map((function(){return 0})).map((function(a,n){return t*r.reduce((function(r,t,a,i){return r+t*g[e][a+n*e]}),0)}))};var w=Object.freeze({__proto__:null,buffer:function(r){return r.signal},rms:function(r){var t=r.signal;if("object"!=typeof t)throw new TypeError;for(var e=0,a=0;a<t.length;a++)e+=Math.pow(t[a],2);return e/=t.length,e=Math.sqrt(e)},energy:function(r){var t=r.signal;if("object"!=typeof t)throw new TypeError;for(var e=0,a=0;a<t.length;a++)e+=Math.pow(Math.abs(t[a]),2);return e},complexSpectrum:function(r){return r.complexSpectrum},spectralSlope:function(r){var t=r.ampSpectrum,e=r.sampleRate,a=r.bufferSize;if("object"!=typeof t)throw new TypeError;for(var n=0,i=0,o=new Float32Array(t.length),u=0,f=0,c=0;c<t.length;c++){n+=t[c];var l=c*e/a;o[c]=l,u+=l*l,i+=l,f+=l*t[c]}return(t.length*f-i*n)/(n*(u-Math.pow(i,2)))},spectralCentroid:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;return m(1,t)},spectralRolloff:function(r){var t=r.ampSpectrum,e=r.sampleRate;if("object"!=typeof t)throw new TypeError;for(var a=t,n=e/(2*(a.length-1)),i=0,o=0;o<a.length;o++)i+=a[o];for(var u=.99*i,f=a.length-1;i>u&&f>=0;)i-=a[f],--f;return(f+1)*n},spectralFlatness:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;for(var e=0,a=0,n=0;n<t.length;n++)e+=Math.log(t[n]),a+=t[n];return Math.exp(e/t.length)*t.length/a},spectralSpread:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;return Math.sqrt(m(2,t)-Math.pow(m(1,t),2))},spectralSkewness:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;var e=m(1,t),a=m(2,t),n=m(3,t);return(2*Math.pow(e,3)-3*e*a+n)/Math.pow(Math.sqrt(a-Math.pow(e,2)),3)},spectralKurtosis:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;var e=t,a=m(1,e),n=m(2,e),i=m(3,e),o=m(4,e);return(-3*Math.pow(a,4)+6*a*n-4*a*i+o)/Math.pow(Math.sqrt(n-Math.pow(a,2)),4)},amplitudeSpectrum:function(r){return r.ampSpectrum},zcr:function(r){var t=r.signal;if("object"!=typeof t)throw new TypeError;for(var e=0,a=1;a<t.length;a++)(t[a-1]>=0&&t[a]<0||t[a-1]<0&&t[a]>=0)&&e++;return e},loudness:p,perceptualSpread:function(r){for(var t=p({ampSpectrum:r.ampSpectrum,barkScale:r.barkScale}),e=0,a=0;a<t.specific.length;a++)t.specific[a]>e&&(e=t.specific[a]);return Math.pow((t.total-e)/t.total,2)},perceptualSharpness:function(r){for(var t=p({ampSpectrum:r.ampSpectrum,barkScale:r.barkScale}),e=t.specific,a=0,n=0;n<e.length;n++)a+=n<15?(n+1)*e[n+1]:.066*Math.exp(.171*(n+1));return a*=.11/t.total},powerSpectrum:h,mfcc:function(r){var t=r.ampSpectrum,e=r.melFilterBank,a=r.numberOfMFCCCoefficients,n=r.bufferSize;if("object"!=typeof t)throw new TypeError("Valid ampSpectrum is required to generate MFCC");if("object"!=typeof e)throw new TypeError("Valid melFilterBank is required to generate MFCC");var i=Math.min(40,Math.max(1,a||13)),o=h({ampSpectrum:t}),u=e.length,f=Array(u);if(u<i)throw new Error("Insufficient filter bank for requested number of coefficients");for(var c=new Float32Array(u),l=0;l<c.length;l++){f[l]=new Float32Array(n/2),c[l]=0;for(var s=0;s<n/2;s++)f[l][s]=e[l][s]*o[s],c[l]+=f[l][s];c[l]=Math.log(c[l]+1)}var m=Array.prototype.slice.call(c);return v(m).slice(0,i)},chroma:function(r){var t=r.ampSpectrum,e=r.chromaFilterBank;if("object"!=typeof t)throw new TypeError("Valid ampSpectrum is required to generate chroma");if("object"!=typeof e)throw new TypeError("Valid chromaFilterBank is required to generate chroma");var a=e.map((function(r,e){return t.reduce((function(t,e,a){return t+e*r[a]}),0)})),n=Math.max.apply(Math,a);return n?a.map((function(r){return r/n})):a},spectralFlux:function(r){var t=r.signal,e=r.previousSignal,a=r.bufferSize;if("object"!=typeof t||"object"!=typeof e)throw new TypeError;for(var n=0,i=-a/2;i<t.length/2-1;i++)x=Math.abs(t[i])-Math.abs(e[i]),n+=(x+Math.abs(x))/2;return n}});function d(r){if(Array.isArray(r)){for(var t=0,e=Array(r.length);t<r.length;t++)e[t]=r[t];return e}return Array.from(r)}var y={},S={},b={bitReverseArray:function(r){if(void 0===y[r]){for(var t=(r-1).toString(2).length,e="0".repeat(t),a={},n=0;n<r;n++){var i=n.toString(2);i=e.substr(i.length)+i,i=[].concat(d(i)).reverse().join(""),a[n]=parseInt(i,2)}y[r]=a}return y[r]},multiply:function(r,t){return{real:r.real*t.real-r.imag*t.imag,imag:r.real*t.imag+r.imag*t.real}},add:function(r,t){return{real:r.real+t.real,imag:r.imag+t.imag}},subtract:function(r,t){return{real:r.real-t.real,imag:r.imag-t.imag}},euler:function(r,t){var e=-2*Math.PI*r/t;return{real:Math.cos(e),imag:Math.sin(e)}},conj:function(r){return r.imag*=-1,r},constructComplexArray:function(r){var t={};t.real=void 0===r.real?r.slice():r.real.slice();var e=t.real.length;return void 0===S[e]&&(S[e]=Array.apply(null,Array(e)).map(Number.prototype.valueOf,0)),t.imag=S[e].slice(),t}},_=function(r){var t={};void 0===r.real||void 0===r.imag?t=b.constructComplexArray(r):(t.real=r.real.slice(),t.imag=r.imag.slice());var e=t.real.length,a=Math.log2(e);if(Math.round(a)!=a)throw new Error("Input size must be a power of 2.");if(t.real.length!=t.imag.length)throw new Error("Real and imaginary components must have the same length.");for(var n=b.bitReverseArray(e),i={real:[],imag:[]},o=0;o<e;o++)i.real[n[o]]=t.real[o],i.imag[n[o]]=t.imag[o];for(var u=0;u<e;u++)t.real[u]=i.real[u],t.imag[u]=i.imag[u];for(var f=1;f<=a;f++)for(var c=Math.pow(2,f),l=0;l<c/2;l++)for(var s=b.euler(l,c),m=0;m<e/c;m++){var p=c*m+l,h=c*m+l+c/2,g={real:t.real[p],imag:t.imag[p]},v={real:t.real[h],imag:t.imag[h]},w=b.multiply(s,v),d=b.subtract(g,w);t.real[h]=d.real,t.imag[h]=d.imag;var y=b.add(w,g);t.real[p]=y.real,t.imag[p]=y.imag}return t},M=_,F=function(){function r(r,t){var e=this;if(this._m=t,!r.audioContext)throw this._m.errors.noAC;if(r.bufferSize&&!i(r.bufferSize))throw this._m._errors.notPow2;if(!r.source)throw this._m._errors.noSource;this._m.audioContext=r.audioContext,this._m.bufferSize=r.bufferSize||this._m.bufferSize||256,this._m.hopSize=r.hopSize||this._m.hopSize||this._m.bufferSize,this._m.sampleRate=r.sampleRate||this._m.audioContext.sampleRate||44100,this._m.callback=r.callback,this._m.windowingFunction=r.windowingFunction||"hanning",this._m.featureExtractors=w,this._m.EXTRACTION_STARTED=r.startImmediately||!1,this._m.channel="number"==typeof r.channel?r.channel:0,this._m.inputs=r.inputs||1,this._m.outputs=r.outputs||1,this._m.numberOfMFCCCoefficients=r.numberOfMFCCCoefficients||this._m.numberOfMFCCCoefficients||13,this._m.numberOfBarkBands=r.numberOfBarkBands||this._m.numberOfBarkBands||24,this._m.spn=this._m.audioContext.createScriptProcessor(this._m.bufferSize,this._m.inputs,this._m.outputs),this._m.spn.connect(this._m.audioContext.destination),this._m._featuresToExtract=r.featureExtractors||[],this._m.barkScale=u(this._m.bufferSize,this._m.sampleRate,this._m.bufferSize),this._m.melFilterBank=l(Math.max(this._m.melBands,this._m.numberOfMFCCCoefficients),this._m.sampleRate,this._m.bufferSize),this._m.inputData=null,this._m.previousInputData=null,this._m.frame=null,this._m.previousFrame=null,this.setSource(r.source),this._m.spn.onaudioprocess=function(r){var t;null!==e._m.inputData&&(e._m.previousInputData=e._m.inputData),e._m.inputData=r.inputBuffer.getChannelData(e._m.channel),e._m.previousInputData?((t=new Float32Array(e._m.previousInputData.length+e._m.inputData.length-e._m.hopSize)).set(e._m.previousInputData.slice(e._m.hopSize)),t.set(e._m.inputData,e._m.previousInputData.length-e._m.hopSize)):t=e._m.inputData,function(r,t,e){if(r.length<t)throw new Error("Buffer is too short for frame length");if(e<1)throw new Error("Hop length cannot be less that 1");if(t<1)throw new Error("Frame length cannot be less that 1");var a=1+Math.floor((r.length-t)/e);return new Array(a).fill(0).map((function(a,n){return r.slice(n*e,n*e+t)}))}(t,e._m.bufferSize,e._m.hopSize).forEach((function(r){e._m.frame=r;var t=e._m.extract(e._m._featuresToExtract,e._m.frame,e._m.previousFrame);"function"==typeof e._m.callback&&e._m.EXTRACTION_STARTED&&e._m.callback(t),e._m.previousFrame=e._m.frame}))}}return r.prototype.start=function(r){this._m._featuresToExtract=r||this._m._featuresToExtract,this._m.EXTRACTION_STARTED=!0},r.prototype.stop=function(){this._m.EXTRACTION_STARTED=!1},r.prototype.setSource=function(r){this._m.source&&this._m.source.disconnect(this._m.spn),this._m.source=r,this._m.source.connect(this._m.spn)},r.prototype.setChannel=function(r){r<=this._m.inputs?this._m.channel=r:console.error("Channel ".concat(r," does not exist. Make sure you've provided a value for 'inputs' that is greater than ").concat(r," when instantiating the MeydaAnalyzer"))},r.prototype.get=function(r){return this._m.inputData?this._m.extract(r||this._m._featuresToExtract,this._m.inputData,this._m.previousInputData):null},r}();function A(r){var t=M(r);return{complexSpectrum:t,ampSpectrum:function(r,t){for(var e=new Float32Array(t/2),a=0;a<t/2;a++)e[a]=Math.sqrt(Math.pow(r.real[a],2)+Math.pow(r.imag[a],2));return e}(t,r.length)}}function C(r){var e=function(r){var e=t({},r),a=e.sampleRate,n=e.bufferSize,i=e.melBands,o=e.mfccCoefficients,f=e.chromaBands;return t(t({},r),{barkScale:u(n,a,n),melFilterBank:l(Math.max(i||0,o),a,n),chromaFilterBank:s(f,a,n)})}(t(t({},{bufferSize:512,sampleRate:44100,melBands:26,chromaBands:12,windowingFunction:"hanning",mfccCoefficients:13,barkBands:24}),r));return function(r,t){var a=Array.isArray(r)?r:[r],n=(Array.isArray(t[0])?t:[t]).map((function(r){var t=function(r,t,e){var a=e.bufferSize,n=e.sampleRate,i=e.melFilterBank,o=e.chromaFilterBank,u=e.barkBands,f=e.barkScale,c=e.mfccCoefficients,l=A(t),s=l.complexSpectrum,m=l.ampSpectrum;return{signal:t instanceof Float32Array?t:Float32Array.from(t),complexSpectrum:s,ampSpectrum:m,bufferSize:a,sampleRate:n,chromaFilterBank:o,melFilterBank:i,numberOfMFCCCoefficients:c,numberOfBarkBands:u,barkScale:f,previousSignal:void 0}}(0,r,e);return Object.fromEntries(a.map((function(r){return w[r],[r,w[r](t)]})))}));return Array.isArray(t)?n:n[0]}}function k(r,t){return function(e){return t(r,e)}}var E={audioContext:null,spn:null,bufferSize:512,sampleRate:44100,melBands:26,chromaBands:12,callback:null,windowingFunction:"hanning",featureExtractors:w,EXTRACTION_STARTED:!1,numberOfMFCCCoefficients:13,numberOfBarkBands:24,_featuresToExtract:[],windowing:o,_errors:{notPow2:new Error("Meyda: Buffer size must be a power of 2, e.g. 64 or 512"),featureUndef:new Error("Meyda: No features defined."),invalidFeatureFmt:new Error("Meyda: Invalid feature format"),invalidInput:new Error("Meyda: Invalid input."),noAC:new Error("Meyda: No AudioContext specified."),noSource:new Error("Meyda: No source node specified.")},createMeydaAnalyzer:function(r){return new F(r,Object.assign({},E))},listAvailableFeatureExtractors:function(){return Object.keys(this.featureExtractors)},extract:function(r,t,e){var a=this;if(!t)throw this._errors.invalidInput;if("object"!=typeof t)throw this._errors.invalidInput;if(!r)throw this._errors.featureUndef;if(!i(t.length))throw this._errors.notPow2;void 0!==this.barkScale&&this.barkScale.length==this.bufferSize||(this.barkScale=u(this.bufferSize,this.sampleRate,this.bufferSize)),void 0!==this.melFilterBank&&this.barkScale.length==this.bufferSize&&this.melFilterBank.length==this.melBands||(this.melFilterBank=l(Math.max(this.melBands,this.numberOfMFCCCoefficients),this.sampleRate,this.bufferSize)),void 0!==this.chromaFilterBank&&this.chromaFilterBank.length==this.chromaBands||(this.chromaFilterBank=s(this.chromaBands,this.sampleRate,this.bufferSize)),"buffer"in t&&void 0===t.buffer?this.signal=f(t):this.signal=t;var n=B(t,this.windowingFunction,this.bufferSize);if(this.signal=n.windowedSignal,this.complexSpectrum=n.complexSpectrum,this.ampSpectrum=n.ampSpectrum,e){var o=B(e,this.windowingFunction,this.bufferSize);this.previousSignal=o.windowedSignal,this.previousComplexSpectrum=o.complexSpectrum,this.previousAmpSpectrum=o.ampSpectrum}var c=function(r){return a.featureExtractors[r]({ampSpectrum:a.ampSpectrum,chromaFilterBank:a.chromaFilterBank,complexSpectrum:a.complexSpectrum,signal:a.signal,bufferSize:a.bufferSize,sampleRate:a.sampleRate,barkScale:a.barkScale,melFilterBank:a.melFilterBank,previousSignal:a.previousSignal,previousAmpSpectrum:a.previousAmpSpectrum,previousComplexSpectrum:a.previousComplexSpectrum,numberOfMFCCCoefficients:a.numberOfMFCCCoefficients,numberOfBarkBands:a.numberOfBarkBands})};if("object"==typeof r)return r.reduce((function(r,t){var e;return Object.assign({},r,((e={})[t]=c(t),e))}),{});if("string"==typeof r)return c(r);throw this._errors.invalidFeatureFmt}},B=function(r,t,e){var a={};void 0===r.buffer?a.signal=f(r):a.signal=r,a.windowedSignal=o(a.signal,t),a.complexSpectrum=M(a.windowedSignal),a.ampSpectrum=new Float32Array(e/2);for(var n=0;n<e/2;n++)a.ampSpectrum[n]=Math.sqrt(Math.pow(a.complexSpectrum.real[n],2)+Math.pow(a.complexSpectrum.imag[n],2));return a};"undefined"!=typeof window&&(window.Meyda=E),r.configureMeyda=C,r.configureMeydaWithExtractors=function(r,t){return function(e){var a=C(t);return k(r,a)(e)}},r.curryMeyda=k,r.default=E,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(r="undefined"!=typeof globalThis?globalThis:r||self).Meyda=t()}(this,(function(){"use strict";function r(r,t,e){if(e||2===arguments.length)for(var a,n=0,o=t.length;n<o;n++)!a&&n in t||(a||(a=Array.prototype.slice.call(t,0,n)),a[n]=t[n]);return r.concat(a||Array.prototype.slice.call(t))}var t=Object.freeze({__proto__:null,blackman:function(r){for(var t=new Float32Array(r),e=2*Math.PI/(r-1),a=2*e,n=0;n<r/2;n++)t[n]=.42-.5*Math.cos(n*e)+.08*Math.cos(n*a);for(n=Math.ceil(r/2);n>0;n--)t[r-n]=t[n-1];return t},sine:function(r){for(var t=Math.PI/(r-1),e=new Float32Array(r),a=0;a<r;a++)e[a]=Math.sin(t*a);return e},hanning:function(r){for(var t=new Float32Array(r),e=0;e<r;e++)t[e]=.5-.5*Math.cos(2*Math.PI*e/(r-1));return t},hamming:function(r){for(var t=new Float32Array(r),e=0;e<r;e++)t[e]=.54-.46*Math.cos(2*Math.PI*(e/r-1));return t}}),e={};function a(r){for(;r%2==0&&r>1;)r/=2;return 1===r}function n(r,a){if("rect"!==a){if(""!==a&&a||(a="hanning"),e[a]||(e[a]={}),!e[a][r.length])try{e[a][r.length]=t[a](r.length)}catch(r){throw new Error("Invalid windowing function")}r=function(r,t){for(var e=[],a=0;a<Math.min(r.length,t.length);a++)e[a]=r[a]*t[a];return e}(r,e[a][r.length])}return r}function o(r,t,e){for(var a=new Float32Array(r),n=0;n<a.length;n++)a[n]=n*t/e,a[n]=13*Math.atan(a[n]/1315.8)+3.5*Math.atan(Math.pow(a[n]/7518,2));return a}function i(r){return Float32Array.from(r)}function u(r){return 1125*Math.log(1+r/700)}function f(r,t,e){for(var a,n=new Float32Array(r+2),o=new Float32Array(r+2),i=t/2,f=u(0),c=(u(i)-f)/(r+1),s=new Array(r+2),l=0;l<n.length;l++)n[l]=l*c,o[l]=(a=n[l],700*(Math.exp(a/1125)-1)),s[l]=Math.floor((e+1)*o[l]/t);for(var p=new Array(r),m=0;m<p.length;m++){p[m]=new Array(e/2+1).fill(0);for(l=s[m];l<s[m+1];l++)p[m][l]=(l-s[m])/(s[m+1]-s[m]);for(l=s[m+1];l<s[m+2];l++)p[m][l]=(s[m+2]-l)/(s[m+2]-s[m+1])}return p}function c(t,e,a,n,o,i,u){void 0===n&&(n=5),void 0===o&&(o=2),void 0===i&&(i=!0),void 0===u&&(u=440);var f=Math.floor(a/2)+1,c=new Array(a).fill(0).map((function(r,n){return t*function(r,t){return Math.log2(16*r/t)}(e*n/a,u)}));c[0]=c[1]-1.5*t;var s,l,p,m=c.slice(1).map((function(r,t){return Math.max(r-c[t])}),1).concat([1]),h=Math.round(t/2),g=new Array(t).fill(0).map((function(r,e){return c.map((function(r){return(10*t+h+r-e)%t-h}))})),w=g.map((function(r,t){return r.map((function(r,e){return Math.exp(-.5*Math.pow(2*g[t][e]/m[e],2))}))}));if(l=(s=w)[0].map((function(){return 0})),p=s.reduce((function(r,t){return t.forEach((function(t,e){r[e]+=Math.pow(t,2)})),r}),l).map(Math.sqrt),w=s.map((function(r,t){return r.map((function(r,t){return r/(p[t]||1)}))})),o){var v=c.map((function(r){return Math.exp(-.5*Math.pow((r/t-n)/o,2))}));w=w.map((function(r){return r.map((function(r,t){return r*v[t]}))}))}return i&&(w=r(r([],w.slice(3),!0),w.slice(0,3),!0)),w.map((function(r){return r.slice(0,f)}))}function s(r,t){for(var e=0,a=0,n=0;n<t.length;n++)e+=Math.pow(n,r)*Math.abs(t[n]),a+=t[n];return e/a}function l(r){var t=r.ampSpectrum,e=r.barkScale,a=r.numberOfBarkBands,n=void 0===a?24:a;if("object"!=typeof t||"object"!=typeof e)throw new TypeError;var o=n,i=new Float32Array(o),u=0,f=t,c=new Int32Array(o+1);c[0]=0;for(var s=e[f.length-1]/o,l=1,p=0;p<f.length;p++)for(;e[p]>s;)c[l++]=p,s=l*e[f.length-1]/o;c[o]=f.length-1;for(p=0;p<o;p++){for(var m=0,h=c[p];h<c[p+1];h++)m+=f[h];i[p]=Math.pow(m,.23)}for(p=0;p<i.length;p++)u+=i[p];return{specific:i,total:u}}function p(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;for(var e=new Float32Array(t.length),a=0;a<e.length;a++)e[a]=Math.pow(t[a],2);return e}function m(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var h={exports:{}},g=null;var w=function(r,t){var e=r.length;return t=t||2,g&&g[e]||function(r){(g=g||{})[r]=new Array(r*r);for(var t=Math.PI/r,e=0;e<r;e++)for(var a=0;a<r;a++)g[r][a+e*r]=Math.cos(t*(a+.5)*e)}(e),r.map((function(){return 0})).map((function(a,n){return t*r.reduce((function(r,t,a,o){return r+t*g[e][a+n*e]}),0)}))};!function(r){r.exports=w}(h);var v=m(h.exports);var d=Object.freeze({__proto__:null,buffer:function(r){return r.signal},rms:function(r){var t=r.signal;if("object"!=typeof t)throw new TypeError;for(var e=0,a=0;a<t.length;a++)e+=Math.pow(t[a],2);return e/=t.length,e=Math.sqrt(e)},energy:function(r){var t=r.signal;if("object"!=typeof t)throw new TypeError;for(var e=0,a=0;a<t.length;a++)e+=Math.pow(Math.abs(t[a]),2);return e},complexSpectrum:function(r){return r.complexSpectrum},spectralSlope:function(r){var t=r.ampSpectrum,e=r.sampleRate,a=r.bufferSize;if("object"!=typeof t)throw new TypeError;for(var n=0,o=0,i=new Float32Array(t.length),u=0,f=0,c=0;c<t.length;c++){n+=t[c];var s=c*e/a;i[c]=s,u+=s*s,o+=s,f+=s*t[c]}return(t.length*f-o*n)/(n*(u-Math.pow(o,2)))},spectralCentroid:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;return s(1,t)},spectralRolloff:function(r){var t=r.ampSpectrum,e=r.sampleRate;if("object"!=typeof t)throw new TypeError;for(var a=t,n=e/(2*(a.length-1)),o=0,i=0;i<a.length;i++)o+=a[i];for(var u=.99*o,f=a.length-1;o>u&&f>=0;)o-=a[f],--f;return(f+1)*n},spectralFlatness:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;for(var e=0,a=0,n=0;n<t.length;n++)e+=Math.log(t[n]),a+=t[n];return Math.exp(e/t.length)*t.length/a},spectralSpread:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;return Math.sqrt(s(2,t)-Math.pow(s(1,t),2))},spectralSkewness:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;var e=s(1,t),a=s(2,t),n=s(3,t);return(2*Math.pow(e,3)-3*e*a+n)/Math.pow(Math.sqrt(a-Math.pow(e,2)),3)},spectralKurtosis:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;var e=t,a=s(1,e),n=s(2,e),o=s(3,e),i=s(4,e);return(-3*Math.pow(a,4)+6*a*n-4*a*o+i)/Math.pow(Math.sqrt(n-Math.pow(a,2)),4)},amplitudeSpectrum:function(r){return r.ampSpectrum},zcr:function(r){var t=r.signal;if("object"!=typeof t)throw new TypeError;for(var e=0,a=1;a<t.length;a++)(t[a-1]>=0&&t[a]<0||t[a-1]<0&&t[a]>=0)&&e++;return e},loudness:l,perceptualSpread:function(r){for(var t=l({ampSpectrum:r.ampSpectrum,barkScale:r.barkScale}),e=0,a=0;a<t.specific.length;a++)t.specific[a]>e&&(e=t.specific[a]);return Math.pow((t.total-e)/t.total,2)},perceptualSharpness:function(r){for(var t=l({ampSpectrum:r.ampSpectrum,barkScale:r.barkScale}),e=t.specific,a=0,n=0;n<e.length;n++)a+=n<15?(n+1)*e[n+1]:.066*Math.exp(.171*(n+1));return a*=.11/t.total},powerSpectrum:p,mfcc:function(r){var t=r.ampSpectrum,e=r.melFilterBank,a=r.numberOfMFCCCoefficients,n=r.bufferSize;if("object"!=typeof t)throw new TypeError("Valid ampSpectrum is required to generate MFCC");if("object"!=typeof e)throw new TypeError("Valid melFilterBank is required to generate MFCC");var o=Math.min(40,Math.max(1,a||13)),i=p({ampSpectrum:t}),u=e.length,f=Array(u);if(u<o)throw new Error("Insufficient filter bank for requested number of coefficients");for(var c=new Float32Array(u),s=0;s<c.length;s++){f[s]=new Float32Array(n/2),c[s]=0;for(var l=0;l<n/2;l++)f[s][l]=e[s][l]*i[l],c[s]+=f[s][l];c[s]=Math.log(c[s]+1)}var m=Array.prototype.slice.call(c);return v(m).slice(0,o)},chroma:function(r){var t=r.ampSpectrum,e=r.chromaFilterBank;if("object"!=typeof t)throw new TypeError("Valid ampSpectrum is required to generate chroma");if("object"!=typeof e)throw new TypeError("Valid chromaFilterBank is required to generate chroma");var a=e.map((function(r,e){return t.reduce((function(t,e,a){return t+e*r[a]}),0)})),n=Math.max.apply(Math,a);return n?a.map((function(r){return r/n})):a},spectralFlux:function(r){var t=r.signal,e=r.previousSignal,a=r.bufferSize;if("object"!=typeof t||"object"!=typeof e)throw new TypeError;for(var n=0,o=-a/2;o<t.length/2-1;o++)x=Math.abs(t[o])-Math.abs(e[o]),n+=(x+Math.abs(x))/2;return n},spectralCrest:function(r){var t=r.ampSpectrum;if("object"!=typeof t)throw new TypeError;var e=0,a=-1/0;return t.forEach((function(r){e+=Math.pow(r,2),a=r>a?r:a})),e/=t.length,e=Math.sqrt(e),a/e}});function y(r){if(Array.isArray(r)){for(var t=0,e=Array(r.length);t<r.length;t++)e[t]=r[t];return e}return Array.from(r)}var _={},S={},b={bitReverseArray:function(r){if(void 0===_[r]){for(var t=(r-1).toString(2).length,e="0".repeat(t),a={},n=0;n<r;n++){var o=n.toString(2);o=e.substr(o.length)+o,o=[].concat(y(o)).reverse().join(""),a[n]=parseInt(o,2)}_[r]=a}return _[r]},multiply:function(r,t){return{real:r.real*t.real-r.imag*t.imag,imag:r.real*t.imag+r.imag*t.real}},add:function(r,t){return{real:r.real+t.real,imag:r.imag+t.imag}},subtract:function(r,t){return{real:r.real-t.real,imag:r.imag-t.imag}},euler:function(r,t){var e=-2*Math.PI*r/t;return{real:Math.cos(e),imag:Math.sin(e)}},conj:function(r){return r.imag*=-1,r},constructComplexArray:function(r){var t={};t.real=void 0===r.real?r.slice():r.real.slice();var e=t.real.length;return void 0===S[e]&&(S[e]=Array.apply(null,Array(e)).map(Number.prototype.valueOf,0)),t.imag=S[e].slice(),t}},M=function(r){var t={};void 0===r.real||void 0===r.imag?t=b.constructComplexArray(r):(t.real=r.real.slice(),t.imag=r.imag.slice());var e=t.real.length,a=Math.log2(e);if(Math.round(a)!=a)throw new Error("Input size must be a power of 2.");if(t.real.length!=t.imag.length)throw new Error("Real and imaginary components must have the same length.");for(var n=b.bitReverseArray(e),o={real:[],imag:[]},i=0;i<e;i++)o.real[n[i]]=t.real[i],o.imag[n[i]]=t.imag[i];for(var u=0;u<e;u++)t.real[u]=o.real[u],t.imag[u]=o.imag[u];for(var f=1;f<=a;f++)for(var c=Math.pow(2,f),s=0;s<c/2;s++)for(var l=b.euler(s,c),p=0;p<e/c;p++){var m=c*p+s,h=c*p+s+c/2,g={real:t.real[m],imag:t.imag[m]},w={real:t.real[h],imag:t.imag[h]},v=b.multiply(l,w),d=b.subtract(g,v);t.real[h]=d.real,t.imag[h]=d.imag;var y=b.add(v,g);t.real[m]=y.real,t.imag[m]=y.imag}return t},F=M,A=function(){function r(r,t){var e=this;if(this._m=t,!r.audioContext)throw this._m.errors.noAC;if(r.bufferSize&&!a(r.bufferSize))throw this._m._errors.notPow2;if(!r.source)throw this._m._errors.noSource;this._m.audioContext=r.audioContext,this._m.bufferSize=r.bufferSize||this._m.bufferSize||256,this._m.hopSize=r.hopSize||this._m.hopSize||this._m.bufferSize,this._m.sampleRate=r.sampleRate||this._m.audioContext.sampleRate||44100,this._m.callback=r.callback,this._m.windowingFunction=r.windowingFunction||"hanning",this._m.featureExtractors=d,this._m.EXTRACTION_STARTED=r.startImmediately||!1,this._m.channel="number"==typeof r.channel?r.channel:0,this._m.inputs=r.inputs||1,this._m.outputs=r.outputs||1,this._m.numberOfMFCCCoefficients=r.numberOfMFCCCoefficients||this._m.numberOfMFCCCoefficients||13,this._m.numberOfBarkBands=r.numberOfBarkBands||this._m.numberOfBarkBands||24,this._m.spn=this._m.audioContext.createScriptProcessor(this._m.bufferSize,this._m.inputs,this._m.outputs),this._m.spn.connect(this._m.audioContext.destination),this._m._featuresToExtract=r.featureExtractors||[],this._m.barkScale=o(this._m.bufferSize,this._m.sampleRate,this._m.bufferSize),this._m.melFilterBank=f(Math.max(this._m.melBands,this._m.numberOfMFCCCoefficients),this._m.sampleRate,this._m.bufferSize),this._m.inputData=null,this._m.previousInputData=null,this._m.frame=null,this._m.previousFrame=null,this.setSource(r.source),this._m.spn.onaudioprocess=function(r){var t;null!==e._m.inputData&&(e._m.previousInputData=e._m.inputData),e._m.inputData=r.inputBuffer.getChannelData(e._m.channel),e._m.previousInputData?((t=new Float32Array(e._m.previousInputData.length+e._m.inputData.length-e._m.hopSize)).set(e._m.previousInputData.slice(e._m.hopSize)),t.set(e._m.inputData,e._m.previousInputData.length-e._m.hopSize)):t=e._m.inputData,function(r,t,e){if(r.length<t)throw new Error("Buffer is too short for frame length");if(e<1)throw new Error("Hop length cannot be less that 1");if(t<1)throw new Error("Frame length cannot be less that 1");var a=1+Math.floor((r.length-t)/e);return new Array(a).fill(0).map((function(a,n){return r.slice(n*e,n*e+t)}))}(t,e._m.bufferSize,e._m.hopSize).forEach((function(r){e._m.frame=r;var t=e._m.extract(e._m._featuresToExtract,e._m.frame,e._m.previousFrame);"function"==typeof e._m.callback&&e._m.EXTRACTION_STARTED&&e._m.callback(t),e._m.previousFrame=e._m.frame}))}}return r.prototype.start=function(r){this._m._featuresToExtract=r||this._m._featuresToExtract,this._m.EXTRACTION_STARTED=!0},r.prototype.stop=function(){this._m.EXTRACTION_STARTED=!1},r.prototype.setSource=function(r){this._m.source&&this._m.source.disconnect(this._m.spn),this._m.source=r,this._m.source.connect(this._m.spn)},r.prototype.setChannel=function(r){r<=this._m.inputs?this._m.channel=r:console.error("Channel ".concat(r," does not exist. Make sure you've provided a value for 'inputs' that is greater than ").concat(r," when instantiating the MeydaAnalyzer"))},r.prototype.get=function(r){return this._m.inputData?this._m.extract(r||this._m._featuresToExtract,this._m.inputData,this._m.previousInputData):null},r}(),C={audioContext:null,spn:null,bufferSize:512,sampleRate:44100,melBands:26,chromaBands:12,callback:null,windowingFunction:"hanning",featureExtractors:d,EXTRACTION_STARTED:!1,numberOfMFCCCoefficients:13,numberOfBarkBands:24,_featuresToExtract:[],windowing:n,_errors:{notPow2:new Error("Meyda: Buffer size must be a power of 2, e.g. 64 or 512"),featureUndef:new Error("Meyda: No features defined."),invalidFeatureFmt:new Error("Meyda: Invalid feature format"),invalidInput:new Error("Meyda: Invalid input."),noAC:new Error("Meyda: No AudioContext specified."),noSource:new Error("Meyda: No source node specified.")},createMeydaAnalyzer:function(r){return new A(r,Object.assign({},C))},listAvailableFeatureExtractors:function(){return Object.keys(this.featureExtractors)},extract:function(r,t,e){var n=this;if(!t)throw this._errors.invalidInput;if("object"!=typeof t)throw this._errors.invalidInput;if(!r)throw this._errors.featureUndef;if(!a(t.length))throw this._errors.notPow2;void 0!==this.barkScale&&this.barkScale.length==this.bufferSize||(this.barkScale=o(this.bufferSize,this.sampleRate,this.bufferSize)),void 0!==this.melFilterBank&&this.barkScale.length==this.bufferSize&&this.melFilterBank.length==this.melBands||(this.melFilterBank=f(Math.max(this.melBands,this.numberOfMFCCCoefficients),this.sampleRate,this.bufferSize)),void 0!==this.chromaFilterBank&&this.chromaFilterBank.length==this.chromaBands||(this.chromaFilterBank=c(this.chromaBands,this.sampleRate,this.bufferSize)),"buffer"in t&&void 0===t.buffer?this.signal=i(t):this.signal=t;var u=E(t,this.windowingFunction,this.bufferSize);if(this.signal=u.windowedSignal,this.complexSpectrum=u.complexSpectrum,this.ampSpectrum=u.ampSpectrum,e){var s=E(e,this.windowingFunction,this.bufferSize);this.previousSignal=s.windowedSignal,this.previousComplexSpectrum=s.complexSpectrum,this.previousAmpSpectrum=s.ampSpectrum}var l=function(r){return n.featureExtractors[r]({ampSpectrum:n.ampSpectrum,chromaFilterBank:n.chromaFilterBank,complexSpectrum:n.complexSpectrum,signal:n.signal,bufferSize:n.bufferSize,sampleRate:n.sampleRate,barkScale:n.barkScale,melFilterBank:n.melFilterBank,previousSignal:n.previousSignal,previousAmpSpectrum:n.previousAmpSpectrum,previousComplexSpectrum:n.previousComplexSpectrum,numberOfMFCCCoefficients:n.numberOfMFCCCoefficients,numberOfBarkBands:n.numberOfBarkBands})};if("object"==typeof r)return r.reduce((function(r,t){var e;return Object.assign({},r,((e={})[t]=l(t),e))}),{});if("string"==typeof r)return l(r);throw this._errors.invalidFeatureFmt}},E=function(r,t,e){var a={};void 0===r.buffer?a.signal=i(r):a.signal=r,a.windowedSignal=n(a.signal,t),a.complexSpectrum=F(a.windowedSignal),a.ampSpectrum=new Float32Array(e/2);for(var o=0;o<e/2;o++)a.ampSpectrum[o]=Math.sqrt(Math.pow(a.complexSpectrum.real[o],2)+Math.pow(a.complexSpectrum.imag[o],2));return a};return"undefined"!=typeof window&&(window.Meyda=C),C})); | ||
//# sourceMappingURL=meyda.min.js.map |
{ | ||
"name": "meyda", | ||
"version": "5.4.0-alpha.1", | ||
"version": "5.4.0", | ||
"description": "Real-time feature extraction for the web audio api", | ||
@@ -47,14 +47,14 @@ "main": "./dist/node/main.js", | ||
"@commitlint/config-conventional": "^16.0.0", | ||
"@rollup/plugin-commonjs": "^21.0.0", | ||
"@rollup/plugin-commonjs": "^22.0.0", | ||
"@rollup/plugin-typescript": "^8.2.3", | ||
"@types/jest": "^27.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.2.0", | ||
"@typescript-eslint/eslint-plugin": "^5.23.0", | ||
"@typescript-eslint/parser": "^5.2.0", | ||
"commitizen": "^4.2.4", | ||
"eslint": "^8.1.0", | ||
"glob": "^7.1.7", | ||
"husky": "^7.0.0", | ||
"glob": "^8.0.1", | ||
"husky": "^8.0.1", | ||
"jest": "^27.0.3", | ||
"lint-staged": "^12.1.2", | ||
"prettier": "2.5.1", | ||
"prettier": "2.6.2", | ||
"rollup": "^2.50.5", | ||
@@ -64,5 +64,5 @@ "rollup-plugin-terser": "^7.0.2", | ||
"ts-jest": "^27.0.3", | ||
"tslib": "^2.3.1", | ||
"tslib": "^2.3.0", | ||
"typedoc": "^0.22.4", | ||
"typescript": "^4.5.4" | ||
"typescript": "^4.3.5" | ||
}, | ||
@@ -73,3 +73,2 @@ "dependencies": { | ||
"node-getopt": "^0.3.2", | ||
"ts-toolbelt": "^9.6.0", | ||
"wav": "^1.0.2" | ||
@@ -136,7 +135,2 @@ }, | ||
"prerelease": "beta" | ||
}, | ||
{ | ||
"name": "new-extract", | ||
"channel": "new-extract", | ||
"prerelease": "alpha" | ||
} | ||
@@ -143,0 +137,0 @@ ] |
@@ -10,3 +10,3 @@ // This file isn't being typechecked at all because there are major issues with it. | ||
signal: Float32Array; | ||
previousSignal?: Float32Array; | ||
previousSignal: Float32Array; | ||
bufferSize: number; | ||
@@ -13,0 +13,0 @@ }): number { |
@@ -18,15 +18,13 @@ import rms from "./extractors/rms"; | ||
import spectralFlux from "./extractors/spectralFlux"; | ||
import { MeydaSignal } from "./main"; | ||
import spectralCrest from "./extractors/spectralCrest"; | ||
let buffer = function (args: { signal: MeydaSignal }): MeydaSignal { | ||
let buffer = function (args) { | ||
return args.signal; | ||
}; | ||
let complexSpectrum = function (args: { | ||
complexSpectrum: { real: number[]; imag: number[] }; | ||
}) { | ||
let complexSpectrum = function (args) { | ||
return args.complexSpectrum; | ||
}; | ||
let amplitudeSpectrum = function (args: { ampSpectrum: Float32Array }) { | ||
let amplitudeSpectrum = function (args) { | ||
return args.ampSpectrum; | ||
@@ -56,2 +54,3 @@ }; | ||
spectralFlux, | ||
spectralCrest, | ||
}; |
@@ -37,2 +37,3 @@ /** | ||
spectralSpread: number; | ||
spectralCrest: number; | ||
zcr: number; | ||
@@ -66,2 +67,3 @@ } | ||
| "spectralSpread" | ||
| "spectralCrest" | ||
| "zcr" | ||
@@ -75,4 +77,3 @@ | "buffer"; | ||
*/ | ||
export type MeydaSignal = number[] | Float32Array; | ||
// export type MeydaSignal = SliceableArrayLike<number> | Float32Array; | ||
export type MeydaSignal = SliceableArrayLike<number> | Float32Array; | ||
@@ -484,3 +485,1 @@ export interface SliceableArrayLike<T> extends ArrayLike<T> { | ||
if (typeof window !== "undefined") window.Meyda = Meyda; | ||
export * from "./new-extract"; |
{ | ||
"exclude": ["./dist", "./docs", "./__tests__", "./rollup.config.js", "./bin"], | ||
"compilerOptions": { | ||
"lib": ["es2019", "dom"], | ||
"outDir": "./dist/esm", | ||
@@ -6,0 +5,0 @@ "declaration": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4
0
489706
106
7419
- Removedts-toolbelt@^9.6.0
- Removedts-toolbelt@9.6.0(transitive)