audiomotion-analyzer 4.0.0-beta.0 → 4.0.0-beta.2
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 +140 -54
- package/package.json +1 -1
- package/src/audioMotion-analyzer.js +361 -197
- package/src/index.d.ts +27 -8
package/README.md
CHANGED
|
@@ -28,17 +28,18 @@ What users are saying:
|
|
|
28
28
|
## Features
|
|
29
29
|
|
|
30
30
|
+ High-resolution real-time dual channel audio spectrum analyzer
|
|
31
|
-
+ Logarithmic frequency
|
|
32
|
-
+
|
|
33
|
-
+
|
|
34
|
-
+
|
|
31
|
+
+ Logarithmic, linear and perceptual (Bark/Mel) frequency scales, with customizable range
|
|
32
|
+
+ Visualization of discrete FFT frequencies or up to 240 frequency bands (supports ANSI and equal-tempered octave bands)
|
|
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
|
|
35
36
|
+ Comes with 3 predefined color gradients - easily add your own!
|
|
36
37
|
+ Fullscreen support, ready for retina / HiDPI displays
|
|
37
38
|
+ Zero-dependency native ES6+ module (ESM), \~20kB minified
|
|
38
39
|
|
|
39
40
|
## Online demos
|
|
40
41
|
|
|
41
|
-
[](https://audiomotion.dev/demo/)
|
|
42
43
|
|
|
43
44
|
?> https://audiomotion.dev/demo/
|
|
44
45
|
|
|
@@ -121,11 +122,13 @@ options = {<br>
|
|
|
121
122
|
  [connectSpeakers](#connectspeakers-boolean): **true**, // constructor only<br>
|
|
122
123
|
  [fftSize](#fftsize-number): **8192**,<br>
|
|
123
124
|
  [fillAlpha](#fillalpha-number): **1**,<br>
|
|
125
|
+
  [frequencyScale](#frequencyscale-string): **'log'**,<br>
|
|
124
126
|
  [fsElement](#fselement-htmlelement-object): *undefined*, // constructor only<br>
|
|
125
127
|
  [gradient](#gradient-string): **'classic'**,<br>
|
|
126
128
|
  [height](#height-number): *undefined*,<br>
|
|
127
129
|
  [ledBars](#ledbars-boolean): **false**,<br>
|
|
128
130
|
  [linearAmplitude](#linearamplitude-boolean): **false**,<br>
|
|
131
|
+
  [linearBoost](#linearboost-number): **1**,<br>
|
|
129
132
|
  [lineWidth](#linewidth-number): **0**,<br>
|
|
130
133
|
  [loRes](#lores-boolean): **false**,<br>
|
|
131
134
|
  [lumiBars](#lumibars-boolean): **false**,<br>
|
|
@@ -158,6 +161,7 @@ options = {<br>
|
|
|
158
161
|
  [stereo](#stereo-boolean): **false**,<br>
|
|
159
162
|
  [useCanvas](#usecanvas-boolean): **true**,<br>
|
|
160
163
|
  [volume](#volume-number): **1**,<br>
|
|
164
|
+
  [weightingFilter](#weightingFilter-string): **''**<br>
|
|
161
165
|
  [width](#width-number): *undefined*<br>
|
|
162
166
|
}
|
|
163
167
|
|
|
@@ -280,7 +284,7 @@ See also the [fluid demo](/demo/fluid.html) and the [multi-instance demo](/demo/
|
|
|
280
284
|
|
|
281
285
|
*Available since v2.0.0*
|
|
282
286
|
|
|
283
|
-
Customize the spacing between bars in
|
|
287
|
+
Customize the spacing between bars in [bands modes](#mode-number).
|
|
284
288
|
|
|
285
289
|
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.
|
|
286
290
|
|
|
@@ -340,13 +344,13 @@ Defaults to **8192**.
|
|
|
340
344
|
|
|
341
345
|
*Available since v2.0.0*
|
|
342
346
|
|
|
343
|
-
Opacity of the area fill in
|
|
347
|
+
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*.
|
|
344
348
|
|
|
345
349
|
It must be a number between 0 (completely transparent) and 1 (completely opaque).
|
|
346
350
|
|
|
347
351
|
Please note that the line stroke (when [`lineWidth`](#linewidth-number) > 0) is always drawn at full opacity, regardless of the `fillAlpha` value.
|
|
348
352
|
|
|
349
|
-
Also, for
|
|
353
|
+
Also, for [bands modes](#mode-number), [`alphaBars`](#alphabars-boolean) set to *true* takes precedence over `fillAlpha`.
|
|
350
354
|
|
|
351
355
|
Defaults to **1**.
|
|
352
356
|
|
|
@@ -356,6 +360,25 @@ Defaults to **1**.
|
|
|
356
360
|
|
|
357
361
|
Current frame rate.
|
|
358
362
|
|
|
363
|
+
### `frequencyScale` *string*
|
|
364
|
+
|
|
365
|
+
*Available since v4.0.0*
|
|
366
|
+
|
|
367
|
+
Scale used to represent frequencies in the horizontal axis.
|
|
368
|
+
|
|
369
|
+
frequencyScale | description
|
|
370
|
+
---------------|------------
|
|
371
|
+
'bark' | [Bark scale](https://en.wikipedia.org/wiki/Bark_scale)
|
|
372
|
+
'linear' | Linear scale
|
|
373
|
+
'log' | Logarithmic scale
|
|
374
|
+
'mel' | [Mel scale](https://en.wikipedia.org/wiki/Mel_scale)
|
|
375
|
+
|
|
376
|
+
Logarithmic scale is required to visualize proper [octave bands](#mode-number) and it's also recommended when using [`noteLabels`](#notelabels-boolean).
|
|
377
|
+
|
|
378
|
+
*Bark* and *Mel* are perceptual pitch scales which provide better visualization of midrange and high frequencies, especially in the [discrete frequencies mode](#mode-number).
|
|
379
|
+
|
|
380
|
+
Defaults to **'log'**.
|
|
381
|
+
|
|
359
382
|
### `fsElement` *HTMLElement object* *(Read only)*
|
|
360
383
|
|
|
361
384
|
*Available since v3.4.0*
|
|
@@ -371,9 +394,9 @@ Canvas dimensions used during fullscreen mode. These take the current pixel rati
|
|
|
371
394
|
|
|
372
395
|
### `gradient` *string*
|
|
373
396
|
|
|
374
|
-
|
|
397
|
+
Name of the color gradient used for analyzer graphs.
|
|
375
398
|
|
|
376
|
-
It must be
|
|
399
|
+
It must be a built-in or [registered](#registergradient-name-options-) gradient name. Built-in gradients are *'classic'*, *'prism'* and *'rainbow'*.
|
|
377
400
|
|
|
378
401
|
Defaults to **'classic'**.
|
|
379
402
|
|
|
@@ -384,7 +407,7 @@ Nominal dimensions of the analyzer.
|
|
|
384
407
|
|
|
385
408
|
If one or both of these are `undefined`, the analyzer will try to adjust to the container's width and/or height.
|
|
386
409
|
If the container's width and/or height are 0 (inline elements), a reference size of **640 x 270 pixels** will be used to replace the missing dimension(s).
|
|
387
|
-
This should be considered the minimum dimensions for proper visualization of all available modes
|
|
410
|
+
This should be considered the minimum dimensions for proper visualization of all available modes and effects.
|
|
388
411
|
|
|
389
412
|
You can set both values at once using the [`setCanvasSize()`](#setcanvassize-width-height-) method.
|
|
390
413
|
|
|
@@ -395,7 +418,15 @@ You can set both values at once using the [`setCanvasSize()`](#setcanvassize-wid
|
|
|
395
418
|
*Available since v3.6.0*
|
|
396
419
|
|
|
397
420
|
***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
|
|
398
|
-
or one of the
|
|
421
|
+
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*.
|
|
422
|
+
|
|
423
|
+
### `isBandsMode` *boolean* *(Read only)*
|
|
424
|
+
|
|
425
|
+
*Available since v4.0.0*
|
|
426
|
+
|
|
427
|
+
***true*** when [`mode`](#mode-number) is set to one of the bands mode (modes 1 to 8).
|
|
428
|
+
|
|
429
|
+
See also [`isOctaveBands`](#isoctavebands-boolean-read-only).
|
|
399
430
|
|
|
400
431
|
### `isFullscreen` *boolean* *(Read only)*
|
|
401
432
|
|
|
@@ -407,19 +438,19 @@ See [`toggleFullscreen()`](#togglefullscreen).
|
|
|
407
438
|
|
|
408
439
|
*Available since v3.6.0* (formerly `isLedDisplay`)
|
|
409
440
|
|
|
410
|
-
***true*** when LED bars are effectively being displayed, i.e., [`
|
|
441
|
+
***true*** when LED bars are effectively being displayed, i.e., [`isBandsMode`](#isbandsmode-boolean-read-only) is *true*, [`ledBars`](#ledBars-boolean) is set to *true* and [`radial`](#radial-boolean) is set to *false*.
|
|
411
442
|
|
|
412
443
|
### `isLumiBars` *boolean* *(Read only)*
|
|
413
444
|
|
|
414
445
|
*Available since v3.0.0*
|
|
415
446
|
|
|
416
|
-
***true*** when luminance bars are effectively being displayed, i.e., [`
|
|
447
|
+
***true*** when luminance bars are effectively being displayed, i.e., [`isBandsMode`](#isbandsmode-boolean-read-only) is *true*, [`lumiBars`](#lumibars-boolean) is set to *true* and [`radial`](#radial-boolean) is set to *false*.
|
|
417
448
|
|
|
418
449
|
### `isOctaveBands` *boolean* *(Read only)*
|
|
419
450
|
|
|
420
451
|
*Available since v3.0.0*
|
|
421
452
|
|
|
422
|
-
***true*** when [`
|
|
453
|
+
***true*** when [`isBandsMode`](#isbandsmode-boolean-read-only) is *true* and [`frequencyScale`](#frequencyscale-string) is set to *'log'*.
|
|
423
454
|
|
|
424
455
|
### `isOn` *boolean* *(Read only)*
|
|
425
456
|
|
|
@@ -431,14 +462,14 @@ See [`toggleAnalyzer()`](#toggleanalyzer-boolean-).
|
|
|
431
462
|
|
|
432
463
|
*Available since v3.6.0*
|
|
433
464
|
|
|
434
|
-
***true*** when outlined bars are effectively being displayed, i.e., [`
|
|
435
|
-
|
|
465
|
+
***true*** when outlined bars are effectively being displayed, i.e., [`isBandsMode`](#isbandsmode-boolean-read-only) is *true*, [`outlineBars`](#outlinebars-boolean) is set to *true*
|
|
466
|
+
and both [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) are set to *false*, or [`radial`](#radial-boolean) is set to *true*.
|
|
436
467
|
|
|
437
468
|
### `ledBars` *boolean*
|
|
438
469
|
|
|
439
470
|
*Available since v3.6.0* (formerly `showLeds`)
|
|
440
471
|
|
|
441
|
-
*true* to activate
|
|
472
|
+
*true* to activate the vintage LED bars effect for [bands modes](#mode-number).
|
|
442
473
|
|
|
443
474
|
This effect can be customized via [`setLedParams()`](#setledparams-params-) method.
|
|
444
475
|
|
|
@@ -450,16 +481,29 @@ Defaults to **false**.
|
|
|
450
481
|
|
|
451
482
|
*Available since v4.0.0*
|
|
452
483
|
|
|
453
|
-
When set to *true
|
|
484
|
+
When set to *true*, spectrum amplitudes are represented in linear scale instead of decibels (logarithmic).
|
|
485
|
+
|
|
454
486
|
This may improve the visualization of predominant tones, especially at higher frequencies, but it will make the entire spectrum look much quieter.
|
|
455
487
|
|
|
488
|
+
See also [`linearBoost`](#linearboost-number).
|
|
489
|
+
|
|
456
490
|
Defaults to **false**.
|
|
457
491
|
|
|
492
|
+
### `linearBoost` *number*
|
|
493
|
+
|
|
494
|
+
*Available since v4.0.0*
|
|
495
|
+
|
|
496
|
+
Performs an *n*th-root to amplify low energy values when using linear scale for the amplitude.
|
|
497
|
+
|
|
498
|
+
It should be a number >= 1, while 1 means no boosting. Only effective when [`linearAmplitude`](#linearamplitude-boolean) is set to *true*.
|
|
499
|
+
|
|
500
|
+
Defaults to **1**.
|
|
501
|
+
|
|
458
502
|
### `lineWidth` *number*
|
|
459
503
|
|
|
460
504
|
*Available since v2.0.0*
|
|
461
505
|
|
|
462
|
-
Line width for
|
|
506
|
+
Line width for [Graph mode](#mode-number), or outline stroke in [bands modes](#mode-number) when [`outlineBars`](#outlinebars-boolean) is *true*.
|
|
463
507
|
|
|
464
508
|
For the line to be distinguishable, set also [`fillAlpha`](#fillalpha-number) < 1.
|
|
465
509
|
|
|
@@ -486,7 +530,7 @@ This will prevent the canvas size from changing, when switching the low resoluti
|
|
|
486
530
|
|
|
487
531
|
*Available since v1.1.0*
|
|
488
532
|
|
|
489
|
-
This is only effective for
|
|
533
|
+
This is only effective for [bands modes](#mode-number).
|
|
490
534
|
|
|
491
535
|
When set to *true* all analyzer bars will be displayed at full height with varying luminance (opacity, actually) instead.
|
|
492
536
|
|
|
@@ -514,7 +558,8 @@ Highest and lowest frequencies represented in the X-axis of the analyzer. Values
|
|
|
514
558
|
|
|
515
559
|
The minimum allowed value is **1**. Trying to set a lower value will throw an `ERR_FREQUENCY_TOO_LOW` [error](#custom-errors).
|
|
516
560
|
|
|
517
|
-
The maximum
|
|
561
|
+
The maximum allowed value is half the sampling rate ([`audioCtx.sampleRate`](#audioctx-audiocontext-object-read-only)), known as the [Nyquist frequency](https://en.wikipedia.org/wiki/Nyquist_frequency).
|
|
562
|
+
Values higher than that will be capped.
|
|
518
563
|
|
|
519
564
|
It is preferable to use the [`setFreqRange()`](#setfreqrange-minfreq-maxfreq-) method and set both values at once, to prevent `minFreq` being higher than the current `maxFreq` or vice-versa at a given moment.
|
|
520
565
|
|
|
@@ -538,26 +583,26 @@ Defaults to **0**.
|
|
|
538
583
|
|
|
539
584
|
### `mode` *number*
|
|
540
585
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
+ **Discrete** mode provides the highest resolution, allowing you to visualize individual frequencies amplitudes as provided by the [FFT](https://en.wikipedia.org/wiki/Fast_Fourier_transform) computation;
|
|
544
|
-
+ **Octave bands** modes display wider vertical bars, each one representing the *n*th part of an octave, based on a [24-tone equal tempered scale](https://en.wikipedia.org/wiki/Quarter_tone);
|
|
545
|
-
+ **Graph** mode uses the discrete data points to draw a continuous line and/or filled area graph (see [`fillAlpha`](#fillalpha-number) and [`lineWidth`](#linewidth-number) properties).
|
|
586
|
+
Visualization mode.
|
|
546
587
|
|
|
547
588
|
mode | description | notes
|
|
548
|
-
|
|
589
|
+
----:|:-----------:|------
|
|
549
590
|
0 | Discrete frequencies |
|
|
550
|
-
1 | 1/24th octave bands |
|
|
551
|
-
2 | 1/12th octave bands |
|
|
552
|
-
3 | 1/8th octave bands |
|
|
553
|
-
4 | 1/6th octave bands |
|
|
554
|
-
5 | 1/4th octave bands |
|
|
555
|
-
6 | 1/3rd octave bands |
|
|
556
|
-
7 | Half octave bands |
|
|
557
|
-
8 | Full octave bands |
|
|
591
|
+
1 | 1/24th octave bands or 240 bands |
|
|
592
|
+
2 | 1/12th octave bands or 120 bands |
|
|
593
|
+
3 | 1/8th octave bands or 80 bands |
|
|
594
|
+
4 | 1/6th octave bands or 60 bands |
|
|
595
|
+
5 | 1/4th octave bands or 40 bands |
|
|
596
|
+
6 | 1/3rd octave bands or 30 bands |
|
|
597
|
+
7 | Half octave bands or 20 bands |
|
|
598
|
+
8 | Full octave bands or 10 bands |
|
|
558
599
|
9 | *(not valid)* | *reserved*
|
|
559
600
|
10 | Graph | *added in v1.1.0*
|
|
560
601
|
|
|
602
|
+
+ **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;
|
|
603
|
+
+ **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;
|
|
604
|
+
+ **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).
|
|
605
|
+
|
|
561
606
|
Defaults to **0**.
|
|
562
607
|
|
|
563
608
|
### `noteLabels` *boolean*
|
|
@@ -566,7 +611,7 @@ Defaults to **0**.
|
|
|
566
611
|
|
|
567
612
|
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*).
|
|
568
613
|
|
|
569
|
-
For best visualization in octave bands modes, make sure [`ansiBands`](#ansibands-boolean) is set to *false*, so all bands will be perfectly aligned with notes frequencies.
|
|
614
|
+
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.
|
|
570
615
|
|
|
571
616
|
Defaults to **false**.
|
|
572
617
|
|
|
@@ -574,7 +619,7 @@ Defaults to **false**.
|
|
|
574
619
|
|
|
575
620
|
*Available since v3.6.0*
|
|
576
621
|
|
|
577
|
-
When *true* and [`mode`](#mode-number) is set to one of the **
|
|
622
|
+
When *true* and [`mode`](#mode-number) is set to one of the **bands** modes, analyzer bars are rendered outlined, with customizable [`fillAlpha`](#fillalpha-number) and [`lineWidth`](#linewidth-number).
|
|
578
623
|
|
|
579
624
|
For effect priority when combined with other settings, see [`isOutlineBars`](#isoutlinebars-boolean-read-only).
|
|
580
625
|
|
|
@@ -735,9 +780,9 @@ When *true*, the gradient will be split between both channels, so each channel w
|
|
|
735
780
|
|
|
736
781
|
| splitGradient: *true* | splitGradient: *false* |
|
|
737
782
|
|:--:|:--:|
|
|
738
|
-
|  |  |
|
|
739
784
|
|
|
740
|
-
This option has no effect
|
|
785
|
+
This option has no effect on horizontal gradients, or when [`stereo`](#stereo-boolean) is set to *false*.
|
|
741
786
|
|
|
742
787
|
Defaults to **false**.
|
|
743
788
|
|
|
@@ -783,6 +828,33 @@ Please note that changing the audio element volume directly will affect the ampl
|
|
|
783
828
|
|
|
784
829
|
Defaults to **1**.
|
|
785
830
|
|
|
831
|
+
### `weightingFilter` *string*
|
|
832
|
+
|
|
833
|
+
*Available since v4.0.0*
|
|
834
|
+
|
|
835
|
+
[Weighting filter](https://en.wikipedia.org/wiki/Weighting_filter) applied to frequency data for spectrum visualization.
|
|
836
|
+
|
|
837
|
+
?> Selecting a weighting filter **does NOT** affect the audio output.
|
|
838
|
+
|
|
839
|
+
Each filter applies a different curve of gain/attenuation to specific frequency ranges, but the general idea is to adjust the
|
|
840
|
+
visualization of frequencies to which the human ear is more or less sensitive.
|
|
841
|
+
|
|
842
|
+
Refer to the [weighting filters viewer tool](/tools/weighting-filters.html) for response tables and an interactive version of the curves graph seen below.
|
|
843
|
+
|
|
844
|
+
<img src="img/weigthing-filters-curves.png" class="align-right">
|
|
845
|
+
|
|
846
|
+
weightingFilter | description
|
|
847
|
+
------|------------------------------
|
|
848
|
+
'' (empty string) | No weighting applied (default)
|
|
849
|
+
'A' | A-weighting
|
|
850
|
+
'B' | B-weighting
|
|
851
|
+
'C' | C-weighting
|
|
852
|
+
'D' | D-weighting
|
|
853
|
+
'468' | ITU-R 468 weighting
|
|
854
|
+
|
|
855
|
+
Defaults to **''**.
|
|
856
|
+
|
|
857
|
+
|
|
786
858
|
## Static properties
|
|
787
859
|
|
|
788
860
|
### `AudioMotionAnalyzer.version` *string* *(Read only)*
|
|
@@ -925,8 +997,9 @@ Returns an array with current data for each analyzer bar. Each array element is
|
|
|
925
997
|
```js
|
|
926
998
|
{
|
|
927
999
|
posX: <number>, // horizontal position of this bar on the canvas
|
|
928
|
-
|
|
929
|
-
|
|
1000
|
+
freq: <number>, // center frequency for this bar (added in v4.0.0)
|
|
1001
|
+
freqLo: <number>, // lower edge frequency
|
|
1002
|
+
freqHi: <number>, // upper edge frequency
|
|
930
1003
|
peak: <array>, // peak values for left and right channels
|
|
931
1004
|
hold: <array>, // peak hold frames for left and right channels - values < 0 mean the peak is falling down
|
|
932
1005
|
value: <array> // current amplitude on left and right channels
|
|
@@ -970,7 +1043,8 @@ Use this method inside your callback function to create additional visual effect
|
|
|
970
1043
|
|
|
971
1044
|
Registers a custom color gradient.
|
|
972
1045
|
|
|
973
|
-
`name` must be a non-empty *string* that will be used
|
|
1046
|
+
`name` must be a non-empty *string* that will be used to select this gradient, via the [`gradient`](#gradient-string) property.
|
|
1047
|
+
`options` must be an object as shown below:
|
|
974
1048
|
|
|
975
1049
|
```js
|
|
976
1050
|
const options = {
|
|
@@ -978,12 +1052,21 @@ const options = {
|
|
|
978
1052
|
dir: 'h', // add this property to create a horizontal gradient (optional)
|
|
979
1053
|
colorStops: [ // list your gradient colors in this array (at least 2 entries are required)
|
|
980
1054
|
'red', // colors may be defined in any valid CSS format
|
|
981
|
-
{ pos: .6, color: '#ff0' }, // use an object to adjust the
|
|
1055
|
+
{ pos: .6, color: '#ff0' }, // use an object to adjust the offset (0 to 1) of a colorStop
|
|
982
1056
|
'hsl( 120, 100%, 50% )' // colors may be defined in any valid CSS format
|
|
983
1057
|
]
|
|
984
1058
|
}
|
|
985
1059
|
|
|
986
|
-
audioMotion.registerGradient( '
|
|
1060
|
+
audioMotion.registerGradient( 'myGradient', options );
|
|
1061
|
+
```
|
|
1062
|
+
|
|
1063
|
+
!> In TypeScript projects make sure to import the `GradientOptions` definition and use it as the type of your object, like so:
|
|
1064
|
+
|
|
1065
|
+
```js
|
|
1066
|
+
import AudioMotionAnalyzer, { GradientOptions } from 'audiomotion-analyzer'
|
|
1067
|
+
|
|
1068
|
+
const options: GradientOptions = {
|
|
1069
|
+
⋮
|
|
987
1070
|
```
|
|
988
1071
|
|
|
989
1072
|
Additional information about [gradient color-stops](https://developer.mozilla.org/en-US/docs/Web/API/CanvasGradient/addColorStop).
|
|
@@ -996,11 +1079,13 @@ Sets the analyzer nominal dimensions in pixels. See [`height`](#height-number) a
|
|
|
996
1079
|
|
|
997
1080
|
Sets the desired frequency range. Values are expressed in Hz (Hertz).
|
|
998
1081
|
|
|
1082
|
+
See [`minFreq` and `maxFreq`](#minfreq-number) for lower and upper limit values.
|
|
1083
|
+
|
|
999
1084
|
### `setLedParams( [params] )`
|
|
1000
1085
|
|
|
1001
1086
|
*Available since v3.2.0*
|
|
1002
1087
|
|
|
1003
|
-
Customize parameters used to create the [
|
|
1088
|
+
Customize parameters used to create the [`ledBars`](#ledbars-boolean) effect.
|
|
1004
1089
|
|
|
1005
1090
|
`params` should be an object with the following structure:
|
|
1006
1091
|
|
|
@@ -1014,16 +1099,16 @@ const params = {
|
|
|
1014
1099
|
|
|
1015
1100
|
property | description
|
|
1016
1101
|
----------|-------------
|
|
1017
|
-
`maxLeds` | maximum desired number of LED elements per analyzer bar
|
|
1102
|
+
`maxLeds` | **maximum** desired number of LED elements per analyzer bar
|
|
1018
1103
|
`spaceV` | vertical spacing ratio, relative to the LED height (**1** means spacing is the same as the LED height)
|
|
1019
|
-
`spaceH` | **minimum** horizontal spacing ratio, relative to the available width
|
|
1104
|
+
`spaceH` | **minimum** horizontal spacing ratio, relative to the available width for each band, or a literal pixel value if **>= 1**;<br>this behaves exactly like [`barSpace`](#barspace-number) and the largest spacing (resulting from either `barSpace` or `spaceH`) will prevail.
|
|
1020
1105
|
|
|
1021
1106
|
The available canvas height is initially divided by `maxLeds` and vertical spacing is calculated observing the `spaceV` ratio;
|
|
1022
1107
|
if necessary, the led count is decreased until both the led segment and the vertical spacing are at least 2px tall.
|
|
1023
1108
|
|
|
1024
1109
|
You can try different values in the [fluid demo](https://audiomotion.dev/demo/fluid.html).
|
|
1025
1110
|
|
|
1026
|
-
|
|
1111
|
+
?> If called with no arguments or any invalid property, clears custom parameters previously set.
|
|
1027
1112
|
|
|
1028
1113
|
### `setOptions( [options] )`
|
|
1029
1114
|
|
|
@@ -1134,15 +1219,16 @@ myAudio.crossOrigin = 'anonymous';
|
|
|
1134
1219
|
|
|
1135
1220
|
### Sound only plays after the user clicks somewhere on the page. <!-- {docsify-ignore} -->
|
|
1136
1221
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1222
|
+
Browser autoplay policy dictates that audio output can only be initiated by a user gesture, and this is enforced by WebAudio API
|
|
1223
|
+
by creating [*AudioContext*](#audioctx-audiocontext-object-read-only) objects in *suspended* mode.
|
|
1139
1224
|
|
|
1140
|
-
|
|
1141
|
-
|
|
1225
|
+
**audioMotion-analyzer** tries to automatically start its audio context on the first click on the page.
|
|
1226
|
+
However, if you're using an `audio` or `video` element with the `controls` property, clicks on those native media controls cannot be detected
|
|
1227
|
+
by JavaScript, so the audio will only be enabled if/when the user clicks somewhere else.
|
|
1142
1228
|
|
|
1143
1229
|
Two possible solutions: **1)** make **sure** your users have to click somewhere else before using the media controls,
|
|
1144
1230
|
like a "power on" button, or simply clicking to select a song from a list will do; or **2)** don't use the native
|
|
1145
|
-
controls at all, and create your own custom
|
|
1231
|
+
controls at all, and create your own custom play and stop buttons. A very simple example:
|
|
1146
1232
|
|
|
1147
1233
|
```html
|
|
1148
1234
|
<audio id="myAudio" src="track.mp3" crossorigin="anonymous"></audio> <!-- do not add the 'controls' property! -->
|
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.
|
|
4
|
+
"version": "4.0.0-beta.2",
|
|
5
5
|
"main": "./src/audioMotion-analyzer.js",
|
|
6
6
|
"module": "./src/audioMotion-analyzer.js",
|
|
7
7
|
"types": "./src/index.d.ts",
|