@audio/spatial-surround 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/package.json +29 -0
- package/surround.js +22 -0
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/spatial-surround",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Stereo → 5.1 matrix upmix — C/LFE/Ls/Rs derivation (documented simple matrix)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "surround.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./surround.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"surround.js"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"audio",
|
|
17
|
+
"dsp",
|
|
18
|
+
"spatial",
|
|
19
|
+
"surround"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/surround.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Stereo → 5.1 matrix upmix: C = center content, L/R pass, Ls/Rs = decorrelated side
|
|
2
|
+
// (delayed ±), LFE = lowpassed mono. Simple matrix upmix, documented — not Dolby decoding.
|
|
3
|
+
|
|
4
|
+
export default function surround ([L, R], { fs = 44100, surroundDelay = 0.012, lfeCut = 120 } = {}) {
|
|
5
|
+
let n = L.length
|
|
6
|
+
let C = new Float32Array(n), Ls = new Float32Array(n), Rs = new Float32Array(n), LFE = new Float32Array(n)
|
|
7
|
+
let D = Math.round(surroundDelay * fs)
|
|
8
|
+
let a = Math.exp(-2 * Math.PI * lfeCut / fs)
|
|
9
|
+
let lp = 0
|
|
10
|
+
for (let i = 0; i < n; i++) {
|
|
11
|
+
let m = (L[i] + R[i]) * 0.5, s = (L[i] - R[i]) * 0.5
|
|
12
|
+
C[i] = m * 0.7071
|
|
13
|
+
lp = m * (1 - a) + lp * a
|
|
14
|
+
LFE[i] = lp
|
|
15
|
+
if (i >= D) {
|
|
16
|
+
let sd = (L[i - D] - R[i - D]) * 0.5
|
|
17
|
+
Ls[i] = sd * 0.7071
|
|
18
|
+
Rs[i] = -sd * 0.7071
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return [Float32Array.from(L), Float32Array.from(R), C, LFE, Ls, Rs]
|
|
22
|
+
}
|