@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.
Files changed (3) hide show
  1. package/README.md +5 -0
  2. package/package.json +30 -0
  3. package/rolloff.js +12 -0
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @audio/spectral-rolloff
2
+
3
+ > Spectral rolloff — frequency below which N% of spectral energy lies
4
+
5
+ Planned — not implemented yet. See the umbrella README for status and sources.
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
+ }