@audio/spectral-rolloff 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/package.json +30 -0
- package/rolloff.js +12 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/spectral-rolloff",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Spectral rolloff — frequency below which \\`p\\` of total spectral energy lies (default 85%).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "rolloff.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./rolloff.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"rolloff.js"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"audio",
|
|
17
|
+
"dsp",
|
|
18
|
+
"spectral",
|
|
19
|
+
"features",
|
|
20
|
+
"rolloff"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/rolloff.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Spectral rolloff — frequency below which `p` of total spectral energy lies (default 85%).
|
|
2
|
+
export default function rolloff (mag, { fs = 44100, n = 2 * (mag.length - 1), p = 0.85 } = {}) {
|
|
3
|
+
let total = 0
|
|
4
|
+
for (let k = 0; k < mag.length; k++) total += mag[k] * mag[k]
|
|
5
|
+
if (total <= 0) return 0
|
|
6
|
+
let acc = 0
|
|
7
|
+
for (let k = 0; k < mag.length; k++) {
|
|
8
|
+
acc += mag[k] * mag[k]
|
|
9
|
+
if (acc >= p * total) return k * fs / n
|
|
10
|
+
}
|
|
11
|
+
return (mag.length - 1) * fs / n
|
|
12
|
+
}
|