@logue/reverb 0.5.2 → 0.5.5

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)
package/dist/Meta.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type MetaInterface from '@/interfaces/MetaInterface';
1
+ import type MetaInterface from './interfaces/MetaInterface';
2
2
  declare const meta: MetaInterface;
3
3
  export default meta;
4
4
  //# sourceMappingURL=Meta.d.ts.map
package/dist/Reverb.d.ts CHANGED
@@ -2,11 +2,6 @@ import type OptionInterface from './interfaces/OptionInterface';
2
2
  import { type NoiseType } from './NoiseType';
3
3
  /**
4
4
  * JS reverb effect class
5
- *
6
- * @license MIT
7
- * @author Logue {@link logue@hotmail.co.jp}
8
- * @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
9
- * @see {@link https://github.com/logue/Reverb.js}
10
5
  */
11
6
  export default class Reverb {
12
7
  /** Version strings */
@@ -1 +1 @@
1
- {"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.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W,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"}
package/dist/reverb.es.js CHANGED
@@ -1,188 +1,111 @@
1
- const meta = {
2
- version: "0.5.2",
3
- date: "2022-03-31T15:54:38.559Z"
4
- };
5
- const Noise = {
6
- WHITE: "white",
7
- PINK: "pink",
8
- BROWN: "brown"
9
- };
10
1
  /**
11
- * JS reverb effect class
2
+ * @logue/reverb
12
3
  *
4
+ * @description JavaScript Reverb effect class
5
+ * @author Logue <logue@hotmail.co.jp>
6
+ * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
13
7
  * @license MIT
14
- * @author Logue {@link logue@hotmail.co.jp}
15
- * @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
8
+ * @version 0.5.5
16
9
  * @see {@link https://github.com/logue/Reverb.js}
17
10
  */
18
- class Reverb {
19
- constructor(ctx, options) {
20
- this.version = meta.version;
21
- this.build = meta.date;
22
- this.ctx = ctx;
23
- this._options = { ...optionDefaults, ...options };
24
- this.wetGainNode = this.ctx.createGain();
25
- this.dryGainNode = this.ctx.createGain();
26
- this.filterNode = this.ctx.createBiquadFilter();
27
- this.convolverNode = this.ctx.createConvolver();
28
- this.outputNode = this.ctx.createGain();
29
- this.isConnected = false;
30
- this.buildImpulse();
31
- this.mix(this._options.mix);
11
+
12
+ const d = {
13
+ version: "0.5.5",
14
+ date: "2022-07-21T01:15:40.735Z"
15
+ }, l = {
16
+ WHITE: "white",
17
+ PINK: "pink",
18
+ BROWN: "brown"
19
+ };
20
+ class s {
21
+ constructor(e, o) {
22
+ this.version = d.version, this.build = d.date, this.ctx = e, this._options = { ...u, ...o }, this.wetGainNode = this.ctx.createGain(), this.dryGainNode = this.ctx.createGain(), this.filterNode = this.ctx.createBiquadFilter(), this.convolverNode = this.ctx.createConvolver(), this.outputNode = this.ctx.createGain(), this.isConnected = !1, this.buildImpulse(), this.mix(this._options.mix);
32
23
  }
33
- connect(sourceNode) {
34
- if (this.isConnected && this._options.once) {
35
- this.isConnected = false;
36
- return this.outputNode;
37
- }
38
- this.convolverNode.connect(this.filterNode);
39
- this.filterNode.connect(this.wetGainNode);
40
- sourceNode.connect(this.convolverNode);
41
- sourceNode.connect(this.dryGainNode).connect(this.outputNode);
42
- sourceNode.connect(this.wetGainNode).connect(this.outputNode);
43
- this.isConnected = true;
44
- return this.outputNode;
24
+ connect(e) {
25
+ return this.isConnected && this._options.once ? (this.isConnected = !1, this.outputNode) : (this.convolverNode.connect(this.filterNode), this.filterNode.connect(this.wetGainNode), e.connect(this.convolverNode), e.connect(this.dryGainNode).connect(this.outputNode), e.connect(this.wetGainNode).connect(this.outputNode), this.isConnected = !0, this.outputNode);
45
26
  }
46
- disconnect(sourceNode) {
47
- if (this.isConnected) {
48
- this.convolverNode.disconnect(this.filterNode);
49
- this.filterNode.disconnect(this.wetGainNode);
50
- }
51
- this.isConnected = false;
52
- return sourceNode;
27
+ disconnect(e) {
28
+ return this.isConnected && (this.convolverNode.disconnect(this.filterNode), this.filterNode.disconnect(this.wetGainNode)), this.isConnected = !1, e;
53
29
  }
54
- mix(mix) {
55
- if (!this.inRange(mix, 0, 1)) {
30
+ mix(e) {
31
+ if (!this.inRange(e, 0, 1))
56
32
  throw new RangeError("Reverb.js: Dry/Wet ratio must be between 0 to 1.");
57
- }
58
- this._options.mix = mix;
59
- this.dryGainNode.gain.value = 1 - this._options.mix;
60
- this.wetGainNode.gain.value = this._options.mix;
61
- console.debug(`Reverb.js: Set dry/wet ratio to ${mix * 100}%`);
33
+ this._options.mix = e, this.dryGainNode.gain.value = 1 - this._options.mix, this.wetGainNode.gain.value = this._options.mix;
62
34
  }
63
- time(value) {
64
- if (!this.inRange(value, 1, 50)) {
35
+ time(e) {
36
+ if (!this.inRange(e, 1, 50))
65
37
  throw new RangeError("Reverb.js: Time length of inpulse response must be less than 50sec.");
66
- }
67
- this._options.time = value;
68
- this.buildImpulse();
69
- console.info(`Reverb.js: Set inpulse response time length to ${value}sec.`);
38
+ this._options.time = e, this.buildImpulse();
70
39
  }
71
- decay(value) {
72
- if (!this.inRange(value, 0, 100)) {
40
+ decay(e) {
41
+ if (!this.inRange(e, 0, 100))
73
42
  throw new RangeError("Reverb.js: Inpulse Response decay level must be less than 100.");
74
- }
75
- this._options.decay = value;
76
- this.buildImpulse();
77
- console.debug(`Reverb.js: Set inpulse response decay level to ${value}.`);
43
+ this._options.decay = e, this.buildImpulse();
78
44
  }
79
- delay(value) {
80
- if (!this.inRange(value, 0, 100)) {
45
+ delay(e) {
46
+ if (!this.inRange(e, 0, 100))
81
47
  throw new RangeError("Reverb.js: Inpulse Response delay time must be less than 100.");
82
- }
83
- this._options.delay = value;
84
- this.buildImpulse();
85
- console.debug(`Reverb.js: Set inpulse response delay time to ${value}sec.`);
48
+ this._options.delay = e, this.buildImpulse();
86
49
  }
87
- reverse(reverse) {
88
- this._options.reverse = reverse;
89
- this.buildImpulse();
90
- console.debug(`Reverb.js: Inpulse response is ${reverse ? "" : "not "}reversed.`);
50
+ reverse(e) {
51
+ this._options.reverse = e, this.buildImpulse();
91
52
  }
92
- filterType(type) {
93
- this.filterNode.type = this._options.filterType = type;
94
- console.debug(`Set filter type to ${type}`);
53
+ filterType(e) {
54
+ this.filterNode.type = this._options.filterType = e;
95
55
  }
96
- filterFreq(freq) {
97
- if (!this.inRange(freq, 20, 5e3)) {
56
+ filterFreq(e) {
57
+ if (!this.inRange(e, 20, 5e3))
98
58
  throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");
99
- }
100
- this._options.filterFreq = freq;
101
- this.filterNode.frequency.value = this._options.filterFreq;
102
- console.debug(`Set filter frequency to ${freq}Hz.`);
59
+ this._options.filterFreq = e, this.filterNode.frequency.value = this._options.filterFreq;
103
60
  }
104
- filterQ(q) {
105
- if (!this.inRange(q, 0, 10)) {
61
+ filterQ(e) {
62
+ if (!this.inRange(e, 0, 10))
106
63
  throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");
107
- }
108
- this._options.filterQ = q;
109
- this.filterNode.Q.value = this._options.filterQ;
110
- console.debug(`Set filter quality to ${q}.`);
64
+ this._options.filterQ = e, this.filterNode.Q.value = this._options.filterQ;
111
65
  }
112
- setNoise(type) {
113
- this._options.noise = type;
114
- this.buildImpulse();
115
- console.debug(`Set Noise type to ${type}.`);
66
+ setNoise(e) {
67
+ this._options.noise = e, this.buildImpulse();
116
68
  }
117
- inRange(x, min, max) {
118
- return (x - min) * (x - max) <= 0;
69
+ inRange(e, o, r) {
70
+ return (e - o) * (e - r) <= 0;
119
71
  }
120
72
  buildImpulse() {
121
- const rate = this.ctx.sampleRate;
122
- const duration = Math.max(rate * this._options.time, 1);
123
- const delayDuration = rate * this._options.delay;
124
- const impulse = this.ctx.createBuffer(2, duration, rate);
125
- const impulseL = new Float32Array(duration);
126
- const impulseR = new Float32Array(duration);
127
- const b = [0, 0, 0, 0, 0, 0, 0];
128
- for (let i = 0; i < duration; i++) {
129
- let n = 0;
130
- if (i < delayDuration) {
131
- impulseL[i] = 0;
132
- impulseR[i] = 0;
133
- n = this._options.reverse ? duration - (i - delayDuration) : i - delayDuration;
134
- } else {
135
- n = this._options.reverse ? duration - i : i;
136
- }
137
- switch (this._options.noise) {
138
- case Noise.PINK:
139
- b[0] = 0.99886 * b[0] + Reverb.whiteNoise() * 0.0555179;
140
- b[1] = 0.99332 * b[1] + Reverb.whiteNoise() * 0.0750759;
141
- b[2] = 0.969 * b[2] + Reverb.whiteNoise() * 0.153852;
142
- b[3] = 0.8665 * b[3] + Reverb.whiteNoise() * 0.3104856;
143
- b[4] = 0.55 * b[4] + Reverb.whiteNoise() * 0.5329522;
144
- b[5] = -0.7616 * b[5] - Reverb.whiteNoise() * 0.016898;
145
- impulseL[i] = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + Reverb.whiteNoise() * 0.5362;
146
- impulseR[i] = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + Reverb.whiteNoise() * 0.5362;
147
- impulseL[i] *= 0.11;
148
- impulseR[i] *= 0.11;
149
- b[6] = Reverb.whiteNoise() * 0.115926;
73
+ const e = this.ctx.sampleRate, o = Math.max(e * this._options.time, 1), r = e * this._options.delay, c = this.ctx.createBuffer(2, o, e), n = new Float32Array(o), h = new Float32Array(o), t = [0, 0, 0, 0, 0, 0, 0];
74
+ for (let i = 0; i < o; i++) {
75
+ let a = 0;
76
+ switch (i < r ? (n[i] = 0, h[i] = 0, a = this._options.reverse ? o - (i - r) : i - r) : a = this._options.reverse ? o - i : i, this._options.noise) {
77
+ case l.PINK:
78
+ t[0] = 0.99886 * t[0] + s.whiteNoise() * 0.0555179, t[1] = 0.99332 * t[1] + s.whiteNoise() * 0.0750759, t[2] = 0.969 * t[2] + s.whiteNoise() * 0.153852, t[3] = 0.8665 * t[3] + s.whiteNoise() * 0.3104856, t[4] = 0.55 * t[4] + s.whiteNoise() * 0.5329522, t[5] = -0.7616 * t[5] - s.whiteNoise() * 0.016898, n[i] = t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + t[6] + s.whiteNoise() * 0.5362, h[i] = t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + t[6] + s.whiteNoise() * 0.5362, n[i] *= 0.11, h[i] *= 0.11, t[6] = s.whiteNoise() * 0.115926;
150
79
  break;
151
- case Noise.BROWN:
152
- impulseL[i] = (b[0] + 0.02 * Reverb.whiteNoise()) / 1.02;
153
- b[0] = impulseL[i];
154
- impulseR[i] = (b[1] + 0.02 * Reverb.whiteNoise()) / 1.02;
155
- b[1] = impulseR[i];
156
- impulseL[i] *= 3.5;
157
- impulseR[i] *= 3.5;
80
+ case l.BROWN:
81
+ n[i] = (t[0] + 0.02 * s.whiteNoise()) / 1.02, t[0] = n[i], h[i] = (t[1] + 0.02 * s.whiteNoise()) / 1.02, t[1] = h[i], n[i] *= 3.5, h[i] *= 3.5;
158
82
  break;
159
- case Noise.WHITE:
83
+ case l.WHITE:
160
84
  default:
161
- impulseL[i] = Reverb.whiteNoise();
162
- impulseR[i] = Reverb.whiteNoise();
85
+ n[i] = s.whiteNoise(), h[i] = s.whiteNoise();
163
86
  break;
164
87
  }
165
- impulseL[i] *= (1 - n / duration) ** this._options.decay;
166
- impulseR[i] *= (1 - n / duration) ** this._options.decay;
88
+ n[i] *= (1 - a / o) ** this._options.decay, h[i] *= (1 - a / o) ** this._options.decay;
167
89
  }
168
- impulse.getChannelData(0).set(impulseL);
169
- impulse.getChannelData(1).set(impulseR);
170
- this.convolverNode.buffer = impulse;
90
+ c.getChannelData(0).set(n), c.getChannelData(1).set(h), this.convolverNode.buffer = c;
171
91
  }
172
92
  static whiteNoise() {
173
93
  return Math.random() * 2 - 1;
174
94
  }
175
95
  }
176
- const optionDefaults = {
177
- noise: Noise.WHITE,
96
+ const u = {
97
+ noise: l.WHITE,
178
98
  decay: 2,
179
99
  delay: 0,
180
- reverse: false,
100
+ reverse: !1,
181
101
  time: 2,
182
102
  filterType: "lowpass",
183
103
  filterFreq: 2200,
184
104
  filterQ: 1,
185
105
  mix: 0.5,
186
- once: false
106
+ once: !1
107
+ };
108
+ window.Reverb || (window.Reverb = s);
109
+ export {
110
+ s as default
187
111
  };
188
- export { Reverb as default };
@@ -1,10 +1,12 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Reverb=t()}(this,(function(){"use strict";const e="0.5.2",t="2022-03-31T15:54:38.559Z",i="white",s="pink",o="brown";
2
1
  /**
3
- * JS reverb effect class
4
- *
5
- * @license MIT
6
- * @author Logue {@link logue@hotmail.co.jp}
7
- * @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
8
- * @see {@link https://github.com/logue/Reverb.js}
9
- */
10
- class n{constructor(i,s){this.version=e,this.build=t,this.ctx=i,this._options={...r,...s},this.wetGainNode=this.ctx.createGain(),this.dryGainNode=this.ctx.createGain(),this.filterNode=this.ctx.createBiquadFilter(),this.convolverNode=this.ctx.createConvolver(),this.outputNode=this.ctx.createGain(),this.isConnected=!1,this.buildImpulse(),this.mix(this._options.mix)}connect(e){return this.isConnected&&this._options.once?(this.isConnected=!1,this.outputNode):(this.convolverNode.connect(this.filterNode),this.filterNode.connect(this.wetGainNode),e.connect(this.convolverNode),e.connect(this.dryGainNode).connect(this.outputNode),e.connect(this.wetGainNode).connect(this.outputNode),this.isConnected=!0,this.outputNode)}disconnect(e){return this.isConnected&&(this.convolverNode.disconnect(this.filterNode),this.filterNode.disconnect(this.wetGainNode)),this.isConnected=!1,e}mix(e){if(!this.inRange(e,0,1))throw new RangeError("Reverb.js: Dry/Wet ratio must be between 0 to 1.");this._options.mix=e,this.dryGainNode.gain.value=1-this._options.mix,this.wetGainNode.gain.value=this._options.mix}time(e){if(!this.inRange(e,1,50))throw new RangeError("Reverb.js: Time length of inpulse response must be less than 50sec.");this._options.time=e,this.buildImpulse()}decay(e){if(!this.inRange(e,0,100))throw new RangeError("Reverb.js: Inpulse Response decay level must be less than 100.");this._options.decay=e,this.buildImpulse()}delay(e){if(!this.inRange(e,0,100))throw new RangeError("Reverb.js: Inpulse Response delay time must be less than 100.");this._options.delay=e,this.buildImpulse()}reverse(e){this._options.reverse=e,this.buildImpulse()}filterType(e){this.filterNode.type=this._options.filterType=e}filterFreq(e){if(!this.inRange(e,20,5e3))throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");this._options.filterFreq=e,this.filterNode.frequency.value=this._options.filterFreq}filterQ(e){if(!this.inRange(e,0,10))throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");this._options.filterQ=e,this.filterNode.Q.value=this._options.filterQ}setNoise(e){this._options.noise=e,this.buildImpulse()}inRange(e,t,i){return(e-t)*(e-i)<=0}buildImpulse(){const e=this.ctx.sampleRate,t=Math.max(e*this._options.time,1),i=e*this._options.delay,r=this.ctx.createBuffer(2,t,e),h=new Float32Array(t),a=new Float32Array(t),l=[0,0,0,0,0,0,0];for(let c=0;c<t;c++){let e=0;switch(c<i?(h[c]=0,a[c]=0,e=this._options.reverse?t-(c-i):c-i):e=this._options.reverse?t-c:c,this._options.noise){case s:l[0]=.99886*l[0]+.0555179*n.whiteNoise(),l[1]=.99332*l[1]+.0750759*n.whiteNoise(),l[2]=.969*l[2]+.153852*n.whiteNoise(),l[3]=.8665*l[3]+.3104856*n.whiteNoise(),l[4]=.55*l[4]+.5329522*n.whiteNoise(),l[5]=-.7616*l[5]-.016898*n.whiteNoise(),h[c]=l[0]+l[1]+l[2]+l[3]+l[4]+l[5]+l[6]+.5362*n.whiteNoise(),a[c]=l[0]+l[1]+l[2]+l[3]+l[4]+l[5]+l[6]+.5362*n.whiteNoise(),h[c]*=.11,a[c]*=.11,l[6]=.115926*n.whiteNoise();break;case o:h[c]=(l[0]+.02*n.whiteNoise())/1.02,l[0]=h[c],a[c]=(l[1]+.02*n.whiteNoise())/1.02,l[1]=a[c],h[c]*=3.5,a[c]*=3.5;break;default:h[c]=n.whiteNoise(),a[c]=n.whiteNoise()}h[c]*=(1-e/t)**this._options.decay,a[c]*=(1-e/t)**this._options.decay}r.getChannelData(0).set(h),r.getChannelData(1).set(a),this.convolverNode.buffer=r}static whiteNoise(){return 2*Math.random()-1}}const r={noise:i,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return n}));
2
+ * @logue/reverb
3
+ *
4
+ * @description JavaScript Reverb effect class
5
+ * @author Logue <logue@hotmail.co.jp>
6
+ * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
+ * @license MIT
8
+ * @version 0.5.5
9
+ * @see {@link https://github.com/logue/Reverb.js}
10
+ */
11
+
12
+ (function(a,r){typeof exports=="object"&&typeof module<"u"?module.exports=r():typeof define=="function"&&define.amd?define(r):(a=typeof globalThis<"u"?globalThis:a||self,a.Reverb=r())})(this,function(){"use strict";const a={version:"0.5.5",date:"2022-07-21T01:15:40.735Z"},r={WHITE:"white",PINK:"pink",BROWN:"brown"};class s{constructor(e,o){this.version=a.version,this.build=a.date,this.ctx=e,this._options={...u,...o},this.wetGainNode=this.ctx.createGain(),this.dryGainNode=this.ctx.createGain(),this.filterNode=this.ctx.createBiquadFilter(),this.convolverNode=this.ctx.createConvolver(),this.outputNode=this.ctx.createGain(),this.isConnected=!1,this.buildImpulse(),this.mix(this._options.mix)}connect(e){return this.isConnected&&this._options.once?(this.isConnected=!1,this.outputNode):(this.convolverNode.connect(this.filterNode),this.filterNode.connect(this.wetGainNode),e.connect(this.convolverNode),e.connect(this.dryGainNode).connect(this.outputNode),e.connect(this.wetGainNode).connect(this.outputNode),this.isConnected=!0,this.outputNode)}disconnect(e){return this.isConnected&&(this.convolverNode.disconnect(this.filterNode),this.filterNode.disconnect(this.wetGainNode)),this.isConnected=!1,e}mix(e){if(!this.inRange(e,0,1))throw new RangeError("Reverb.js: Dry/Wet ratio must be between 0 to 1.");this._options.mix=e,this.dryGainNode.gain.value=1-this._options.mix,this.wetGainNode.gain.value=this._options.mix}time(e){if(!this.inRange(e,1,50))throw new RangeError("Reverb.js: Time length of inpulse response must be less than 50sec.");this._options.time=e,this.buildImpulse()}decay(e){if(!this.inRange(e,0,100))throw new RangeError("Reverb.js: Inpulse Response decay level must be less than 100.");this._options.decay=e,this.buildImpulse()}delay(e){if(!this.inRange(e,0,100))throw new RangeError("Reverb.js: Inpulse Response delay time must be less than 100.");this._options.delay=e,this.buildImpulse()}reverse(e){this._options.reverse=e,this.buildImpulse()}filterType(e){this.filterNode.type=this._options.filterType=e}filterFreq(e){if(!this.inRange(e,20,5e3))throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");this._options.filterFreq=e,this.filterNode.frequency.value=this._options.filterFreq}filterQ(e){if(!this.inRange(e,0,10))throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");this._options.filterQ=e,this.filterNode.Q.value=this._options.filterQ}setNoise(e){this._options.noise=e,this.buildImpulse()}inRange(e,o,l){return(e-o)*(e-l)<=0}buildImpulse(){const e=this.ctx.sampleRate,o=Math.max(e*this._options.time,1),l=e*this._options.delay,d=this.ctx.createBuffer(2,o,e),n=new Float32Array(o),h=new Float32Array(o),t=[0,0,0,0,0,0,0];for(let i=0;i<o;i++){let c=0;switch(i<l?(n[i]=0,h[i]=0,c=this._options.reverse?o-(i-l):i-l):c=this._options.reverse?o-i:i,this._options.noise){case r.PINK:t[0]=.99886*t[0]+s.whiteNoise()*.0555179,t[1]=.99332*t[1]+s.whiteNoise()*.0750759,t[2]=.969*t[2]+s.whiteNoise()*.153852,t[3]=.8665*t[3]+s.whiteNoise()*.3104856,t[4]=.55*t[4]+s.whiteNoise()*.5329522,t[5]=-.7616*t[5]-s.whiteNoise()*.016898,n[i]=t[0]+t[1]+t[2]+t[3]+t[4]+t[5]+t[6]+s.whiteNoise()*.5362,h[i]=t[0]+t[1]+t[2]+t[3]+t[4]+t[5]+t[6]+s.whiteNoise()*.5362,n[i]*=.11,h[i]*=.11,t[6]=s.whiteNoise()*.115926;break;case r.BROWN:n[i]=(t[0]+.02*s.whiteNoise())/1.02,t[0]=n[i],h[i]=(t[1]+.02*s.whiteNoise())/1.02,t[1]=h[i],n[i]*=3.5,h[i]*=3.5;break;case r.WHITE:default:n[i]=s.whiteNoise(),h[i]=s.whiteNoise();break}n[i]*=(1-c/o)**this._options.decay,h[i]*=(1-c/o)**this._options.decay}d.getChannelData(0).set(n),d.getChannelData(1).set(h),this.convolverNode.buffer=d}static whiteNoise(){return Math.random()*2-1}}const u={noise:r.WHITE,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return window.Reverb||(window.Reverb=s),s});
package/package.json CHANGED
@@ -1,29 +1,15 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@logue/reverb",
4
- "version": "0.5.2",
5
- "description": "Reverb effect.",
6
- "files": [
7
- "dist"
8
- ],
9
- "main": "./dist/reverb.umd.js",
10
- "module": "./dist/reverb.es.js",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/reverb.es.js",
14
- "require": "./dist/reverb.umd.js"
15
- }
16
- },
17
- "types": "./dist/Reverb.d.ts",
18
- "directories": {
19
- "doc": "docs"
20
- },
4
+ "version": "0.5.5",
5
+ "description": "JavaScript Reverb effect class",
21
6
  "keywords": [
22
7
  "webaudio",
23
8
  "convolver",
24
9
  "effect",
25
10
  "reverb"
26
11
  ],
12
+ "license": "MIT",
27
13
  "author": {
28
14
  "name": "Logue",
29
15
  "email": "logue@hotmail.co.jp",
@@ -37,40 +23,55 @@
37
23
  "bugs": {
38
24
  "url": "https://github.com/logue/Reverb.js/issues"
39
25
  },
26
+ "directories": {
27
+ "doc": "docs"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "main": "./dist/reverb.umd.js",
33
+ "module": "./dist/reverb.es.js",
34
+ "exports": {
35
+ ".": {
36
+ "import": "./dist/reverb.es.js",
37
+ "require": "./dist/reverb.umd.js"
38
+ }
39
+ },
40
+ "types": "./dist/Reverb.d.ts",
40
41
  "engines": {
41
- "node": ">=16"
42
+ "node": ">=16.16.0",
43
+ "yarn": ">=1.22.4"
42
44
  },
43
- "license": "MIT",
45
+ "packageManager": "yarn@3.2.1",
44
46
  "sideEffects": false,
45
47
  "scripts": {
46
48
  "dev": "vite",
47
- "build": "vite build & tsc",
49
+ "build": "vite build && tsc --declaration --emitDeclarationOnly",
48
50
  "build:clean": "rimraf dist",
49
51
  "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
50
52
  "prepare": "husky install"
51
53
  },
52
54
  "devDependencies": {
53
- "@modyqyw/vite-plugin-eslint": "^1.2.0",
54
- "@types/eslint": "^8.4.1",
55
- "@types/node": "^17.0.23",
56
- "@typescript-eslint/eslint-plugin": "^5.17.0",
57
- "@typescript-eslint/parser": "^5.17.0",
58
- "eslint": "^8.12.0",
55
+ "@types/node": "^18.0.6",
56
+ "@typescript-eslint/eslint-plugin": "^5.30.7",
57
+ "@typescript-eslint/parser": "^5.30.7",
58
+ "eslint": "^8.20.0",
59
59
  "eslint-config-google": "^0.14.0",
60
60
  "eslint-config-prettier": "^8.5.0",
61
61
  "eslint-import-resolver-alias": "^1.1.2",
62
- "eslint-import-resolver-typescript": "^2.7.0",
63
- "eslint-plugin-import": "^2.25.4",
64
- "eslint-plugin-prettier": "^4.0.0",
65
- "eslint-plugin-tsdoc": "^0.2.14",
66
- "husky": "^7.0.4",
67
- "lint-staged": "^12.3.7",
68
- "prettier": "^2.6.1",
69
- "prettier-plugin-jsdoc": "^0.3.34",
70
- "prettier-plugin-md-nocjsp": "^1.2.0",
62
+ "eslint-import-resolver-typescript": "^3.3.0",
63
+ "eslint-plugin-import": "^2.26.0",
64
+ "eslint-plugin-jsdoc": "^39.3.3",
65
+ "eslint-plugin-prettier": "^4.2.1",
66
+ "eslint-plugin-tsdoc": "^0.2.16",
67
+ "husky": "^8.0.1",
68
+ "lint-staged": "^13.0.3",
69
+ "prettier": "^2.7.1",
71
70
  "rimraf": "^3.0.2",
72
- "typescript": "^4.6.3",
73
- "vite": "^2.9.1"
71
+ "typescript": "^4.7.4",
72
+ "vite": "^3.0.2",
73
+ "vite-plugin-banner": "^0.3.0",
74
+ "vite-plugin-checker": "^0.4.9"
74
75
  },
75
76
  "husky": {
76
77
  "hooks": {
@@ -80,5 +81,8 @@
80
81
  "lint-staged": {
81
82
  "*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
82
83
  "*": "prettier -w -u"
84
+ },
85
+ "resolutions": {
86
+ "prettier": "^2.7.1"
83
87
  }
84
88
  }