@audio/spatial-delay 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/delay.js +21 -0
  2. package/package.json +29 -0
package/delay.js ADDED
@@ -0,0 +1,21 @@
1
+ // Per-channel delay (FFmpeg adelay class) — integer-sample shifts, zero-filled.
2
+
3
+ /**
4
+ * @param {Float32Array[]} channels — modified in place
5
+ * @param {object} opts — { delays: number[] (ms per channel), fs=44100, samples: number[] (overrides ms) }
6
+ */
7
+ export default function delay (channels, { delays = [], fs = 44100, samples } = {}) {
8
+ for (let c = 0; c < channels.length; c++) {
9
+ let d = samples ? (samples[c] | 0) : Math.round((delays[c] || 0) * fs / 1000)
10
+ if (!d) continue
11
+ let ch = channels[c]
12
+ if (d > 0) {
13
+ ch.copyWithin(d, 0, ch.length - d)
14
+ ch.fill(0, 0, d)
15
+ } else {
16
+ ch.copyWithin(0, -d)
17
+ ch.fill(0, ch.length + d)
18
+ }
19
+ }
20
+ return channels
21
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@audio/spatial-delay",
3
+ "version": "1.0.0",
4
+ "description": "Per-channel delay in ms/samples (FFmpeg adelay)",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "delay.js",
8
+ "exports": {
9
+ ".": "./delay.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "delay.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "spatial",
19
+ "delay"
20
+ ],
21
+ "license": "MIT",
22
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }