@audio/saturate-multiband 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 (2) hide show
  1. package/multiband.js +25 -0
  2. package/package.json +33 -0
package/multiband.js ADDED
@@ -0,0 +1,25 @@
1
+ // Multiband saturation — Linkwitz-Riley split, per-band drive/character, flat sum
2
+ // (FabFilter Saturn class).
3
+ import crossover from '@audio/eq-crossover'
4
+ import tube from '@audio/saturate-tube'
5
+
6
+ export default function multiband (data, { freqs = [200, 2000], bands, order = 4, fs = 44100 } = {}) {
7
+ let sos = crossover(freqs, order, fs)
8
+ let out = new Float64Array(data.length)
9
+ for (let b = 0; b < sos.length; b++) {
10
+ let band = Float32Array.from(data)
11
+ for (let sec of sos[b]) {
12
+ let x1 = 0, x2 = 0, y1 = 0, y2 = 0
13
+ for (let i = 0; i < band.length; i++) {
14
+ let x = band[i]
15
+ let y = sec.b0 * x + sec.b1 * x1 + sec.b2 * x2 - sec.a1 * y1 - sec.a2 * y2
16
+ x2 = x1; x1 = x; y2 = y1; y1 = band[i] = y
17
+ }
18
+ }
19
+ let params = Array.isArray(bands) ? bands[b] : bands
20
+ if (params) tube(band, { fs, ...params })
21
+ for (let i = 0; i < out.length; i++) out[i] += band[i]
22
+ }
23
+ for (let i = 0; i < data.length; i++) data[i] = out[i]
24
+ return data
25
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@audio/saturate-multiband",
3
+ "version": "1.0.0",
4
+ "description": "Multiband saturation \u2014 LR split + per-band tube drive (Saturn class)",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "multiband.js",
8
+ "exports": {
9
+ ".": "./multiband.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "multiband.js"
14
+ ],
15
+ "dependencies": {
16
+ "@audio/eq-crossover": "^1.0.0",
17
+ "@audio/saturate-tube": "^1.0.0"
18
+ },
19
+ "keywords": [
20
+ "audio",
21
+ "dsp",
22
+ "saturation",
23
+ "multiband"
24
+ ],
25
+ "license": "MIT",
26
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ }
33
+ }