@logue/reverb 0.4.6 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +23 -21
- package/dist/Meta.d.ts +3 -3
- package/dist/Meta.d.ts.map +1 -1
- package/dist/NoiseType.d.ts +13 -6
- package/dist/NoiseType.d.ts.map +1 -1
- package/dist/Reverb.d.ts +117 -113
- package/dist/Reverb.d.ts.map +1 -1
- package/dist/interfaces/MetaInterface.d.ts +7 -9
- package/dist/interfaces/MetaInterface.d.ts.map +1 -1
- package/dist/interfaces/OptionInterface.d.ts +24 -26
- package/dist/interfaces/OptionInterface.d.ts.map +1 -1
- package/dist/reverb.es.js +188 -0
- package/dist/reverb.umd.js +10 -0
- package/package.json +59 -45
- package/.eslintignore +0 -4
- package/.eslintrc.js +0 -21
- package/.gitattributes +0 -1
- package/.prettierrc.js +0 -3
- package/bin/reverb.js +0 -434
- 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.js +0 -9
- package/dist/Meta.js.map +0 -1
- package/dist/NoiseType.js +0 -12
- package/dist/NoiseType.js.map +0 -1
- package/dist/Reverb.js +0 -333
- package/dist/Reverb.js.map +0 -1
- package/dist/interfaces/MetaInterface.js +0 -3
- package/dist/interfaces/MetaInterface.js.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 -377
- package/docs/localaudio.html +0 -718
- package/docs/reverb.js +0 -434
- package/docs/reverb.js.map +0 -1
- package/src/Meta.ts +0 -8
- package/src/NoiseType.ts +0 -7
- package/src/Reverb.ts +0 -368
- package/src/interfaces/MetaInterface.ts +0 -9
- package/src/interfaces/OptionInterface.ts +0 -27
- package/tsconfig.json +0 -32
- package/webpack.config.ts +0 -102
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2019-
|
|
3
|
+
Copyright (c) 2019-2022 Masashi Yoshikawa <https://logue.dev>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
# Reverb.js
|
|
2
2
|
|
|
3
|
-
[](https://www.jsdelivr.com/package/npm/@logue/reverb)
|
|
4
|
+
[](https://www.npmjs.com/package/@logue/reverb)
|
|
5
|
+
[](https://uiwjs.github.io/npm-unpkg/#/pkg/@logue/reverb/file/README.md)
|
|
6
|
+
[](https://www.npmjs.com/package/@logue/reverb)
|
|
7
|
+
[](https://gitpod.io/#https://github.com/logue/Reverb.js)
|
|
5
8
|
|
|
6
9
|
Append reverb effect to audio source.
|
|
7
10
|
|
|
8
11
|
This script is originally a spin out of [sf2synth.js](https://github.com/logue/smfplayer.js)'s reverb effect.
|
|
9
12
|
|
|
10
|
-
|
|
11
13
|
## Sample
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
- <https://logue.dev/Reverb.js/>
|
|
16
|
+
- <https://logue.dev/Reverb.js/localaudio.html>
|
|
15
17
|
|
|
16
18
|
## Syntax
|
|
17
19
|
|
|
18
20
|
```js
|
|
19
|
-
const reverb = new Reverb
|
|
20
|
-
noise: 0,
|
|
21
|
-
decay: 5,
|
|
22
|
-
delay: 0,
|
|
23
|
-
filterFreq: 2200,
|
|
24
|
-
filterQ: 1,
|
|
25
|
-
filterType: 'lowpass',
|
|
26
|
-
mix: 0.5,
|
|
27
|
-
reverse: false,
|
|
28
|
-
time: 3
|
|
21
|
+
const reverb = new Reverb(ctx, {
|
|
22
|
+
noise: 0, // Inpulse Response Noise algorithm (0: White noise, 1: Pink noise, 2: Brown noise)
|
|
23
|
+
decay: 5, // Amount of IR (Inpulse Response) decay. 0~100
|
|
24
|
+
delay: 0, // Delay time o IR. (NOT delay effect) 0~100 [sec]
|
|
25
|
+
filterFreq: 2200, // Filter frequency. 20~5000 [Hz]
|
|
26
|
+
filterQ: 1, // Filter quality. 0~10
|
|
27
|
+
filterType: 'lowpass', // Filter type. 'bandpass' etc. See https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode/type .
|
|
28
|
+
mix: 0.5, // Dry (Original Sound) and Wet (Effected sound) raito. 0~1
|
|
29
|
+
reverse: false, // Reverse IR.
|
|
30
|
+
time: 3, // Time length of IR. 0~50 [sec]
|
|
29
31
|
});
|
|
30
32
|
```
|
|
31
33
|
|
|
@@ -46,7 +48,7 @@ function initAudioContext() {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
// Setup Reverb Class
|
|
49
|
-
const reverb = new Reverb
|
|
51
|
+
const reverb = new Reverb(ctx, {});
|
|
50
52
|
|
|
51
53
|
// put Audio data to audio buffer source
|
|
52
54
|
const sourceNode = ctx.createBufferSource();
|
|
@@ -62,11 +64,11 @@ sourceNode.play();
|
|
|
62
64
|
|
|
63
65
|
## Reference
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
- [Web Audio API](https://www.w3.org/TR/webaudio/)
|
|
68
|
+
- [Web Audio API 日本語訳](https://g200kg.github.io/web-audio-api-ja/)
|
|
69
|
+
- [コンボルバーの使い方](https://www.g200kg.com/jp/docs/webaudio/convolver.html)
|
|
70
|
+
- [WebAudio の闇](https://qiita.com/zprodev/items/7fcd8335d7e8e613a01f)
|
|
69
71
|
|
|
70
72
|
## License
|
|
71
73
|
|
|
72
|
-
[MIT](LICENSE)
|
|
74
|
+
[MIT](LICENSE)
|
package/dist/Meta.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import MetaInterface from '
|
|
2
|
-
declare const meta: MetaInterface;
|
|
3
|
-
export default meta;
|
|
1
|
+
import type MetaInterface from '@/interfaces/MetaInterface';
|
|
2
|
+
declare const meta: MetaInterface;
|
|
3
|
+
export default meta;
|
|
4
4
|
//# sourceMappingURL=Meta.d.ts.map
|
package/dist/Meta.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Meta.d.ts","sourceRoot":"","sources":["../src/Meta.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,4BAA4B,CAAC;
|
|
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"}
|
package/dist/NoiseType.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
/** Impulse response noise generation algorithm
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
7
14
|
//# sourceMappingURL=NoiseType.d.ts.map
|
package/dist/NoiseType.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoiseType.d.ts","sourceRoot":"","sources":["../src/NoiseType.ts"],"names":[],"mappings":"AAAA,
|
|
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"}
|
package/dist/Reverb.d.ts
CHANGED
|
@@ -1,114 +1,118 @@
|
|
|
1
|
-
import OptionInterface from './interfaces/OptionInterface';
|
|
2
|
-
import { NoiseType } from './NoiseType';
|
|
3
|
-
/**
|
|
4
|
-
* JS reverb effect class
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @see
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
* @param value
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*
|
|
96
|
-
* @
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
*
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*
|
|
111
|
-
*/
|
|
112
|
-
private
|
|
113
|
-
|
|
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
|
+
}
|
|
114
118
|
//# sourceMappingURL=Reverb.d.ts.map
|
package/dist/Reverb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,8BAA8B,CAAC;
|
|
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,10 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
date: string;
|
|
9
|
-
}
|
|
1
|
+
/** Meta Information Interface */
|
|
2
|
+
export default interface MetaInterface {
|
|
3
|
+
/** Version */
|
|
4
|
+
version: string;
|
|
5
|
+
/** Build Date */
|
|
6
|
+
date: string;
|
|
7
|
+
}
|
|
10
8
|
//# sourceMappingURL=MetaInterface.d.ts.map
|
|
@@ -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,27 +1,25 @@
|
|
|
1
|
-
import { NoiseType } from '../NoiseType';
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
/** Filter
|
|
13
|
-
|
|
14
|
-
/** Filter
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
once: boolean;
|
|
26
|
-
}
|
|
1
|
+
import { NoiseType } from '../NoiseType';
|
|
2
|
+
/** Reverb Option */
|
|
3
|
+
export default interface OptionInterface {
|
|
4
|
+
/** Types of impulse response noise generation algorithms */
|
|
5
|
+
noise: NoiseType;
|
|
6
|
+
/** Decay */
|
|
7
|
+
decay: number;
|
|
8
|
+
/** Delay until impulse response is generated */
|
|
9
|
+
delay: number;
|
|
10
|
+
/** Filter frequency applied to impulse response[Hz] */
|
|
11
|
+
filterFreq: number;
|
|
12
|
+
/** Filter quality for impulse response */
|
|
13
|
+
filterQ: number;
|
|
14
|
+
/** Filter type for impulse response */
|
|
15
|
+
filterType: BiquadFilterType;
|
|
16
|
+
/** Dry/Wet ratio */
|
|
17
|
+
mix: number;
|
|
18
|
+
/** Invert the impulse response */
|
|
19
|
+
reverse: boolean;
|
|
20
|
+
/** Impulse response length */
|
|
21
|
+
time: number;
|
|
22
|
+
/** Prevents multiple effectors from being connected. */
|
|
23
|
+
once: boolean;
|
|
24
|
+
}
|
|
27
25
|
//# sourceMappingURL=OptionInterface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptionInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/OptionInterface.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
const meta = {
|
|
2
|
+
version: "0.5.2",
|
|
3
|
+
date: "2022-03-31T15:54:38.559Z"
|
|
4
|
+
};
|
|
5
|
+
const Noise = {
|
|
6
|
+
WHITE: "white",
|
|
7
|
+
PINK: "pink",
|
|
8
|
+
BROWN: "brown"
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
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 };
|