@logue/reverb 1.4.2 → 1.4.5
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 +60 -0
- package/package.json +36 -26
- package/dist/Meta.d.ts +0 -3
- package/dist/NoiseType.d.ts +0 -2
- package/dist/Reverb.cjs.js +0 -12
- package/dist/Reverb.d.ts +0 -141
- package/dist/Reverb.es.js +0 -251
- package/dist/Reverb.iife.js +0 -12
- package/dist/Reverb.umd.js +0 -12
- 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
|
@@ -87,6 +87,66 @@ sourceNode.connect(ctx.destination);
|
|
|
87
87
|
sourceNode.play();
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
## Testing
|
|
91
|
+
|
|
92
|
+
This project includes a comprehensive test suite to ensure reliability and code quality.
|
|
93
|
+
|
|
94
|
+
### Test Coverage
|
|
95
|
+
|
|
96
|
+
- **Statement Coverage**: 100%
|
|
97
|
+
- **Function Coverage**: 100%
|
|
98
|
+
- **Branch Coverage**: 90.56%
|
|
99
|
+
- **Line Coverage**: 100%
|
|
100
|
+
|
|
101
|
+
### Test Structure
|
|
102
|
+
|
|
103
|
+
The test suite is organized into several categories:
|
|
104
|
+
|
|
105
|
+
- **Unit Tests**: Individual method and property testing
|
|
106
|
+
- `src/__tests__/Reverb.test.ts` - Main Reverb class tests
|
|
107
|
+
- `src/__tests__/NoiseType.test.ts` - Noise type definition tests
|
|
108
|
+
- `src/__tests__/OptionInterface.test.ts` - Configuration interface tests
|
|
109
|
+
|
|
110
|
+
- **Integration Tests**: Component interaction testing
|
|
111
|
+
- `src/__tests__/integration.test.ts` - Cross-component integration tests
|
|
112
|
+
|
|
113
|
+
- **End-to-End Tests**: Real-world usage scenarios
|
|
114
|
+
- `src/__tests__/e2e.test.ts` - Practical implementation scenarios
|
|
115
|
+
|
|
116
|
+
### Test Features
|
|
117
|
+
|
|
118
|
+
The test suite covers:
|
|
119
|
+
|
|
120
|
+
- ✅ Constructor with default and custom options
|
|
121
|
+
- ✅ Audio node connection and disconnection
|
|
122
|
+
- ✅ Parameter validation and error handling
|
|
123
|
+
- ✅ All reverb parameters (mix, time, decay, delay, reverse)
|
|
124
|
+
- ✅ Filter configurations (type, frequency, Q-factor)
|
|
125
|
+
- ✅ Noise algorithm variations (white, pink, brown, blue, violet, red, green)
|
|
126
|
+
- ✅ Performance testing with multiple instances
|
|
127
|
+
- ✅ Edge cases and boundary conditions
|
|
128
|
+
- ✅ Real-world scenarios (guitar, vocal, drum reverb settings)
|
|
129
|
+
|
|
130
|
+
### Running Tests
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Run all tests
|
|
134
|
+
pnpm test
|
|
135
|
+
|
|
136
|
+
# Run tests once
|
|
137
|
+
pnpm test:run
|
|
138
|
+
|
|
139
|
+
# Run tests with coverage report
|
|
140
|
+
pnpm test:coverage
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Test Environment
|
|
144
|
+
|
|
145
|
+
- **Vitest** - Fast Vite-based test framework
|
|
146
|
+
- **Happy-DOM** - Browser environment simulation
|
|
147
|
+
- **Web Audio API Mocking** - Complete audio context simulation
|
|
148
|
+
- **TypeScript Support** - Full type checking during tests
|
|
149
|
+
|
|
90
150
|
### CDN Usage
|
|
91
151
|
|
|
92
152
|
Not really intended for use with a CDN.
|
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.5",
|
|
5
5
|
"description": "JavaScript Reverb effect class",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webaudio",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"./package.json": "./package.json"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=22.0
|
|
51
|
-
"pnpm": ">=10.
|
|
50
|
+
"node": "^20.19.0 || >=22.12.0",
|
|
51
|
+
"pnpm": ">=10.2.0"
|
|
52
52
|
},
|
|
53
|
-
"packageManager": "pnpm@10.
|
|
53
|
+
"packageManager": "pnpm@10.29.3",
|
|
54
54
|
"sideEffects": false,
|
|
55
55
|
"scripts": {
|
|
56
56
|
"dev": "vite",
|
|
@@ -61,9 +61,15 @@
|
|
|
61
61
|
"build:analyze": "vite build --mode=analyze",
|
|
62
62
|
"build:clean": "rimraf dist",
|
|
63
63
|
"build-only": "vite build",
|
|
64
|
-
"lint": "
|
|
64
|
+
"lint": "run-s lint:*",
|
|
65
|
+
"lint:oxlint": "oxlint . --fix",
|
|
66
|
+
"lint:eslint": "eslint . --fix --cache --cache-location ./node_modules/.vite/eslint-cache",
|
|
67
|
+
"lint:prettier": "prettier \"./**/*.{js,ts,json,css,sass,scss,htm,html,vue,md}\" -w -u",
|
|
65
68
|
"preview": "vite preview --mode=docs",
|
|
66
|
-
"prepare": "husky"
|
|
69
|
+
"prepare": "husky",
|
|
70
|
+
"test": "vitest",
|
|
71
|
+
"test:run": "vitest run",
|
|
72
|
+
"test:coverage": "vitest run --coverage"
|
|
67
73
|
},
|
|
68
74
|
"peerDependencies": {
|
|
69
75
|
"@thi.ng/colored-noise": "^1.0.103",
|
|
@@ -71,31 +77,35 @@
|
|
|
71
77
|
"@thi.ng/transducers": "^9.5.1"
|
|
72
78
|
},
|
|
73
79
|
"devDependencies": {
|
|
74
|
-
"@eslint/js": "^9.
|
|
75
|
-
"@tsconfig/node-lts": "^
|
|
76
|
-
"@types/node": "^
|
|
77
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"eslint
|
|
80
|
+
"@eslint/js": "^9.17.0",
|
|
81
|
+
"@tsconfig/node-lts": "^24.0.0",
|
|
82
|
+
"@types/node": "^25.2.3",
|
|
83
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
84
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
85
|
+
"bootstrap": "^5.3.8",
|
|
86
|
+
"eslint": "^9.17.0",
|
|
87
|
+
"eslint-config-prettier": "^10.1.8",
|
|
81
88
|
"eslint-import-resolver-custom-alias": "^1.3.2",
|
|
82
89
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
83
90
|
"eslint-plugin-import": "^2.32.0",
|
|
84
|
-
"eslint-plugin-
|
|
85
|
-
"globals": "^
|
|
91
|
+
"eslint-plugin-oxlint": "^1.46.0",
|
|
92
|
+
"globals": "^17.3.0",
|
|
93
|
+
"happy-dom": "^20.6.1",
|
|
86
94
|
"husky": "^9.1.7",
|
|
87
|
-
"jiti": "^2.
|
|
88
|
-
"lint-staged": "^16.
|
|
95
|
+
"jiti": "^2.6.1",
|
|
96
|
+
"lint-staged": "^16.2.7",
|
|
89
97
|
"npm-run-all2": "^8.0.4",
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"typescript
|
|
95
|
-
"
|
|
98
|
+
"oxlint": "^1.47.0",
|
|
99
|
+
"prettier": "^3.8.1",
|
|
100
|
+
"rimraf": "^6.1.3",
|
|
101
|
+
"rollup-plugin-visualizer": "^6.0.5",
|
|
102
|
+
"typescript": "^5.9.3",
|
|
103
|
+
"typescript-eslint": "^8.56.0",
|
|
104
|
+
"vite": "^7.3.1",
|
|
96
105
|
"vite-plugin-banner": "^0.8.1",
|
|
97
|
-
"vite-plugin-checker": "^0.
|
|
98
|
-
"vite-plugin-dts": "^4.5.4"
|
|
106
|
+
"vite-plugin-checker": "^0.12.0",
|
|
107
|
+
"vite-plugin-dts": "^4.5.4",
|
|
108
|
+
"vitest": "^4.0.18"
|
|
99
109
|
},
|
|
100
110
|
"husky": {
|
|
101
111
|
"hooks": {
|
|
@@ -110,4 +120,4 @@
|
|
|
110
120
|
"json5": ">=2.2.3",
|
|
111
121
|
"yaml": ">=2.3.2"
|
|
112
122
|
}
|
|
113
|
-
}
|
|
123
|
+
}
|
package/dist/Meta.d.ts
DELETED
package/dist/NoiseType.d.ts
DELETED
package/dist/Reverb.cjs.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-2025 By Masashi Yoshikawa All rights reserved.
|
|
7
|
-
* @license MIT
|
|
8
|
-
* @version 1.4.1
|
|
9
|
-
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var s=require("@thi.ng/colored-noise"),u=require("@thi.ng/transducers"),f=require("@thi.ng/random");const d={version:"1.4.1",date:"2025-07-12T06:07:47.985Z"},m={noise:"white",scale:1,peaks:2,randomAlgorithm:f.SYSTEM,decay:2,delay:0,reverse:!1,time:2,filterType:"allpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};class o{static version=d.version;static build=d.date;ctx;wetGainNode;dryGainNode;filterNode;convolverNode;outputNode;options;isConnected;noise=s.white;noiseMap={blue:s.blue,green:s.green,pink:s.pink,red:s.red,brown:s.red,violet:s.violet,white:s.white};constructor(e,t){this.ctx=e,this.options=Object.assign(m,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(!o.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-e,this.wetGainNode.gain.value=e}time(e){if(!o.inRange(e,1,50))throw new RangeError("[Reverb.js] Time length of impulse response must be less than 50sec.");this.options.time=e,this.buildImpulse()}decay(e){if(!o.inRange(e,0,100))throw new RangeError("[Reverb.js] Impulse Response decay level must be less than 100.");this.options.decay=e,this.buildImpulse()}delay(e){if(!o.inRange(e,0,100))throw new RangeError("[Reverb.js] Impulse Response delay time must be less than 100.");this.options.delay=e,this.buildImpulse()}reverse(e){this.options.reverse=e,this.buildImpulse()}filterType(e="allpass"){this.filterNode.type=this.options.filterType=e}filterFreq(e){if(!o.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}filterQ(e){if(!o.inRange(e,0,10))throw new RangeError("[Reverb.js] Filter Q value must be between 0 and 10.");this.options.filterQ=e,this.filterNode.Q.value=this.options.filterQ}peaks(e){this.options.peaks=e,this.buildImpulse()}scale(e){this.options.scale=e,this.buildImpulse()}getNoise(e){return[...u.take(e,this.noise({bins:this.options.peaks,scale:this.options.scale,rnd:this.options.randomAlgorithm}))]}setNoise(e){this.options.noise=e,this.noise=this.noiseMap[e]||s.white,this.buildImpulse()}setRandomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse()}static inRange(e,t,n){return e>=t&&e<=n}buildImpulse(){const e=this.ctx.sampleRate,t=Math.max(e*this.options.time,1),n=e*this.options.delay,a=this.ctx.createBuffer(2,t,e),l=new Float32Array(t),h=new Float32Array(t),c=this.getNoise(t),p=this.getNoise(t);for(let i=0;i<t;i++){let r=0;i<n?(l[i]=0,h[i]=0,r=this.options.reverse??!1?t-(i-n):i-n):r=this.options.reverse??!1?t-i:i,l[i]=(c[i]??0)*(1-r/t)**this.options.decay,h[i]=(p[i]??0)*(1-r/t)**this.options.decay}a.getChannelData(0).set(l),a.getChannelData(1).set(h),this.convolverNode.buffer=a}}exports.default=o;
|
package/dist/Reverb.d.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { NoiseType } from './NoiseType';
|
|
2
|
-
import { default as OptionInterface } from './interfaces/OptionInterface';
|
|
3
|
-
import { INorm } from '@thi.ng/random';
|
|
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
|
-
}
|
package/dist/Reverb.es.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @logue/reverb
|
|
3
|
-
*
|
|
4
|
-
* @description JavaScript Reverb effect class
|
|
5
|
-
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
-
* @copyright 2019-2025 By Masashi Yoshikawa All rights reserved.
|
|
7
|
-
* @license MIT
|
|
8
|
-
* @version 1.4.1
|
|
9
|
-
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { white as l, violet as f, red as d, pink as m, green as N, blue as g } from "@thi.ng/colored-noise";
|
|
13
|
-
import { take as v } from "@thi.ng/transducers";
|
|
14
|
-
import { SYSTEM as w } from "@thi.ng/random";
|
|
15
|
-
const c = {
|
|
16
|
-
version: "1.4.1",
|
|
17
|
-
date: "2025-07-12T06:07:47.985Z"
|
|
18
|
-
}, y = {
|
|
19
|
-
noise: "white",
|
|
20
|
-
scale: 1,
|
|
21
|
-
peaks: 2,
|
|
22
|
-
randomAlgorithm: w,
|
|
23
|
-
decay: 2,
|
|
24
|
-
delay: 0,
|
|
25
|
-
reverse: !1,
|
|
26
|
-
time: 2,
|
|
27
|
-
filterType: "allpass",
|
|
28
|
-
filterFreq: 2200,
|
|
29
|
-
filterQ: 1,
|
|
30
|
-
mix: 0.5,
|
|
31
|
-
once: !1
|
|
32
|
-
};
|
|
33
|
-
class s {
|
|
34
|
-
/** Version strings */
|
|
35
|
-
static version = c.version;
|
|
36
|
-
/** Build date */
|
|
37
|
-
static build = c.date;
|
|
38
|
-
/** AudioContext */
|
|
39
|
-
ctx;
|
|
40
|
-
/** Wet Level (Reverberated node) */
|
|
41
|
-
wetGainNode;
|
|
42
|
-
/** Dry Level (Original sound node) */
|
|
43
|
-
dryGainNode;
|
|
44
|
-
/** Impulse response filter */
|
|
45
|
-
filterNode;
|
|
46
|
-
/** Convolution node for applying impulse response */
|
|
47
|
-
convolverNode;
|
|
48
|
-
/** Output gain node */
|
|
49
|
-
outputNode;
|
|
50
|
-
/** Option */
|
|
51
|
-
options;
|
|
52
|
-
/** Connected flag */
|
|
53
|
-
isConnected;
|
|
54
|
-
/** Noise Generator */
|
|
55
|
-
noise = l;
|
|
56
|
-
/**
|
|
57
|
-
* Map of noise types to their respective generator functions.
|
|
58
|
-
*/
|
|
59
|
-
noiseMap = {
|
|
60
|
-
blue: g,
|
|
61
|
-
green: N,
|
|
62
|
-
pink: m,
|
|
63
|
-
red: d,
|
|
64
|
-
brown: d,
|
|
65
|
-
// brown is an alias for red
|
|
66
|
-
violet: f,
|
|
67
|
-
white: l
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Constructor
|
|
71
|
-
*
|
|
72
|
-
* @param ctx - Root AudioContext
|
|
73
|
-
* @param options - Configure
|
|
74
|
-
*/
|
|
75
|
-
constructor(e, t) {
|
|
76
|
-
this.ctx = e, this.options = Object.assign(y, 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);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Connect the node for the reverb effect to the original sound node.
|
|
80
|
-
*
|
|
81
|
-
* @param sourceNode - Input source node
|
|
82
|
-
*/
|
|
83
|
-
connect(e) {
|
|
84
|
-
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);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Disconnect the reverb node
|
|
88
|
-
*
|
|
89
|
-
* @param sourceNode - Input source node
|
|
90
|
-
*/
|
|
91
|
-
disconnect(e) {
|
|
92
|
-
return this.isConnected && (this.convolverNode.disconnect(this.filterNode), this.filterNode.disconnect(this.wetGainNode)), this.isConnected = !1, e;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Dry/Wet ratio
|
|
96
|
-
*
|
|
97
|
-
* @param mix - Ratio (0~1)
|
|
98
|
-
*/
|
|
99
|
-
mix(e) {
|
|
100
|
-
if (!s.inRange(e, 0, 1))
|
|
101
|
-
throw new RangeError("[Reverb.js] Dry/Wet ratio must be between 0 to 1.");
|
|
102
|
-
this.options.mix = e, this.dryGainNode.gain.value = 1 - e, this.wetGainNode.gain.value = e;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Set Impulse Response time length (second)
|
|
106
|
-
*
|
|
107
|
-
* @param value - IR length
|
|
108
|
-
*/
|
|
109
|
-
time(e) {
|
|
110
|
-
if (!s.inRange(e, 1, 50))
|
|
111
|
-
throw new RangeError(
|
|
112
|
-
"[Reverb.js] Time length of impulse response must be less than 50sec."
|
|
113
|
-
);
|
|
114
|
-
this.options.time = e, this.buildImpulse();
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Impulse response decay rate.
|
|
118
|
-
*
|
|
119
|
-
* @param value - Decay value
|
|
120
|
-
*/
|
|
121
|
-
decay(e) {
|
|
122
|
-
if (!s.inRange(e, 0, 100))
|
|
123
|
-
throw new RangeError(
|
|
124
|
-
"[Reverb.js] Impulse Response decay level must be less than 100."
|
|
125
|
-
);
|
|
126
|
-
this.options.decay = e, this.buildImpulse();
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Delay before reverberation starts
|
|
130
|
-
*
|
|
131
|
-
* @param value - Time[ms]
|
|
132
|
-
*/
|
|
133
|
-
delay(e) {
|
|
134
|
-
if (!s.inRange(e, 0, 100))
|
|
135
|
-
throw new RangeError(
|
|
136
|
-
"[Reverb.js] Impulse Response delay time must be less than 100."
|
|
137
|
-
);
|
|
138
|
-
this.options.delay = e, this.buildImpulse();
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Reverse the impulse response.
|
|
142
|
-
*
|
|
143
|
-
* @param reverse - Reverse IR
|
|
144
|
-
*/
|
|
145
|
-
reverse(e) {
|
|
146
|
-
this.options.reverse = e, this.buildImpulse();
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Filter for impulse response
|
|
150
|
-
*
|
|
151
|
-
* @param type - Filiter Type
|
|
152
|
-
*/
|
|
153
|
-
filterType(e = "allpass") {
|
|
154
|
-
this.filterNode.type = this.options.filterType = e;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Filter frequency applied to impulse response
|
|
158
|
-
*
|
|
159
|
-
* @param freq - Frequency
|
|
160
|
-
*/
|
|
161
|
-
filterFreq(e) {
|
|
162
|
-
if (!s.inRange(e, 20, 2e4))
|
|
163
|
-
throw new RangeError(
|
|
164
|
-
"[Reverb.js] Filter frequrncy must be between 20 and 20000."
|
|
165
|
-
);
|
|
166
|
-
this.options.filterFreq = e, this.filterNode.frequency.value = this.options.filterFreq;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Filter quality.
|
|
170
|
-
*
|
|
171
|
-
* @param q - Quality
|
|
172
|
-
*/
|
|
173
|
-
filterQ(e) {
|
|
174
|
-
if (!s.inRange(e, 0, 10))
|
|
175
|
-
throw new RangeError(
|
|
176
|
-
"[Reverb.js] Filter Q value must be between 0 and 10."
|
|
177
|
-
);
|
|
178
|
-
this.options.filterQ = e, this.filterNode.Q.value = this.options.filterQ;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* set IR source noise peaks
|
|
182
|
-
*
|
|
183
|
-
* @param p - Peaks
|
|
184
|
-
*/
|
|
185
|
-
peaks(e) {
|
|
186
|
-
this.options.peaks = e, this.buildImpulse();
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* set IR source noise scale.
|
|
190
|
-
*
|
|
191
|
-
* @param s - Scale
|
|
192
|
-
*/
|
|
193
|
-
scale(e) {
|
|
194
|
-
this.options.scale = e, this.buildImpulse();
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Noise source
|
|
198
|
-
*
|
|
199
|
-
* @param duration - length of IR.
|
|
200
|
-
*/
|
|
201
|
-
getNoise(e) {
|
|
202
|
-
return [
|
|
203
|
-
...v(
|
|
204
|
-
e,
|
|
205
|
-
this.noise({
|
|
206
|
-
bins: this.options.peaks,
|
|
207
|
-
scale: this.options.scale,
|
|
208
|
-
rnd: this.options.randomAlgorithm
|
|
209
|
-
})
|
|
210
|
-
)
|
|
211
|
-
];
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Inpulse Response Noise algorithm.
|
|
215
|
-
*
|
|
216
|
-
* @param type - IR noise algorithm type.
|
|
217
|
-
*/
|
|
218
|
-
setNoise(e) {
|
|
219
|
-
this.options.noise = e, this.noise = this.noiseMap[e] || l, this.buildImpulse();
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Set Random Algorythm
|
|
223
|
-
*
|
|
224
|
-
* @param algorithm - Algorythm
|
|
225
|
-
*/
|
|
226
|
-
setRandomAlgorithm(e) {
|
|
227
|
-
this.options.randomAlgorithm = e, this.buildImpulse();
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Return true if in range, otherwise false
|
|
231
|
-
*
|
|
232
|
-
* @param x - Target value
|
|
233
|
-
* @param min - Minimum value
|
|
234
|
-
* @param max - Maximum value
|
|
235
|
-
*/
|
|
236
|
-
static inRange(e, t, o) {
|
|
237
|
-
return e >= t && e <= o;
|
|
238
|
-
}
|
|
239
|
-
/** Utility function for building an impulse response from the module parameters. */
|
|
240
|
-
buildImpulse() {
|
|
241
|
-
const e = this.ctx.sampleRate, t = Math.max(e * this.options.time, 1), o = e * this.options.delay, r = this.ctx.createBuffer(2, t, e), a = new Float32Array(t), h = new Float32Array(t), p = this.getNoise(t), u = this.getNoise(t);
|
|
242
|
-
for (let i = 0; i < t; i++) {
|
|
243
|
-
let n = 0;
|
|
244
|
-
i < o ? (a[i] = 0, h[i] = 0, n = this.options.reverse ?? !1 ? t - (i - o) : i - o) : n = this.options.reverse ?? !1 ? t - i : i, a[i] = (p[i] ?? 0) * (1 - n / t) ** this.options.decay, h[i] = (u[i] ?? 0) * (1 - n / t) ** this.options.decay;
|
|
245
|
-
}
|
|
246
|
-
r.getChannelData(0).set(a), r.getChannelData(1).set(h), this.convolverNode.buffer = r;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
export {
|
|
250
|
-
s as default
|
|
251
|
-
};
|
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-2025 By Masashi Yoshikawa All rights reserved.
|
|
7
|
-
* @license MIT
|
|
8
|
-
* @version 1.4.1
|
|
9
|
-
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
var Reverb=function(a,s,u,p){"use strict";const c={version:"1.4.1",date:"2025-07-12T06:07:47.985Z"},f={noise:"white",scale:1,peaks:2,randomAlgorithm:p.SYSTEM,decay:2,delay:0,reverse:!1,time:2,filterType:"allpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};class n{static version=c.version;static build=c.date;ctx;wetGainNode;dryGainNode;filterNode;convolverNode;outputNode;options;isConnected;noise=s.white;noiseMap={blue:s.blue,green:s.green,pink:s.pink,red:s.red,brown:s.red,violet:s.violet,white:s.white};constructor(e,t){this.ctx=e,this.options=Object.assign(f,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 new 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}time(e){if(!n.inRange(e,1,50))throw new RangeError("[Reverb.js] Time length of impulse response must be less than 50sec.");this.options.time=e,this.buildImpulse()}decay(e){if(!n.inRange(e,0,100))throw new RangeError("[Reverb.js] Impulse Response decay level must be less than 100.");this.options.decay=e,this.buildImpulse()}delay(e){if(!n.inRange(e,0,100))throw new RangeError("[Reverb.js] Impulse Response delay time must be less than 100.");this.options.delay=e,this.buildImpulse()}reverse(e){this.options.reverse=e,this.buildImpulse()}filterType(e="allpass"){this.filterNode.type=this.options.filterType=e}filterFreq(e){if(!n.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}filterQ(e){if(!n.inRange(e,0,10))throw new RangeError("[Reverb.js] Filter Q value must be between 0 and 10.");this.options.filterQ=e,this.filterNode.Q.value=this.options.filterQ}peaks(e){this.options.peaks=e,this.buildImpulse()}scale(e){this.options.scale=e,this.buildImpulse()}getNoise(e){return[...u.take(e,this.noise({bins:this.options.peaks,scale:this.options.scale,rnd:this.options.randomAlgorithm}))]}setNoise(e){this.options.noise=e,this.noise=this.noiseMap[e]||s.white,this.buildImpulse()}setRandomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse()}static inRange(e,t,o){return e>=t&&e<=o}buildImpulse(){const e=this.ctx.sampleRate,t=Math.max(e*this.options.time,1),o=e*this.options.delay,h=this.ctx.createBuffer(2,t,e),l=new Float32Array(t),d=new Float32Array(t),m=this.getNoise(t),v=this.getNoise(t);for(let i=0;i<t;i++){let r=0;i<o?(l[i]=0,d[i]=0,r=this.options.reverse??!1?t-(i-o):i-o):r=this.options.reverse??!1?t-i:i,l[i]=(m[i]??0)*(1-r/t)**this.options.decay,d[i]=(v[i]??0)*(1-r/t)**this.options.decay}h.getChannelData(0).set(l),h.getChannelData(1).set(d),this.convolverNode.buffer=h}}return a.default=n,Object.defineProperty(a,"__esModule",{value:!0}),a}({},coloredNoise,transducers,random);
|
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-2025 By Masashi Yoshikawa All rights reserved.
|
|
7
|
-
* @license MIT
|
|
8
|
-
* @version 1.4.1
|
|
9
|
-
* @see {@link https://github.com/logue/Reverb.js}
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(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"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.Reverb={},n.coloredNoise,n.transducers,n.random))})(this,function(n,i,u,p){"use strict";const c={version:"1.4.1",date:"2025-07-12T06:07:47.985Z"},f={noise:"white",scale:1,peaks:2,randomAlgorithm:p.SYSTEM,decay:2,delay:0,reverse:!1,time:2,filterType:"allpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};class o{static version=c.version;static build=c.date;ctx;wetGainNode;dryGainNode;filterNode;convolverNode;outputNode;options;isConnected;noise=i.white;noiseMap={blue:i.blue,green:i.green,pink:i.pink,red:i.red,brown:i.red,violet:i.violet,white:i.white};constructor(e,t){this.ctx=e,this.options=Object.assign(f,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(!o.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-e,this.wetGainNode.gain.value=e}time(e){if(!o.inRange(e,1,50))throw new RangeError("[Reverb.js] Time length of impulse response must be less than 50sec.");this.options.time=e,this.buildImpulse()}decay(e){if(!o.inRange(e,0,100))throw new RangeError("[Reverb.js] Impulse Response decay level must be less than 100.");this.options.decay=e,this.buildImpulse()}delay(e){if(!o.inRange(e,0,100))throw new RangeError("[Reverb.js] Impulse Response delay time must be less than 100.");this.options.delay=e,this.buildImpulse()}reverse(e){this.options.reverse=e,this.buildImpulse()}filterType(e="allpass"){this.filterNode.type=this.options.filterType=e}filterFreq(e){if(!o.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}filterQ(e){if(!o.inRange(e,0,10))throw new RangeError("[Reverb.js] Filter Q value must be between 0 and 10.");this.options.filterQ=e,this.filterNode.Q.value=this.options.filterQ}peaks(e){this.options.peaks=e,this.buildImpulse()}scale(e){this.options.scale=e,this.buildImpulse()}getNoise(e){return[...u.take(e,this.noise({bins:this.options.peaks,scale:this.options.scale,rnd:this.options.randomAlgorithm}))]}setNoise(e){this.options.noise=e,this.noise=this.noiseMap[e]||i.white,this.buildImpulse()}setRandomAlgorithm(e){this.options.randomAlgorithm=e,this.buildImpulse()}static inRange(e,t,r){return e>=t&&e<=r}buildImpulse(){const e=this.ctx.sampleRate,t=Math.max(e*this.options.time,1),r=e*this.options.delay,a=this.ctx.createBuffer(2,t,e),l=new Float32Array(t),d=new Float32Array(t),m=this.getNoise(t),g=this.getNoise(t);for(let s=0;s<t;s++){let h=0;s<r?(l[s]=0,d[s]=0,h=this.options.reverse??!1?t-(s-r):s-r):h=this.options.reverse??!1?t-s:s,l[s]=(m[s]??0)*(1-h/t)**this.options.decay,d[s]=(g[s]??0)*(1-h/t)**this.options.decay}a.getChannelData(0).set(l),a.getChannelData(1).set(d),this.convolverNode.buffer=a}}n.default=o,Object.defineProperty(n,"__esModule",{value:!0})});
|
package/dist/demo.flac
DELETED
|
Binary file
|
|
@@ -1,39 +0,0 @@
|
|
|
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;
|