@logue/reverb 1.2.3 → 1.2.6
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 +0 -1
- package/dist/Meta.js +6 -0
- package/dist/NoiseType.d.ts +0 -1
- package/dist/NoiseType.js +19 -0
- package/dist/Reverb.d.ts +0 -1
- package/dist/Reverb.es.js +145 -43
- package/dist/Reverb.iife.js +320 -218
- package/dist/Reverb.js +339 -0
- package/dist/Reverb.umd.js +322 -220
- package/dist/interfaces/MetaInterface.d.ts +0 -1
- package/dist/interfaces/MetaInterface.js +1 -0
- package/dist/interfaces/OptionInterface.d.ts +1 -2
- package/dist/interfaces/OptionInterface.js +17 -0
- package/package.json +23 -20
- package/dist/Meta.d.ts.map +0 -1
- package/dist/NoiseType.d.ts.map +0 -1
- package/dist/Reverb.d.ts.map +0 -1
- package/dist/interfaces/MetaInterface.d.ts.map +0 -1
- package/dist/interfaces/OptionInterface.d.ts.map +0 -1
package/dist/Meta.d.ts
CHANGED
package/dist/Meta.js
ADDED
package/dist/NoiseType.d.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Impulse response noise generation algorithm */
|
|
2
|
+
const Noise = {
|
|
3
|
+
/** Blue noise */
|
|
4
|
+
BLUE: 'blue',
|
|
5
|
+
/** Green noise */
|
|
6
|
+
GREEN: 'green',
|
|
7
|
+
/** Pink noise */
|
|
8
|
+
PINK: 'pink',
|
|
9
|
+
/** Red noise */
|
|
10
|
+
RED: 'red',
|
|
11
|
+
/** Violet noise */
|
|
12
|
+
VIOLET: 'violet',
|
|
13
|
+
/** White noise */
|
|
14
|
+
WHITE: 'white',
|
|
15
|
+
/** Brown noise (same as red noise) */
|
|
16
|
+
BROWN: 'red',
|
|
17
|
+
};
|
|
18
|
+
/** Noise */
|
|
19
|
+
export default Noise;
|
package/dist/Reverb.d.ts
CHANGED
package/dist/Reverb.es.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @description JavaScript Reverb effect class
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
-
* @copyright 2019-
|
|
6
|
+
* @copyright 2019-2023 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.2.
|
|
8
|
+
* @version 1.2.6
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -13,59 +13,73 @@ import { SYSTEM } from '@thi.ng/random';
|
|
|
13
13
|
import { white, violet, red, pink, green, blue } from '@thi.ng/colored-noise';
|
|
14
14
|
import { take } from '@thi.ng/transducers';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/** Brown noise (same as red noise) */
|
|
31
|
-
BROWN: 'red',
|
|
16
|
+
const defaults = {
|
|
17
|
+
noise: "white",
|
|
18
|
+
scale: 1,
|
|
19
|
+
peaks: 2,
|
|
20
|
+
randomAlgorithm: SYSTEM,
|
|
21
|
+
decay: 2,
|
|
22
|
+
delay: 0,
|
|
23
|
+
reverse: false,
|
|
24
|
+
time: 2,
|
|
25
|
+
filterType: "allpass",
|
|
26
|
+
filterFreq: 2200,
|
|
27
|
+
filterQ: 1,
|
|
28
|
+
mix: 0.5,
|
|
29
|
+
once: false
|
|
32
30
|
};
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
scale: 1,
|
|
38
|
-
peaks: 2,
|
|
39
|
-
randomAlgorithm: SYSTEM,
|
|
40
|
-
decay: 2,
|
|
41
|
-
delay: 0,
|
|
42
|
-
reverse: false,
|
|
43
|
-
time: 2,
|
|
44
|
-
filterType: 'allpass',
|
|
45
|
-
filterFreq: 2200,
|
|
46
|
-
filterQ: 1,
|
|
47
|
-
mix: 0.5,
|
|
48
|
-
once: false,
|
|
32
|
+
const meta = {
|
|
33
|
+
version: "1.2.6",
|
|
34
|
+
date: "2023-02-15T04:55:52.436Z"
|
|
49
35
|
};
|
|
50
36
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
37
|
+
const Noise = {
|
|
38
|
+
/** Blue noise */
|
|
39
|
+
BLUE: "blue",
|
|
40
|
+
/** Green noise */
|
|
41
|
+
GREEN: "green",
|
|
42
|
+
/** Pink noise */
|
|
43
|
+
PINK: "pink",
|
|
44
|
+
/** Red noise */
|
|
45
|
+
RED: "red",
|
|
46
|
+
/** Violet noise */
|
|
47
|
+
VIOLET: "violet",
|
|
48
|
+
/** White noise */
|
|
49
|
+
WHITE: "white",
|
|
50
|
+
/** Brown noise (same as red noise) */
|
|
51
|
+
BROWN: "red"
|
|
55
52
|
};
|
|
56
53
|
|
|
57
54
|
class Reverb {
|
|
55
|
+
/** Version strings */
|
|
58
56
|
static version = meta.version;
|
|
57
|
+
/** Build date */
|
|
59
58
|
static build = meta.date;
|
|
59
|
+
/** AudioContext */
|
|
60
60
|
ctx;
|
|
61
|
+
/** Wet Level (Reverberated node) */
|
|
61
62
|
wetGainNode;
|
|
63
|
+
/** Dry Level (Original sound node) */
|
|
62
64
|
dryGainNode;
|
|
65
|
+
/** Impulse response filter */
|
|
63
66
|
filterNode;
|
|
67
|
+
/** Convolution node for applying impulse response */
|
|
64
68
|
convolverNode;
|
|
69
|
+
/** Output gain node */
|
|
65
70
|
outputNode;
|
|
71
|
+
/** Option */
|
|
66
72
|
options;
|
|
73
|
+
/** Connected flag */
|
|
67
74
|
isConnected;
|
|
75
|
+
/** Noise Generator */
|
|
68
76
|
noise = white;
|
|
77
|
+
/**
|
|
78
|
+
* Constructor
|
|
79
|
+
*
|
|
80
|
+
* @param ctx - Root AudioContext
|
|
81
|
+
* @param options - Configure
|
|
82
|
+
*/
|
|
69
83
|
constructor(ctx, options) {
|
|
70
84
|
this.ctx = ctx;
|
|
71
85
|
this.options = { ...defaults, ...options };
|
|
@@ -80,6 +94,11 @@ class Reverb {
|
|
|
80
94
|
this.buildImpulse();
|
|
81
95
|
this.mix(this.options.mix);
|
|
82
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Connect the node for the reverb effect to the original sound node.
|
|
99
|
+
*
|
|
100
|
+
* @param sourceNode - Input source node
|
|
101
|
+
*/
|
|
83
102
|
connect(sourceNode) {
|
|
84
103
|
if (this.isConnected && this.options.once) {
|
|
85
104
|
this.isConnected = false;
|
|
@@ -93,6 +112,11 @@ class Reverb {
|
|
|
93
112
|
this.isConnected = true;
|
|
94
113
|
return this.outputNode;
|
|
95
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Disconnect the reverb node
|
|
117
|
+
*
|
|
118
|
+
* @param sourceNode - Input source node
|
|
119
|
+
*/
|
|
96
120
|
disconnect(sourceNode) {
|
|
97
121
|
if (this.isConnected) {
|
|
98
122
|
this.convolverNode.disconnect(this.filterNode);
|
|
@@ -101,6 +125,11 @@ class Reverb {
|
|
|
101
125
|
this.isConnected = false;
|
|
102
126
|
return sourceNode;
|
|
103
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Dry/Wet ratio
|
|
130
|
+
*
|
|
131
|
+
* @param mix - Ratio (0~1)
|
|
132
|
+
*/
|
|
104
133
|
mix(mix) {
|
|
105
134
|
if (!this.inRange(mix, 0, 1)) {
|
|
106
135
|
throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
|
|
@@ -109,6 +138,11 @@ class Reverb {
|
|
|
109
138
|
this.dryGainNode.gain.value = 1 - this.options.mix;
|
|
110
139
|
this.wetGainNode.gain.value = this.options.mix;
|
|
111
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Set Impulse Response time length (second)
|
|
143
|
+
*
|
|
144
|
+
* @param value - IR length
|
|
145
|
+
*/
|
|
112
146
|
time(value) {
|
|
113
147
|
if (!this.inRange(value, 1, 50)) {
|
|
114
148
|
throw new RangeError(
|
|
@@ -118,6 +152,11 @@ class Reverb {
|
|
|
118
152
|
this.options.time = value;
|
|
119
153
|
this.buildImpulse();
|
|
120
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Impulse response decay rate.
|
|
157
|
+
*
|
|
158
|
+
* @param value - Decay value
|
|
159
|
+
*/
|
|
121
160
|
decay(value) {
|
|
122
161
|
if (!this.inRange(value, 0, 100)) {
|
|
123
162
|
throw new RangeError(
|
|
@@ -127,6 +166,11 @@ class Reverb {
|
|
|
127
166
|
this.options.decay = value;
|
|
128
167
|
this.buildImpulse();
|
|
129
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Delay before reverberation starts
|
|
171
|
+
*
|
|
172
|
+
* @param value - Time[ms]
|
|
173
|
+
*/
|
|
130
174
|
delay(value) {
|
|
131
175
|
if (!this.inRange(value, 0, 100)) {
|
|
132
176
|
throw new RangeError(
|
|
@@ -136,13 +180,28 @@ class Reverb {
|
|
|
136
180
|
this.options.delay = value;
|
|
137
181
|
this.buildImpulse();
|
|
138
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Reverse the impulse response.
|
|
185
|
+
*
|
|
186
|
+
* @param reverse - Reverse IR
|
|
187
|
+
*/
|
|
139
188
|
reverse(reverse) {
|
|
140
189
|
this.options.reverse = reverse;
|
|
141
190
|
this.buildImpulse();
|
|
142
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Filter for impulse response
|
|
194
|
+
*
|
|
195
|
+
* @param type - Filiter Type
|
|
196
|
+
*/
|
|
143
197
|
filterType(type = "allpass") {
|
|
144
198
|
this.filterNode.type = this.options.filterType = type;
|
|
145
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Filter frequency applied to impulse response
|
|
202
|
+
*
|
|
203
|
+
* @param freq - Frequency
|
|
204
|
+
*/
|
|
146
205
|
filterFreq(freq) {
|
|
147
206
|
if (!this.inRange(freq, 20, 2e4)) {
|
|
148
207
|
throw new RangeError(
|
|
@@ -152,6 +211,11 @@ class Reverb {
|
|
|
152
211
|
this.options.filterFreq = freq;
|
|
153
212
|
this.filterNode.frequency.value = this.options.filterFreq;
|
|
154
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Filter quality.
|
|
216
|
+
*
|
|
217
|
+
* @param q - Quality
|
|
218
|
+
*/
|
|
155
219
|
filterQ(q) {
|
|
156
220
|
if (!this.inRange(q, 0, 10)) {
|
|
157
221
|
throw new RangeError(
|
|
@@ -161,35 +225,55 @@ class Reverb {
|
|
|
161
225
|
this.options.filterQ = q;
|
|
162
226
|
this.filterNode.Q.value = this.options.filterQ;
|
|
163
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* set IR source noise peaks
|
|
230
|
+
*
|
|
231
|
+
* @param p - Peaks
|
|
232
|
+
*/
|
|
164
233
|
peaks(p) {
|
|
165
234
|
this.options.peaks = p;
|
|
166
235
|
this.buildImpulse();
|
|
167
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* set IR source noise scale.
|
|
239
|
+
*
|
|
240
|
+
* @param s - Scale
|
|
241
|
+
*/
|
|
168
242
|
scale(s) {
|
|
169
243
|
this.options.scale = s;
|
|
170
244
|
this.buildImpulse();
|
|
171
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* set IR source noise generator.
|
|
248
|
+
*
|
|
249
|
+
* @param a - Algorithm
|
|
250
|
+
*/
|
|
172
251
|
randomAlgorithm(a) {
|
|
173
252
|
this.options.randomAlgorithm = a;
|
|
174
253
|
this.buildImpulse();
|
|
175
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Inpulse Response Noise algorithm.
|
|
257
|
+
*
|
|
258
|
+
* @param type - IR noise algorithm type.
|
|
259
|
+
*/
|
|
176
260
|
setNoise(type) {
|
|
177
261
|
this.options.noise = type;
|
|
178
262
|
switch (type) {
|
|
179
|
-
case Noise
|
|
263
|
+
case Noise["BLUE"]:
|
|
180
264
|
this.noise = blue;
|
|
181
265
|
break;
|
|
182
|
-
case Noise
|
|
266
|
+
case Noise["GREEN"]:
|
|
183
267
|
this.noise = green;
|
|
184
268
|
break;
|
|
185
|
-
case Noise
|
|
269
|
+
case Noise["PINK"]:
|
|
186
270
|
this.noise = pink;
|
|
187
271
|
break;
|
|
188
|
-
case Noise
|
|
189
|
-
case Noise
|
|
272
|
+
case Noise["RED"]:
|
|
273
|
+
case Noise["BROWN"]:
|
|
190
274
|
this.noise = red;
|
|
191
275
|
break;
|
|
192
|
-
case Noise
|
|
276
|
+
case Noise["VIOLET"]:
|
|
193
277
|
this.noise = violet;
|
|
194
278
|
break;
|
|
195
279
|
default:
|
|
@@ -197,13 +281,26 @@ class Reverb {
|
|
|
197
281
|
}
|
|
198
282
|
this.buildImpulse();
|
|
199
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Set Random Algorythm
|
|
286
|
+
*
|
|
287
|
+
* @param algorithm - Algorythm
|
|
288
|
+
*/
|
|
200
289
|
setRandomAlgorythm(algorithm) {
|
|
201
290
|
this.options.randomAlgorithm = algorithm;
|
|
202
291
|
this.buildImpulse();
|
|
203
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Return true if in range, otherwise false
|
|
295
|
+
*
|
|
296
|
+
* @param x - Target value
|
|
297
|
+
* @param min - Minimum value
|
|
298
|
+
* @param max - Maximum value
|
|
299
|
+
*/
|
|
204
300
|
inRange(x, min, max) {
|
|
205
301
|
return (x - min) * (x - max) <= 0;
|
|
206
302
|
}
|
|
303
|
+
/** Utility function for building an impulse response from the module parameters. */
|
|
207
304
|
buildImpulse() {
|
|
208
305
|
const rate = this.ctx.sampleRate;
|
|
209
306
|
const duration = Math.max(rate * this.options.time, 1);
|
|
@@ -229,6 +326,11 @@ class Reverb {
|
|
|
229
326
|
impulse.getChannelData(1).set(impulseR);
|
|
230
327
|
this.convolverNode.buffer = impulse;
|
|
231
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Noise source
|
|
331
|
+
*
|
|
332
|
+
* @param duration - length of IR.
|
|
333
|
+
*/
|
|
232
334
|
getNoise(duration) {
|
|
233
335
|
return [
|
|
234
336
|
...take(
|