@logue/reverb 0.5.1 → 0.5.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019-2021 Masashi Yoshikawa <https://logue.dev>
3
+ Copyright (c) 2019-2022 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
@@ -1,6 +1,10 @@
1
1
  # Reverb.js
2
2
 
3
- [![npm version](https://badge.fury.io/js/%40logue%2Freverb.svg)](https://badge.fury.io/js/%40logue%2Freverb)
3
+ [![jsdelivr CDN](https://data.jsdelivr.com/v1/package/npm/@logue/reverb/badge)](https://www.jsdelivr.com/package/npm/@logue/reverb)
4
+ [![NPM Downloads](https://img.shields.io/npm/dm/vuetify-swatches.svg?style=flat)](https://www.npmjs.com/package/@logue/reverb)
5
+ [![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@logue/reverb/file/README.md)
6
+ [![npm version](https://img.shields.io/npm/v/@logue/reverb.svg)](https://www.npmjs.com/package/@logue/reverb)
7
+ [![Open in Gitpod](https://shields.io/badge/Open%20in-Gitpod-green?logo=Gitpod)](https://gitpod.io/#https://github.com/logue/Reverb.js)
4
8
 
5
9
  Append reverb effect to audio source.
6
10
 
@@ -8,22 +12,22 @@ This script is originally a spin out of [sf2synth.js](https://github.com/logue/s
8
12
 
9
13
  ## Sample
10
14
 
11
- * <https://logue.dev/Reverb.js/>
12
- * <https://logue.dev/Reverb.js/localaudio.html>
15
+ - <https://logue.dev/Reverb.js/>
16
+ - <https://logue.dev/Reverb.js/localaudio.html>
13
17
 
14
18
  ## Syntax
15
19
 
16
20
  ```js
17
21
  const reverb = new Reverb(ctx, {
18
- noise: 0, // Inpulse Response Noise algorithm (0: White noise, 1: Pink noise, 2: Brown noise)
19
- decay: 5, // Amount of IR (Inpulse Response) decay. 0~100
20
- delay: 0, // Delay time o IR. (NOT delay effect) 0~100 [sec]
21
- filterFreq: 2200, // Filter frequency. 20~5000 [Hz]
22
- filterQ: 1, // Filter quality. 0~10
23
- filterType: 'lowpass', // Filter type. 'bandpass' etc. See https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode/type .
24
- mix: 0.5, // Dry (Original Sound) and Wet (Effected sound) raito. 0~1
25
- reverse: false, // Reverse IR.
26
- time: 3 // Time length of IR. 0~50 [sec]
22
+ noise: 0, // Inpulse Response Noise algorithm (0: White noise, 1: Pink noise, 2: Brown noise)
23
+ decay: 5, // Amount of IR (Inpulse Response) decay. 0~100
24
+ delay: 0, // Delay time o IR. (NOT delay effect) 0~100 [sec]
25
+ filterFreq: 2200, // Filter frequency. 20~5000 [Hz]
26
+ filterQ: 1, // Filter quality. 0~10
27
+ filterType: 'lowpass', // Filter type. 'bandpass' etc. See https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode/type .
28
+ mix: 0.5, // Dry (Original Sound) and Wet (Effected sound) raito. 0~1
29
+ reverse: false, // Reverse IR.
30
+ time: 3, // Time length of IR. 0~50 [sec]
27
31
  });
28
32
  ```
29
33
 
@@ -60,10 +64,10 @@ sourceNode.play();
60
64
 
61
65
  ## Reference
62
66
 
63
- * [Web Audio API](https://www.w3.org/TR/webaudio/)
64
- * [Web Audio API日本語訳](https://g200kg.github.io/web-audio-api-ja/)
65
- * [コンボルバーの使い方](https://www.g200kg.com/jp/docs/webaudio/convolver.html)
66
- * [WebAudioの闇](https://qiita.com/zprodev/items/7fcd8335d7e8e613a01f)
67
+ - [Web Audio API](https://www.w3.org/TR/webaudio/)
68
+ - [Web Audio API 日本語訳](https://g200kg.github.io/web-audio-api-ja/)
69
+ - [コンボルバーの使い方](https://www.g200kg.com/jp/docs/webaudio/convolver.html)
70
+ - [WebAudio の闇](https://qiita.com/zprodev/items/7fcd8335d7e8e613a01f)
67
71
 
68
72
  ## License
69
73
 
package/dist/Meta.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type MetaInterface from './interfaces/MetaInterface';
2
+ declare const meta: MetaInterface;
3
+ export default meta;
4
+ //# sourceMappingURL=Meta.d.ts.map
File without changes
@@ -1,14 +1,14 @@
1
1
  /** Impulse response noise generation algorithm */
2
2
  declare const Noise: {
3
- /** White noise */
4
- readonly WHITE: 'white';
5
- /** Pink noise */
6
- readonly PINK: 'pink';
7
- /** Brown Noise */
8
- readonly BROWN: 'brown';
3
+ /** White noise */
4
+ readonly WHITE: "white";
5
+ /** Pink noise */
6
+ readonly PINK: "pink";
7
+ /** Brown Noise */
8
+ readonly BROWN: "brown";
9
9
  };
10
10
  /** Noise Type */
11
11
  export declare type NoiseType = typeof Noise[keyof typeof Noise];
12
12
  /** Noise */
13
13
  export default Noise;
14
- // # sourceMappingURL=NoiseType.d.ts.map
14
+ //# sourceMappingURL=NoiseType.d.ts.map
File without changes
@@ -0,0 +1,113 @@
1
+ import type OptionInterface from './interfaces/OptionInterface';
2
+ import { type NoiseType } from './NoiseType';
3
+ /**
4
+ * JS reverb effect class
5
+ */
6
+ export default class Reverb {
7
+ /** Version strings */
8
+ readonly version: string;
9
+ /** Build date */
10
+ readonly build: string;
11
+ /** AudioContext */
12
+ private readonly ctx;
13
+ /** Wet Level (Reverberated node) */
14
+ private readonly wetGainNode;
15
+ /** Dry Level (Original sound node) */
16
+ private readonly dryGainNode;
17
+ /** Impulse response filter */
18
+ private readonly filterNode;
19
+ /** Convolution node for applying impulse response */
20
+ private readonly convolverNode;
21
+ /** Output nodse */
22
+ private readonly outputNode;
23
+ /** Option */
24
+ private readonly _options;
25
+ /** Connected flag */
26
+ private isConnected;
27
+ /**
28
+ * Constructor
29
+ *
30
+ * @param ctx - Root AudioContext
31
+ * @param options - Configure
32
+ */
33
+ constructor(ctx: AudioContext, options: OptionInterface | undefined);
34
+ /**
35
+ * Connect the node for the reverb effect to the original sound node.
36
+ *
37
+ * @param sourceNode - Input source node
38
+ */
39
+ connect(sourceNode: AudioNode): AudioNode;
40
+ /**
41
+ * Disconnect the reverb node
42
+ *
43
+ * @param sourceNode - Input source node
44
+ */
45
+ disconnect(sourceNode: AudioNode | undefined): AudioNode | undefined;
46
+ /**
47
+ * Dry/Wet ratio
48
+ *
49
+ * @param mix - Ratio (0~1)
50
+ */
51
+ mix(mix: number): void;
52
+ /**
53
+ * Set Impulse Response time length (second)
54
+ *
55
+ * @param value - IR length
56
+ */
57
+ time(value: number): void;
58
+ /**
59
+ * Impulse response decay rate.
60
+ *
61
+ * @param value - Decay value
62
+ */
63
+ decay(value: number): void;
64
+ /**
65
+ * Delay before reverberation starts
66
+ *
67
+ * @param value - Time[ms]
68
+ */
69
+ delay(value: number): void;
70
+ /**
71
+ * Reverse the impulse response.
72
+ *
73
+ * @param reverse - Reverse IR
74
+ */
75
+ reverse(reverse: boolean): void;
76
+ /**
77
+ * Filter for impulse response
78
+ *
79
+ * @param type - Filiter Type
80
+ */
81
+ filterType(type: BiquadFilterType): void;
82
+ /**
83
+ * Filter frequency applied to impulse response
84
+ *
85
+ * @param freq - Frequency
86
+ */
87
+ filterFreq(freq: number): void;
88
+ /**
89
+ * Filter quality.
90
+ *
91
+ * @param q - Quality
92
+ */
93
+ filterQ(q: number): void;
94
+ /**
95
+ * Inpulse Response Noise algorithm.
96
+ *
97
+ * @param type - IR noise algorithm type.
98
+ */
99
+ setNoise(type: NoiseType): void;
100
+ /**
101
+ * Return true if in range, otherwise false
102
+ *
103
+ * @param x - Target value
104
+ * @param min - Minimum value
105
+ * @param max - Maximum value
106
+ */
107
+ private inRange;
108
+ /** Utility function for building an impulse response from the module parameters. */
109
+ private buildImpulse;
110
+ /** Generate white noise */
111
+ private static whiteNoise;
112
+ }
113
+ //# sourceMappingURL=Reverb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAChE,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iBAAiB;IACjB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,8BAA8B;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,aAAa;IACb,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,qBAAqB;IACrB,OAAO,CAAC,WAAW,CAAU;IAE7B;;;;;OAKG;gBACS,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,GAAG,SAAS;IAsBnE;;;;OAIG;IACI,OAAO,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS;IAsBhD;;;;OAIG;IACI,UAAU,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS;IAe3E;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAU7B;;;;OAIG;IACI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWhC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAQtC;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAK/C;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWrC;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAW/B;;;;OAIG;IACI,QAAQ,CAAC,IAAI,EAAE,SAAS;IAM/B;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAIf,oFAAoF;IACpF,OAAO,CAAC,YAAY;IAoGpB,2BAA2B;IAC3B,OAAO,CAAC,MAAM,CAAC,UAAU;CAI1B"}
@@ -0,0 +1,8 @@
1
+ /** Meta Information Interface */
2
+ export default interface MetaInterface {
3
+ /** Version */
4
+ version: string;
5
+ /** Build Date */
6
+ date: string;
7
+ }
8
+ //# sourceMappingURL=MetaInterface.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { NoiseType } from '../NoiseType';
2
+ /** Reverb Option */
3
+ export default interface OptionInterface {
4
+ /** Types of impulse response noise generation algorithms */
5
+ noise: NoiseType;
6
+ /** Decay */
7
+ decay: number;
8
+ /** Delay until impulse response is generated */
9
+ delay: number;
10
+ /** Filter frequency applied to impulse response[Hz] */
11
+ filterFreq: number;
12
+ /** Filter quality for impulse response */
13
+ filterQ: number;
14
+ /** Filter type for impulse response */
15
+ filterType: BiquadFilterType;
16
+ /** Dry/Wet ratio */
17
+ mix: number;
18
+ /** Invert the impulse response */
19
+ reverse: boolean;
20
+ /** Impulse response length */
21
+ time: number;
22
+ /** Prevents multiple effectors from being connected. */
23
+ once: boolean;
24
+ }
25
+ //# sourceMappingURL=OptionInterface.d.ts.map
package/dist/reverb.es.js CHANGED
@@ -1,20 +1,23 @@
1
+ /**
2
+ * @logue/reverb
3
+ *
4
+ * @description JavaScript Reverb effect class
5
+ * @author Logue <logue@hotmail.co.jp>
6
+ * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
+ * @license MIT
8
+ * @version 0.5.4
9
+ * @see {@link https://github.com/logue/Reverb.js}
10
+ */
11
+
1
12
  const meta = {
2
- version: "0.5.0",
3
- date: "2022-02-21T09:25:39.234Z"
13
+ version: "0.5.4",
14
+ date: "2022-07-08T12:56:05.192Z"
4
15
  };
5
16
  const Noise = {
6
17
  WHITE: "white",
7
18
  PINK: "pink",
8
19
  BROWN: "brown"
9
20
  };
10
- /**
11
- * JS reverb effect class
12
- *
13
- * @license MIT
14
- * @author Logue {@link logue@hotmail.co.jp}
15
- * @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
16
- * @see {@link https://github.com/logue/Reverb.js}
17
- */
18
21
  class Reverb {
19
22
  constructor(ctx, options) {
20
23
  this.version = meta.version;
@@ -58,7 +61,6 @@ class Reverb {
58
61
  this._options.mix = mix;
59
62
  this.dryGainNode.gain.value = 1 - this._options.mix;
60
63
  this.wetGainNode.gain.value = this._options.mix;
61
- console.debug(`Reverb.js: Set dry/wet ratio to ${mix * 100}%`);
62
64
  }
63
65
  time(value) {
64
66
  if (!this.inRange(value, 1, 50)) {
@@ -66,7 +68,6 @@ class Reverb {
66
68
  }
67
69
  this._options.time = value;
68
70
  this.buildImpulse();
69
- console.info(`Reverb.js: Set inpulse response time length to ${value}sec.`);
70
71
  }
71
72
  decay(value) {
72
73
  if (!this.inRange(value, 0, 100)) {
@@ -74,7 +75,6 @@ class Reverb {
74
75
  }
75
76
  this._options.decay = value;
76
77
  this.buildImpulse();
77
- console.debug(`Reverb.js: Set inpulse response decay level to ${value}.`);
78
78
  }
79
79
  delay(value) {
80
80
  if (!this.inRange(value, 0, 100)) {
@@ -82,16 +82,13 @@ class Reverb {
82
82
  }
83
83
  this._options.delay = value;
84
84
  this.buildImpulse();
85
- console.debug(`Reverb.js: Set inpulse response delay time to ${value}sec.`);
86
85
  }
87
86
  reverse(reverse) {
88
87
  this._options.reverse = reverse;
89
88
  this.buildImpulse();
90
- console.debug(`Reverb.js: Inpulse response is ${reverse ? "" : "not "}reversed.`);
91
89
  }
92
90
  filterType(type) {
93
91
  this.filterNode.type = this._options.filterType = type;
94
- console.debug(`Set filter type to ${type}`);
95
92
  }
96
93
  filterFreq(freq) {
97
94
  if (!this.inRange(freq, 20, 5e3)) {
@@ -99,7 +96,6 @@ class Reverb {
99
96
  }
100
97
  this._options.filterFreq = freq;
101
98
  this.filterNode.frequency.value = this._options.filterFreq;
102
- console.debug(`Set filter frequency to ${freq}Hz.`);
103
99
  }
104
100
  filterQ(q) {
105
101
  if (!this.inRange(q, 0, 10)) {
@@ -112,7 +108,6 @@ class Reverb {
112
108
  setNoise(type) {
113
109
  this._options.noise = type;
114
110
  this.buildImpulse();
115
- console.debug(`Set Noise type to ${type}.`);
116
111
  }
117
112
  inRange(x, min, max) {
118
113
  return (x - min) * (x - max) <= 0;
@@ -1,10 +1,12 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Reverb=t()}(this,(function(){"use strict";const e="0.5.0",t="2022-02-21T09:25:39.234Z",i="white",s="pink",o="brown";
2
1
  /**
3
- * JS reverb effect class
4
- *
5
- * @license MIT
6
- * @author Logue {@link logue@hotmail.co.jp}
7
- * @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
8
- * @see {@link https://github.com/logue/Reverb.js}
9
- */
10
- class n{constructor(i,s){this.version=e,this.build=t,this.ctx=i,this._options={...r,...s},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.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).connect(this.outputNode),e.connect(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(!this.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-this._options.mix,this.wetGainNode.gain.value=this._options.mix}time(e){if(!this.inRange(e,1,50))throw new RangeError("Reverb.js: Time length of inpulse response must be less than 50sec.");this._options.time=e,this.buildImpulse()}decay(e){if(!this.inRange(e,0,100))throw new RangeError("Reverb.js: Inpulse Response decay level must be less than 100.");this._options.decay=e,this.buildImpulse()}delay(e){if(!this.inRange(e,0,100))throw new RangeError("Reverb.js: Inpulse Response delay time must be less than 100.");this._options.delay=e,this.buildImpulse()}reverse(e){this._options.reverse=e,this.buildImpulse()}filterType(e){this.filterNode.type=this._options.filterType=e}filterFreq(e){if(!this.inRange(e,20,5e3))throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");this._options.filterFreq=e,this.filterNode.frequency.value=this._options.filterFreq}filterQ(e){if(!this.inRange(e,0,10))throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");this._options.filterQ=e,this.filterNode.Q.value=this._options.filterQ}setNoise(e){this._options.noise=e,this.buildImpulse()}inRange(e,t,i){return(e-t)*(e-i)<=0}buildImpulse(){const e=this.ctx.sampleRate,t=Math.max(e*this._options.time,1),i=e*this._options.delay,r=this.ctx.createBuffer(2,t,e),h=new Float32Array(t),a=new Float32Array(t),l=[0,0,0,0,0,0,0];for(let c=0;c<t;c++){let e=0;switch(c<i?(h[c]=0,a[c]=0,e=this._options.reverse?t-(c-i):c-i):e=this._options.reverse?t-c:c,this._options.noise){case s:l[0]=.99886*l[0]+.0555179*n.whiteNoise(),l[1]=.99332*l[1]+.0750759*n.whiteNoise(),l[2]=.969*l[2]+.153852*n.whiteNoise(),l[3]=.8665*l[3]+.3104856*n.whiteNoise(),l[4]=.55*l[4]+.5329522*n.whiteNoise(),l[5]=-.7616*l[5]-.016898*n.whiteNoise(),h[c]=l[0]+l[1]+l[2]+l[3]+l[4]+l[5]+l[6]+.5362*n.whiteNoise(),a[c]=l[0]+l[1]+l[2]+l[3]+l[4]+l[5]+l[6]+.5362*n.whiteNoise(),h[c]*=.11,a[c]*=.11,l[6]=.115926*n.whiteNoise();break;case o:h[c]=(l[0]+.02*n.whiteNoise())/1.02,l[0]=h[c],a[c]=(l[1]+.02*n.whiteNoise())/1.02,l[1]=a[c],h[c]*=3.5,a[c]*=3.5;break;default:h[c]=n.whiteNoise(),a[c]=n.whiteNoise()}h[c]*=(1-e/t)**this._options.decay,a[c]*=(1-e/t)**this._options.decay}r.getChannelData(0).set(h),r.getChannelData(1).set(a),this.convolverNode.buffer=r}static whiteNoise(){return 2*Math.random()-1}}const r={noise:i,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return n}));
2
+ * @logue/reverb
3
+ *
4
+ * @description JavaScript Reverb effect class
5
+ * @author Logue <logue@hotmail.co.jp>
6
+ * @copyright 2019-2022 By Masashi Yoshikawa All rights reserved.
7
+ * @license MIT
8
+ * @version 0.5.4
9
+ * @see {@link https://github.com/logue/Reverb.js}
10
+ */
11
+
12
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Reverb=t()}(this,(function(){"use strict";const e="0.5.4",t="2022-07-08T12:56:05.192Z",i="white",s="pink",o="brown";class n{constructor(i,s){this.version=e,this.build=t,this.ctx=i,this._options={...r,...s},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.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).connect(this.outputNode),e.connect(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(!this.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-this._options.mix,this.wetGainNode.gain.value=this._options.mix}time(e){if(!this.inRange(e,1,50))throw new RangeError("Reverb.js: Time length of inpulse response must be less than 50sec.");this._options.time=e,this.buildImpulse()}decay(e){if(!this.inRange(e,0,100))throw new RangeError("Reverb.js: Inpulse Response decay level must be less than 100.");this._options.decay=e,this.buildImpulse()}delay(e){if(!this.inRange(e,0,100))throw new RangeError("Reverb.js: Inpulse Response delay time must be less than 100.");this._options.delay=e,this.buildImpulse()}reverse(e){this._options.reverse=e,this.buildImpulse()}filterType(e){this.filterNode.type=this._options.filterType=e}filterFreq(e){if(!this.inRange(e,20,5e3))throw new RangeError("Reverb.js: Filter frequrncy must be between 20 and 5000.");this._options.filterFreq=e,this.filterNode.frequency.value=this._options.filterFreq}filterQ(e){if(!this.inRange(e,0,10))throw new RangeError("Reverb.js: Filter quality value must be between 0 and 10.");this._options.filterQ=e,this.filterNode.Q.value=this._options.filterQ}setNoise(e){this._options.noise=e,this.buildImpulse()}inRange(e,t,i){return(e-t)*(e-i)<=0}buildImpulse(){const e=this.ctx.sampleRate,t=Math.max(e*this._options.time,1),i=e*this._options.delay,r=this.ctx.createBuffer(2,t,e),h=new Float32Array(t),a=new Float32Array(t),l=[0,0,0,0,0,0,0];for(let c=0;c<t;c++){let e=0;switch(c<i?(h[c]=0,a[c]=0,e=this._options.reverse?t-(c-i):c-i):e=this._options.reverse?t-c:c,this._options.noise){case s:l[0]=.99886*l[0]+.0555179*n.whiteNoise(),l[1]=.99332*l[1]+.0750759*n.whiteNoise(),l[2]=.969*l[2]+.153852*n.whiteNoise(),l[3]=.8665*l[3]+.3104856*n.whiteNoise(),l[4]=.55*l[4]+.5329522*n.whiteNoise(),l[5]=-.7616*l[5]-.016898*n.whiteNoise(),h[c]=l[0]+l[1]+l[2]+l[3]+l[4]+l[5]+l[6]+.5362*n.whiteNoise(),a[c]=l[0]+l[1]+l[2]+l[3]+l[4]+l[5]+l[6]+.5362*n.whiteNoise(),h[c]*=.11,a[c]*=.11,l[6]=.115926*n.whiteNoise();break;case o:h[c]=(l[0]+.02*n.whiteNoise())/1.02,l[0]=h[c],a[c]=(l[1]+.02*n.whiteNoise())/1.02,l[1]=a[c],h[c]*=3.5,a[c]*=3.5;break;default:h[c]=n.whiteNoise(),a[c]=n.whiteNoise()}h[c]*=(1-e/t)**this._options.decay,a[c]*=(1-e/t)**this._options.decay}r.getChannelData(0).set(h),r.getChannelData(1).set(a),this.convolverNode.buffer=r}static whiteNoise(){return 2*Math.random()-1}}const r={noise:i,decay:2,delay:0,reverse:!1,time:2,filterType:"lowpass",filterFreq:2200,filterQ:1,mix:.5,once:!1};return n}));
package/package.json CHANGED
@@ -1,30 +1,15 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@logue/reverb",
4
- "version": "0.5.1",
5
- "description": "Reverb effect.",
6
- "files": [
7
- "dist",
8
- "types"
9
- ],
10
- "main": "./dist/reverb.umd.js",
11
- "module": "./dist/reverb.es.js",
12
- "exports": {
13
- ".": {
14
- "import": "./dist/reverb.es.js",
15
- "require": "./dist/reverb.umd.js"
16
- }
17
- },
18
- "types": "./types/Reverb.d.ts",
19
- "directories": {
20
- "doc": "docs"
21
- },
4
+ "version": "0.5.4",
5
+ "description": "JavaScript Reverb effect class",
22
6
  "keywords": [
23
7
  "webaudio",
24
8
  "convolver",
25
9
  "effect",
26
10
  "reverb"
27
11
  ],
12
+ "license": "MIT",
28
13
  "author": {
29
14
  "name": "Logue",
30
15
  "email": "logue@hotmail.co.jp",
@@ -38,39 +23,55 @@
38
23
  "bugs": {
39
24
  "url": "https://github.com/logue/Reverb.js/issues"
40
25
  },
26
+ "directories": {
27
+ "doc": "docs"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "main": "./dist/reverb.umd.js",
33
+ "module": "./dist/reverb.es.js",
34
+ "exports": {
35
+ ".": {
36
+ "import": "./dist/reverb.es.js",
37
+ "require": "./dist/reverb.umd.js"
38
+ }
39
+ },
40
+ "types": "./dist/Reverb.d.ts",
41
41
  "engines": {
42
- "node": ">=16"
42
+ "node": ">=16.16.0",
43
+ "yarn": ">=1.22.4"
43
44
  },
44
- "license": "MIT",
45
+ "packageManager": "yarn@3.2.1",
45
46
  "sideEffects": false,
46
47
  "scripts": {
47
48
  "dev": "vite",
48
- "build": "tsc && vite build",
49
+ "build": "vite build && tsc --declaration --emitDeclarationOnly",
49
50
  "build:clean": "rimraf dist",
50
51
  "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
51
52
  "prepare": "husky install"
52
53
  },
53
54
  "devDependencies": {
54
- "@types/node": "^17.0.18",
55
- "@typescript-eslint/eslint-plugin": "^5.12.0",
56
- "@typescript-eslint/parser": "^5.12.0",
57
- "eslint": "^8.9.0",
55
+ "@types/node": "^18.0.3",
56
+ "@typescript-eslint/eslint-plugin": "^5.30.5",
57
+ "@typescript-eslint/parser": "^5.30.5",
58
+ "eslint": "^8.19.0",
58
59
  "eslint-config-google": "^0.14.0",
59
- "eslint-config-prettier": "^8.4.0",
60
+ "eslint-config-prettier": "^8.5.0",
60
61
  "eslint-import-resolver-alias": "^1.1.2",
61
- "eslint-import-resolver-typescript": "^2.5.0",
62
- "eslint-plugin-import": "^2.25.4",
63
- "eslint-plugin-prettier": "^4.0.0",
64
- "eslint-plugin-tsdoc": "^0.2.14",
65
- "husky": "^7.0.4",
66
- "lint-staged": "^12.3.4",
67
- "prettier": "^2.5.1",
68
- "prettier-plugin-jsdoc": "^0.3.30",
69
- "prettier-plugin-md-nocjsp": "^1.2.0",
62
+ "eslint-import-resolver-typescript": "^3.2.4",
63
+ "eslint-plugin-import": "^2.26.0",
64
+ "eslint-plugin-jsdoc": "^39.3.3",
65
+ "eslint-plugin-prettier": "^4.2.1",
66
+ "eslint-plugin-tsdoc": "^0.2.16",
67
+ "husky": "^8.0.1",
68
+ "lint-staged": "^13.0.3",
69
+ "prettier": "^2.7.1",
70
70
  "rimraf": "^3.0.2",
71
- "typescript": "^4.5.5",
72
- "vite": "^2.8.4",
73
- "vite-plugin-eslint": "^1.3.0"
71
+ "typescript": "^4.7.4",
72
+ "vite": "^2.9.14",
73
+ "vite-plugin-banner": "^0.3.0",
74
+ "vite-plugin-checker": "^0.4.8"
74
75
  },
75
76
  "husky": {
76
77
  "hooks": {
@@ -80,5 +81,8 @@
80
81
  "lint-staged": {
81
82
  "*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
82
83
  "*": "prettier -w -u"
84
+ },
85
+ "resolutions": {
86
+ "prettier": "^2.7.1"
83
87
  }
84
88
  }
package/types/Meta.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type MetaInterface from '@/interfaces/MetaInterface';
2
- declare const meta: MetaInterface;
3
- export default meta;
4
- // # sourceMappingURL=Meta.d.ts.map
package/types/Reverb.d.ts DELETED
@@ -1,118 +0,0 @@
1
- import type OptionInterface from './interfaces/OptionInterface';
2
- import { type NoiseType } from './NoiseType';
3
- /**
4
- * JS reverb effect class
5
- *
6
- * @license MIT
7
- * @author Logue {@link logue@hotmail.co.jp}
8
- * @copyright 2019-2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
9
- * @see {@link https://github.com/logue/Reverb.js}
10
- */
11
- export default class Reverb {
12
- /** Version strings */
13
- readonly version: string;
14
- /** Build date */
15
- readonly build: string;
16
- /** AudioContext */
17
- private readonly ctx;
18
- /** Wet Level (Reverberated node) */
19
- private readonly wetGainNode;
20
- /** Dry Level (Original sound node) */
21
- private readonly dryGainNode;
22
- /** Impulse response filter */
23
- private readonly filterNode;
24
- /** Convolution node for applying impulse response */
25
- private readonly convolverNode;
26
- /** Output nodse */
27
- private readonly outputNode;
28
- /** Option */
29
- private readonly _options;
30
- /** Connected flag */
31
- private isConnected;
32
- /**
33
- * Constructor
34
- *
35
- * @param ctx - Root AudioContext
36
- * @param options - Configure
37
- */
38
- constructor(ctx: AudioContext, options: OptionInterface | undefined);
39
- /**
40
- * Connect the node for the reverb effect to the original sound node.
41
- *
42
- * @param sourceNode - Input source node
43
- */
44
- connect(sourceNode: AudioNode): AudioNode;
45
- /**
46
- * Disconnect the reverb node
47
- *
48
- * @param sourceNode - Input source node
49
- */
50
- disconnect(sourceNode: AudioNode | undefined): AudioNode | undefined;
51
- /**
52
- * Dry/Wet ratio
53
- *
54
- * @param mix - Ratio (0~1)
55
- */
56
- mix(mix: number): void;
57
- /**
58
- * Set Impulse Response time length (second)
59
- *
60
- * @param value - IR length
61
- */
62
- time(value: number): void;
63
- /**
64
- * Impulse response decay rate.
65
- *
66
- * @param value - Decay value
67
- */
68
- decay(value: number): void;
69
- /**
70
- * Delay before reverberation starts
71
- *
72
- * @param value - Time[ms]
73
- */
74
- delay(value: number): void;
75
- /**
76
- * Reverse the impulse response.
77
- *
78
- * @param reverse - Reverse IR
79
- */
80
- reverse(reverse: boolean): void;
81
- /**
82
- * Filter for impulse response
83
- *
84
- * @param type - Filiter Type
85
- */
86
- filterType(type: BiquadFilterType): void;
87
- /**
88
- * Filter frequency applied to impulse response
89
- *
90
- * @param freq - Frequency
91
- */
92
- filterFreq(freq: number): void;
93
- /**
94
- * Filter quality.
95
- *
96
- * @param q - Quality
97
- */
98
- filterQ(q: number): void;
99
- /**
100
- * Inpulse Response Noise algorithm.
101
- *
102
- * @param type - IR noise algorithm type.
103
- */
104
- setNoise(type: NoiseType): void;
105
- /**
106
- * Return true if in range, otherwise false
107
- *
108
- * @param x - Target value
109
- * @param min - Minimum value
110
- * @param max - Maximum value
111
- */
112
- private inRange;
113
- /** Utility function for building an impulse response from the module parameters. */
114
- private buildImpulse;
115
- /** Generate white noise */
116
- private static whiteNoise;
117
- }
118
- // # sourceMappingURL=Reverb.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Reverb.d.ts","sourceRoot":"","sources":["../src/Reverb.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAChE,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iBAAiB;IACjB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,8BAA8B;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,mBAAmB;IACnB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,aAAa;IACb,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,qBAAqB;IACrB,OAAO,CAAC,WAAW,CAAU;IAE7B;;;;;OAKG;gBACS,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,GAAG,SAAS;IAsBnE;;;;OAIG;IACI,OAAO,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS;IAsBhD;;;;OAIG;IACI,UAAU,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS;IAe3E;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAU7B;;;;OAIG;IACI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWhC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACI,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAQtC;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAK/C;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWrC;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAW/B;;;;OAIG;IACI,QAAQ,CAAC,IAAI,EAAE,SAAS;IAM/B;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAIf,oFAAoF;IACpF,OAAO,CAAC,YAAY;IAoGpB,2BAA2B;IAC3B,OAAO,CAAC,MAAM,CAAC,UAAU;CAI1B"}
@@ -1,8 +0,0 @@
1
- /** Meta Information Interface */
2
- export default interface MetaInterface {
3
- /** Version */
4
- version: string;
5
- /** Build Date */
6
- date: string;
7
- }
8
- // # sourceMappingURL=MetaInterface.d.ts.map
@@ -1,25 +0,0 @@
1
- import { NoiseType } from '../NoiseType';
2
- /** Reverb Option */
3
- export default interface OptionInterface {
4
- /** Types of impulse response noise generation algorithms */
5
- noise: NoiseType;
6
- /** Decay */
7
- decay: number;
8
- /** Delay until impulse response is generated */
9
- delay: number;
10
- /** Filter frequency applied to impulse response[Hz] */
11
- filterFreq: number;
12
- /** Filter quality for impulse response */
13
- filterQ: number;
14
- /** Filter type for impulse response */
15
- filterType: BiquadFilterType;
16
- /** Dry/Wet ratio */
17
- mix: number;
18
- /** Invert the impulse response */
19
- reverse: boolean;
20
- /** Impulse response length */
21
- time: number;
22
- /** Prevents multiple effectors from being connected. */
23
- once: boolean;
24
- }
25
- // # sourceMappingURL=OptionInterface.d.ts.map