@logue/reverb 1.0.2 → 1.2.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/dist/Reverb.es.js CHANGED
@@ -5,14 +5,11 @@
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.0.2
8
+ * @version 1.1.2
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
11
 
12
- const g = {
13
- version: "1.0.2",
14
- date: "2022-09-09T10:45:33.869Z"
15
- }, l = {
12
+ const Noise = {
16
13
  BLUE: "blue",
17
14
  GREEN: "green",
18
15
  PINK: "pink",
@@ -20,228 +17,483 @@ const g = {
20
17
  VIOLET: "violet",
21
18
  WHITE: "white",
22
19
  BROWN: "red"
23
- }, T = (t, e) => t != null && typeof t[e] == "function", x = (t) => T(t, "xform") ? t.xform() : t, F = (t) => t != null && typeof t[Symbol.iterator] == "function";
24
- class u {
25
- constructor(e) {
26
- this.value = e;
27
- }
28
- deref() {
29
- return this.value;
30
- }
20
+ };
21
+
22
+ const INV_MAX = 1 / 2 ** 32;
23
+ class ARandom {
24
+ float(norm = 1) {
25
+ return this.int() * INV_MAX * norm;
26
+ }
27
+ norm(norm = 1) {
28
+ return (this.int() * INV_MAX - 0.5) * 2 * norm;
29
+ }
30
+ minmax(min, max) {
31
+ return this.float() * (max - min) + min;
32
+ }
33
+ minmaxInt(min, max) {
34
+ min |= 0;
35
+ max |= 0;
36
+ return min + ((this.float() * (max - min)) | 0);
37
+ }
31
38
  }
32
- const k = (t) => new u(t), C = (t) => t instanceof u, D = (t) => t instanceof u ? t : new u(t), N = (t) => t instanceof u ? t.deref() : t, j = (t, e) => [t, (i) => i, e];
33
- function q(t) {
34
- return t ? [...t] : j(() => [], (e, i) => (e.push(i), e));
39
+
40
+ const random = Math.random;
41
+ /**
42
+ * A `Math.random()` based {@link IRandom} implementation. Also @see
43
+ * {@link SYSTEM}.
44
+ */
45
+ class SystemRandom extends ARandom {
46
+ int() {
47
+ return (random() * 4294967296) /* 2**32 */ >>> 0;
48
+ }
49
+ float(norm = 1) {
50
+ return random() * norm;
51
+ }
52
+ norm(norm = 1) {
53
+ return (random() - 0.5) * 2 * norm;
54
+ }
35
55
  }
36
- function* B(t, e) {
37
- const i = x(t)(q()), s = i[1], o = i[2];
38
- for (let r of e) {
39
- const n = o([], r);
40
- if (C(n)) {
41
- yield* N(s(n.deref()));
42
- return;
56
+ /**
57
+ * Used as default PRNG throughout most other thi.ng projects, though usually is
58
+ * configurable.
59
+ */
60
+ const SYSTEM = new SystemRandom();
61
+
62
+ const defaults = {
63
+ noise: Noise.WHITE,
64
+ scale: 1,
65
+ peaks: 2,
66
+ randomAlgorithm: SYSTEM,
67
+ decay: 2,
68
+ delay: 0,
69
+ reverse: false,
70
+ time: 2,
71
+ filterType: "allpass",
72
+ filterFreq: 2200,
73
+ filterQ: 1,
74
+ mix: 0.5,
75
+ once: false
76
+ };
77
+
78
+ const meta = {
79
+ version: "1.1.2",
80
+ date: "2022-11-06T12:24:34.397Z"
81
+ };
82
+
83
+ const preseed = (n, scale, rnd) => {
84
+ const state = new Array(n);
85
+ for (let i = 0; i < n; i++) {
86
+ state[i] = rnd.norm(scale);
87
+ }
88
+ return state;
89
+ };
90
+ const sum = (src) => src.reduce((sum, x) => sum + x, 0);
91
+ function* interleave(a, b) {
92
+ const src = [a[Symbol.iterator](), b[Symbol.iterator]()];
93
+ for (let i = 0; true; i ^= 1) {
94
+ const next = src[i].next();
95
+ if (next.done)
96
+ return;
97
+ yield next.value;
43
98
  }
44
- n.length && (yield* n);
45
- }
46
- yield* N(s([]));
47
99
  }
48
- const L = (t, e) => [t[0], t[1], e];
49
- function E(t, e) {
50
- return F(e) ? B(E(t), e) : (i) => {
51
- const s = i[2];
52
- let o = t;
53
- return L(i, (r, n) => --o > 0 ? s(r, n) : o === 0 ? D(s(r, n)) : k(r));
54
- };
100
+
101
+ /**
102
+ * High-pass filtered noise. Opposite of {@link red}.
103
+ *
104
+ * @param n -
105
+ * @param scale -
106
+ * @param rnd -
107
+ */
108
+ function* blue(n = 2, scale = 1, rnd = SYSTEM) {
109
+ const state = preseed(n, scale, rnd);
110
+ state.forEach((x, i) => (state[i] = i & 1 ? x : -x));
111
+ const invN = 1 / n;
112
+ let acc = sum(state);
113
+ for (let i = 0, sign = -1; true; ++i >= n && (i = 0)) {
114
+ acc -= state[i];
115
+ acc += state[i] = sign * rnd.norm(scale);
116
+ sign ^= 0xfffffffe;
117
+ yield sign * acc * invN;
118
+ }
55
119
  }
56
- const w = 1 / 2 ** 32;
57
- class S {
58
- float(e = 1) {
59
- return this.int() * w * e;
60
- }
61
- norm(e = 1) {
62
- return (this.int() * w - 0.5) * 2 * e;
63
- }
64
- minmax(e, i) {
65
- return this.float() * (i - e) + e;
66
- }
67
- minmaxInt(e, i) {
68
- return e |= 0, i |= 0, e + (this.float() * (i - e) | 0);
69
- }
120
+
121
+ /**
122
+ * Band-pass filtered noise (interleaved blue noise). Opposite of
123
+ * {@link violet}.
124
+ *
125
+ * @param n -
126
+ * @param scale -
127
+ * @param rnd -
128
+ */
129
+ const green = (n = 2, scale = 1, rnd = SYSTEM) => interleave(blue(n, scale, rnd), blue(n, scale, rnd));
130
+
131
+ /**
132
+ * Returns number of 1 bits in `x`.
133
+ *
134
+ * @param x -
135
+ */
136
+ const ctz32 = (x) => {
137
+ let c = 32;
138
+ x &= -x;
139
+ x && c--;
140
+ x & 0x0000ffff && (c -= 16);
141
+ x & 0x00ff00ff && (c -= 8);
142
+ x & 0x0f0f0f0f && (c -= 4);
143
+ x & 0x33333333 && (c -= 2);
144
+ x & 0x55555555 && (c -= 1);
145
+ return c;
146
+ };
147
+
148
+ /**
149
+ * Exponential decay (1/f) noise, based on Voss-McCarthy algorithm.
150
+ *
151
+ * @remarks
152
+ * The number of internal states should be in the [4..32] range (default: 8).
153
+ * Due to JS integer limitations, `n` > 32 are meaningless.
154
+ *
155
+ * References:
156
+ *
157
+ * - https://www.dsprelated.com/showarticle/908.php
158
+ * - https://www.firstpr.com.au/dsp/pink-noise/#Voss-McCartney
159
+ *
160
+ * @param n -
161
+ * @param scale -
162
+ * @param rnd -
163
+ */
164
+ function* pink(n = 8, scale = 1, rnd = SYSTEM) {
165
+ const state = preseed(n, scale, rnd);
166
+ const invN = 1 / n;
167
+ let acc = sum(state);
168
+ for (let i = 0; true; i = (i + 1) >>> 0) {
169
+ const id = ctz32(i) % n;
170
+ acc -= state[id];
171
+ acc += state[id] = rnd.norm(scale);
172
+ yield acc * invN;
173
+ }
70
174
  }
71
- const f = Math.random;
72
- class A extends S {
73
- int() {
74
- return f() * 4294967296 >>> 0;
75
- }
76
- float(e = 1) {
77
- return f() * e;
78
- }
79
- norm(e = 1) {
80
- return (f() - 0.5) * 2 * e;
81
- }
175
+
176
+ /**
177
+ * Low-pass filtered noise (same as brown noise). Opposite of {@link blue}.
178
+ *
179
+ * @param n -
180
+ * @param scale -
181
+ * @param rnd -
182
+ */
183
+ function* red(n = 2, scale = 1, rnd = SYSTEM) {
184
+ const state = preseed(n, scale, rnd);
185
+ const invN = 1 / n;
186
+ let acc = sum(state);
187
+ for (let i = 0; true; ++i >= n && (i = 0)) {
188
+ acc -= state[i];
189
+ acc += state[i] = rnd.norm(scale);
190
+ yield acc * invN;
191
+ }
82
192
  }
83
- const h = new A(), v = (t, e, i) => {
84
- const s = new Array(t);
85
- for (let o = 0; o < t; o++)
86
- s[o] = i.norm(e);
87
- return s;
88
- }, b = (t) => t.reduce((e, i) => e + i, 0);
89
- function* I(t, e) {
90
- const i = [t[Symbol.iterator](), e[Symbol.iterator]()];
91
- for (let s = 0; ; s ^= 1) {
92
- const o = i[s].next();
93
- if (o.done)
94
- return;
95
- yield o.value;
96
- }
193
+
194
+ /**
195
+ * Band-stop filtered noise (interleaved red noise). Opposite of {@link green}.
196
+ *
197
+ * @param n -
198
+ * @param scale -
199
+ * @param rnd -
200
+ */
201
+ const violet = (n = 2, scale = 1, rnd = SYSTEM) => interleave(red(n, scale, rnd), red(n, scale, rnd));
202
+
203
+ /**
204
+ * Unfiltered noise w/ uniform distribution. Merely yields samples from
205
+ * given PRNG.
206
+ *
207
+ * @param scale -
208
+ * @param rnd -
209
+ */
210
+ function* white(scale = 1, rnd = SYSTEM) {
211
+ while (true) {
212
+ yield rnd.norm(scale);
213
+ }
97
214
  }
98
- function* p(t = 2, e = 1, i = h) {
99
- const s = v(t, e, i);
100
- s.forEach((n, a) => s[a] = a & 1 ? n : -n);
101
- const o = 1 / t;
102
- let r = b(s);
103
- for (let n = 0, a = -1; ; ++n >= t && (n = 0))
104
- r -= s[n], r += s[n] = a * i.norm(e), a ^= 4294967294, yield a * r * o;
215
+
216
+ const implementsFunction = (x, fn) => x != null && typeof x[fn] === "function";
217
+
218
+ const ensureTransducer = (x) => implementsFunction(x, "xform") ? x.xform() : x;
219
+
220
+ const isIterable = (x) => x != null && typeof x[Symbol.iterator] === "function";
221
+
222
+ class Reduced {
223
+ constructor(val) {
224
+ this.value = val;
225
+ }
226
+ deref() {
227
+ return this.value;
228
+ }
105
229
  }
106
- const Q = (t = 2, e = 1, i = h) => I(p(t, e, i), p(t, e, i)), W = (t) => {
107
- let e = 32;
108
- 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;
109
- };
110
- function* M(t = 8, e = 1, i = h) {
111
- const s = v(t, e, i), o = 1 / t;
112
- let r = b(s);
113
- for (let n = 0; ; n = n + 1 >>> 0) {
114
- const a = W(n) % t;
115
- r -= s[a], r += s[a] = i.norm(e), yield r * o;
116
- }
230
+ const reduced = (x) => new Reduced(x);
231
+ const isReduced = (x) => x instanceof Reduced;
232
+ const ensureReduced = (x) => x instanceof Reduced ? x : new Reduced(x);
233
+ const unreduced = (x) => (x instanceof Reduced ? x.deref() : x);
234
+
235
+ /**
236
+ * Convenience helper for building a full {@link Reducer} using the identity
237
+ * function (i.e. `(x) => x`) as completion step (true for 90% of all
238
+ * bundled transducers).
239
+ *
240
+ * @param init - init step of reducer
241
+ * @param rfn - reduction step of reducer
242
+ */
243
+ const reducer = (init, rfn) => [init, (acc) => acc, rfn];
244
+
245
+ function push(xs) {
246
+ return xs
247
+ ? [...xs]
248
+ : reducer(() => [], (acc, x) => (acc.push(x), acc));
117
249
  }
118
- function* m(t = 2, e = 1, i = h) {
119
- const s = v(t, e, i), o = 1 / t;
120
- let r = b(s);
121
- for (let n = 0; ; ++n >= t && (n = 0))
122
- r -= s[n], r += s[n] = i.norm(e), yield r * o;
250
+
251
+ /**
252
+ * Takes a transducer and input iterable. Returns iterator of
253
+ * transformed results.
254
+ *
255
+ * @param xform -
256
+ * @param xs -
257
+ */
258
+ function* iterator(xform, xs) {
259
+ const rfn = ensureTransducer(xform)(push());
260
+ const complete = rfn[1];
261
+ const reduce = rfn[2];
262
+ for (let x of xs) {
263
+ const y = reduce([], x);
264
+ if (isReduced(y)) {
265
+ yield* unreduced(complete(y.deref()));
266
+ return;
267
+ }
268
+ if (y.length) {
269
+ yield* y;
270
+ }
271
+ }
272
+ yield* unreduced(complete([]));
123
273
  }
124
- const O = (t = 2, e = 1, i = h) => I(m(t, e, i), m(t, e, i));
125
- function* R(t = 1, e = h) {
126
- for (; ; )
127
- yield e.norm(t);
274
+
275
+ /**
276
+ * Reducer composition helper, internally used by various transducers
277
+ * during initialization. Takes existing reducer `rfn` (a 3-tuple) and a
278
+ * reducing function `fn`. Returns a new reducer tuple.
279
+ *
280
+ * @remarks
281
+ * `rfn[2]` reduces values of type `B` into an accumulator of type `A`.
282
+ * `fn` accepts values of type `C` and produces interim results of type
283
+ * `B`, which are then (possibly) passed to the "inner" `rfn[2]`
284
+ * function. Therefore the resulting reducer takes inputs of `C` and an
285
+ * accumulator of type `A`.
286
+ *
287
+ * It is assumed that `fn` internally calls `rfn[2]` to pass its own
288
+ * results for further processing by the nested reducer `rfn`.
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * compR(rfn, fn)
293
+ * // [rfn[0], rfn[1], fn]
294
+ * ```
295
+ *
296
+ * @param rfn -
297
+ * @param fn -
298
+ */
299
+ const compR = (rfn, fn) => [rfn[0], rfn[1], fn];
300
+
301
+ function take(n, src) {
302
+ return isIterable(src)
303
+ ? iterator(take(n), src)
304
+ : (rfn) => {
305
+ const r = rfn[2];
306
+ let m = n;
307
+ return compR(rfn, (acc, x) => --m > 0
308
+ ? r(acc, x)
309
+ : m === 0
310
+ ? ensureReduced(r(acc, x))
311
+ : reduced(acc));
312
+ };
128
313
  }
129
- class y {
130
- constructor(e, i) {
131
- this.noise = R, this.ctx = e, this.options = { ...V, ...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.setNoise(this.options.noise), this.buildImpulse(), this.mix(this.options.mix);
314
+
315
+ class Reverb {
316
+ constructor(ctx, options) {
317
+ this.noise = white;
318
+ this.ctx = ctx;
319
+ this.options = { ...defaults, ...options };
320
+ this.wetGainNode = this.ctx.createGain();
321
+ this.dryGainNode = this.ctx.createGain();
322
+ this.filterNode = this.ctx.createBiquadFilter();
323
+ this.convolverNode = this.ctx.createConvolver();
324
+ this.outputNode = this.ctx.createGain();
325
+ this.isConnected = false;
326
+ this.filterType(this.options.filterType);
327
+ this.setNoise(this.options.noise);
328
+ this.buildImpulse();
329
+ this.mix(this.options.mix);
132
330
  }
133
- connect(e) {
134
- 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);
331
+ connect(sourceNode) {
332
+ if (this.isConnected && this.options.once) {
333
+ this.isConnected = false;
334
+ return this.outputNode;
335
+ }
336
+ this.convolverNode.connect(this.filterNode);
337
+ this.filterNode.connect(this.wetGainNode);
338
+ sourceNode.connect(this.convolverNode);
339
+ sourceNode.connect(this.dryGainNode).connect(this.outputNode);
340
+ sourceNode.connect(this.wetGainNode).connect(this.outputNode);
341
+ this.isConnected = true;
342
+ return this.outputNode;
135
343
  }
136
- disconnect(e) {
137
- return this.isConnected && (this.convolverNode.disconnect(this.filterNode), this.filterNode.disconnect(this.wetGainNode)), this.isConnected = !1, e;
344
+ disconnect(sourceNode) {
345
+ if (this.isConnected) {
346
+ this.convolverNode.disconnect(this.filterNode);
347
+ this.filterNode.disconnect(this.wetGainNode);
348
+ }
349
+ this.isConnected = false;
350
+ return sourceNode;
138
351
  }
139
- mix(e) {
140
- if (!this.inRange(e, 0, 1))
352
+ mix(mix) {
353
+ if (!this.inRange(mix, 0, 1)) {
141
354
  throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
142
- this.options.mix = e, this.dryGainNode.gain.value = 1 - this.options.mix, this.wetGainNode.gain.value = this.options.mix;
355
+ }
356
+ this.options.mix = mix;
357
+ this.dryGainNode.gain.value = 1 - this.options.mix;
358
+ this.wetGainNode.gain.value = this.options.mix;
143
359
  }
144
- time(e) {
145
- if (!this.inRange(e, 1, 50))
360
+ time(value) {
361
+ if (!this.inRange(value, 1, 50)) {
146
362
  throw new RangeError(
147
363
  "[Reverb.js] Time length of inpulse response must be less than 50sec."
148
364
  );
149
- this.options.time = e, this.buildImpulse();
365
+ }
366
+ this.options.time = value;
367
+ this.buildImpulse();
150
368
  }
151
- decay(e) {
152
- if (!this.inRange(e, 0, 100))
369
+ decay(value) {
370
+ if (!this.inRange(value, 0, 100)) {
153
371
  throw new RangeError(
154
372
  "[Reverb.js] Inpulse Response decay level must be less than 100."
155
373
  );
156
- this.options.decay = e, this.buildImpulse();
374
+ }
375
+ this.options.decay = value;
376
+ this.buildImpulse();
157
377
  }
158
- delay(e) {
159
- if (!this.inRange(e, 0, 100))
378
+ delay(value) {
379
+ if (!this.inRange(value, 0, 100)) {
160
380
  throw new RangeError(
161
381
  "[Reverb.js] Inpulse Response delay time must be less than 100."
162
382
  );
163
- this.options.delay = e, this.buildImpulse();
383
+ }
384
+ this.options.delay = value;
385
+ this.buildImpulse();
164
386
  }
165
- reverse(e) {
166
- this.options.reverse = e, this.buildImpulse();
387
+ reverse(reverse) {
388
+ this.options.reverse = reverse;
389
+ this.buildImpulse();
167
390
  }
168
- filterType(e) {
169
- this.filterNode.type = this.options.filterType = e;
391
+ filterType(type = "allpass") {
392
+ this.filterNode.type = this.options.filterType = type;
170
393
  }
171
- filterFreq(e) {
172
- if (!this.inRange(e, 20, 2e4))
394
+ filterFreq(freq) {
395
+ if (!this.inRange(freq, 20, 2e4)) {
173
396
  throw new RangeError(
174
397
  "[Reverb.js] Filter frequrncy must be between 20 and 20000."
175
398
  );
176
- this.options.filterFreq = e, this.filterNode.frequency.value = this.options.filterFreq;
399
+ }
400
+ this.options.filterFreq = freq;
401
+ this.filterNode.frequency.value = this.options.filterFreq;
177
402
  }
178
- filterQ(e) {
179
- if (!this.inRange(e, 0, 10))
403
+ filterQ(q) {
404
+ if (!this.inRange(q, 0, 10)) {
180
405
  throw new RangeError(
181
406
  "[Reverb.js] Filter quality value must be between 0 and 10."
182
407
  );
183
- this.options.filterQ = e, this.filterNode.Q.value = this.options.filterQ;
408
+ }
409
+ this.options.filterQ = q;
410
+ this.filterNode.Q.value = this.options.filterQ;
184
411
  }
185
- power(e) {
186
- this.options.power = e, this.buildImpulse();
412
+ peaks(p) {
413
+ this.options.peaks = p;
414
+ this.buildImpulse();
187
415
  }
188
- setNoise(e) {
189
- switch (this.options.noise = e, e) {
190
- case l.BLUE:
191
- this.noise = p;
416
+ scale(s) {
417
+ this.options.scale = s;
418
+ this.buildImpulse();
419
+ }
420
+ randomAlgorithm(a) {
421
+ this.options.randomAlgorithm = a;
422
+ this.buildImpulse();
423
+ }
424
+ setNoise(type) {
425
+ this.options.noise = type;
426
+ switch (type) {
427
+ case Noise.BLUE:
428
+ this.noise = blue;
192
429
  break;
193
- case l.GREEN:
194
- this.noise = Q;
430
+ case Noise.GREEN:
431
+ this.noise = green;
195
432
  break;
196
- case l.PINK:
197
- this.noise = M;
433
+ case Noise.PINK:
434
+ this.noise = pink;
198
435
  break;
199
- case l.RED:
200
- case l.BROWN:
201
- this.noise = m;
436
+ case Noise.RED:
437
+ case Noise.BROWN:
438
+ this.noise = red;
202
439
  break;
203
- case l.VIOLET:
204
- this.noise = O;
440
+ case Noise.VIOLET:
441
+ this.noise = violet;
205
442
  break;
206
443
  default:
207
- this.noise = R;
208
- break;
444
+ this.noise = white;
209
445
  }
210
446
  this.buildImpulse();
211
447
  }
212
- inRange(e, i, s) {
213
- return (e - i) * (e - s) <= 0;
448
+ setRandomAlgorythm(algorithm) {
449
+ this.options.randomAlgorithm = algorithm;
450
+ this.buildImpulse();
451
+ }
452
+ inRange(x, min, max) {
453
+ return (x - min) * (x - max) <= 0;
214
454
  }
215
455
  buildImpulse() {
216
- const e = this.ctx.sampleRate, i = Math.max(e * this.options.time, 1), s = e * this.options.delay, o = this.ctx.createBuffer(2, i, e), r = new Float32Array(i), n = new Float32Array(i), a = this.getNoise(i), G = this.getNoise(i);
217
- for (let c = 0; c < i; c++) {
218
- let d = 0;
219
- c < s ? (r[c] = 0, n[c] = 0, d = this.options.reverse ? i - (c - s) : c - s) : d = this.options.reverse ? i - c : c, r[c] = a[c] * (1 - d / i) ** this.options.decay, n[c] = G[c] * (1 - d / i) ** this.options.decay;
456
+ const rate = this.ctx.sampleRate;
457
+ const duration = Math.max(rate * this.options.time, 1);
458
+ const delayDuration = rate * this.options.delay;
459
+ const impulse = this.ctx.createBuffer(2, duration, rate);
460
+ const impulseL = new Float32Array(duration);
461
+ const impulseR = new Float32Array(duration);
462
+ const noiseL = this.getNoise(duration);
463
+ const noiseR = this.getNoise(duration);
464
+ for (let i = 0; i < duration; i++) {
465
+ let n = 0;
466
+ if (i < delayDuration) {
467
+ impulseL[i] = 0;
468
+ impulseR[i] = 0;
469
+ n = this.options.reverse ? duration - (i - delayDuration) : i - delayDuration;
470
+ } else {
471
+ n = this.options.reverse ? duration - i : i;
472
+ }
473
+ impulseL[i] = noiseL[i] * (1 - n / duration) ** this.options.decay;
474
+ impulseR[i] = noiseR[i] * (1 - n / duration) ** this.options.decay;
220
475
  }
221
- o.getChannelData(0).set(r), o.getChannelData(1).set(n), this.convolverNode.buffer = o;
476
+ impulse.getChannelData(0).set(impulseL);
477
+ impulse.getChannelData(1).set(impulseR);
478
+ this.convolverNode.buffer = impulse;
222
479
  }
223
- getNoise(e) {
224
- return [...E(e, this.noise())].map(
225
- (i) => i * this.options.power
226
- );
480
+ getNoise(duration) {
481
+ return [
482
+ ...take(
483
+ duration,
484
+ this.noise === white ? white(this.options.scale, this.options.randomAlgorithm) : this.noise(
485
+ this.options.peaks,
486
+ this.options.scale,
487
+ this.options.randomAlgorithm
488
+ )
489
+ )
490
+ ];
227
491
  }
228
492
  }
229
- y.version = g.version;
230
- y.build = g.date;
231
- const V = {
232
- noise: l.WHITE,
233
- power: 2,
234
- decay: 2,
235
- delay: 0,
236
- reverse: !1,
237
- time: 2,
238
- filterType: "lowpass",
239
- filterFreq: 2200,
240
- filterQ: 1,
241
- mix: 0.5,
242
- once: !1
243
- };
244
- window.Reverb || (window.Reverb = y);
245
- export {
246
- y as default
247
- };
493
+ Reverb.version = meta.version;
494
+ Reverb.build = meta.date;
495
+ if (!window.Reverb) {
496
+ window.Reverb = Reverb;
497
+ }
498
+
499
+ export { Reverb as default };