@audio/eq-crossover 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/crossover.js +49 -0
  2. package/package.json +33 -0
package/crossover.js ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * N-way crossover network using Linkwitz-Riley filters.
3
+ *
4
+ * @module audio-filter/eq/crossover
5
+ */
6
+
7
+ import linkwitzRiley from 'digital-filter/iir/linkwitz-riley.js'
8
+
9
+ /**
10
+ * @param {Array} frequencies - Crossover frequencies [f1, f2, ...] (N-1 frequencies for N bands)
11
+ * @param {number} order - LR order (2, 4, or 8)
12
+ * @param {number} fs - Sample rate
13
+ * @returns {Array<Array<{b0,b1,b2,a1,a2}>>} Array of SOS arrays, one per band
14
+ */
15
+ export default function crossover (frequencies, order, fs) {
16
+ if (!order) order = 4
17
+ if (!fs) fs = 44100
18
+
19
+ let bands = []
20
+
21
+ for (let i = 0; i <= frequencies.length; i++) {
22
+ if (i === 0) {
23
+ // First band: lowpass at first crossover
24
+ bands.push(linkwitzRiley(order, frequencies[0], fs).low)
25
+ } else if (i === frequencies.length) {
26
+ // Last band: highpass at last crossover
27
+ bands.push(linkwitzRiley(order, frequencies[i - 1], fs).high)
28
+ } else {
29
+ // Middle band: highpass at lower + lowpass at upper
30
+ let hp = linkwitzRiley(order, frequencies[i - 1], fs).high
31
+ let lp = linkwitzRiley(order, frequencies[i], fs).low
32
+ bands.push(hp.concat(lp))
33
+ }
34
+ }
35
+
36
+ // LR order ≡ 2 (mod 4) — LR2, LR6, ... — sums flat only with one output inverted
37
+ // per crossover; order ≡ 0 (mod 4) — LR4, LR8, ... — sums in-phase already.
38
+ // Linkwitz, S. & Riley, R. (1976), JAES 24(1)
39
+ if ((order / 2) % 2) {
40
+ for (let i = 1; i < bands.length; i += 2) {
41
+ let sos = bands[i].slice()
42
+ let c = sos[0]
43
+ sos[0] = { ...c, b0: -c.b0, b1: -c.b1, b2: -c.b2 }
44
+ bands[i] = sos
45
+ }
46
+ }
47
+
48
+ return bands
49
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@audio/eq-crossover",
3
+ "version": "1.0.0",
4
+ "description": "N-way crossover network using Linkwitz-Riley filters",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "crossover.js",
8
+ "exports": {
9
+ ".": "./crossover.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "crossover.js"
14
+ ],
15
+ "dependencies": {
16
+ "digital-filter": "^2.0.0"
17
+ },
18
+ "keywords": [
19
+ "audio",
20
+ "dsp",
21
+ "eq",
22
+ "equalizer",
23
+ "crossover"
24
+ ],
25
+ "license": "MIT",
26
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ }
33
+ }