audiomotion-analyzer 4.4.0 → 4.5.0-beta.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/README.md CHANGED
@@ -140,6 +140,7 @@ options = {<br>
140
140
  &emsp;&emsp;[gradient](#gradient-string): **'classic'**,<br>
141
141
  &emsp;&emsp;[gradientLeft](#gradientleft-string): *undefined*,<br>
142
142
  &emsp;&emsp;[gradientRight](#gradientright-string): *undefined*,<br>
143
+ &emsp;&emsp;[gravity](#gravity-number): **1**,<br>
143
144
  &emsp;&emsp;[height](#height-number): *undefined*,<br>
144
145
  &emsp;&emsp;[ledBars](#ledbars-boolean): **false**,<br>
145
146
  &emsp;&emsp;[linearAmplitude](#linearamplitude-boolean): **false**,<br>
@@ -498,6 +499,16 @@ For **_dual-combined_** channel layout or [`radial`](#radial-boolean) spectrum,
498
499
 
499
500
  See also [`gradient`](#gradient-string) and [`splitGradient`](#splitgradient-boolean).
500
501
 
502
+ ### `gravity` *number*
503
+
504
+ *Available since v4.5.0*
505
+
506
+ Controls the acceleration of [peaks](#showpeaks-boolean) falling down.
507
+
508
+ It must be a number greater than zero. Invalid values are ignored and no error is thrown.
509
+
510
+ Defaults to **1**.
511
+
501
512
  ### `height` *number*
502
513
  ### `width` *number*
503
514
 
@@ -607,7 +618,7 @@ Defaults to **false**.
607
618
 
608
619
  *Available since v4.0.0*
609
620
 
610
- Performs an *n*th-root to amplify low energy values when using linear scale for the amplitude.
621
+ Performs an *n*th-root operation to amplify low energy values when using linear scale for the amplitude.
611
622
 
612
623
  It should be a number >= 1, while 1 means no boosting. Only effective when [`linearAmplitude`](#linearamplitude-boolean) is set to *true*.
613
624
 
@@ -906,9 +917,11 @@ and setting `showBgColor` to ***true*** will make the "unlit" LEDs visible inste
906
917
 
907
918
  ### `showPeaks` *boolean*
908
919
 
909
- *true* to show amplitude peaks. Defaults to **true**.
920
+ *true* to show amplitude peaks.
910
921
 
911
- See also [`peakLine`](#peakline-boolean).
922
+ See also [`gravity`](#gravity-number) and [`peakLine`](#peakline-boolean).
923
+
924
+ Defaults to **true**.
912
925
 
913
926
  ### `showScaleX` *boolean*
914
927
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "audiomotion-analyzer",
3
3
  "description": "High-resolution real-time graphic audio spectrum analyzer JavaScript module with no dependencies.",
4
- "version": "4.4.0",
4
+ "version": "4.5.0-beta.0",
5
5
  "main": "./src/audioMotion-analyzer.js",
6
6
  "module": "./src/audioMotion-analyzer.js",
7
7
  "types": "./src/index.d.ts",
@@ -9,6 +9,7 @@
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": "./src/audioMotion-analyzer.js",
12
+ "require": "./src/audioMotion-analyzer.js",
12
13
  "types": "./src/index.d.ts"
13
14
  }
14
15
  },
@@ -2,12 +2,12 @@
2
2
  * audioMotion-analyzer
3
3
  * High-resolution real-time graphic audio spectrum analyzer JS module
4
4
  *
5
- * @version 4.4.0
5
+ * @version 4.5.0-beta.0
6
6
  * @author Henrique Avila Vianna <hvianna@gmail.com> <https://henriquevianna.com>
7
7
  * @license AGPL-3.0-or-later
8
8
  */
9
9
 
10
- const VERSION = '4.4.0';
10
+ const VERSION = '4.5.0-beta.0';
11
11
 
12
12
  // internal constants
13
13
  const PI = Math.PI,
@@ -92,6 +92,7 @@ const DEFAULT_SETTINGS = {
92
92
  fillAlpha : 1,
93
93
  frequencyScale : SCALE_LOG,
94
94
  gradient : GRADIENTS[0][0],
95
+ gravity : 1,
95
96
  height : undefined,
96
97
  ledBars : false,
97
98
  linearAmplitude: false,
@@ -186,7 +187,7 @@ if ( ! Array.prototype.findLastIndex ) {
186
187
 
187
188
  // AudioMotionAnalyzer class
188
189
 
189
- export default class AudioMotionAnalyzer {
190
+ class AudioMotionAnalyzer {
190
191
 
191
192
  /**
192
193
  * CONSTRUCTOR
@@ -485,6 +486,13 @@ export default class AudioMotionAnalyzer {
485
486
  this._setGradient( value, 1 );
486
487
  }
487
488
 
489
+ get gravity() {
490
+ return this._gravity;
491
+ }
492
+ set gravity( value ) {
493
+ this._gravity = value > 0 ? +value : this._gravity || DEFAULT_SETTINGS.gravity;
494
+ }
495
+
488
496
  get height() {
489
497
  return this._height;
490
498
  }
@@ -1767,6 +1775,7 @@ export default class AudioMotionAnalyzer {
1767
1775
  _energy,
1768
1776
  fillAlpha,
1769
1777
  _fps,
1778
+ _gravity,
1770
1779
  _linearAmplitude,
1771
1780
  _lineWidth,
1772
1781
  maxDecibels,
@@ -1909,7 +1918,7 @@ export default class AudioMotionAnalyzer {
1909
1918
  if ( _energy.peak > 0 ) {
1910
1919
  _energy.hold--;
1911
1920
  if ( _energy.hold < 0 )
1912
- _energy.peak += _energy.hold / ( holdFrames * holdFrames / 2 );
1921
+ _energy.peak += _energy.hold / ( holdFrames * holdFrames / _gravity );
1913
1922
  }
1914
1923
  if ( newVal >= _energy.peak ) {
1915
1924
  _energy.peak = newVal;
@@ -2141,7 +2150,7 @@ export default class AudioMotionAnalyzer {
2141
2150
  bar.hold[ channel ]--;
2142
2151
  // if hold is negative, it becomes the "acceleration" for peak drop
2143
2152
  if ( bar.hold[ channel ] < 0 )
2144
- bar.peak[ channel ] += bar.hold[ channel ] / ( holdFrames * holdFrames / 2 );
2153
+ bar.peak[ channel ] += bar.hold[ channel ] / ( holdFrames * holdFrames / _gravity );
2145
2154
  }
2146
2155
 
2147
2156
  // check if it's a new peak for this bar
@@ -2641,3 +2650,6 @@ export default class AudioMotionAnalyzer {
2641
2650
  }
2642
2651
 
2643
2652
  }
2653
+
2654
+ export { AudioMotionAnalyzer };
2655
+ export default AudioMotionAnalyzer;
package/src/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export interface Options {
28
28
  gradient?: string;
29
29
  gradientLeft?: string;
30
30
  gradientRight?: string;
31
+ gravity?: number;
31
32
  height?: number;
32
33
  ledBars?: boolean;
33
34
  linearAmplitude?: boolean;
@@ -165,6 +166,9 @@ declare class AudioMotionAnalyzer {
165
166
  get gradientRight(): string;
166
167
  set gradientRight(value: string);
167
168
 
169
+ get gravity(): number;
170
+ set gravity(value: number);
171
+
168
172
  get height(): number;
169
173
  set height(h: number);
170
174
 
@@ -319,4 +323,5 @@ declare class AudioMotionAnalyzer {
319
323
  public toggleFullscreen(): void;
320
324
  }
321
325
 
326
+ export { AudioMotionAnalyzer };
322
327
  export default AudioMotionAnalyzer;