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