@logue/reverb 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/reverb.js DELETED
@@ -1,426 +0,0 @@
1
- /*! @logue/reverb v0.4.1 | Logue | license: MIT | build: 2021-05-28T08:52:52.630Z */
2
- (function webpackUniversalModuleDefinition(root, factory) {
3
- if(typeof exports === 'object' && typeof module === 'object')
4
- module.exports = factory();
5
- else if(typeof define === 'function' && define.amd)
6
- define("Reverb", [], factory);
7
- else if(typeof exports === 'object')
8
- exports["Reverb"] = factory();
9
- else
10
- root["Reverb"] = factory();
11
- })((typeof self !== 'undefined' ? self : this), function() {
12
- return /******/ (() => { // webpackBootstrap
13
- /******/ "use strict";
14
- /******/ var __webpack_modules__ = ({
15
-
16
- /***/ "./src/Meta.ts":
17
- /*!*********************!*\
18
- !*** ./src/Meta.ts ***!
19
- \*********************/
20
- /***/ ((__unused_webpack_module, exports) => {
21
-
22
-
23
- Object.defineProperty(exports, "__esModule", ({ value: true }));
24
- // This file is auto-generated by the build system.
25
- const meta = {
26
- version: '0.4.1',
27
- date: '2021-05-28T08:52:52.630Z',
28
- };
29
- exports.default = meta;
30
-
31
-
32
- /***/ }),
33
-
34
- /***/ "./src/NoiseType.ts":
35
- /*!**************************!*\
36
- !*** ./src/NoiseType.ts ***!
37
- \**************************/
38
- /***/ ((__unused_webpack_module, exports) => {
39
-
40
-
41
- Object.defineProperty(exports, "__esModule", ({ value: true }));
42
- exports.NoiseType = void 0;
43
- var NoiseType;
44
- (function (NoiseType) {
45
- NoiseType[NoiseType["WHITE"] = 0] = "WHITE";
46
- NoiseType[NoiseType["PINK"] = 1] = "PINK";
47
- NoiseType[NoiseType["BROWN"] = 2] = "BROWN";
48
- })(NoiseType = exports.NoiseType || (exports.NoiseType = {}));
49
-
50
-
51
- /***/ }),
52
-
53
- /***/ "./src/Reverb.ts":
54
- /*!***********************!*\
55
- !*** ./src/Reverb.ts ***!
56
- \***********************/
57
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
58
-
59
-
60
- var __importDefault = (this && this.__importDefault) || function (mod) {
61
- return (mod && mod.__esModule) ? mod : { "default": mod };
62
- };
63
- Object.defineProperty(exports, "__esModule", ({ value: true }));
64
- const Meta_1 = __importDefault(__webpack_require__(/*! ./Meta */ "./src/Meta.ts"));
65
- const NoiseType_1 = __webpack_require__(/*! ./NoiseType */ "./src/NoiseType.ts");
66
- /**
67
- * JS reverb effect class
68
- *
69
- * @author Logue <logue@hotmail.co.jp>
70
- * @copyright 2019-2020 Masashi Yoshikawa <https://logue.dev/> All rights reserved.
71
- * @license MIT
72
- * @see {@link https://github.com/logue/Reverb.js}
73
- * {@link https://github.com/web-audio-components/simple-reverb}
74
- */
75
- class Reverb {
76
- /** @type {string} バージョン */
77
- version;
78
- /** @type {string} ビルド日時 */
79
- build;
80
- /** @type {AudioContext} AudioContext */
81
- ctx;
82
- /** @type {GainNode} ウェットレベル(エフェクターをかけたレベル) */
83
- wetGainNode;
84
- /** @type {GainNode} ドライレベル(原音レベル) */
85
- dryGainNode;
86
- /** @type {BiquadFilterNode} インパルス応答用フィルタ */
87
- filterNode;
88
- /** @type {ConvolverNode} 畳み込みノード */
89
- convolverNode;
90
- /** @type {GainNode} 出力ノード */
91
- outputNode;
92
- /** @type {Option} 変数 */
93
- _options;
94
- /** @type {boolean} 接続済みフラグ */
95
- isConnected;
96
- /**
97
- * constructor
98
- * @param {AudioContext} ctx Root AudioContext
99
- * @param {OptionInterface} options Configure
100
- */
101
- constructor(ctx, options) {
102
- // バージョン情報など
103
- this.version = Meta_1.default.version;
104
- this.build = Meta_1.default.date;
105
- // マスターのAudioContextを取得
106
- this.ctx = ctx;
107
- // デフォルト値をマージ
108
- this._options = { ...optionDefaults, ...options };
109
- // 初期化
110
- this.wetGainNode = this.ctx.createGain();
111
- this.dryGainNode = this.ctx.createGain();
112
- this.filterNode = this.ctx.createBiquadFilter();
113
- this.convolverNode = this.ctx.createConvolver();
114
- this.outputNode = this.ctx.createGain();
115
- // 接続済みフラグを落とす
116
- this.isConnected = false;
117
- // インパルス応答を生成
118
- this.buildImpulse();
119
- }
120
- /**
121
- * connect
122
- * @param {AudioNode} sourceNode 原音ノード
123
- * @return {AudioNode}
124
- */
125
- connect(sourceNode) {
126
- // 畳み込みノードをウェットレベルに接続
127
- this.convolverNode.connect(this.filterNode);
128
- // フィルタノードをウェットレベルに接続
129
- this.filterNode.connect(this.wetGainNode);
130
- // 入力ノードを畳み込みノードに接続
131
- sourceNode.connect(this.convolverNode);
132
- // ドライレベルを出力ノードに接続
133
- sourceNode.connect(this.dryGainNode).connect(this.outputNode);
134
- // ウェットレベルを出力ノードに接続
135
- sourceNode.connect(this.wetGainNode).connect(this.outputNode);
136
- // 接続済みフラグを立てる
137
- this.isConnected = true;
138
- return this.outputNode;
139
- }
140
- /**
141
- * disconnect
142
- * @param {AudioNode} sourceNode 原音のノード
143
- * @return {AudioNode}
144
- */
145
- disconnect(sourceNode) {
146
- // 初期状態ではノードがつながっていないためエラーになる
147
- if (this.isConnected) {
148
- // 畳み込みノードをウェットレベルから切断
149
- this.convolverNode.disconnect(this.filterNode);
150
- // フィルタノードをウェットレベルから切断
151
- this.filterNode.disconnect(this.wetGainNode);
152
- }
153
- // 接続済みフラグを解除
154
- this.isConnected = false;
155
- // そのままノードを返す(他のAPIに似せるため)
156
- return sourceNode;
157
- }
158
- /**
159
- * Dry/Wet ratio
160
- * @param {number} mix
161
- */
162
- mix(mix) {
163
- if (!this.inRange(mix, 0, 1)) {
164
- throw new RangeError('Reverb.js: Dry/Wet ratio must be between 0 to 1.');
165
- }
166
- this._options.mix = mix;
167
- this.dryGainNode.gain.value = 1 - this._options.mix;
168
- this.wetGainNode.gain.value = this._options.mix;
169
- console.debug(`Reverb.js: Set dry/wet ratio to ${mix * 100}%`);
170
- }
171
- /**
172
- * Set Impulse Response time length (second)
173
- * @param {number} value
174
- */
175
- time(value) {
176
- if (!this.inRange(value, 1, 50)) {
177
- throw new RangeError('Reverb.js: Time length of inpulse response must be less than 50sec.');
178
- }
179
- this._options.time = value;
180
- this.buildImpulse();
181
- console.info(`Reverb.js: Set inpulse response time length to ${value}sec.`);
182
- }
183
- /**
184
- * Impulse response decay rate.
185
- * @param {number} value
186
- */
187
- decay(value) {
188
- if (!this.inRange(value, 0, 100)) {
189
- throw new RangeError('Reverb.js: Inpulse Response decay level must be less than 100.');
190
- }
191
- this._options.decay = value;
192
- this.buildImpulse();
193
- console.debug(`Reverb.js: Set inpulse response decay level to ${value}.`);
194
- }
195
- /**
196
- * Impulse response delay time. (NOT deley effect)
197
- * @param {number} value
198
- */
199
- delay(value) {
200
- if (!this.inRange(value, 0, 100)) {
201
- throw new RangeError('Reverb.js: Inpulse Response delay time must be less than 100.');
202
- }
203
- this._options.delay = value;
204
- this.buildImpulse();
205
- console.debug(`Reverb.js: Set inpulse response delay time to ${value}sec.`);
206
- }
207
- /**
208
- * Reverse the impulse response.
209
- * @param {boolean} reverse
210
- */
211
- reverse(reverse) {
212
- this._options.reverse = reverse;
213
- this.buildImpulse();
214
- console.debug(`Reverb.js: Inpulse response is ${reverse ? '' : 'not '}reversed.`);
215
- }
216
- /**
217
- * Filter type.
218
- * @param {BiquadFilterType} type
219
- */
220
- filterType(type) {
221
- this.filterNode.type = this._options.filterType = type;
222
- console.debug(`Set filter type to ${type}`);
223
- }
224
- /**
225
- * Filter frequency.
226
- * @param {number} freq
227
- */
228
- filterFreq(freq) {
229
- if (!this.inRange(freq, 20, 5000)) {
230
- throw new RangeError('Reverb.js: Filter frequrncy must be between 20 and 5000.');
231
- }
232
- this._options.filterFreq = freq;
233
- this.filterNode.frequency.value = this._options.filterFreq;
234
- console.debug(`Set filter frequency to ${freq}Hz.`);
235
- }
236
- /**
237
- * Filter quality.
238
- * @param {number} q
239
- */
240
- filterQ(q) {
241
- if (!this.inRange(q, 0, 10)) {
242
- throw new RangeError('Reverb.js: Filter quality value must be between 0 and 10.');
243
- }
244
- this._options.filterQ = q;
245
- this.filterNode.Q.value = this._options.filterQ;
246
- console.debug(`Set filter quality to ${q}.`);
247
- }
248
- /**
249
- * Inpulse Response Noise algorithm.
250
- * @param type
251
- */
252
- setNoise(type) {
253
- this._options.noise = type;
254
- this.buildImpulse();
255
- console.debug(`Set Noise type to ${type}.`);
256
- }
257
- /**
258
- * return true if in range, otherwise false
259
- * @private
260
- * @param {number} x Target value
261
- * @param {number} min Minimum value
262
- * @param {number} max Maximum value
263
- * @return {bool}
264
- */
265
- inRange(x, min, max) {
266
- return (x - min) * (x - max) <= 0;
267
- }
268
- /**
269
- * Utility function for building an impulse response
270
- * from the module parameters.
271
- * @private
272
- */
273
- buildImpulse() {
274
- // インパルス応答生成ロジック
275
- /** @type {number} サンプリングレート */
276
- const rate = this.ctx.sampleRate;
277
- /** @type {number} インパルス応答の演奏時間 */
278
- const duration = Math.max(rate * this._options.time, 1);
279
- /** @type {number} インパルス応答が始まるまでの遅延時間 */
280
- const delayDuration = rate * this._options.delay;
281
- /** @type {AudioBuffer} インパルス応答バッファ(今の所ステレオのみ) */
282
- const impulse = this.ctx.createBuffer(2, duration, rate);
283
- /** @type {Array<number>|ArrayBufferView} 左チャンネル */
284
- const impulseL = new Float32Array(duration);
285
- /** @type {Array<number>|ArrayBufferView} 右チャンネル*/
286
- const impulseR = new Float32Array(duration);
287
- /** 一時計算用 */
288
- const b = [0, 0, 0, 0, 0, 0, 0];
289
- for (let i = 0; i < duration; i++) {
290
- /** @type {number} 減衰率 */
291
- let n = 0;
292
- if (i < delayDuration) {
293
- // Delay Effect
294
- impulseL[i] = 0;
295
- impulseR[i] = 0;
296
- n = this._options.reverse
297
- ? duration - (i - delayDuration)
298
- : i - delayDuration;
299
- }
300
- else {
301
- n = this._options.reverse ? duration - i : i;
302
- }
303
- switch (this._options.noise) {
304
- default:
305
- case NoiseType_1.NoiseType.WHITE:
306
- // White Noise
307
- impulseL[i] = Reverb.whiteNoise();
308
- impulseR[i] = Reverb.whiteNoise();
309
- break;
310
- case NoiseType_1.NoiseType.PINK:
311
- // ピンクノイズ生成処理
312
- // http://noisehack.com/generate-noise-web-audio-api/
313
- b[0] = 0.99886 * b[0] + Reverb.whiteNoise() * 0.0555179;
314
- b[1] = 0.99332 * b[1] + Reverb.whiteNoise() * 0.0750759;
315
- b[2] = 0.969 * b[2] + Reverb.whiteNoise() * 0.153852;
316
- b[3] = 0.8665 * b[3] + Reverb.whiteNoise() * 0.3104856;
317
- b[4] = 0.55 * b[4] + Reverb.whiteNoise() * 0.5329522;
318
- b[5] = -0.7616 * b[5] - Reverb.whiteNoise() * 0.016898;
319
- impulseL[i] =
320
- b[0] +
321
- b[1] +
322
- b[2] +
323
- b[3] +
324
- b[4] +
325
- b[5] +
326
- b[6] +
327
- Reverb.whiteNoise() * 0.5362;
328
- impulseR[i] =
329
- b[0] +
330
- b[1] +
331
- b[2] +
332
- b[3] +
333
- b[4] +
334
- b[5] +
335
- b[6] +
336
- Reverb.whiteNoise() * 0.5362;
337
- // ゲイン補償処理
338
- impulseL[i] *= 0.11;
339
- impulseR[i] *= 0.11;
340
- b[6] = Reverb.whiteNoise() * 0.115926;
341
- break;
342
- case NoiseType_1.NoiseType.BROWN:
343
- // ブラウンノイズ生成処理
344
- impulseL[i] = (b[0] + 0.02 * Reverb.whiteNoise()) / 1.02;
345
- b[0] = impulseL[i];
346
- impulseR[i] = (b[1] + 0.02 * Reverb.whiteNoise()) / 1.02;
347
- b[1] = impulseR[i];
348
- // ゲイン補償処理
349
- impulseL[i] *= 3.5;
350
- impulseR[i] *= 3.5;
351
- break;
352
- }
353
- // 音を減衰させる
354
- impulseL[i] *= (1 - n / duration) ** this._options.decay;
355
- impulseR[i] *= (1 - n / duration) ** this._options.decay;
356
- }
357
- // インパルス応答のバッファに生成したWaveTableを代入
358
- impulse.getChannelData(0).set(impulseL);
359
- impulse.getChannelData(1).set(impulseR);
360
- this.convolverNode.buffer = impulse;
361
- }
362
- /**
363
- * Generate white noise
364
- */
365
- static whiteNoise() {
366
- // TODO: この乱数は本当に偏り無いのだろうか?
367
- return Math.random() * 2 - 1;
368
- }
369
- }
370
- exports.default = Reverb;
371
- /**
372
- * デフォルト値
373
- */
374
- const optionDefaults = {
375
- noise: 1,
376
- decay: 5,
377
- delay: 0,
378
- reverse: false,
379
- time: 3,
380
- filterType: 'lowpass',
381
- filterFreq: 2200,
382
- filterQ: 1,
383
- mix: 0.5,
384
- };
385
-
386
-
387
- /***/ })
388
-
389
- /******/ });
390
- /************************************************************************/
391
- /******/ // The module cache
392
- /******/ var __webpack_module_cache__ = {};
393
- /******/
394
- /******/ // The require function
395
- /******/ function __webpack_require__(moduleId) {
396
- /******/ // Check if module is in cache
397
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
398
- /******/ if (cachedModule !== undefined) {
399
- /******/ return cachedModule.exports;
400
- /******/ }
401
- /******/ // Create a new module (and put it into the cache)
402
- /******/ var module = __webpack_module_cache__[moduleId] = {
403
- /******/ // no module.id needed
404
- /******/ // no module.loaded needed
405
- /******/ exports: {}
406
- /******/ };
407
- /******/
408
- /******/ // Execute the module function
409
- /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
410
- /******/
411
- /******/ // Return the exports of the module
412
- /******/ return module.exports;
413
- /******/ }
414
- /******/
415
- /************************************************************************/
416
- /******/
417
- /******/ // startup
418
- /******/ // Load entry module and return exports
419
- /******/ // This entry module is referenced by other modules so it can't be inlined
420
- /******/ var __webpack_exports__ = __webpack_require__("./src/Reverb.ts");
421
- /******/
422
- /******/ return __webpack_exports__;
423
- /******/ })()
424
- ;
425
- });
426
- //# sourceMappingURL=reverb.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["webpack://Reverb/webpack/universalModuleDefinition","webpack://Reverb/./src/Meta.ts","webpack://Reverb/./src/Reverb.ts","webpack://Reverb/webpack/bootstrap","webpack://Reverb/webpack/startup"],"names":[],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;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AC,CAAC,CAAC,CAAC;aAC9C;YAED,kCAAkC;YAClC,MAAM,GAAG,GAAW,CAAC,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;YAC9D,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,GAAG,CAAC;YACpC,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,GAAG,CAAC;SACrC;QAED,gCAAgC;QAChC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACxC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAExC,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,OAAO,CAAC;IACtC,CAAC;IACD;;;;;OAKG;IACK,QAAQ;QACd,2BAA2B;QAC3B,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACF;AA7QD,yBA6QC;AAED;;GAEG;AACH,MAAM,cAAc,GAAoB;IACtC,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,CAAC;IACP,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,CAAC;IACV,GAAG,EAAE,GAAG;CACT,CAAC;;;;;;;UCvSF;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;UCrBA;UACA;UACA;UACA","file":"reverb.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"Reverb\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Reverb\"] = factory();\n\telse\n\t\troot[\"Reverb\"] = factory();\n})((typeof self !== 'undefined' ? self : this), function() {\nreturn ","import MetaInterface from './interfaces/MetaInterface';\n\n// This file is auto-generated by the build system.\nconst meta: MetaInterface = {\n version: '0.3.1',\n date: '2020-12-23T05:51:29.106Z',\n};\nexport default meta;\n","import Meta from './Meta';\nimport OptionInterface from './interfaces/OptionInterface';\n\n/**\n * JS reverb effect class\n *\n * @author Logue <logue@hotmail.co.jp>\n * @copyright 2019-2020 Masashi Yoshikawa <https://logue.dev/> All rights reserved.\n * @license MIT\n * @see {@link https://github.com/logue/Reverb.js}\n * {@link https://github.com/web-audio-components/simple-reverb}\n */\nexport default class Reverb {\n /** @type {string} バージョン */\n public readonly version: string;\n /** @type {string} ビルド日時 */\n public readonly build: string;\n /** @type {AudioContext} AudioContext */\n private readonly ctx: AudioContext;\n /** @type {GainNode} ウェットレベル(エフェクターをかけたレベル) */\n private readonly wetGainNode: GainNode;\n /** @type {GainNode} ドライレベル(原音レベル) */\n private readonly dryGainNode: GainNode;\n /** @type {BiquadFilterNode} インパルス応答用フィルタ */\n private readonly filterNode: BiquadFilterNode;\n /** @type {ConvolverNode} 畳み込みノード */\n private readonly convolverNode: ConvolverNode;\n /** @type {GainNode} 出力ノード */\n private readonly outputNode: GainNode;\n /** @type {Option} 変数 */\n private readonly _options: OptionInterface;\n /** @type {boolean} 接続済みフラグ */\n private isConnected: boolean;\n\n /**\n * constructor\n * @param {AudioContext} ctx Root AudioContext\n * @param {OptionInterface} options Configure\n */\n constructor(ctx: AudioContext, options: OptionInterface | undefined) {\n // バージョン情報など\n this.version = Meta.version;\n this.build = Meta.date;\n // マスターのAudioContextを取得\n this.ctx = ctx;\n // デフォルト値をマージ\n this._options = {...optionDefaults, ...options} as const;\n // 初期化\n this.wetGainNode = this.ctx.createGain();\n this.dryGainNode = this.ctx.createGain();\n this.filterNode = this.ctx.createBiquadFilter();\n this.convolverNode = this.ctx.createConvolver();\n this.outputNode = this.ctx.createGain();\n // 接続済みフラグを落とす\n this.isConnected = false;\n // インパルス応答を生成\n this.buildImpulse();\n }\n\n /**\n * connect\n * @param {AudioNode} sourceNode 原音ノード\n * @return {AudioNode}\n */\n public connect(sourceNode: AudioNode): AudioNode {\n // 畳み込みノードをウェットレベルに接続\n this.convolverNode.connect(this.filterNode);\n // フィルタノードをウェットレベルに接続\n this.filterNode.connect(this.wetGainNode);\n // 入力ノードを畳み込みノードに接続\n sourceNode.connect(this.convolverNode);\n // ドライレベルを出力ノードに接続\n sourceNode.connect(this.dryGainNode).connect(this.outputNode);\n // ウェットレベルを出力ノードに接続\n sourceNode.connect(this.wetGainNode).connect(this.outputNode);\n // 接続済みフラグを立てる\n this.isConnected = true;\n\n return this.outputNode;\n }\n\n /**\n * disconnect\n * @param {AudioNode} sourceNode 原音のノード\n * @return {AudioNode}\n */\n public disconnect(sourceNode: AudioNode | undefined): AudioNode | undefined {\n // 初期状態ではノードがつながっていないためエラーになる\n if (this.isConnected) {\n // 畳み込みノードをウェットレベルから切断\n this.convolverNode.disconnect(this.filterNode);\n // フィルタノードをウェットレベルから切断\n this.filterNode.disconnect(this.wetGainNode);\n }\n // 接続済みフラグを解除\n this.isConnected = false;\n\n // そのままノードを返す(他のAPIに似せるため)\n return sourceNode;\n }\n\n /**\n * Dry/Wet ratio\n * @param {number} mix\n */\n public mix(mix: number): void {\n if (!this.inRange(mix, 0, 1)) {\n throw new RangeError('Reverb.js: Dry/Wet ratio must be between 0 to 1.');\n }\n this._options.mix = mix;\n this.dryGainNode.gain.value = 1 - this._options.mix;\n this.wetGainNode.gain.value = this._options.mix;\n console.debug(`Reverb.js: Set dry/wet ratio to ${mix * 100}%`);\n }\n\n /**\n * Set Impulse Response time length (second)\n * @param {number} value\n */\n public time(value: number): void {\n if (!this.inRange(value, 1, 50)) {\n throw new RangeError(\n 'Reverb.js: Time length of inpulse response must be less than 50sec.'\n );\n }\n this._options.time = value;\n this.buildImpulse();\n console.info(`Reverb.js: Set inpulse response time length to ${value}sec.`);\n }\n\n /**\n * Impulse response decay rate.\n * @param {number} value\n */\n public decay(value: number): void {\n if (!this.inRange(value, 0, 100)) {\n throw new RangeError(\n 'Reverb.js: Inpulse Response decay level must be less than 100.'\n );\n }\n this._options.decay = value;\n this.buildImpulse();\n console.debug(`Reverb.js: Set inpulse response decay level to ${value}.`);\n }\n\n /**\n * Impulse response delay time. (NOT deley effect)\n * @param {number} value\n */\n public delay(value: number): void {\n if (!this.inRange(value, 0, 100)) {\n throw new RangeError(\n 'Reverb.js: Inpulse Response delay time must be less than 100.'\n );\n }\n this._options.delay = value;\n this.buildImpulse();\n console.debug(`Reverb.js: Set inpulse response delay time to ${value}sec.`);\n }\n\n /**\n * Reverse the impulse response.\n * @param {boolean} reverse\n */\n public reverse(reverse: boolean): void {\n this._options.reverse = reverse;\n this.buildImpulse();\n console.debug(\n `Reverb.js: Inpulse response is ${reverse ? '' : 'not '}reversed.`\n );\n }\n\n /**\n * Filter type.\n * @param {BiquadFilterType} type\n */\n public filterType(type: BiquadFilterType): void {\n this.filterNode.type = this._options.filterType = type;\n console.debug(`Set filter type to ${type}`);\n }\n\n /**\n * Filter frequency.\n * @param {number} freq\n */\n public filterFreq(freq: number): void {\n if (!this.inRange(freq, 20, 5000)) {\n throw new RangeError(\n 'Reverb.js: Filter frequrncy must be between 20 and 5000.'\n );\n }\n this._options.filterFreq = freq;\n this.filterNode.frequency.value = this._options.filterFreq;\n console.debug(`Set filter frequency to ${freq}Hz.`);\n }\n\n /**\n * Filter quality.\n * @param {number} q\n */\n public filterQ(q: number): void {\n if (!this.inRange(q, 0, 10)) {\n throw new RangeError(\n 'Reverb.js: Filter quality value must be between 0 and 10.'\n );\n }\n this._options.filterQ = q;\n this.filterNode.Q.value = this._options.filterQ;\n console.debug(`Set filter quality to ${q}.`);\n }\n\n /**\n * return true if in range, otherwise false\n * @private\n * @param {number} x Target value\n * @param {number} min Minimum value\n * @param {number} max Maximum value\n * @return {bool}\n */\n private inRange(x: number, min: number, max: number): boolean {\n return (x - min) * (x - max) <= 0;\n }\n\n /**\n * Utility function for building an impulse response\n * from the module parameters.\n * @private\n */\n private buildImpulse(): void {\n // インパルス応答生成ロジック\n\n /** @type {number} サンプリングレート */\n const rate: number = this.ctx.sampleRate;\n /** @type {number} インパルス応答の演奏時間 */\n const duration: number = Math.max(rate * this._options.time, 1);\n /** @type {number} インパルス応答が始まるまでの遅延時間 */\n const delayDuration: number = rate * this._options.delay;\n /** @type {AudioBuffer} インパルス応答バッファ(今の所ステレオのみ) */\n const impulse: AudioBuffer = this.ctx.createBuffer(2, duration, rate);\n /** @type {Array<number>|ArrayBufferView} 左チャンネル */\n const impulseL: Float32Array = new Float32Array(duration);\n /** @type {Array<number>|ArrayBufferView} 右チャンネル*/\n const impulseR: Float32Array = new Float32Array(duration);\n\n for (let i = 0; i < duration; i++) {\n /** @type {number} 減衰率 */\n let n = 0;\n\n if (i < delayDuration) {\n // Delay Effect\n impulseL[i] = 0;\n impulseR[i] = 0;\n n = this._options.reverse\n ? duration - (i - delayDuration)\n : i - delayDuration;\n } else {\n n = this._options.reverse ? duration - i : i;\n }\n\n /** @type {number} 平方根を利用した減衰曲線 */\n const pow: number = (1 - n / duration) ** this._options.decay;\n impulseL[i] = this.getNoise() * pow;\n impulseR[i] = this.getNoise() * pow;\n }\n\n // インパルス応答のバッファに生成したWaveTableを代入\n impulse.getChannelData(0).set(impulseL);\n impulse.getChannelData(1).set(impulseR);\n\n this.convolverNode.buffer = impulse;\n }\n /**\n * Generate white noise\n * @param {number} rate Attenuation rate\n * @return {number}\n * @private\n */\n private getNoise(): number {\n // TODO: 他のカラードノイズを指定できるように\n return Math.random() * 2 - 1;\n }\n}\n\n/**\n * デフォルト値\n */\nconst optionDefaults: OptionInterface = {\n decay: 5,\n delay: 0,\n reverse: false,\n time: 3,\n filterType: 'lowpass',\n filterFreq: 2200,\n filterQ: 1,\n mix: 0.5,\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tif(__webpack_module_cache__[moduleId]) {\n\t\treturn __webpack_module_cache__[moduleId].exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// module exports must be returned from runtime so entry inlining is disabled\n// startup\n// Load entry module and return exports\nreturn __webpack_require__(\"./src/Reverb.ts\");\n"],"sourceRoot":""}
package/src/Meta.ts DELETED
@@ -1,8 +0,0 @@
1
- import MetaInterface from './interfaces/MetaInterface';
2
-
3
- // This file is auto-generated by the build system.
4
- const meta: MetaInterface = {
5
- version: '0.4.2',
6
- date: '2021-07-04T08:13:17.775Z',
7
- };
8
- export default meta;
package/src/NoiseType.ts DELETED
@@ -1,5 +0,0 @@
1
- export enum NoiseType {
2
- WHITE,
3
- PINK,
4
- BROWN,
5
- }