@logue/reverb 0.5.5 → 1.0.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/README.md CHANGED
@@ -19,15 +19,32 @@ This script is originally a spin out of [sf2synth.js](https://github.com/logue/s
19
19
 
20
20
  ```js
21
21
  const reverb = new Reverb(ctx, {
22
- noise: 0, // Inpulse Response Noise algorithm (0: White noise, 1: Pink noise, 2: Brown noise)
23
- decay: 5, // Amount of IR (Inpulse Response) decay. 0~100
24
- delay: 0, // Delay time o IR. (NOT delay effect) 0~100 [sec]
25
- filterFreq: 2200, // Filter frequency. 20~5000 [Hz]
26
- filterQ: 1, // Filter quality. 0~10
27
- filterType: 'lowpass', // Filter type. 'bandpass' etc. See https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode/type .
28
- mix: 0.5, // Dry (Original Sound) and Wet (Effected sound) raito. 0~1
29
- reverse: false, // Reverse IR.
30
- time: 3, // Time length of IR. 0~50 [sec]
22
+ /**
23
+ * IR (Inpulse Response) colord noise algorithm (BLUE, GREEN, PINK, RED, VIOLET, WHITE)
24
+ * @see {@link https://en.wikipedia.org/wiki/Colors_of_noise}
25
+ */
26
+ noise: Noise.WHITE,
27
+ /** IR noise power multiplier */
28
+ power: 2,
29
+ /** Amount of IR decay. 0~100 */
30
+ decay: 5,
31
+ /** Delay time o IR. (NOT delay effect) 0~100 [sec] */
32
+ delay: 0,
33
+ /** Filter frequency. 20~5000 [Hz] */
34
+ filterFreq: 2200,
35
+ /** Filter Q. 0~10 */
36
+ filterQ: 1,
37
+ /**
38
+ * Filter type. 'bandpass' etc.
39
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode/type}
40
+ */
41
+ filterType: 'lowpass',
42
+ /** Dry (Original Sound) and Wet (Effected sound) raito. 0~1 */
43
+ mix: 0.5,
44
+ /** Reverse IR. */
45
+ reverse: false,
46
+ /** Time length of IR. 0~50 [sec] */
47
+ time: 3,
31
48
  });
32
49
  ```
33
50
 
@@ -1,12 +1,5 @@
1
1
  /** Impulse response noise generation algorithm */
2
- declare const Noise: {
3
- /** White noise */
4
- readonly WHITE: "white";
5
- /** Pink noise */
6
- readonly PINK: "pink";
7
- /** Brown Noise */
8
- readonly BROWN: "brown";
9
- };
2
+ declare const Noise: Record<string, string>;
10
3
  /** Noise Type */
11
4
  export declare type NoiseType = typeof Noise[keyof typeof Noise];
12
5
  /** Noise */
@@ -1 +1 @@
1
- {"version":3,"file":"NoiseType.d.ts","sourceRoot":"","sources":["../src/NoiseType.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,QAAA,MAAM,KAAK;IACT,kBAAkB;;IAElB,iBAAiB;;IAEjB,kBAAkB;;CAGV,CAAC;AAEX,iBAAiB;AACjB,oBAAY,SAAS,GAAG,OAAO,KAAK,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC;AAEzD,YAAY;AACZ,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"NoiseType.d.ts","sourceRoot":"","sources":["../src/NoiseType.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,QAAA,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAexB,CAAC;AAEX,iBAAiB;AACjB,oBAAY,SAAS,GAAG,OAAO,KAAK,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC;AAEzD,YAAY;AACZ,eAAe,KAAK,CAAC"}
package/dist/Reverb.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import type OptionInterface from './interfaces/OptionInterface';
2
2
  import { type NoiseType } from './NoiseType';
3
3
  /**
4
- * JS reverb effect class
4
+ * Reverb effect class
5
5
  */
6
6
  export default class Reverb {
7
7
  /** Version strings */
8
- readonly version: string;
8
+ static version: string;
9
9
  /** Build date */
10
- readonly build: string;
10
+ static build: string;
11
11
  /** AudioContext */
12
12
  private readonly ctx;
13
13
  /** Wet Level (Reverberated node) */
@@ -21,16 +21,18 @@ export default class Reverb {
21
21
  /** Output nodse */
22
22
  private readonly outputNode;
23
23
  /** Option */
24
- private readonly _options;
24
+ private readonly options;
25
25
  /** Connected flag */
26
26
  private isConnected;
27
+ /** Noise Generator */
28
+ private noise;
27
29
  /**
28
30
  * Constructor
29
31
  *
30
32
  * @param ctx - Root AudioContext
31
33
  * @param options - Configure
32
34
  */
33
- constructor(ctx: AudioContext, options: OptionInterface | undefined);
35
+ constructor(ctx: AudioContext, options?: OptionInterface);
34
36
  /**
35
37
  * Connect the node for the reverb effect to the original sound node.
36
38
  *
@@ -91,6 +93,12 @@ export default class Reverb {
91
93
  * @param q - Quality
92
94
  */
93
95
  filterQ(q: number): void;
96
+ /**
97
+ * set IR noise power multiplier.
98
+ *
99
+ * @param p - Power
100
+ */
101
+ power(p: number): void;
94
102
  /**
95
103
  * Inpulse Response Noise algorithm.
96
104
  *
@@ -107,7 +115,11 @@ export default class Reverb {
107
115
  private inRange;
108
116
  /** Utility function for building an impulse response from the module parameters. */
109
117
  private buildImpulse;
110
- /** Generate white noise */
111
- private static whiteNoise;
118
+ /**
119
+ * Noise source
120
+ *
121
+ * @param duration - length of IR.
122
+ */
123
+ private getNoise;
112
124
  }
113
125
  //# sourceMappingURL=Reverb.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAChE,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iBAAiB;IACjB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,8BAA8B;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,aAAa;IACb,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,qBAAqB;IACrB,OAAO,CAAC,WAAW,CAAU;IAE7B;;;;;OAKG;gBACS,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,GAAG,SAAS;IAsBnE;;;;OAIG;IACI,OAAO,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS;IAsBhD;;;;OAIG;IACI,UAAU,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS;IAe3E;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAU7B;;;;OAIG;IACI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWhC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAQtC;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAK/C;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWrC;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAW/B;;;;OAIG;IACI,QAAQ,CAAC,IAAI,EAAE,SAAS;IAM/B;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAIf,oFAAoF;IACpF,OAAO,CAAC,YAAY;IAoGpB,2BAA2B;IAC3B,OAAO,CAAC,MAAM,CAAC,UAAU;CAI1B"}
1
+ {"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAChE,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAIpD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,sBAAsB;IACtB,MAAM,CAAC,OAAO,EAAE,MAAM,CAAgB;IACtC,iBAAiB;IACjB,MAAM,CAAC,KAAK,EAAE,MAAM,CAAa;IACjC,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,8BAA8B;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,aAAa;IACb,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,qBAAqB;IACrB,OAAO,CAAC,WAAW,CAAU;IAC7B,sBAAsB;IACtB,OAAO,CAAC,KAAK,CAAmB;IAEhC;;;;;OAKG;gBACS,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,eAAe;IAoBxD;;;;OAIG;IACI,OAAO,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS;IAsBhD;;;;OAIG;IACI,UAAU,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS;IAe3E;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAU7B;;;;OAIG;IACI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAahC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAajC;;;;OAIG;IACI,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAQtC;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAK/C;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWrC;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAW/B;;;;OAIG;IACI,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAM7B;;;;OAIG;IACI,QAAQ,CAAC,IAAI,EAAE,SAAS;IA2B/B;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAIf,oFAAoF;IACpF,OAAO,CAAC,YAAY;IA6CpB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;CAKjB"}
@@ -0,0 +1,247 @@
1
+ /**
2
+ * @logue/reverb
3
+ *
4
+ * @description JavaScript Reverb effect class
5
+ * @author Logue <logue@hotmail.co.jp>
6
+ * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
+ * @license MIT
8
+ * @version 1.0.2
9
+ * @see {@link https://github.com/logue/Reverb.js}
10
+ */
11
+
12
+ const g = {
13
+ version: "1.0.2",
14
+ date: "2022-09-09T10:45:33.869Z"
15
+ }, l = {
16
+ BLUE: "blue",
17
+ GREEN: "green",
18
+ PINK: "pink",
19
+ RED: "red",
20
+ VIOLET: "violet",
21
+ WHITE: "white",
22
+ 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
+ }
31
+ }
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));
35
+ }
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;
43
+ }
44
+ n.length && (yield* n);
45
+ }
46
+ yield* N(s([]));
47
+ }
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
+ };
55
+ }
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
+ }
70
+ }
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
+ }
82
+ }
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
+ }
97
+ }
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;
105
+ }
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
+ }
117
+ }
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;
123
+ }
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);
128
+ }
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);
132
+ }
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);
135
+ }
136
+ disconnect(e) {
137
+ return this.isConnected && (this.convolverNode.disconnect(this.filterNode), this.filterNode.disconnect(this.wetGainNode)), this.isConnected = !1, e;
138
+ }
139
+ mix(e) {
140
+ if (!this.inRange(e, 0, 1))
141
+ 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;
143
+ }
144
+ time(e) {
145
+ if (!this.inRange(e, 1, 50))
146
+ throw new RangeError(
147
+ "[Reverb.js] Time length of inpulse response must be less than 50sec."
148
+ );
149
+ this.options.time = e, this.buildImpulse();
150
+ }
151
+ decay(e) {
152
+ if (!this.inRange(e, 0, 100))
153
+ throw new RangeError(
154
+ "[Reverb.js] Inpulse Response decay level must be less than 100."
155
+ );
156
+ this.options.decay = e, this.buildImpulse();
157
+ }
158
+ delay(e) {
159
+ if (!this.inRange(e, 0, 100))
160
+ throw new RangeError(
161
+ "[Reverb.js] Inpulse Response delay time must be less than 100."
162
+ );
163
+ this.options.delay = e, this.buildImpulse();
164
+ }
165
+ reverse(e) {
166
+ this.options.reverse = e, this.buildImpulse();
167
+ }
168
+ filterType(e) {
169
+ this.filterNode.type = this.options.filterType = e;
170
+ }
171
+ filterFreq(e) {
172
+ if (!this.inRange(e, 20, 2e4))
173
+ throw new RangeError(
174
+ "[Reverb.js] Filter frequrncy must be between 20 and 20000."
175
+ );
176
+ this.options.filterFreq = e, this.filterNode.frequency.value = this.options.filterFreq;
177
+ }
178
+ filterQ(e) {
179
+ if (!this.inRange(e, 0, 10))
180
+ throw new RangeError(
181
+ "[Reverb.js] Filter quality value must be between 0 and 10."
182
+ );
183
+ this.options.filterQ = e, this.filterNode.Q.value = this.options.filterQ;
184
+ }
185
+ power(e) {
186
+ this.options.power = e, this.buildImpulse();
187
+ }
188
+ setNoise(e) {
189
+ switch (this.options.noise = e, e) {
190
+ case l.BLUE:
191
+ this.noise = p;
192
+ break;
193
+ case l.GREEN:
194
+ this.noise = Q;
195
+ break;
196
+ case l.PINK:
197
+ this.noise = M;
198
+ break;
199
+ case l.RED:
200
+ case l.BROWN:
201
+ this.noise = m;
202
+ break;
203
+ case l.VIOLET:
204
+ this.noise = O;
205
+ break;
206
+ default:
207
+ this.noise = R;
208
+ break;
209
+ }
210
+ this.buildImpulse();
211
+ }
212
+ inRange(e, i, s) {
213
+ return (e - i) * (e - s) <= 0;
214
+ }
215
+ 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;
220
+ }
221
+ o.getChannelData(0).set(r), o.getChannelData(1).set(n), this.convolverNode.buffer = o;
222
+ }
223
+ getNoise(e) {
224
+ return [...E(e, this.noise())].map(
225
+ (i) => i * this.options.power
226
+ );
227
+ }
228
+ }
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
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @logue/reverb
3
+ *
4
+ * @description JavaScript Reverb effect class
5
+ * @author Logue <logue@hotmail.co.jp>
6
+ * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
+ * @license MIT
8
+ * @version 1.0.2
9
+ * @see {@link https://github.com/logue/Reverb.js}
10
+ */
11
+
12
+ var Reverb=function(){"use strict";const N={version:"1.0.2",date:"2022-09-09T10:45:33.869Z"},l={BLUE:"blue",GREEN:"green",PINK:"pink",RED:"red",VIOLET:"violet",WHITE:"white",BROWN:"red"},G=(t,e)=>t!=null&&typeof t[e]=="function",T=t=>G(t,"xform")?t.xform():t,F=t=>t!=null&&typeof t[Symbol.iterator]=="function";class u{constructor(e){this.value=e}deref(){return this.value}}const k=t=>new u(t),x=t=>t instanceof u,C=t=>t instanceof u?t:new u(t),R=t=>t instanceof u?t.deref():t,D=(t,e)=>[t,i=>i,e];function j(t){return t?[...t]:D(()=>[],(e,i)=>(e.push(i),e))}function*q(t,e){const i=T(t)(j()),s=i[1],o=i[2];for(let r of e){const n=o([],r);if(x(n)){yield*R(s(n.deref()));return}n.length&&(yield*n)}yield*R(s([]))}const B=(t,e)=>[t[0],t[1],e];function w(t,e){return F(e)?q(w(t),e):i=>{const s=i[2];let o=t;return B(i,(r,n)=>--o>0?s(r,n):o===0?C(s(r,n)):k(r))}}const g=1/2**32;class L{float(e=1){return this.int()*g*e}norm(e=1){return(this.int()*g-.5)*2*e}minmax(e,i){return this.float()*(i-e)+e}minmaxInt(e,i){return e|=0,i|=0,e+(this.float()*(i-e)|0)}}const p=Math.random;class S extends L{int(){return p()*4294967296>>>0}float(e=1){return p()*e}norm(e=1){return(p()-.5)*2*e}}const h=new S,m=(t,e,i)=>{const s=new Array(t);for(let o=0;o<t;o++)s[o]=i.norm(e);return s},v=t=>t.reduce((e,i)=>e+i,0);function*E(t,e){const i=[t[Symbol.iterator](),e[Symbol.iterator]()];for(let s=0;;s^=1){const o=i[s].next();if(o.done)return;yield o.value}}function*b(t=2,e=1,i=h){const s=m(t,e,i);s.forEach((n,a)=>s[a]=a&1?n:-n);const o=1/t;let r=v(s);for(let n=0,a=-1;;++n>=t&&(n=0))r-=s[n],r+=s[n]=a*i.norm(e),a^=4294967294,yield a*r*o}const A=(t=2,e=1,i=h)=>E(b(t,e,i),b(t,e,i)),Q=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*W(t=8,e=1,i=h){const s=m(t,e,i),o=1/t;let r=v(s);for(let n=0;;n=n+1>>>0){const a=Q(n)%t;r-=s[a],r+=s[a]=i.norm(e),yield r*o}}function*y(t=2,e=1,i=h){const s=m(t,e,i),o=1/t;let r=v(s);for(let n=0;;++n>=t&&(n=0))r-=s[n],r+=s[n]=i.norm(e),yield r*o}const M=(t=2,e=1,i=h)=>E(y(t,e,i),y(t,e,i));function*I(t=1,e=h){for(;;)yield e.norm(t)}class d{constructor(e,i){this.noise=I,this.ctx=e,this.options={...O,...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)}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(!this.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(!this.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(!this.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(!this.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){this.filterNode.type=this.options.filterType=e}filterFreq(e){if(!this.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(!this.inRange(e,0,10))throw new RangeError("[Reverb.js] Filter quality value must be between 0 and 10.");this.options.filterQ=e,this.filterNode.Q.value=this.options.filterQ}power(e){this.options.power=e,this.buildImpulse()}setNoise(e){switch(this.options.noise=e,e){case l.BLUE:this.noise=b;break;case l.GREEN:this.noise=A;break;case l.PINK:this.noise=W;break;case l.RED:case l.BROWN:this.noise=y;break;case l.VIOLET:this.noise=M;break;default:this.noise=I;break}this.buildImpulse()}inRange(e,i,s){return(e-i)*(e-s)<=0}buildImpulse(){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),V=this.getNoise(i);for(let c=0;c<i;c++){let f=0;c<s?(r[c]=0,n[c]=0,f=this.options.reverse?i-(c-s):c-s):f=this.options.reverse?i-c:c,r[c]=a[c]*(1-f/i)**this.options.decay,n[c]=V[c]*(1-f/i)**this.options.decay}o.getChannelData(0).set(r),o.getChannelData(1).set(n),this.convolverNode.buffer=o}getNoise(e){return[...w(e,this.noise())].map(i=>i*this.options.power)}}d.version=N.version,d.build=N.date;const O={noise:l.WHITE,power:2,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return window.Reverb||(window.Reverb=d),d}();
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @logue/reverb
3
+ *
4
+ * @description JavaScript Reverb effect class
5
+ * @author Logue <logue@hotmail.co.jp>
6
+ * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
+ * @license MIT
8
+ * @version 1.0.2
9
+ * @see {@link https://github.com/logue/Reverb.js}
10
+ */
11
+
12
+ (function(h,l){typeof exports=="object"&&typeof module<"u"?module.exports=l():typeof define=="function"&&define.amd?define(l):(h=typeof globalThis<"u"?globalThis:h||self,h.Reverb=l())})(this,function(){"use strict";const h={version:"1.0.2",date:"2022-09-09T10:45:33.869Z"},l={BLUE:"blue",GREEN:"green",PINK:"pink",RED:"red",VIOLET:"violet",WHITE:"white",BROWN:"red"},G=(t,e)=>t!=null&&typeof t[e]=="function",T=t=>G(t,"xform")?t.xform():t,x=t=>t!=null&&typeof t[Symbol.iterator]=="function";class d{constructor(e){this.value=e}deref(){return this.value}}const F=t=>new d(t),k=t=>t instanceof d,C=t=>t instanceof d?t:new d(t),R=t=>t instanceof d?t.deref():t,j=(t,e)=>[t,i=>i,e];function D(t){return t?[...t]:j(()=>[],(e,i)=>(e.push(i),e))}function*q(t,e){const i=T(t)(D()),s=i[1],o=i[2];for(let r of e){const n=o([],r);if(k(n)){yield*R(s(n.deref()));return}n.length&&(yield*n)}yield*R(s([]))}const B=(t,e)=>[t[0],t[1],e];function w(t,e){return x(e)?q(w(t),e):i=>{const s=i[2];let o=t;return B(i,(r,n)=>--o>0?s(r,n):o===0?C(s(r,n)):F(r))}}const g=1/2**32;class L{float(e=1){return this.int()*g*e}norm(e=1){return(this.int()*g-.5)*2*e}minmax(e,i){return this.float()*(i-e)+e}minmaxInt(e,i){return e|=0,i|=0,e+(this.float()*(i-e)|0)}}const m=Math.random;class S extends L{int(){return m()*4294967296>>>0}float(e=1){return m()*e}norm(e=1){return(m()-.5)*2*e}}const u=new S,b=(t,e,i)=>{const s=new Array(t);for(let o=0;o<t;o++)s[o]=i.norm(e);return s},v=t=>t.reduce((e,i)=>e+i,0);function*E(t,e){const i=[t[Symbol.iterator](),e[Symbol.iterator]()];for(let s=0;;s^=1){const o=i[s].next();if(o.done)return;yield o.value}}function*y(t=2,e=1,i=u){const s=b(t,e,i);s.forEach((n,a)=>s[a]=a&1?n:-n);const o=1/t;let r=v(s);for(let n=0,a=-1;;++n>=t&&(n=0))r-=s[n],r+=s[n]=a*i.norm(e),a^=4294967294,yield a*r*o}const A=(t=2,e=1,i=u)=>E(y(t,e,i),y(t,e,i)),Q=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*W(t=8,e=1,i=u){const s=b(t,e,i),o=1/t;let r=v(s);for(let n=0;;n=n+1>>>0){const a=Q(n)%t;r-=s[a],r+=s[a]=i.norm(e),yield r*o}}function*N(t=2,e=1,i=u){const s=b(t,e,i),o=1/t;let r=v(s);for(let n=0;;++n>=t&&(n=0))r-=s[n],r+=s[n]=i.norm(e),yield r*o}const M=(t=2,e=1,i=u)=>E(N(t,e,i),N(t,e,i));function*I(t=1,e=u){for(;;)yield e.norm(t)}class f{constructor(e,i){this.noise=I,this.ctx=e,this.options={...O,...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)}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(!this.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(!this.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(!this.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(!this.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){this.filterNode.type=this.options.filterType=e}filterFreq(e){if(!this.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(!this.inRange(e,0,10))throw new RangeError("[Reverb.js] Filter quality value must be between 0 and 10.");this.options.filterQ=e,this.filterNode.Q.value=this.options.filterQ}power(e){this.options.power=e,this.buildImpulse()}setNoise(e){switch(this.options.noise=e,e){case l.BLUE:this.noise=y;break;case l.GREEN:this.noise=A;break;case l.PINK:this.noise=W;break;case l.RED:case l.BROWN:this.noise=N;break;case l.VIOLET:this.noise=M;break;default:this.noise=I;break}this.buildImpulse()}inRange(e,i,s){return(e-i)*(e-s)<=0}buildImpulse(){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),V=this.getNoise(i);for(let c=0;c<i;c++){let p=0;c<s?(r[c]=0,n[c]=0,p=this.options.reverse?i-(c-s):c-s):p=this.options.reverse?i-c:c,r[c]=a[c]*(1-p/i)**this.options.decay,n[c]=V[c]*(1-p/i)**this.options.decay}o.getChannelData(0).set(r),o.getChannelData(1).set(n),this.convolverNode.buffer=o}getNoise(e){return[...w(e,this.noise())].map(i=>i*this.options.power)}}f.version=h.version,f.build=h.date;const O={noise:l.WHITE,power:2,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return window.Reverb||(window.Reverb=f),f});
@@ -3,6 +3,8 @@ import { NoiseType } from '../NoiseType';
3
3
  export default interface OptionInterface {
4
4
  /** Types of impulse response noise generation algorithms */
5
5
  noise: NoiseType;
6
+ /** IR Power */
7
+ power: number;
6
8
  /** Decay */
7
9
  decay: number;
8
10
  /** Delay until impulse response is generated */
@@ -1 +1 @@
1
- {"version":3,"file":"OptionInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/OptionInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,oBAAoB;AACpB,MAAM,CAAC,OAAO,WAAW,eAAe;IACtC,4DAA4D;IAC5D,KAAK,EAAE,SAAS,CAAC;IACjB,YAAY;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,EAAE,OAAO,CAAC;CACf"}
1
+ {"version":3,"file":"OptionInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/OptionInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,oBAAoB;AACpB,MAAM,CAAC,OAAO,WAAW,eAAe;IACtC,4DAA4D;IAC5D,KAAK,EAAE,SAAS,CAAC;IACjB,eAAe;IACf,KAAK,EAAE,MAAM,CAAC;IACd,YAAY;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,EAAE,OAAO,CAAC;CACf"}
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": "0.5.5",
4
+ "version": "1.0.2",
5
5
  "description": "JavaScript Reverb effect class",
6
6
  "keywords": [
7
7
  "webaudio",
@@ -10,6 +10,7 @@
10
10
  "reverb"
11
11
  ],
12
12
  "license": "MIT",
13
+ "type": "module",
13
14
  "author": {
14
15
  "name": "Logue",
15
16
  "email": "logue@hotmail.co.jp",
@@ -23,26 +24,23 @@
23
24
  "bugs": {
24
25
  "url": "https://github.com/logue/Reverb.js/issues"
25
26
  },
26
- "directories": {
27
- "doc": "docs"
28
- },
29
27
  "files": [
30
28
  "dist"
31
29
  ],
32
- "main": "./dist/reverb.umd.js",
33
- "module": "./dist/reverb.es.js",
30
+ "main": "dist/Reverb.umd.js",
31
+ "module": "dist/Reverb.es.js",
32
+ "types": "dist/Reverb.d.ts",
34
33
  "exports": {
35
34
  ".": {
36
- "import": "./dist/reverb.es.js",
37
- "require": "./dist/reverb.umd.js"
35
+ "import": "./dist/Reverb.es.js",
36
+ "require": "./dist/Reverb.umd.js"
38
37
  }
39
38
  },
40
- "types": "./dist/Reverb.d.ts",
41
39
  "engines": {
42
- "node": ">=16.16.0",
43
- "yarn": ">=1.22.4"
40
+ "node": ">=16.17.0",
41
+ "yarn": ">=1.22.10"
44
42
  },
45
- "packageManager": "yarn@3.2.1",
43
+ "packageManager": "yarn@3.2.3",
46
44
  "sideEffects": false,
47
45
  "scripts": {
48
46
  "dev": "vite",
@@ -51,27 +49,31 @@
51
49
  "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
52
50
  "prepare": "husky install"
53
51
  },
52
+ "dependencies": {
53
+ "@thi.ng/colored-noise": "^0.3.16",
54
+ "@thi.ng/transducers": "^8.3.13"
55
+ },
54
56
  "devDependencies": {
55
- "@types/node": "^18.0.6",
56
- "@typescript-eslint/eslint-plugin": "^5.30.7",
57
- "@typescript-eslint/parser": "^5.30.7",
58
- "eslint": "^8.20.0",
57
+ "@types/node": "^18.7.16",
58
+ "@typescript-eslint/eslint-plugin": "^5.36.2",
59
+ "@typescript-eslint/parser": "^5.36.2",
60
+ "eslint": "^8.23.0",
59
61
  "eslint-config-google": "^0.14.0",
60
62
  "eslint-config-prettier": "^8.5.0",
61
63
  "eslint-import-resolver-alias": "^1.1.2",
62
- "eslint-import-resolver-typescript": "^3.3.0",
64
+ "eslint-import-resolver-typescript": "^3.5.1",
63
65
  "eslint-plugin-import": "^2.26.0",
64
- "eslint-plugin-jsdoc": "^39.3.3",
66
+ "eslint-plugin-jsdoc": "^39.3.6",
65
67
  "eslint-plugin-prettier": "^4.2.1",
66
68
  "eslint-plugin-tsdoc": "^0.2.16",
67
69
  "husky": "^8.0.1",
68
70
  "lint-staged": "^13.0.3",
69
71
  "prettier": "^2.7.1",
70
72
  "rimraf": "^3.0.2",
71
- "typescript": "^4.7.4",
72
- "vite": "^3.0.2",
73
- "vite-plugin-banner": "^0.3.0",
74
- "vite-plugin-checker": "^0.4.9"
73
+ "typescript": "^4.8.3",
74
+ "vite": "^3.1.0",
75
+ "vite-plugin-banner": "^0.5.0",
76
+ "vite-plugin-checker": "^0.5.1"
75
77
  },
76
78
  "husky": {
77
79
  "hooks": {
package/dist/reverb.es.js DELETED
@@ -1,111 +0,0 @@
1
- /**
2
- * @logue/reverb
3
- *
4
- * @description JavaScript Reverb effect class
5
- * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
- * @license MIT
8
- * @version 0.5.5
9
- * @see {@link https://github.com/logue/Reverb.js}
10
- */
11
-
12
- const d = {
13
- version: "0.5.5",
14
- date: "2022-07-21T01:15:40.735Z"
15
- }, l = {
16
- WHITE: "white",
17
- PINK: "pink",
18
- BROWN: "brown"
19
- };
20
- class s {
21
- constructor(e, o) {
22
- this.version = d.version, this.build = d.date, this.ctx = e, this._options = { ...u, ...o }, 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.buildImpulse(), this.mix(this._options.mix);
23
- }
24
- connect(e) {
25
- 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);
26
- }
27
- disconnect(e) {
28
- return this.isConnected && (this.convolverNode.disconnect(this.filterNode), this.filterNode.disconnect(this.wetGainNode)), this.isConnected = !1, e;
29
- }
30
- mix(e) {
31
- if (!this.inRange(e, 0, 1))
32
- throw new RangeError("Reverb.js: Dry/Wet ratio must be between 0 to 1.");
33
- this._options.mix = e, this.dryGainNode.gain.value = 1 - this._options.mix, this.wetGainNode.gain.value = this._options.mix;
34
- }
35
- time(e) {
36
- if (!this.inRange(e, 1, 50))
37
- throw new RangeError("Reverb.js: Time length of inpulse response must be less than 50sec.");
38
- this._options.time = e, this.buildImpulse();
39
- }
40
- decay(e) {
41
- if (!this.inRange(e, 0, 100))
42
- throw new RangeError("Reverb.js: Inpulse Response decay level must be less than 100.");
43
- this._options.decay = e, this.buildImpulse();
44
- }
45
- delay(e) {
46
- if (!this.inRange(e, 0, 100))
47
- throw new RangeError("Reverb.js: Inpulse Response delay time must be less than 100.");
48
- this._options.delay = e, this.buildImpulse();
49
- }
50
- reverse(e) {
51
- this._options.reverse = e, this.buildImpulse();
52
- }
53
- filterType(e) {
54
- this.filterNode.type = this._options.filterType = e;
55
- }
56
- filterFreq(e) {
57
- if (!this.inRange(e, 20, 5e3))
58
- throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");
59
- this._options.filterFreq = e, this.filterNode.frequency.value = this._options.filterFreq;
60
- }
61
- filterQ(e) {
62
- if (!this.inRange(e, 0, 10))
63
- throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");
64
- this._options.filterQ = e, this.filterNode.Q.value = this._options.filterQ;
65
- }
66
- setNoise(e) {
67
- this._options.noise = e, this.buildImpulse();
68
- }
69
- inRange(e, o, r) {
70
- return (e - o) * (e - r) <= 0;
71
- }
72
- buildImpulse() {
73
- const e = this.ctx.sampleRate, o = Math.max(e * this._options.time, 1), r = e * this._options.delay, c = this.ctx.createBuffer(2, o, e), n = new Float32Array(o), h = new Float32Array(o), t = [0, 0, 0, 0, 0, 0, 0];
74
- for (let i = 0; i < o; i++) {
75
- let a = 0;
76
- switch (i < r ? (n[i] = 0, h[i] = 0, a = this._options.reverse ? o - (i - r) : i - r) : a = this._options.reverse ? o - i : i, this._options.noise) {
77
- case l.PINK:
78
- t[0] = 0.99886 * t[0] + s.whiteNoise() * 0.0555179, t[1] = 0.99332 * t[1] + s.whiteNoise() * 0.0750759, t[2] = 0.969 * t[2] + s.whiteNoise() * 0.153852, t[3] = 0.8665 * t[3] + s.whiteNoise() * 0.3104856, t[4] = 0.55 * t[4] + s.whiteNoise() * 0.5329522, t[5] = -0.7616 * t[5] - s.whiteNoise() * 0.016898, n[i] = t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + t[6] + s.whiteNoise() * 0.5362, h[i] = t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + t[6] + s.whiteNoise() * 0.5362, n[i] *= 0.11, h[i] *= 0.11, t[6] = s.whiteNoise() * 0.115926;
79
- break;
80
- case l.BROWN:
81
- n[i] = (t[0] + 0.02 * s.whiteNoise()) / 1.02, t[0] = n[i], h[i] = (t[1] + 0.02 * s.whiteNoise()) / 1.02, t[1] = h[i], n[i] *= 3.5, h[i] *= 3.5;
82
- break;
83
- case l.WHITE:
84
- default:
85
- n[i] = s.whiteNoise(), h[i] = s.whiteNoise();
86
- break;
87
- }
88
- n[i] *= (1 - a / o) ** this._options.decay, h[i] *= (1 - a / o) ** this._options.decay;
89
- }
90
- c.getChannelData(0).set(n), c.getChannelData(1).set(h), this.convolverNode.buffer = c;
91
- }
92
- static whiteNoise() {
93
- return Math.random() * 2 - 1;
94
- }
95
- }
96
- const u = {
97
- noise: l.WHITE,
98
- decay: 2,
99
- delay: 0,
100
- reverse: !1,
101
- time: 2,
102
- filterType: "lowpass",
103
- filterFreq: 2200,
104
- filterQ: 1,
105
- mix: 0.5,
106
- once: !1
107
- };
108
- window.Reverb || (window.Reverb = s);
109
- export {
110
- s as default
111
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * @logue/reverb
3
- *
4
- * @description JavaScript Reverb effect class
5
- * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
- * @license MIT
8
- * @version 0.5.5
9
- * @see {@link https://github.com/logue/Reverb.js}
10
- */
11
-
12
- (function(a,r){typeof exports=="object"&&typeof module<"u"?module.exports=r():typeof define=="function"&&define.amd?define(r):(a=typeof globalThis<"u"?globalThis:a||self,a.Reverb=r())})(this,function(){"use strict";const a={version:"0.5.5",date:"2022-07-21T01:15:40.735Z"},r={WHITE:"white",PINK:"pink",BROWN:"brown"};class s{constructor(e,o){this.version=a.version,this.build=a.date,this.ctx=e,this._options={...u,...o},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.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(!this.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(!this.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(!this.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(!this.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){this.filterNode.type=this._options.filterType=e}filterFreq(e){if(!this.inRange(e,20,5e3))throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");this._options.filterFreq=e,this.filterNode.frequency.value=this._options.filterFreq}filterQ(e){if(!this.inRange(e,0,10))throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");this._options.filterQ=e,this.filterNode.Q.value=this._options.filterQ}setNoise(e){this._options.noise=e,this.buildImpulse()}inRange(e,o,l){return(e-o)*(e-l)<=0}buildImpulse(){const e=this.ctx.sampleRate,o=Math.max(e*this._options.time,1),l=e*this._options.delay,d=this.ctx.createBuffer(2,o,e),n=new Float32Array(o),h=new Float32Array(o),t=[0,0,0,0,0,0,0];for(let i=0;i<o;i++){let c=0;switch(i<l?(n[i]=0,h[i]=0,c=this._options.reverse?o-(i-l):i-l):c=this._options.reverse?o-i:i,this._options.noise){case r.PINK:t[0]=.99886*t[0]+s.whiteNoise()*.0555179,t[1]=.99332*t[1]+s.whiteNoise()*.0750759,t[2]=.969*t[2]+s.whiteNoise()*.153852,t[3]=.8665*t[3]+s.whiteNoise()*.3104856,t[4]=.55*t[4]+s.whiteNoise()*.5329522,t[5]=-.7616*t[5]-s.whiteNoise()*.016898,n[i]=t[0]+t[1]+t[2]+t[3]+t[4]+t[5]+t[6]+s.whiteNoise()*.5362,h[i]=t[0]+t[1]+t[2]+t[3]+t[4]+t[5]+t[6]+s.whiteNoise()*.5362,n[i]*=.11,h[i]*=.11,t[6]=s.whiteNoise()*.115926;break;case r.BROWN:n[i]=(t[0]+.02*s.whiteNoise())/1.02,t[0]=n[i],h[i]=(t[1]+.02*s.whiteNoise())/1.02,t[1]=h[i],n[i]*=3.5,h[i]*=3.5;break;case r.WHITE:default:n[i]=s.whiteNoise(),h[i]=s.whiteNoise();break}n[i]*=(1-c/o)**this._options.decay,h[i]*=(1-c/o)**this._options.decay}d.getChannelData(0).set(n),d.getChannelData(1).set(h),this.convolverNode.buffer=d}static whiteNoise(){return Math.random()*2-1}}const u={noise:r.WHITE,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return window.Reverb||(window.Reverb=s),s});