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