@logue/reverb 1.4.5 → 1.4.7
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 +9 -1
- package/dist/Meta.d.ts +3 -0
- package/dist/NoiseType.d.ts +4 -0
- package/dist/Reverb.cjs.js +12 -0
- package/dist/Reverb.d.ts +141 -0
- package/dist/Reverb.es.js +151 -0
- package/dist/Reverb.iife.js +12 -0
- package/dist/Reverb.umd.js +12 -0
- package/dist/demo.flac +0 -0
- package/dist/interfaces/MetaInterface.d.ts +7 -0
- package/dist/interfaces/OptionInterface.d.ts +39 -0
- package/package.json +24 -23
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2019-
|
|
3
|
+
Copyright (c) 2019-2026 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
|
@@ -163,4 +163,12 @@ The dependent libraries [@thi.ng/colored-noise](https://www.jsdelivr.com/package
|
|
|
163
163
|
|
|
164
164
|
## License
|
|
165
165
|
|
|
166
|
-
©2019-
|
|
166
|
+
©2019-2026 by Logue. Licensed under the [MIT License](LICENSE).
|
|
167
|
+
|
|
168
|
+
## 🎨 Crafted for Developers
|
|
169
|
+
|
|
170
|
+
This library is built with a focus **modern developer experience**. Maintaining it involves constant testing and updates to ensure everything works seamlessly.
|
|
171
|
+
|
|
172
|
+
If you appreciate the attention to detail in this project, a small sponsorship would go a long way in supporting my work across the Vue.js and Metaverse ecosystems.
|
|
173
|
+
|
|
174
|
+
[](https://github.com/sponsors/logue)
|
package/dist/Meta.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ColoredNoiseOpts } from '@thi.ng/colored-noise';
|
|
2
|
+
/** Noise Type */
|
|
3
|
+
export type NoiseType = 'blue' | 'brown' | 'green' | 'pink' | 'red' | 'violet' | 'white';
|
|
4
|
+
export declare const NoiseType: Record<NoiseType, (opts?: Partial<ColoredNoiseOpts>) => Generator<number, void, unknown>>;
|
|
@@ -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-2026 By Masashi Yoshikawa All rights reserved.
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @version 1.4.7
|
|
9
|
+
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require(`@thi.ng/colored-noise`),t=require(`@thi.ng/transducers`),n=require(`@thi.ng/random`);var r={version:`1.4.7`,date:`2026-04-19T23:22:26.611Z`},i={blue:e.blue,brown:e.red,green:e.green,pink:e.pink,red:e.red,violet:e.violet,white:e.white},a={noise:`white`,scale:1,peaks:2,randomAlgorithm:n.SYSTEM,decay:2,delay:0,reverse:!1,time:2,filterType:`allpass`,filterFreq:2200,filterQ:1,mix:.5,once:!1},o=class n{static version=r.version;static build=r.date;ctx;wetGainNode;dryGainNode;filterNode;convolverNode;outputNode;options;isConnected;noise=e.white;noiseMap=i;constructor(e,t){this.ctx=e,this.options=Object.assign({},a,t),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.filterType(this.options.filterType),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),e.connect(this.wetGainNode),this.dryGainNode.connect(this.outputNode),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(!n.inRange(e,0,1))throw RangeError(`[Reverb.js] Dry/Wet ratio must be between 0 to 1.`);this.options.mix=e,this.dryGainNode.gain.value=1-e,this.wetGainNode.gain.value=e,console.debug(`[Reverb.js] Set dry/wet ratio to ${e*100}%`)}time(e){if(!n.inRange(e,1,50))throw RangeError(`[Reverb.js] Time length of impulse response must be less than 50sec.`);this.options.time=e,this.buildImpulse(),console.debug(`[Reverb.js] Set impulse response time length to ${e}sec.`)}decay(e){if(!n.inRange(e,0,100))throw RangeError(`[Reverb.js] Impulse Response decay level must be less than 100.`);this.options.decay=e,this.buildImpulse(),console.debug(`[Reverb.js] Set impulse response decay level to ${e}.`)}delay(e){if(!n.inRange(e,0,100))throw RangeError(`[Reverb.js] Impulse Response delay time must be less than 100.`);this.options.delay=e,this.buildImpulse(),console.debug(`[Reverb.js] Set impulse 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=`allpass`){this.filterNode.type=this.options.filterType=e,console.debug(`[Reverb.js] Set filter type to ${e}`)}filterFreq(e){if(!n.inRange(e,20,2e4))throw 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(!n.inRange(e,0,10))throw RangeError(`[Reverb.js] Filter Q 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}.`)}getNoise(e){return[...(0,t.take)(e,this.noise({bins:this.options.peaks,scale:this.options.scale,rnd:this.options.randomAlgorithm}))]}setNoise(t){switch(this.options.noise=t,t){case`blue`:this.noise=this.noiseMap.blue;break;case`brown`:this.noise=this.noiseMap.brown;break;case`green`:this.noise=this.noiseMap.green;break;case`pink`:this.noise=this.noiseMap.pink;break;case`red`:this.noise=this.noiseMap.red;break;case`violet`:this.noise=this.noiseMap.violet;break;case`white`:this.noise=this.noiseMap.white;break;default:this.noise=e.white;break}this.buildImpulse(),console.debug(`[Reverb.js] Set IR generator source noise type to ${t}.`)}setRandomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse(),console.debug(`[Reverb.js] Set IR source noise generator.`)}static inRange(e,t,n){return e>=t&&e<=n}buildImpulse(){let e=this.ctx.sampleRate,t=Math.max(e*this.options.time,1),n=e*this.options.delay,r=this.ctx.createBuffer(2,t,e),i=new Float32Array(t),a=new Float32Array(t),o=new Float32Array(1),s=new Float32Array(1),c=this.getNoise(t),l=this.getNoise(t);for(let e=0;e<t;e++){let r;e<n?(o[0]=0,s[0]=0,i.set(o,e),a.set(s,e),r=this.options.reverse??!1?t-(e-n):e-n):r=this.options.reverse??!1?t-e:e,o[0]=(c.at(e)??0)*(1-r/t)**this.options.decay,s[0]=(l.at(e)??0)*(1-r/t)**this.options.decay,i.set(o,e),a.set(s,e)}r.getChannelData(0).set(i),r.getChannelData(1).set(a),this.convolverNode.buffer=r}};exports.default=o;
|
package/dist/Reverb.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { default as OptionInterface } from './interfaces/OptionInterface';
|
|
2
|
+
import { INorm } from '@thi.ng/random';
|
|
3
|
+
import { NoiseType } from './NoiseType';
|
|
4
|
+
/**
|
|
5
|
+
* Reverb effect class
|
|
6
|
+
*/
|
|
7
|
+
export default class Reverb {
|
|
8
|
+
/** Version strings */
|
|
9
|
+
static readonly version: string;
|
|
10
|
+
/** Build date */
|
|
11
|
+
static readonly build: string;
|
|
12
|
+
/** AudioContext */
|
|
13
|
+
private readonly ctx;
|
|
14
|
+
/** Wet Level (Reverberated node) */
|
|
15
|
+
private readonly wetGainNode;
|
|
16
|
+
/** Dry Level (Original sound node) */
|
|
17
|
+
private readonly dryGainNode;
|
|
18
|
+
/** Impulse response filter */
|
|
19
|
+
private readonly filterNode;
|
|
20
|
+
/** Convolution node for applying impulse response */
|
|
21
|
+
private readonly convolverNode;
|
|
22
|
+
/** Output gain node */
|
|
23
|
+
private readonly outputNode;
|
|
24
|
+
/** Option */
|
|
25
|
+
private readonly options;
|
|
26
|
+
/** Connected flag */
|
|
27
|
+
private isConnected;
|
|
28
|
+
/** Noise Generator */
|
|
29
|
+
private noise;
|
|
30
|
+
/**
|
|
31
|
+
* Map of noise types to their respective generator functions.
|
|
32
|
+
*/
|
|
33
|
+
private readonly noiseMap;
|
|
34
|
+
/**
|
|
35
|
+
* Constructor
|
|
36
|
+
*
|
|
37
|
+
* @param ctx - Root AudioContext
|
|
38
|
+
* @param options - Configure
|
|
39
|
+
*/
|
|
40
|
+
constructor(ctx: AudioContext, options: Partial<OptionInterface>);
|
|
41
|
+
/**
|
|
42
|
+
* Connect the node for the reverb effect to the original sound node.
|
|
43
|
+
*
|
|
44
|
+
* @param sourceNode - Input source node
|
|
45
|
+
*/
|
|
46
|
+
connect(sourceNode: AudioNode): AudioNode;
|
|
47
|
+
/**
|
|
48
|
+
* Disconnect the reverb node
|
|
49
|
+
*
|
|
50
|
+
* @param sourceNode - Input source node
|
|
51
|
+
*/
|
|
52
|
+
disconnect(sourceNode?: AudioNode): AudioNode | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Dry/Wet ratio
|
|
55
|
+
*
|
|
56
|
+
* @param mix - Ratio (0~1)
|
|
57
|
+
*/
|
|
58
|
+
mix(mix: number): void;
|
|
59
|
+
/**
|
|
60
|
+
* Set Impulse Response time length (second)
|
|
61
|
+
*
|
|
62
|
+
* @param value - IR length
|
|
63
|
+
*/
|
|
64
|
+
time(value: number): void;
|
|
65
|
+
/**
|
|
66
|
+
* Impulse response decay rate.
|
|
67
|
+
*
|
|
68
|
+
* @param value - Decay value
|
|
69
|
+
*/
|
|
70
|
+
decay(value: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* Delay before reverberation starts
|
|
73
|
+
*
|
|
74
|
+
* @param value - Time[ms]
|
|
75
|
+
*/
|
|
76
|
+
delay(value: number): void;
|
|
77
|
+
/**
|
|
78
|
+
* Reverse the impulse response.
|
|
79
|
+
*
|
|
80
|
+
* @param reverse - Reverse IR
|
|
81
|
+
*/
|
|
82
|
+
reverse(reverse: boolean): void;
|
|
83
|
+
/**
|
|
84
|
+
* Filter for impulse response
|
|
85
|
+
*
|
|
86
|
+
* @param type - Filiter Type
|
|
87
|
+
*/
|
|
88
|
+
filterType(type?: BiquadFilterType): void;
|
|
89
|
+
/**
|
|
90
|
+
* Filter frequency applied to impulse response
|
|
91
|
+
*
|
|
92
|
+
* @param freq - Frequency
|
|
93
|
+
*/
|
|
94
|
+
filterFreq(freq: number): void;
|
|
95
|
+
/**
|
|
96
|
+
* Filter quality.
|
|
97
|
+
*
|
|
98
|
+
* @param q - Quality
|
|
99
|
+
*/
|
|
100
|
+
filterQ(q: number): void;
|
|
101
|
+
/**
|
|
102
|
+
* set IR source noise peaks
|
|
103
|
+
*
|
|
104
|
+
* @param p - Peaks
|
|
105
|
+
*/
|
|
106
|
+
peaks(p: number): void;
|
|
107
|
+
/**
|
|
108
|
+
* set IR source noise scale.
|
|
109
|
+
*
|
|
110
|
+
* @param s - Scale
|
|
111
|
+
*/
|
|
112
|
+
scale(s: number): void;
|
|
113
|
+
/**
|
|
114
|
+
* Noise source
|
|
115
|
+
*
|
|
116
|
+
* @param duration - length of IR.
|
|
117
|
+
*/
|
|
118
|
+
private getNoise;
|
|
119
|
+
/**
|
|
120
|
+
* Inpulse Response Noise algorithm.
|
|
121
|
+
*
|
|
122
|
+
* @param type - IR noise algorithm type.
|
|
123
|
+
*/
|
|
124
|
+
setNoise(type: NoiseType): void;
|
|
125
|
+
/**
|
|
126
|
+
* Set Random Algorythm
|
|
127
|
+
*
|
|
128
|
+
* @param algorithm - Algorythm
|
|
129
|
+
*/
|
|
130
|
+
setRandomAlgorithm(algorithm: INorm): void;
|
|
131
|
+
/**
|
|
132
|
+
* Return true if in range, otherwise false
|
|
133
|
+
*
|
|
134
|
+
* @param x - Target value
|
|
135
|
+
* @param min - Minimum value
|
|
136
|
+
* @param max - Maximum value
|
|
137
|
+
*/
|
|
138
|
+
private static inRange;
|
|
139
|
+
/** Utility function for building an impulse response from the module parameters. */
|
|
140
|
+
private buildImpulse;
|
|
141
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @logue/reverb
|
|
3
|
+
*
|
|
4
|
+
* @description JavaScript Reverb effect class
|
|
5
|
+
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
+
* @copyright 2019-2026 By Masashi Yoshikawa All rights reserved.
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @version 1.4.7
|
|
9
|
+
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { blue as e, green as t, pink as n, red as r, violet as i, white as a } from "@thi.ng/colored-noise";
|
|
13
|
+
import { take as o } from "@thi.ng/transducers";
|
|
14
|
+
import { SYSTEM as s } from "@thi.ng/random";
|
|
15
|
+
//#region src/Meta.ts
|
|
16
|
+
var c = {
|
|
17
|
+
version: "1.4.7",
|
|
18
|
+
date: "2026-04-19T23:22:26.611Z"
|
|
19
|
+
}, l = {
|
|
20
|
+
blue: e,
|
|
21
|
+
brown: r,
|
|
22
|
+
green: t,
|
|
23
|
+
pink: n,
|
|
24
|
+
red: r,
|
|
25
|
+
violet: i,
|
|
26
|
+
white: a
|
|
27
|
+
}, u = {
|
|
28
|
+
noise: "white",
|
|
29
|
+
scale: 1,
|
|
30
|
+
peaks: 2,
|
|
31
|
+
randomAlgorithm: s,
|
|
32
|
+
decay: 2,
|
|
33
|
+
delay: 0,
|
|
34
|
+
reverse: !1,
|
|
35
|
+
time: 2,
|
|
36
|
+
filterType: "allpass",
|
|
37
|
+
filterFreq: 2200,
|
|
38
|
+
filterQ: 1,
|
|
39
|
+
mix: .5,
|
|
40
|
+
once: !1
|
|
41
|
+
}, d = class e {
|
|
42
|
+
static version = c.version;
|
|
43
|
+
static build = c.date;
|
|
44
|
+
ctx;
|
|
45
|
+
wetGainNode;
|
|
46
|
+
dryGainNode;
|
|
47
|
+
filterNode;
|
|
48
|
+
convolverNode;
|
|
49
|
+
outputNode;
|
|
50
|
+
options;
|
|
51
|
+
isConnected;
|
|
52
|
+
noise = a;
|
|
53
|
+
noiseMap = l;
|
|
54
|
+
constructor(e, t) {
|
|
55
|
+
this.ctx = e, this.options = Object.assign({}, u, t), 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.filterType(this.options.filterType), this.setNoise(this.options.noise), this.buildImpulse(), this.mix(this.options.mix);
|
|
56
|
+
}
|
|
57
|
+
connect(e) {
|
|
58
|
+
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), e.connect(this.wetGainNode), this.dryGainNode.connect(this.outputNode), this.wetGainNode.connect(this.outputNode), this.isConnected = !0, this.outputNode);
|
|
59
|
+
}
|
|
60
|
+
disconnect(e) {
|
|
61
|
+
return this.isConnected && (this.convolverNode.disconnect(this.filterNode), this.filterNode.disconnect(this.wetGainNode)), this.isConnected = !1, e;
|
|
62
|
+
}
|
|
63
|
+
mix(t) {
|
|
64
|
+
if (!e.inRange(t, 0, 1)) throw RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
|
|
65
|
+
this.options.mix = t, this.dryGainNode.gain.value = 1 - t, this.wetGainNode.gain.value = t, console.debug(`[Reverb.js] Set dry/wet ratio to ${t * 100}%`);
|
|
66
|
+
}
|
|
67
|
+
time(t) {
|
|
68
|
+
if (!e.inRange(t, 1, 50)) throw RangeError("[Reverb.js] Time length of impulse response must be less than 50sec.");
|
|
69
|
+
this.options.time = t, this.buildImpulse(), console.debug(`[Reverb.js] Set impulse response time length to ${t}sec.`);
|
|
70
|
+
}
|
|
71
|
+
decay(t) {
|
|
72
|
+
if (!e.inRange(t, 0, 100)) throw RangeError("[Reverb.js] Impulse Response decay level must be less than 100.");
|
|
73
|
+
this.options.decay = t, this.buildImpulse(), console.debug(`[Reverb.js] Set impulse response decay level to ${t}.`);
|
|
74
|
+
}
|
|
75
|
+
delay(t) {
|
|
76
|
+
if (!e.inRange(t, 0, 100)) throw RangeError("[Reverb.js] Impulse Response delay time must be less than 100.");
|
|
77
|
+
this.options.delay = t, this.buildImpulse(), console.debug(`[Reverb.js] Set impulse response delay time to ${t}sec.`);
|
|
78
|
+
}
|
|
79
|
+
reverse(e) {
|
|
80
|
+
this.options.reverse = e, this.buildImpulse(), console.debug(`[Reverb.js] Inpulse response is ${e ? "" : "not "}reversed.`);
|
|
81
|
+
}
|
|
82
|
+
filterType(e = "allpass") {
|
|
83
|
+
this.filterNode.type = this.options.filterType = e, console.debug(`[Reverb.js] Set filter type to ${e}`);
|
|
84
|
+
}
|
|
85
|
+
filterFreq(t) {
|
|
86
|
+
if (!e.inRange(t, 20, 2e4)) throw RangeError("[Reverb.js] Filter frequrncy must be between 20 and 20000.");
|
|
87
|
+
this.options.filterFreq = t, this.filterNode.frequency.value = this.options.filterFreq, console.debug(`[Reverb.js] Set filter frequency to ${t}Hz.`);
|
|
88
|
+
}
|
|
89
|
+
filterQ(t) {
|
|
90
|
+
if (!e.inRange(t, 0, 10)) throw RangeError("[Reverb.js] Filter Q value must be between 0 and 10.");
|
|
91
|
+
this.options.filterQ = t, this.filterNode.Q.value = this.options.filterQ, console.debug(`[Reverb.js] Set filter Q to ${t}.`);
|
|
92
|
+
}
|
|
93
|
+
peaks(e) {
|
|
94
|
+
this.options.peaks = e, this.buildImpulse(), console.debug(`[Reverb.js] Set IR source noise peaks to ${e}.`);
|
|
95
|
+
}
|
|
96
|
+
scale(e) {
|
|
97
|
+
this.options.scale = e, this.buildImpulse(), console.debug(`[Reverb.js] Set IR source noise scale to ${e}.`);
|
|
98
|
+
}
|
|
99
|
+
getNoise(e) {
|
|
100
|
+
return [...o(e, this.noise({
|
|
101
|
+
bins: this.options.peaks,
|
|
102
|
+
scale: this.options.scale,
|
|
103
|
+
rnd: this.options.randomAlgorithm
|
|
104
|
+
}))];
|
|
105
|
+
}
|
|
106
|
+
setNoise(e) {
|
|
107
|
+
switch (this.options.noise = e, e) {
|
|
108
|
+
case "blue":
|
|
109
|
+
this.noise = this.noiseMap.blue;
|
|
110
|
+
break;
|
|
111
|
+
case "brown":
|
|
112
|
+
this.noise = this.noiseMap.brown;
|
|
113
|
+
break;
|
|
114
|
+
case "green":
|
|
115
|
+
this.noise = this.noiseMap.green;
|
|
116
|
+
break;
|
|
117
|
+
case "pink":
|
|
118
|
+
this.noise = this.noiseMap.pink;
|
|
119
|
+
break;
|
|
120
|
+
case "red":
|
|
121
|
+
this.noise = this.noiseMap.red;
|
|
122
|
+
break;
|
|
123
|
+
case "violet":
|
|
124
|
+
this.noise = this.noiseMap.violet;
|
|
125
|
+
break;
|
|
126
|
+
case "white":
|
|
127
|
+
this.noise = this.noiseMap.white;
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
this.noise = a;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
this.buildImpulse(), console.debug(`[Reverb.js] Set IR generator source noise type to ${e}.`);
|
|
134
|
+
}
|
|
135
|
+
setRandomAlgorithm(e) {
|
|
136
|
+
this.options.randomAlgorithm = e, this.buildImpulse(), console.debug("[Reverb.js] Set IR source noise generator.");
|
|
137
|
+
}
|
|
138
|
+
static inRange(e, t, n) {
|
|
139
|
+
return e >= t && e <= n;
|
|
140
|
+
}
|
|
141
|
+
buildImpulse() {
|
|
142
|
+
let e = this.ctx.sampleRate, t = Math.max(e * this.options.time, 1), n = e * this.options.delay, r = this.ctx.createBuffer(2, t, e), i = new Float32Array(t), a = new Float32Array(t), o = new Float32Array(1), s = new Float32Array(1), c = this.getNoise(t), l = this.getNoise(t);
|
|
143
|
+
for (let e = 0; e < t; e++) {
|
|
144
|
+
let r;
|
|
145
|
+
e < n ? (o[0] = 0, s[0] = 0, i.set(o, e), a.set(s, e), r = this.options.reverse ?? !1 ? t - (e - n) : e - n) : r = this.options.reverse ?? !1 ? t - e : e, o[0] = (c.at(e) ?? 0) * (1 - r / t) ** this.options.decay, s[0] = (l.at(e) ?? 0) * (1 - r / t) ** this.options.decay, i.set(o, e), a.set(s, e);
|
|
146
|
+
}
|
|
147
|
+
r.getChannelData(0).set(i), r.getChannelData(1).set(a), this.convolverNode.buffer = r;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
//#endregion
|
|
151
|
+
export { d as default };
|
|
@@ -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-2026 By Masashi Yoshikawa All rights reserved.
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @version 1.4.7
|
|
9
|
+
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var Reverb=(function(e,t,n,r){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var i={version:`1.4.7`,date:`2026-04-19T23:22:26.611Z`},a={blue:t.blue,brown:t.red,green:t.green,pink:t.pink,red:t.red,violet:t.violet,white:t.white},o={noise:`white`,scale:1,peaks:2,randomAlgorithm:r.SYSTEM,decay:2,delay:0,reverse:!1,time:2,filterType:`allpass`,filterFreq:2200,filterQ:1,mix:.5,once:!1};return e.default=class e{static version=i.version;static build=i.date;ctx;wetGainNode;dryGainNode;filterNode;convolverNode;outputNode;options;isConnected;noise=t.white;noiseMap=a;constructor(e,t){this.ctx=e,this.options=Object.assign({},o,t),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.filterType(this.options.filterType),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),e.connect(this.wetGainNode),this.dryGainNode.connect(this.outputNode),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(t){if(!e.inRange(t,0,1))throw RangeError(`[Reverb.js] Dry/Wet ratio must be between 0 to 1.`);this.options.mix=t,this.dryGainNode.gain.value=1-t,this.wetGainNode.gain.value=t,console.debug(`[Reverb.js] Set dry/wet ratio to ${t*100}%`)}time(t){if(!e.inRange(t,1,50))throw RangeError(`[Reverb.js] Time length of impulse response must be less than 50sec.`);this.options.time=t,this.buildImpulse(),console.debug(`[Reverb.js] Set impulse response time length to ${t}sec.`)}decay(t){if(!e.inRange(t,0,100))throw RangeError(`[Reverb.js] Impulse Response decay level must be less than 100.`);this.options.decay=t,this.buildImpulse(),console.debug(`[Reverb.js] Set impulse response decay level to ${t}.`)}delay(t){if(!e.inRange(t,0,100))throw RangeError(`[Reverb.js] Impulse Response delay time must be less than 100.`);this.options.delay=t,this.buildImpulse(),console.debug(`[Reverb.js] Set impulse response delay time to ${t}sec.`)}reverse(e){this.options.reverse=e,this.buildImpulse(),console.debug(`[Reverb.js] Inpulse response is ${e?``:`not `}reversed.`)}filterType(e=`allpass`){this.filterNode.type=this.options.filterType=e,console.debug(`[Reverb.js] Set filter type to ${e}`)}filterFreq(t){if(!e.inRange(t,20,2e4))throw RangeError(`[Reverb.js] Filter frequrncy must be between 20 and 20000.`);this.options.filterFreq=t,this.filterNode.frequency.value=this.options.filterFreq,console.debug(`[Reverb.js] Set filter frequency to ${t}Hz.`)}filterQ(t){if(!e.inRange(t,0,10))throw RangeError(`[Reverb.js] Filter Q value must be between 0 and 10.`);this.options.filterQ=t,this.filterNode.Q.value=this.options.filterQ,console.debug(`[Reverb.js] Set filter Q to ${t}.`)}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}.`)}getNoise(e){return[...(0,n.take)(e,this.noise({bins:this.options.peaks,scale:this.options.scale,rnd:this.options.randomAlgorithm}))]}setNoise(e){switch(this.options.noise=e,e){case`blue`:this.noise=this.noiseMap.blue;break;case`brown`:this.noise=this.noiseMap.brown;break;case`green`:this.noise=this.noiseMap.green;break;case`pink`:this.noise=this.noiseMap.pink;break;case`red`:this.noise=this.noiseMap.red;break;case`violet`:this.noise=this.noiseMap.violet;break;case`white`:this.noise=this.noiseMap.white;break;default:this.noise=t.white;break}this.buildImpulse(),console.debug(`[Reverb.js] Set IR generator source noise type to ${e}.`)}setRandomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse(),console.debug(`[Reverb.js] Set IR source noise generator.`)}static inRange(e,t,n){return e>=t&&e<=n}buildImpulse(){let e=this.ctx.sampleRate,t=Math.max(e*this.options.time,1),n=e*this.options.delay,r=this.ctx.createBuffer(2,t,e),i=new Float32Array(t),a=new Float32Array(t),o=new Float32Array(1),s=new Float32Array(1),c=this.getNoise(t),l=this.getNoise(t);for(let e=0;e<t;e++){let r;e<n?(o[0]=0,s[0]=0,i.set(o,e),a.set(s,e),r=this.options.reverse??!1?t-(e-n):e-n):r=this.options.reverse??!1?t-e:e,o[0]=(c.at(e)??0)*(1-r/t)**this.options.decay,s[0]=(l.at(e)??0)*(1-r/t)**this.options.decay,i.set(o,e),a.set(s,e)}r.getChannelData(0).set(i),r.getChannelData(1).set(a),this.convolverNode.buffer=r}},e})({},coloredNoise,transducers,random);
|
|
@@ -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-2026 By Masashi Yoshikawa All rights reserved.
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @version 1.4.7
|
|
9
|
+
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@thi.ng/colored-noise`),require(`@thi.ng/transducers`),require(`@thi.ng/random`)):typeof define==`function`&&define.amd?define([`exports`,`@thi.ng/colored-noise`,`@thi.ng/transducers`,`@thi.ng/random`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Reverb={},e.coloredNoise,e.transducers,e.random))})(this,function(e,t,n,r){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var i={version:`1.4.7`,date:`2026-04-19T23:22:26.611Z`},a={blue:t.blue,brown:t.red,green:t.green,pink:t.pink,red:t.red,violet:t.violet,white:t.white},o={noise:`white`,scale:1,peaks:2,randomAlgorithm:r.SYSTEM,decay:2,delay:0,reverse:!1,time:2,filterType:`allpass`,filterFreq:2200,filterQ:1,mix:.5,once:!1};e.default=class e{static version=i.version;static build=i.date;ctx;wetGainNode;dryGainNode;filterNode;convolverNode;outputNode;options;isConnected;noise=t.white;noiseMap=a;constructor(e,t){this.ctx=e,this.options=Object.assign({},o,t),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.filterType(this.options.filterType),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),e.connect(this.wetGainNode),this.dryGainNode.connect(this.outputNode),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(t){if(!e.inRange(t,0,1))throw RangeError(`[Reverb.js] Dry/Wet ratio must be between 0 to 1.`);this.options.mix=t,this.dryGainNode.gain.value=1-t,this.wetGainNode.gain.value=t,console.debug(`[Reverb.js] Set dry/wet ratio to ${t*100}%`)}time(t){if(!e.inRange(t,1,50))throw RangeError(`[Reverb.js] Time length of impulse response must be less than 50sec.`);this.options.time=t,this.buildImpulse(),console.debug(`[Reverb.js] Set impulse response time length to ${t}sec.`)}decay(t){if(!e.inRange(t,0,100))throw RangeError(`[Reverb.js] Impulse Response decay level must be less than 100.`);this.options.decay=t,this.buildImpulse(),console.debug(`[Reverb.js] Set impulse response decay level to ${t}.`)}delay(t){if(!e.inRange(t,0,100))throw RangeError(`[Reverb.js] Impulse Response delay time must be less than 100.`);this.options.delay=t,this.buildImpulse(),console.debug(`[Reverb.js] Set impulse response delay time to ${t}sec.`)}reverse(e){this.options.reverse=e,this.buildImpulse(),console.debug(`[Reverb.js] Inpulse response is ${e?``:`not `}reversed.`)}filterType(e=`allpass`){this.filterNode.type=this.options.filterType=e,console.debug(`[Reverb.js] Set filter type to ${e}`)}filterFreq(t){if(!e.inRange(t,20,2e4))throw RangeError(`[Reverb.js] Filter frequrncy must be between 20 and 20000.`);this.options.filterFreq=t,this.filterNode.frequency.value=this.options.filterFreq,console.debug(`[Reverb.js] Set filter frequency to ${t}Hz.`)}filterQ(t){if(!e.inRange(t,0,10))throw RangeError(`[Reverb.js] Filter Q value must be between 0 and 10.`);this.options.filterQ=t,this.filterNode.Q.value=this.options.filterQ,console.debug(`[Reverb.js] Set filter Q to ${t}.`)}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}.`)}getNoise(e){return[...(0,n.take)(e,this.noise({bins:this.options.peaks,scale:this.options.scale,rnd:this.options.randomAlgorithm}))]}setNoise(e){switch(this.options.noise=e,e){case`blue`:this.noise=this.noiseMap.blue;break;case`brown`:this.noise=this.noiseMap.brown;break;case`green`:this.noise=this.noiseMap.green;break;case`pink`:this.noise=this.noiseMap.pink;break;case`red`:this.noise=this.noiseMap.red;break;case`violet`:this.noise=this.noiseMap.violet;break;case`white`:this.noise=this.noiseMap.white;break;default:this.noise=t.white;break}this.buildImpulse(),console.debug(`[Reverb.js] Set IR generator source noise type to ${e}.`)}setRandomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse(),console.debug(`[Reverb.js] Set IR source noise generator.`)}static inRange(e,t,n){return e>=t&&e<=n}buildImpulse(){let e=this.ctx.sampleRate,t=Math.max(e*this.options.time,1),n=e*this.options.delay,r=this.ctx.createBuffer(2,t,e),i=new Float32Array(t),a=new Float32Array(t),o=new Float32Array(1),s=new Float32Array(1),c=this.getNoise(t),l=this.getNoise(t);for(let e=0;e<t;e++){let r;e<n?(o[0]=0,s[0]=0,i.set(o,e),a.set(s,e),r=this.options.reverse??!1?t-(e-n):e-n):r=this.options.reverse??!1?t-e:e,o[0]=(c.at(e)??0)*(1-r/t)**this.options.decay,s[0]=(l.at(e)??0)*(1-r/t)**this.options.decay,i.set(o,e),a.set(s,e)}r.getChannelData(0).set(i),r.getChannelData(1).set(a),this.convolverNode.buffer=r}}});
|
package/dist/demo.flac
ADDED
|
Binary file
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NoiseType } from '../NoiseType';
|
|
2
|
+
import { INorm } from '@thi.ng/random';
|
|
3
|
+
/** Reverb Option */
|
|
4
|
+
export default interface OptionInterface {
|
|
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
|
+
*/
|
|
9
|
+
noise: NoiseType;
|
|
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;
|
|
19
|
+
/** Decay */
|
|
20
|
+
decay: number;
|
|
21
|
+
/** Delay until impulse response is generated */
|
|
22
|
+
delay: number;
|
|
23
|
+
/** Filter frequency applied to impulse response[Hz] */
|
|
24
|
+
filterFreq: number;
|
|
25
|
+
/** Filter quality for impulse response */
|
|
26
|
+
filterQ: number;
|
|
27
|
+
/** Filter type for impulse response */
|
|
28
|
+
filterType: BiquadFilterType;
|
|
29
|
+
/** Dry/Wet ratio */
|
|
30
|
+
mix: number;
|
|
31
|
+
/** Invert the impulse response */
|
|
32
|
+
reverse?: boolean;
|
|
33
|
+
/** Impulse response length */
|
|
34
|
+
time: number;
|
|
35
|
+
/** Prevents multiple effectors from being connected. */
|
|
36
|
+
once: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Default Value */
|
|
39
|
+
export declare const defaults: OptionInterface;
|
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.4.
|
|
4
|
+
"version": "1.4.7",
|
|
5
5
|
"description": "JavaScript Reverb effect class",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webaudio",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"node": "^20.19.0 || >=22.12.0",
|
|
51
51
|
"pnpm": ">=10.2.0"
|
|
52
52
|
},
|
|
53
|
-
"packageManager": "pnpm@10.
|
|
53
|
+
"packageManager": "pnpm@10.33.0",
|
|
54
54
|
"sideEffects": false,
|
|
55
55
|
"scripts": {
|
|
56
56
|
"dev": "vite",
|
|
@@ -69,7 +69,8 @@
|
|
|
69
69
|
"prepare": "husky",
|
|
70
70
|
"test": "vitest",
|
|
71
71
|
"test:run": "vitest run",
|
|
72
|
-
"test:coverage": "vitest run --coverage"
|
|
72
|
+
"test:coverage": "vitest run --coverage",
|
|
73
|
+
"version": "auto-changelog -p && git add CHANGELOG.md"
|
|
73
74
|
},
|
|
74
75
|
"peerDependencies": {
|
|
75
76
|
"@thi.ng/colored-noise": "^1.0.103",
|
|
@@ -77,35 +78,36 @@
|
|
|
77
78
|
"@thi.ng/transducers": "^9.5.1"
|
|
78
79
|
},
|
|
79
80
|
"devDependencies": {
|
|
80
|
-
"@eslint/js": "^
|
|
81
|
+
"@eslint/js": "^10.0.1",
|
|
81
82
|
"@tsconfig/node-lts": "^24.0.0",
|
|
82
|
-
"@types/node": "^25.
|
|
83
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
84
|
-
"@vitest/coverage-v8": "^4.
|
|
83
|
+
"@types/node": "^25.6.0",
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^8.58.2",
|
|
85
|
+
"@vitest/coverage-v8": "^4.1.4",
|
|
85
86
|
"bootstrap": "^5.3.8",
|
|
86
|
-
"eslint": "^
|
|
87
|
+
"eslint": "^10.2.1",
|
|
87
88
|
"eslint-config-prettier": "^10.1.8",
|
|
88
89
|
"eslint-import-resolver-custom-alias": "^1.3.2",
|
|
89
90
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
90
|
-
"eslint-plugin-import": "^
|
|
91
|
-
"eslint-plugin-oxlint": "^1.
|
|
92
|
-
"
|
|
93
|
-
"
|
|
91
|
+
"eslint-plugin-import-x": "^4.16.2",
|
|
92
|
+
"eslint-plugin-oxlint": "^1.60.0",
|
|
93
|
+
"eslint-plugin-security": "^4.0.0",
|
|
94
|
+
"globals": "^17.5.0",
|
|
95
|
+
"happy-dom": "^20.9.0",
|
|
94
96
|
"husky": "^9.1.7",
|
|
95
97
|
"jiti": "^2.6.1",
|
|
96
|
-
"lint-staged": "^16.
|
|
98
|
+
"lint-staged": "^16.4.0",
|
|
97
99
|
"npm-run-all2": "^8.0.4",
|
|
98
|
-
"oxlint": "^1.
|
|
99
|
-
"prettier": "^3.8.
|
|
100
|
+
"oxlint": "^1.60.0",
|
|
101
|
+
"prettier": "^3.8.3",
|
|
100
102
|
"rimraf": "^6.1.3",
|
|
101
|
-
"rollup-plugin-visualizer": "^
|
|
102
|
-
"typescript": "^
|
|
103
|
-
"typescript-eslint": "^8.
|
|
104
|
-
"vite": "^
|
|
103
|
+
"rollup-plugin-visualizer": "^7.0.1",
|
|
104
|
+
"typescript": "^6.0.3",
|
|
105
|
+
"typescript-eslint": "^8.58.2",
|
|
106
|
+
"vite": "^8.0.8",
|
|
105
107
|
"vite-plugin-banner": "^0.8.1",
|
|
106
|
-
"vite-plugin-checker": "^0.
|
|
108
|
+
"vite-plugin-checker": "^0.13.0",
|
|
107
109
|
"vite-plugin-dts": "^4.5.4",
|
|
108
|
-
"vitest": "^4.
|
|
110
|
+
"vitest": "^4.1.4"
|
|
109
111
|
},
|
|
110
112
|
"husky": {
|
|
111
113
|
"hooks": {
|
|
@@ -117,7 +119,6 @@
|
|
|
117
119
|
"*": "prettier -w -u"
|
|
118
120
|
},
|
|
119
121
|
"resolutions": {
|
|
120
|
-
"
|
|
121
|
-
"yaml": ">=2.3.2"
|
|
122
|
+
"rollup": ">=4.60.2"
|
|
122
123
|
}
|
|
123
124
|
}
|