@audio/effect-wah 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/package.json +38 -0
- package/wah.js +48 -0
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/effect-wah",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Wah-wah — swept resonant bandpass filter",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "wah.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./wah.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"wah.js"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"audio",
|
|
17
|
+
"dsp",
|
|
18
|
+
"effect",
|
|
19
|
+
"wah"
|
|
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-wah"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/audiojs/effect/tree/main/packages/effect-wah",
|
|
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/wah.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wah-wah — swept resonant bandpass filter
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
let {sin, pow, PI} = Math
|
|
6
|
+
|
|
7
|
+
export default function wah (data, params) {
|
|
8
|
+
let rate = params.rate == null ? 1.5 : params.rate
|
|
9
|
+
let depth = params.depth == null ? 0.8 : params.depth
|
|
10
|
+
let fc = params.fc || 1000
|
|
11
|
+
let Q = params.Q == null ? 5 : params.Q
|
|
12
|
+
let fs = params.fs || 44100
|
|
13
|
+
let mode = params.mode || 'auto'
|
|
14
|
+
|
|
15
|
+
if (params._lp == null) {
|
|
16
|
+
params._lp = 0
|
|
17
|
+
params._bp = 0
|
|
18
|
+
params._phase = 0
|
|
19
|
+
}
|
|
20
|
+
let lp = params._lp, bp = params._bp, phase = params._phase
|
|
21
|
+
let inc = 2 * PI * rate / fs
|
|
22
|
+
let q = 1 / Q
|
|
23
|
+
|
|
24
|
+
for (let i = 0, l = data.length; i < l; i++) {
|
|
25
|
+
let freq
|
|
26
|
+
if (mode === 'auto') {
|
|
27
|
+
let lfo = sin(phase)
|
|
28
|
+
phase += inc
|
|
29
|
+
if (phase > 2 * PI) phase -= 2 * PI
|
|
30
|
+
freq = fc * pow(2, depth * lfo)
|
|
31
|
+
} else {
|
|
32
|
+
freq = fc
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let f = 2 * sin(PI * freq / fs)
|
|
36
|
+
let x = data[i]
|
|
37
|
+
lp += f * bp
|
|
38
|
+
let hp = x - lp - q * bp
|
|
39
|
+
bp += f * hp
|
|
40
|
+
data[i] = bp
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
params._lp = lp
|
|
44
|
+
params._bp = bp
|
|
45
|
+
params._phase = phase
|
|
46
|
+
|
|
47
|
+
return data
|
|
48
|
+
}
|