@logue/reverb 0.5.4 → 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 +1 -1
- package/dist/reverb.es.js +58 -130
- package/dist/reverb.umd.js +2 -2
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Reverb.js
|
|
2
2
|
|
|
3
3
|
[](https://www.jsdelivr.com/package/npm/@logue/reverb)
|
|
4
|
-
[](https://www.npmjs.com/package/@logue/reverb)
|
|
5
5
|
[](https://uiwjs.github.io/npm-unpkg/#/pkg/@logue/reverb/file/README.md)
|
|
6
6
|
[](https://www.npmjs.com/package/@logue/reverb)
|
|
7
7
|
[](https://gitpod.io/#https://github.com/logue/Reverb.js)
|
package/dist/reverb.es.js
CHANGED
|
@@ -5,179 +5,107 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 0.5.
|
|
8
|
+
* @version 0.5.5
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
version: "0.5.
|
|
14
|
-
date: "2022-07-
|
|
15
|
-
}
|
|
16
|
-
const Noise = {
|
|
12
|
+
const d = {
|
|
13
|
+
version: "0.5.5",
|
|
14
|
+
date: "2022-07-21T01:15:40.735Z"
|
|
15
|
+
}, l = {
|
|
17
16
|
WHITE: "white",
|
|
18
17
|
PINK: "pink",
|
|
19
18
|
BROWN: "brown"
|
|
20
19
|
};
|
|
21
|
-
class
|
|
22
|
-
constructor(
|
|
23
|
-
this.version =
|
|
24
|
-
this.build = meta.date;
|
|
25
|
-
this.ctx = ctx;
|
|
26
|
-
this._options = { ...optionDefaults, ...options };
|
|
27
|
-
this.wetGainNode = this.ctx.createGain();
|
|
28
|
-
this.dryGainNode = this.ctx.createGain();
|
|
29
|
-
this.filterNode = this.ctx.createBiquadFilter();
|
|
30
|
-
this.convolverNode = this.ctx.createConvolver();
|
|
31
|
-
this.outputNode = this.ctx.createGain();
|
|
32
|
-
this.isConnected = false;
|
|
33
|
-
this.buildImpulse();
|
|
34
|
-
this.mix(this._options.mix);
|
|
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);
|
|
35
23
|
}
|
|
36
|
-
connect(
|
|
37
|
-
|
|
38
|
-
this.isConnected = false;
|
|
39
|
-
return this.outputNode;
|
|
40
|
-
}
|
|
41
|
-
this.convolverNode.connect(this.filterNode);
|
|
42
|
-
this.filterNode.connect(this.wetGainNode);
|
|
43
|
-
sourceNode.connect(this.convolverNode);
|
|
44
|
-
sourceNode.connect(this.dryGainNode).connect(this.outputNode);
|
|
45
|
-
sourceNode.connect(this.wetGainNode).connect(this.outputNode);
|
|
46
|
-
this.isConnected = true;
|
|
47
|
-
return this.outputNode;
|
|
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);
|
|
48
26
|
}
|
|
49
|
-
disconnect(
|
|
50
|
-
|
|
51
|
-
this.convolverNode.disconnect(this.filterNode);
|
|
52
|
-
this.filterNode.disconnect(this.wetGainNode);
|
|
53
|
-
}
|
|
54
|
-
this.isConnected = false;
|
|
55
|
-
return sourceNode;
|
|
27
|
+
disconnect(e) {
|
|
28
|
+
return this.isConnected && (this.convolverNode.disconnect(this.filterNode), this.filterNode.disconnect(this.wetGainNode)), this.isConnected = !1, e;
|
|
56
29
|
}
|
|
57
|
-
mix(
|
|
58
|
-
if (!this.inRange(
|
|
30
|
+
mix(e) {
|
|
31
|
+
if (!this.inRange(e, 0, 1))
|
|
59
32
|
throw new RangeError("Reverb.js: Dry/Wet ratio must be between 0 to 1.");
|
|
60
|
-
|
|
61
|
-
this._options.mix = mix;
|
|
62
|
-
this.dryGainNode.gain.value = 1 - this._options.mix;
|
|
63
|
-
this.wetGainNode.gain.value = this._options.mix;
|
|
33
|
+
this._options.mix = e, this.dryGainNode.gain.value = 1 - this._options.mix, this.wetGainNode.gain.value = this._options.mix;
|
|
64
34
|
}
|
|
65
|
-
time(
|
|
66
|
-
if (!this.inRange(
|
|
35
|
+
time(e) {
|
|
36
|
+
if (!this.inRange(e, 1, 50))
|
|
67
37
|
throw new RangeError("Reverb.js: Time length of inpulse response must be less than 50sec.");
|
|
68
|
-
|
|
69
|
-
this._options.time = value;
|
|
70
|
-
this.buildImpulse();
|
|
38
|
+
this._options.time = e, this.buildImpulse();
|
|
71
39
|
}
|
|
72
|
-
decay(
|
|
73
|
-
if (!this.inRange(
|
|
40
|
+
decay(e) {
|
|
41
|
+
if (!this.inRange(e, 0, 100))
|
|
74
42
|
throw new RangeError("Reverb.js: Inpulse Response decay level must be less than 100.");
|
|
75
|
-
|
|
76
|
-
this._options.decay = value;
|
|
77
|
-
this.buildImpulse();
|
|
43
|
+
this._options.decay = e, this.buildImpulse();
|
|
78
44
|
}
|
|
79
|
-
delay(
|
|
80
|
-
if (!this.inRange(
|
|
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();
|
|
48
|
+
this._options.delay = e, this.buildImpulse();
|
|
85
49
|
}
|
|
86
|
-
reverse(
|
|
87
|
-
this._options.reverse =
|
|
88
|
-
this.buildImpulse();
|
|
50
|
+
reverse(e) {
|
|
51
|
+
this._options.reverse = e, this.buildImpulse();
|
|
89
52
|
}
|
|
90
|
-
filterType(
|
|
91
|
-
this.filterNode.type = this._options.filterType =
|
|
53
|
+
filterType(e) {
|
|
54
|
+
this.filterNode.type = this._options.filterType = e;
|
|
92
55
|
}
|
|
93
|
-
filterFreq(
|
|
94
|
-
if (!this.inRange(
|
|
56
|
+
filterFreq(e) {
|
|
57
|
+
if (!this.inRange(e, 20, 5e3))
|
|
95
58
|
throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");
|
|
96
|
-
|
|
97
|
-
this._options.filterFreq = freq;
|
|
98
|
-
this.filterNode.frequency.value = this._options.filterFreq;
|
|
59
|
+
this._options.filterFreq = e, this.filterNode.frequency.value = this._options.filterFreq;
|
|
99
60
|
}
|
|
100
|
-
filterQ(
|
|
101
|
-
if (!this.inRange(
|
|
61
|
+
filterQ(e) {
|
|
62
|
+
if (!this.inRange(e, 0, 10))
|
|
102
63
|
throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");
|
|
103
|
-
|
|
104
|
-
this._options.filterQ = q;
|
|
105
|
-
this.filterNode.Q.value = this._options.filterQ;
|
|
106
|
-
console.debug(`Set filter quality to ${q}.`);
|
|
64
|
+
this._options.filterQ = e, this.filterNode.Q.value = this._options.filterQ;
|
|
107
65
|
}
|
|
108
|
-
setNoise(
|
|
109
|
-
this._options.noise =
|
|
110
|
-
this.buildImpulse();
|
|
66
|
+
setNoise(e) {
|
|
67
|
+
this._options.noise = e, this.buildImpulse();
|
|
111
68
|
}
|
|
112
|
-
inRange(
|
|
113
|
-
return (
|
|
69
|
+
inRange(e, o, r) {
|
|
70
|
+
return (e - o) * (e - r) <= 0;
|
|
114
71
|
}
|
|
115
72
|
buildImpulse() {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const b = [0, 0, 0, 0, 0, 0, 0];
|
|
123
|
-
for (let i = 0; i < duration; i++) {
|
|
124
|
-
let n = 0;
|
|
125
|
-
if (i < delayDuration) {
|
|
126
|
-
impulseL[i] = 0;
|
|
127
|
-
impulseR[i] = 0;
|
|
128
|
-
n = this._options.reverse ? duration - (i - delayDuration) : i - delayDuration;
|
|
129
|
-
} else {
|
|
130
|
-
n = this._options.reverse ? duration - i : i;
|
|
131
|
-
}
|
|
132
|
-
switch (this._options.noise) {
|
|
133
|
-
case Noise.PINK:
|
|
134
|
-
b[0] = 0.99886 * b[0] + Reverb.whiteNoise() * 0.0555179;
|
|
135
|
-
b[1] = 0.99332 * b[1] + Reverb.whiteNoise() * 0.0750759;
|
|
136
|
-
b[2] = 0.969 * b[2] + Reverb.whiteNoise() * 0.153852;
|
|
137
|
-
b[3] = 0.8665 * b[3] + Reverb.whiteNoise() * 0.3104856;
|
|
138
|
-
b[4] = 0.55 * b[4] + Reverb.whiteNoise() * 0.5329522;
|
|
139
|
-
b[5] = -0.7616 * b[5] - Reverb.whiteNoise() * 0.016898;
|
|
140
|
-
impulseL[i] = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + Reverb.whiteNoise() * 0.5362;
|
|
141
|
-
impulseR[i] = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + Reverb.whiteNoise() * 0.5362;
|
|
142
|
-
impulseL[i] *= 0.11;
|
|
143
|
-
impulseR[i] *= 0.11;
|
|
144
|
-
b[6] = Reverb.whiteNoise() * 0.115926;
|
|
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;
|
|
145
79
|
break;
|
|
146
|
-
case
|
|
147
|
-
|
|
148
|
-
b[0] = impulseL[i];
|
|
149
|
-
impulseR[i] = (b[1] + 0.02 * Reverb.whiteNoise()) / 1.02;
|
|
150
|
-
b[1] = impulseR[i];
|
|
151
|
-
impulseL[i] *= 3.5;
|
|
152
|
-
impulseR[i] *= 3.5;
|
|
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;
|
|
153
82
|
break;
|
|
154
|
-
case
|
|
83
|
+
case l.WHITE:
|
|
155
84
|
default:
|
|
156
|
-
|
|
157
|
-
impulseR[i] = Reverb.whiteNoise();
|
|
85
|
+
n[i] = s.whiteNoise(), h[i] = s.whiteNoise();
|
|
158
86
|
break;
|
|
159
87
|
}
|
|
160
|
-
|
|
161
|
-
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;
|
|
162
89
|
}
|
|
163
|
-
|
|
164
|
-
impulse.getChannelData(1).set(impulseR);
|
|
165
|
-
this.convolverNode.buffer = impulse;
|
|
90
|
+
c.getChannelData(0).set(n), c.getChannelData(1).set(h), this.convolverNode.buffer = c;
|
|
166
91
|
}
|
|
167
92
|
static whiteNoise() {
|
|
168
93
|
return Math.random() * 2 - 1;
|
|
169
94
|
}
|
|
170
95
|
}
|
|
171
|
-
const
|
|
172
|
-
noise:
|
|
96
|
+
const u = {
|
|
97
|
+
noise: l.WHITE,
|
|
173
98
|
decay: 2,
|
|
174
99
|
delay: 0,
|
|
175
|
-
reverse:
|
|
100
|
+
reverse: !1,
|
|
176
101
|
time: 2,
|
|
177
102
|
filterType: "lowpass",
|
|
178
103
|
filterFreq: 2200,
|
|
179
104
|
filterQ: 1,
|
|
180
105
|
mix: 0.5,
|
|
181
|
-
once:
|
|
106
|
+
once: !1
|
|
107
|
+
};
|
|
108
|
+
window.Reverb || (window.Reverb = s);
|
|
109
|
+
export {
|
|
110
|
+
s as default
|
|
182
111
|
};
|
|
183
|
-
export { Reverb as default };
|
package/dist/reverb.umd.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 0.5.
|
|
8
|
+
* @version 0.5.5
|
|
9
9
|
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@logue/reverb",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.5",
|
|
5
5
|
"description": "JavaScript Reverb effect class",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webaudio",
|
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
"prepare": "husky install"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@types/node": "^18.0.
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^5.30.
|
|
57
|
-
"@typescript-eslint/parser": "^5.30.
|
|
58
|
-
"eslint": "^8.
|
|
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": "^3.
|
|
62
|
+
"eslint-import-resolver-typescript": "^3.3.0",
|
|
63
63
|
"eslint-plugin-import": "^2.26.0",
|
|
64
64
|
"eslint-plugin-jsdoc": "^39.3.3",
|
|
65
65
|
"eslint-plugin-prettier": "^4.2.1",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"prettier": "^2.7.1",
|
|
70
70
|
"rimraf": "^3.0.2",
|
|
71
71
|
"typescript": "^4.7.4",
|
|
72
|
-
"vite": "^
|
|
72
|
+
"vite": "^3.0.2",
|
|
73
73
|
"vite-plugin-banner": "^0.3.0",
|
|
74
|
-
"vite-plugin-checker": "^0.4.
|
|
74
|
+
"vite-plugin-checker": "^0.4.9"
|
|
75
75
|
},
|
|
76
76
|
"husky": {
|
|
77
77
|
"hooks": {
|