@logue/reverb 1.5.2 → 1.6.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 +39 -31
- package/dist/Reverb.d.ts +180 -136
- package/dist/Reverb.es.js +235 -302
- package/dist/Reverb.es.js.map +1 -0
- package/dist/Reverb.umd.js +11 -10
- package/dist/Reverb.umd.js.map +1 -0
- package/package.json +34 -64
- package/dist/Meta.d.ts +0 -3
- package/dist/NoiseType.d.ts +0 -4
- package/dist/Reverb.iife.js +0 -12
- package/dist/demo.d.ts +0 -1
- package/dist/demo.flac +0 -0
- package/dist/interfaces/MetaInterface.d.ts +0 -7
- package/dist/interfaces/OptionInterface.d.ts +0 -39
package/README.md
CHANGED
|
@@ -16,6 +16,45 @@ This script is originally a spin out of [sf2synth.js](https://github.com/logue/s
|
|
|
16
16
|
- <https://logue.dev/Reverb.js/>
|
|
17
17
|
- <https://logue.dev/Reverb.js/localaudio.html>
|
|
18
18
|
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm install @logue/reverb @thi.ng/colored-noise @thi.ng/transducers @thi.ng/random
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import Reverb from '@logue/reverb';
|
|
29
|
+
|
|
30
|
+
// Setup Audio Context
|
|
31
|
+
const ctx = new window.AudioContext();
|
|
32
|
+
|
|
33
|
+
// iOS fix.
|
|
34
|
+
document.addEventListener('touchstart', initAudioContext);
|
|
35
|
+
function initAudioContext() {
|
|
36
|
+
document.removeEventListener('touchstart', initAudioContext);
|
|
37
|
+
// wake up AudioContext
|
|
38
|
+
const emptySource = ctx.createBufferSource();
|
|
39
|
+
emptySource.start();
|
|
40
|
+
emptySource.stop();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Setup Reverb Class
|
|
44
|
+
const reverb = new Reverb(ctx, {});
|
|
45
|
+
|
|
46
|
+
// put Audio data to audio buffer source
|
|
47
|
+
const sourceNode = ctx.createBufferSource();
|
|
48
|
+
sourceNode.buffer = [AudioBuffer];
|
|
49
|
+
|
|
50
|
+
// Connect Reverb
|
|
51
|
+
reverb.connect(sourceNode);
|
|
52
|
+
sourceNode.connect(ctx.destination);
|
|
53
|
+
|
|
54
|
+
// fire
|
|
55
|
+
sourceNode.play();
|
|
56
|
+
```
|
|
57
|
+
|
|
19
58
|
## Syntax
|
|
20
59
|
|
|
21
60
|
```js
|
|
@@ -56,37 +95,6 @@ const reverb = new Reverb(ctx, {
|
|
|
56
95
|
});
|
|
57
96
|
```
|
|
58
97
|
|
|
59
|
-
## Usage
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
// Setup Audio Context
|
|
63
|
-
const ctx = new window.AudioContext();
|
|
64
|
-
|
|
65
|
-
// iOS fix.
|
|
66
|
-
document.addEventListener('touchstart', initAudioContext);
|
|
67
|
-
function initAudioContext() {
|
|
68
|
-
document.removeEventListener('touchstart', initAudioContext);
|
|
69
|
-
// wake up AudioContext
|
|
70
|
-
const emptySource = ctx.createBufferSource();
|
|
71
|
-
emptySource.start();
|
|
72
|
-
emptySource.stop();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Setup Reverb Class
|
|
76
|
-
const reverb = new Reverb(ctx, {});
|
|
77
|
-
|
|
78
|
-
// put Audio data to audio buffer source
|
|
79
|
-
const sourceNode = ctx.createBufferSource();
|
|
80
|
-
sourceNode.buffer = [AudioBuffer];
|
|
81
|
-
|
|
82
|
-
// Connect Reverb
|
|
83
|
-
reverb.connect(sourceNode);
|
|
84
|
-
sourceNode.connect(ctx.destination);
|
|
85
|
-
|
|
86
|
-
// fire
|
|
87
|
-
sourceNode.play();
|
|
88
|
-
```
|
|
89
|
-
|
|
90
98
|
## Testing
|
|
91
99
|
|
|
92
100
|
This project includes a comprehensive test suite to ensure reliability and code quality.
|
package/dist/Reverb.d.ts
CHANGED
|
@@ -1,141 +1,185 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ColoredNoiseOpts } from '@thi.ng/colored-noise';
|
|
2
2
|
import { INorm } from '@thi.ng/random';
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
/** Noise Type */
|
|
5
|
+
export type NoiseType = "blue" | "brown" | "green" | "pink" | "red" | "violet" | "white";
|
|
6
|
+
declare const NoiseType: Record<NoiseType, (opts?: Partial<ColoredNoiseOpts>) => Generator<number, void, unknown>>;
|
|
7
|
+
/** Reverb Option */
|
|
8
|
+
export interface OptionInterface {
|
|
9
|
+
/**
|
|
10
|
+
* IR (Inpulse Response) colord noise algorithm (BLUE, GREEN, PINK, RED, VIOLET, WHITE)
|
|
11
|
+
* @see {@link https://github.com/thi-ng/umbrella/tree/develop/packages/colored-noise}
|
|
12
|
+
*/
|
|
13
|
+
noise: NoiseType;
|
|
14
|
+
/** IR source noise scale */
|
|
15
|
+
scale: number;
|
|
16
|
+
/** Number of IR source noise peaks */
|
|
17
|
+
peaks: number;
|
|
18
|
+
/**
|
|
19
|
+
* Randam noise algorythm
|
|
20
|
+
* @see {@link https://github.com/thi-ng/umbrella/tree/develop/packages/random}
|
|
21
|
+
*/
|
|
22
|
+
randomAlgorithm: INorm;
|
|
23
|
+
/** Decay */
|
|
24
|
+
decay: number;
|
|
25
|
+
/** Delay until impulse response is generated */
|
|
26
|
+
delay: number;
|
|
27
|
+
/** Filter frequency applied to impulse response[Hz] */
|
|
28
|
+
filterFreq: number;
|
|
29
|
+
/** Filter quality for impulse response */
|
|
30
|
+
filterQ: number;
|
|
31
|
+
/** Filter type for impulse response */
|
|
32
|
+
filterType: BiquadFilterType;
|
|
33
|
+
/** Dry/Wet ratio */
|
|
34
|
+
mix: number;
|
|
35
|
+
/** Invert the impulse response */
|
|
36
|
+
reverse?: boolean;
|
|
37
|
+
/** Impulse response length */
|
|
38
|
+
time: number;
|
|
39
|
+
/** Prevents multiple effectors from being connected. */
|
|
40
|
+
once: boolean;
|
|
41
|
+
}
|
|
4
42
|
/**
|
|
5
43
|
* Reverb effect class
|
|
6
44
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
45
|
+
declare class Reverb {
|
|
46
|
+
/** Version strings */
|
|
47
|
+
static readonly version: string;
|
|
48
|
+
/** Build date */
|
|
49
|
+
static readonly build: string;
|
|
50
|
+
/** AudioContext */
|
|
51
|
+
private readonly ctx;
|
|
52
|
+
/** Wet Level (Reverberated node) */
|
|
53
|
+
private readonly wetGainNode;
|
|
54
|
+
/** Dry Level (Original sound node) */
|
|
55
|
+
private readonly dryGainNode;
|
|
56
|
+
/** Impulse response filter */
|
|
57
|
+
private readonly filterNode;
|
|
58
|
+
/** Convolution node for applying impulse response */
|
|
59
|
+
private readonly convolverNode;
|
|
60
|
+
/** Output gain node */
|
|
61
|
+
private readonly outputNode;
|
|
62
|
+
/** Option */
|
|
63
|
+
private readonly options;
|
|
64
|
+
/** Connected flag */
|
|
65
|
+
private isConnected;
|
|
66
|
+
/** Noise Generator */
|
|
67
|
+
private noise;
|
|
68
|
+
/**
|
|
69
|
+
* Map of noise types to their respective generator functions.
|
|
70
|
+
*/
|
|
71
|
+
private readonly noiseMap;
|
|
72
|
+
/**
|
|
73
|
+
* Constructor
|
|
74
|
+
*
|
|
75
|
+
* @param ctx - Root AudioContext
|
|
76
|
+
* @param options - Configure
|
|
77
|
+
*/
|
|
78
|
+
constructor(ctx: AudioContext, options?: Partial<OptionInterface>);
|
|
79
|
+
/**
|
|
80
|
+
* Connect the node for the reverb effect to the original sound node.
|
|
81
|
+
*
|
|
82
|
+
* @param sourceNode - Input source node
|
|
83
|
+
*/
|
|
84
|
+
connect(sourceNode: AudioNode): AudioNode;
|
|
85
|
+
/**
|
|
86
|
+
* Disconnect the reverb node
|
|
87
|
+
*
|
|
88
|
+
* @param sourceNode - Input source node
|
|
89
|
+
*/
|
|
90
|
+
disconnect(sourceNode?: AudioNode): AudioNode | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Dry/Wet ratio
|
|
93
|
+
*
|
|
94
|
+
* @param mix - Ratio (0~1)
|
|
95
|
+
*/
|
|
96
|
+
mix(mix: number): void;
|
|
97
|
+
/**
|
|
98
|
+
* Set Impulse Response time length (second)
|
|
99
|
+
*
|
|
100
|
+
* @param value - IR length
|
|
101
|
+
*/
|
|
102
|
+
time(value: number): void;
|
|
103
|
+
/**
|
|
104
|
+
* Impulse response decay rate.
|
|
105
|
+
*
|
|
106
|
+
* @param value - Decay value
|
|
107
|
+
*/
|
|
108
|
+
decay(value: number): void;
|
|
109
|
+
/**
|
|
110
|
+
* Delay before reverberation starts
|
|
111
|
+
*
|
|
112
|
+
* @param value - Time[ms]
|
|
113
|
+
*/
|
|
114
|
+
delay(value: number): void;
|
|
115
|
+
/**
|
|
116
|
+
* Reverse the impulse response.
|
|
117
|
+
*
|
|
118
|
+
* @param reverse - Reverse IR
|
|
119
|
+
*/
|
|
120
|
+
reverse(reverse: boolean): void;
|
|
121
|
+
/**
|
|
122
|
+
* Filter for impulse response
|
|
123
|
+
*
|
|
124
|
+
* @param type - Filiter Type
|
|
125
|
+
*/
|
|
126
|
+
filterType(type?: BiquadFilterType): void;
|
|
127
|
+
/**
|
|
128
|
+
* Filter frequency applied to impulse response
|
|
129
|
+
*
|
|
130
|
+
* @param freq - Frequency
|
|
131
|
+
*/
|
|
132
|
+
filterFreq(freq: number): void;
|
|
133
|
+
/**
|
|
134
|
+
* Filter quality.
|
|
135
|
+
*
|
|
136
|
+
* @param q - Quality
|
|
137
|
+
*/
|
|
138
|
+
filterQ(q: number): void;
|
|
139
|
+
/**
|
|
140
|
+
* set IR source noise peaks
|
|
141
|
+
*
|
|
142
|
+
* @param p - Peaks
|
|
143
|
+
*/
|
|
144
|
+
peaks(p: number): void;
|
|
145
|
+
/**
|
|
146
|
+
* set IR source noise scale.
|
|
147
|
+
*
|
|
148
|
+
* @param s - Scale
|
|
149
|
+
*/
|
|
150
|
+
scale(s: number): void;
|
|
151
|
+
/**
|
|
152
|
+
* Noise source
|
|
153
|
+
*
|
|
154
|
+
* @param duration - length of IR.
|
|
155
|
+
*/
|
|
156
|
+
private getNoise;
|
|
157
|
+
/**
|
|
158
|
+
* Inpulse Response Noise algorithm.
|
|
159
|
+
*
|
|
160
|
+
* @param type - IR noise algorithm type.
|
|
161
|
+
*/
|
|
162
|
+
setNoise(type: NoiseType): void;
|
|
163
|
+
/**
|
|
164
|
+
* Set the random number algorithm used for noise generation.
|
|
165
|
+
*
|
|
166
|
+
* @param algorithm - Random algorithm implementing {@link INorm}
|
|
167
|
+
*/
|
|
168
|
+
setRandomAlgorithm(algorithm: INorm): void;
|
|
169
|
+
/**
|
|
170
|
+
* Return true if in range, otherwise false
|
|
171
|
+
*
|
|
172
|
+
* @param x - Target value
|
|
173
|
+
* @param min - Minimum value
|
|
174
|
+
* @param max - Maximum value
|
|
175
|
+
*/
|
|
176
|
+
private static inRange;
|
|
177
|
+
/** Builds the impulse response buffer from the current options. */
|
|
178
|
+
private buildImpulse;
|
|
141
179
|
}
|
|
180
|
+
|
|
181
|
+
export {
|
|
182
|
+
Reverb as default,
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export {};
|