audiomotion-analyzer 4.0.0-beta.5 β†’ 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 CHANGED
@@ -27,19 +27,19 @@ What users are saying:
27
27
 
28
28
  ## Features
29
29
 
30
- + High-resolution real-time dual channel audio spectrum analyzer
31
- + Logarithmic, linear and perceptual (Bark/Mel) frequency scales, with customizable range
30
+ + Dual-channel high-resolution real-time audio spectrum analyzer
31
+ + Logarithmic, linear and perceptual (Bark and Mel) frequency scales, with customizable range
32
32
  + Visualization of discrete FFT frequencies or up to 240 frequency bands (supports ANSI and equal-tempered octave bands)
33
33
  + Decibel and linear amplitude scales, with customizable sensitivity
34
- + A, B, C, D and ITU-R 468 weighting filters
35
- + Optional effects: LED bars, luminance bars, mirroring and reflection, radial spectrum
36
- + Comes with 3 predefined color gradients - easily add your own!
34
+ + Optional A, B, C, D and ITU-R 468 weighting filters
35
+ + Additional effects: LED bars, luminance bars, mirroring and reflection, radial spectrum
36
+ + Choose from 5 built-in color gradients or easily add your own!
37
37
  + Fullscreen support, ready for retina / HiDPI displays
38
38
  + Zero-dependency native ES6+ module (ESM), \~25kB minified
39
39
 
40
40
  ## Online demos
41
41
 
