@logue/reverb 1.3.4 → 1.3.7

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.
@@ -5,638 +5,8 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2019-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.3.4
8
+ * @version 1.3.7
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
11
 
12
- var Reverb = (function () {
13
- 'use strict';
14
-
15
- const INV_MAX = 1 / 2 ** 32;
16
- class ARandom {
17
- float(norm = 1) {
18
- return this.int() * INV_MAX * norm;
19
- }
20
- probability(p) {
21
- return this.float() < p;
22
- }
23
- norm(norm = 1) {
24
- return (this.int() * INV_MAX - 0.5) * 2 * norm;
25
- }
26
- normMinMax(min, max) {
27
- const x = this.minmax(min, max);
28
- return this.float() < 0.5 ? x : -x;
29
- }
30
- minmax(min, max) {
31
- return this.float() * (max - min) + min;
32
- }
33
- minmaxInt(min, max) {
34
- min |= 0;
35
- const range = (max | 0) - min;
36
- return range ? min + (this.int() % range) : min;
37
- }
38
- minmaxUint(min, max) {
39
- min >>>= 0;
40
- const range = (max >>> 0) - min;
41
- return range ? min + (this.int() % range) : min;
42
- }
43
- }
44
-
45
- const random = Math.random;
46
- /**
47
- * A `Math.random()` based {@link IRandom} implementation. Also @see
48
- * {@link SYSTEM}.
49
- */
50
- class SystemRandom extends ARandom {
51
- int() {
52
- return (random() * 4294967296) /* 2**32 */ >>> 0;
53
- }
54
- float(norm = 1) {
55
- return random() * norm;
56
- }
57
- norm(norm = 1) {
58
- return (random() - 0.5) * 2 * norm;
59
- }
60
- }
61
- /**
62
- * Used as default PRNG throughout most other thi.ng projects, though usually is
63
- * configurable.
64
- */
65
- const SYSTEM = new SystemRandom();
66
-
67
- const defaults = {
68
- noise: "white",
69
- scale: 1,
70
- peaks: 2,
71
- randomAlgorithm: SYSTEM,
72
- decay: 2,
73
- delay: 0,
74
- reverse: false,
75
- time: 2,
76
- filterType: "allpass",
77
- filterFreq: 2200,
78
- filterQ: 1,
79
- mix: 0.5,
80
- once: false
81
- };
82
-
83
- const Meta = {
84
- version: "1.3.4",
85
- date: "2023-11-06T00:21:39.551Z"
86
- };
87
-
88
- const Noise = {
89
- /** Blue noise */
90
- blue: "blue",
91
- /** Brown noise (same as red noise) */
92
- brown: "red",
93
- /** Green noise */
94
- green: "green",
95
- /** Pink noise */
96
- pink: "pink",
97
- /** Red noise */
98
- red: "red",
99
- /** Violet noise */
100
- violet: "violet",
101
- /** White noise */
102
- white: "white"
103
- };
104
-
105
- const DEFAULT_OPTS = {
106
- bins: 2,
107
- scale: 1,
108
- rnd: SYSTEM,
109
- };
110
-
111
- const preseed = (n, scale, rnd) => {
112
- const state = new Array(n);
113
- for (let i = 0; i < n; i++) {
114
- state[i] = rnd.norm(scale);
115
- }
116
- return state;
117
- };
118
- const sum = (src) => src.reduce((sum, x) => sum + x, 0);
119
- function* interleave(a, b) {
120
- const src = [a[Symbol.iterator](), b[Symbol.iterator]()];
121
- for (let i = 0; true; i ^= 1) {
122
- const next = src[i].next();
123
- if (next.done)
124
- return;
125
- yield next.value;
126
- }
127
- }
128
-
129
- /**
130
- * High-pass filtered noise. Opposite of {@link red}.
131
- *
132
- * @param opts -
133
- */
134
- function* blue(opts) {
135
- const { bins, scale, rnd } = {
136
- ...DEFAULT_OPTS,
137
- ...opts,
138
- };
139
- const state = preseed(bins, scale, rnd);
140
- state.forEach((x, i) => (state[i] = i & 1 ? x : -x));
141
- const invN = 1 / bins;
142
- let acc = sum(state);
143
- for (let i = 0, sign = -1; true; ++i >= bins && (i = 0)) {
144
- acc -= state[i];
145
- acc += state[i] = sign * rnd.norm(scale);
146
- sign ^= 0xfffffffe;
147
- yield sign * acc * invN;
148
- }
149
- }
150
-
151
- /**
152
- * Band-pass filtered noise (interleaved blue noise). Opposite of
153
- * {@link violet}.
154
- *
155
- * @param opts -
156
- */
157
- const green = (opts) => interleave(blue(opts), blue(opts));
158
-
159
- /**
160
- * Returns number of 1 bits in `x`.
161
- *
162
- * @param x -
163
- */
164
- const ctz32 = (x) => {
165
- let c = 32;
166
- x &= -x;
167
- x && c--;
168
- x & 0x0000ffff && (c -= 16);
169
- x & 0x00ff00ff && (c -= 8);
170
- x & 0x0f0f0f0f && (c -= 4);
171
- x & 0x33333333 && (c -= 2);
172
- x & 0x55555555 && (c -= 1);
173
- return c;
174
- };
175
-
176
- /**
177
- * Exponential decay (1/f) noise, based on Voss-McCarthy algorithm.
178
- *
179
- * @remarks
180
- * The number of internal states should be in the [4..32] range (default: 8).
181
- * Due to JS integer limitations, `n` > 32 are meaningless.
182
- *
183
- * References:
184
- *
185
- * - https://www.dsprelated.com/showarticle/908.php
186
- * - https://www.firstpr.com.au/dsp/pink-noise/#Voss-McCartney
187
- *
188
- * @param opts -
189
- */
190
- function* pink(opts) {
191
- const { bins, scale, rnd } = {
192
- ...DEFAULT_OPTS,
193
- bins: 8,
194
- ...opts,
195
- };
196
- const state = preseed(bins, scale, rnd);
197
- const invN = 1 / bins;
198
- let acc = sum(state);
199
- for (let i = 0; true; i = (i + 1) >>> 0) {
200
- const id = ctz32(i) % bins;
201
- acc -= state[id];
202
- acc += state[id] = rnd.norm(scale);
203
- yield acc * invN;
204
- }
205
- }
206
-
207
- /**
208
- * Low-pass filtered noise (same as brown noise). Opposite of {@link blue}.
209
- *
210
- * @param opts -
211
- */
212
- function* red(opts) {
213
- const { bins, scale, rnd } = {
214
- ...DEFAULT_OPTS,
215
- ...opts,
216
- };
217
- const state = preseed(bins, scale, rnd);
218
- const invN = 1 / bins;
219
- let acc = sum(state);
220
- for (let i = 0; true; ++i >= bins && (i = 0)) {
221
- acc -= state[i];
222
- acc += state[i] = rnd.norm(scale);
223
- yield acc * invN;
224
- }
225
- }
226
-
227
- /**
228
- * Band-stop filtered noise (interleaved red noise). Opposite of {@link green}.
229
- *
230
- * @param opts -
231
- */
232
- const violet = (opts) => interleave(red(opts), red(opts));
233
-
234
- /**
235
- * Unfiltered noise w/ uniform distribution. Merely yields samples from
236
- * given PRNG.
237
- *
238
- * @param opts -
239
- */
240
- function* white(opts) {
241
- const { scale, rnd } = { ...DEFAULT_OPTS, ...opts };
242
- while (true) {
243
- yield rnd.norm(scale);
244
- }
245
- }
246
-
247
- const implementsFunction = (x, fn) => x != null && typeof x[fn] === "function";
248
-
249
- const ensureTransducer = (x) => implementsFunction(x, "xform") ? x.xform() : x;
250
-
251
- const isIterable = (x) => x != null && typeof x[Symbol.iterator] === "function";
252
-
253
- class Reduced {
254
- constructor(val) {
255
- this.value = val;
256
- }
257
- deref() {
258
- return this.value;
259
- }
260
- }
261
- const reduced = (x) => new Reduced(x);
262
- const isReduced = (x) => x instanceof Reduced;
263
- const ensureReduced = (x) => x instanceof Reduced ? x : new Reduced(x);
264
- const unreduced = (x) => (x instanceof Reduced ? x.deref() : x);
265
-
266
- /**
267
- * Convenience helper for building a full {@link Reducer} using the identity
268
- * function (i.e. `(x) => x`) as completion step (true for 90% of all
269
- * bundled transducers).
270
- *
271
- * @param init - init step of reducer
272
- * @param rfn - reduction step of reducer
273
- */
274
- const reducer = (init, rfn) => [init, (acc) => acc, rfn];
275
-
276
- function push(xs) {
277
- return xs
278
- ? [...xs]
279
- : reducer(() => [], (acc, x) => (acc.push(x), acc));
280
- }
281
-
282
- /**
283
- * Takes a transducer and input iterable. Returns iterator of
284
- * transformed results.
285
- *
286
- * @param xform -
287
- * @param xs -
288
- */
289
- function* iterator(xform, xs) {
290
- const rfn = ensureTransducer(xform)(push());
291
- const complete = rfn[1];
292
- const reduce = rfn[2];
293
- for (let x of xs) {
294
- const y = reduce([], x);
295
- if (isReduced(y)) {
296
- yield* unreduced(complete(y.deref()));
297
- return;
298
- }
299
- if (y.length) {
300
- yield* y;
301
- }
302
- }
303
- yield* unreduced(complete([]));
304
- }
305
-
306
- /**
307
- * Reducer composition helper, internally used by various transducers
308
- * during initialization. Takes existing reducer `rfn` (a 3-tuple) and a
309
- * reducing function `fn`. Returns a new reducer tuple.
310
- *
311
- * @remarks
312
- * `rfn[2]` reduces values of type `B` into an accumulator of type `A`.
313
- * `fn` accepts values of type `C` and produces interim results of type
314
- * `B`, which are then (possibly) passed to the "inner" `rfn[2]`
315
- * function. Therefore the resulting reducer takes inputs of `C` and an
316
- * accumulator of type `A`.
317
- *
318
- * It is assumed that `fn` internally calls `rfn[2]` to pass its own
319
- * results for further processing by the nested reducer `rfn`.
320
- *
321
- * @example
322
- * ```ts
323
- * compR(rfn, fn)
324
- * // [rfn[0], rfn[1], fn]
325
- * ```
326
- *
327
- * @param rfn -
328
- * @param fn -
329
- */
330
- const compR = (rfn, fn) => [rfn[0], rfn[1], fn];
331
-
332
- function take(n, src) {
333
- return isIterable(src)
334
- ? iterator(take(n), src)
335
- : (rfn) => {
336
- const r = rfn[2];
337
- let m = n;
338
- return compR(rfn, (acc, x) => --m > 0
339
- ? r(acc, x)
340
- : m === 0
341
- ? ensureReduced(r(acc, x))
342
- : reduced(acc));
343
- };
344
- }
345
-
346
- class Reverb {
347
- /** Version strings */
348
- static version = Meta.version;
349
- /** Build date */
350
- static build = Meta.date;
351
- /** AudioContext */
352
- ctx;
353
- /** Wet Level (Reverberated node) */
354
- wetGainNode;
355
- /** Dry Level (Original sound node) */
356
- dryGainNode;
357
- /** Impulse response filter */
358
- filterNode;
359
- /** Convolution node for applying impulse response */
360
- convolverNode;
361
- /** Output gain node */
362
- outputNode;
363
- /** Option */
364
- options;
365
- /** Connected flag */
366
- isConnected;
367
- /** Noise Generator */
368
- noise = white;
369
- /**
370
- * Constructor
371
- *
372
- * @param ctx - Root AudioContext
373
- * @param options - Configure
374
- */
375
- constructor(ctx, options) {
376
- this.ctx = ctx;
377
- this.options = Object.assign(defaults, options);
378
- this.wetGainNode = this.ctx.createGain();
379
- this.dryGainNode = this.ctx.createGain();
380
- this.filterNode = this.ctx.createBiquadFilter();
381
- this.convolverNode = this.ctx.createConvolver();
382
- this.outputNode = this.ctx.createGain();
383
- this.isConnected = false;
384
- this.filterType(this.options.filterType);
385
- this.setNoise(this.options.noise);
386
- this.buildImpulse();
387
- this.mix(this.options.mix);
388
- }
389
- /**
390
- * Connect the node for the reverb effect to the original sound node.
391
- *
392
- * @param sourceNode - Input source node
393
- */
394
- connect(sourceNode) {
395
- if (this.isConnected && this.options.once) {
396
- this.isConnected = false;
397
- return this.outputNode;
398
- }
399
- this.convolverNode.connect(this.filterNode);
400
- this.filterNode.connect(this.wetGainNode);
401
- sourceNode.connect(this.convolverNode);
402
- sourceNode.connect(this.dryGainNode).connect(this.outputNode);
403
- sourceNode.connect(this.wetGainNode).connect(this.outputNode);
404
- this.isConnected = true;
405
- return this.outputNode;
406
- }
407
- /**
408
- * Disconnect the reverb node
409
- *
410
- * @param sourceNode - Input source node
411
- */
412
- disconnect(sourceNode) {
413
- if (this.isConnected) {
414
- this.convolverNode.disconnect(this.filterNode);
415
- this.filterNode.disconnect(this.wetGainNode);
416
- }
417
- this.isConnected = false;
418
- return sourceNode;
419
- }
420
- /**
421
- * Dry/Wet ratio
422
- *
423
- * @param mix - Ratio (0~1)
424
- */
425
- mix(mix) {
426
- if (!Reverb.inRange(mix, 0, 1)) {
427
- throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
428
- }
429
- this.options.mix = mix;
430
- this.dryGainNode.gain.value = 1 - this.options.mix;
431
- this.wetGainNode.gain.value = this.options.mix;
432
- }
433
- /**
434
- * Set Impulse Response time length (second)
435
- *
436
- * @param value - IR length
437
- */
438
- time(value) {
439
- if (!Reverb.inRange(value, 1, 50)) {
440
- throw new RangeError(
441
- "[Reverb.js] Time length of inpulse response must be less than 50sec."
442
- );
443
- }
444
- this.options.time = value;
445
- this.buildImpulse();
446
- }
447
- /**
448
- * Impulse response decay rate.
449
- *
450
- * @param value - Decay value
451
- */
452
- decay(value) {
453
- if (!Reverb.inRange(value, 0, 100)) {
454
- throw new RangeError(
455
- "[Reverb.js] Inpulse Response decay level must be less than 100."
456
- );
457
- }
458
- this.options.decay = value;
459
- this.buildImpulse();
460
- }
461
- /**
462
- * Delay before reverberation starts
463
- *
464
- * @param value - Time[ms]
465
- */
466
- delay(value) {
467
- if (!Reverb.inRange(value, 0, 100)) {
468
- throw new RangeError(
469
- "[Reverb.js] Inpulse Response delay time must be less than 100."
470
- );
471
- }
472
- this.options.delay = value;
473
- this.buildImpulse();
474
- }
475
- /**
476
- * Reverse the impulse response.
477
- *
478
- * @param reverse - Reverse IR
479
- */
480
- reverse(reverse) {
481
- this.options.reverse = reverse;
482
- this.buildImpulse();
483
- }
484
- /**
485
- * Filter for impulse response
486
- *
487
- * @param type - Filiter Type
488
- */
489
- filterType(type = "allpass") {
490
- this.filterNode.type = this.options.filterType = type;
491
- }
492
- /**
493
- * Filter frequency applied to impulse response
494
- *
495
- * @param freq - Frequency
496
- */
497
- filterFreq(freq) {
498
- if (!Reverb.inRange(freq, 20, 2e4)) {
499
- throw new RangeError(
500
- "[Reverb.js] Filter frequrncy must be between 20 and 20000."
501
- );
502
- }
503
- this.options.filterFreq = freq;
504
- this.filterNode.frequency.value = this.options.filterFreq;
505
- }
506
- /**
507
- * Filter quality.
508
- *
509
- * @param q - Quality
510
- */
511
- filterQ(q) {
512
- if (!Reverb.inRange(q, 0, 10)) {
513
- throw new RangeError(
514
- "[Reverb.js] Filter quality value must be between 0 and 10."
515
- );
516
- }
517
- this.options.filterQ = q;
518
- this.filterNode.Q.value = this.options.filterQ;
519
- }
520
- /**
521
- * set IR source noise peaks
522
- *
523
- * @param p - Peaks
524
- */
525
- peaks(p) {
526
- this.options.peaks = p;
527
- this.buildImpulse();
528
- }
529
- /**
530
- * set IR source noise scale.
531
- *
532
- * @param s - Scale
533
- */
534
- scale(s) {
535
- this.options.scale = s;
536
- this.buildImpulse();
537
- }
538
- /**
539
- * set IR source noise generator.
540
- *
541
- * @param a - Algorithm
542
- */
543
- randomAlgorithm(a) {
544
- this.options.randomAlgorithm = a;
545
- this.buildImpulse();
546
- }
547
- /**
548
- * Inpulse Response Noise algorithm.
549
- *
550
- * @param type - IR noise algorithm type.
551
- */
552
- setNoise(type) {
553
- this.options.noise = type;
554
- switch (type) {
555
- case Noise.blue:
556
- this.noise = blue;
557
- break;
558
- case Noise.green:
559
- this.noise = green;
560
- break;
561
- case Noise.pink:
562
- this.noise = pink;
563
- break;
564
- case Noise.red:
565
- case Noise.brown:
566
- this.noise = red;
567
- break;
568
- case Noise.violet:
569
- this.noise = violet;
570
- break;
571
- default:
572
- this.noise = white;
573
- }
574
- this.buildImpulse();
575
- }
576
- /**
577
- * Set Random Algorythm
578
- *
579
- * @param algorithm - Algorythm
580
- */
581
- setRandomAlgorythm(algorithm) {
582
- this.options.randomAlgorithm = algorithm;
583
- this.buildImpulse();
584
- }
585
- /**
586
- * Return true if in range, otherwise false
587
- *
588
- * @param x - Target value
589
- * @param min - Minimum value
590
- * @param max - Maximum value
591
- */
592
- static inRange(x, min, max) {
593
- return (x - min) * (x - max) <= 0;
594
- }
595
- /** Utility function for building an impulse response from the module parameters. */
596
- buildImpulse() {
597
- const rate = this.ctx.sampleRate;
598
- const duration = Math.max(rate * this.options.time, 1);
599
- const delayDuration = rate * this.options.delay;
600
- const impulse = this.ctx.createBuffer(2, duration, rate);
601
- const impulseL = new Float32Array(duration);
602
- const impulseR = new Float32Array(duration);
603
- const noiseL = this.getNoise(duration);
604
- const noiseR = this.getNoise(duration);
605
- for (let i = 0; i < duration; i++) {
606
- let n = 0;
607
- if (i < delayDuration) {
608
- impulseL[i] = 0;
609
- impulseR[i] = 0;
610
- n = this.options.reverse ?? false ? duration - (i - delayDuration) : i - delayDuration;
611
- } else {
612
- n = this.options.reverse ?? false ? duration - i : i;
613
- }
614
- impulseL[i] = (noiseL[i] ?? 0) * (1 - n / duration) ** this.options.decay;
615
- impulseR[i] = (noiseR[i] ?? 0) * (1 - n / duration) ** this.options.decay;
616
- }
617
- impulse.getChannelData(0).set(impulseL);
618
- impulse.getChannelData(1).set(impulseR);
619
- this.convolverNode.buffer = impulse;
620
- }
621
- /**
622
- * Noise source
623
- *
624
- * @param duration - length of IR.
625
- */
626
- getNoise(duration) {
627
- return [
628
- ...take(
629
- duration,
630
- this.noise({
631
- bins: this.options.peaks,
632
- scale: this.options.scale,
633
- rnd: this.options.randomAlgorithm
634
- })
635
- )
636
- ];
637
- }
638
- }
639
-
640
- return Reverb;
641
-
642
- })();
12
+ var Reverb=function(){"use strict";const g=23283064365386963e-26;class F{float(e=1){return this.int()*g*e}probability(e){return this.float()<e}norm(e=1){return(this.int()*g-.5)*2*e}normMinMax(e,s){const i=this.minmax(e,s);return this.float()<.5?i:-i}minmax(e,s){return this.float()*(s-e)+e}minmaxInt(e,s){e|=0;const i=(s|0)-e;return i?e+this.int()%i:e}minmaxUint(e,s){e>>>=0;const i=(s>>>0)-e;return i?e+this.int()%i:e}}const m=Math.random;class T extends F{int(){return m()*4294967296>>>0}float(e=1){return m()*e}norm(e=1){return(m()-.5)*2*e}}const w=new T,C={noise:"white",scale:1,peaks:2,randomAlgorithm:w,decay:2,delay:0,reverse:!1,time:2,filterType:"allpass",filterFreq:2200,filterQ:1,mix:.5,once:!1},R={version:"1.3.7",date:"2024-01-29T10:30:54.595Z"},u={blue:"blue",brown:"red",green:"green",pink:"pink",red:"red",violet:"violet",white:"white"},f={bins:2,scale:1,rnd:w},b=(t,e,s)=>{const i=new Array(t);for(let n=0;n<t;n++)i[n]=s.norm(e);return i},y=t=>t.reduce((e,s)=>e+s,0);function*I(t,e){const s=[t[Symbol.iterator](),e[Symbol.iterator]()];for(let i=0;;i^=1){const n=s[i].next();if(n.done)return;yield n.value}}function*v(t){const{bins:e,scale:s,rnd:i}={...f,...t},n=b(e,s,i);n.forEach((r,l)=>n[l]=l&1?r:-r);const c=1/e;let o=y(n);for(let r=0,l=-1;;++r>=e&&(r=0))o-=n[r],o+=n[r]=l*i.norm(s),l^=4294967294,yield l*o*c}const x=t=>I(v(t),v(t)),E=t=>{let e=32;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};function*j(t){const{bins:e,scale:s,rnd:i}={...f,bins:8,...t},n=b(e,s,i),c=1/e;let o=y(n);for(let r=0;;r=r+1>>>0){const l=E(r)%e;o-=n[l],o+=n[l]=i.norm(s),yield o*c}}function*N(t){const{bins:e,scale:s,rnd:i}={...f,...t},n=b(e,s,i),c=1/e;let o=y(n);for(let r=0;;++r>=e&&(r=0))o-=n[r],o+=n[r]=i.norm(s),yield o*c}const M=t=>I(N(t),N(t));function*k(t){const{scale:e,rnd:s}={...f,...t};for(;;)yield s.norm(e)}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";class d{value;constructor(e){this.value=e}deref(){return this.value}}const D=t=>new d(t),L=t=>t instanceof d,B=t=>t instanceof d?t:new d(t),G=t=>t instanceof d?t.deref():t,O=(t,e)=>[t,s=>s,e];function U(t){return t?[...t]:O(()=>[],(e,s)=>(e.push(s),e))}function*z(t,e){const s=Q(t)(U()),i=s[1],n=s[2];for(let c of e){const o=n([],c);if(L(o)){yield*G(i(o.deref()));return}o.length&&(yield*o)}yield*G(i([]))}const P=(t,e)=>[t[0],t[1],e];function A(t,e){return q(e)?z(A(t),e):s=>{const i=s[2];let n=t;return P(s,(c,o)=>--n>0?i(c,o):n===0?B(i(c,o)):D(c))}}class h{static version=R.version;static build=R.date;ctx;wetGainNode;dryGainNode;filterNode;convolverNode;outputNode;options;isConnected;noise=k;constructor(e,s){this.ctx=e,this.options=Object.assign(C,s),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(!h.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(!h.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(!h.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(!h.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(!h.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(!h.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 u.blue:this.noise=v;break;case u.green:this.noise=x;break;case u.pink:this.noise=j;break;case u.red:case u.brown:this.noise=N;break;case u.violet:this.noise=M;break;default:this.noise=k}this.buildImpulse()}setRandomAlgorythm(e){this.options.randomAlgorithm=e,this.buildImpulse()}static inRange(e,s,i){return(e-s)*(e-i)<=0}buildImpulse(){const e=this.ctx.sampleRate,s=Math.max(e*this.options.time,1),i=e*this.options.delay,n=this.ctx.createBuffer(2,s,e),c=new Float32Array(s),o=new Float32Array(s),r=this.getNoise(s),l=this.getNoise(s);for(let a=0;a<s;a++){let p=0;a<i?(c[a]=0,o[a]=0,p=this.options.reverse??!1?s-(a-i):a-i):p=this.options.reverse??!1?s-a:a,c[a]=(r[a]??0)*(1-p/s)**this.options.decay,o[a]=(l[a]??0)*(1-p/s)**this.options.decay}n.getChannelData(0).set(c),n.getChannelData(1).set(o),this.convolverNode.buffer=n}getNoise(e){return[...A(e,this.noise({bins:this.options.peaks,scale:this.options.scale,rnd:this.options.randomAlgorithm}))]}}return h}();