@audio/spectral-centroid 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/centroid.js +6 -0
  3. package/package.json +30 -0
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @audio/spectral-centroid
2
+
3
+ > Spectral centroid — brightness (Hz), magnitude-weighted mean frequency
4
+
5
+ Planned — not implemented yet. See the umbrella README for status and sources.
package/centroid.js ADDED
@@ -0,0 +1,6 @@
1
+ // Spectral centroid — magnitude-weighted mean frequency (Hz). Peeters 2004 §6.1.
2
+ export default function centroid (mag, { fs = 44100, n = 2 * (mag.length - 1) } = {}) {
3
+ let num = 0, den = 0
4
+ for (let k = 0; k < mag.length; k++) { num += (k * fs / n) * mag[k]; den += mag[k] }
5
+ return den > 0 ? num / den : 0
6
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@audio/spectral-centroid",
3
+ "version": "1.0.0",
4
+ "description": "Spectral centroid — magnitude-weighted mean frequency (Hz). Peeters 2004 §6.1.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "centroid.js",
8
+ "exports": {
9
+ ".": "./centroid.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "centroid.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "spectral",
19
+ "features",
20
+ "centroid"
21
+ ],
22
+ "license": "MIT",
23
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }