@logue/reverb 1.0.2 → 1.1.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,10 +1,11 @@
1
1
  # Reverb.js
2
2
 
3
- [![jsdelivr CDN](https://data.jsdelivr.com/v1/package/npm/@logue/reverb/badge)](https://www.jsdelivr.com/package/npm/@logue/reverb)
3
+ [![jsdelivr CDN](https://data.jsdelivr.com/v1/package/npm/@logue/reverb/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@logue/reverb)
4
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)
8
+ [![Twitter Follow](https://img.shields.io/twitter/follow/logue256?style=plastic)](https://twitter.com/thing_umbrella)
8
9
 
9
10
  Append reverb effect to audio source.
10
11
 
@@ -19,13 +20,20 @@ This script is originally a spin out of [sf2synth.js](https://github.com/logue/s
19
20
 
20
21
  ```js
21
22
  const reverb = new Reverb(ctx, {
23
+ /**
24
+ * Randam noise algorythm
25
+ * @see {@link https://github.com/thi-ng/umbrella/tree/develop/packages/random}
26
+ */
27
+ randomAlgorithm: SYSTEM;
22
28
  /**
23
29
  * IR (Inpulse Response) colord noise algorithm (BLUE, GREEN, PINK, RED, VIOLET, WHITE)
24
- * @see {@link https://en.wikipedia.org/wiki/Colors_of_noise}
30
+ * @see {@link https://github.com/thi-ng/umbrella/tree/develop/packages/colored-noise}
25
31
  */
26
32
  noise: Noise.WHITE,
27
- /** IR noise power multiplier */
28
- power: 2,
33
+ /** IR source noise scale */
34
+ scale: 1;
35
+ /** Number of IR source noise peaks */
36
+ peaks: 2;
29
37
  /** Amount of IR decay. 0~100 */
30
38
  decay: 5,
31
39
  /** Delay time o IR. (NOT delay effect) 0~100 [sec] */
@@ -52,7 +60,7 @@ const reverb = new Reverb(ctx, {
52
60
 
53
61
  ```js
54
62
  // Setup Audio Context
55
- const ctx = new (window.AudioContext || window.webkitAudioContext)();
63
+ const ctx = new window.AudioContext();
56
64
 
57
65
  // iOS fix.
58
66
  document.addEventListener('touchstart', initAudioContext);
@@ -85,6 +93,7 @@ sourceNode.play();
85
93
  - [Web Audio API 日本語訳](https://g200kg.github.io/web-audio-api-ja/)
86
94
  - [コンボルバーの使い方](https://www.g200kg.com/jp/docs/webaudio/convolver.html)
87
95
  - [WebAudio の闇](https://qiita.com/zprodev/items/7fcd8335d7e8e613a01f)
96
+ - [@thi.ng/colored-noise](https://github.com/thi-ng/umbrella/tree/develop/packages/colored-noise)
88
97
 
89
98
  ## License
90
99
 
package/dist/Reverb.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type OptionInterface from './interfaces/OptionInterface';
2
1
  import { type NoiseType } from './NoiseType';
2
+ import type OptionInterface from './interfaces/OptionInterface';
3
+ import type { INorm } from '@thi.ng/random';
3
4
  /**
4
5
  * Reverb effect class
5
6
  */
@@ -18,7 +19,7 @@ export default class Reverb {
18
19
  private readonly filterNode;
19
20
  /** Convolution node for applying impulse response */
20
21
  private readonly convolverNode;
21
- /** Output nodse */
22
+ /** Output gain node */
22
23
  private readonly outputNode;
23
24
  /** Option */
24
25
  private readonly options;
@@ -94,17 +95,35 @@ export default class Reverb {
94
95
  */
95
96
  filterQ(q: number): void;
96
97
  /**
97
- * set IR noise power multiplier.
98
+ * set IR source noise peaks
99
+ *
100
+ * @param p - Peaks
101
+ */
102
+ peaks(p: number): void;
103
+ /**
104
+ * set IR source noise scale.
98
105
  *
99
- * @param p - Power
106
+ * @param s - Scale
100
107
  */
101
- power(p: number): void;
108
+ scale(s: number): void;
109
+ /**
110
+ * set IR source noise generator.
111
+ *
112
+ * @param a - Algorithm
113
+ */
114
+ randomAlgorithm(a: INorm): void;
102
115
  /**
103
116
  * Inpulse Response Noise algorithm.
104
117
  *
105
118
  * @param type - IR noise algorithm type.
106
119
  */
107
120
  setNoise(type: NoiseType): void;
121
+ /**
122
+ * Set Random Algorythm
123
+ *
124
+ * @param algorithm - Algorythm
125
+ */
126
+ setRandomAlgorythm(algorithm: INorm): void;
108
127
  /**
109
128
  * Return true if in range, otherwise false
110
129
  *
@@ -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;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"}
1
+ {"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.ts"],"names":[],"mappings":"AAEA,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAIhE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;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,uBAAuB;IACvB,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,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAM7B;;;;OAIG;IACI,eAAe,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI;IAMtC;;;;OAIG;IACI,QAAQ,CAAC,IAAI,EAAE,SAAS;IA2B/B;;;;OAIG;IACI,kBAAkB,CAAC,SAAS,EAAE,KAAK;IAK1C;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAIf,oFAAoF;IACpF,OAAO,CAAC,YAAY;IA+CpB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;CAcjB"}
package/dist/Reverb.es.js CHANGED
@@ -5,14 +5,11 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.0.2
8
+ * @version 1.1.0
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
11
 
12
- const g = {
13
- version: "1.0.2",
14
- date: "2022-09-09T10:45:33.869Z"
15
- }, l = {
12
+ const a = {
16
13
  BLUE: "blue",
17
14
  GREEN: "green",
18
15
  PINK: "pink",
@@ -20,56 +17,23 @@ const g = {
20
17
  VIOLET: "violet",
21
18
  WHITE: "white",
22
19
  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;
20
+ }, g = 1 / 2 ** 32;
57
21
  class S {
58
22
  float(e = 1) {
59
- return this.int() * w * e;
23
+ return this.int() * g * e;
60
24
  }
61
25
  norm(e = 1) {
62
- return (this.int() * w - 0.5) * 2 * e;
26
+ return (this.int() * g - 0.5) * 2 * e;
63
27
  }
64
- minmax(e, i) {
65
- return this.float() * (i - e) + e;
28
+ minmax(e, s) {
29
+ return this.float() * (s - e) + e;
66
30
  }
67
- minmaxInt(e, i) {
68
- return e |= 0, i |= 0, e + (this.float() * (i - e) | 0);
31
+ minmaxInt(e, s) {
32
+ return e |= 0, s |= 0, e + (this.float() * (s - e) | 0);
69
33
  }
70
34
  }
71
35
  const f = Math.random;
72
- class A extends S {
36
+ class k extends S {
73
37
  int() {
74
38
  return f() * 4294967296 >>> 0;
75
39
  }
@@ -80,55 +44,105 @@ class A extends S {
80
44
  return (f() - 0.5) * 2 * e;
81
45
  }
82
46
  }
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);
47
+ const h = new k(), G = {
48
+ noise: a.WHITE,
49
+ scale: 2,
50
+ peaks: 2,
51
+ randomAlgorithm: h,
52
+ decay: 2,
53
+ delay: 0,
54
+ reverse: !1,
55
+ time: 2,
56
+ filterType: "lowpass",
57
+ filterFreq: 2200,
58
+ filterQ: 1,
59
+ mix: 0.5,
60
+ once: !1
61
+ }, w = {
62
+ version: "1.1.0",
63
+ date: "2022-10-04T02:13:31.946Z"
64
+ }, b = (t, e, s) => {
65
+ const o = new Array(t);
66
+ for (let n = 0; n < t; n++)
67
+ o[n] = s.norm(e);
68
+ return o;
69
+ }, R = (t) => t.reduce((e, s) => e + s, 0);
89
70
  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)
71
+ const s = [t[Symbol.iterator](), e[Symbol.iterator]()];
72
+ for (let o = 0; ; o ^= 1) {
73
+ const n = s[o].next();
74
+ if (n.done)
94
75
  return;
95
- yield o.value;
76
+ yield n.value;
96
77
  }
97
78
  }
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;
79
+ function* p(t = 2, e = 1, s = h) {
80
+ const o = b(t, e, s);
81
+ o.forEach((i, c) => o[c] = c & 1 ? i : -i);
82
+ const n = 1 / t;
83
+ let r = R(o);
84
+ for (let i = 0, c = -1; ; ++i >= t && (i = 0))
85
+ r -= o[i], r += o[i] = c * s.norm(e), c ^= 4294967294, yield c * r * n;
105
86
  }
106
- const Q = (t = 2, e = 1, i = h) => I(p(t, e, i), p(t, e, i)), W = (t) => {
87
+ const A = (t = 2, e = 1, s = h) => I(p(t, e, s), p(t, e, s)), T = (t) => {
107
88
  let e = 32;
108
89
  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
90
  };
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;
91
+ function* $(t = 8, e = 1, s = h) {
92
+ const o = b(t, e, s), n = 1 / t;
93
+ let r = R(o);
94
+ for (let i = 0; ; i = i + 1 >>> 0) {
95
+ const c = T(i) % t;
96
+ r -= o[c], r += o[c] = s.norm(e), yield r * n;
116
97
  }
117
98
  }
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;
99
+ function* m(t = 2, e = 1, s = h) {
100
+ const o = b(t, e, s), n = 1 / t;
101
+ let r = R(o);
102
+ for (let i = 0; ; ++i >= t && (i = 0))
103
+ r -= o[i], r += o[i] = s.norm(e), yield r * n;
123
104
  }
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) {
105
+ const F = (t = 2, e = 1, s = h) => I(m(t, e, s), m(t, e, s));
106
+ function* y(t = 1, e = h) {
126
107
  for (; ; )
127
108
  yield e.norm(t);
128
109
  }
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);
110
+ const x = (t, e) => t != null && typeof t[e] == "function", C = (t) => x(t, "xform") ? t.xform() : t, B = (t) => t != null && typeof t[Symbol.iterator] == "function";
111
+ class u {
112
+ constructor(e) {
113
+ this.value = e;
114
+ }
115
+ deref() {
116
+ return this.value;
117
+ }
118
+ }
119
+ const D = (t) => new u(t), L = (t) => t instanceof u, Q = (t) => t instanceof u ? t : new u(t), N = (t) => t instanceof u ? t.deref() : t, W = (t, e) => [t, (s) => s, e];
120
+ function q(t) {
121
+ return t ? [...t] : W(() => [], (e, s) => (e.push(s), e));
122
+ }
123
+ function* H(t, e) {
124
+ const s = C(t)(q()), o = s[1], n = s[2];
125
+ for (let r of e) {
126
+ const i = n([], r);
127
+ if (L(i)) {
128
+ yield* N(o(i.deref()));
129
+ return;
130
+ }
131
+ i.length && (yield* i);
132
+ }
133
+ yield* N(o([]));
134
+ }
135
+ const M = (t, e) => [t[0], t[1], e];
136
+ function E(t, e) {
137
+ return B(e) ? H(E(t), e) : (s) => {
138
+ const o = s[2];
139
+ let n = t;
140
+ return M(s, (r, i) => --n > 0 ? o(r, i) : n === 0 ? Q(o(r, i)) : D(r));
141
+ };
142
+ }
143
+ class v {
144
+ constructor(e, s) {
145
+ this.noise = y, this.ctx = e, this.options = { ...G, ...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.setNoise(this.options.noise), this.buildImpulse(), this.mix(this.options.mix);
132
146
  }
133
147
  connect(e) {
134
148
  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);
@@ -139,109 +153,118 @@ class y {
139
153
  mix(e) {
140
154
  if (!this.inRange(e, 0, 1))
141
155
  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;
156
+ this.options.mix = e, this.dryGainNode.gain.value = 1 - this.options.mix, this.wetGainNode.gain.value = this.options.mix, console.debug(`[Reverb.js] Set dry/wet ratio to ${e * 100}%`);
143
157
  }
144
158
  time(e) {
145
159
  if (!this.inRange(e, 1, 50))
146
160
  throw new RangeError(
147
161
  "[Reverb.js] Time length of inpulse response must be less than 50sec."
148
162
  );
149
- this.options.time = e, this.buildImpulse();
163
+ this.options.time = e, this.buildImpulse(), console.debug(
164
+ `[Reverb.js] Set inpulse response time length to ${e}sec.`
165
+ );
150
166
  }
151
167
  decay(e) {
152
168
  if (!this.inRange(e, 0, 100))
153
169
  throw new RangeError(
154
170
  "[Reverb.js] Inpulse Response decay level must be less than 100."
155
171
  );
156
- this.options.decay = e, this.buildImpulse();
172
+ this.options.decay = e, this.buildImpulse(), console.debug(`[Reverb.js] Set inpulse response decay level to ${e}.`);
157
173
  }
158
174
  delay(e) {
159
175
  if (!this.inRange(e, 0, 100))
160
176
  throw new RangeError(
161
177
  "[Reverb.js] Inpulse Response delay time must be less than 100."
162
178
  );
163
- this.options.delay = e, this.buildImpulse();
179
+ this.options.delay = e, this.buildImpulse(), console.debug(
180
+ `[Reverb.js] Set inpulse response delay time to ${e}sec.`
181
+ );
164
182
  }
165
183
  reverse(e) {
166
- this.options.reverse = e, this.buildImpulse();
184
+ this.options.reverse = e, this.buildImpulse(), console.debug(
185
+ `[Reverb.js] Inpulse response is ${e ? "" : "not "}reversed.`
186
+ );
167
187
  }
168
188
  filterType(e) {
169
- this.filterNode.type = this.options.filterType = e;
189
+ this.filterNode.type = this.options.filterType = e, console.debug(`[Reverb.js] Set filter type to ${e}`);
170
190
  }
171
191
  filterFreq(e) {
172
192
  if (!this.inRange(e, 20, 2e4))
173
193
  throw new RangeError(
174
194
  "[Reverb.js] Filter frequrncy must be between 20 and 20000."
175
195
  );
176
- this.options.filterFreq = e, this.filterNode.frequency.value = this.options.filterFreq;
196
+ this.options.filterFreq = e, this.filterNode.frequency.value = this.options.filterFreq, console.debug(`[Reverb.js] Set filter frequency to ${e}Hz.`);
177
197
  }
178
198
  filterQ(e) {
179
199
  if (!this.inRange(e, 0, 10))
180
200
  throw new RangeError(
181
201
  "[Reverb.js] Filter quality value must be between 0 and 10."
182
202
  );
183
- this.options.filterQ = e, this.filterNode.Q.value = this.options.filterQ;
203
+ this.options.filterQ = e, this.filterNode.Q.value = this.options.filterQ, console.debug(`[Reverb.js] Set filter Q to ${e}.`);
204
+ }
205
+ peaks(e) {
206
+ this.options.peaks = e, this.buildImpulse(), console.debug(`[Reverb.js] Set IR source noise peaks to ${e}.`);
184
207
  }
185
- power(e) {
186
- this.options.power = e, this.buildImpulse();
208
+ scale(e) {
209
+ this.options.scale = e, this.buildImpulse(), console.debug(`[Reverb.js] Set IR source noise scale to ${e}.`);
210
+ }
211
+ randomAlgorithm(e) {
212
+ this.options.randomAlgorithm = e, this.buildImpulse(), console.debug(`[Reverb.js] Set IR source noise generator to ${e}.`);
187
213
  }
188
214
  setNoise(e) {
189
215
  switch (this.options.noise = e, e) {
190
- case l.BLUE:
216
+ case a.BLUE:
191
217
  this.noise = p;
192
218
  break;
193
- case l.GREEN:
194
- this.noise = Q;
219
+ case a.GREEN:
220
+ this.noise = A;
195
221
  break;
196
- case l.PINK:
197
- this.noise = M;
222
+ case a.PINK:
223
+ this.noise = $;
198
224
  break;
199
- case l.RED:
200
- case l.BROWN:
225
+ case a.RED:
226
+ case a.BROWN:
201
227
  this.noise = m;
202
228
  break;
203
- case l.VIOLET:
204
- this.noise = O;
229
+ case a.VIOLET:
230
+ this.noise = F;
205
231
  break;
206
232
  default:
207
- this.noise = R;
233
+ this.noise = y;
208
234
  break;
209
235
  }
210
- this.buildImpulse();
236
+ this.buildImpulse(), console.debug(`[Reverb.js] Set IR generator source noise type to ${e}.`);
237
+ }
238
+ setRandomAlgorythm(e) {
239
+ this.options.randomAlgorithm = e, this.buildImpulse();
211
240
  }
212
- inRange(e, i, s) {
213
- return (e - i) * (e - s) <= 0;
241
+ inRange(e, s, o) {
242
+ return (e - s) * (e - o) <= 0;
214
243
  }
215
244
  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++) {
245
+ const e = this.ctx.sampleRate, s = Math.max(e * this.options.time, 1), o = e * this.options.delay, n = this.ctx.createBuffer(2, s, e), r = new Float32Array(s), i = new Float32Array(s), c = this.getNoise(s), j = this.getNoise(s);
246
+ for (let l = 0; l < s; l++) {
218
247
  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;
248
+ l < o ? (r[l] = 0, i[l] = 0, d = this.options.reverse ? s - (l - o) : l - o) : d = this.options.reverse ? s - l : l, r[l] = c[l] * (1 - d / s) ** this.options.decay, i[l] = j[l] * (1 - d / s) ** this.options.decay;
220
249
  }
221
- o.getChannelData(0).set(r), o.getChannelData(1).set(n), this.convolverNode.buffer = o;
250
+ n.getChannelData(0).set(r), n.getChannelData(1).set(i), this.convolverNode.buffer = n;
222
251
  }
223
252
  getNoise(e) {
224
- return [...E(e, this.noise())].map(
225
- (i) => i * this.options.power
226
- );
253
+ return [
254
+ ...E(
255
+ e,
256
+ this.options.noise === a.WHITE ? this.noise(this.options.peaks, this.options.randomAlgorithm) : this.noise(
257
+ this.options.peaks,
258
+ this.options.scale,
259
+ this.options.randomAlgorithm
260
+ )
261
+ )
262
+ ];
227
263
  }
228
264
  }
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);
265
+ v.version = w.version;
266
+ v.build = w.date;
267
+ window.Reverb || (window.Reverb = v);
245
268
  export {
246
- y as default
269
+ v as default
247
270
  };
@@ -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 1.0.2
8
+ * @version 1.1.0
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
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}();
12
+ var Reverb=function(){"use strict";const a={BLUE:"blue",GREEN:"green",PINK:"pink",RED:"red",VIOLET:"violet",WHITE:"white",BROWN:"red"},g=1/2**32;class j{float(e=1){return this.int()*g*e}norm(e=1){return(this.int()*g-.5)*2*e}minmax(e,s){return this.float()*(s-e)+e}minmaxInt(e,s){return e|=0,s|=0,e+(this.float()*(s-e)|0)}}const p=Math.random;class S extends j{int(){return p()*4294967296>>>0}float(e=1){return p()*e}norm(e=1){return(p()-.5)*2*e}}const h=new S,k={noise:a.WHITE,scale:2,peaks:2,randomAlgorithm:h,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1},y={version:"1.1.0",date:"2022-10-04T02:13:31.946Z"},m=(t,e,s)=>{const o=new Array(t);for(let n=0;n<t;n++)o[n]=s.norm(e);return o},b=t=>t.reduce((e,s)=>e+s,0);function*N(t,e){const s=[t[Symbol.iterator](),e[Symbol.iterator]()];for(let o=0;;o^=1){const n=s[o].next();if(n.done)return;yield n.value}}function*R(t=2,e=1,s=h){const o=m(t,e,s);o.forEach((i,l)=>o[l]=l&1?i:-i);const n=1/t;let r=b(o);for(let i=0,l=-1;;++i>=t&&(i=0))r-=o[i],r+=o[i]=l*s.norm(e),l^=4294967294,yield l*r*n}const G=(t=2,e=1,s=h)=>N(R(t,e,s),R(t,e,s)),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*T(t=8,e=1,s=h){const o=m(t,e,s),n=1/t;let r=b(o);for(let i=0;;i=i+1>>>0){const l=A(i)%t;r-=o[l],r+=o[l]=s.norm(e),yield r*n}}function*v(t=2,e=1,s=h){const o=m(t,e,s),n=1/t;let r=b(o);for(let i=0;;++i>=t&&(i=0))r-=o[i],r+=o[i]=s.norm(e),yield r*n}const $=(t=2,e=1,s=h)=>N(v(t,e,s),v(t,e,s));function*w(t=1,e=h){for(;;)yield e.norm(t)}const F=(t,e)=>t!=null&&typeof t[e]=="function",C=t=>F(t,"xform")?t.xform():t,x=t=>t!=null&&typeof t[Symbol.iterator]=="function";class u{constructor(e){this.value=e}deref(){return this.value}}const B=t=>new u(t),D=t=>t instanceof u,L=t=>t instanceof u?t:new u(t),I=t=>t instanceof u?t.deref():t,Q=(t,e)=>[t,s=>s,e];function W(t){return t?[...t]:Q(()=>[],(e,s)=>(e.push(s),e))}function*q(t,e){const s=C(t)(W()),o=s[1],n=s[2];for(let r of e){const i=n([],r);if(D(i)){yield*I(o(i.deref()));return}i.length&&(yield*i)}yield*I(o([]))}const H=(t,e)=>[t[0],t[1],e];function E(t,e){return x(e)?q(E(t),e):s=>{const o=s[2];let n=t;return H(s,(r,i)=>--n>0?o(r,i):n===0?L(o(r,i)):B(r))}}class d{constructor(e,s){this.noise=w,this.ctx=e,this.options={...k,...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.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,console.debug(`[Reverb.js] Set dry/wet ratio to ${e*100}%`)}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(),console.debug(`[Reverb.js] Set inpulse response time length to ${e}sec.`)}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(),console.debug(`[Reverb.js] Set inpulse response decay level to ${e}.`)}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(),console.debug(`[Reverb.js] Set inpulse response delay time to ${e}sec.`)}reverse(e){this.options.reverse=e,this.buildImpulse(),console.debug(`[Reverb.js] Inpulse response is ${e?"":"not "}reversed.`)}filterType(e){this.filterNode.type=this.options.filterType=e,console.debug(`[Reverb.js] Set filter type to ${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,console.debug(`[Reverb.js] Set filter frequency to ${e}Hz.`)}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,console.debug(`[Reverb.js] Set filter Q to ${e}.`)}peaks(e){this.options.peaks=e,this.buildImpulse(),console.debug(`[Reverb.js] Set IR source noise peaks to ${e}.`)}scale(e){this.options.scale=e,this.buildImpulse(),console.debug(`[Reverb.js] Set IR source noise scale to ${e}.`)}randomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse(),console.debug(`[Reverb.js] Set IR source noise generator to ${e}.`)}setNoise(e){switch(this.options.noise=e,e){case a.BLUE:this.noise=R;break;case a.GREEN:this.noise=G;break;case a.PINK:this.noise=T;break;case a.RED:case a.BROWN:this.noise=v;break;case a.VIOLET:this.noise=$;break;default:this.noise=w;break}this.buildImpulse(),console.debug(`[Reverb.js] Set IR generator source noise type to ${e}.`)}setRandomAlgorythm(e){this.options.randomAlgorithm=e,this.buildImpulse()}inRange(e,s,o){return(e-s)*(e-o)<=0}buildImpulse(){const e=this.ctx.sampleRate,s=Math.max(e*this.options.time,1),o=e*this.options.delay,n=this.ctx.createBuffer(2,s,e),r=new Float32Array(s),i=new Float32Array(s),l=this.getNoise(s),M=this.getNoise(s);for(let c=0;c<s;c++){let f=0;c<o?(r[c]=0,i[c]=0,f=this.options.reverse?s-(c-o):c-o):f=this.options.reverse?s-c:c,r[c]=l[c]*(1-f/s)**this.options.decay,i[c]=M[c]*(1-f/s)**this.options.decay}n.getChannelData(0).set(r),n.getChannelData(1).set(i),this.convolverNode.buffer=n}getNoise(e){return[...E(e,this.options.noise===a.WHITE?this.noise(this.options.peaks,this.options.randomAlgorithm):this.noise(this.options.peaks,this.options.scale,this.options.randomAlgorithm))]}}return d.version=y.version,d.build=y.date,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 1.0.2
8
+ * @version 1.1.0
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
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});
12
+ (function(l,h){typeof exports=="object"&&typeof module<"u"?module.exports=h():typeof define=="function"&&define.amd?define(h):(l=typeof globalThis<"u"?globalThis:l||self,l.Reverb=h())})(this,function(){"use strict";const l={BLUE:"blue",GREEN:"green",PINK:"pink",RED:"red",VIOLET:"violet",WHITE:"white",BROWN:"red"},h=1/2**32;class j{float(e=1){return this.int()*h*e}norm(e=1){return(this.int()*h-.5)*2*e}minmax(e,s){return this.float()*(s-e)+e}minmaxInt(e,s){return e|=0,s|=0,e+(this.float()*(s-e)|0)}}const m=Math.random;class S extends j{int(){return m()*4294967296>>>0}float(e=1){return m()*e}norm(e=1){return(m()-.5)*2*e}}const a=new S,k={noise:l.WHITE,scale:2,peaks:2,randomAlgorithm:a,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1},y={version:"1.1.0",date:"2022-10-04T02:13:31.946Z"},b=(t,e,s)=>{const o=new Array(t);for(let n=0;n<t;n++)o[n]=s.norm(e);return o},R=t=>t.reduce((e,s)=>e+s,0);function*N(t,e){const s=[t[Symbol.iterator](),e[Symbol.iterator]()];for(let o=0;;o^=1){const n=s[o].next();if(n.done)return;yield n.value}}function*v(t=2,e=1,s=a){const o=b(t,e,s);o.forEach((i,u)=>o[u]=u&1?i:-i);const n=1/t;let r=R(o);for(let i=0,u=-1;;++i>=t&&(i=0))r-=o[i],r+=o[i]=u*s.norm(e),u^=4294967294,yield u*r*n}const T=(t=2,e=1,s=a)=>N(v(t,e,s),v(t,e,s)),G=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*A(t=8,e=1,s=a){const o=b(t,e,s),n=1/t;let r=R(o);for(let i=0;;i=i+1>>>0){const u=G(i)%t;r-=o[u],r+=o[u]=s.norm(e),yield r*n}}function*g(t=2,e=1,s=a){const o=b(t,e,s),n=1/t;let r=R(o);for(let i=0;;++i>=t&&(i=0))r-=o[i],r+=o[i]=s.norm(e),yield r*n}const $=(t=2,e=1,s=a)=>N(g(t,e,s),g(t,e,s));function*w(t=1,e=a){for(;;)yield e.norm(t)}const x=(t,e)=>t!=null&&typeof t[e]=="function",F=t=>x(t,"xform")?t.xform():t,C=t=>t!=null&&typeof t[Symbol.iterator]=="function";class d{constructor(e){this.value=e}deref(){return this.value}}const B=t=>new d(t),D=t=>t instanceof d,L=t=>t instanceof d?t:new d(t),I=t=>t instanceof d?t.deref():t,Q=(t,e)=>[t,s=>s,e];function W(t){return t?[...t]:Q(()=>[],(e,s)=>(e.push(s),e))}function*q(t,e){const s=F(t)(W()),o=s[1],n=s[2];for(let r of e){const i=n([],r);if(D(i)){yield*I(o(i.deref()));return}i.length&&(yield*i)}yield*I(o([]))}const H=(t,e)=>[t[0],t[1],e];function E(t,e){return C(e)?q(E(t),e):s=>{const o=s[2];let n=t;return H(s,(r,i)=>--n>0?o(r,i):n===0?L(o(r,i)):B(r))}}class f{constructor(e,s){this.noise=w,this.ctx=e,this.options={...k,...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.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,console.debug(`[Reverb.js] Set dry/wet ratio to ${e*100}%`)}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(),console.debug(`[Reverb.js] Set inpulse response time length to ${e}sec.`)}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(),console.debug(`[Reverb.js] Set inpulse response decay level to ${e}.`)}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(),console.debug(`[Reverb.js] Set inpulse response delay time to ${e}sec.`)}reverse(e){this.options.reverse=e,this.buildImpulse(),console.debug(`[Reverb.js] Inpulse response is ${e?"":"not "}reversed.`)}filterType(e){this.filterNode.type=this.options.filterType=e,console.debug(`[Reverb.js] Set filter type to ${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,console.debug(`[Reverb.js] Set filter frequency to ${e}Hz.`)}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,console.debug(`[Reverb.js] Set filter Q to ${e}.`)}peaks(e){this.options.peaks=e,this.buildImpulse(),console.debug(`[Reverb.js] Set IR source noise peaks to ${e}.`)}scale(e){this.options.scale=e,this.buildImpulse(),console.debug(`[Reverb.js] Set IR source noise scale to ${e}.`)}randomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse(),console.debug(`[Reverb.js] Set IR source noise generator to ${e}.`)}setNoise(e){switch(this.options.noise=e,e){case l.BLUE:this.noise=v;break;case l.GREEN:this.noise=T;break;case l.PINK:this.noise=A;break;case l.RED:case l.BROWN:this.noise=g;break;case l.VIOLET:this.noise=$;break;default:this.noise=w;break}this.buildImpulse(),console.debug(`[Reverb.js] Set IR generator source noise type to ${e}.`)}setRandomAlgorythm(e){this.options.randomAlgorithm=e,this.buildImpulse()}inRange(e,s,o){return(e-s)*(e-o)<=0}buildImpulse(){const e=this.ctx.sampleRate,s=Math.max(e*this.options.time,1),o=e*this.options.delay,n=this.ctx.createBuffer(2,s,e),r=new Float32Array(s),i=new Float32Array(s),u=this.getNoise(s),M=this.getNoise(s);for(let c=0;c<s;c++){let p=0;c<o?(r[c]=0,i[c]=0,p=this.options.reverse?s-(c-o):c-o):p=this.options.reverse?s-c:c,r[c]=u[c]*(1-p/s)**this.options.decay,i[c]=M[c]*(1-p/s)**this.options.decay}n.getChannelData(0).set(r),n.getChannelData(1).set(i),this.convolverNode.buffer=n}getNoise(e){return[...E(e,this.options.noise===l.WHITE?this.noise(this.options.peaks,this.options.randomAlgorithm):this.noise(this.options.peaks,this.options.scale,this.options.randomAlgorithm))]}}return f.version=y.version,f.build=y.date,window.Reverb||(window.Reverb=f),f});
@@ -1,10 +1,21 @@
1
- import { NoiseType } from '../NoiseType';
1
+ import { type NoiseType } from '../NoiseType';
2
+ import type { INorm } from '@thi.ng/random';
2
3
  /** Reverb Option */
3
4
  export default interface OptionInterface {
4
- /** Types of impulse response noise generation algorithms */
5
+ /**
6
+ * IR (Inpulse Response) colord noise algorithm (BLUE, GREEN, PINK, RED, VIOLET, WHITE)
7
+ * @see {@link https://github.com/thi-ng/umbrella/tree/develop/packages/colored-noise}
8
+ */
5
9
  noise: NoiseType;
6
- /** IR Power */
7
- power: number;
10
+ /** IR source noise scale */
11
+ scale: number;
12
+ /** Number of IR source noise peaks */
13
+ peaks: number;
14
+ /**
15
+ * Randam noise algorythm
16
+ * @see {@link https://github.com/thi-ng/umbrella/tree/develop/packages/random}
17
+ */
18
+ randomAlgorithm: INorm;
8
19
  /** Decay */
9
20
  decay: number;
10
21
  /** Delay until impulse response is generated */
@@ -24,4 +35,6 @@ export default interface OptionInterface {
24
35
  /** Prevents multiple effectors from being connected. */
25
36
  once: boolean;
26
37
  }
38
+ /** デフォルト値 */
39
+ export declare const defaults: OptionInterface;
27
40
  //# sourceMappingURL=OptionInterface.d.ts.map
@@ -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,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"}
1
+ {"version":3,"file":"OptionInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/OptionInterface.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAG5C,oBAAoB;AACpB,MAAM,CAAC,OAAO,WAAW,eAAe;IACtC;;;OAGG;IACH,KAAK,EAAE,SAAS,CAAC;IACjB,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,eAAe,EAAE,KAAK,CAAC;IACvB,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;AAED,aAAa;AACb,eAAO,MAAM,QAAQ,EAAE,eActB,CAAC"}
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": "1.0.2",
4
+ "version": "1.1.0",
5
5
  "description": "JavaScript Reverb effect class",
6
6
  "keywords": [
7
7
  "webaudio",
@@ -37,7 +37,7 @@
37
37
  }
38
38
  },
39
39
  "engines": {
40
- "node": ">=16.17.0",
40
+ "node": ">=16.17.1",
41
41
  "yarn": ">=1.22.10"
42
42
  },
43
43
  "packageManager": "yarn@3.2.3",
@@ -45,19 +45,20 @@
45
45
  "scripts": {
46
46
  "dev": "vite",
47
47
  "build": "vite build && tsc --declaration --emitDeclarationOnly",
48
+ "build:analyze": "vite build --mode analyze && tsc --declaration --emitDeclarationOnly ",
48
49
  "build:clean": "rimraf dist",
49
50
  "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
50
51
  "prepare": "husky install"
51
52
  },
52
53
  "dependencies": {
53
- "@thi.ng/colored-noise": "^0.3.16",
54
- "@thi.ng/transducers": "^8.3.13"
54
+ "@thi.ng/colored-noise": "^0.3.18",
55
+ "@thi.ng/transducers": "^8.3.16"
55
56
  },
56
57
  "devDependencies": {
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",
58
+ "@types/node": "^18.8.1",
59
+ "@typescript-eslint/eslint-plugin": "^5.39.0",
60
+ "@typescript-eslint/parser": "^5.39.0",
61
+ "eslint": "^8.24.0",
61
62
  "eslint-config-google": "^0.14.0",
62
63
  "eslint-config-prettier": "^8.5.0",
63
64
  "eslint-import-resolver-alias": "^1.1.2",
@@ -65,13 +66,14 @@
65
66
  "eslint-plugin-import": "^2.26.0",
66
67
  "eslint-plugin-jsdoc": "^39.3.6",
67
68
  "eslint-plugin-prettier": "^4.2.1",
68
- "eslint-plugin-tsdoc": "^0.2.16",
69
+ "eslint-plugin-tsdoc": "^0.2.17",
69
70
  "husky": "^8.0.1",
70
71
  "lint-staged": "^13.0.3",
71
72
  "prettier": "^2.7.1",
72
73
  "rimraf": "^3.0.2",
73
- "typescript": "^4.8.3",
74
- "vite": "^3.1.0",
74
+ "rollup-plugin-visualizer": "^5.8.2",
75
+ "typescript": "^4.8.4",
76
+ "vite": "^3.1.4",
75
77
  "vite-plugin-banner": "^0.5.0",
76
78
  "vite-plugin-checker": "^0.5.1"
77
79
  },