@audio/spatial-autopan 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/auto-panner.js +32 -0
  2. package/package.json +30 -0
package/auto-panner.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Auto-panner — LFO-driven stereo panning. Constant-power cos/sin law.
3
+ * Signal sweeps between speakers at `rate` Hz, full excursion at depth=1.
4
+ */
5
+
6
+ let {cos, sin, PI} = Math
7
+
8
+ export default function autoPanner (left, right, params) {
9
+ let rate = params.rate ?? 0.5 // Hz
10
+ let depth = params.depth ?? 1 // 0–1
11
+ let fs = params.fs || 44100
12
+
13
+ if (params._phase == null) params._phase = 0
14
+ let phase = params._phase
15
+ let inc = 2 * PI * rate / fs
16
+
17
+ for (let i = 0, l = left.length; i < l; i++) {
18
+ let pan = sin(phase) * depth // −1..+1
19
+ phase += inc
20
+ if (phase > 2 * PI) phase -= 2 * PI
21
+
22
+ let a = (pan + 1) * PI / 4 // 0..π/2
23
+ let gL = cos(a), gR = sin(a)
24
+
25
+ let mid = (left[i] + right[i]) * 0.5
26
+ left[i] = mid * gL
27
+ right[i] = mid * gR
28
+ }
29
+
30
+ params._phase = phase
31
+ return [left, right]
32
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@audio/spatial-autopan",
3
+ "version": "1.0.0",
4
+ "description": "Auto-panner — LFO-driven stereo panning. Constant-power cos/sin law",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "auto-panner.js",
8
+ "exports": {
9
+ ".": "./auto-panner.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "auto-panner.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "spatial",
19
+ "stereo",
20
+ "autopan"
21
+ ],
22
+ "license": "MIT",
23
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }