@logue/reverb 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Reverb.d.ts.map +1 -1
- package/dist/{reverb.es.js → Reverb.es.js} +30 -18
- package/dist/Reverb.iife.js +12 -0
- package/dist/Reverb.umd.js +12 -0
- package/package.json +18 -21
- package/dist/reverb.iife.js +0 -12
- package/dist/reverb.umd.js +0 -12
package/dist/Reverb.d.ts.map
CHANGED
|
@@ -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;
|
|
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"}
|
|
@@ -5,13 +5,13 @@
|
|
|
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.
|
|
8
|
+
* @version 1.0.2
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
const g = {
|
|
13
|
-
version: "1.0.
|
|
14
|
-
date: "2022-
|
|
13
|
+
version: "1.0.2",
|
|
14
|
+
date: "2022-09-09T10:45:33.869Z"
|
|
15
15
|
}, l = {
|
|
16
16
|
BLUE: "blue",
|
|
17
17
|
GREEN: "green",
|
|
@@ -69,7 +69,7 @@ class S {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
const f = Math.random;
|
|
72
|
-
class
|
|
72
|
+
class A extends S {
|
|
73
73
|
int() {
|
|
74
74
|
return f() * 4294967296 >>> 0;
|
|
75
75
|
}
|
|
@@ -80,7 +80,7 @@ class W extends S {
|
|
|
80
80
|
return (f() - 0.5) * 2 * e;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
const h = new
|
|
83
|
+
const h = new A(), v = (t, e, i) => {
|
|
84
84
|
const s = new Array(t);
|
|
85
85
|
for (let o = 0; o < t; o++)
|
|
86
86
|
s[o] = i.norm(e);
|
|
@@ -103,7 +103,7 @@ function* p(t = 2, e = 1, i = h) {
|
|
|
103
103
|
for (let n = 0, a = -1; ; ++n >= t && (n = 0))
|
|
104
104
|
r -= s[n], r += s[n] = a * i.norm(e), a ^= 4294967294, yield a * r * o;
|
|
105
105
|
}
|
|
106
|
-
const
|
|
106
|
+
const Q = (t = 2, e = 1, i = h) => I(p(t, e, i), p(t, e, i)), W = (t) => {
|
|
107
107
|
let e = 32;
|
|
108
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
109
|
};
|
|
@@ -111,7 +111,7 @@ function* M(t = 8, e = 1, i = h) {
|
|
|
111
111
|
const s = v(t, e, i), o = 1 / t;
|
|
112
112
|
let r = b(s);
|
|
113
113
|
for (let n = 0; ; n = n + 1 >>> 0) {
|
|
114
|
-
const a =
|
|
114
|
+
const a = W(n) % t;
|
|
115
115
|
r -= s[a], r += s[a] = i.norm(e), yield r * o;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -128,7 +128,7 @@ function* R(t = 1, e = h) {
|
|
|
128
128
|
}
|
|
129
129
|
class y {
|
|
130
130
|
constructor(e, i) {
|
|
131
|
-
this.noise = R, this.ctx = e, this.options = { ...
|
|
131
|
+
this.noise = R, this.ctx = e, this.options = { ...V, ...i }, this.wetGainNode = this.ctx.createGain(), this.dryGainNode = this.ctx.createGain(), this.filterNode = this.ctx.createBiquadFilter(), this.convolverNode = this.ctx.createConvolver(), this.outputNode = this.ctx.createGain(), this.isConnected = !1, this.setNoise(this.options.noise), this.buildImpulse(), this.mix(this.options.mix);
|
|
132
132
|
}
|
|
133
133
|
connect(e) {
|
|
134
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);
|
|
@@ -138,22 +138,28 @@ class y {
|
|
|
138
138
|
}
|
|
139
139
|
mix(e) {
|
|
140
140
|
if (!this.inRange(e, 0, 1))
|
|
141
|
-
throw new RangeError("Reverb.js
|
|
141
|
+
throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
|
|
142
142
|
this.options.mix = e, this.dryGainNode.gain.value = 1 - this.options.mix, this.wetGainNode.gain.value = this.options.mix;
|
|
143
143
|
}
|
|
144
144
|
time(e) {
|
|
145
145
|
if (!this.inRange(e, 1, 50))
|
|
146
|
-
throw new RangeError(
|
|
146
|
+
throw new RangeError(
|
|
147
|
+
"[Reverb.js] Time length of inpulse response must be less than 50sec."
|
|
148
|
+
);
|
|
147
149
|
this.options.time = e, this.buildImpulse();
|
|
148
150
|
}
|
|
149
151
|
decay(e) {
|
|
150
152
|
if (!this.inRange(e, 0, 100))
|
|
151
|
-
throw new RangeError(
|
|
153
|
+
throw new RangeError(
|
|
154
|
+
"[Reverb.js] Inpulse Response decay level must be less than 100."
|
|
155
|
+
);
|
|
152
156
|
this.options.decay = e, this.buildImpulse();
|
|
153
157
|
}
|
|
154
158
|
delay(e) {
|
|
155
159
|
if (!this.inRange(e, 0, 100))
|
|
156
|
-
throw new RangeError(
|
|
160
|
+
throw new RangeError(
|
|
161
|
+
"[Reverb.js] Inpulse Response delay time must be less than 100."
|
|
162
|
+
);
|
|
157
163
|
this.options.delay = e, this.buildImpulse();
|
|
158
164
|
}
|
|
159
165
|
reverse(e) {
|
|
@@ -163,13 +169,17 @@ class y {
|
|
|
163
169
|
this.filterNode.type = this.options.filterType = e;
|
|
164
170
|
}
|
|
165
171
|
filterFreq(e) {
|
|
166
|
-
if (!this.inRange(e, 20,
|
|
167
|
-
throw new RangeError(
|
|
172
|
+
if (!this.inRange(e, 20, 2e4))
|
|
173
|
+
throw new RangeError(
|
|
174
|
+
"[Reverb.js] Filter frequrncy must be between 20 and 20000."
|
|
175
|
+
);
|
|
168
176
|
this.options.filterFreq = e, this.filterNode.frequency.value = this.options.filterFreq;
|
|
169
177
|
}
|
|
170
178
|
filterQ(e) {
|
|
171
179
|
if (!this.inRange(e, 0, 10))
|
|
172
|
-
throw new RangeError(
|
|
180
|
+
throw new RangeError(
|
|
181
|
+
"[Reverb.js] Filter quality value must be between 0 and 10."
|
|
182
|
+
);
|
|
173
183
|
this.options.filterQ = e, this.filterNode.Q.value = this.options.filterQ;
|
|
174
184
|
}
|
|
175
185
|
power(e) {
|
|
@@ -181,7 +191,7 @@ class y {
|
|
|
181
191
|
this.noise = p;
|
|
182
192
|
break;
|
|
183
193
|
case l.GREEN:
|
|
184
|
-
this.noise =
|
|
194
|
+
this.noise = Q;
|
|
185
195
|
break;
|
|
186
196
|
case l.PINK:
|
|
187
197
|
this.noise = M;
|
|
@@ -211,12 +221,14 @@ class y {
|
|
|
211
221
|
o.getChannelData(0).set(r), o.getChannelData(1).set(n), this.convolverNode.buffer = o;
|
|
212
222
|
}
|
|
213
223
|
getNoise(e) {
|
|
214
|
-
return [...E(e, this.noise())].map(
|
|
224
|
+
return [...E(e, this.noise())].map(
|
|
225
|
+
(i) => i * this.options.power
|
|
226
|
+
);
|
|
215
227
|
}
|
|
216
228
|
}
|
|
217
229
|
y.version = g.version;
|
|
218
230
|
y.build = g.date;
|
|
219
|
-
const
|
|
231
|
+
const V = {
|
|
220
232
|
noise: l.WHITE,
|
|
221
233
|
power: 2,
|
|
222
234
|
decay: 2,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @logue/reverb
|
|
3
|
+
*
|
|
4
|
+
* @description JavaScript Reverb effect class
|
|
5
|
+
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
+
* @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @version 1.0.2
|
|
9
|
+
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var Reverb=function(){"use strict";const N={version:"1.0.2",date:"2022-09-09T10:45:33.869Z"},l={BLUE:"blue",GREEN:"green",PINK:"pink",RED:"red",VIOLET:"violet",WHITE:"white",BROWN:"red"},G=(t,e)=>t!=null&&typeof t[e]=="function",T=t=>G(t,"xform")?t.xform():t,F=t=>t!=null&&typeof t[Symbol.iterator]=="function";class u{constructor(e){this.value=e}deref(){return this.value}}const k=t=>new u(t),x=t=>t instanceof u,C=t=>t instanceof u?t:new u(t),R=t=>t instanceof u?t.deref():t,D=(t,e)=>[t,i=>i,e];function j(t){return t?[...t]:D(()=>[],(e,i)=>(e.push(i),e))}function*q(t,e){const i=T(t)(j()),s=i[1],o=i[2];for(let r of e){const n=o([],r);if(x(n)){yield*R(s(n.deref()));return}n.length&&(yield*n)}yield*R(s([]))}const B=(t,e)=>[t[0],t[1],e];function w(t,e){return F(e)?q(w(t),e):i=>{const s=i[2];let o=t;return B(i,(r,n)=>--o>0?s(r,n):o===0?C(s(r,n)):k(r))}}const g=1/2**32;class L{float(e=1){return this.int()*g*e}norm(e=1){return(this.int()*g-.5)*2*e}minmax(e,i){return this.float()*(i-e)+e}minmaxInt(e,i){return e|=0,i|=0,e+(this.float()*(i-e)|0)}}const p=Math.random;class S extends L{int(){return p()*4294967296>>>0}float(e=1){return p()*e}norm(e=1){return(p()-.5)*2*e}}const h=new S,m=(t,e,i)=>{const s=new Array(t);for(let o=0;o<t;o++)s[o]=i.norm(e);return s},v=t=>t.reduce((e,i)=>e+i,0);function*E(t,e){const i=[t[Symbol.iterator](),e[Symbol.iterator]()];for(let s=0;;s^=1){const o=i[s].next();if(o.done)return;yield o.value}}function*b(t=2,e=1,i=h){const s=m(t,e,i);s.forEach((n,a)=>s[a]=a&1?n:-n);const o=1/t;let r=v(s);for(let n=0,a=-1;;++n>=t&&(n=0))r-=s[n],r+=s[n]=a*i.norm(e),a^=4294967294,yield a*r*o}const A=(t=2,e=1,i=h)=>E(b(t,e,i),b(t,e,i)),Q=t=>{let e=32;return t&=-t,t&&e--,t&65535&&(e-=16),t&16711935&&(e-=8),t&252645135&&(e-=4),t&858993459&&(e-=2),t&1431655765&&(e-=1),e};function*W(t=8,e=1,i=h){const s=m(t,e,i),o=1/t;let r=v(s);for(let n=0;;n=n+1>>>0){const a=Q(n)%t;r-=s[a],r+=s[a]=i.norm(e),yield r*o}}function*y(t=2,e=1,i=h){const s=m(t,e,i),o=1/t;let r=v(s);for(let n=0;;++n>=t&&(n=0))r-=s[n],r+=s[n]=i.norm(e),yield r*o}const M=(t=2,e=1,i=h)=>E(y(t,e,i),y(t,e,i));function*I(t=1,e=h){for(;;)yield e.norm(t)}class d{constructor(e,i){this.noise=I,this.ctx=e,this.options={...O,...i},this.wetGainNode=this.ctx.createGain(),this.dryGainNode=this.ctx.createGain(),this.filterNode=this.ctx.createBiquadFilter(),this.convolverNode=this.ctx.createConvolver(),this.outputNode=this.ctx.createGain(),this.isConnected=!1,this.setNoise(this.options.noise),this.buildImpulse(),this.mix(this.options.mix)}connect(e){return this.isConnected&&this.options.once?(this.isConnected=!1,this.outputNode):(this.convolverNode.connect(this.filterNode),this.filterNode.connect(this.wetGainNode),e.connect(this.convolverNode),e.connect(this.dryGainNode).connect(this.outputNode),e.connect(this.wetGainNode).connect(this.outputNode),this.isConnected=!0,this.outputNode)}disconnect(e){return this.isConnected&&(this.convolverNode.disconnect(this.filterNode),this.filterNode.disconnect(this.wetGainNode)),this.isConnected=!1,e}mix(e){if(!this.inRange(e,0,1))throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");this.options.mix=e,this.dryGainNode.gain.value=1-this.options.mix,this.wetGainNode.gain.value=this.options.mix}time(e){if(!this.inRange(e,1,50))throw new RangeError("[Reverb.js] Time length of inpulse response must be less than 50sec.");this.options.time=e,this.buildImpulse()}decay(e){if(!this.inRange(e,0,100))throw new RangeError("[Reverb.js] Inpulse Response decay level must be less than 100.");this.options.decay=e,this.buildImpulse()}delay(e){if(!this.inRange(e,0,100))throw new RangeError("[Reverb.js] Inpulse Response delay time must be less than 100.");this.options.delay=e,this.buildImpulse()}reverse(e){this.options.reverse=e,this.buildImpulse()}filterType(e){this.filterNode.type=this.options.filterType=e}filterFreq(e){if(!this.inRange(e,20,2e4))throw new RangeError("[Reverb.js] Filter frequrncy must be between 20 and 20000.");this.options.filterFreq=e,this.filterNode.frequency.value=this.options.filterFreq}filterQ(e){if(!this.inRange(e,0,10))throw new RangeError("[Reverb.js] Filter quality value must be between 0 and 10.");this.options.filterQ=e,this.filterNode.Q.value=this.options.filterQ}power(e){this.options.power=e,this.buildImpulse()}setNoise(e){switch(this.options.noise=e,e){case l.BLUE:this.noise=b;break;case l.GREEN:this.noise=A;break;case l.PINK:this.noise=W;break;case l.RED:case l.BROWN:this.noise=y;break;case l.VIOLET:this.noise=M;break;default:this.noise=I;break}this.buildImpulse()}inRange(e,i,s){return(e-i)*(e-s)<=0}buildImpulse(){const e=this.ctx.sampleRate,i=Math.max(e*this.options.time,1),s=e*this.options.delay,o=this.ctx.createBuffer(2,i,e),r=new Float32Array(i),n=new Float32Array(i),a=this.getNoise(i),V=this.getNoise(i);for(let c=0;c<i;c++){let f=0;c<s?(r[c]=0,n[c]=0,f=this.options.reverse?i-(c-s):c-s):f=this.options.reverse?i-c:c,r[c]=a[c]*(1-f/i)**this.options.decay,n[c]=V[c]*(1-f/i)**this.options.decay}o.getChannelData(0).set(r),o.getChannelData(1).set(n),this.convolverNode.buffer=o}getNoise(e){return[...w(e,this.noise())].map(i=>i*this.options.power)}}d.version=N.version,d.build=N.date;const O={noise:l.WHITE,power:2,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return window.Reverb||(window.Reverb=d),d}();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @logue/reverb
|
|
3
|
+
*
|
|
4
|
+
* @description JavaScript Reverb effect class
|
|
5
|
+
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
+
* @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @version 1.0.2
|
|
9
|
+
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
(function(h,l){typeof exports=="object"&&typeof module<"u"?module.exports=l():typeof define=="function"&&define.amd?define(l):(h=typeof globalThis<"u"?globalThis:h||self,h.Reverb=l())})(this,function(){"use strict";const h={version:"1.0.2",date:"2022-09-09T10:45:33.869Z"},l={BLUE:"blue",GREEN:"green",PINK:"pink",RED:"red",VIOLET:"violet",WHITE:"white",BROWN:"red"},G=(t,e)=>t!=null&&typeof t[e]=="function",T=t=>G(t,"xform")?t.xform():t,x=t=>t!=null&&typeof t[Symbol.iterator]=="function";class d{constructor(e){this.value=e}deref(){return this.value}}const F=t=>new d(t),k=t=>t instanceof d,C=t=>t instanceof d?t:new d(t),R=t=>t instanceof d?t.deref():t,j=(t,e)=>[t,i=>i,e];function D(t){return t?[...t]:j(()=>[],(e,i)=>(e.push(i),e))}function*q(t,e){const i=T(t)(D()),s=i[1],o=i[2];for(let r of e){const n=o([],r);if(k(n)){yield*R(s(n.deref()));return}n.length&&(yield*n)}yield*R(s([]))}const B=(t,e)=>[t[0],t[1],e];function w(t,e){return x(e)?q(w(t),e):i=>{const s=i[2];let o=t;return B(i,(r,n)=>--o>0?s(r,n):o===0?C(s(r,n)):F(r))}}const g=1/2**32;class L{float(e=1){return this.int()*g*e}norm(e=1){return(this.int()*g-.5)*2*e}minmax(e,i){return this.float()*(i-e)+e}minmaxInt(e,i){return e|=0,i|=0,e+(this.float()*(i-e)|0)}}const m=Math.random;class S extends L{int(){return m()*4294967296>>>0}float(e=1){return m()*e}norm(e=1){return(m()-.5)*2*e}}const u=new S,b=(t,e,i)=>{const s=new Array(t);for(let o=0;o<t;o++)s[o]=i.norm(e);return s},v=t=>t.reduce((e,i)=>e+i,0);function*E(t,e){const i=[t[Symbol.iterator](),e[Symbol.iterator]()];for(let s=0;;s^=1){const o=i[s].next();if(o.done)return;yield o.value}}function*y(t=2,e=1,i=u){const s=b(t,e,i);s.forEach((n,a)=>s[a]=a&1?n:-n);const o=1/t;let r=v(s);for(let n=0,a=-1;;++n>=t&&(n=0))r-=s[n],r+=s[n]=a*i.norm(e),a^=4294967294,yield a*r*o}const A=(t=2,e=1,i=u)=>E(y(t,e,i),y(t,e,i)),Q=t=>{let e=32;return t&=-t,t&&e--,t&65535&&(e-=16),t&16711935&&(e-=8),t&252645135&&(e-=4),t&858993459&&(e-=2),t&1431655765&&(e-=1),e};function*W(t=8,e=1,i=u){const s=b(t,e,i),o=1/t;let r=v(s);for(let n=0;;n=n+1>>>0){const a=Q(n)%t;r-=s[a],r+=s[a]=i.norm(e),yield r*o}}function*N(t=2,e=1,i=u){const s=b(t,e,i),o=1/t;let r=v(s);for(let n=0;;++n>=t&&(n=0))r-=s[n],r+=s[n]=i.norm(e),yield r*o}const M=(t=2,e=1,i=u)=>E(N(t,e,i),N(t,e,i));function*I(t=1,e=u){for(;;)yield e.norm(t)}class f{constructor(e,i){this.noise=I,this.ctx=e,this.options={...O,...i},this.wetGainNode=this.ctx.createGain(),this.dryGainNode=this.ctx.createGain(),this.filterNode=this.ctx.createBiquadFilter(),this.convolverNode=this.ctx.createConvolver(),this.outputNode=this.ctx.createGain(),this.isConnected=!1,this.setNoise(this.options.noise),this.buildImpulse(),this.mix(this.options.mix)}connect(e){return this.isConnected&&this.options.once?(this.isConnected=!1,this.outputNode):(this.convolverNode.connect(this.filterNode),this.filterNode.connect(this.wetGainNode),e.connect(this.convolverNode),e.connect(this.dryGainNode).connect(this.outputNode),e.connect(this.wetGainNode).connect(this.outputNode),this.isConnected=!0,this.outputNode)}disconnect(e){return this.isConnected&&(this.convolverNode.disconnect(this.filterNode),this.filterNode.disconnect(this.wetGainNode)),this.isConnected=!1,e}mix(e){if(!this.inRange(e,0,1))throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");this.options.mix=e,this.dryGainNode.gain.value=1-this.options.mix,this.wetGainNode.gain.value=this.options.mix}time(e){if(!this.inRange(e,1,50))throw new RangeError("[Reverb.js] Time length of inpulse response must be less than 50sec.");this.options.time=e,this.buildImpulse()}decay(e){if(!this.inRange(e,0,100))throw new RangeError("[Reverb.js] Inpulse Response decay level must be less than 100.");this.options.decay=e,this.buildImpulse()}delay(e){if(!this.inRange(e,0,100))throw new RangeError("[Reverb.js] Inpulse Response delay time must be less than 100.");this.options.delay=e,this.buildImpulse()}reverse(e){this.options.reverse=e,this.buildImpulse()}filterType(e){this.filterNode.type=this.options.filterType=e}filterFreq(e){if(!this.inRange(e,20,2e4))throw new RangeError("[Reverb.js] Filter frequrncy must be between 20 and 20000.");this.options.filterFreq=e,this.filterNode.frequency.value=this.options.filterFreq}filterQ(e){if(!this.inRange(e,0,10))throw new RangeError("[Reverb.js] Filter quality value must be between 0 and 10.");this.options.filterQ=e,this.filterNode.Q.value=this.options.filterQ}power(e){this.options.power=e,this.buildImpulse()}setNoise(e){switch(this.options.noise=e,e){case l.BLUE:this.noise=y;break;case l.GREEN:this.noise=A;break;case l.PINK:this.noise=W;break;case l.RED:case l.BROWN:this.noise=N;break;case l.VIOLET:this.noise=M;break;default:this.noise=I;break}this.buildImpulse()}inRange(e,i,s){return(e-i)*(e-s)<=0}buildImpulse(){const e=this.ctx.sampleRate,i=Math.max(e*this.options.time,1),s=e*this.options.delay,o=this.ctx.createBuffer(2,i,e),r=new Float32Array(i),n=new Float32Array(i),a=this.getNoise(i),V=this.getNoise(i);for(let c=0;c<i;c++){let p=0;c<s?(r[c]=0,n[c]=0,p=this.options.reverse?i-(c-s):c-s):p=this.options.reverse?i-c:c,r[c]=a[c]*(1-p/i)**this.options.decay,n[c]=V[c]*(1-p/i)**this.options.decay}o.getChannelData(0).set(r),o.getChannelData(1).set(n),this.convolverNode.buffer=o}getNoise(e){return[...w(e,this.noise())].map(i=>i*this.options.power)}}f.version=h.version,f.build=h.date;const O={noise:l.WHITE,power:2,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return window.Reverb||(window.Reverb=f),f});
|
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.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "JavaScript Reverb effect class",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webaudio",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"reverb"
|
|
11
11
|
],
|
|
12
12
|
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
13
14
|
"author": {
|
|
14
15
|
"name": "Logue",
|
|
15
16
|
"email": "logue@hotmail.co.jp",
|
|
@@ -23,20 +24,16 @@
|
|
|
23
24
|
"bugs": {
|
|
24
25
|
"url": "https://github.com/logue/Reverb.js/issues"
|
|
25
26
|
},
|
|
26
|
-
"directories": {
|
|
27
|
-
"doc": "docs"
|
|
28
|
-
},
|
|
29
27
|
"files": [
|
|
30
28
|
"dist"
|
|
31
29
|
],
|
|
32
|
-
"main": "dist/
|
|
33
|
-
"module": "dist/
|
|
34
|
-
"browser": "dist/reverb.iife.js",
|
|
30
|
+
"main": "dist/Reverb.umd.js",
|
|
31
|
+
"module": "dist/Reverb.es.js",
|
|
35
32
|
"types": "dist/Reverb.d.ts",
|
|
36
33
|
"exports": {
|
|
37
34
|
".": {
|
|
38
|
-
"import": "./dist/
|
|
39
|
-
"require": "./dist/
|
|
35
|
+
"import": "./dist/Reverb.es.js",
|
|
36
|
+
"require": "./dist/Reverb.umd.js"
|
|
40
37
|
}
|
|
41
38
|
},
|
|
42
39
|
"engines": {
|
|
@@ -52,15 +49,19 @@
|
|
|
52
49
|
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
|
|
53
50
|
"prepare": "husky install"
|
|
54
51
|
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@thi.ng/colored-noise": "^0.3.16",
|
|
54
|
+
"@thi.ng/transducers": "^8.3.13"
|
|
55
|
+
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@types/node": "^18.7.
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
58
|
-
"@typescript-eslint/parser": "^5.
|
|
57
|
+
"@types/node": "^18.7.16",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
59
|
+
"@typescript-eslint/parser": "^5.36.2",
|
|
59
60
|
"eslint": "^8.23.0",
|
|
60
61
|
"eslint-config-google": "^0.14.0",
|
|
61
62
|
"eslint-config-prettier": "^8.5.0",
|
|
62
63
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
63
|
-
"eslint-import-resolver-typescript": "^3.5.
|
|
64
|
+
"eslint-import-resolver-typescript": "^3.5.1",
|
|
64
65
|
"eslint-plugin-import": "^2.26.0",
|
|
65
66
|
"eslint-plugin-jsdoc": "^39.3.6",
|
|
66
67
|
"eslint-plugin-prettier": "^4.2.1",
|
|
@@ -69,10 +70,10 @@
|
|
|
69
70
|
"lint-staged": "^13.0.3",
|
|
70
71
|
"prettier": "^2.7.1",
|
|
71
72
|
"rimraf": "^3.0.2",
|
|
72
|
-
"typescript": "^4.
|
|
73
|
-
"vite": "^3.0
|
|
74
|
-
"vite-plugin-banner": "^0.
|
|
75
|
-
"vite-plugin-checker": "^0.5.
|
|
73
|
+
"typescript": "^4.8.3",
|
|
74
|
+
"vite": "^3.1.0",
|
|
75
|
+
"vite-plugin-banner": "^0.5.0",
|
|
76
|
+
"vite-plugin-checker": "^0.5.1"
|
|
76
77
|
},
|
|
77
78
|
"husky": {
|
|
78
79
|
"hooks": {
|
|
@@ -85,9 +86,5 @@
|
|
|
85
86
|
},
|
|
86
87
|
"resolutions": {
|
|
87
88
|
"prettier": "^2.7.1"
|
|
88
|
-
},
|
|
89
|
-
"dependencies": {
|
|
90
|
-
"@thi.ng/colored-noise": "^0.3.16",
|
|
91
|
-
"@thi.ng/transducers": "^8.3.13"
|
|
92
89
|
}
|
|
93
90
|
}
|
package/dist/reverb.iife.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @logue/reverb
|
|
3
|
-
*
|
|
4
|
-
* @description JavaScript Reverb effect class
|
|
5
|
-
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
-
* @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
|
|
7
|
-
* @license MIT
|
|
8
|
-
* @version 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}();
|
package/dist/reverb.umd.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @logue/reverb
|
|
3
|
-
*
|
|
4
|
-
* @description JavaScript Reverb effect class
|
|
5
|
-
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
-
* @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
|
|
7
|
-
* @license MIT
|
|
8
|
-
* @version 1.0.1
|
|
9
|
-
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
(function(h,l){typeof exports=="object"&&typeof module<"u"?module.exports=l():typeof define=="function"&&define.amd?define(l):(h=typeof globalThis<"u"?globalThis:h||self,h.Reverb=l())})(this,function(){"use strict";const h={version:"1.0.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});
|