audiomotion-analyzer 4.0.0 → 4.1.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 +92 -28
- package/package.json +1 -1
- package/src/audioMotion-analyzer.js +622 -446
- package/src/index.d.ts +18 -2
package/README.md
CHANGED
|
@@ -120,6 +120,7 @@ options = {<br>
|
|
|
120
120
|
  [barSpace](#barspace-number): **0.1**,<br>
|
|
121
121
|
  [bgAlpha](#bgalpha-number): **0.7**,<br>
|
|
122
122
|
  [channelLayout](#channellayout-string): **'single'**,<br>
|
|
123
|
+
  [colorMode](#colormode-string): **'gradient'**,<br>
|
|
123
124
|
  [connectSpeakers](#connectspeakers-boolean): **true**, // constructor only<br>
|
|
124
125
|
  [fftSize](#fftsize-number): **8192**,<br>
|
|
125
126
|
  [fillAlpha](#fillalpha-number): **1**,<br>
|
|
@@ -151,6 +152,7 @@ options = {<br>
|
|
|
151
152
|
  [reflexBright](#reflexbright-number): **1**,<br>
|
|
152
153
|
  [reflexFit](#reflexfit-boolean): **true**,<br>
|
|
153
154
|
  [reflexRatio](#reflexratio-number): **0**,<br>
|
|
155
|
+
  [roundBars](#roundbars-boolean): **false**,<br>
|
|
154
156
|
  [showBgColor](#showbgcolor-boolean): **true**,<br>
|
|
155
157
|
  [showFPS](#showfps-boolean): **false**,<br>
|
|
156
158
|
  [showPeaks](#showpeaks-boolean): **true**,<br>
|
|
@@ -161,6 +163,7 @@ options = {<br>
|
|
|
161
163
|
  [spinSpeed](#spinspeed-number): **0**,<br>
|
|
162
164
|
  [splitGradient](#splitgradient-boolean): **false**,<br>
|
|
163
165
|
  [start](#start-boolean): **true**,<br>
|
|
166
|
+
  [trueLeds](#trueleds-boolean): **false**,<br>
|
|
164
167
|
  [useCanvas](#usecanvas-boolean): **true**,<br>
|
|
165
168
|
  [volume](#volume-number): **1**,<br>
|
|
166
169
|
  [weightingFilter](#weightingFilter-string): **''**<br>
|
|
@@ -291,7 +294,7 @@ See also the [fluid demo](/demo/fluid.html) and the [multi-instance demo](/demo/
|
|
|
291
294
|
|
|
292
295
|
*Available since v2.0.0*
|
|
293
296
|
|
|
294
|
-
Customize the spacing between bars in
|
|
297
|
+
Customize the spacing between bars in frequency bands modes (see [`mode`](#mode-number)).
|
|
295
298
|
|
|
296
299
|
Use a value between 0 and 1 for spacing proportional to the band width. Values >= 1 will be considered as a literal number of pixels.
|
|
297
300
|
|
|
@@ -328,7 +331,7 @@ Defaults to **0.7**.
|
|
|
328
331
|
|
|
329
332
|
Defines the number and layout of analyzer channels.
|
|
330
333
|
|
|
331
|
-
channelLayout |
|
|
334
|
+
channelLayout | Description
|
|
332
335
|
----------------|------------
|
|
333
336
|
'single' | Single channel analyzer, representing the combined output of both left and right channels.
|
|
334
337
|
'dual-combined' | Dual channel analyzer, with both channel graphs overlaid. Works best with semi-transparent **Graph** [`mode`](#mode-number) or [`outlineBars`](#outlinebars-boolean).
|
|
@@ -339,6 +342,22 @@ unless a stereo source is simultaneously connected to the analyzer, which will f
|
|
|
339
342
|
|
|
340
343
|
See also [`gradientLeft`](#gradientleft-string), [`gradientRight`](#gradientright-string) and [`splitGradient`](#splitgradient-boolean).
|
|
341
344
|
|
|
345
|
+
### `colorMode` *string*
|
|
346
|
+
|
|
347
|
+
*Available since v4.1.0*
|
|
348
|
+
|
|
349
|
+
Selects the desired mode for coloring the analyzer bars. This property has no effect in **Graph** [`mode`](#mode-number).
|
|
350
|
+
|
|
351
|
+
colorMode | Description | Preview ('prism' gradient)
|
|
352
|
+
------------|-------------|----------------------------
|
|
353
|
+
'gradient' | Analyzer bars are painted with the currently selected [`gradient`](#gradient-string). This is the default behavior. | 
|
|
354
|
+
'bar-index' | Each analyzer bar is painted with a **single color** from the selected gradient's *colorStops*, starting with the first color applied to the first bar, and so on, cycling through the available colorStops. | 
|
|
355
|
+
'bar-level' | Colors from the selected gradient are used to paint each bar, according to its current level (amplitude). | 
|
|
356
|
+
|
|
357
|
+
See also [`registerGradient()`](#registergradient-name-options-).
|
|
358
|
+
|
|
359
|
+
Defaults to **'gradient'**.
|
|
360
|
+
|
|
342
361
|
### `connectedSources` *array* *(Read only)*
|
|
343
362
|
|
|
344
363
|
*Available since v3.0.0*
|
|
@@ -368,13 +387,13 @@ Defaults to **8192**.
|
|
|
368
387
|
|
|
369
388
|
*Available since v2.0.0*
|
|
370
389
|
|
|
371
|
-
Opacity of the area fill in [Graph mode](#mode-number), or inner fill of bars in [bands modes](#mode-number) when [`outlineBars`](#outlinebars-boolean) is *true*.
|
|
390
|
+
Opacity of the area fill in [Graph mode](#mode-number), or inner fill of bars in [frequency bands modes](#mode-number) when [`outlineBars`](#outlinebars-boolean) is *true*.
|
|
372
391
|
|
|
373
392
|
It must be a number between 0 (completely transparent) and 1 (completely opaque).
|
|
374
393
|
|
|
375
394
|
Please note that the line stroke (when [`lineWidth`](#linewidth-number) > 0) is always drawn at full opacity, regardless of the `fillAlpha` value.
|
|
376
395
|
|
|
377
|
-
Also, for [bands modes](#mode-number), [`alphaBars`](#alphabars-boolean) set to *true* takes precedence over `fillAlpha`.
|
|
396
|
+
Also, for [frequency bands modes](#mode-number), [`alphaBars`](#alphabars-boolean) set to *true* takes precedence over `fillAlpha`.
|
|
378
397
|
|
|
379
398
|
Defaults to **1**.
|
|
380
399
|
|
|
@@ -390,16 +409,16 @@ Current frame rate.
|
|
|
390
409
|
|
|
391
410
|
Scale used to represent frequencies in the horizontal axis.
|
|
392
411
|
|
|
393
|
-
frequencyScale | description | scale preview (
|
|
412
|
+
frequencyScale | description | scale preview (10Hz - 24kHz range)
|
|
394
413
|
---------------|-------------|-----------------------------------
|
|
395
|
-
'bark' |
|
|
414
|
+
'bark' | Bark scale | 
|
|
396
415
|
'linear' | Linear scale | 
|
|
397
416
|
'log' | Logarithmic scale | 
|
|
398
|
-
'mel' |
|
|
417
|
+
'mel' | Mel scale | 
|
|
399
418
|
|
|
400
419
|
Logarithmic scale allows visualization of proper **octave bands** (see [`mode`](#mode-number)) and it's also recommended when using [`noteLabels`](#notelabels-boolean).
|
|
401
420
|
|
|
402
|
-
*Bark* and *Mel* are perceptual pitch scales, which provide better visualization of mid-range to
|
|
421
|
+
[*Bark*](https://en.wikipedia.org/wiki/Bark_scale) and [*Mel*](https://en.wikipedia.org/wiki/Mel_scale) are perceptual pitch scales, which may provide better visualization of mid-range frequencies, when compared to log or linear scales.
|
|
403
422
|
|
|
404
423
|
Defaults to **'log'**.
|
|
405
424
|
|
|
@@ -471,7 +490,7 @@ You can set both values at once using the [`setCanvasSize()`](#setcanvassize-wid
|
|
|
471
490
|
*Available since v3.6.0*
|
|
472
491
|
|
|
473
492
|
***true*** when alpha bars are effectively being displayed, i.e., [`alphaBars`](#alphabars-boolean) is set to *true* and [`mode`](#mode-number) is set to discrete frequencies
|
|
474
|
-
or one of the bands modes, in which case [`lumiBars`](#lumibars-boolean) must be set to *false* or [`radial`](#radial-boolean) must be set to *true*.
|
|
493
|
+
or one of the frequency bands modes, in which case [`lumiBars`](#lumibars-boolean) must be set to *false* or [`radial`](#radial-boolean) must be set to *true*.
|
|
475
494
|
|
|
476
495
|
### `isBandsMode` *boolean* *(Read only)*
|
|
477
496
|
|
|
@@ -518,11 +537,18 @@ See [`toggleAnalyzer()`](#toggleanalyzer-boolean-).
|
|
|
518
537
|
***true*** when outlined bars are effectively being displayed, i.e., [`isBandsMode`](#isbandsmode-boolean-read-only) is *true*, [`outlineBars`](#outlinebars-boolean) is set to *true*
|
|
519
538
|
and both [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) are set to *false*, or [`radial`](#radial-boolean) is set to *true*.
|
|
520
539
|
|
|
540
|
+
### `isRoundBars` *boolean* *(Read only)*
|
|
541
|
+
|
|
542
|
+
*Available since v4.1.0*
|
|
543
|
+
|
|
544
|
+
***true*** when round bars are effectively being displayed, i.e., [`isBandsMode`](#isbandsmode-boolean-read-only) is *true*, [`roundBars`](#roundbars-boolean) is set to *true*
|
|
545
|
+
and [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) are both set to *false*.
|
|
546
|
+
|
|
521
547
|
### `ledBars` *boolean*
|
|
522
548
|
|
|
523
549
|
*Available since v3.6.0* (formerly `showLeds`)
|
|
524
550
|
|
|
525
|
-
*true* to activate the vintage LED bars effect for
|
|
551
|
+
*true* to activate the vintage LED bars effect for frequency bands modes (see [`mode`](#mode-number)).
|
|
526
552
|
|
|
527
553
|
This effect can be customized via [`setLedParams()`](#setledparams-params-) method.
|
|
528
554
|
|
|
@@ -556,7 +582,7 @@ Defaults to **1**.
|
|
|
556
582
|
|
|
557
583
|
*Available since v2.0.0*
|
|
558
584
|
|
|
559
|
-
Line width for [Graph mode](#mode-number), or outline stroke in [bands modes](#mode-number) when [`outlineBars`](#outlinebars-boolean) is *true*.
|
|
585
|
+
Line width for [Graph mode](#mode-number), or outline stroke in [frequency bands modes](#mode-number) when [`outlineBars`](#outlinebars-boolean) is *true*.
|
|
560
586
|
|
|
561
587
|
For the line to be distinguishable, set also [`fillAlpha`](#fillalpha-number) < 1.
|
|
562
588
|
|
|
@@ -583,7 +609,7 @@ This will prevent the canvas size from changing, when switching the low resoluti
|
|
|
583
609
|
|
|
584
610
|
*Available since v1.1.0*
|
|
585
611
|
|
|
586
|
-
This is only effective for
|
|
612
|
+
This is only effective for frequency bands modes (see [`mode`](#mode-number)).
|
|
587
613
|
|
|
588
614
|
When set to *true* all analyzer bars will be displayed at full height with varying luminance (opacity, actually) instead.
|
|
589
615
|
|
|
@@ -666,7 +692,8 @@ Defaults to **0**.
|
|
|
666
692
|
|
|
667
693
|
When set to *true* displays musical note labels instead of frequency values, in the X axis (when [`showScaleX`](#showscalex-boolean) is also set to *true*).
|
|
668
694
|
|
|
669
|
-
For best visualization in [octave bands modes](#mode-number), make sure [`frequencyScale`](#frequencyscale-string) is set to *'log'*
|
|
695
|
+
For best visualization in [octave bands modes](#mode-number), make sure [`frequencyScale`](#frequencyscale-string) is set to *'log'*
|
|
696
|
+
and [`ansiBands`](#ansibands-boolean) is set to *false*, so bands are tuned to the equal temperament musical scale.
|
|
670
697
|
|
|
671
698
|
Defaults to **false**.
|
|
672
699
|
|
|
@@ -707,8 +734,7 @@ You can refer to this value to adjust any additional drawings done in the canvas
|
|
|
707
734
|
|
|
708
735
|
When *true*, the spectrum analyzer is rendered in a circular shape, with radial frequency bars spreading from its center.
|
|
709
736
|
|
|
710
|
-
|
|
711
|
-
[`showPeaks`](#showpeaks-boolean) has no effect for [**Graph** mode](#mode-number).
|
|
737
|
+
In radial view, [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) effects are disabled, and [`showPeaks`](#showpeaks-boolean) has no effect when in **Graph** [`mode`](#mode-number).
|
|
712
738
|
|
|
713
739
|
When [`channelLayout`](#channellayout-string) is set to *'dual-vertical'*, a larger diameter is used and the right channel bars are rendered towards the center of the analyzer.
|
|
714
740
|
|
|
@@ -761,6 +787,21 @@ This has no effect when [`lumiBars`](#lumibars-boolean) is *true*.
|
|
|
761
787
|
|
|
762
788
|
Defaults to **0** (no reflection).
|
|
763
789
|
|
|
790
|
+
### `roundBars` *boolean*
|
|
791
|
+
|
|
792
|
+
*Available since v4.1.0*
|
|
793
|
+
|
|
794
|
+
When *true* and [`mode`](#mode-number) is set to one of the **bands** modes, analyzer bars are rendered with rounded corners at the top.
|
|
795
|
+
|
|
796
|
+
In [`radial`](#radial-boolean) view this makes the top and bottom of bars to follow the curvatures of the outer and inner circles, respectivelly, although the effect
|
|
797
|
+
can be barely noticeable with a band count greater than 20 (half-octave bands).
|
|
798
|
+
|
|
799
|
+
This has no effect when [`ledBars`](#ledbars-boolean) or [`lumiBars`](#lumibars-boolean) are set to *true*.
|
|
800
|
+
|
|
801
|
+
See also [`isRoundBars`](#isroundbars-boolean-read-only).
|
|
802
|
+
|
|
803
|
+
Defaults to **false**.
|
|
804
|
+
|
|
764
805
|
### `showBgColor` *boolean*
|
|
765
806
|
|
|
766
807
|
Determines whether the canvas background should be painted.
|
|
@@ -835,9 +876,9 @@ Defaults to **0**.
|
|
|
835
876
|
|
|
836
877
|
When set to *true* and [`channelLayout`](#channellayout-string) is **_dual-vertical_**, the gradient will be split between channels.
|
|
837
878
|
|
|
838
|
-
When *false*, both channels will use the full gradient.
|
|
879
|
+
When *false*, both channels will use the full gradient. The effect is illustrated below, using the *'classic'* gradient.
|
|
839
880
|
|
|
840
|
-
|
|
|
881
|
+
| splitGradient: *false* | splitGradient: *true* |
|
|
841
882
|
|:--:|:--:|
|
|
842
883
|
|  |  |
|
|
843
884
|
|
|
@@ -849,6 +890,24 @@ Defaults to **false**.
|
|
|
849
890
|
|
|
850
891
|
**This property will be removed in version 5** - Use [`channelLayout`](#channellayout-string) instead.
|
|
851
892
|
|
|
893
|
+
### `trueLeds` *boolean*
|
|
894
|
+
|
|
895
|
+
*Available since v4.1.0*
|
|
896
|
+
|
|
897
|
+
When set to *true*, LEDs are painted with individual colors from the current gradient, instead of using the gradient itself.
|
|
898
|
+
|
|
899
|
+
The effect is illustrated below, using the *'classic'* gradient.
|
|
900
|
+
|
|
901
|
+
| trueLeds: *false* | trueLeds: *true* |
|
|
902
|
+
|:--:|:--:|
|
|
903
|
+
|  |  |
|
|
904
|
+
|
|
905
|
+
The threshold for each color can be adjusted via the `level` property when registering a gradient. See [`registerGradient()`](#registergradient-name-options-).
|
|
906
|
+
|
|
907
|
+
This option is only effective for frequency bands [modes](#mode-number), when [`ledBars`](#ledbars-boolean) is *true* and [`colorMode`](#colormode-string) is set to *'gradient'*.
|
|
908
|
+
|
|
909
|
+
Defaults to **false**.
|
|
910
|
+
|
|
852
911
|
### `useCanvas` *boolean*
|
|
853
912
|
|
|
854
913
|
*Available since v3.5.0*
|
|
@@ -1105,29 +1164,34 @@ Use this method inside your callback function to create additional visual effect
|
|
|
1105
1164
|
|
|
1106
1165
|
Registers a custom color gradient.
|
|
1107
1166
|
|
|
1108
|
-
`name` must be a non-empty string that will be used to select this gradient, via the [`gradient`](#gradient-string) property.
|
|
1167
|
+
`name` must be a non-empty string that will be used to select this gradient, via the [`gradient`](#gradient-string) property. Names are case sensitive.
|
|
1109
1168
|
|
|
1110
1169
|
`options` must be an object as shown below:
|
|
1111
1170
|
|
|
1112
1171
|
```js
|
|
1113
|
-
|
|
1172
|
+
audioMotion.registerGradient( 'myGradient', {
|
|
1114
1173
|
bgColor: '#011a35', // background color (optional) - defaults to '#111'
|
|
1115
1174
|
dir: 'h', // add this property to create a horizontal gradient (optional)
|
|
1116
1175
|
colorStops: [ // list your gradient colors in this array (at least one color is required)
|
|
1117
|
-
'
|
|
1118
|
-
{
|
|
1119
|
-
'
|
|
1176
|
+
'hsl( 0, 100%, 50% )', // colors can be defined in any valid CSS format
|
|
1177
|
+
{ color: 'yellow', pos: .6 }, // in an object, use `pos` to adjust the offset (0 to 1) of a colorStop
|
|
1178
|
+
{ color: '#0f0', level: .5 } // use `level` to set the max bar amplitude (0 to 1) to use this color
|
|
1120
1179
|
]
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
audioMotion.registerGradient( 'myGradient', options );
|
|
1180
|
+
});
|
|
1124
1181
|
```
|
|
1125
1182
|
|
|
1126
|
-
|
|
1183
|
+
The `dir` property has no effect on [`radial`](#radial-boolean) spectrum or when [`trueLeds`](#trueleds-boolean) is in effect.
|
|
1127
1184
|
|
|
1128
|
-
|
|
1185
|
+
Each element of `colorStops` may be either a string (color only), or an object with at least a `color` property and optional `pos` and `level` properties.
|
|
1186
|
+
- `pos` defines the relative position of a color in the gradient, when [`colorMode`](#colormode-string) is set to **'gradient'**. It must be a number between `0` and `1`, where `0` represents the top of the screen and `1` the bottom
|
|
1187
|
+
(or left and right sides, for horizontal gradients);
|
|
1188
|
+
- `level` defines the level threshold of a color, when [`colorMode`](#colormode-string) is set to **'bar-level'** or [`trueLeds`](#trueleds-boolean) is active.
|
|
1189
|
+
The color will be applied to bars (or LED elements) with amplitude **less than or equal to** `level`. It must be a number between `0` and `1`, where `1` is the maximum
|
|
1190
|
+
amplitude (top of screen);
|
|
1191
|
+
- If `pos` or `level` are not explicitly defined, colors will be evenly distributed across the gradient or amplitude range;
|
|
1192
|
+
- Defining `level: 0` for a colorStop will effectively prevent that color from being used for *'bar-level'* colorMode and *trueLeds* effect.
|
|
1129
1193
|
|
|
1130
|
-
?> Any gradient, including the built-in ones, may be modified by (re-)registering the same gradient name
|
|
1194
|
+
?> Any gradient, including the built-in ones, may be modified at any time by (re-)registering the same gradient name.
|
|
1131
1195
|
|
|
1132
1196
|
### `setCanvasSize( width, height )`
|
|
1133
1197
|
|
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
|
+
"version": "4.1.0",
|
|
5
5
|
"main": "./src/audioMotion-analyzer.js",
|
|
6
6
|
"module": "./src/audioMotion-analyzer.js",
|
|
7
7
|
"types": "./src/index.d.ts",
|