@audio/spatial-haas 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/haas.js +30 -0
- package/package.json +30 -0
package/haas.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Haas effect — delays one channel by 1–35 ms to create phantom stereo image.
|
|
3
|
+
* Takes two channel buffers, modifies both in-place.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export default function haas (left, right, params) {
|
|
7
|
+
let time = params.time ?? 0.02 // seconds (20ms default)
|
|
8
|
+
let channel = params.channel ?? 'right'
|
|
9
|
+
let fs = params.fs || 44100
|
|
10
|
+
|
|
11
|
+
let delaySamples = (time * fs) | 0
|
|
12
|
+
let target = channel === 'left' ? left : right
|
|
13
|
+
|
|
14
|
+
if (!params.buffer || params.buffer.length < delaySamples) {
|
|
15
|
+
params.buffer = new Float64Array(delaySamples)
|
|
16
|
+
params.ptr = 0
|
|
17
|
+
}
|
|
18
|
+
let buf = params.buffer, ptr = params.ptr
|
|
19
|
+
|
|
20
|
+
for (let i = 0, l = target.length; i < l; i++) {
|
|
21
|
+
let delayed = buf[ptr]
|
|
22
|
+
buf[ptr] = target[i]
|
|
23
|
+
ptr = (ptr + 1) % delaySamples
|
|
24
|
+
target[i] = delayed
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
params.ptr = ptr
|
|
28
|
+
|
|
29
|
+
return [left, right]
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/spatial-haas",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Haas effect — delays one channel by 1–35 ms to create phantom stereo image",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "haas.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./haas.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"haas.js"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"audio",
|
|
17
|
+
"dsp",
|
|
18
|
+
"spatial",
|
|
19
|
+
"stereo",
|
|
20
|
+
"haas"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|