42
- [![demo-animation](img/demo.gif)](https://audiomotion.dev/demo/)
42
+ [![demo-animation](img/demo.webp)](https://audiomotion.dev/demo/)
43
43
 
44
44
  ?> https://audiomotion.dev/demo/
45
45
 
@@ -120,6 +120,7 @@ options = {<br>
120
120
  &emsp;&emsp;[barSpace](#barspace-number): **0.1**,<br>
121
121
  &emsp;&emsp;[bgAlpha](#bgalpha-number): **0.7**,<br>
122
122
  &emsp;&emsp;[channelLayout](#channellayout-string): **'single'**,<br>
123
+ &emsp;&emsp;[colorMode](#colormode-string): **'gradient'**,<br>
123
124
  &emsp;&emsp;[connectSpeakers](#connectspeakers-boolean): **true**, // constructor only<br>
124
125
  &emsp;&emsp;[fftSize](#fftsize-number): **8192**,<br>
125
126
  &emsp;&emsp;[fillAlpha](#fillalpha-number): **1**,<br>
@@ -151,6 +152,7 @@ options = {<br>
151
152
  &emsp;&emsp;[reflexBright](#reflexbright-number): **1**,<br>
152
153
  &emsp;&emsp;[reflexFit](#reflexfit-boolean): **true**,<br>
153
154
  &emsp;&emsp;[reflexRatio](#reflexratio-number): **0**,<br>
155
+ &emsp;&emsp;[roundBars](#roundbars-boolean): **false**,<br>
154
156
  &emsp;&emsp;[showBgColor](#showbgcolor-boolean): **true**,<br>
155
157
  &emsp;&emsp;[showFPS](#showfps-boolean): **false**,<br>
156
158
  &emsp;&emsp;[showPeaks](#showpeaks-boolean): **true**,<br>
@@ -161,6 +163,7 @@ options = {<br>
161
163
  &emsp;&emsp;[spinSpeed](#spinspeed-number): **0**,<br>
162
164
  &emsp;&emsp;[splitGradient](#splitgradient-boolean): **false**,<br>
163
165
  &emsp;&emsp;[start](#start-boolean): **true**,<br>
166
+ &emsp;&emsp;[trueLeds](#trueleds-boolean): **false**,<br>
164
167
  &emsp;&emsp;[useCanvas](#usecanvas-boolean): **true**,<br>
165
168
  &emsp;&emsp;[volume](#volume-number): **1**,<br>
166
169
  &emsp;&emsp;[weightingFilter](#weightingFilter-string): **''**<br>
@@ -247,12 +250,17 @@ Defaults to **false**.
247
250
 
248
251
  *Available since v4.0.0*
249
252
 
250
- When set to *true* uses ANSI/IEC preferred frequencies to generate the bands for [octave bands modes](#mode-number).
253
+ When set to *true*, ANSI/IEC preferred frequencies are used to generate the bands for **octave bands** modes (see [`mode`](#mode-number)).
251
254
  The preferred base-10 scale is used to compute the center and bandedge frequencies, as specified in the [ANSI S1.11-2004 standard](https://archive.org/details/gov.law.ansi.s1.11.2004).
252
255
 
253
- The default is to use the [equal temperament scale](http://hyperphysics.phy-astr.gsu.edu/hbase/Music/et.html), so that in 1/12 octave bands
256
+ When *false*, bands are based on the [equal-tempered scale](http://hyperphysics.phy-astr.gsu.edu/hbase/Music/et.html), so that in 1/12 octave bands
254
257
  the center of each band is perfectly tuned to a musical note.
255
258
 
259
+ ansiBands | bands standard | octaves' center frequencies
260
+ ----------|----------------|----------------------------
261
+ false | Equal temperament (A-440 Hz) | ![scale-log-equal-temperament](img/scale-log-equal-temperament.png)
262
+ true | ANSI S1.11-2004 | ![scale-log-ansi](img/scale-log-ansi.png)
263
+
256
264
  Defaults to **false**.
257
265
 
258
266
  ### `audioCtx` *AudioContext object* *(Read only)*
@@ -286,7 +294,7 @@ See also the [fluid demo](/demo/fluid.html) and the [multi-instance demo](/demo/
286
294
 
287
295
  *Available since v2.0.0*
288
296
 
289
- Customize the spacing between bars in [bands modes](#mode-number).
297
+ Customize the spacing between bars in frequency bands modes (see [`mode`](#mode-number)).
290
298
 
291
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.
292
300
 
@@ -323,17 +331,33 @@ Defaults to **0.7**.
323
331
 
324
332
  Defines the number and layout of analyzer channels.
325
333
 
326
- channelLayout | description
334
+ channelLayout | Description
327
335
  ----------------|------------
328
336
  'single' | Single channel analyzer, representing the combined output of both left and right channels.
329
- 'dual-vertical' | Dual channel analyzer, with left channel shown at the top and right channel at the bottom.
330
- 'dual-combined' | Left and right channel graphs are shown overlaid. Works best with semi-transparent **Graph** [`mode`](#mode-number) or [`outlineBars`](#outlinebars-boolean).
337
+ 'dual-combined' | Dual channel analyzer, with both channel graphs overlaid. Works best with semi-transparent **Graph** [`mode`](#mode-number) or [`outlineBars`](#outlinebars-boolean).
338
+ 'dual-vertical' | Left channel shown at the top half of the canvas and right channel at the bottom.
331
339
 
332
340
  !> When a *dual* layout is selected, any mono (single channel) audio source connected to the analyzer will output sound only from the left speaker,
333
341
  unless a stereo source is simultaneously connected to the analyzer, which will force the mono input to be upmixed to stereo.
334
342
 
335
343
  See also [`gradientLeft`](#gradientleft-string), [`gradientRight`](#gradientright-string) and [`splitGradient`](#splitgradient-boolean).
336
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. | ![prism](img/gradient-prism.png)
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. | ![prism-bar-index](img/gradient-prism-bar-index.png)
355
+ 'bar-level' | Colors from the selected gradient are used to paint each bar, according to its current level (amplitude). | ![prism-bar-level](img/gradient-prism-bar-level.png)
356
+
357
+ See also [`registerGradient()`](#registergradient-name-options-).
358
+
359
+ Defaults to **'gradient'**.
360
+
337
361
  ### `connectedSources` *array* *(Read only)*
338
362
 
339
363
  *Available since v3.0.0*
@@ -363,13 +387,13 @@ Defaults to **8192**.
363
387
 
364
388
  *Available since v2.0.0*
365
389
 
366
- 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*.
367
391
 
368
392
  It must be a number between 0 (completely transparent) and 1 (completely opaque).
369
393
 
370
394
  Please note that the line stroke (when [`lineWidth`](#linewidth-number) > 0) is always drawn at full opacity, regardless of the `fillAlpha` value.
371
395
 
372
- 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`.
373
397
 
374
398
  Defaults to **1**.
375
399
 
@@ -385,16 +409,16 @@ Current frame rate.
385
409
 
386
410
  Scale used to represent frequencies in the horizontal axis.
387
411
 
388
- frequencyScale | description
389
- ---------------|------------
390
- 'bark' | [Bark scale](https://en.wikipedia.org/wiki/Bark_scale)
391
- 'linear' | Linear scale
392
- 'log' | Logarithmic scale
393
- 'mel' | [Mel scale](https://en.wikipedia.org/wiki/Mel_scale)
412
+ frequencyScale | description | scale preview (10Hz - 24kHz range)
413
+ ---------------|-------------|-----------------------------------
414
+ 'bark' | Bark scale | ![scale-bark](img/scale-bark.png)
415
+ 'linear' | Linear scale | ![scale-linear](img/scale-linear.png)
416
+ 'log' | Logarithmic scale | ![scale-log-ansi](img/scale-log-ansi.png)
417
+ 'mel' | Mel scale | ![scale-mel](img/scale-mel.png)
394
418
 
395
- Logarithmic scale is required to visualize proper [octave bands](#mode-number) and it's also recommended when using [`noteLabels`](#notelabels-boolean).
419
+ Logarithmic scale allows visualization of proper **octave bands** (see [`mode`](#mode-number)) and it's also recommended when using [`noteLabels`](#notelabels-boolean).
396
420
 
397
- *Bark* and *Mel* are perceptual pitch scales which provide better visualization of midrange and high frequencies, especially in the [discrete frequencies mode](#mode-number).
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.
398
422
 
399
423
  Defaults to **'log'**.
400
424
 
@@ -419,7 +443,7 @@ It must be a built-in or registered gradient name (see [`registerGradient()`](#r
419
443
 
420
444
  `gradient` sets the gradient for both analyzer channels, but its read value represents only the gradient on the left (or single) channel.
421
445
 
422
- When using a dual [`channelLayout`](#channellayout-string), use [`gradientLeft`](#gradientleft-string) and [`gradientRight`](#gradientright-string) if you want to individually set/read the gradient for each channel.
446
+ When using a dual [`channelLayout`](#channellayout-string), use [`gradientLeft`](#gradientleft-string) and [`gradientRight`](#gradientright-string) to set/read the gradient on each channel individually.
423
447
 
424
448
  Built-in gradients are shown below:
425
449
 
@@ -466,7 +490,7 @@ You can set both values at once using the [`setCanvasSize()`](#setcanvassize-wid
466
490
  *Available since v3.6.0*
467
491
 
468
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
469
- 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*.
470
494
 
471
495
  ### `isBandsMode` *boolean* *(Read only)*
472
496
 
@@ -513,11 +537,18 @@ See [`toggleAnalyzer()`](#toggleanalyzer-boolean-).
513
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*
514
538
  and both [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) are set to *false*, or [`radial`](#radial-boolean) is set to *true*.
515
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
+
516
547
  ### `ledBars` *boolean*
517
548
 
518
549
  *Available since v3.6.0* (formerly `showLeds`)
519
550
 
520
- *true* to activate the vintage LED bars effect for [bands modes](#mode-number).
551
+ *true* to activate the vintage LED bars effect for frequency bands modes (see [`mode`](#mode-number)).
521
552
 
522
553
  This effect can be customized via [`setLedParams()`](#setledparams-params-) method.
523
554
 
@@ -551,7 +582,7 @@ Defaults to **1**.
551
582
 
552
583
  *Available since v2.0.0*
553
584
 
554
- 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*.
555
586
 
556
587
  For the line to be distinguishable, set also [`fillAlpha`](#fillalpha-number) < 1.
557
588
 
@@ -578,7 +609,7 @@ This will prevent the canvas size from changing, when switching the low resoluti
578
609
 
579
610
  *Available since v1.1.0*
580
611
 
581
- This is only effective for [bands modes](#mode-number).
612
+ This is only effective for frequency bands modes (see [`mode`](#mode-number)).
582
613
 
583
614
  When set to *true* all analyzer bars will be displayed at full height with varying luminance (opacity, actually) instead.
584
615
 
@@ -635,22 +666,24 @@ Visualization mode.
635
666
 
636
667
  mode | description | notes
637
668
  ----:|:-----------:|------
638
- 0 | Discrete frequencies |
639
- 1 | 1/24th octave bands or 240 bands |
640
- 2 | 1/12th octave bands or 120 bands |
641
- 3 | 1/8th octave bands or 80 bands |
642
- 4 | 1/6th octave bands or 60 bands |
643
- 5 | 1/4th octave bands or 40 bands |
644
- 6 | 1/3rd octave bands or 30 bands |
645
- 7 | Half octave bands or 20 bands |
646
- 8 | Full octave bands or 10 bands |
669
+ 0 | Discrete frequencies | *default*
670
+ 1 | 1/24th octave bands or 240 bands | *use 'log' `frequencyScale` for octave bands*
671
+ 2 | 1/12th octave bands or 120 bands | *use 'log' `frequencyScale` for octave bands*
672
+ 3 | 1/8th octave bands or 80 bands | *use 'log' `frequencyScale` for octave bands*
673
+ 4 | 1/6th octave bands or 60 bands | *use 'log' `frequencyScale` for octave bands*
674
+ 5 | 1/4th octave bands or 40 bands | *use 'log' `frequencyScale` for octave bands*
675
+ 6 | 1/3rd octave bands or 30 bands | *use 'log' `frequencyScale` for octave bands*
676
+ 7 | Half octave bands or 20 bands | *use 'log' `frequencyScale` for octave bands*
677
+ 8 | Full octave bands or 10 bands | *use 'log' `frequencyScale` for octave bands*
647
678
  9 | *(not valid)* | *reserved*
648
679
  10 | Graph | *added in v1.1.0*
649
680
 
650
681
  + **Mode 0** provides the highest resolution, allowing you to visualize individual frequencies as provided by the [FFT](https://en.wikipedia.org/wiki/Fast_Fourier_transform) computation;
651
- + **Modes 1 - 8** divide the frequency spectrum in bands; when using the default **logarithmic** [frequency scale](#frequencyscale-string), each band represents the *n*th part of an octave (see also [`ansiBands`](#ansibands-boolean)); otherwise, a fixed number of bands is used for each mode;
682
+ + **Modes 1 - 8** divide the frequency spectrum in bands; when using the default **logarithmic** [`frequencyScale`](#frequencyscale-string), each band represents the *n*th part of an octave; otherwise, a fixed number of bands is used for each mode;
652
683
  + **Mode 10** uses the discrete FFT data points to draw a continuous line and/or a filled area graph (see [`fillAlpha`](#fillalpha-number) and [`lineWidth`](#linewidth-number) properties).
653
684
 
685
+ See also [`ansiBands`](#ansibands-boolean).
686
+
654
687
  Defaults to **0**.
655
688
 
656
689
  ### `noteLabels` *boolean*
@@ -659,7 +692,8 @@ Defaults to **0**.
659
692
 
660
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*).
661
694
 
662
- For best visualization in [octave bands modes](#mode-number), make sure [`frequencyScale`](#frequencyscale-string) is set to *'log'* and [`ansiBands`](#ansibands-boolean) is set to *false*, so all bands will be perfectly aligned with notes frequencies.
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.
663
697
 
664
698
  Defaults to **false**.
665
699
 
@@ -700,8 +734,7 @@ You can refer to this value to adjust any additional drawings done in the canvas
700
734
 
701
735
  When *true*, the spectrum analyzer is rendered in a circular shape, with radial frequency bars spreading from its center.
702
736
 
703
- On radial spectrum, [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) effects are disabled, and
704
- [`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).
705
738
 
706
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.
707
740
 
@@ -754,6 +787,21 @@ This has no effect when [`lumiBars`](#lumibars-boolean) is *true*.
754
787
 
755
788
  Defaults to **0** (no reflection).
756
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
+
757
805
  ### `showBgColor` *boolean*
758
806
 
759
807
  Determines whether the canvas background should be painted.
@@ -828,9 +876,9 @@ Defaults to **0**.
828
876
 
829
877
  When set to *true* and [`channelLayout`](#channellayout-string) is **_dual-vertical_**, the gradient will be split between channels.
830
878
 
831
- 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.
832
880
 
833
- | gradient: *'classic'* - splitGradient: *false* | gradient: *'classic'* - splitGradient: *true* |
881
+ | splitGradient: *false* | splitGradient: *true* |
834
882
  |:--:|:--:|
835
883
  | ![split-off](img/splitGradient_off.png) | ![split-on](img/splitGradient_on.png) |
836
884
 
@@ -842,6 +890,24 @@ Defaults to **false**.
842
890
 
843
891
  **This property will be removed in version 5** - Use [`channelLayout`](#channellayout-string) instead.
844
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
+ | ![split-off](img/trueleds_off.png) | ![split-on](img/trueleds_on.png) |
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
+
845
911
  ### `useCanvas` *boolean*
846
912
 
847
913
  *Available since v3.5.0*
@@ -911,11 +977,15 @@ Since this is a static property, you should always access it as `AudioMotionAnal
911
977
 
912
978
  ### `onCanvasDraw` *function*
913
979
 
914
- If defined, this function will be called after rendering each frame.
980
+ If defined, this function will be called after **audioMotion-analyzer** finishes rendering each animation frame.
915
981
 
916
- The audioMotion object will be passed as an argument to the callback function.
982
+ The callback function is passed two arguments: an *AudioMotionAnalyzer* object, and an object with the following properties:
983
+ - `timestamp`, a [*DOMHighResTimeStamp*](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp)
984
+ which indicates the elapsed time in milliseconds since the analyzer started running;
985
+ - `canvasGradients`, an array of [*CanvasGradient*](https://developer.mozilla.org/en-US/docs/Web/API/CanvasGradient])
986
+ objects currently in use on the left (or single) and right analyzer channels.
917
987
 
918
- Canvas properties `fillStyle` and `strokeStyle` will be set to the current gradient when the function is called.
988
+ The canvas properties `fillStyle` and `strokeStyle` will be set to the left/single channel gradient before the function is called.
919
989
 
920
990
  Usage example:
921
991
 
@@ -928,16 +998,26 @@ const audioMotion = new AudioMotionAnalyzer(
928
998
  }
929
999
  );
930
1000
 
931
- function drawCallback( instance ) {
932
- const ctx = instance.canvasCtx,
933
- baseSize = ( instance.isFullscreen ? 40 : 20 ) * instance.pixelRatio;
934
-
935
- // use the 'energy' value to increase the font size and make the logo pulse to the beat
1001
+ function drawCallback( instance, info ) {
1002
+ const baseSize = ( instance.isFullscreen ? 40 : 20 ) * instance.pixelRatio,
1003
+ canvas = instance.canvas,
1004
+ centerX = canvas.width / 2,
1005
+ centerY = canvas.height / 2,
1006
+ ctx = instance.canvasCtx,
1007
+ maxHeight = centerY / 2,
1008
+ maxWidth = centerX - baseSize * 5,
1009
+ time = info.timestamp / 1e4;
1010
+
1011
+ // the energy value is used here to increase the font size and make the logo pulsate to the beat
936
1012
  ctx.font = `${ baseSize + instance.getEnergy() * 25 * instance.pixelRatio }px Orbitron, sans-serif`;
937
1013
 
938
- ctx.fillStyle = '#fff8';
1014
+ // use the right-channel gradient to fill text
1015
+ ctx.fillStyle = info.canvasGradients[1];
939
1016
  ctx.textAlign = 'center';
940
- ctx.fillText( 'audioMotion', instance.canvas.width - baseSize * 8, baseSize * 2 );
1017
+ ctx.globalCompositeOperation = 'lighter';
1018
+
1019
+ // the timestamp can be used to create effects and animations based on the elapsed time
1020
+ ctx.fillText( 'audioMotion', centerX + maxWidth * Math.cos( time % Math.PI * 2 ), centerY + maxHeight * Math.sin( time % Math.PI * 16 ) );
941
1021
  }
942
1022
  ```
943
1023
 
@@ -947,7 +1027,7 @@ For more examples, see the fluid demo [source code](https://github.com/hvianna/a
947
1027
 
948
1028
  If defined, this function will be called whenever the canvas is resized.
949
1029
 
950
- Two arguments are passed: a string with the reason why the function was called (see below) and the audioMotion object.
1030
+ The callback function is passed two arguments: a string which indicates the reason that triggered the call (see below) and the *AudioMotionAnalyzer* object.
951
1031
 
952
1032
  Reason | Description
953
1033
  -------|------------
@@ -1084,29 +1164,34 @@ Use this method inside your callback function to create additional visual effect
1084
1164
 
1085
1165
  Registers a custom color gradient.
1086
1166
 
1087
- `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.
1088
1168
 
1089
1169
  `options` must be an object as shown below:
1090
1170
 
1091
1171
  ```js
1092
- const options = {
1172
+ audioMotion.registerGradient( 'myGradient', {
1093
1173
  bgColor: '#011a35', // background color (optional) - defaults to '#111'
1094
1174
  dir: 'h', // add this property to create a horizontal gradient (optional)
1095
1175
  colorStops: [ // list your gradient colors in this array (at least one color is required)
1096
- 'red', // colors may be defined in any valid CSS format
1097
- { pos: .6, color: '#ff0' }, // use an object to adjust the offset (0 to 1) of a colorStop
1098
- 'hsl( 120, 100%, 50% )'
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
1099
1179
  ]
1100
- }
1101
-
1102
- audioMotion.registerGradient( 'myGradient', options );
1180
+ });
1103
1181
  ```
1104
1182
 
1105
- Check the [built-in **_'rainbow'_** gradient](#gradient-string) for an example of horizontal gradient.
1183
+ The `dir` property has no effect on [`radial`](#radial-boolean) spectrum or when [`trueLeds`](#trueleds-boolean) is in effect.
1106
1184
 
1107
- **Note:** the horizontal flag (`dir: 'h'`) has no effect on [`radial`](#radial-boolean) spectrum, because in that mode all gradients are rendered in radial direction.
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.
1108
1193
 
1109
- ?> Any gradient, including the built-in ones, may be modified by (re-)registering the same gradient name (names are case sensitive).
1194
+ ?> Any gradient, including the built-in ones, may be modified at any time by (re-)registering the same gradient name.
1110
1195
 
1111
1196
  ### `setCanvasSize( width, height )`
1112
1197
 
@@ -1259,11 +1344,11 @@ myAudio.crossOrigin = 'anonymous';
1259
1344
  Browser autoplay policy dictates that audio output can only be initiated by a user gesture, and this is enforced by WebAudio API
1260
1345
  by creating [*AudioContext*](#audioctx-audiocontext-object-read-only) objects in *suspended* mode.
1261
1346
 
1262
- **audioMotion-analyzer** tries to automatically start its audio context on the first click on the page.
1347
+ **audioMotion-analyzer** tries to automatically start its AudioContext on the first click on the page.
1263
1348
  However, if you're using an `audio` or `video` element with the `controls` property, clicks on those native media controls cannot be detected
1264
1349
  by JavaScript, so the audio will only be enabled if/when the user clicks somewhere else.
1265
1350
 
1266
- Two possible solutions: **1)** make **sure** your users have to click somewhere else before using the media controls,
1351
+ Two possible solutions are: **1)** ensure your users have to click somewhere else before using the media controls,
1267
1352
  like a "power on" button, or simply clicking to select a song from a list will do; or **2)** don't use the native
1268
1353
  controls at all, and create your own custom play and stop buttons. A very simple example:
1269
1354
 
@@ -1281,6 +1366,9 @@ document.getElementById('play').addEventListener( 'click', () => myAudio.play()
1281
1366
  document.getElementById('stop').addEventListener( 'click', () => myAudio.pause() );
1282
1367
  ```
1283
1368
 
1369
+ You can also prevent the _"The AudioContext was not allowed to start"_ warning message from appearing in the browser console, by instantiating
1370
+ your **audioMotion-analyzer** object within a function triggered by a user click. See the [minimal demo](/demo/minimal.html) code for an example.
1371
+
1284
1372
 
1285
1373
  ## References and acknowledgments
1286
1374
 
@@ -1293,7 +1381,9 @@ document.getElementById('stop').addEventListener( 'click', () => myAudio.pause()
1293
1381
  * [Equations for equal-tempered scale frequencies](http://pages.mtu.edu/~suits/NoteFreqCalcs.html)
1294
1382
  * [Making Audio Reactive Visuals](https://www.airtightinteractive.com/2013/10/making-audio-reactive-visuals/)
1295
1383
  * The font used in audioMotion's logo is [Orbitron](https://fonts.google.com/specimen/Orbitron) by Matt McInerney
1296
- * This documentation website is powered by [GitHub Pages](https://pages.github.com/), [docsify](https://docsify.js.org/) and [docsify-themeable](https://jhildenbiddle.github.io/docsify-themeable).
1384
+ * The _prism_ and _rainbow_ gradients use the [12-bit rainbow palette](https://iamkate.com/data/12-bit-rainbow/) by Kate Morley
1385
+ * The cover page animation was recorded with [ScreenToGif](https://github.com/NickeManarin/ScreenToGif) by Nicke Manarin
1386
+ * This documentation website is powered by [GitHub Pages](https://pages.github.com/), [docsify](https://docsify.js.org/) and [docsify-themeable](https://jhildenbiddle.github.io/docsify-themeable)
1297
1387
 
1298
1388
 
1299
1389
  ## Changelog
@@ -1303,18 +1393,20 @@ See [Changelog.md](Changelog.md)
1303
1393
 
1304
1394
  ## Contributing
1305
1395
 
1306
- If you want to send feedback, ask a question, or need help with something, please use the [**Discussions**](https://github.com/hvianna/audioMotion-analyzer/discussions) area on GitHub.
1396
+ I kindly request that you only [open an issue](https://github.com/hvianna/audioMotion-analyzer/issues) for submitting a **bug report**.
1307
1397
 
1308
- I would love to see your cool projects using **audioMotion-analyzer** -- post them in the *Show and tell* section of [Discussions](https://github.com/hvianna/audioMotion-analyzer/discussions)!
1398
+ If you need help integrating *audioMotion-analyzer* with your project, have ideas for **new features** or any other questions or feedback,
1399
+ please use the [**Discussions**](https://github.com/hvianna/audioMotion-analyzer/discussions) section on GitHub.
1309
1400
 
1310
- For **bug reports** and **feature requests**, feel free to [open an issue](https://github.com/hvianna/audioMotion-analyzer/issues).
1401
+ Additionally, I would love it if you could showcase your project using *audioMotion-analyzer* in [**Show and Tell**](https://github.com/hvianna/audioMotion-analyzer/discussions/categories/show-and-tell),
1402
+ and share your custom gradients with the community in [**Gradients**](https://github.com/hvianna/audioMotion-analyzer/discussions/categories/gradients)!
1311
1403
 
1312
- If you want to submit a **Pull Request**, please branch it off the project's `develop` branch.
1404
+ When submitting a **Pull Request**, please branch it off the project's `develop` branch.
1313
1405
 
1314
1406
  And if you're feeling generous, maybe:
1315
1407
 
1316
1408
  * [Buy me a coffee](https://ko-fi.com/Q5Q6157GZ) on Ko-fi β˜•πŸ˜
1317
- * Gift me something from my [Bandcamp wishlist](https://bandcamp.com/henriquevianna/wishlist) 🎁πŸ₯°
1409
+ * Gift me something from my [Bandcamp wishlist](https://bandcamp.com/henriquevianna/wishlist) 🎁🎢πŸ₯°
1318
1410
  * Tip me via [Brave Rewards](https://brave.com/brave-rewards/) using Brave browser πŸ€“
1319
1411
 
1320
1412
 
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.0.0-beta.5",
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",