@logue/reverb 0.4.4 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -10
- package/dist/reverb.es.js +188 -0
- package/dist/reverb.umd.js +10 -0
- package/package.json +59 -44
- package/types/Meta.d.ts +4 -0
- package/types/Meta.d.ts.map +1 -0
- package/types/NoiseType.d.ts +14 -0
- package/types/NoiseType.d.ts.map +1 -0
- package/types/Reverb.d.ts +118 -0
- package/types/Reverb.d.ts.map +1 -0
- package/{src/interfaces/MetaInterface.ts → types/interfaces/MetaInterface.d.ts} +2 -3
- package/{dist → types}/interfaces/MetaInterface.d.ts.map +1 -1
- package/{src/interfaces/OptionInterface.ts → types/interfaces/OptionInterface.d.ts} +5 -5
- package/types/interfaces/OptionInterface.d.ts.map +1 -0
- package/.eslintignore +0 -4
- package/.eslintrc.js +0 -21
- package/.gitattributes +0 -1
- package/.prettierrc.js +0 -3
- package/bin/reverb.js +0 -432
- package/bin/reverb.js.map +0 -1
- package/bin/reverb.min.js +0 -2
- package/bin/reverb.min.js.LICENSE.txt +0 -11
- package/dist/Meta.d.ts +0 -4
- package/dist/Meta.d.ts.map +0 -1
- package/dist/Meta.js +0 -9
- package/dist/Meta.js.map +0 -1
- package/dist/NoiseType.d.ts +0 -7
- package/dist/NoiseType.d.ts.map +0 -1
- package/dist/NoiseType.js +0 -12
- package/dist/NoiseType.js.map +0 -1
- package/dist/Reverb.d.ts +0 -114
- package/dist/Reverb.d.ts.map +0 -1
- package/dist/Reverb.js +0 -331
- package/dist/Reverb.js.map +0 -1
- package/dist/interfaces/MetaInterface.d.ts +0 -10
- package/dist/interfaces/MetaInterface.js +0 -3
- package/dist/interfaces/MetaInterface.js.map +0 -1
- package/dist/interfaces/OptionInterface.d.ts +0 -25
- package/dist/interfaces/OptionInterface.d.ts.map +0 -1
- package/dist/interfaces/OptionInterface.js +0 -3
- package/dist/interfaces/OptionInterface.js.map +0 -1
- package/docs/demo.wav +0 -0
- package/docs/index.html +0 -365
- package/docs/localaudio.html +0 -718
- package/docs/reverb.js +0 -432
- package/docs/reverb.js.map +0 -1
- package/src/Meta.ts +0 -8
- package/src/NoiseType.ts +0 -7
- package/src/Reverb.ts +0 -366
- package/tsconfig.json +0 -32
- package/webpack.config.ts +0 -102
package/README.md
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
# Reverb.js
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/%40logue%2Freverb)
|
|
4
|
-
[](https://github.com/google/gts)
|
|
5
4
|
|
|
6
5
|
Append reverb effect to audio source.
|
|
7
6
|
|
|
8
7
|
This script is originally a spin out of [sf2synth.js](https://github.com/logue/smfplayer.js)'s reverb effect.
|
|
9
8
|
|
|
10
|
-
|
|
11
9
|
## Sample
|
|
12
10
|
|
|
13
|
-
* <https://logue.
|
|
14
|
-
* <https://logue.
|
|
11
|
+
* <https://logue.dev/Reverb.js/>
|
|
12
|
+
* <https://logue.dev/Reverb.js/localaudio.html>
|
|
15
13
|
|
|
16
14
|
## Syntax
|
|
17
15
|
|
|
18
16
|
```js
|
|
19
|
-
const reverb = new Reverb
|
|
20
|
-
noise: 0, // Inpulse Response Noise algorithm (0: White noise, 1: Pink noise, 2: Brown noise)
|
|
17
|
+
const reverb = new Reverb(ctx, {
|
|
18
|
+
noise: 0, // Inpulse Response Noise algorithm (0: White noise, 1: Pink noise, 2: Brown noise)
|
|
21
19
|
decay: 5, // Amount of IR (Inpulse Response) decay. 0~100
|
|
22
|
-
delay: 0, // Delay time o IR. (NOT delay effect) 0~100 [sec]
|
|
20
|
+
delay: 0, // Delay time o IR. (NOT delay effect) 0~100 [sec]
|
|
23
21
|
filterFreq: 2200, // Filter frequency. 20~5000 [Hz]
|
|
24
22
|
filterQ: 1, // Filter quality. 0~10
|
|
25
23
|
filterType: 'lowpass', // Filter type. 'bandpass' etc. See https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode/type .
|
|
@@ -46,7 +44,7 @@ function initAudioContext() {
|
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
// Setup Reverb Class
|
|
49
|
-
const reverb = new Reverb
|
|
47
|
+
const reverb = new Reverb(ctx, {});
|
|
50
48
|
|
|
51
49
|
// put Audio data to audio buffer source
|
|
52
50
|
const sourceNode = ctx.createBufferSource();
|
|
@@ -63,10 +61,10 @@ sourceNode.play();
|
|
|
63
61
|
## Reference
|
|
64
62
|
|
|
65
63
|
* [Web Audio API](https://www.w3.org/TR/webaudio/)
|
|
66
|
-
|
|
64
|
+
* [Web Audio API日本語訳](https://g200kg.github.io/web-audio-api-ja/)
|
|
67
65
|
* [コンボルバーの使い方](https://www.g200kg.com/jp/docs/webaudio/convolver.html)
|
|
68
66
|
* [WebAudioの闇](https://qiita.com/zprodev/items/7fcd8335d7e8e613a01f)
|
|
69
67
|
|
|
70
68
|
## License
|
|
71
69
|
|
|
72
|
-
[MIT](LICENSE)
|
|
70
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
const meta = {
|
|
2
|
+
version: "0.5.0",
|
|
3
|
+
date: "2022-02-21T09:25:39.234Z"
|
|
4
|
+
};
|
|
5
|
+
const Noise = {
|
|
6
|
+
WHITE: "white",
|
|
7
|
+
PINK: "pink",
|
|
8
|
+
BROWN: "brown"
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* JS reverb effect class
|
|
12
|
+
*
|
|
13
|
+
* @license MIT
|
|
14
|
+
* @author Logue {@link logue@hotmail.co.jp}
|
|
15
|
+
* @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
16
|
+
* @see {@link https://github.com/logue/Reverb.js}
|
|
17
|
+
*/
|
|
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);
|
|
32
|
+
}
|
|
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;
|
|
45
|
+
}
|
|
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;
|
|
53
|
+
}
|
|
54
|
+
mix(mix) {
|
|
55
|
+
if (!this.inRange(mix, 0, 1)) {
|
|
56
|
+
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}%`);
|
|
62
|
+
}
|
|
63
|
+
time(value) {
|
|
64
|
+
if (!this.inRange(value, 1, 50)) {
|
|
65
|
+
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.`);
|
|
70
|
+
}
|
|
71
|
+
decay(value) {
|
|
72
|
+
if (!this.inRange(value, 0, 100)) {
|
|
73
|
+
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}.`);
|
|
78
|
+
}
|
|
79
|
+
delay(value) {
|
|
80
|
+
if (!this.inRange(value, 0, 100)) {
|
|
81
|
+
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.`);
|
|
86
|
+
}
|
|
87
|
+
reverse(reverse) {
|
|
88
|
+
this._options.reverse = reverse;
|
|
89
|
+
this.buildImpulse();
|
|
90
|
+
console.debug(`Reverb.js: Inpulse response is ${reverse ? "" : "not "}reversed.`);
|
|
91
|
+
}
|
|
92
|
+
filterType(type) {
|
|
93
|
+
this.filterNode.type = this._options.filterType = type;
|
|
94
|
+
console.debug(`Set filter type to ${type}`);
|
|
95
|
+
}
|
|
96
|
+
filterFreq(freq) {
|
|
97
|
+
if (!this.inRange(freq, 20, 5e3)) {
|
|
98
|
+
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.`);
|
|
103
|
+
}
|
|
104
|
+
filterQ(q) {
|
|
105
|
+
if (!this.inRange(q, 0, 10)) {
|
|
106
|
+
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}.`);
|
|
111
|
+
}
|
|
112
|
+
setNoise(type) {
|
|
113
|
+
this._options.noise = type;
|
|
114
|
+
this.buildImpulse();
|
|
115
|
+
console.debug(`Set Noise type to ${type}.`);
|
|
116
|
+
}
|
|
117
|
+
inRange(x, min, max) {
|
|
118
|
+
return (x - min) * (x - max) <= 0;
|
|
119
|
+
}
|
|
120
|
+
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;
|
|
150
|
+
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;
|
|
158
|
+
break;
|
|
159
|
+
case Noise.WHITE:
|
|
160
|
+
default:
|
|
161
|
+
impulseL[i] = Reverb.whiteNoise();
|
|
162
|
+
impulseR[i] = Reverb.whiteNoise();
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
impulseL[i] *= (1 - n / duration) ** this._options.decay;
|
|
166
|
+
impulseR[i] *= (1 - n / duration) ** this._options.decay;
|
|
167
|
+
}
|
|
168
|
+
impulse.getChannelData(0).set(impulseL);
|
|
169
|
+
impulse.getChannelData(1).set(impulseR);
|
|
170
|
+
this.convolverNode.buffer = impulse;
|
|
171
|
+
}
|
|
172
|
+
static whiteNoise() {
|
|
173
|
+
return Math.random() * 2 - 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const optionDefaults = {
|
|
177
|
+
noise: Noise.WHITE,
|
|
178
|
+
decay: 2,
|
|
179
|
+
delay: 0,
|
|
180
|
+
reverse: false,
|
|
181
|
+
time: 2,
|
|
182
|
+
filterType: "lowpass",
|
|
183
|
+
filterFreq: 2200,
|
|
184
|
+
filterQ: 1,
|
|
185
|
+
mix: 0.5,
|
|
186
|
+
once: false
|
|
187
|
+
};
|
|
188
|
+
export { Reverb as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
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.0",t="2022-02-21T09:25:39.234Z",i="white",s="pink",o="brown";
|
|
2
|
+
/**
|
|
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}));
|
package/package.json
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
2
3
|
"name": "@logue/reverb",
|
|
3
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
4
5
|
"description": "Reverb effect.",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"types"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/reverb.umd.js",
|
|
11
|
+
"module": "./dist/reverb.es.js",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/reverb.es.js",
|
|
15
|
+
"require": "./dist/reverb.umd.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"types": "./types/Reverb.d.ts",
|
|
8
19
|
"directories": {
|
|
9
20
|
"doc": "docs"
|
|
10
21
|
},
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "webpack --mode production",
|
|
13
|
-
"build:esm": "tsc --module es2015",
|
|
14
|
-
"dev": "webpack --mode development",
|
|
15
|
-
"serve": "webpack serve --mode development --color --progress",
|
|
16
|
-
"lint": "gts lint ./src/**/*.{js,ts}",
|
|
17
|
-
"clean": "gts clean",
|
|
18
|
-
"compile": "tsc",
|
|
19
|
-
"fix": "gts fix ./src/**/*.{js,ts}",
|
|
20
|
-
"prepare": "npm.cmd run compile",
|
|
21
|
-
"pretest": "npm.cmd run compile",
|
|
22
|
-
"posttest": "npm.cmd run lint"
|
|
23
|
-
},
|
|
24
|
-
"repository": {
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/logue/reverb.js.git"
|
|
27
|
-
},
|
|
28
22
|
"keywords": [
|
|
29
23
|
"webaudio",
|
|
30
24
|
"convolver",
|
|
@@ -36,34 +30,55 @@
|
|
|
36
30
|
"email": "logue@hotmail.co.jp",
|
|
37
31
|
"url": "https://logue.dev/"
|
|
38
32
|
},
|
|
39
|
-
"
|
|
33
|
+
"homepage": "https://github.com/logue/Reverb.js",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git@github.com:logue/Reverb.js.git"
|
|
37
|
+
},
|
|
40
38
|
"bugs": {
|
|
41
|
-
"url": "https://github.com/logue/
|
|
39
|
+
"url": "https://github.com/logue/Reverb.js/issues"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=16"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"sideEffects": false,
|
|
46
|
+
"scripts": {
|
|
47
|
+
"dev": "vite",
|
|
48
|
+
"build": "tsc && vite build",
|
|
49
|
+
"build:clean": "rimraf dist",
|
|
50
|
+
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
|
|
51
|
+
"prepare": "husky install"
|
|
42
52
|
},
|
|
43
|
-
"homepage": "https://github.com/logue/reverb.js#readme",
|
|
44
53
|
"devDependencies": {
|
|
45
|
-
"@types/
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
54
|
+
"@types/node": "^17.0.18",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^5.12.0",
|
|
56
|
+
"@typescript-eslint/parser": "^5.12.0",
|
|
57
|
+
"eslint": "^8.9.0",
|
|
58
|
+
"eslint-config-google": "^0.14.0",
|
|
59
|
+
"eslint-config-prettier": "^8.4.0",
|
|
60
|
+
"eslint-import-resolver-alias": "^1.1.2",
|
|
61
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
62
|
+
"eslint-plugin-import": "^2.25.4",
|
|
63
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
64
|
+
"eslint-plugin-tsdoc": "^0.2.14",
|
|
65
|
+
"husky": "^7.0.4",
|
|
66
|
+
"lint-staged": "^12.3.4",
|
|
67
|
+
"prettier": "^2.5.1",
|
|
68
|
+
"prettier-plugin-jsdoc": "^0.3.30",
|
|
69
|
+
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
70
|
+
"rimraf": "^3.0.2",
|
|
71
|
+
"typescript": "^4.5.5",
|
|
72
|
+
"vite": "^2.8.4",
|
|
73
|
+
"vite-plugin-eslint": "^1.3.0"
|
|
59
74
|
},
|
|
60
|
-
"
|
|
61
|
-
"
|
|
75
|
+
"husky": {
|
|
76
|
+
"hooks": {
|
|
77
|
+
"pre-commit": "lint-staged"
|
|
78
|
+
}
|
|
62
79
|
},
|
|
63
80
|
"lint-staged": {
|
|
64
|
-
"*.{js,
|
|
65
|
-
|
|
66
|
-
"git add"
|
|
67
|
-
]
|
|
81
|
+
"*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
82
|
+
"*": "prettier -w -u"
|
|
68
83
|
}
|
|
69
84
|
}
|
package/types/Meta.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Meta.d.ts","sourceRoot":"","sources":["../src/Meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,4BAA4B,CAAC;AAG5D,QAAA,MAAM,IAAI,EAAE,aAGX,CAAC;AACF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Impulse response noise generation algorithm */
|
|
2
|
+
declare const Noise: {
|
|
3
|
+
/** White noise */
|
|
4
|
+
readonly WHITE: 'white';
|
|
5
|
+
/** Pink noise */
|
|
6
|
+
readonly PINK: 'pink';
|
|
7
|
+
/** Brown Noise */
|
|
8
|
+
readonly BROWN: 'brown';
|
|
9
|
+
};
|
|
10
|
+
/** Noise Type */
|
|
11
|
+
export declare type NoiseType = typeof Noise[keyof typeof Noise];
|
|
12
|
+
/** Noise */
|
|
13
|
+
export default Noise;
|
|
14
|
+
// # sourceMappingURL=NoiseType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoiseType.d.ts","sourceRoot":"","sources":["../src/NoiseType.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,QAAA,MAAM,KAAK;IACT,kBAAkB;;IAElB,iBAAiB;;IAEjB,kBAAkB;;CAGV,CAAC;AAEX,iBAAiB;AACjB,oBAAY,SAAS,GAAG,OAAO,KAAK,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC;AAEzD,YAAY;AACZ,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type OptionInterface from './interfaces/OptionInterface';
|
|
2
|
+
import { type NoiseType } from './NoiseType';
|
|
3
|
+
/**
|
|
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
|
+
*/
|
|
11
|
+
export default class Reverb {
|
|
12
|
+
/** Version strings */
|
|
13
|
+
readonly version: string;
|
|
14
|
+
/** Build date */
|
|
15
|
+
readonly build: string;
|
|
16
|
+
/** AudioContext */
|
|
17
|
+
private readonly ctx;
|
|
18
|
+
/** Wet Level (Reverberated node) */
|
|
19
|
+
private readonly wetGainNode;
|
|
20
|
+
/** Dry Level (Original sound node) */
|
|
21
|
+
private readonly dryGainNode;
|
|
22
|
+
/** Impulse response filter */
|
|
23
|
+
private readonly filterNode;
|
|
24
|
+
/** Convolution node for applying impulse response */
|
|
25
|
+
private readonly convolverNode;
|
|
26
|
+
/** Output nodse */
|
|
27
|
+
private readonly outputNode;
|
|
28
|
+
/** Option */
|
|
29
|
+
private readonly _options;
|
|
30
|
+
/** Connected flag */
|
|
31
|
+
private isConnected;
|
|
32
|
+
/**
|
|
33
|
+
* Constructor
|
|
34
|
+
*
|
|
35
|
+
* @param ctx - Root AudioContext
|
|
36
|
+
* @param options - Configure
|
|
37
|
+
*/
|
|
38
|
+
constructor(ctx: AudioContext, options: OptionInterface | undefined);
|
|
39
|
+
/**
|
|
40
|
+
* Connect the node for the reverb effect to the original sound node.
|
|
41
|
+
*
|
|
42
|
+
* @param sourceNode - Input source node
|
|
43
|
+
*/
|
|
44
|
+
connect(sourceNode: AudioNode): AudioNode;
|
|
45
|
+
/**
|
|
46
|
+
* Disconnect the reverb node
|
|
47
|
+
*
|
|
48
|
+
* @param sourceNode - Input source node
|
|
49
|
+
*/
|
|
50
|
+
disconnect(sourceNode: AudioNode | undefined): AudioNode | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Dry/Wet ratio
|
|
53
|
+
*
|
|
54
|
+
* @param mix - Ratio (0~1)
|
|
55
|
+
*/
|
|
56
|
+
mix(mix: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Set Impulse Response time length (second)
|
|
59
|
+
*
|
|
60
|
+
* @param value - IR length
|
|
61
|
+
*/
|
|
62
|
+
time(value: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* Impulse response decay rate.
|
|
65
|
+
*
|
|
66
|
+
* @param value - Decay value
|
|
67
|
+
*/
|
|
68
|
+
decay(value: number): void;
|
|
69
|
+
/**
|
|
70
|
+
* Delay before reverberation starts
|
|
71
|
+
*
|
|
72
|
+
* @param value - Time[ms]
|
|
73
|
+
*/
|
|
74
|
+
delay(value: number): void;
|
|
75
|
+
/**
|
|
76
|
+
* Reverse the impulse response.
|
|
77
|
+
*
|
|
78
|
+
* @param reverse - Reverse IR
|
|
79
|
+
*/
|
|
80
|
+
reverse(reverse: boolean): void;
|
|
81
|
+
/**
|
|
82
|
+
* Filter for impulse response
|
|
83
|
+
*
|
|
84
|
+
* @param type - Filiter Type
|
|
85
|
+
*/
|
|
86
|
+
filterType(type: BiquadFilterType): void;
|
|
87
|
+
/**
|
|
88
|
+
* Filter frequency applied to impulse response
|
|
89
|
+
*
|
|
90
|
+
* @param freq - Frequency
|
|
91
|
+
*/
|
|
92
|
+
filterFreq(freq: number): void;
|
|
93
|
+
/**
|
|
94
|
+
* Filter quality.
|
|
95
|
+
*
|
|
96
|
+
* @param q - Quality
|
|
97
|
+
*/
|
|
98
|
+
filterQ(q: number): void;
|
|
99
|
+
/**
|
|
100
|
+
* Inpulse Response Noise algorithm.
|
|
101
|
+
*
|
|
102
|
+
* @param type - IR noise algorithm type.
|
|
103
|
+
*/
|
|
104
|
+
setNoise(type: NoiseType): void;
|
|
105
|
+
/**
|
|
106
|
+
* Return true if in range, otherwise false
|
|
107
|
+
*
|
|
108
|
+
* @param x - Target value
|
|
109
|
+
* @param min - Minimum value
|
|
110
|
+
* @param max - Maximum value
|
|
111
|
+
*/
|
|
112
|
+
private inRange;
|
|
113
|
+
/** Utility function for building an impulse response from the module parameters. */
|
|
114
|
+
private buildImpulse;
|
|
115
|
+
/** Generate white noise */
|
|
116
|
+
private static whiteNoise;
|
|
117
|
+
}
|
|
118
|
+
// # sourceMappingURL=Reverb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAChE,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iBAAiB;IACjB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,8BAA8B;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,aAAa;IACb,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,qBAAqB;IACrB,OAAO,CAAC,WAAW,CAAU;IAE7B;;;;;OAKG;gBACS,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,GAAG,SAAS;IAsBnE;;;;OAIG;IACI,OAAO,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS;IAsBhD;;;;OAIG;IACI,UAAU,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS;IAe3E;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAU7B;;;;OAIG;IACI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWhC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAQtC;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAK/C;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWrC;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAW/B;;;;OAIG;IACI,QAAQ,CAAC,IAAI,EAAE,SAAS;IAM/B;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAIf,oFAAoF;IACpF,OAAO,CAAC,YAAY;IAoGpB,2BAA2B;IAC3B,OAAO,CAAC,MAAM,CAAC,UAAU;CAI1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/MetaInterface.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MetaInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/MetaInterface.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,MAAM,CAAC,OAAO,WAAW,aAAa;IACpC,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {NoiseType} from '../NoiseType';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Reverb Option
|
|
5
|
-
*/
|
|
1
|
+
import { NoiseType } from '../NoiseType';
|
|
2
|
+
/** Reverb Option */
|
|
6
3
|
export default interface OptionInterface {
|
|
7
4
|
/** Types of impulse response noise generation algorithms */
|
|
8
5
|
noise: NoiseType;
|
|
@@ -22,4 +19,7 @@ export default interface OptionInterface {
|
|
|
22
19
|
reverse: boolean;
|
|
23
20
|
/** Impulse response length */
|
|
24
21
|
time: number;
|
|
22
|
+
/** Prevents multiple effectors from being connected. */
|
|
23
|
+
once: boolean;
|
|
25
24
|
}
|
|
25
|
+
// # sourceMappingURL=OptionInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/OptionInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,oBAAoB;AACpB,MAAM,CAAC,OAAO,WAAW,eAAe;IACtC,4DAA4D;IAC5D,KAAK,EAAE,SAAS,CAAC;IACjB,YAAY;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,EAAE,OAAO,CAAC;CACf"}
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
env: {
|
|
4
|
-
browser: true,
|
|
5
|
-
es6: true,
|
|
6
|
-
node: true,
|
|
7
|
-
},
|
|
8
|
-
extends: ['./node_modules/gts/'],
|
|
9
|
-
parserOptions: {
|
|
10
|
-
ecmaVersion: 2020,
|
|
11
|
-
},
|
|
12
|
-
overrides: [
|
|
13
|
-
{
|
|
14
|
-
files: ['webpack.config.ts'],
|
|
15
|
-
rules: {
|
|
16
|
-
'node/no-unpublished-import': 'off',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
rules: {},
|
|
21
|
-
};
|
package/.gitattributes
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
* text=auto eol=lf encoding=utf-8
|
package/.prettierrc.js
DELETED