@audio/spatial-microshift 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/microshift.js +36 -0
  2. package/package.json +29 -0
package/microshift.js ADDED
@@ -0,0 +1,36 @@
1
+ // Micro-pitch stereo widener (Eventide H3000/MicroShift class) — L detuned up, R detuned
2
+ // down by a few cents via 2-head varispeed ring readers, blended with the dry signal.
3
+
4
+ function shifter (cents, size) {
5
+ let ring = new Float32Array(size)
6
+ let w = 0, r = 0
7
+ let rate = 2 ** (cents / 1200)
8
+ return x => {
9
+ ring[w] = x
10
+ let head = pos => {
11
+ let p = pos % size; if (p < 0) p += size
12
+ let i0 = p | 0, frac = p - i0
13
+ return ring[i0] * (1 - frac) + ring[(i0 + 1) % size] * frac
14
+ }
15
+ let phase = (r % (size / 2)) / (size / 2)
16
+ let g = 1 - Math.abs(2 * phase - 1)
17
+ let y = head(r) * g + head(r + size / 2) * (1 - g)
18
+ r = (r + rate) % size
19
+ w = (w + 1) % size
20
+ return y
21
+ }
22
+ }
23
+
24
+ /**
25
+ * @param {Float32Array[]} [L, R] — modified in place
26
+ * @param {object} opts — { cents=9, mix=0.5, fs=44100 }
27
+ */
28
+ export default function microshift ([L, R], { cents = 9, mix = 0.5, fs = 44100 } = {}) {
29
+ let size = Math.max(256, Math.round(fs * 0.05))
30
+ let up = shifter(cents, size), down = shifter(-cents, size)
31
+ for (let i = 0; i < L.length; i++) {
32
+ L[i] = L[i] * (1 - mix) + up(L[i]) * mix
33
+ R[i] = R[i] * (1 - mix) + down(R[i]) * mix
34
+ }
35
+ return [L, R]
36
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@audio/spatial-microshift",
3
+ "version": "1.0.0",
4
+ "description": "Micro-pitch stereo widener — ±cents detuned copies (H3000 MicroShift class)",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "microshift.js",
8
+ "exports": {
9
+ ".": "./microshift.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "microshift.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "spatial",
19
+ "microshift"
20
+ ],
21
+ "license": "MIT",
22
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }