@logue/reverb 1.3.7 → 1.3.9
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/dist/Reverb.d.ts +4 -3
- package/dist/Reverb.es.js +55 -193
- package/dist/Reverb.iife.js +3 -3
- package/dist/Reverb.umd.js +3 -3
- package/package.json +28 -24
package/dist/Reverb.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { NoiseType } from './NoiseType';
|
|
2
|
+
import { INorm } from '@thi.ng/random';
|
|
3
|
+
import { default as OptionInterface } from './interfaces/OptionInterface';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Reverb effect class
|
|
6
7
|
*/
|
package/dist/Reverb.es.js
CHANGED
|
@@ -3,71 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @description JavaScript Reverb effect class
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
-
* @copyright 2019-
|
|
6
|
+
* @copyright 2019-2024 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.3.
|
|
8
|
+
* @version 1.3.9
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
norm(e = 1) {
|
|
21
|
-
return (this.int() * g - 0.5) * 2 * e;
|
|
22
|
-
}
|
|
23
|
-
normMinMax(e, s) {
|
|
24
|
-
const i = this.minmax(e, s);
|
|
25
|
-
return this.float() < 0.5 ? i : -i;
|
|
26
|
-
}
|
|
27
|
-
minmax(e, s) {
|
|
28
|
-
return this.float() * (s - e) + e;
|
|
29
|
-
}
|
|
30
|
-
minmaxInt(e, s) {
|
|
31
|
-
e |= 0;
|
|
32
|
-
const i = (s | 0) - e;
|
|
33
|
-
return i ? e + this.int() % i : e;
|
|
34
|
-
}
|
|
35
|
-
minmaxUint(e, s) {
|
|
36
|
-
e >>>= 0;
|
|
37
|
-
const i = (s >>> 0) - e;
|
|
38
|
-
return i ? e + this.int() % i : e;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const m = Math.random;
|
|
42
|
-
class T extends F {
|
|
43
|
-
int() {
|
|
44
|
-
return m() * 4294967296 >>> 0;
|
|
45
|
-
}
|
|
46
|
-
float(e = 1) {
|
|
47
|
-
return m() * e;
|
|
48
|
-
}
|
|
49
|
-
norm(e = 1) {
|
|
50
|
-
return (m() - 0.5) * 2 * e;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const k = new T(), x = {
|
|
54
|
-
noise: "white",
|
|
55
|
-
scale: 1,
|
|
56
|
-
peaks: 2,
|
|
57
|
-
randomAlgorithm: k,
|
|
58
|
-
decay: 2,
|
|
59
|
-
delay: 0,
|
|
60
|
-
reverse: !1,
|
|
61
|
-
time: 2,
|
|
62
|
-
filterType: "allpass",
|
|
63
|
-
filterFreq: 2200,
|
|
64
|
-
filterQ: 1,
|
|
65
|
-
mix: 0.5,
|
|
66
|
-
once: !1
|
|
67
|
-
}, w = {
|
|
68
|
-
version: "1.3.7",
|
|
69
|
-
date: "2024-01-29T10:30:54.595Z"
|
|
70
|
-
}, d = {
|
|
12
|
+
import { white as c, violet as m, red as f, pink as b, green as N, blue as g } from "@thi.ng/colored-noise";
|
|
13
|
+
import { take as v } from "@thi.ng/transducers";
|
|
14
|
+
import { SYSTEM as w } from "@thi.ng/random";
|
|
15
|
+
const d = {
|
|
16
|
+
version: "1.3.9",
|
|
17
|
+
date: "2024-04-24T08:29:36.615Z"
|
|
18
|
+
}, o = {
|
|
71
19
|
/** Blue noise */
|
|
72
20
|
blue: "blue",
|
|
73
21
|
/** Brown noise (same as red noise) */
|
|
@@ -82,112 +30,26 @@ const k = new T(), x = {
|
|
|
82
30
|
violet: "violet",
|
|
83
31
|
/** White noise */
|
|
84
32
|
white: "white"
|
|
85
|
-
},
|
|
86
|
-
|
|
33
|
+
}, y = {
|
|
34
|
+
noise: "white",
|
|
87
35
|
scale: 1,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (n.done)
|
|
100
|
-
return;
|
|
101
|
-
yield n.value;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function* b(t) {
|
|
105
|
-
const { bins: e, scale: s, rnd: i } = {
|
|
106
|
-
...p,
|
|
107
|
-
...t
|
|
108
|
-
}, n = N(e, s, i);
|
|
109
|
-
n.forEach((r, l) => n[l] = l & 1 ? r : -r);
|
|
110
|
-
const a = 1 / e;
|
|
111
|
-
let o = v(n);
|
|
112
|
-
for (let r = 0, l = -1; ; ++r >= e && (r = 0))
|
|
113
|
-
o -= n[r], o += n[r] = l * i.norm(s), l ^= 4294967294, yield l * o * a;
|
|
114
|
-
}
|
|
115
|
-
const C = (t) => G(b(t), b(t)), E = (t) => {
|
|
116
|
-
let e = 32;
|
|
117
|
-
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;
|
|
36
|
+
peaks: 2,
|
|
37
|
+
randomAlgorithm: w,
|
|
38
|
+
decay: 2,
|
|
39
|
+
delay: 0,
|
|
40
|
+
reverse: !1,
|
|
41
|
+
time: 2,
|
|
42
|
+
filterType: "allpass",
|
|
43
|
+
filterFreq: 2200,
|
|
44
|
+
filterQ: 1,
|
|
45
|
+
mix: 0.5,
|
|
46
|
+
once: !1
|
|
118
47
|
};
|
|
119
|
-
|
|
120
|
-
const { bins: e, scale: s, rnd: i } = {
|
|
121
|
-
...p,
|
|
122
|
-
bins: 8,
|
|
123
|
-
...t
|
|
124
|
-
}, n = N(e, s, i), a = 1 / e;
|
|
125
|
-
let o = v(n);
|
|
126
|
-
for (let r = 0; ; r = r + 1 >>> 0) {
|
|
127
|
-
const l = E(r) % e;
|
|
128
|
-
o -= n[l], o += n[l] = i.norm(s), yield o * a;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function* y(t) {
|
|
132
|
-
const { bins: e, scale: s, rnd: i } = {
|
|
133
|
-
...p,
|
|
134
|
-
...t
|
|
135
|
-
}, n = N(e, s, i), a = 1 / e;
|
|
136
|
-
let o = v(n);
|
|
137
|
-
for (let r = 0; ; ++r >= e && (r = 0))
|
|
138
|
-
o -= n[r], o += n[r] = i.norm(s), yield o * a;
|
|
139
|
-
}
|
|
140
|
-
const M = (t) => G(y(t), y(t));
|
|
141
|
-
function* R(t) {
|
|
142
|
-
const { scale: e, rnd: s } = { ...p, ...t };
|
|
143
|
-
for (; ; )
|
|
144
|
-
yield s.norm(e);
|
|
145
|
-
}
|
|
146
|
-
const S = (t, e) => t != null && typeof t[e] == "function", Q = (t) => S(t, "xform") ? t.xform() : t, q = (t) => t != null && typeof t[Symbol.iterator] == "function";
|
|
147
|
-
class u {
|
|
148
|
-
value;
|
|
149
|
-
constructor(e) {
|
|
150
|
-
this.value = e;
|
|
151
|
-
}
|
|
152
|
-
deref() {
|
|
153
|
-
return this.value;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const D = (t) => new u(t), L = (t) => t instanceof u, B = (t) => t instanceof u ? t : new u(t), I = (t) => t instanceof u ? t.deref() : t, O = (t, e) => [t, (s) => s, e];
|
|
157
|
-
function U(t) {
|
|
158
|
-
return t ? [...t] : O(
|
|
159
|
-
() => [],
|
|
160
|
-
(e, s) => (e.push(s), e)
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
function* z(t, e) {
|
|
164
|
-
const s = Q(t)(U()), i = s[1], n = s[2];
|
|
165
|
-
for (let a of e) {
|
|
166
|
-
const o = n([], a);
|
|
167
|
-
if (L(o)) {
|
|
168
|
-
yield* I(i(o.deref()));
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
o.length && (yield* o);
|
|
172
|
-
}
|
|
173
|
-
yield* I(i([]));
|
|
174
|
-
}
|
|
175
|
-
const P = (t, e) => [t[0], t[1], e];
|
|
176
|
-
function A(t, e) {
|
|
177
|
-
return q(e) ? z(A(t), e) : (s) => {
|
|
178
|
-
const i = s[2];
|
|
179
|
-
let n = t;
|
|
180
|
-
return P(
|
|
181
|
-
s,
|
|
182
|
-
(a, o) => --n > 0 ? i(a, o) : n === 0 ? B(i(a, o)) : D(a)
|
|
183
|
-
);
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
class h {
|
|
48
|
+
class s {
|
|
187
49
|
/** Version strings */
|
|
188
|
-
static version =
|
|
50
|
+
static version = d.version;
|
|
189
51
|
/** Build date */
|
|
190
|
-
static build =
|
|
52
|
+
static build = d.date;
|
|
191
53
|
/** AudioContext */
|
|
192
54
|
ctx;
|
|
193
55
|
/** Wet Level (Reverberated node) */
|
|
@@ -205,15 +67,15 @@ class h {
|
|
|
205
67
|
/** Connected flag */
|
|
206
68
|
isConnected;
|
|
207
69
|
/** Noise Generator */
|
|
208
|
-
noise =
|
|
70
|
+
noise = c;
|
|
209
71
|
/**
|
|
210
72
|
* Constructor
|
|
211
73
|
*
|
|
212
74
|
* @param ctx - Root AudioContext
|
|
213
75
|
* @param options - Configure
|
|
214
76
|
*/
|
|
215
|
-
constructor(e,
|
|
216
|
-
this.ctx = e, this.options = Object.assign(
|
|
77
|
+
constructor(e, t) {
|
|
78
|
+
this.ctx = e, this.options = Object.assign(y, t), this.wetGainNode = this.ctx.createGain(), this.dryGainNode = this.ctx.createGain(), this.filterNode = this.ctx.createBiquadFilter(), this.convolverNode = this.ctx.createConvolver(), this.outputNode = this.ctx.createGain(), this.isConnected = !1, this.filterType(this.options.filterType), this.setNoise(this.options.noise), this.buildImpulse(), this.mix(this.options.mix);
|
|
217
79
|
}
|
|
218
80
|
/**
|
|
219
81
|
* Connect the node for the reverb effect to the original sound node.
|
|
@@ -237,7 +99,7 @@ class h {
|
|
|
237
99
|
* @param mix - Ratio (0~1)
|
|
238
100
|
*/
|
|
239
101
|
mix(e) {
|
|
240
|
-
if (!
|
|
102
|
+
if (!s.inRange(e, 0, 1))
|
|
241
103
|
throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
|
|
242
104
|
this.options.mix = e, this.dryGainNode.gain.value = 1 - this.options.mix, this.wetGainNode.gain.value = this.options.mix;
|
|
243
105
|
}
|
|
@@ -247,7 +109,7 @@ class h {
|
|
|
247
109
|
* @param value - IR length
|
|
248
110
|
*/
|
|
249
111
|
time(e) {
|
|
250
|
-
if (!
|
|
112
|
+
if (!s.inRange(e, 1, 50))
|
|
251
113
|
throw new RangeError(
|
|
252
114
|
"[Reverb.js] Time length of inpulse response must be less than 50sec."
|
|
253
115
|
);
|
|
@@ -259,7 +121,7 @@ class h {
|
|
|
259
121
|
* @param value - Decay value
|
|
260
122
|
*/
|
|
261
123
|
decay(e) {
|
|
262
|
-
if (!
|
|
124
|
+
if (!s.inRange(e, 0, 100))
|
|
263
125
|
throw new RangeError(
|
|
264
126
|
"[Reverb.js] Inpulse Response decay level must be less than 100."
|
|
265
127
|
);
|
|
@@ -271,7 +133,7 @@ class h {
|
|
|
271
133
|
* @param value - Time[ms]
|
|
272
134
|
*/
|
|
273
135
|
delay(e) {
|
|
274
|
-
if (!
|
|
136
|
+
if (!s.inRange(e, 0, 100))
|
|
275
137
|
throw new RangeError(
|
|
276
138
|
"[Reverb.js] Inpulse Response delay time must be less than 100."
|
|
277
139
|
);
|
|
@@ -299,7 +161,7 @@ class h {
|
|
|
299
161
|
* @param freq - Frequency
|
|
300
162
|
*/
|
|
301
163
|
filterFreq(e) {
|
|
302
|
-
if (!
|
|
164
|
+
if (!s.inRange(e, 20, 2e4))
|
|
303
165
|
throw new RangeError(
|
|
304
166
|
"[Reverb.js] Filter frequrncy must be between 20 and 20000."
|
|
305
167
|
);
|
|
@@ -311,7 +173,7 @@ class h {
|
|
|
311
173
|
* @param q - Quality
|
|
312
174
|
*/
|
|
313
175
|
filterQ(e) {
|
|
314
|
-
if (!
|
|
176
|
+
if (!s.inRange(e, 0, 10))
|
|
315
177
|
throw new RangeError(
|
|
316
178
|
"[Reverb.js] Filter Q value must be between 0 and 10."
|
|
317
179
|
);
|
|
@@ -348,24 +210,24 @@ class h {
|
|
|
348
210
|
*/
|
|
349
211
|
setNoise(e) {
|
|
350
212
|
switch (this.options.noise = e, e) {
|
|
351
|
-
case
|
|
352
|
-
this.noise =
|
|
213
|
+
case o.blue:
|
|
214
|
+
this.noise = g;
|
|
353
215
|
break;
|
|
354
|
-
case
|
|
355
|
-
this.noise =
|
|
216
|
+
case o.green:
|
|
217
|
+
this.noise = N;
|
|
356
218
|
break;
|
|
357
|
-
case
|
|
358
|
-
this.noise =
|
|
219
|
+
case o.pink:
|
|
220
|
+
this.noise = b;
|
|
359
221
|
break;
|
|
360
|
-
case
|
|
361
|
-
case
|
|
362
|
-
this.noise =
|
|
222
|
+
case o.red:
|
|
223
|
+
case o.brown:
|
|
224
|
+
this.noise = f;
|
|
363
225
|
break;
|
|
364
|
-
case
|
|
365
|
-
this.noise =
|
|
226
|
+
case o.violet:
|
|
227
|
+
this.noise = m;
|
|
366
228
|
break;
|
|
367
229
|
default:
|
|
368
|
-
this.noise =
|
|
230
|
+
this.noise = c;
|
|
369
231
|
}
|
|
370
232
|
this.buildImpulse();
|
|
371
233
|
}
|
|
@@ -384,17 +246,17 @@ class h {
|
|
|
384
246
|
* @param min - Minimum value
|
|
385
247
|
* @param max - Maximum value
|
|
386
248
|
*/
|
|
387
|
-
static inRange(e,
|
|
388
|
-
return (e -
|
|
249
|
+
static inRange(e, t, n) {
|
|
250
|
+
return (e - t) * (e - n) <= 0;
|
|
389
251
|
}
|
|
390
252
|
/** Utility function for building an impulse response from the module parameters. */
|
|
391
253
|
buildImpulse() {
|
|
392
|
-
const e = this.ctx.sampleRate,
|
|
393
|
-
for (let
|
|
394
|
-
let
|
|
395
|
-
|
|
254
|
+
const e = this.ctx.sampleRate, t = Math.max(e * this.options.time, 1), n = e * this.options.delay, a = this.ctx.createBuffer(2, t, e), h = new Float32Array(t), l = new Float32Array(t), p = this.getNoise(t), u = this.getNoise(t);
|
|
255
|
+
for (let i = 0; i < t; i++) {
|
|
256
|
+
let r = 0;
|
|
257
|
+
i < n ? (h[i] = 0, l[i] = 0, r = this.options.reverse ?? !1 ? t - (i - n) : i - n) : r = this.options.reverse ?? !1 ? t - i : i, h[i] = (p[i] ?? 0) * (1 - r / t) ** this.options.decay, l[i] = (u[i] ?? 0) * (1 - r / t) ** this.options.decay;
|
|
396
258
|
}
|
|
397
|
-
|
|
259
|
+
a.getChannelData(0).set(h), a.getChannelData(1).set(l), this.convolverNode.buffer = a;
|
|
398
260
|
}
|
|
399
261
|
/**
|
|
400
262
|
* Noise source
|
|
@@ -403,7 +265,7 @@ class h {
|
|
|
403
265
|
*/
|
|
404
266
|
getNoise(e) {
|
|
405
267
|
return [
|
|
406
|
-
...
|
|
268
|
+
...v(
|
|
407
269
|
e,
|
|
408
270
|
this.noise({
|
|
409
271
|
bins: this.options.peaks,
|
|
@@ -415,5 +277,5 @@ class h {
|
|
|
415
277
|
}
|
|
416
278
|
}
|
|
417
279
|
export {
|
|
418
|
-
|
|
280
|
+
s as default
|
|
419
281
|
};
|
package/dist/Reverb.iife.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @description JavaScript Reverb effect class
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
-
* @copyright 2019-
|
|
6
|
+
* @copyright 2019-2024 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.3.
|
|
8
|
+
* @version 1.3.9
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
var Reverb=function(){"use strict";const
|
|
12
|
+
var Reverb=function(n,p,u){"use strict";const d={version:"1.3.9",date:"2024-04-24T08:29:36.615Z"},o={blue:"blue",brown:"red",green:"green",pink:"pink",red:"red",violet:"violet",white:"white"},f={noise:"white",scale:1,peaks:2,randomAlgorithm:u.SYSTEM,decay:2,delay:0,reverse:!1,time:2,filterType:"allpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};class s{static version=d.version;static build=d.date;ctx;wetGainNode;dryGainNode;filterNode;convolverNode;outputNode;options;isConnected;noise=n.white;constructor(e,t){this.ctx=e,this.options=Object.assign(f,t),this.wetGainNode=this.ctx.createGain(),this.dryGainNode=this.ctx.createGain(),this.filterNode=this.ctx.createBiquadFilter(),this.convolverNode=this.ctx.createConvolver(),this.outputNode=this.ctx.createGain(),this.isConnected=!1,this.filterType(this.options.filterType),this.setNoise(this.options.noise),this.buildImpulse(),this.mix(this.options.mix)}connect(e){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)}disconnect(e){return this.isConnected&&(this.convolverNode.disconnect(this.filterNode),this.filterNode.disconnect(this.wetGainNode)),this.isConnected=!1,e}mix(e){if(!s.inRange(e,0,1))throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");this.options.mix=e,this.dryGainNode.gain.value=1-this.options.mix,this.wetGainNode.gain.value=this.options.mix}time(e){if(!s.inRange(e,1,50))throw new RangeError("[Reverb.js] Time length of inpulse response must be less than 50sec.");this.options.time=e,this.buildImpulse()}decay(e){if(!s.inRange(e,0,100))throw new RangeError("[Reverb.js] Inpulse Response decay level must be less than 100.");this.options.decay=e,this.buildImpulse()}delay(e){if(!s.inRange(e,0,100))throw new RangeError("[Reverb.js] Inpulse Response delay time must be less than 100.");this.options.delay=e,this.buildImpulse()}reverse(e){this.options.reverse=e,this.buildImpulse()}filterType(e="allpass"){this.filterNode.type=this.options.filterType=e}filterFreq(e){if(!s.inRange(e,20,2e4))throw new RangeError("[Reverb.js] Filter frequrncy must be between 20 and 20000.");this.options.filterFreq=e,this.filterNode.frequency.value=this.options.filterFreq}filterQ(e){if(!s.inRange(e,0,10))throw new RangeError("[Reverb.js] Filter Q value must be between 0 and 10.");this.options.filterQ=e,this.filterNode.Q.value=this.options.filterQ}peaks(e){this.options.peaks=e,this.buildImpulse()}scale(e){this.options.scale=e,this.buildImpulse()}randomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse()}setNoise(e){switch(this.options.noise=e,e){case o.blue:this.noise=n.blue;break;case o.green:this.noise=n.green;break;case o.pink:this.noise=n.pink;break;case o.red:case o.brown:this.noise=n.red;break;case o.violet:this.noise=n.violet;break;default:this.noise=n.white}this.buildImpulse()}setRandomAlgorythm(e){this.options.randomAlgorithm=e,this.buildImpulse()}static inRange(e,t,r){return(e-t)*(e-r)<=0}buildImpulse(){const e=this.ctx.sampleRate,t=Math.max(e*this.options.time,1),r=e*this.options.delay,h=this.ctx.createBuffer(2,t,e),l=new Float32Array(t),c=new Float32Array(t),m=this.getNoise(t),b=this.getNoise(t);for(let i=0;i<t;i++){let a=0;i<r?(l[i]=0,c[i]=0,a=this.options.reverse??!1?t-(i-r):i-r):a=this.options.reverse??!1?t-i:i,l[i]=(m[i]??0)*(1-a/t)**this.options.decay,c[i]=(b[i]??0)*(1-a/t)**this.options.decay}h.getChannelData(0).set(l),h.getChannelData(1).set(c),this.convolverNode.buffer=h}getNoise(e){return[...p.take(e,this.noise({bins:this.options.peaks,scale:this.options.scale,rnd:this.options.randomAlgorithm}))]}}return s}(coloredNoise,transducers,random);
|
package/dist/Reverb.umd.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @description JavaScript Reverb effect class
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
-
* @copyright 2019-
|
|
6
|
+
* @copyright 2019-2024 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.3.
|
|
8
|
+
* @version 1.3.9
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
(function(
|
|
12
|
+
(function(t,r){typeof exports=="object"&&typeof module<"u"?module.exports=r(require("@thi.ng/colored-noise"),require("@thi.ng/transducers"),require("@thi.ng/random")):typeof define=="function"&&define.amd?define(["@thi.ng/colored-noise","@thi.ng/transducers","@thi.ng/random"],r):(t=typeof globalThis<"u"?globalThis:t||self,t.Reverb=r(t.coloredNoise,t.transducers,t.random))})(this,function(t,r,p){"use strict";const u={version:"1.3.9",date:"2024-04-24T08:29:36.615Z"},o={blue:"blue",brown:"red",green:"green",pink:"pink",red:"red",violet:"violet",white:"white"},f={noise:"white",scale:1,peaks:2,randomAlgorithm:p.SYSTEM,decay:2,delay:0,reverse:!1,time:2,filterType:"allpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};class n{static version=u.version;static build=u.date;ctx;wetGainNode;dryGainNode;filterNode;convolverNode;outputNode;options;isConnected;noise=t.white;constructor(e,i){this.ctx=e,this.options=Object.assign(f,i),this.wetGainNode=this.ctx.createGain(),this.dryGainNode=this.ctx.createGain(),this.filterNode=this.ctx.createBiquadFilter(),this.convolverNode=this.ctx.createConvolver(),this.outputNode=this.ctx.createGain(),this.isConnected=!1,this.filterType(this.options.filterType),this.setNoise(this.options.noise),this.buildImpulse(),this.mix(this.options.mix)}connect(e){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)}disconnect(e){return this.isConnected&&(this.convolverNode.disconnect(this.filterNode),this.filterNode.disconnect(this.wetGainNode)),this.isConnected=!1,e}mix(e){if(!n.inRange(e,0,1))throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");this.options.mix=e,this.dryGainNode.gain.value=1-this.options.mix,this.wetGainNode.gain.value=this.options.mix}time(e){if(!n.inRange(e,1,50))throw new RangeError("[Reverb.js] Time length of inpulse response must be less than 50sec.");this.options.time=e,this.buildImpulse()}decay(e){if(!n.inRange(e,0,100))throw new RangeError("[Reverb.js] Inpulse Response decay level must be less than 100.");this.options.decay=e,this.buildImpulse()}delay(e){if(!n.inRange(e,0,100))throw new RangeError("[Reverb.js] Inpulse Response delay time must be less than 100.");this.options.delay=e,this.buildImpulse()}reverse(e){this.options.reverse=e,this.buildImpulse()}filterType(e="allpass"){this.filterNode.type=this.options.filterType=e}filterFreq(e){if(!n.inRange(e,20,2e4))throw new RangeError("[Reverb.js] Filter frequrncy must be between 20 and 20000.");this.options.filterFreq=e,this.filterNode.frequency.value=this.options.filterFreq}filterQ(e){if(!n.inRange(e,0,10))throw new RangeError("[Reverb.js] Filter Q value must be between 0 and 10.");this.options.filterQ=e,this.filterNode.Q.value=this.options.filterQ}peaks(e){this.options.peaks=e,this.buildImpulse()}scale(e){this.options.scale=e,this.buildImpulse()}randomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse()}setNoise(e){switch(this.options.noise=e,e){case o.blue:this.noise=t.blue;break;case o.green:this.noise=t.green;break;case o.pink:this.noise=t.pink;break;case o.red:case o.brown:this.noise=t.red;break;case o.violet:this.noise=t.violet;break;default:this.noise=t.white}this.buildImpulse()}setRandomAlgorythm(e){this.options.randomAlgorithm=e,this.buildImpulse()}static inRange(e,i,h){return(e-i)*(e-h)<=0}buildImpulse(){const e=this.ctx.sampleRate,i=Math.max(e*this.options.time,1),h=e*this.options.delay,l=this.ctx.createBuffer(2,i,e),d=new Float32Array(i),c=new Float32Array(i),m=this.getNoise(i),b=this.getNoise(i);for(let s=0;s<i;s++){let a=0;s<h?(d[s]=0,c[s]=0,a=this.options.reverse??!1?i-(s-h):s-h):a=this.options.reverse??!1?i-s:s,d[s]=(m[s]??0)*(1-a/i)**this.options.decay,c[s]=(b[s]??0)*(1-a/i)**this.options.decay}l.getChannelData(0).set(d),l.getChannelData(1).set(c),this.convolverNode.buffer=l}getNoise(e){return[...r.take(e,this.noise({bins:this.options.peaks,scale:this.options.scale,rnd:this.options.randomAlgorithm}))]}}return n});
|
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.3.
|
|
4
|
+
"version": "1.3.9",
|
|
5
5
|
"description": "JavaScript Reverb effect class",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webaudio",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
43
|
+
"node": ">=20.1.3",
|
|
44
44
|
"yarn": ">=1.22.19"
|
|
45
45
|
},
|
|
46
|
-
"packageManager": "yarn@4.0
|
|
46
|
+
"packageManager": "yarn@4.1.0",
|
|
47
47
|
"sideEffects": false,
|
|
48
48
|
"scripts": {
|
|
49
49
|
"dev": "vite",
|
|
@@ -59,36 +59,38 @@
|
|
|
59
59
|
"prepare": "husky install"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@thi.ng/colored-noise": "^1.0.
|
|
63
|
-
"@thi.ng/transducers": "^
|
|
62
|
+
"@thi.ng/colored-noise": "^1.0.69",
|
|
63
|
+
"@thi.ng/transducers": "^9.0.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@
|
|
67
|
-
"@
|
|
68
|
-
"@
|
|
69
|
-
"
|
|
70
|
-
"
|
|
66
|
+
"@eslint/js": "^9.1.1",
|
|
67
|
+
"@tsconfig/node-lts": "^20.1.3",
|
|
68
|
+
"@types/node": "^20.12.7",
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
70
|
+
"bootstrap": "^5.3.3",
|
|
71
|
+
"eslint": "^9.1.1",
|
|
71
72
|
"eslint-config-prettier": "^9.1.0",
|
|
72
73
|
"eslint-config-standard-with-typescript": "^43.0.1",
|
|
73
74
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
74
75
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
75
|
-
"eslint-plugin-html": "^
|
|
76
|
+
"eslint-plugin-html": "^8.1.1",
|
|
76
77
|
"eslint-plugin-import": "^2.29.1",
|
|
77
|
-
"eslint-plugin-n": "^
|
|
78
|
+
"eslint-plugin-n": "^17.2.1",
|
|
78
79
|
"eslint-plugin-promise": "^6.1.1",
|
|
79
80
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
80
81
|
"eslint-plugin-yaml": "^0.5.0",
|
|
81
|
-
"husky": "^9.0.
|
|
82
|
-
"lint-staged": "^15.2.
|
|
82
|
+
"husky": "^9.0.11",
|
|
83
|
+
"lint-staged": "^15.2.2",
|
|
83
84
|
"npm-run-all": "^4.1.5",
|
|
84
|
-
"prettier": "^3.2.
|
|
85
|
+
"prettier": "^3.2.5",
|
|
85
86
|
"rimraf": "^5.0.5",
|
|
86
87
|
"rollup-plugin-visualizer": "^5.12.0",
|
|
87
|
-
"typescript": "
|
|
88
|
-
"
|
|
88
|
+
"typescript": "^5.4.5",
|
|
89
|
+
"typescript-eslint": "^7.7.1",
|
|
90
|
+
"vite": "^5.2.10",
|
|
89
91
|
"vite-plugin-banner": "^0.7.1",
|
|
90
|
-
"vite-plugin-checker": "^0.6.
|
|
91
|
-
"vite-plugin-dts": "^3.
|
|
92
|
+
"vite-plugin-checker": "^0.6.4",
|
|
93
|
+
"vite-plugin-dts": "^3.9.0"
|
|
92
94
|
},
|
|
93
95
|
"husky": {
|
|
94
96
|
"hooks": {
|
|
@@ -100,10 +102,12 @@
|
|
|
100
102
|
"*": "prettier -w -u"
|
|
101
103
|
},
|
|
102
104
|
"resolutions": {
|
|
103
|
-
"json5": "
|
|
105
|
+
"json5": ">=2.2.3",
|
|
106
|
+
"ip": ">=2.0.1",
|
|
104
107
|
"lodash": ">=4.17.21",
|
|
105
|
-
"postcss": "
|
|
106
|
-
"semver": "
|
|
107
|
-
"
|
|
108
|
+
"postcss": ">=8.4.31",
|
|
109
|
+
"semver": ">=7.5.3",
|
|
110
|
+
"tar": ">=6.2.1",
|
|
111
|
+
"yaml": ">=2.3.2"
|
|
108
112
|
}
|
|
109
|
-
}
|
|
113
|
+
}
|