@logue/reverb 0.5.3 → 1.0.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Reverb.js
2
2
 
3
3
  [![jsdelivr CDN](https://data.jsdelivr.com/v1/package/npm/@logue/reverb/badge)](https://www.jsdelivr.com/package/npm/@logue/reverb)
4
- [![NPM Downloads](https://img.shields.io/npm/dm/vuetify-swatches.svg?style=flat)](https://www.npmjs.com/package/@logue/reverb)
4
+ [![NPM Downloads](https://img.shields.io/npm/dm/@logue/reverb.svg?style=flat)](https://www.npmjs.com/package/@logue/reverb)
5
5
  [![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@logue/reverb/file/README.md)
6
6
  [![npm version](https://img.shields.io/npm/v/@logue/reverb.svg)](https://www.npmjs.com/package/@logue/reverb)
7
7
  [![Open in Gitpod](https://shields.io/badge/Open%20in-Gitpod-green?logo=Gitpod)](https://gitpod.io/#https://github.com/logue/Reverb.js)
@@ -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,CAOxB,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,18 +1,13 @@
1
1
  import type OptionInterface from './interfaces/OptionInterface';
2
2
  import { type NoiseType } from './NoiseType';
3
3
  /**
4
- * JS reverb effect class
5
- *
6
- * @license MIT
7
- * @author Logue {@link logue@hotmail.co.jp}
8
- * @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
9
- * @see {@link https://github.com/logue/Reverb.js}
4
+ * Reverb effect class
10
5
  */
11
6
  export default class Reverb {
12
7
  /** Version strings */
13
- readonly version: string;
8
+ static version: string;
14
9
  /** Build date */
15
- readonly build: string;
10
+ static build: string;
16
11
  /** AudioContext */
17
12
  private readonly ctx;
18
13
  /** Wet Level (Reverberated node) */
@@ -26,16 +21,18 @@ export default class Reverb {
26
21
  /** Output nodse */
27
22
  private readonly outputNode;
28
23
  /** Option */
29
- private readonly _options;
24
+ private readonly options;
30
25
  /** Connected flag */
31
26
  private isConnected;
27
+ /** Noise Generator */
28
+ private noise;
32
29
  /**
33
30
  * Constructor
34
31
  *
35
32
  * @param ctx - Root AudioContext
36
33
  * @param options - Configure
37
34
  */
38
- constructor(ctx: AudioContext, options: OptionInterface | undefined);
35
+ constructor(ctx: AudioContext, options?: OptionInterface);
39
36
  /**
40
37
  * Connect the node for the reverb effect to the original sound node.
41
38
  *
@@ -112,7 +109,5 @@ export default class Reverb {
112
109
  private inRange;
113
110
  /** Utility function for building an impulse response from the module parameters. */
114
111
  private buildImpulse;
115
- /** Generate white noise */
116
- private static whiteNoise;
117
112
  }
118
113
  //# 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;;;;;;;GAOG;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;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;IA2B/B;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAIf,oFAAoF;IACpF,OAAO,CAAC,YAAY;CAgDrB"}
@@ -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/dist/reverb.es.js CHANGED
@@ -1,188 +1,228 @@
1
- const meta = {
2
- version: "0.5.3",
3
- date: "2022-06-05T00:53:37.175Z"
4
- };
5
- const Noise = {
6
- WHITE: "white",
7
- PINK: "pink",
8
- BROWN: "brown"
9
- };
10
1
  /**
11
- * JS reverb effect class
2
+ * @logue/reverb
12
3
  *
4
+ * @description JavaScript Reverb effect class
5
+ * @author Logue <logue@hotmail.co.jp>
6
+ * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
13
7
  * @license MIT
14
- * @author Logue {@link logue@hotmail.co.jp}
15
- * @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
8
+ * @version 1.0.0
16
9
  * @see {@link https://github.com/logue/Reverb.js}
17
10
  */
18
- class Reverb {
19
- constructor(ctx, options) {
20
- this.version = meta.version;
21
- this.build = meta.date;
22
- this.ctx = ctx;
23
- this._options = { ...optionDefaults, ...options };
24
- this.wetGainNode = this.ctx.createGain();
25
- this.dryGainNode = this.ctx.createGain();
26
- this.filterNode = this.ctx.createBiquadFilter();
27
- this.convolverNode = this.ctx.createConvolver();
28
- this.outputNode = this.ctx.createGain();
29
- this.isConnected = false;
30
- this.buildImpulse();
31
- this.mix(this._options.mix);
11
+
12
+ const E = {
13
+ version: "1.0.0",
14
+ date: "2022-08-29T12:34:03.524Z"
15
+ }, l = {
16
+ BLUE: "blue",
17
+ GREEN: "green",
18
+ PINK: "pink",
19
+ RED: "red",
20
+ VIOLET: "violet",
21
+ WHITE: "white"
22
+ }, 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";
23
+ class u {
24
+ constructor(e) {
25
+ this.value = e;
32
26
  }
33
- connect(sourceNode) {
34
- if (this.isConnected && this._options.once) {
35
- this.isConnected = false;
36
- return this.outputNode;
37
- }
38
- this.convolverNode.connect(this.filterNode);
39
- this.filterNode.connect(this.wetGainNode);
40
- sourceNode.connect(this.convolverNode);
41
- sourceNode.connect(this.dryGainNode).connect(this.outputNode);
42
- sourceNode.connect(this.wetGainNode).connect(this.outputNode);
43
- this.isConnected = true;
44
- return this.outputNode;
45
- }
46
- disconnect(sourceNode) {
47
- if (this.isConnected) {
48
- this.convolverNode.disconnect(this.filterNode);
49
- this.filterNode.disconnect(this.wetGainNode);
27
+ deref() {
28
+ return this.value;
29
+ }
30
+ }
31
+ const k = (t) => new u(t), C = (t) => t instanceof u, D = (t) => t instanceof u ? t : new u(t), R = (t) => t instanceof u ? t.deref() : t, j = (t, e) => [t, (i) => i, e];
32
+ function q(t) {
33
+ return t ? [...t] : j(() => [], (e, i) => (e.push(i), e));
34
+ }
35
+ function* L(t, e) {
36
+ const i = x(t)(q()), s = i[1], r = i[2];
37
+ for (let o of e) {
38
+ const n = r([], o);
39
+ if (C(n)) {
40
+ yield* R(s(n.deref()));
41
+ return;
50
42
  }
51
- this.isConnected = false;
52
- return sourceNode;
43
+ n.length && (yield* n);
44
+ }
45
+ yield* R(s([]));
46
+ }
47
+ const S = (t, e) => [t[0], t[1], e];
48
+ function p(t, e) {
49
+ return F(e) ? L(p(t), e) : (i) => {
50
+ const s = i[2];
51
+ let r = t;
52
+ return S(i, (o, n) => --r > 0 ? s(o, n) : r === 0 ? D(s(o, n)) : k(o));
53
+ };
54
+ }
55
+ const N = 1 / 2 ** 32;
56
+ class A {
57
+ float(e = 1) {
58
+ return this.int() * N * e;
59
+ }
60
+ norm(e = 1) {
61
+ return (this.int() * N - 0.5) * 2 * e;
62
+ }
63
+ minmax(e, i) {
64
+ return this.float() * (i - e) + e;
65
+ }
66
+ minmaxInt(e, i) {
67
+ return e |= 0, i |= 0, e + (this.float() * (i - e) | 0);
68
+ }
69
+ }
70
+ const d = Math.random;
71
+ class B extends A {
72
+ int() {
73
+ return d() * 4294967296 >>> 0;
74
+ }
75
+ float(e = 1) {
76
+ return d() * e;
77
+ }
78
+ norm(e = 1) {
79
+ return (d() - 0.5) * 2 * e;
80
+ }
81
+ }
82
+ const h = new B(), y = (t, e, i) => {
83
+ const s = new Array(t);
84
+ for (let r = 0; r < t; r++)
85
+ s[r] = i.norm(e);
86
+ return s;
87
+ }, b = (t) => t.reduce((e, i) => e + i, 0);
88
+ function* I(t, e) {
89
+ const i = [t[Symbol.iterator](), e[Symbol.iterator]()];
90
+ for (let s = 0; ; s ^= 1) {
91
+ const r = i[s].next();
92
+ if (r.done)
93
+ return;
94
+ yield r.value;
95
+ }
96
+ }
97
+ function* m(t = 2, e = 1, i = h) {
98
+ const s = y(t, e, i);
99
+ s.forEach((n, a) => s[a] = a & 1 ? n : -n);
100
+ const r = 1 / t;
101
+ let o = b(s);
102
+ for (let n = 0, a = -1; ; ++n >= t && (n = 0))
103
+ o -= s[n], o += s[n] = a * i.norm(e), a ^= 4294967294, yield a * o * r;
104
+ }
105
+ const Q = (t = 2, e = 1, i = h) => I(m(t, e, i), m(t, e, i)), W = (t) => {
106
+ let e = 32;
107
+ 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;
108
+ };
109
+ function* M(t = 8, e = 1, i = h) {
110
+ const s = y(t, e, i), r = 1 / t;
111
+ let o = b(s);
112
+ for (let n = 0; ; n = n + 1 >>> 0) {
113
+ const a = W(n) % t;
114
+ o -= s[a], o += s[a] = i.norm(e), yield o * r;
53
115
  }
54
- mix(mix) {
55
- if (!this.inRange(mix, 0, 1)) {
116
+ }
117
+ function* v(t = 2, e = 1, i = h) {
118
+ const s = y(t, e, i), r = 1 / t;
119
+ let o = b(s);
120
+ for (let n = 0; ; ++n >= t && (n = 0))
121
+ o -= s[n], o += s[n] = i.norm(e), yield o * r;
122
+ }
123
+ const H = (t = 2, e = 1, i = h) => I(v(t, e, i), v(t, e, i));
124
+ function* g(t = 1, e = h) {
125
+ for (; ; )
126
+ yield e.norm(t);
127
+ }
128
+ class w {
129
+ constructor(e, i) {
130
+ this.noise = g, 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(l.WHITE), this.buildImpulse(), this.mix(this.options.mix);
131
+ }
132
+ connect(e) {
133
+ 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);
134
+ }
135
+ disconnect(e) {
136
+ return this.isConnected && (this.convolverNode.disconnect(this.filterNode), this.filterNode.disconnect(this.wetGainNode)), this.isConnected = !1, e;
137
+ }
138
+ mix(e) {
139
+ if (!this.inRange(e, 0, 1))
56
140
  throw new RangeError("Reverb.js: Dry/Wet ratio must be between 0 to 1.");
57
- }
58
- this._options.mix = mix;
59
- this.dryGainNode.gain.value = 1 - this._options.mix;
60
- this.wetGainNode.gain.value = this._options.mix;
61
- console.debug(`Reverb.js: Set dry/wet ratio to ${mix * 100}%`);
141
+ this.options.mix = e, this.dryGainNode.gain.value = 1 - this.options.mix, this.wetGainNode.gain.value = this.options.mix;
62
142
  }
63
- time(value) {
64
- if (!this.inRange(value, 1, 50)) {
143
+ time(e) {
144
+ if (!this.inRange(e, 1, 50))
65
145
  throw new RangeError("Reverb.js: Time length of inpulse response must be less than 50sec.");
66
- }
67
- this._options.time = value;
68
- this.buildImpulse();
69
- console.info(`Reverb.js: Set inpulse response time length to ${value}sec.`);
146
+ this.options.time = e, this.buildImpulse();
70
147
  }
71
- decay(value) {
72
- if (!this.inRange(value, 0, 100)) {
148
+ decay(e) {
149
+ if (!this.inRange(e, 0, 100))
73
150
  throw new RangeError("Reverb.js: Inpulse Response decay level must be less than 100.");
74
- }
75
- this._options.decay = value;
76
- this.buildImpulse();
77
- console.debug(`Reverb.js: Set inpulse response decay level to ${value}.`);
151
+ this.options.decay = e, this.buildImpulse();
78
152
  }
79
- delay(value) {
80
- if (!this.inRange(value, 0, 100)) {
153
+ delay(e) {
154
+ if (!this.inRange(e, 0, 100))
81
155
  throw new RangeError("Reverb.js: Inpulse Response delay time must be less than 100.");
82
- }
83
- this._options.delay = value;
84
- this.buildImpulse();
85
- console.debug(`Reverb.js: Set inpulse response delay time to ${value}sec.`);
156
+ this.options.delay = e, this.buildImpulse();
86
157
  }
87
- reverse(reverse) {
88
- this._options.reverse = reverse;
89
- this.buildImpulse();
90
- console.debug(`Reverb.js: Inpulse response is ${reverse ? "" : "not "}reversed.`);
158
+ reverse(e) {
159
+ this.options.reverse = e, this.buildImpulse();
91
160
  }
92
- filterType(type) {
93
- this.filterNode.type = this._options.filterType = type;
94
- console.debug(`Set filter type to ${type}`);
161
+ filterType(e) {
162
+ this.filterNode.type = this.options.filterType = e;
95
163
  }
96
- filterFreq(freq) {
97
- if (!this.inRange(freq, 20, 5e3)) {
164
+ filterFreq(e) {
165
+ if (!this.inRange(e, 20, 5e3))
98
166
  throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");
99
- }
100
- this._options.filterFreq = freq;
101
- this.filterNode.frequency.value = this._options.filterFreq;
102
- console.debug(`Set filter frequency to ${freq}Hz.`);
167
+ this.options.filterFreq = e, this.filterNode.frequency.value = this.options.filterFreq;
103
168
  }
104
- filterQ(q) {
105
- if (!this.inRange(q, 0, 10)) {
169
+ filterQ(e) {
170
+ if (!this.inRange(e, 0, 10))
106
171
  throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");
107
- }
108
- this._options.filterQ = q;
109
- this.filterNode.Q.value = this._options.filterQ;
110
- console.debug(`Set filter quality to ${q}.`);
172
+ this.options.filterQ = e, this.filterNode.Q.value = this.options.filterQ;
111
173
  }
112
- setNoise(type) {
113
- this._options.noise = type;
174
+ setNoise(e) {
175
+ switch (this.options.noise = e, e) {
176
+ case l.BLUE:
177
+ this.noise = m;
178
+ break;
179
+ case l.GREEN:
180
+ this.noise = Q;
181
+ break;
182
+ case l.PINK:
183
+ this.noise = M;
184
+ break;
185
+ case l.RED:
186
+ case l.BROWN:
187
+ this.noise = v;
188
+ break;
189
+ case l.VIOLET:
190
+ this.noise = H;
191
+ break;
192
+ default:
193
+ this.noise = g;
194
+ break;
195
+ }
114
196
  this.buildImpulse();
115
- console.debug(`Set Noise type to ${type}.`);
116
197
  }
117
- inRange(x, min, max) {
118
- return (x - min) * (x - max) <= 0;
198
+ inRange(e, i, s) {
199
+ return (e - i) * (e - s) <= 0;
119
200
  }
120
201
  buildImpulse() {
121
- const rate = this.ctx.sampleRate;
122
- const duration = Math.max(rate * this._options.time, 1);
123
- const delayDuration = rate * this._options.delay;
124
- const impulse = this.ctx.createBuffer(2, duration, rate);
125
- const impulseL = new Float32Array(duration);
126
- const impulseR = new Float32Array(duration);
127
- const b = [0, 0, 0, 0, 0, 0, 0];
128
- for (let i = 0; i < duration; i++) {
129
- let n = 0;
130
- if (i < delayDuration) {
131
- impulseL[i] = 0;
132
- impulseR[i] = 0;
133
- n = this._options.reverse ? duration - (i - delayDuration) : i - delayDuration;
134
- } else {
135
- n = this._options.reverse ? duration - i : i;
136
- }
137
- switch (this._options.noise) {
138
- case Noise.PINK:
139
- b[0] = 0.99886 * b[0] + Reverb.whiteNoise() * 0.0555179;
140
- b[1] = 0.99332 * b[1] + Reverb.whiteNoise() * 0.0750759;
141
- b[2] = 0.969 * b[2] + Reverb.whiteNoise() * 0.153852;
142
- b[3] = 0.8665 * b[3] + Reverb.whiteNoise() * 0.3104856;
143
- b[4] = 0.55 * b[4] + Reverb.whiteNoise() * 0.5329522;
144
- b[5] = -0.7616 * b[5] - Reverb.whiteNoise() * 0.016898;
145
- impulseL[i] = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + Reverb.whiteNoise() * 0.5362;
146
- impulseR[i] = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + Reverb.whiteNoise() * 0.5362;
147
- impulseL[i] *= 0.11;
148
- impulseR[i] *= 0.11;
149
- b[6] = Reverb.whiteNoise() * 0.115926;
150
- break;
151
- case Noise.BROWN:
152
- impulseL[i] = (b[0] + 0.02 * Reverb.whiteNoise()) / 1.02;
153
- b[0] = impulseL[i];
154
- impulseR[i] = (b[1] + 0.02 * Reverb.whiteNoise()) / 1.02;
155
- b[1] = impulseR[i];
156
- impulseL[i] *= 3.5;
157
- impulseR[i] *= 3.5;
158
- break;
159
- case Noise.WHITE:
160
- default:
161
- impulseL[i] = Reverb.whiteNoise();
162
- impulseR[i] = Reverb.whiteNoise();
163
- break;
164
- }
165
- impulseL[i] *= (1 - n / duration) ** this._options.decay;
166
- impulseR[i] *= (1 - n / duration) ** this._options.decay;
202
+ const e = this.ctx.sampleRate, i = Math.max(e * this.options.time, 1), s = e * this.options.delay, r = this.ctx.createBuffer(2, i, e), o = new Float32Array(i), n = new Float32Array(i), a = [...p(i, this.noise(1))], G = [...p(i, this.noise(1))];
203
+ for (let c = 0; c < i; c++) {
204
+ let f = 0;
205
+ c < s ? (o[c] = 0, n[c] = 0, f = this.options.reverse ? i - (c - s) : c - s) : f = this.options.reverse ? i - c : c, o[c] = 1 + a[c] * this.options.power, n[c] = 1 + G[c] * this.options.power, o[c] *= (1 - f / i) ** this.options.decay, n[c] *= (1 - f / i) ** this.options.decay;
167
206
  }
168
- impulse.getChannelData(0).set(impulseL);
169
- impulse.getChannelData(1).set(impulseR);
170
- this.convolverNode.buffer = impulse;
171
- }
172
- static whiteNoise() {
173
- return Math.random() * 2 - 1;
207
+ r.getChannelData(0).set(o), r.getChannelData(1).set(n), this.convolverNode.buffer = r;
174
208
  }
175
209
  }
176
- const optionDefaults = {
177
- noise: Noise.WHITE,
210
+ w.version = E.version;
211
+ w.build = E.date;
212
+ const O = {
213
+ noise: l.WHITE,
214
+ power: 2,
178
215
  decay: 2,
179
216
  delay: 0,
180
- reverse: false,
217
+ reverse: !1,
181
218
  time: 2,
182
219
  filterType: "lowpass",
183
220
  filterFreq: 2200,
184
221
  filterQ: 1,
185
222
  mix: 0.5,
186
- once: false
223
+ once: !1
224
+ };
225
+ window.Reverb || (window.Reverb = w);
226
+ export {
227
+ w as default
187
228
  };
188
- export { Reverb as default };
@@ -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.0
9
+ * @see {@link https://github.com/logue/Reverb.js}
10
+ */
11
+
12
+ var Reverb=function(){"use strict";const w={version:"1.0.0",date:"2022-08-29T12:34:03.524Z"},l={BLUE:"blue",GREEN:"green",PINK:"pink",RED:"red",VIOLET:"violet",WHITE:"white"},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),N=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],r=i[2];for(let o of e){const n=r([],o);if(x(n)){yield*N(s(n.deref()));return}n.length&&(yield*n)}yield*N(s([]))}const L=(t,e)=>[t[0],t[1],e];function p(t,e){return F(e)?q(p(t),e):i=>{const s=i[2];let r=t;return L(i,(o,n)=>--r>0?s(o,n):r===0?C(s(o,n)):k(o))}}const g=1/2**32;class S{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 A extends S{int(){return m()*4294967296>>>0}float(e=1){return m()*e}norm(e=1){return(m()-.5)*2*e}}const h=new A,v=(t,e,i)=>{const s=new Array(t);for(let r=0;r<t;r++)s[r]=i.norm(e);return s},b=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 r=i[s].next();if(r.done)return;yield r.value}}function*y(t=2,e=1,i=h){const s=v(t,e,i);s.forEach((n,a)=>s[a]=a&1?n:-n);const r=1/t;let o=b(s);for(let n=0,a=-1;;++n>=t&&(n=0))o-=s[n],o+=s[n]=a*i.norm(e),a^=4294967294,yield a*o*r}const B=(t=2,e=1,i=h)=>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=h){const s=v(t,e,i),r=1/t;let o=b(s);for(let n=0;;n=n+1>>>0){const a=Q(n)%t;o-=s[a],o+=s[a]=i.norm(e),yield o*r}}function*R(t=2,e=1,i=h){const s=v(t,e,i),r=1/t;let o=b(s);for(let n=0;;++n>=t&&(n=0))o-=s[n],o+=s[n]=i.norm(e),yield o*r}const M=(t=2,e=1,i=h)=>E(R(t,e,i),R(t,e,i));function*I(t=1,e=h){for(;;)yield e.norm(t)}class f{constructor(e,i){this.noise=I,this.ctx=e,this.options={...H,...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(l.WHITE),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){switch(this.options.noise=e,e){case l.BLUE:this.noise=y;break;case l.GREEN:this.noise=B;break;case l.PINK:this.noise=W;break;case l.RED:case l.BROWN:this.noise=R;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,r=this.ctx.createBuffer(2,i,e),o=new Float32Array(i),n=new Float32Array(i),a=[...p(i,this.noise(1))],O=[...p(i,this.noise(1))];for(let c=0;c<i;c++){let d=0;c<s?(o[c]=0,n[c]=0,d=this.options.reverse?i-(c-s):c-s):d=this.options.reverse?i-c:c,o[c]=1+a[c]*this.options.power,n[c]=1+O[c]*this.options.power,o[c]*=(1-d/i)**this.options.decay,n[c]*=(1-d/i)**this.options.decay}r.getChannelData(0).set(o),r.getChannelData(1).set(n),this.convolverNode.buffer=r}}f.version=w.version,f.build=w.date;const H={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}();
@@ -1,10 +1,12 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Reverb=t()}(this,(function(){"use strict";const e="0.5.3",t="2022-06-05T00:53:37.175Z",i="white",s="pink",o="brown";
2
1
  /**
3
- * JS reverb effect class
4
- *
5
- * @license MIT
6
- * @author Logue {@link logue@hotmail.co.jp}
7
- * @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
8
- * @see {@link https://github.com/logue/Reverb.js}
9
- */
10
- class n{constructor(i,s){this.version=e,this.build=t,this.ctx=i,this._options={...r,...s},this.wetGainNode=this.ctx.createGain(),this.dryGainNode=this.ctx.createGain(),this.filterNode=this.ctx.createBiquadFilter(),this.convolverNode=this.ctx.createConvolver(),this.outputNode=this.ctx.createGain(),this.isConnected=!1,this.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,t,i){return(e-t)*(e-i)<=0}buildImpulse(){const e=this.ctx.sampleRate,t=Math.max(e*this._options.time,1),i=e*this._options.delay,r=this.ctx.createBuffer(2,t,e),h=new Float32Array(t),a=new Float32Array(t),l=[0,0,0,0,0,0,0];for(let c=0;c<t;c++){let e=0;switch(c<i?(h[c]=0,a[c]=0,e=this._options.reverse?t-(c-i):c-i):e=this._options.reverse?t-c:c,this._options.noise){case s:l[0]=.99886*l[0]+.0555179*n.whiteNoise(),l[1]=.99332*l[1]+.0750759*n.whiteNoise(),l[2]=.969*l[2]+.153852*n.whiteNoise(),l[3]=.8665*l[3]+.3104856*n.whiteNoise(),l[4]=.55*l[4]+.5329522*n.whiteNoise(),l[5]=-.7616*l[5]-.016898*n.whiteNoise(),h[c]=l[0]+l[1]+l[2]+l[3]+l[4]+l[5]+l[6]+.5362*n.whiteNoise(),a[c]=l[0]+l[1]+l[2]+l[3]+l[4]+l[5]+l[6]+.5362*n.whiteNoise(),h[c]*=.11,a[c]*=.11,l[6]=.115926*n.whiteNoise();break;case o:h[c]=(l[0]+.02*n.whiteNoise())/1.02,l[0]=h[c],a[c]=(l[1]+.02*n.whiteNoise())/1.02,l[1]=a[c],h[c]*=3.5,a[c]*=3.5;break;default:h[c]=n.whiteNoise(),a[c]=n.whiteNoise()}h[c]*=(1-e/t)**this._options.decay,a[c]*=(1-e/t)**this._options.decay}r.getChannelData(0).set(h),r.getChannelData(1).set(a),this.convolverNode.buffer=r}static whiteNoise(){return 2*Math.random()-1}}const r={noise:i,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return n}));
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.0
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.0",date:"2022-08-29T12:34:03.524Z"},l={BLUE:"blue",GREEN:"green",PINK:"pink",RED:"red",VIOLET:"violet",WHITE:"white"},T=(t,e)=>t!=null&&typeof t[e]=="function",G=t=>T(t,"xform")?t.xform():t,x=t=>t!=null&&typeof t[Symbol.iterator]=="function";class f{constructor(e){this.value=e}deref(){return this.value}}const F=t=>new f(t),k=t=>t instanceof f,C=t=>t instanceof f?t:new f(t),N=t=>t instanceof f?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=G(t)(D()),s=i[1],r=i[2];for(let o of e){const n=r([],o);if(k(n)){yield*N(s(n.deref()));return}n.length&&(yield*n)}yield*N(s([]))}const L=(t,e)=>[t[0],t[1],e];function m(t,e){return x(e)?q(m(t),e):i=>{const s=i[2];let r=t;return L(i,(o,n)=>--r>0?s(o,n):r===0?C(s(o,n)):F(o))}}const g=1/2**32;class S{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 v=Math.random;class A extends S{int(){return v()*4294967296>>>0}float(e=1){return v()*e}norm(e=1){return(v()-.5)*2*e}}const u=new A,y=(t,e,i)=>{const s=new Array(t);for(let r=0;r<t;r++)s[r]=i.norm(e);return s},b=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 r=i[s].next();if(r.done)return;yield r.value}}function*R(t=2,e=1,i=u){const s=y(t,e,i);s.forEach((n,a)=>s[a]=a&1?n:-n);const r=1/t;let o=b(s);for(let n=0,a=-1;;++n>=t&&(n=0))o-=s[n],o+=s[n]=a*i.norm(e),a^=4294967294,yield a*o*r}const B=(t=2,e=1,i=u)=>E(R(t,e,i),R(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=y(t,e,i),r=1/t;let o=b(s);for(let n=0;;n=n+1>>>0){const a=Q(n)%t;o-=s[a],o+=s[a]=i.norm(e),yield o*r}}function*w(t=2,e=1,i=u){const s=y(t,e,i),r=1/t;let o=b(s);for(let n=0;;++n>=t&&(n=0))o-=s[n],o+=s[n]=i.norm(e),yield o*r}const M=(t=2,e=1,i=u)=>E(w(t,e,i),w(t,e,i));function*I(t=1,e=u){for(;;)yield e.norm(t)}class d{constructor(e,i){this.noise=I,this.ctx=e,this.options={...H,...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(l.WHITE),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){switch(this.options.noise=e,e){case l.BLUE:this.noise=R;break;case l.GREEN:this.noise=B;break;case l.PINK:this.noise=W;break;case l.RED:case l.BROWN:this.noise=w;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,r=this.ctx.createBuffer(2,i,e),o=new Float32Array(i),n=new Float32Array(i),a=[...m(i,this.noise(1))],O=[...m(i,this.noise(1))];for(let c=0;c<i;c++){let p=0;c<s?(o[c]=0,n[c]=0,p=this.options.reverse?i-(c-s):c-s):p=this.options.reverse?i-c:c,o[c]=1+a[c]*this.options.power,n[c]=1+O[c]*this.options.power,o[c]*=(1-p/i)**this.options.decay,n[c]*=(1-p/i)**this.options.decay}r.getChannelData(0).set(o),r.getChannelData(1).set(n),this.convolverNode.buffer=r}}d.version=h.version,d.build=h.date;const H={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});
package/package.json CHANGED
@@ -1,29 +1,15 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@logue/reverb",
4
- "version": "0.5.3",
5
- "description": "Reverb effect.",
6
- "files": [
7
- "dist"
8
- ],
9
- "main": "./dist/reverb.umd.js",
10
- "module": "./dist/reverb.es.js",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/reverb.es.js",
14
- "require": "./dist/reverb.umd.js"
15
- }
16
- },
17
- "types": "./dist/Reverb.d.ts",
18
- "directories": {
19
- "doc": "docs"
20
- },
4
+ "version": "1.0.0",
5
+ "description": "JavaScript Reverb effect class",
21
6
  "keywords": [
22
7
  "webaudio",
23
8
  "convolver",
24
9
  "effect",
25
10
  "reverb"
26
11
  ],
12
+ "license": "MIT",
27
13
  "author": {
28
14
  "name": "Logue",
29
15
  "email": "logue@hotmail.co.jp",
@@ -37,12 +23,27 @@
37
23
  "bugs": {
38
24
  "url": "https://github.com/logue/Reverb.js/issues"
39
25
  },
26
+ "directories": {
27
+ "doc": "docs"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "main": "dist/reverb.umd.js",
33
+ "module": "dist/reverb.es.js",
34
+ "browser": "dist/reverb.iife.js",
35
+ "types": "dist/Reverb.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "import": "./dist/reverb.es.js",
39
+ "require": "./dist/reverb.umd.js"
40
+ }
41
+ },
40
42
  "engines": {
41
- "node": ">=16.15.0",
42
- "yarn": ">=1.22.4"
43
+ "node": ">=16.17.0",
44
+ "yarn": ">=1.22.10"
43
45
  },
44
- "packageManager": "yarn@3.2.1",
45
- "license": "MIT",
46
+ "packageManager": "yarn@3.2.3",
46
47
  "sideEffects": false,
47
48
  "scripts": {
48
49
  "dev": "vite",
@@ -52,28 +53,26 @@
52
53
  "prepare": "husky install"
53
54
  },
54
55
  "devDependencies": {
55
- "@microsoft/api-extractor": "^7.24.2",
56
- "@types/eslint": "^8.4.2",
57
- "@types/node": "^17.0.39",
58
- "@typescript-eslint/eslint-plugin": "^5.27.0",
59
- "@typescript-eslint/parser": "^5.27.0",
60
- "eslint": "^8.17.0",
56
+ "@types/node": "^18.7.13",
57
+ "@typescript-eslint/eslint-plugin": "^5.35.1",
58
+ "@typescript-eslint/parser": "^5.35.1",
59
+ "eslint": "^8.23.0",
61
60
  "eslint-config-google": "^0.14.0",
62
61
  "eslint-config-prettier": "^8.5.0",
63
62
  "eslint-import-resolver-alias": "^1.1.2",
64
- "eslint-import-resolver-typescript": "^2.7.1",
63
+ "eslint-import-resolver-typescript": "^3.5.0",
65
64
  "eslint-plugin-import": "^2.26.0",
66
- "eslint-plugin-jsdoc": "^39.3.2",
67
- "eslint-plugin-prettier": "^4.0.0",
65
+ "eslint-plugin-jsdoc": "^39.3.6",
66
+ "eslint-plugin-prettier": "^4.2.1",
68
67
  "eslint-plugin-tsdoc": "^0.2.16",
69
68
  "husky": "^8.0.1",
70
- "lint-staged": "^13.0.0",
71
- "optionator": "^0.9.1",
72
- "prettier": "^2.6.2",
69
+ "lint-staged": "^13.0.3",
70
+ "prettier": "^2.7.1",
73
71
  "rimraf": "^3.0.2",
74
- "typescript": "^4.7.3",
75
- "vite": "^2.9.9",
76
- "vite-plugin-checker": "^0.4.6"
72
+ "typescript": "^4.7.4",
73
+ "vite": "^3.0.9",
74
+ "vite-plugin-banner": "^0.4.0",
75
+ "vite-plugin-checker": "^0.5.0"
77
76
  },
78
77
  "husky": {
79
78
  "hooks": {
@@ -83,5 +82,12 @@
83
82
  "lint-staged": {
84
83
  "*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
85
84
  "*": "prettier -w -u"
85
+ },
86
+ "resolutions": {
87
+ "prettier": "^2.7.1"
88
+ },
89
+ "dependencies": {
90
+ "@thi.ng/colored-noise": "^0.3.16",
91
+ "@thi.ng/transducers": "^8.3.13"
86
92
  }
87
93
  }