@logue/reverb 1.1.0 → 1.2.1
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/README.md +1 -1
- package/dist/NoiseType.d.ts +1 -1
- package/dist/NoiseType.d.ts.map +1 -1
- package/dist/Reverb.d.ts +2 -2
- package/dist/Reverb.d.ts.map +1 -1
- package/dist/Reverb.es.js +167 -198
- package/dist/Reverb.iife.js +230 -2
- package/dist/Reverb.umd.js +233 -2
- package/dist/interfaces/OptionInterface.d.ts.map +1 -1
- package/package.json +25 -22
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://uiwjs.github.io/npm-unpkg/#/pkg/@logue/reverb/file/README.md)
|
|
6
6
|
[](https://www.npmjs.com/package/@logue/reverb)
|
|
7
7
|
[](https://gitpod.io/#https://github.com/logue/Reverb.js)
|
|
8
|
-
[](https://twitter.com/
|
|
8
|
+
[](https://twitter.com/logue256)
|
|
9
9
|
|
|
10
10
|
Append reverb effect to audio source.
|
|
11
11
|
|
package/dist/NoiseType.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Impulse response noise generation algorithm */
|
|
2
2
|
declare const Noise: Record<string, string>;
|
|
3
3
|
/** Noise Type */
|
|
4
|
-
export
|
|
4
|
+
export type NoiseType = typeof Noise[keyof typeof Noise];
|
|
5
5
|
/** Noise */
|
|
6
6
|
export default Noise;
|
|
7
7
|
//# sourceMappingURL=NoiseType.d.ts.map
|
package/dist/NoiseType.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoiseType.d.ts","sourceRoot":"","sources":["../src/NoiseType.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,QAAA,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAexB,CAAC;AAEX,iBAAiB;AACjB,
|
|
1
|
+
{"version":3,"file":"NoiseType.d.ts","sourceRoot":"","sources":["../src/NoiseType.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,QAAA,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAexB,CAAC;AAEX,iBAAiB;AACjB,MAAM,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC;AAEzD,YAAY;AACZ,eAAe,KAAK,CAAC"}
|
package/dist/Reverb.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export default class Reverb {
|
|
|
45
45
|
*
|
|
46
46
|
* @param sourceNode - Input source node
|
|
47
47
|
*/
|
|
48
|
-
disconnect(sourceNode
|
|
48
|
+
disconnect(sourceNode?: AudioNode): AudioNode | undefined;
|
|
49
49
|
/**
|
|
50
50
|
* Dry/Wet ratio
|
|
51
51
|
*
|
|
@@ -81,7 +81,7 @@ export default class Reverb {
|
|
|
81
81
|
*
|
|
82
82
|
* @param type - Filiter Type
|
|
83
83
|
*/
|
|
84
|
-
filterType(type
|
|
84
|
+
filterType(type?: BiquadFilterType): void;
|
|
85
85
|
/**
|
|
86
86
|
* Filter frequency applied to impulse response
|
|
87
87
|
*
|
package/dist/Reverb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.ts"],"names":[],"mappings":"AAEA,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAIhE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,sBAAsB;IACtB,MAAM,CAAC,OAAO,EAAE,MAAM,CAAgB;IACtC,iBAAiB;IACjB,MAAM,CAAC,KAAK,EAAE,MAAM,CAAa;IACjC,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,8BAA8B;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,uBAAuB;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,aAAa;IACb,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,qBAAqB;IACrB,OAAO,CAAC,WAAW,CAAU;IAC7B,sBAAsB;IACtB,OAAO,CAAC,KAAK,CAAmB;IAEhC;;;;;OAKG;gBACS,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,eAAe;
|
|
1
|
+
{"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.ts"],"names":[],"mappings":"AAEA,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAIhE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,sBAAsB;IACtB,MAAM,CAAC,OAAO,EAAE,MAAM,CAAgB;IACtC,iBAAiB;IACjB,MAAM,CAAC,KAAK,EAAE,MAAM,CAAa;IACjC,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,8BAA8B;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,uBAAuB;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,aAAa;IACb,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,qBAAqB;IACrB,OAAO,CAAC,WAAW,CAAU;IAC7B,sBAAsB;IACtB,OAAO,CAAC,KAAK,CAAmB;IAEhC;;;;;OAKG;gBACS,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,eAAe;IAqBxD;;;;OAIG;IACI,OAAO,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS;IAsBhD;;;;OAIG;IACI,UAAU,CAAC,UAAU,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS;IAehE;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAU7B;;;;OAIG;IACI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAahC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAajC;;;;OAIG;IACI,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAQtC;;;;OAIG;IACI,UAAU,CAAC,IAAI,GAAE,gBAA4B,GAAG,IAAI;IAK3D;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWrC;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAW/B;;;;OAIG;IACI,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAM7B;;;;OAIG;IACI,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAM7B;;;;OAIG;IACI,eAAe,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI;IAMtC;;;;OAIG;IACI,QAAQ,CAAC,IAAI,EAAE,SAAS;IA0B/B;;;;OAIG;IACI,kBAAkB,CAAC,SAAS,EAAE,KAAK;IAK1C;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAIf,oFAAoF;IACpF,OAAO,CAAC,YAAY;IA+CpB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;CAYjB"}
|
package/dist/Reverb.es.js
CHANGED
|
@@ -5,11 +5,15 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.1
|
|
8
|
+
* @version 1.2.1
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
import { SYSTEM } from '@thi.ng/random';
|
|
13
|
+
import { white, violet, red, pink, green, blue } from '@thi.ng/colored-noise';
|
|
14
|
+
import { take } from '@thi.ng/transducers';
|
|
15
|
+
|
|
16
|
+
const Noise = {
|
|
13
17
|
BLUE: "blue",
|
|
14
18
|
GREEN: "green",
|
|
15
19
|
PINK: "pink",
|
|
@@ -17,243 +21,209 @@ const a = {
|
|
|
17
21
|
VIOLET: "violet",
|
|
18
22
|
WHITE: "white",
|
|
19
23
|
BROWN: "red"
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
norm(e = 1) {
|
|
26
|
-
return (this.int() * g - 0.5) * 2 * e;
|
|
27
|
-
}
|
|
28
|
-
minmax(e, s) {
|
|
29
|
-
return this.float() * (s - e) + e;
|
|
30
|
-
}
|
|
31
|
-
minmaxInt(e, s) {
|
|
32
|
-
return e |= 0, s |= 0, e + (this.float() * (s - e) | 0);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const f = Math.random;
|
|
36
|
-
class k extends S {
|
|
37
|
-
int() {
|
|
38
|
-
return f() * 4294967296 >>> 0;
|
|
39
|
-
}
|
|
40
|
-
float(e = 1) {
|
|
41
|
-
return f() * e;
|
|
42
|
-
}
|
|
43
|
-
norm(e = 1) {
|
|
44
|
-
return (f() - 0.5) * 2 * e;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const h = new k(), G = {
|
|
48
|
-
noise: a.WHITE,
|
|
49
|
-
scale: 2,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const defaults = {
|
|
27
|
+
noise: Noise.WHITE,
|
|
28
|
+
scale: 1,
|
|
50
29
|
peaks: 2,
|
|
51
|
-
randomAlgorithm:
|
|
30
|
+
randomAlgorithm: SYSTEM,
|
|
52
31
|
decay: 2,
|
|
53
32
|
delay: 0,
|
|
54
|
-
reverse:
|
|
33
|
+
reverse: false,
|
|
55
34
|
time: 2,
|
|
56
|
-
filterType: "
|
|
35
|
+
filterType: "allpass",
|
|
57
36
|
filterFreq: 2200,
|
|
58
37
|
filterQ: 1,
|
|
59
38
|
mix: 0.5,
|
|
60
|
-
once:
|
|
61
|
-
}, w = {
|
|
62
|
-
version: "1.1.0",
|
|
63
|
-
date: "2022-10-04T02:13:31.946Z"
|
|
64
|
-
}, b = (t, e, s) => {
|
|
65
|
-
const o = new Array(t);
|
|
66
|
-
for (let n = 0; n < t; n++)
|
|
67
|
-
o[n] = s.norm(e);
|
|
68
|
-
return o;
|
|
69
|
-
}, R = (t) => t.reduce((e, s) => e + s, 0);
|
|
70
|
-
function* I(t, e) {
|
|
71
|
-
const s = [t[Symbol.iterator](), e[Symbol.iterator]()];
|
|
72
|
-
for (let o = 0; ; o ^= 1) {
|
|
73
|
-
const n = s[o].next();
|
|
74
|
-
if (n.done)
|
|
75
|
-
return;
|
|
76
|
-
yield n.value;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function* p(t = 2, e = 1, s = h) {
|
|
80
|
-
const o = b(t, e, s);
|
|
81
|
-
o.forEach((i, c) => o[c] = c & 1 ? i : -i);
|
|
82
|
-
const n = 1 / t;
|
|
83
|
-
let r = R(o);
|
|
84
|
-
for (let i = 0, c = -1; ; ++i >= t && (i = 0))
|
|
85
|
-
r -= o[i], r += o[i] = c * s.norm(e), c ^= 4294967294, yield c * r * n;
|
|
86
|
-
}
|
|
87
|
-
const A = (t = 2, e = 1, s = h) => I(p(t, e, s), p(t, e, s)), T = (t) => {
|
|
88
|
-
let e = 32;
|
|
89
|
-
return t &= -t, t && e--, t & 65535 && (e -= 16), t & 16711935 && (e -= 8), t & 252645135 && (e -= 4), t & 858993459 && (e -= 2), t & 1431655765 && (e -= 1), e;
|
|
39
|
+
once: false
|
|
90
40
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (L(i)) {
|
|
128
|
-
yield* N(o(i.deref()));
|
|
129
|
-
return;
|
|
41
|
+
|
|
42
|
+
const meta = {
|
|
43
|
+
version: "1.2.1",
|
|
44
|
+
date: "2022-11-24T14:46:07.438Z"
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
class Reverb {
|
|
48
|
+
static version = meta.version;
|
|
49
|
+
static build = meta.date;
|
|
50
|
+
ctx;
|
|
51
|
+
wetGainNode;
|
|
52
|
+
dryGainNode;
|
|
53
|
+
filterNode;
|
|
54
|
+
convolverNode;
|
|
55
|
+
outputNode;
|
|
56
|
+
options;
|
|
57
|
+
isConnected;
|
|
58
|
+
noise = white;
|
|
59
|
+
constructor(ctx, options) {
|
|
60
|
+
this.ctx = ctx;
|
|
61
|
+
this.options = { ...defaults, ...options };
|
|
62
|
+
this.wetGainNode = this.ctx.createGain();
|
|
63
|
+
this.dryGainNode = this.ctx.createGain();
|
|
64
|
+
this.filterNode = this.ctx.createBiquadFilter();
|
|
65
|
+
this.convolverNode = this.ctx.createConvolver();
|
|
66
|
+
this.outputNode = this.ctx.createGain();
|
|
67
|
+
this.isConnected = false;
|
|
68
|
+
this.filterType(this.options.filterType);
|
|
69
|
+
this.setNoise(this.options.noise);
|
|
70
|
+
this.buildImpulse();
|
|
71
|
+
this.mix(this.options.mix);
|
|
72
|
+
}
|
|
73
|
+
connect(sourceNode) {
|
|
74
|
+
if (this.isConnected && this.options.once) {
|
|
75
|
+
this.isConnected = false;
|
|
76
|
+
return this.outputNode;
|
|
130
77
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
connect(e) {
|
|
148
|
-
return this.isConnected && this.options.once ? (this.isConnected = !1, this.outputNode) : (this.convolverNode.connect(this.filterNode), this.filterNode.connect(this.wetGainNode), e.connect(this.convolverNode), e.connect(this.dryGainNode).connect(this.outputNode), e.connect(this.wetGainNode).connect(this.outputNode), this.isConnected = !0, this.outputNode);
|
|
149
|
-
}
|
|
150
|
-
disconnect(e) {
|
|
151
|
-
return this.isConnected && (this.convolverNode.disconnect(this.filterNode), this.filterNode.disconnect(this.wetGainNode)), this.isConnected = !1, e;
|
|
78
|
+
this.convolverNode.connect(this.filterNode);
|
|
79
|
+
this.filterNode.connect(this.wetGainNode);
|
|
80
|
+
sourceNode.connect(this.convolverNode);
|
|
81
|
+
sourceNode.connect(this.dryGainNode).connect(this.outputNode);
|
|
82
|
+
sourceNode.connect(this.wetGainNode).connect(this.outputNode);
|
|
83
|
+
this.isConnected = true;
|
|
84
|
+
return this.outputNode;
|
|
85
|
+
}
|
|
86
|
+
disconnect(sourceNode) {
|
|
87
|
+
if (this.isConnected) {
|
|
88
|
+
this.convolverNode.disconnect(this.filterNode);
|
|
89
|
+
this.filterNode.disconnect(this.wetGainNode);
|
|
90
|
+
}
|
|
91
|
+
this.isConnected = false;
|
|
92
|
+
return sourceNode;
|
|
152
93
|
}
|
|
153
|
-
mix(
|
|
154
|
-
if (!this.inRange(
|
|
94
|
+
mix(mix) {
|
|
95
|
+
if (!this.inRange(mix, 0, 1)) {
|
|
155
96
|
throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
|
|
156
|
-
|
|
97
|
+
}
|
|
98
|
+
this.options.mix = mix;
|
|
99
|
+
this.dryGainNode.gain.value = 1 - this.options.mix;
|
|
100
|
+
this.wetGainNode.gain.value = this.options.mix;
|
|
157
101
|
}
|
|
158
|
-
time(
|
|
159
|
-
if (!this.inRange(
|
|
102
|
+
time(value) {
|
|
103
|
+
if (!this.inRange(value, 1, 50)) {
|
|
160
104
|
throw new RangeError(
|
|
161
105
|
"[Reverb.js] Time length of inpulse response must be less than 50sec."
|
|
162
106
|
);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
);
|
|
107
|
+
}
|
|
108
|
+
this.options.time = value;
|
|
109
|
+
this.buildImpulse();
|
|
166
110
|
}
|
|
167
|
-
decay(
|
|
168
|
-
if (!this.inRange(
|
|
111
|
+
decay(value) {
|
|
112
|
+
if (!this.inRange(value, 0, 100)) {
|
|
169
113
|
throw new RangeError(
|
|
170
114
|
"[Reverb.js] Inpulse Response decay level must be less than 100."
|
|
171
115
|
);
|
|
172
|
-
|
|
116
|
+
}
|
|
117
|
+
this.options.decay = value;
|
|
118
|
+
this.buildImpulse();
|
|
173
119
|
}
|
|
174
|
-
delay(
|
|
175
|
-
if (!this.inRange(
|
|
120
|
+
delay(value) {
|
|
121
|
+
if (!this.inRange(value, 0, 100)) {
|
|
176
122
|
throw new RangeError(
|
|
177
123
|
"[Reverb.js] Inpulse Response delay time must be less than 100."
|
|
178
124
|
);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
);
|
|
125
|
+
}
|
|
126
|
+
this.options.delay = value;
|
|
127
|
+
this.buildImpulse();
|
|
182
128
|
}
|
|
183
|
-
reverse(
|
|
184
|
-
this.options.reverse =
|
|
185
|
-
|
|
186
|
-
);
|
|
129
|
+
reverse(reverse) {
|
|
130
|
+
this.options.reverse = reverse;
|
|
131
|
+
this.buildImpulse();
|
|
187
132
|
}
|
|
188
|
-
filterType(
|
|
189
|
-
this.filterNode.type = this.options.filterType =
|
|
133
|
+
filterType(type = "allpass") {
|
|
134
|
+
this.filterNode.type = this.options.filterType = type;
|
|
190
135
|
}
|
|
191
|
-
filterFreq(
|
|
192
|
-
if (!this.inRange(
|
|
136
|
+
filterFreq(freq) {
|
|
137
|
+
if (!this.inRange(freq, 20, 2e4)) {
|
|
193
138
|
throw new RangeError(
|
|
194
139
|
"[Reverb.js] Filter frequrncy must be between 20 and 20000."
|
|
195
140
|
);
|
|
196
|
-
|
|
141
|
+
}
|
|
142
|
+
this.options.filterFreq = freq;
|
|
143
|
+
this.filterNode.frequency.value = this.options.filterFreq;
|
|
197
144
|
}
|
|
198
|
-
filterQ(
|
|
199
|
-
if (!this.inRange(
|
|
145
|
+
filterQ(q) {
|
|
146
|
+
if (!this.inRange(q, 0, 10)) {
|
|
200
147
|
throw new RangeError(
|
|
201
148
|
"[Reverb.js] Filter quality value must be between 0 and 10."
|
|
202
149
|
);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
this.
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
this.options.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
150
|
+
}
|
|
151
|
+
this.options.filterQ = q;
|
|
152
|
+
this.filterNode.Q.value = this.options.filterQ;
|
|
153
|
+
}
|
|
154
|
+
peaks(p) {
|
|
155
|
+
this.options.peaks = p;
|
|
156
|
+
this.buildImpulse();
|
|
157
|
+
}
|
|
158
|
+
scale(s) {
|
|
159
|
+
this.options.scale = s;
|
|
160
|
+
this.buildImpulse();
|
|
161
|
+
}
|
|
162
|
+
randomAlgorithm(a) {
|
|
163
|
+
this.options.randomAlgorithm = a;
|
|
164
|
+
this.buildImpulse();
|
|
165
|
+
}
|
|
166
|
+
setNoise(type) {
|
|
167
|
+
this.options.noise = type;
|
|
168
|
+
switch (type) {
|
|
169
|
+
case Noise.BLUE:
|
|
170
|
+
this.noise = blue;
|
|
218
171
|
break;
|
|
219
|
-
case
|
|
220
|
-
this.noise =
|
|
172
|
+
case Noise.GREEN:
|
|
173
|
+
this.noise = green;
|
|
221
174
|
break;
|
|
222
|
-
case
|
|
223
|
-
this.noise =
|
|
175
|
+
case Noise.PINK:
|
|
176
|
+
this.noise = pink;
|
|
224
177
|
break;
|
|
225
|
-
case
|
|
226
|
-
case
|
|
227
|
-
this.noise =
|
|
178
|
+
case Noise.RED:
|
|
179
|
+
case Noise.BROWN:
|
|
180
|
+
this.noise = red;
|
|
228
181
|
break;
|
|
229
|
-
case
|
|
230
|
-
this.noise =
|
|
182
|
+
case Noise.VIOLET:
|
|
183
|
+
this.noise = violet;
|
|
231
184
|
break;
|
|
232
185
|
default:
|
|
233
|
-
this.noise =
|
|
234
|
-
break;
|
|
186
|
+
this.noise = white;
|
|
235
187
|
}
|
|
236
|
-
this.buildImpulse()
|
|
188
|
+
this.buildImpulse();
|
|
237
189
|
}
|
|
238
|
-
setRandomAlgorythm(
|
|
239
|
-
this.options.randomAlgorithm =
|
|
190
|
+
setRandomAlgorythm(algorithm) {
|
|
191
|
+
this.options.randomAlgorithm = algorithm;
|
|
192
|
+
this.buildImpulse();
|
|
240
193
|
}
|
|
241
|
-
inRange(
|
|
242
|
-
return (
|
|
194
|
+
inRange(x, min, max) {
|
|
195
|
+
return (x - min) * (x - max) <= 0;
|
|
243
196
|
}
|
|
244
197
|
buildImpulse() {
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
198
|
+
const rate = this.ctx.sampleRate;
|
|
199
|
+
const duration = Math.max(rate * this.options.time, 1);
|
|
200
|
+
const delayDuration = rate * this.options.delay;
|
|
201
|
+
const impulse = this.ctx.createBuffer(2, duration, rate);
|
|
202
|
+
const impulseL = new Float32Array(duration);
|
|
203
|
+
const impulseR = new Float32Array(duration);
|
|
204
|
+
const noiseL = this.getNoise(duration);
|
|
205
|
+
const noiseR = this.getNoise(duration);
|
|
206
|
+
for (let i = 0; i < duration; i++) {
|
|
207
|
+
let n = 0;
|
|
208
|
+
if (i < delayDuration) {
|
|
209
|
+
impulseL[i] = 0;
|
|
210
|
+
impulseR[i] = 0;
|
|
211
|
+
n = this.options.reverse ? duration - (i - delayDuration) : i - delayDuration;
|
|
212
|
+
} else {
|
|
213
|
+
n = this.options.reverse ? duration - i : i;
|
|
214
|
+
}
|
|
215
|
+
impulseL[i] = noiseL[i] * (1 - n / duration) ** this.options.decay;
|
|
216
|
+
impulseR[i] = noiseR[i] * (1 - n / duration) ** this.options.decay;
|
|
249
217
|
}
|
|
250
|
-
|
|
218
|
+
impulse.getChannelData(0).set(impulseL);
|
|
219
|
+
impulse.getChannelData(1).set(impulseR);
|
|
220
|
+
this.convolverNode.buffer = impulse;
|
|
251
221
|
}
|
|
252
|
-
getNoise(
|
|
222
|
+
getNoise(duration) {
|
|
253
223
|
return [
|
|
254
|
-
...
|
|
255
|
-
|
|
256
|
-
this.
|
|
224
|
+
...take(
|
|
225
|
+
duration,
|
|
226
|
+
this.noise(
|
|
257
227
|
this.options.peaks,
|
|
258
228
|
this.options.scale,
|
|
259
229
|
this.options.randomAlgorithm
|
|
@@ -262,9 +232,8 @@ class v {
|
|
|
262
232
|
];
|
|
263
233
|
}
|
|
264
234
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
};
|
|
235
|
+
if (!window.Reverb) {
|
|
236
|
+
window.Reverb = Reverb;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export { Reverb as default };
|
package/dist/Reverb.iife.js
CHANGED
|
@@ -5,8 +5,236 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.1
|
|
8
|
+
* @version 1.2.1
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
var Reverb
|
|
12
|
+
var Reverb = (function (random, coloredNoise, transducers) {
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const Noise = {
|
|
16
|
+
BLUE: "blue",
|
|
17
|
+
GREEN: "green",
|
|
18
|
+
PINK: "pink",
|
|
19
|
+
RED: "red",
|
|
20
|
+
VIOLET: "violet",
|
|
21
|
+
WHITE: "white",
|
|
22
|
+
BROWN: "red"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const defaults = {
|
|
26
|
+
noise: Noise.WHITE,
|
|
27
|
+
scale: 1,
|
|
28
|
+
peaks: 2,
|
|
29
|
+
randomAlgorithm: random.SYSTEM,
|
|
30
|
+
decay: 2,
|
|
31
|
+
delay: 0,
|
|
32
|
+
reverse: false,
|
|
33
|
+
time: 2,
|
|
34
|
+
filterType: "allpass",
|
|
35
|
+
filterFreq: 2200,
|
|
36
|
+
filterQ: 1,
|
|
37
|
+
mix: 0.5,
|
|
38
|
+
once: false
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const meta = {
|
|
42
|
+
version: "1.2.1",
|
|
43
|
+
date: "2022-11-24T14:46:07.438Z"
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
class Reverb {
|
|
47
|
+
static version = meta.version;
|
|
48
|
+
static build = meta.date;
|
|
49
|
+
ctx;
|
|
50
|
+
wetGainNode;
|
|
51
|
+
dryGainNode;
|
|
52
|
+
filterNode;
|
|
53
|
+
convolverNode;
|
|
54
|
+
outputNode;
|
|
55
|
+
options;
|
|
56
|
+
isConnected;
|
|
57
|
+
noise = coloredNoise.white;
|
|
58
|
+
constructor(ctx, options) {
|
|
59
|
+
this.ctx = ctx;
|
|
60
|
+
this.options = { ...defaults, ...options };
|
|
61
|
+
this.wetGainNode = this.ctx.createGain();
|
|
62
|
+
this.dryGainNode = this.ctx.createGain();
|
|
63
|
+
this.filterNode = this.ctx.createBiquadFilter();
|
|
64
|
+
this.convolverNode = this.ctx.createConvolver();
|
|
65
|
+
this.outputNode = this.ctx.createGain();
|
|
66
|
+
this.isConnected = false;
|
|
67
|
+
this.filterType(this.options.filterType);
|
|
68
|
+
this.setNoise(this.options.noise);
|
|
69
|
+
this.buildImpulse();
|
|
70
|
+
this.mix(this.options.mix);
|
|
71
|
+
}
|
|
72
|
+
connect(sourceNode) {
|
|
73
|
+
if (this.isConnected && this.options.once) {
|
|
74
|
+
this.isConnected = false;
|
|
75
|
+
return this.outputNode;
|
|
76
|
+
}
|
|
77
|
+
this.convolverNode.connect(this.filterNode);
|
|
78
|
+
this.filterNode.connect(this.wetGainNode);
|
|
79
|
+
sourceNode.connect(this.convolverNode);
|
|
80
|
+
sourceNode.connect(this.dryGainNode).connect(this.outputNode);
|
|
81
|
+
sourceNode.connect(this.wetGainNode).connect(this.outputNode);
|
|
82
|
+
this.isConnected = true;
|
|
83
|
+
return this.outputNode;
|
|
84
|
+
}
|
|
85
|
+
disconnect(sourceNode) {
|
|
86
|
+
if (this.isConnected) {
|
|
87
|
+
this.convolverNode.disconnect(this.filterNode);
|
|
88
|
+
this.filterNode.disconnect(this.wetGainNode);
|
|
89
|
+
}
|
|
90
|
+
this.isConnected = false;
|
|
91
|
+
return sourceNode;
|
|
92
|
+
}
|
|
93
|
+
mix(mix) {
|
|
94
|
+
if (!this.inRange(mix, 0, 1)) {
|
|
95
|
+
throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
|
|
96
|
+
}
|
|
97
|
+
this.options.mix = mix;
|
|
98
|
+
this.dryGainNode.gain.value = 1 - this.options.mix;
|
|
99
|
+
this.wetGainNode.gain.value = this.options.mix;
|
|
100
|
+
}
|
|
101
|
+
time(value) {
|
|
102
|
+
if (!this.inRange(value, 1, 50)) {
|
|
103
|
+
throw new RangeError(
|
|
104
|
+
"[Reverb.js] Time length of inpulse response must be less than 50sec."
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
this.options.time = value;
|
|
108
|
+
this.buildImpulse();
|
|
109
|
+
}
|
|
110
|
+
decay(value) {
|
|
111
|
+
if (!this.inRange(value, 0, 100)) {
|
|
112
|
+
throw new RangeError(
|
|
113
|
+
"[Reverb.js] Inpulse Response decay level must be less than 100."
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
this.options.decay = value;
|
|
117
|
+
this.buildImpulse();
|
|
118
|
+
}
|
|
119
|
+
delay(value) {
|
|
120
|
+
if (!this.inRange(value, 0, 100)) {
|
|
121
|
+
throw new RangeError(
|
|
122
|
+
"[Reverb.js] Inpulse Response delay time must be less than 100."
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
this.options.delay = value;
|
|
126
|
+
this.buildImpulse();
|
|
127
|
+
}
|
|
128
|
+
reverse(reverse) {
|
|
129
|
+
this.options.reverse = reverse;
|
|
130
|
+
this.buildImpulse();
|
|
131
|
+
}
|
|
132
|
+
filterType(type = "allpass") {
|
|
133
|
+
this.filterNode.type = this.options.filterType = type;
|
|
134
|
+
}
|
|
135
|
+
filterFreq(freq) {
|
|
136
|
+
if (!this.inRange(freq, 20, 2e4)) {
|
|
137
|
+
throw new RangeError(
|
|
138
|
+
"[Reverb.js] Filter frequrncy must be between 20 and 20000."
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
this.options.filterFreq = freq;
|
|
142
|
+
this.filterNode.frequency.value = this.options.filterFreq;
|
|
143
|
+
}
|
|
144
|
+
filterQ(q) {
|
|
145
|
+
if (!this.inRange(q, 0, 10)) {
|
|
146
|
+
throw new RangeError(
|
|
147
|
+
"[Reverb.js] Filter quality value must be between 0 and 10."
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
this.options.filterQ = q;
|
|
151
|
+
this.filterNode.Q.value = this.options.filterQ;
|
|
152
|
+
}
|
|
153
|
+
peaks(p) {
|
|
154
|
+
this.options.peaks = p;
|
|
155
|
+
this.buildImpulse();
|
|
156
|
+
}
|
|
157
|
+
scale(s) {
|
|
158
|
+
this.options.scale = s;
|
|
159
|
+
this.buildImpulse();
|
|
160
|
+
}
|
|
161
|
+
randomAlgorithm(a) {
|
|
162
|
+
this.options.randomAlgorithm = a;
|
|
163
|
+
this.buildImpulse();
|
|
164
|
+
}
|
|
165
|
+
setNoise(type) {
|
|
166
|
+
this.options.noise = type;
|
|
167
|
+
switch (type) {
|
|
168
|
+
case Noise.BLUE:
|
|
169
|
+
this.noise = coloredNoise.blue;
|
|
170
|
+
break;
|
|
171
|
+
case Noise.GREEN:
|
|
172
|
+
this.noise = coloredNoise.green;
|
|
173
|
+
break;
|
|
174
|
+
case Noise.PINK:
|
|
175
|
+
this.noise = coloredNoise.pink;
|
|
176
|
+
break;
|
|
177
|
+
case Noise.RED:
|
|
178
|
+
case Noise.BROWN:
|
|
179
|
+
this.noise = coloredNoise.red;
|
|
180
|
+
break;
|
|
181
|
+
case Noise.VIOLET:
|
|
182
|
+
this.noise = coloredNoise.violet;
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
this.noise = coloredNoise.white;
|
|
186
|
+
}
|
|
187
|
+
this.buildImpulse();
|
|
188
|
+
}
|
|
189
|
+
setRandomAlgorythm(algorithm) {
|
|
190
|
+
this.options.randomAlgorithm = algorithm;
|
|
191
|
+
this.buildImpulse();
|
|
192
|
+
}
|
|
193
|
+
inRange(x, min, max) {
|
|
194
|
+
return (x - min) * (x - max) <= 0;
|
|
195
|
+
}
|
|
196
|
+
buildImpulse() {
|
|
197
|
+
const rate = this.ctx.sampleRate;
|
|
198
|
+
const duration = Math.max(rate * this.options.time, 1);
|
|
199
|
+
const delayDuration = rate * this.options.delay;
|
|
200
|
+
const impulse = this.ctx.createBuffer(2, duration, rate);
|
|
201
|
+
const impulseL = new Float32Array(duration);
|
|
202
|
+
const impulseR = new Float32Array(duration);
|
|
203
|
+
const noiseL = this.getNoise(duration);
|
|
204
|
+
const noiseR = this.getNoise(duration);
|
|
205
|
+
for (let i = 0; i < duration; i++) {
|
|
206
|
+
let n = 0;
|
|
207
|
+
if (i < delayDuration) {
|
|
208
|
+
impulseL[i] = 0;
|
|
209
|
+
impulseR[i] = 0;
|
|
210
|
+
n = this.options.reverse ? duration - (i - delayDuration) : i - delayDuration;
|
|
211
|
+
} else {
|
|
212
|
+
n = this.options.reverse ? duration - i : i;
|
|
213
|
+
}
|
|
214
|
+
impulseL[i] = noiseL[i] * (1 - n / duration) ** this.options.decay;
|
|
215
|
+
impulseR[i] = noiseR[i] * (1 - n / duration) ** this.options.decay;
|
|
216
|
+
}
|
|
217
|
+
impulse.getChannelData(0).set(impulseL);
|
|
218
|
+
impulse.getChannelData(1).set(impulseR);
|
|
219
|
+
this.convolverNode.buffer = impulse;
|
|
220
|
+
}
|
|
221
|
+
getNoise(duration) {
|
|
222
|
+
return [
|
|
223
|
+
...transducers.take(
|
|
224
|
+
duration,
|
|
225
|
+
this.noise(
|
|
226
|
+
this.options.peaks,
|
|
227
|
+
this.options.scale,
|
|
228
|
+
this.options.randomAlgorithm
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!window.Reverb) {
|
|
235
|
+
window.Reverb = Reverb;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return Reverb;
|
|
239
|
+
|
|
240
|
+
})(random, colordNoise, transducers);
|
package/dist/Reverb.umd.js
CHANGED
|
@@ -5,8 +5,239 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.1
|
|
8
|
+
* @version 1.2.1
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
(function
|
|
12
|
+
(function (global, factory) {
|
|
13
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@thi.ng/random'), require('@thi.ng/colored-noise'), require('@thi.ng/transducers')) :
|
|
14
|
+
typeof define === 'function' && define.amd ? define(['@thi.ng/random', '@thi.ng/colored-noise', '@thi.ng/transducers'], factory) :
|
|
15
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Reverb = factory(global.random, global.colordNoise, global.transducers));
|
|
16
|
+
})(this, (function (random, coloredNoise, transducers) { 'use strict';
|
|
17
|
+
|
|
18
|
+
const Noise = {
|
|
19
|
+
BLUE: "blue",
|
|
20
|
+
GREEN: "green",
|
|
21
|
+
PINK: "pink",
|
|
22
|
+
RED: "red",
|
|
23
|
+
VIOLET: "violet",
|
|
24
|
+
WHITE: "white",
|
|
25
|
+
BROWN: "red"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const defaults = {
|
|
29
|
+
noise: Noise.WHITE,
|
|
30
|
+
scale: 1,
|
|
31
|
+
peaks: 2,
|
|
32
|
+
randomAlgorithm: random.SYSTEM,
|
|
33
|
+
decay: 2,
|
|
34
|
+
delay: 0,
|
|
35
|
+
reverse: false,
|
|
36
|
+
time: 2,
|
|
37
|
+
filterType: "allpass",
|
|
38
|
+
filterFreq: 2200,
|
|
39
|
+
filterQ: 1,
|
|
40
|
+
mix: 0.5,
|
|
41
|
+
once: false
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const meta = {
|
|
45
|
+
version: "1.2.1",
|
|
46
|
+
date: "2022-11-24T14:46:07.438Z"
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
class Reverb {
|
|
50
|
+
static version = meta.version;
|
|
51
|
+
static build = meta.date;
|
|
52
|
+
ctx;
|
|
53
|
+
wetGainNode;
|
|
54
|
+
dryGainNode;
|
|
55
|
+
filterNode;
|
|
56
|
+
convolverNode;
|
|
57
|
+
outputNode;
|
|
58
|
+
options;
|
|
59
|
+
isConnected;
|
|
60
|
+
noise = coloredNoise.white;
|
|
61
|
+
constructor(ctx, options) {
|
|
62
|
+
this.ctx = ctx;
|
|
63
|
+
this.options = { ...defaults, ...options };
|
|
64
|
+
this.wetGainNode = this.ctx.createGain();
|
|
65
|
+
this.dryGainNode = this.ctx.createGain();
|
|
66
|
+
this.filterNode = this.ctx.createBiquadFilter();
|
|
67
|
+
this.convolverNode = this.ctx.createConvolver();
|
|
68
|
+
this.outputNode = this.ctx.createGain();
|
|
69
|
+
this.isConnected = false;
|
|
70
|
+
this.filterType(this.options.filterType);
|
|
71
|
+
this.setNoise(this.options.noise);
|
|
72
|
+
this.buildImpulse();
|
|
73
|
+
this.mix(this.options.mix);
|
|
74
|
+
}
|
|
75
|
+
connect(sourceNode) {
|
|
76
|
+
if (this.isConnected && this.options.once) {
|
|
77
|
+
this.isConnected = false;
|
|
78
|
+
return this.outputNode;
|
|
79
|
+
}
|
|
80
|
+
this.convolverNode.connect(this.filterNode);
|
|
81
|
+
this.filterNode.connect(this.wetGainNode);
|
|
82
|
+
sourceNode.connect(this.convolverNode);
|
|
83
|
+
sourceNode.connect(this.dryGainNode).connect(this.outputNode);
|
|
84
|
+
sourceNode.connect(this.wetGainNode).connect(this.outputNode);
|
|
85
|
+
this.isConnected = true;
|
|
86
|
+
return this.outputNode;
|
|
87
|
+
}
|
|
88
|
+
disconnect(sourceNode) {
|
|
89
|
+
if (this.isConnected) {
|
|
90
|
+
this.convolverNode.disconnect(this.filterNode);
|
|
91
|
+
this.filterNode.disconnect(this.wetGainNode);
|
|
92
|
+
}
|
|
93
|
+
this.isConnected = false;
|
|
94
|
+
return sourceNode;
|
|
95
|
+
}
|
|
96
|
+
mix(mix) {
|
|
97
|
+
if (!this.inRange(mix, 0, 1)) {
|
|
98
|
+
throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
|
|
99
|
+
}
|
|
100
|
+
this.options.mix = mix;
|
|
101
|
+
this.dryGainNode.gain.value = 1 - this.options.mix;
|
|
102
|
+
this.wetGainNode.gain.value = this.options.mix;
|
|
103
|
+
}
|
|
104
|
+
time(value) {
|
|
105
|
+
if (!this.inRange(value, 1, 50)) {
|
|
106
|
+
throw new RangeError(
|
|
107
|
+
"[Reverb.js] Time length of inpulse response must be less than 50sec."
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
this.options.time = value;
|
|
111
|
+
this.buildImpulse();
|
|
112
|
+
}
|
|
113
|
+
decay(value) {
|
|
114
|
+
if (!this.inRange(value, 0, 100)) {
|
|
115
|
+
throw new RangeError(
|
|
116
|
+
"[Reverb.js] Inpulse Response decay level must be less than 100."
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
this.options.decay = value;
|
|
120
|
+
this.buildImpulse();
|
|
121
|
+
}
|
|
122
|
+
delay(value) {
|
|
123
|
+
if (!this.inRange(value, 0, 100)) {
|
|
124
|
+
throw new RangeError(
|
|
125
|
+
"[Reverb.js] Inpulse Response delay time must be less than 100."
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
this.options.delay = value;
|
|
129
|
+
this.buildImpulse();
|
|
130
|
+
}
|
|
131
|
+
reverse(reverse) {
|
|
132
|
+
this.options.reverse = reverse;
|
|
133
|
+
this.buildImpulse();
|
|
134
|
+
}
|
|
135
|
+
filterType(type = "allpass") {
|
|
136
|
+
this.filterNode.type = this.options.filterType = type;
|
|
137
|
+
}
|
|
138
|
+
filterFreq(freq) {
|
|
139
|
+
if (!this.inRange(freq, 20, 2e4)) {
|
|
140
|
+
throw new RangeError(
|
|
141
|
+
"[Reverb.js] Filter frequrncy must be between 20 and 20000."
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
this.options.filterFreq = freq;
|
|
145
|
+
this.filterNode.frequency.value = this.options.filterFreq;
|
|
146
|
+
}
|
|
147
|
+
filterQ(q) {
|
|
148
|
+
if (!this.inRange(q, 0, 10)) {
|
|
149
|
+
throw new RangeError(
|
|
150
|
+
"[Reverb.js] Filter quality value must be between 0 and 10."
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
this.options.filterQ = q;
|
|
154
|
+
this.filterNode.Q.value = this.options.filterQ;
|
|
155
|
+
}
|
|
156
|
+
peaks(p) {
|
|
157
|
+
this.options.peaks = p;
|
|
158
|
+
this.buildImpulse();
|
|
159
|
+
}
|
|
160
|
+
scale(s) {
|
|
161
|
+
this.options.scale = s;
|
|
162
|
+
this.buildImpulse();
|
|
163
|
+
}
|
|
164
|
+
randomAlgorithm(a) {
|
|
165
|
+
this.options.randomAlgorithm = a;
|
|
166
|
+
this.buildImpulse();
|
|
167
|
+
}
|
|
168
|
+
setNoise(type) {
|
|
169
|
+
this.options.noise = type;
|
|
170
|
+
switch (type) {
|
|
171
|
+
case Noise.BLUE:
|
|
172
|
+
this.noise = coloredNoise.blue;
|
|
173
|
+
break;
|
|
174
|
+
case Noise.GREEN:
|
|
175
|
+
this.noise = coloredNoise.green;
|
|
176
|
+
break;
|
|
177
|
+
case Noise.PINK:
|
|
178
|
+
this.noise = coloredNoise.pink;
|
|
179
|
+
break;
|
|
180
|
+
case Noise.RED:
|
|
181
|
+
case Noise.BROWN:
|
|
182
|
+
this.noise = coloredNoise.red;
|
|
183
|
+
break;
|
|
184
|
+
case Noise.VIOLET:
|
|
185
|
+
this.noise = coloredNoise.violet;
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
this.noise = coloredNoise.white;
|
|
189
|
+
}
|
|
190
|
+
this.buildImpulse();
|
|
191
|
+
}
|
|
192
|
+
setRandomAlgorythm(algorithm) {
|
|
193
|
+
this.options.randomAlgorithm = algorithm;
|
|
194
|
+
this.buildImpulse();
|
|
195
|
+
}
|
|
196
|
+
inRange(x, min, max) {
|
|
197
|
+
return (x - min) * (x - max) <= 0;
|
|
198
|
+
}
|
|
199
|
+
buildImpulse() {
|
|
200
|
+
const rate = this.ctx.sampleRate;
|
|
201
|
+
const duration = Math.max(rate * this.options.time, 1);
|
|
202
|
+
const delayDuration = rate * this.options.delay;
|
|
203
|
+
const impulse = this.ctx.createBuffer(2, duration, rate);
|
|
204
|
+
const impulseL = new Float32Array(duration);
|
|
205
|
+
const impulseR = new Float32Array(duration);
|
|
206
|
+
const noiseL = this.getNoise(duration);
|
|
207
|
+
const noiseR = this.getNoise(duration);
|
|
208
|
+
for (let i = 0; i < duration; i++) {
|
|
209
|
+
let n = 0;
|
|
210
|
+
if (i < delayDuration) {
|
|
211
|
+
impulseL[i] = 0;
|
|
212
|
+
impulseR[i] = 0;
|
|
213
|
+
n = this.options.reverse ? duration - (i - delayDuration) : i - delayDuration;
|
|
214
|
+
} else {
|
|
215
|
+
n = this.options.reverse ? duration - i : i;
|
|
216
|
+
}
|
|
217
|
+
impulseL[i] = noiseL[i] * (1 - n / duration) ** this.options.decay;
|
|
218
|
+
impulseR[i] = noiseR[i] * (1 - n / duration) ** this.options.decay;
|
|
219
|
+
}
|
|
220
|
+
impulse.getChannelData(0).set(impulseL);
|
|
221
|
+
impulse.getChannelData(1).set(impulseR);
|
|
222
|
+
this.convolverNode.buffer = impulse;
|
|
223
|
+
}
|
|
224
|
+
getNoise(duration) {
|
|
225
|
+
return [
|
|
226
|
+
...transducers.take(
|
|
227
|
+
duration,
|
|
228
|
+
this.noise(
|
|
229
|
+
this.options.peaks,
|
|
230
|
+
this.options.scale,
|
|
231
|
+
this.options.randomAlgorithm
|
|
232
|
+
)
|
|
233
|
+
)
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!window.Reverb) {
|
|
238
|
+
window.Reverb = Reverb;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return Reverb;
|
|
242
|
+
|
|
243
|
+
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptionInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/OptionInterface.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"OptionInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/OptionInterface.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,oBAAoB;AACpB,MAAM,CAAC,OAAO,WAAW,eAAe;IACtC;;;OAGG;IACH,KAAK,EAAE,SAAS,CAAC;IACjB,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,eAAe,EAAE,KAAK,CAAC;IACvB,YAAY;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,EAAE,OAAO,CAAC;CACf;AAED,aAAa;AACb,eAAO,MAAM,QAAQ,EAAE,eActB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@logue/reverb",
|
|
4
|
-
"version": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"description": "JavaScript Reverb effect class",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webaudio",
|
|
@@ -37,45 +37,48 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
|
-
"node": ">=
|
|
41
|
-
"yarn": ">=1.22.
|
|
40
|
+
"node": ">=18.12.1",
|
|
41
|
+
"yarn": ">=1.22.19"
|
|
42
42
|
},
|
|
43
|
-
"packageManager": "yarn@3.
|
|
43
|
+
"packageManager": "yarn@3.3.0",
|
|
44
44
|
"sideEffects": false,
|
|
45
45
|
"scripts": {
|
|
46
46
|
"dev": "vite",
|
|
47
|
-
"
|
|
48
|
-
"build
|
|
47
|
+
"type-check": "tsc --composite false",
|
|
48
|
+
"build": "vite build && tsc --noEmit false --declaration --emitDeclarationOnly",
|
|
49
|
+
"build:analyze": "vite build --mode analyze",
|
|
49
50
|
"build:clean": "rimraf dist",
|
|
50
51
|
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
|
|
52
|
+
"preview": "vite serve docs",
|
|
51
53
|
"prepare": "husky install"
|
|
52
54
|
},
|
|
53
55
|
"dependencies": {
|
|
54
|
-
"@thi.ng/colored-noise": "^0.
|
|
55
|
-
"@thi.ng/transducers": "^8.3.
|
|
56
|
+
"@thi.ng/colored-noise": "^1.0.0",
|
|
57
|
+
"@thi.ng/transducers": "^8.3.23"
|
|
56
58
|
},
|
|
57
59
|
"devDependencies": {
|
|
58
|
-
"@types/node": "^18.
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
60
|
-
"@typescript-eslint/parser": "^5.
|
|
61
|
-
"eslint": "^8.
|
|
60
|
+
"@types/node": "^18.11.9",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
|
62
|
+
"@typescript-eslint/parser": "^5.44.0",
|
|
63
|
+
"eslint": "^8.28.0",
|
|
62
64
|
"eslint-config-google": "^0.14.0",
|
|
63
65
|
"eslint-config-prettier": "^8.5.0",
|
|
64
66
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
65
|
-
"eslint-import-resolver-typescript": "^3.5.
|
|
67
|
+
"eslint-import-resolver-typescript": "^3.5.2",
|
|
66
68
|
"eslint-plugin-import": "^2.26.0",
|
|
67
|
-
"eslint-plugin-jsdoc": "^39.
|
|
69
|
+
"eslint-plugin-jsdoc": "^39.6.2",
|
|
68
70
|
"eslint-plugin-prettier": "^4.2.1",
|
|
69
71
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
70
|
-
"husky": "^8.0.
|
|
72
|
+
"husky": "^8.0.2",
|
|
71
73
|
"lint-staged": "^13.0.3",
|
|
72
|
-
"prettier": "^2.
|
|
74
|
+
"prettier": "^2.8.0",
|
|
73
75
|
"rimraf": "^3.0.2",
|
|
74
|
-
"rollup-plugin-visualizer": "^5.8.
|
|
75
|
-
"typescript": "^4.
|
|
76
|
-
"vite": "^3.
|
|
77
|
-
"vite-plugin-banner": "^0.
|
|
78
|
-
"vite-plugin-checker": "^0.5.1"
|
|
76
|
+
"rollup-plugin-visualizer": "^5.8.3",
|
|
77
|
+
"typescript": "^4.9.3",
|
|
78
|
+
"vite": "^3.2.4",
|
|
79
|
+
"vite-plugin-banner": "^0.6.1",
|
|
80
|
+
"vite-plugin-checker": "^0.5.1",
|
|
81
|
+
"vite-plugin-dts": "^1.7.1"
|
|
79
82
|
},
|
|
80
83
|
"husky": {
|
|
81
84
|
"hooks": {
|
|
@@ -87,6 +90,6 @@
|
|
|
87
90
|
"*": "prettier -w -u"
|
|
88
91
|
},
|
|
89
92
|
"resolutions": {
|
|
90
|
-
"prettier": "^2.
|
|
93
|
+
"prettier": "^2.8.0"
|
|
91
94
|
}
|
|
92
95
|
}
|