@logue/reverb 0.5.4 → 1.0.1

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,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;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,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAK7B;;;;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"}
@@ -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
@@ -5,179 +5,231 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 0.5.4
8
+ * @version 1.0.1
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
11
 
12
- const meta = {
13
- version: "0.5.4",
14
- date: "2022-07-08T12:56:05.192Z"
15
- };
16
- const Noise = {
17
- WHITE: "white",
12
+ const g = {
13
+ version: "1.0.1",
14
+ date: "2022-08-29T23:50:47.342Z"
15
+ }, l = {
16
+ BLUE: "blue",
17
+ GREEN: "green",
18
18
  PINK: "pink",
19
- BROWN: "brown"
20
- };
21
- class Reverb {
22
- constructor(ctx, options) {
23
- this.version = meta.version;
24
- this.build = meta.date;
25
- this.ctx = ctx;
26
- this._options = { ...optionDefaults, ...options };
27
- this.wetGainNode = this.ctx.createGain();
28
- this.dryGainNode = this.ctx.createGain();
29
- this.filterNode = this.ctx.createBiquadFilter();
30
- this.convolverNode = this.ctx.createConvolver();
31
- this.outputNode = this.ctx.createGain();
32
- this.isConnected = false;
33
- this.buildImpulse();
34
- this.mix(this._options.mix);
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;
35
27
  }
36
- connect(sourceNode) {
37
- if (this.isConnected && this._options.once) {
38
- this.isConnected = false;
39
- return this.outputNode;
40
- }
41
- this.convolverNode.connect(this.filterNode);
42
- this.filterNode.connect(this.wetGainNode);
43
- sourceNode.connect(this.convolverNode);
44
- sourceNode.connect(this.dryGainNode).connect(this.outputNode);
45
- sourceNode.connect(this.wetGainNode).connect(this.outputNode);
46
- this.isConnected = true;
47
- return this.outputNode;
48
- }
49
- disconnect(sourceNode) {
50
- if (this.isConnected) {
51
- this.convolverNode.disconnect(this.filterNode);
52
- this.filterNode.disconnect(this.wetGainNode);
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;
53
43
  }
54
- this.isConnected = false;
55
- return sourceNode;
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 W 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 W(), 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 A = (t = 2, e = 1, i = h) => I(p(t, e, i), p(t, e, i)), Q = (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 = Q(n) % t;
115
+ r -= s[a], r += s[a] = i.norm(e), yield r * o;
56
116
  }
57
- mix(mix) {
58
- if (!this.inRange(mix, 0, 1)) {
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 = { ...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);
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))
59
141
  throw new RangeError("Reverb.js: Dry/Wet ratio must be between 0 to 1.");
60
- }
61
- this._options.mix = mix;
62
- this.dryGainNode.gain.value = 1 - this._options.mix;
63
- this.wetGainNode.gain.value = this._options.mix;
142
+ this.options.mix = e, this.dryGainNode.gain.value = 1 - this.options.mix, this.wetGainNode.gain.value = this.options.mix;
64
143
  }
65
- time(value) {
66
- if (!this.inRange(value, 1, 50)) {
144
+ time(e) {
145
+ if (!this.inRange(e, 1, 50))
67
146
  throw new RangeError("Reverb.js: Time length of inpulse response must be less than 50sec.");
68
- }
69
- this._options.time = value;
70
- this.buildImpulse();
147
+ this.options.time = e, this.buildImpulse();
71
148
  }
72
- decay(value) {
73
- if (!this.inRange(value, 0, 100)) {
149
+ decay(e) {
150
+ if (!this.inRange(e, 0, 100))
74
151
  throw new RangeError("Reverb.js: Inpulse Response decay level must be less than 100.");
75
- }
76
- this._options.decay = value;
77
- this.buildImpulse();
152
+ this.options.decay = e, this.buildImpulse();
78
153
  }
79
- delay(value) {
80
- if (!this.inRange(value, 0, 100)) {
154
+ delay(e) {
155
+ if (!this.inRange(e, 0, 100))
81
156
  throw new RangeError("Reverb.js: Inpulse Response delay time must be less than 100.");
82
- }
83
- this._options.delay = value;
84
- this.buildImpulse();
157
+ this.options.delay = e, this.buildImpulse();
85
158
  }
86
- reverse(reverse) {
87
- this._options.reverse = reverse;
88
- this.buildImpulse();
159
+ reverse(e) {
160
+ this.options.reverse = e, this.buildImpulse();
89
161
  }
90
- filterType(type) {
91
- this.filterNode.type = this._options.filterType = type;
162
+ filterType(e) {
163
+ this.filterNode.type = this.options.filterType = e;
92
164
  }
93
- filterFreq(freq) {
94
- if (!this.inRange(freq, 20, 5e3)) {
165
+ filterFreq(e) {
166
+ if (!this.inRange(e, 20, 5e3))
95
167
  throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");
96
- }
97
- this._options.filterFreq = freq;
98
- this.filterNode.frequency.value = this._options.filterFreq;
168
+ this.options.filterFreq = e, this.filterNode.frequency.value = this.options.filterFreq;
99
169
  }
100
- filterQ(q) {
101
- if (!this.inRange(q, 0, 10)) {
170
+ filterQ(e) {
171
+ if (!this.inRange(e, 0, 10))
102
172
  throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");
103
- }
104
- this._options.filterQ = q;
105
- this.filterNode.Q.value = this._options.filterQ;
106
- console.debug(`Set filter quality to ${q}.`);
173
+ this.options.filterQ = e, this.filterNode.Q.value = this.options.filterQ;
174
+ }
175
+ power(e) {
176
+ this.options.power = e, this.buildImpulse();
107
177
  }
108
- setNoise(type) {
109
- this._options.noise = type;
178
+ setNoise(e) {
179
+ switch (this.options.noise = e, e) {
180
+ case l.BLUE:
181
+ this.noise = p;
182
+ break;
183
+ case l.GREEN:
184
+ this.noise = A;
185
+ break;
186
+ case l.PINK:
187
+ this.noise = M;
188
+ break;
189
+ case l.RED:
190
+ case l.BROWN:
191
+ this.noise = m;
192
+ break;
193
+ case l.VIOLET:
194
+ this.noise = O;
195
+ break;
196
+ default:
197
+ this.noise = R;
198
+ break;
199
+ }
110
200
  this.buildImpulse();
111
201
  }
112
- inRange(x, min, max) {
113
- return (x - min) * (x - max) <= 0;
202
+ inRange(e, i, s) {
203
+ return (e - i) * (e - s) <= 0;
114
204
  }
115
205
  buildImpulse() {
116
- const rate = this.ctx.sampleRate;
117
- const duration = Math.max(rate * this._options.time, 1);
118
- const delayDuration = rate * this._options.delay;
119
- const impulse = this.ctx.createBuffer(2, duration, rate);
120
- const impulseL = new Float32Array(duration);
121
- const impulseR = new Float32Array(duration);
122
- const b = [0, 0, 0, 0, 0, 0, 0];
123
- for (let i = 0; i < duration; i++) {
124
- let n = 0;
125
- if (i < delayDuration) {
126
- impulseL[i] = 0;
127
- impulseR[i] = 0;
128
- n = this._options.reverse ? duration - (i - delayDuration) : i - delayDuration;
129
- } else {
130
- n = this._options.reverse ? duration - i : i;
131
- }
132
- switch (this._options.noise) {
133
- case Noise.PINK:
134
- b[0] = 0.99886 * b[0] + Reverb.whiteNoise() * 0.0555179;
135
- b[1] = 0.99332 * b[1] + Reverb.whiteNoise() * 0.0750759;
136
- b[2] = 0.969 * b[2] + Reverb.whiteNoise() * 0.153852;
137
- b[3] = 0.8665 * b[3] + Reverb.whiteNoise() * 0.3104856;
138
- b[4] = 0.55 * b[4] + Reverb.whiteNoise() * 0.5329522;
139
- b[5] = -0.7616 * b[5] - Reverb.whiteNoise() * 0.016898;
140
- impulseL[i] = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + Reverb.whiteNoise() * 0.5362;
141
- impulseR[i] = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + Reverb.whiteNoise() * 0.5362;
142
- impulseL[i] *= 0.11;
143
- impulseR[i] *= 0.11;
144
- b[6] = Reverb.whiteNoise() * 0.115926;
145
- break;
146
- case Noise.BROWN:
147
- impulseL[i] = (b[0] + 0.02 * Reverb.whiteNoise()) / 1.02;
148
- b[0] = impulseL[i];
149
- impulseR[i] = (b[1] + 0.02 * Reverb.whiteNoise()) / 1.02;
150
- b[1] = impulseR[i];
151
- impulseL[i] *= 3.5;
152
- impulseR[i] *= 3.5;
153
- break;
154
- case Noise.WHITE:
155
- default:
156
- impulseL[i] = Reverb.whiteNoise();
157
- impulseR[i] = Reverb.whiteNoise();
158
- break;
159
- }
160
- impulseL[i] *= (1 - n / duration) ** this._options.decay;
161
- impulseR[i] *= (1 - n / duration) ** this._options.decay;
206
+ 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);
207
+ for (let c = 0; c < i; c++) {
208
+ let d = 0;
209
+ 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;
162
210
  }
163
- impulse.getChannelData(0).set(impulseL);
164
- impulse.getChannelData(1).set(impulseR);
165
- this.convolverNode.buffer = impulse;
211
+ o.getChannelData(0).set(r), o.getChannelData(1).set(n), this.convolverNode.buffer = o;
166
212
  }
167
- static whiteNoise() {
168
- return Math.random() * 2 - 1;
213
+ getNoise(e) {
214
+ return [...E(e, this.noise())].map((i) => i * this.options.power);
169
215
  }
170
216
  }
171
- const optionDefaults = {
172
- noise: Noise.WHITE,
217
+ y.version = g.version;
218
+ y.build = g.date;
219
+ const H = {
220
+ noise: l.WHITE,
221
+ power: 2,
173
222
  decay: 2,
174
223
  delay: 0,
175
- reverse: false,
224
+ reverse: !1,
176
225
  time: 2,
177
226
  filterType: "lowpass",
178
227
  filterFreq: 2200,
179
228
  filterQ: 1,
180
229
  mix: 0.5,
181
- once: false
230
+ once: !1
231
+ };
232
+ window.Reverb || (window.Reverb = y);
233
+ export {
234
+ y as default
182
235
  };
183
- 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.1
9
+ * @see {@link https://github.com/logue/Reverb.js}
10
+ */
11
+
12
+ var Reverb=function(){"use strict";const N={version:"1.0.1",date:"2022-08-29T23:50:47.342Z"},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 W=(t=2,e=1,i=h)=>E(b(t,e,i),b(t,e,i)),A=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*Q(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=A(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(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}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=W;break;case l.PINK:this.noise=Q;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),H=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]=H[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}();
@@ -5,8 +5,8 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 0.5.4
8
+ * @version 1.0.1
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
11
 
12
- !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.4",t="2022-07-08T12:56:05.192Z",i="white",s="pink",o="brown";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}));
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.1",date:"2022-08-29T23:50:47.342Z"},l={BLUE:"blue",GREEN:"green",PINK:"pink",RED:"red",VIOLET:"violet",WHITE:"white",BROWN:"red"},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 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=G(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 W=(t=2,e=1,i=u)=>E(y(t,e,i),y(t,e,i)),A=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*Q(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=A(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(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}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=W;break;case l.PINK:this.noise=Q;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),H=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]=H[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});
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.4",
4
+ "version": "1.0.1",
5
5
  "description": "JavaScript Reverb effect class",
6
6
  "keywords": [
7
7
  "webaudio",
@@ -29,20 +29,21 @@
29
29
  "files": [
30
30
  "dist"
31
31
  ],
32
- "main": "./dist/reverb.umd.js",
33
- "module": "./dist/reverb.es.js",
32
+ "main": "dist/reverb.umd.js",
33
+ "module": "dist/reverb.es.js",
34
+ "browser": "dist/reverb.iife.js",
35
+ "types": "dist/Reverb.d.ts",
34
36
  "exports": {
35
37
  ".": {
36
38
  "import": "./dist/reverb.es.js",
37
39
  "require": "./dist/reverb.umd.js"
38
40
  }
39
41
  },
40
- "types": "./dist/Reverb.d.ts",
41
42
  "engines": {
42
- "node": ">=16.16.0",
43
- "yarn": ">=1.22.4"
43
+ "node": ">=16.17.0",
44
+ "yarn": ">=1.22.10"
44
45
  },
45
- "packageManager": "yarn@3.2.1",
46
+ "packageManager": "yarn@3.2.3",
46
47
  "sideEffects": false,
47
48
  "scripts": {
48
49
  "dev": "vite",
@@ -52,16 +53,16 @@
52
53
  "prepare": "husky install"
53
54
  },
54
55
  "devDependencies": {
55
- "@types/node": "^18.0.3",
56
- "@typescript-eslint/eslint-plugin": "^5.30.5",
57
- "@typescript-eslint/parser": "^5.30.5",
58
- "eslint": "^8.19.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",
59
60
  "eslint-config-google": "^0.14.0",
60
61
  "eslint-config-prettier": "^8.5.0",
61
62
  "eslint-import-resolver-alias": "^1.1.2",
62
- "eslint-import-resolver-typescript": "^3.2.4",
63
+ "eslint-import-resolver-typescript": "^3.5.0",
63
64
  "eslint-plugin-import": "^2.26.0",
64
- "eslint-plugin-jsdoc": "^39.3.3",
65
+ "eslint-plugin-jsdoc": "^39.3.6",
65
66
  "eslint-plugin-prettier": "^4.2.1",
66
67
  "eslint-plugin-tsdoc": "^0.2.16",
67
68
  "husky": "^8.0.1",
@@ -69,9 +70,9 @@
69
70
  "prettier": "^2.7.1",
70
71
  "rimraf": "^3.0.2",
71
72
  "typescript": "^4.7.4",
72
- "vite": "^2.9.14",
73
- "vite-plugin-banner": "^0.3.0",
74
- "vite-plugin-checker": "^0.4.8"
73
+ "vite": "^3.0.9",
74
+ "vite-plugin-banner": "^0.4.0",
75
+ "vite-plugin-checker": "^0.5.0"
75
76
  },
76
77
  "husky": {
77
78
  "hooks": {
@@ -84,5 +85,9 @@
84
85
  },
85
86
  "resolutions": {
86
87
  "prettier": "^2.7.1"
88
+ },
89
+ "dependencies": {
90
+ "@thi.ng/colored-noise": "^0.3.16",
91
+ "@thi.ng/transducers": "^8.3.13"
87
92
  }
88
93
  }