@logue/reverb 1.2.6 → 1.2.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/README.md CHANGED
@@ -97,4 +97,4 @@ sourceNode.play();
97
97
 
98
98
  ## License
99
99
 
100
- [MIT](LICENSE)
100
+ ©2019-2023 by Logue. Licensed under the [MIT License](LICENSE).
package/dist/Reverb.es.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2019-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.6
8
+ * @version 1.2.7
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
11
 
@@ -30,8 +30,8 @@ const defaults = {
30
30
  };
31
31
 
32
32
  const meta = {
33
- version: "1.2.6",
34
- date: "2023-02-15T04:55:52.436Z"
33
+ version: "1.2.7",
34
+ date: "2023-03-10T12:40:23.409Z"
35
35
  };
36
36
 
37
37
  const Noise = {
@@ -5,7 +5,7 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2019-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.6
8
+ * @version 1.2.7
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
11
 
@@ -29,8 +29,8 @@ var Reverb = (function (random, coloredNoise, transducers) {
29
29
  };
30
30
 
31
31
  const meta = {
32
- version: "1.2.6",
33
- date: "2023-02-15T04:55:52.436Z"
32
+ version: "1.2.7",
33
+ date: "2023-03-10T12:40:23.409Z"
34
34
  };
35
35
 
36
36
  const Noise = {
@@ -5,7 +5,7 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2019-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.6
8
+ * @version 1.2.7
9
9
  * @see {@link https://github.com/logue/Reverb.js}
10
10
  */
11
11
 
@@ -32,8 +32,8 @@
32
32
  };
33
33
 
34
34
  const meta = {
35
- version: "1.2.6",
36
- date: "2023-02-15T04:55:52.436Z"
35
+ version: "1.2.7",
36
+ date: "2023-03-10T12:40:23.409Z"
37
37
  };
38
38
 
39
39
  const Noise = {
@@ -1,3 +1,3 @@
1
- import type MetaInterface from './interfaces/MetaInterface';
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;
@@ -1,6 +1,6 @@
1
- /** Impulse response noise generation algorithm */
2
- declare const Noise: Record<string, string>;
3
- /** Noise Type */
4
- export type NoiseType = typeof Noise[keyof typeof Noise];
5
- /** Noise */
6
- export default Noise;
1
+ /** Impulse response noise generation algorithm */
2
+ declare const Noise: Record<string, string>;
3
+ /** Noise Type */
4
+ export type NoiseType = (typeof Noise)[keyof typeof Noise];
5
+ /** Noise */
6
+ export default Noise;
@@ -1,143 +1,143 @@
1
- import { type NoiseType } from './NoiseType';
2
- import type OptionInterface from './interfaces/OptionInterface';
3
- import type { INorm } from '@thi.ng/random';
4
- /**
5
- * Reverb effect class
6
- */
7
- export default class Reverb {
8
- /** Version strings */
9
- static version: string;
10
- /** Build date */
11
- static 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
- * Constructor
32
- *
33
- * @param ctx - Root AudioContext
34
- * @param options - Configure
35
- */
36
- constructor(ctx: AudioContext, options?: OptionInterface);
37
- /**
38
- * Connect the node for the reverb effect to the original sound node.
39
- *
40
- * @param sourceNode - Input source node
41
- */
42
- connect(sourceNode: AudioNode): AudioNode;
43
- /**
44
- * Disconnect the reverb node
45
- *
46
- * @param sourceNode - Input source node
47
- */
48
- disconnect(sourceNode?: AudioNode): AudioNode | undefined;
49
- /**
50
- * Dry/Wet ratio
51
- *
52
- * @param mix - Ratio (0~1)
53
- */
54
- mix(mix: number): void;
55
- /**
56
- * Set Impulse Response time length (second)
57
- *
58
- * @param value - IR length
59
- */
60
- time(value: number): void;
61
- /**
62
- * Impulse response decay rate.
63
- *
64
- * @param value - Decay value
65
- */
66
- decay(value: number): void;
67
- /**
68
- * Delay before reverberation starts
69
- *
70
- * @param value - Time[ms]
71
- */
72
- delay(value: number): void;
73
- /**
74
- * Reverse the impulse response.
75
- *
76
- * @param reverse - Reverse IR
77
- */
78
- reverse(reverse: boolean): void;
79
- /**
80
- * Filter for impulse response
81
- *
82
- * @param type - Filiter Type
83
- */
84
- filterType(type?: BiquadFilterType): void;
85
- /**
86
- * Filter frequency applied to impulse response
87
- *
88
- * @param freq - Frequency
89
- */
90
- filterFreq(freq: number): void;
91
- /**
92
- * Filter quality.
93
- *
94
- * @param q - Quality
95
- */
96
- filterQ(q: number): void;
97
- /**
98
- * set IR source noise peaks
99
- *
100
- * @param p - Peaks
101
- */
102
- peaks(p: number): void;
103
- /**
104
- * set IR source noise scale.
105
- *
106
- * @param s - Scale
107
- */
108
- scale(s: number): void;
109
- /**
110
- * set IR source noise generator.
111
- *
112
- * @param a - Algorithm
113
- */
114
- randomAlgorithm(a: INorm): void;
115
- /**
116
- * Inpulse Response Noise algorithm.
117
- *
118
- * @param type - IR noise algorithm type.
119
- */
120
- setNoise(type: NoiseType): void;
121
- /**
122
- * Set Random Algorythm
123
- *
124
- * @param algorithm - Algorythm
125
- */
126
- setRandomAlgorythm(algorithm: INorm): void;
127
- /**
128
- * Return true if in range, otherwise false
129
- *
130
- * @param x - Target value
131
- * @param min - Minimum value
132
- * @param max - Maximum value
133
- */
134
- private inRange;
135
- /** Utility function for building an impulse response from the module parameters. */
136
- private buildImpulse;
137
- /**
138
- * Noise source
139
- *
140
- * @param duration - length of IR.
141
- */
142
- private getNoise;
143
- }
1
+ import { type NoiseType } from './NoiseType';
2
+ import type OptionInterface from './interfaces/OptionInterface';
3
+ import type { INorm } from '@thi.ng/random';
4
+ /**
5
+ * Reverb effect class
6
+ */
7
+ export default class Reverb {
8
+ /** Version strings */
9
+ static version: string;
10
+ /** Build date */
11
+ static 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
+ * Constructor
32
+ *
33
+ * @param ctx - Root AudioContext
34
+ * @param options - Configure
35
+ */
36
+ constructor(ctx: AudioContext, options?: OptionInterface);
37
+ /**
38
+ * Connect the node for the reverb effect to the original sound node.
39
+ *
40
+ * @param sourceNode - Input source node
41
+ */
42
+ connect(sourceNode: AudioNode): AudioNode;
43
+ /**
44
+ * Disconnect the reverb node
45
+ *
46
+ * @param sourceNode - Input source node
47
+ */
48
+ disconnect(sourceNode?: AudioNode): AudioNode | undefined;
49
+ /**
50
+ * Dry/Wet ratio
51
+ *
52
+ * @param mix - Ratio (0~1)
53
+ */
54
+ mix(mix: number): void;
55
+ /**
56
+ * Set Impulse Response time length (second)
57
+ *
58
+ * @param value - IR length
59
+ */
60
+ time(value: number): void;
61
+ /**
62
+ * Impulse response decay rate.
63
+ *
64
+ * @param value - Decay value
65
+ */
66
+ decay(value: number): void;
67
+ /**
68
+ * Delay before reverberation starts
69
+ *
70
+ * @param value - Time[ms]
71
+ */
72
+ delay(value: number): void;
73
+ /**
74
+ * Reverse the impulse response.
75
+ *
76
+ * @param reverse - Reverse IR
77
+ */
78
+ reverse(reverse: boolean): void;
79
+ /**
80
+ * Filter for impulse response
81
+ *
82
+ * @param type - Filiter Type
83
+ */
84
+ filterType(type?: BiquadFilterType): void;
85
+ /**
86
+ * Filter frequency applied to impulse response
87
+ *
88
+ * @param freq - Frequency
89
+ */
90
+ filterFreq(freq: number): void;
91
+ /**
92
+ * Filter quality.
93
+ *
94
+ * @param q - Quality
95
+ */
96
+ filterQ(q: number): void;
97
+ /**
98
+ * set IR source noise peaks
99
+ *
100
+ * @param p - Peaks
101
+ */
102
+ peaks(p: number): void;
103
+ /**
104
+ * set IR source noise scale.
105
+ *
106
+ * @param s - Scale
107
+ */
108
+ scale(s: number): void;
109
+ /**
110
+ * set IR source noise generator.
111
+ *
112
+ * @param a - Algorithm
113
+ */
114
+ randomAlgorithm(a: INorm): void;
115
+ /**
116
+ * Inpulse Response Noise algorithm.
117
+ *
118
+ * @param type - IR noise algorithm type.
119
+ */
120
+ setNoise(type: NoiseType): void;
121
+ /**
122
+ * Set Random Algorythm
123
+ *
124
+ * @param algorithm - Algorythm
125
+ */
126
+ setRandomAlgorythm(algorithm: INorm): void;
127
+ /**
128
+ * Return true if in range, otherwise false
129
+ *
130
+ * @param x - Target value
131
+ * @param min - Minimum value
132
+ * @param max - Maximum value
133
+ */
134
+ private inRange;
135
+ /** Utility function for building an impulse response from the module parameters. */
136
+ private buildImpulse;
137
+ /**
138
+ * Noise source
139
+ *
140
+ * @param duration - length of IR.
141
+ */
142
+ private getNoise;
143
+ }
@@ -1,7 +1,7 @@
1
- /** Meta Information Interface */
2
- export default interface MetaInterface {
3
- /** Version */
4
- version: string;
5
- /** Build Date */
6
- date: string;
7
- }
1
+ /** Meta Information Interface */
2
+ export default interface MetaInterface {
3
+ /** Version */
4
+ version: string;
5
+ /** Build Date */
6
+ date: string;
7
+ }
@@ -1,39 +1,39 @@
1
- import type { NoiseType } from '../NoiseType';
2
- import type { 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
- /** デフォルト値 */
39
- export declare const defaults: OptionInterface;
1
+ import type { NoiseType } from '../NoiseType';
2
+ import type { 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
+ /** デフォルト値 */
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.2.6",
4
+ "version": "1.2.7",
5
5
  "description": "JavaScript Reverb effect class",
6
6
  "keywords": [
7
7
  "webaudio",
@@ -29,15 +29,16 @@
29
29
  ],
30
30
  "main": "dist/Reverb.umd.js",
31
31
  "module": "dist/Reverb.es.js",
32
- "types": "dist/Reverb.d.ts",
32
+ "types": "dist/src/Reverb.d.ts",
33
33
  "exports": {
34
34
  ".": {
35
35
  "import": "./dist/Reverb.es.js",
36
- "require": "./dist/Reverb.umd.js"
36
+ "require": "./dist/Reverb.umd.js",
37
+ "types": "./dist/src/Reverb.d.ts"
37
38
  }
38
39
  },
39
40
  "engines": {
40
- "node": ">=18.14.0",
41
+ "node": ">=18.15.0",
41
42
  "yarn": ">=1.22.19"
42
43
  },
43
44
  "packageManager": "yarn@3.4.1",
@@ -46,42 +47,42 @@
46
47
  "dev": "vite",
47
48
  "clean": "rimraf node_modules/.vite",
48
49
  "type-check": "tsc --noEmit --composite false",
49
- "build": "run-p type-check build-only build-declaration",
50
+ "build": "run-p type-check build-only",
50
51
  "build:analyze": "vite build --mode=analyze",
51
52
  "build:clean": "rimraf dist",
52
53
  "build-only": "vite build",
53
- "build-declaration": "tsc -p tsconfig.app.json --composite false",
54
54
  "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
55
55
  "prepare": "husky install"
56
56
  },
57
57
  "dependencies": {
58
- "@thi.ng/colored-noise": "^1.0.9",
59
- "@thi.ng/transducers": "^8.3.33"
58
+ "@thi.ng/colored-noise": "^1.0.11",
59
+ "@thi.ng/transducers": "^8.3.37"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@tsconfig/node18-strictest-esm": "^1.0.1",
63
- "@types/node": "^18.13.0",
64
- "@typescript-eslint/eslint-plugin": "^5.52.0",
65
- "@typescript-eslint/parser": "^5.52.0",
66
- "eslint": "^8.34.0",
63
+ "@types/node": "^18.15.0",
64
+ "@typescript-eslint/eslint-plugin": "^5.54.1",
65
+ "@typescript-eslint/parser": "^5.54.1",
66
+ "eslint": "^8.35.0",
67
67
  "eslint-config-google": "^0.14.0",
68
- "eslint-config-prettier": "^8.6.0",
68
+ "eslint-config-prettier": "^8.7.0",
69
69
  "eslint-import-resolver-alias": "^1.1.2",
70
70
  "eslint-import-resolver-typescript": "^3.5.3",
71
71
  "eslint-plugin-import": "^2.27.5",
72
- "eslint-plugin-jsdoc": "^40.0.0",
72
+ "eslint-plugin-jsdoc": "^40.0.1",
73
73
  "eslint-plugin-prettier": "^4.2.1",
74
74
  "eslint-plugin-tsdoc": "^0.2.17",
75
75
  "husky": "^8.0.3",
76
- "lint-staged": "^13.1.2",
76
+ "lint-staged": "^13.2.0",
77
77
  "npm-run-all": "^4.1.5",
78
78
  "prettier": "^2.8.4",
79
- "rimraf": "^4.1.2",
79
+ "rimraf": "^4.4.0",
80
80
  "rollup-plugin-visualizer": "^5.9.0",
81
81
  "typescript": "^4.9.5",
82
- "vite": "^4.1.1",
82
+ "vite": "^4.1.4",
83
83
  "vite-plugin-banner": "^0.7.0",
84
- "vite-plugin-checker": "^0.5.5"
84
+ "vite-plugin-checker": "^0.5.6",
85
+ "vite-plugin-dts": "^2.1.0"
85
86
  },
86
87
  "husky": {
87
88
  "hooks": {
package/dist/Meta.js DELETED
@@ -1,6 +0,0 @@
1
- // This file is auto-generated by the build system.
2
- const meta = {
3
- version: '1.2.5',
4
- date: '2023-02-15T04:51:13.995Z',
5
- };
6
- export default meta;
package/dist/NoiseType.js DELETED
@@ -1,19 +0,0 @@
1
- /** Impulse response noise generation algorithm */
2
- const Noise = {
3
- /** Blue noise */
4
- BLUE: 'blue',
5
- /** Green noise */
6
- GREEN: 'green',
7
- /** Pink noise */
8
- PINK: 'pink',
9
- /** Red noise */
10
- RED: 'red',
11
- /** Violet noise */
12
- VIOLET: 'violet',
13
- /** White noise */
14
- WHITE: 'white',
15
- /** Brown noise (same as red noise) */
16
- BROWN: 'red',
17
- };
18
- /** Noise */
19
- export default Noise;
package/dist/Reverb.js DELETED
@@ -1,339 +0,0 @@
1
- import { defaults } from './interfaces/OptionInterface';
2
- import Meta from './Meta';
3
- import Noise from './NoiseType';
4
- import { blue, green, pink, red, violet, white } from '@thi.ng/colored-noise';
5
- import { take } from '@thi.ng/transducers';
6
- /**
7
- * Reverb effect class
8
- */
9
- export default class Reverb {
10
- /** Version strings */
11
- static version = Meta.version;
12
- /** Build date */
13
- static build = Meta.date;
14
- /** AudioContext */
15
- ctx;
16
- /** Wet Level (Reverberated node) */
17
- wetGainNode;
18
- /** Dry Level (Original sound node) */
19
- dryGainNode;
20
- /** Impulse response filter */
21
- filterNode;
22
- /** Convolution node for applying impulse response */
23
- convolverNode;
24
- /** Output gain node */
25
- outputNode;
26
- /** Option */
27
- options;
28
- /** Connected flag */
29
- isConnected;
30
- /** Noise Generator */
31
- noise = white;
32
- /**
33
- * Constructor
34
- *
35
- * @param ctx - Root AudioContext
36
- * @param options - Configure
37
- */
38
- constructor(ctx, options) {
39
- // マスターのAudioContextを取得
40
- this.ctx = ctx;
41
- // デフォルト値をマージ
42
- this.options = { ...defaults, ...options };
43
- // 初期化
44
- this.wetGainNode = this.ctx.createGain();
45
- this.dryGainNode = this.ctx.createGain();
46
- this.filterNode = this.ctx.createBiquadFilter();
47
- this.convolverNode = this.ctx.createConvolver();
48
- this.outputNode = this.ctx.createGain();
49
- // 接続済みフラグを落とす
50
- this.isConnected = false;
51
- this.filterType(this.options.filterType);
52
- this.setNoise(this.options.noise);
53
- // インパルス応答を生成
54
- this.buildImpulse();
55
- // トライ/ウェットノードの量を調整
56
- this.mix(this.options.mix);
57
- }
58
- /**
59
- * Connect the node for the reverb effect to the original sound node.
60
- *
61
- * @param sourceNode - Input source node
62
- */
63
- connect(sourceNode) {
64
- if (this.isConnected && this.options.once) {
65
- // 接続済みだった場合、フラグを落としてそのまま出力ノードを返す
66
- this.isConnected = false;
67
- return this.outputNode;
68
- }
69
- // 畳み込みノードをウェットレベルに接続
70
- this.convolverNode.connect(this.filterNode);
71
- // フィルタノードをウェットレベルに接続
72
- this.filterNode.connect(this.wetGainNode);
73
- // 入力ノードを畳み込みノードに接続
74
- sourceNode.connect(this.convolverNode);
75
- // ドライレベルを出力ノードに接続
76
- sourceNode.connect(this.dryGainNode).connect(this.outputNode);
77
- // ウェットレベルを出力ノードに接続
78
- sourceNode.connect(this.wetGainNode).connect(this.outputNode);
79
- // 接続済みフラグを立てる
80
- this.isConnected = true;
81
- return this.outputNode;
82
- }
83
- /**
84
- * Disconnect the reverb node
85
- *
86
- * @param sourceNode - Input source node
87
- */
88
- disconnect(sourceNode) {
89
- // 初期状態ではノードがつながっていないためエラーになる
90
- if (this.isConnected) {
91
- // 畳み込みノードをウェットレベルから切断
92
- this.convolverNode.disconnect(this.filterNode);
93
- // フィルタノードをウェットレベルから切断
94
- this.filterNode.disconnect(this.wetGainNode);
95
- }
96
- // 接続済みフラグを解除
97
- this.isConnected = false;
98
- // そのままノードを返す(他のAPIに似せるため)
99
- return sourceNode;
100
- }
101
- /**
102
- * Dry/Wet ratio
103
- *
104
- * @param mix - Ratio (0~1)
105
- */
106
- mix(mix) {
107
- if (!this.inRange(mix, 0, 1)) {
108
- throw new RangeError('[Reverb.js] Dry/Wet ratio must be between 0 to 1.');
109
- }
110
- this.options.mix = mix;
111
- this.dryGainNode.gain.value = 1 - this.options.mix;
112
- this.wetGainNode.gain.value = this.options.mix;
113
- console.debug(`[Reverb.js] Set dry/wet ratio to ${mix * 100}%`);
114
- }
115
- /**
116
- * Set Impulse Response time length (second)
117
- *
118
- * @param value - IR length
119
- */
120
- time(value) {
121
- if (!this.inRange(value, 1, 50)) {
122
- throw new RangeError('[Reverb.js] Time length of inpulse response must be less than 50sec.');
123
- }
124
- this.options.time = value;
125
- this.buildImpulse();
126
- console.debug(`[Reverb.js] Set inpulse response time length to ${value}sec.`);
127
- }
128
- /**
129
- * Impulse response decay rate.
130
- *
131
- * @param value - Decay value
132
- */
133
- decay(value) {
134
- if (!this.inRange(value, 0, 100)) {
135
- throw new RangeError('[Reverb.js] Inpulse Response decay level must be less than 100.');
136
- }
137
- this.options.decay = value;
138
- this.buildImpulse();
139
- console.debug(`[Reverb.js] Set inpulse response decay level to ${value}.`);
140
- }
141
- /**
142
- * Delay before reverberation starts
143
- *
144
- * @param value - Time[ms]
145
- */
146
- delay(value) {
147
- if (!this.inRange(value, 0, 100)) {
148
- throw new RangeError('[Reverb.js] Inpulse Response delay time must be less than 100.');
149
- }
150
- this.options.delay = value;
151
- this.buildImpulse();
152
- console.debug(`[Reverb.js] Set inpulse response delay time to ${value}sec.`);
153
- }
154
- /**
155
- * Reverse the impulse response.
156
- *
157
- * @param reverse - Reverse IR
158
- */
159
- reverse(reverse) {
160
- this.options.reverse = reverse;
161
- this.buildImpulse();
162
- console.debug(`[Reverb.js] Inpulse response is ${reverse ? '' : 'not '}reversed.`);
163
- }
164
- /**
165
- * Filter for impulse response
166
- *
167
- * @param type - Filiter Type
168
- */
169
- filterType(type = 'allpass') {
170
- this.filterNode.type = this.options.filterType = type;
171
- console.debug(`[Reverb.js] Set filter type to ${type}`);
172
- }
173
- /**
174
- * Filter frequency applied to impulse response
175
- *
176
- * @param freq - Frequency
177
- */
178
- filterFreq(freq) {
179
- if (!this.inRange(freq, 20, 20000)) {
180
- throw new RangeError('[Reverb.js] Filter frequrncy must be between 20 and 20000.');
181
- }
182
- this.options.filterFreq = freq;
183
- this.filterNode.frequency.value = this.options.filterFreq;
184
- console.debug(`[Reverb.js] Set filter frequency to ${freq}Hz.`);
185
- }
186
- /**
187
- * Filter quality.
188
- *
189
- * @param q - Quality
190
- */
191
- filterQ(q) {
192
- if (!this.inRange(q, 0, 10)) {
193
- throw new RangeError('[Reverb.js] Filter quality value must be between 0 and 10.');
194
- }
195
- this.options.filterQ = q;
196
- this.filterNode.Q.value = this.options.filterQ;
197
- console.debug(`[Reverb.js] Set filter Q to ${q}.`);
198
- }
199
- /**
200
- * set IR source noise peaks
201
- *
202
- * @param p - Peaks
203
- */
204
- peaks(p) {
205
- this.options.peaks = p;
206
- this.buildImpulse();
207
- console.debug(`[Reverb.js] Set IR source noise peaks to ${p}.`);
208
- }
209
- /**
210
- * set IR source noise scale.
211
- *
212
- * @param s - Scale
213
- */
214
- scale(s) {
215
- this.options.scale = s;
216
- this.buildImpulse();
217
- console.debug(`[Reverb.js] Set IR source noise scale to ${s}.`);
218
- }
219
- /**
220
- * set IR source noise generator.
221
- *
222
- * @param a - Algorithm
223
- */
224
- randomAlgorithm(a) {
225
- this.options.randomAlgorithm = a;
226
- this.buildImpulse();
227
- console.debug(`[Reverb.js] Set IR source noise generator to ${a}.`);
228
- }
229
- /**
230
- * Inpulse Response Noise algorithm.
231
- *
232
- * @param type - IR noise algorithm type.
233
- */
234
- setNoise(type) {
235
- this.options.noise = type;
236
- switch (type) {
237
- case Noise['BLUE']:
238
- this.noise = blue;
239
- break;
240
- case Noise['GREEN']:
241
- this.noise = green;
242
- break;
243
- case Noise['PINK']:
244
- this.noise = pink;
245
- break;
246
- case Noise['RED']:
247
- case Noise['BROWN']:
248
- this.noise = red;
249
- break;
250
- case Noise['VIOLET']:
251
- this.noise = violet;
252
- break;
253
- default:
254
- this.noise = white;
255
- }
256
- this.buildImpulse();
257
- console.debug(`[Reverb.js] Set IR generator source noise type to ${type}.`);
258
- }
259
- /**
260
- * Set Random Algorythm
261
- *
262
- * @param algorithm - Algorythm
263
- */
264
- setRandomAlgorythm(algorithm) {
265
- this.options.randomAlgorithm = algorithm;
266
- this.buildImpulse();
267
- }
268
- /**
269
- * Return true if in range, otherwise false
270
- *
271
- * @param x - Target value
272
- * @param min - Minimum value
273
- * @param max - Maximum value
274
- */
275
- inRange(x, min, max) {
276
- return (x - min) * (x - max) <= 0;
277
- }
278
- /** Utility function for building an impulse response from the module parameters. */
279
- buildImpulse() {
280
- // インパルス応答生成ロジック
281
- /** サンプリングレート */
282
- const rate = this.ctx.sampleRate;
283
- /** インパルス応答の演奏時間 */
284
- const duration = Math.max(rate * this.options.time, 1);
285
- /** インパルス応答が始まるまでの遅延時間 */
286
- const delayDuration = rate * this.options.delay;
287
- /** インパルス応答バッファ(今の所ステレオのみ) */
288
- const impulse = this.ctx.createBuffer(2, duration, rate);
289
- /** 左チャンネル */
290
- const impulseL = new Float32Array(duration);
291
- /** 右チャンネル */
292
- const impulseR = new Float32Array(duration);
293
- /** 左チャンネルのオーディオソース */
294
- const noiseL = this.getNoise(duration);
295
- /** 右チャンネルのオーディオソース */
296
- const noiseR = this.getNoise(duration);
297
- // console.log(noiseL);
298
- for (let i = 0; i < duration; i++) {
299
- /** 減衰率 */
300
- let n = 0;
301
- if (i < delayDuration) {
302
- // Delay Effect
303
- impulseL[i] = 0;
304
- impulseR[i] = 0;
305
- n = this.options.reverse
306
- ? duration - (i - delayDuration)
307
- : i - delayDuration;
308
- }
309
- else {
310
- n = this.options.reverse ? duration - i : i;
311
- }
312
- // 元の音(ノイズ)を時間経過とともに減衰させる
313
- impulseL[i] =
314
- noiseL[i] * (1 - n / duration) ** this.options.decay;
315
- impulseR[i] =
316
- noiseR[i] * (1 - n / duration) ** this.options.decay;
317
- }
318
- // インパルス応答のバッファに生成したWaveTableを代入
319
- impulse.getChannelData(0).set(impulseL);
320
- impulse.getChannelData(1).set(impulseR);
321
- this.convolverNode.buffer = impulse;
322
- }
323
- /**
324
- * Noise source
325
- *
326
- * @param duration - length of IR.
327
- */
328
- getNoise(duration) {
329
- return [
330
- ...take(duration, this.noise(this.options.peaks, this.options.scale, this.options.randomAlgorithm)),
331
- ];
332
- }
333
- }
334
- // For CDN.
335
- // @ts-ignore
336
- if (!window.Reverb) {
337
- // @ts-ignore
338
- window.Reverb = Reverb;
339
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import { SYSTEM } from '@thi.ng/random';
2
- /** デフォルト値 */
3
- export const defaults = {
4
- noise: 'white',
5
- scale: 1,
6
- peaks: 2,
7
- randomAlgorithm: SYSTEM,
8
- decay: 2,
9
- delay: 0,
10
- reverse: false,
11
- time: 2,
12
- filterType: 'allpass',
13
- filterFreq: 2200,
14
- filterQ: 1,
15
- mix: 0.5,
16
- once: false,
17
- };