@audio/effect-pingpong 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/package.json +38 -0
  2. package/ping-pong.js +38 -0
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@audio/effect-pingpong",
3
+ "version": "1.0.0",
4
+ "description": "Ping-pong delay — stereo: left and right delays alternate",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "ping-pong.js",
8
+ "exports": {
9
+ ".": "./ping-pong.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "ping-pong.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "effect",
19
+ "pingpong"
20
+ ],
21
+ "license": "MIT",
22
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/audiojs/effect.git",
26
+ "directory": "packages/effect-pingpong"
27
+ },
28
+ "homepage": "https://github.com/audiojs/effect/tree/main/packages/effect-pingpong",
29
+ "bugs": {
30
+ "url": "https://github.com/audiojs/effect/issues"
31
+ },
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ }
38
+ }
package/ping-pong.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Ping-pong delay — stereo: left and right delays alternate.
3
+ * Takes two channel buffers, modifies both in-place.
4
+ */
5
+
6
+ export default function pingPong (left, right, params) {
7
+ let time = params.time ?? 0.25
8
+ let feedback = params.feedback ?? 0.4
9
+ let mix = params.mix ?? 0.5
10
+ let fs = params.fs || 44100
11
+
12
+ let delaySamples = (time * fs) | 0
13
+
14
+ if (!params._bufL || params._bufL.length < delaySamples) {
15
+ params._bufL = new Float64Array(delaySamples)
16
+ params._bufR = new Float64Array(delaySamples)
17
+ params._ptr = 0
18
+ }
19
+ let bufL = params._bufL, bufR = params._bufR, ptr = params._ptr
20
+
21
+ for (let i = 0, l = left.length; i < l; i++) {
22
+ let dL = bufL[ptr]
23
+ let dR = bufR[ptr]
24
+
25
+ // Cross-feed: left delay feeds right, right feeds left
26
+ bufL[ptr] = left[i] + feedback * dR
27
+ bufR[ptr] = right[i] + feedback * dL
28
+
29
+ left[i] = left[i] * (1 - mix) + dL * mix
30
+ right[i] = right[i] * (1 - mix) + dR * mix
31
+
32
+ ptr = (ptr + 1) % delaySamples
33
+ }
34
+
35
+ params._ptr = ptr
36
+
37
+ return [left, right]
38
+ }