audiomotion-analyzer 3.6.1 → 4.0.0-beta.1
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 +182 -44
- package/package.json +1 -1
- package/src/audioMotion-analyzer.js +399 -229
- package/src/index.d.ts +23 -10
package/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
**audioMotion-analyzer** is a high-resolution real-time audio spectrum analyzer built upon **Web Audio** and **Canvas** JavaScript APIs.
|
|
5
5
|
|
|
6
|
-
It was originally conceived as part of a full-featured music player called [**audioMotion**](https://audiomotion.me),
|
|
7
|
-
the spectrum analyzer available as a self-contained module, so other developers could use it in their own projects.
|
|
6
|
+
It was originally conceived as part of a full-featured music player called [**audioMotion**](https://audiomotion.me),
|
|
7
|
+
but I later decided to make only the spectrum analyzer available as a self-contained module, so other developers could use it in their own projects.
|
|
8
8
|
|
|
9
9
|
My goal is to make this the best looking, most accurate and customizable spectrum analyzer around, in a small-footprint and high-performance package.
|
|
10
10
|
|
|
@@ -29,7 +29,7 @@ What users are saying:
|
|
|
29
29
|
|
|
30
30
|
+ High-resolution real-time dual channel audio spectrum analyzer
|
|
31
31
|
+ Logarithmic frequency scale with customizable range
|
|
32
|
-
+ Visualize discrete frequencies or octave bands
|
|
32
|
+
+ Visualize discrete FFT frequencies or octave bands
|
|
33
33
|
+ Optional effects: vintage LEDs, luminance bars, mirroring and reflection, radial visualization
|
|
34
34
|
+ Customizable sensitivity, FFT size and time-smoothing constant
|
|
35
35
|
+ Comes with 3 predefined color gradients - easily add your own!
|
|
@@ -48,7 +48,10 @@ What users are saying:
|
|
|
48
48
|
- [Using microphone input](https://codepen.io/hvianna/pen/VwKZgEE)
|
|
49
49
|
- [Creating additional effects with `getEnergy()`](https://codepen.io/hvianna/pen/poNmVYo)
|
|
50
50
|
- [No canvas example](https://codepen.io/hvianna/pen/ZEKWWJb) (create your own visualization using analyzer data)
|
|
51
|
-
-
|
|
51
|
+
- Example integrations with other audio libraries:
|
|
52
|
+
- [Icecast Metadata Player](https://codepen.io/hvianna/pen/YzrgWVe)
|
|
53
|
+
- [Pizzicato](https://codesandbox.io/s/9y6qb)
|
|
54
|
+
- [jPlayer](https://codepen.io/hvianna/pen/dyVrMJX)
|
|
52
55
|
- [See more code examples on CodePen](https://codepen.io/collection/ABbbKr)
|
|
53
56
|
|
|
54
57
|
## Usage
|
|
@@ -71,7 +74,7 @@ Or download the [latest version](https://github.com/hvianna/audioMotion-analyzer
|
|
|
71
74
|
Install as a dependency:
|
|
72
75
|
|
|
73
76
|
```console
|
|
74
|
-
$ npm i
|
|
77
|
+
$ npm i audiomotion-analyzer
|
|
75
78
|
```
|
|
76
79
|
|
|
77
80
|
Use ES6 import syntax:
|
|
@@ -111,6 +114,7 @@ Properties marked as *constructor only* can only be set by the constructor call,
|
|
|
111
114
|
|
|
112
115
|
options = {<br>
|
|
113
116
|
  [alphaBars](#alphabars-boolean): **false**,<br>
|
|
117
|
+
  [ansiBands](#ansibands-boolean): **false**,<br>
|
|
114
118
|
  [audioCtx](#audioctx-audiocontext-object): *undefined*, // constructor only<br>
|
|
115
119
|
  [barSpace](#barspace-number): **0.1**,<br>
|
|
116
120
|
  [bgAlpha](#bgalpha-number): **0.7**,<br>
|
|
@@ -121,6 +125,7 @@ options = {<br>
|
|
|
121
125
|
  [gradient](#gradient-string): **'classic'**,<br>
|
|
122
126
|
  [height](#height-number): *undefined*,<br>
|
|
123
127
|
  [ledBars](#ledbars-boolean): **false**,<br>
|
|
128
|
+
  [linearAmplitude](#linearamplitude-boolean): **false**,<br>
|
|
124
129
|
  [lineWidth](#linewidth-number): **0**,<br>
|
|
125
130
|
  [loRes](#lores-boolean): **false**,<br>
|
|
126
131
|
  [lumiBars](#lumibars-boolean): **false**,<br>
|
|
@@ -130,6 +135,7 @@ options = {<br>
|
|
|
130
135
|
  [minFreq](#minfreq-number): **20**,<br>
|
|
131
136
|
  [mirror](#mirror-number): **0**,<br>
|
|
132
137
|
  [mode](#mode-number): **0**,<br>
|
|
138
|
+
  [noteLabels](#notelabels-boolean): **false**,<br>
|
|
133
139
|
  [onCanvasDraw](#oncanvasdraw-function): *undefined*,<br>
|
|
134
140
|
  [onCanvasResize](#oncanvasresize-function): *undefined*,<br>
|
|
135
141
|
  [outlineBars](#outlinebars-boolean): **false**,<br>
|
|
@@ -141,7 +147,6 @@ options = {<br>
|
|
|
141
147
|
  [reflexRatio](#reflexratio-number): **0**,<br>
|
|
142
148
|
  [showBgColor](#showbgcolor-boolean): **true**,<br>
|
|
143
149
|
  [showFPS](#showfps-boolean): **false**,<br>
|
|
144
|
-
  [showLeds](#showleds-deprecated): **false**, // DEPRECATED - use ledBars instead<br>
|
|
145
150
|
  [showPeaks](#showpeaks-boolean): **true**,<br>
|
|
146
151
|
  [showScaleX](#showscalex-boolean): **true**,<br>
|
|
147
152
|
  [showScaleY](#showscaley-boolean): **false**,<br>
|
|
@@ -153,6 +158,7 @@ options = {<br>
|
|
|
153
158
|
  [stereo](#stereo-boolean): **false**,<br>
|
|
154
159
|
  [useCanvas](#usecanvas-boolean): **true**,<br>
|
|
155
160
|
  [volume](#volume-number): **1**,<br>
|
|
161
|
+
  [weightingFilter](#weightingFilter-string): **''**<br>
|
|
156
162
|
  [width](#width-number): *undefined*<br>
|
|
157
163
|
}
|
|
158
164
|
|
|
@@ -186,10 +192,10 @@ only one of them needs to be connected to the speakers, otherwise the volume wil
|
|
|
186
192
|
|
|
187
193
|
After instantiation, use [`connectOutput()`](#connectoutput-node-) and [`disconnectOutput()`](#disconnectoutput-node-) to connect or disconnect the output from the speakers (or other nodes).
|
|
188
194
|
|
|
189
|
-
Defaults to **true**.
|
|
190
|
-
|
|
191
195
|
See also [`connectedTo`](#connectedto-array-read-only).
|
|
192
196
|
|
|
197
|
+
Defaults to **true**.
|
|
198
|
+
|
|
193
199
|
#### `fsElement` *HTMLElement object*
|
|
194
200
|
|
|
195
201
|
*Available since v3.4.0*
|
|
@@ -232,6 +238,18 @@ Defaults to **false**.
|
|
|
232
238
|
|
|
233
239
|
!> [See related known issue](#alphabars-and-fillalpha-wont-work-with-radial-on-firefox)
|
|
234
240
|
|
|
241
|
+
### `ansiBands` *boolean*
|
|
242
|
+
|
|
243
|
+
*Available since v4.0.0*
|
|
244
|
+
|
|
245
|
+
When set to *true* uses ANSI/IEC preferred frequencies to generate the bands for [octave bands modes](#mode-number).
|
|
246
|
+
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).
|
|
247
|
+
|
|
248
|
+
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
|
|
249
|
+
the center of each band is perfectly tuned to a musical note.
|
|
250
|
+
|
|
251
|
+
Defaults to **false**.
|
|
252
|
+
|
|
235
253
|
### `audioCtx` *AudioContext object* *(Read only)*
|
|
236
254
|
|
|
237
255
|
[*AudioContext*](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) used by **audioMotion-analyzer**.
|
|
@@ -310,10 +328,6 @@ By default, **audioMotion-analyzer** is connected to the *AudioContext* `destina
|
|
|
310
328
|
|
|
311
329
|
See also [`connectOutput()`](#connectoutput-node-).
|
|
312
330
|
|
|
313
|
-
### `energy` **(DEPRECATED)**
|
|
314
|
-
|
|
315
|
-
**This property will be removed in version 4.0.0** - Use [`getEnergy()`](#getenergy-preset-startfreq-endfreq-) instead.
|
|
316
|
-
|
|
317
331
|
### `fftSize` *number*
|
|
318
332
|
|
|
319
333
|
Number of samples used for the FFT performed by the [*AnalyzerNode*](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode).
|
|
@@ -396,10 +410,6 @@ See [`toggleFullscreen()`](#togglefullscreen).
|
|
|
396
410
|
|
|
397
411
|
***true*** when LED bars are effectively being displayed, i.e., [`ledBars`](#ledBars-boolean) is set to *true* and [`mode`](#mode-number) is set to an octave bands mode and [`radial`](#radial-boolean) is *false*.
|
|
398
412
|
|
|
399
|
-
### `isLedDisplay` **(DEPRECATED)**
|
|
400
|
-
|
|
401
|
-
**This property will be removed in version 4.0.0** - Use [`isLedBars`](#isledbars-boolean-read-only) instead.
|
|
402
|
-
|
|
403
413
|
### `isLumiBars` *boolean* *(Read only)*
|
|
404
414
|
|
|
405
415
|
*Available since v3.0.0*
|
|
@@ -437,6 +447,28 @@ For effect priority when combined with other settings, see [`isLedBars`](#isledb
|
|
|
437
447
|
|
|
438
448
|
Defaults to **false**.
|
|
439
449
|
|
|
450
|
+
### `linearAmplitude` *boolean*
|
|
451
|
+
|
|
452
|
+
*Available since v4.0.0*
|
|
453
|
+
|
|
454
|
+
When set to *true*, spectrum amplitudes are represented in linear scale instead of decibels (logarithmic).
|
|
455
|
+
|
|
456
|
+
This may improve the visualization of predominant tones, especially at higher frequencies, but it will make the entire spectrum look much quieter.
|
|
457
|
+
|
|
458
|
+
See also [`linearBoost`](#linearboost-number).
|
|
459
|
+
|
|
460
|
+
Defaults to **false**.
|
|
461
|
+
|
|
462
|
+
### `linearBoost` *number*
|
|
463
|
+
|
|
464
|
+
*Available since v4.0.0*
|
|
465
|
+
|
|
466
|
+
Performs an *n*th-root to amplify low energy values when using linear scale for the amplitude.
|
|
467
|
+
|
|
468
|
+
It should be a number >= 1, while 1 means no boosting. Only effective when [`linearAmplitude`](#linearamplitude-boolean) is set to *true*.
|
|
469
|
+
|
|
470
|
+
Defaults to **1**.
|
|
471
|
+
|
|
440
472
|
### `lineWidth` *number*
|
|
441
473
|
|
|
442
474
|
*Available since v2.0.0*
|
|
@@ -496,7 +528,8 @@ Highest and lowest frequencies represented in the X-axis of the analyzer. Values
|
|
|
496
528
|
|
|
497
529
|
The minimum allowed value is **1**. Trying to set a lower value will throw an `ERR_FREQUENCY_TOO_LOW` [error](#custom-errors).
|
|
498
530
|
|
|
499
|
-
The maximum
|
|
531
|
+
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).
|
|
532
|
+
Values higher than that will be capped.
|
|
500
533
|
|
|
501
534
|
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.
|
|
502
535
|
|
|
@@ -542,6 +575,16 @@ mode | description | notes
|
|
|
542
575
|
|
|
543
576
|
Defaults to **0**.
|
|
544
577
|
|
|
578
|
+
### `noteLabels` *boolean*
|
|
579
|
+
|
|
580
|
+
*Available since v4.0.0*
|
|
581
|
+
|
|
582
|
+
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*).
|
|
583
|
+
|
|
584
|
+
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.
|
|
585
|
+
|
|
586
|
+
Defaults to **false**.
|
|
587
|
+
|
|
545
588
|
### `outlineBars` *boolean*
|
|
546
589
|
|
|
547
590
|
*Available since v3.6.0*
|
|
@@ -564,27 +607,25 @@ Defaults to **false**.
|
|
|
564
607
|
|
|
565
608
|
?> In order to keep elements other than the canvas visible in fullscreen, you'll need to set the [`fsElement`](#fselement-htmlelement-object) property in the [constructor](#constructor) options.
|
|
566
609
|
|
|
567
|
-
### `peakEnergy` **(DEPRECATED)**
|
|
568
|
-
|
|
569
|
-
**This property will be removed in version 4.0.0** - Use [`getEnergy('peak')`](#getenergy-preset-startfreq-endfreq-) instead.
|
|
570
|
-
|
|
571
610
|
### `pixelRatio` *number* *(Read only)*
|
|
572
611
|
|
|
573
612
|
Current [devicePixelRatio](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio).
|
|
574
613
|
This is usually **1** for standard displays and **2** for retina / Hi-DPI screens.
|
|
575
614
|
|
|
576
|
-
|
|
615
|
+
When [`loRes`](#lores-boolean) is *true*, the value of `pixelRatio` is halved, i.e. **0.5** for standard displays and **1** for retina / Hi-DPI.
|
|
577
616
|
|
|
578
|
-
|
|
617
|
+
You can refer to this value to adjust any additional drawings done in the canvas (via [callback function](#oncanvasdraw-function)).
|
|
579
618
|
|
|
580
619
|
### `radial` *boolean*
|
|
581
620
|
|
|
582
621
|
*Available since v2.4.0*
|
|
583
622
|
|
|
584
|
-
When *true*, the spectrum analyzer is rendered
|
|
623
|
+
When *true*, the spectrum analyzer is rendered in a circular shape, with radial frequency bars spreading from its center.
|
|
585
624
|
|
|
586
|
-
|
|
587
|
-
|
|
625
|
+
In radial visualization, [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) effects are disabled, and
|
|
626
|
+
[`showPeaks`](#showpeaks-boolean) has no effect for [**Graph** mode](#mode-number).
|
|
627
|
+
|
|
628
|
+
When [`stereo`](#stereo-boolean) is *true*, a larger diameter is used and the right channel bars are rendered towards the center of the analyzer.
|
|
588
629
|
|
|
589
630
|
See also [`spinSpeed`](#spinspeed-number).
|
|
590
631
|
|
|
@@ -654,30 +695,35 @@ and setting `showBgColor` to ***true*** will make the "unlit" LEDs visible inste
|
|
|
654
695
|
|
|
655
696
|
*true* to display the current frame rate. Defaults to **false**.
|
|
656
697
|
|
|
657
|
-
### `showLeds` **(DEPRECATED)**
|
|
658
|
-
|
|
659
|
-
**This property will be removed in version 4.0.0** - Use [`ledBars`](#ledbars-boolean) instead.
|
|
660
|
-
|
|
661
698
|
### `showPeaks` *boolean*
|
|
662
699
|
|
|
663
700
|
*true* to show amplitude peaks for each frequency. Defaults to **true**.
|
|
664
701
|
|
|
665
702
|
### `showScaleX` *boolean*
|
|
666
703
|
|
|
667
|
-
*Available since v3.0.0*
|
|
704
|
+
*Available since v3.0.0 - this property was named `showScale` in earlier versions*
|
|
705
|
+
|
|
706
|
+
*true* to display scale labels on the X axis.
|
|
668
707
|
|
|
669
|
-
|
|
708
|
+
See also [`noteLabels`](#notelabels-boolean).
|
|
670
709
|
|
|
671
|
-
|
|
710
|
+
Defaults to **true**.
|
|
672
711
|
|
|
673
712
|
### `showScaleY` *boolean*
|
|
674
713
|
|
|
675
714
|
*Available since v2.4.0*
|
|
676
715
|
|
|
677
|
-
*true* to display the level
|
|
716
|
+
*true* to display the level/amplitude scale on the Y axis.
|
|
678
717
|
|
|
679
718
|
This option has no effect when [`radial`](#radial-boolean) or [`lumiBars`](#lumibars-boolean) are set to *true*.
|
|
680
719
|
|
|
720
|
+
When [`linearAmplitude`](#linearamplitude-boolean) is set to *false* (default), labels are shown in decibels (dB);
|
|
721
|
+
otherwise, values represent a percentage (0-100%) of the maximum amplitude.
|
|
722
|
+
|
|
723
|
+
See also [`minDecibels`](#mindecibels-number) and [`maxDecibels`](#maxdecibels-number).
|
|
724
|
+
|
|
725
|
+
Defaults to **false**.
|
|
726
|
+
|
|
681
727
|
### `smoothing` *number*
|
|
682
728
|
|
|
683
729
|
Sets the analyzer's [smoothingTimeConstant](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant).
|
|
@@ -752,6 +798,30 @@ Please note that changing the audio element volume directly will affect the ampl
|
|
|
752
798
|
|
|
753
799
|
Defaults to **1**.
|
|
754
800
|
|
|
801
|
+
### `weightingFilter` *string*
|
|
802
|
+
|
|
803
|
+
*Available since v4.0.0*
|
|
804
|
+
|
|
805
|
+
Select a [weighting filter](https://en.wikipedia.org/wiki/Weighting_filter) for spectrum visualization.
|
|
806
|
+
|
|
807
|
+
Each filter applies a different curve of gain/attenuation to specific frequency ranges, but the general idea is to adjust the
|
|
808
|
+
visualization of frequencies to which the human ear is more or less sensitive.
|
|
809
|
+
Refer to the [weighting filters viewer tool](/tools/weighting-filters.html) for curves and response tables.
|
|
810
|
+
|
|
811
|
+
?> Selecting a weighting filter **does NOT** affect the audio output, only the visualization.
|
|
812
|
+
|
|
813
|
+
weightingFilter | description
|
|
814
|
+
------|------------------------------
|
|
815
|
+
'' (empty string) | No weighting applied (default)
|
|
816
|
+
'A' | A-weighting
|
|
817
|
+
'B' | B-weighting
|
|
818
|
+
'C' | C-weighting
|
|
819
|
+
'D' | D-weighting
|
|
820
|
+
'468' | ITU-R 468 weighting
|
|
821
|
+
|
|
822
|
+
Defaults to **''**.
|
|
823
|
+
|
|
824
|
+
|
|
755
825
|
## Static properties
|
|
756
826
|
|
|
757
827
|
### `AudioMotionAnalyzer.version` *string* *(Read only)*
|
|
@@ -894,8 +964,9 @@ Returns an array with current data for each analyzer bar. Each array element is
|
|
|
894
964
|
```js
|
|
895
965
|
{
|
|
896
966
|
posX: <number>, // horizontal position of this bar on the canvas
|
|
897
|
-
|
|
898
|
-
|
|
967
|
+
freq: <number>, // center frequency for this bar (added in v4.0.0)
|
|
968
|
+
freqLo: <number>, // lower edge frequency
|
|
969
|
+
freqHi: <number>, // upper edge frequency
|
|
899
970
|
peak: <array>, // peak values for left and right channels
|
|
900
971
|
hold: <array>, // peak hold frames for left and right channels - values < 0 mean the peak is falling down
|
|
901
972
|
value: <array> // current amplitude on left and right channels
|
|
@@ -910,7 +981,7 @@ Please note that `hold` and `value` will have only one element when [`stereo`](#
|
|
|
910
981
|
|
|
911
982
|
You can use this method to create your own visualizations using the analyzer data. See [this pen](https://codepen.io/hvianna/pen/ZEKWWJb) for usage example.
|
|
912
983
|
|
|
913
|
-
### `getEnergy( [preset | startFreq
|
|
984
|
+
### `getEnergy( [preset | startFreq [, endFreq] ] )`
|
|
914
985
|
|
|
915
986
|
*Available since v3.2.0*
|
|
916
987
|
|
|
@@ -975,11 +1046,13 @@ Sets the analyzer nominal dimensions in pixels. See [`height`](#height-number) a
|
|
|
975
1046
|
|
|
976
1047
|
Sets the desired frequency range. Values are expressed in Hz (Hertz).
|
|
977
1048
|
|
|
1049
|
+
See [`minFreq` and `maxFreq`](#minfreq-number) for lower and upper limit values.
|
|
1050
|
+
|
|
978
1051
|
### `setLedParams( [params] )`
|
|
979
1052
|
|
|
980
1053
|
*Available since v3.2.0*
|
|
981
1054
|
|
|
982
|
-
Customize parameters used to create the [
|
|
1055
|
+
Customize parameters used to create the [`ledBars`](#ledbars-boolean) effect.
|
|
983
1056
|
|
|
984
1057
|
`params` should be an object with the following structure:
|
|
985
1058
|
|
|
@@ -993,16 +1066,16 @@ const params = {
|
|
|
993
1066
|
|
|
994
1067
|
property | description
|
|
995
1068
|
----------|-------------
|
|
996
|
-
`maxLeds` | maximum desired number of LED elements per analyzer bar
|
|
1069
|
+
`maxLeds` | **maximum** desired number of LED elements per analyzer bar
|
|
997
1070
|
`spaceV` | vertical spacing ratio, relative to the LED height (**1** means spacing is the same as the LED height)
|
|
998
|
-
`spaceH` | **minimum** horizontal spacing ratio, relative to the available width
|
|
1071
|
+
`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.
|
|
999
1072
|
|
|
1000
1073
|
The available canvas height is initially divided by `maxLeds` and vertical spacing is calculated observing the `spaceV` ratio;
|
|
1001
1074
|
if necessary, the led count is decreased until both the led segment and the vertical spacing are at least 2px tall.
|
|
1002
1075
|
|
|
1003
1076
|
You can try different values in the [fluid demo](https://audiomotion.dev/demo/fluid.html).
|
|
1004
1077
|
|
|
1005
|
-
**If called with no arguments or any invalid property,
|
|
1078
|
+
**If called with no arguments or any invalid property, clears custom parameters previously set.**
|
|
1006
1079
|
|
|
1007
1080
|
### `setOptions( [options] )`
|
|
1008
1081
|
|
|
@@ -1061,12 +1134,12 @@ ERR_UNKNOWN_GRADIENT | User tried to [select a gradient](#gradient-string)
|
|
|
1061
1134
|
|
|
1062
1135
|
## Known Issues
|
|
1063
1136
|
|
|
1064
|
-
### reflexBright won't work on some browsers {docsify-ignore}
|
|
1137
|
+
### reflexBright won't work on some browsers <!-- {docsify-ignore} -->
|
|
1065
1138
|
|
|
1066
1139
|
[`reflexBright`](#reflexbright-number) feature relies on the [`filter`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/filter) property of the Canvas API,
|
|
1067
1140
|
which is [currently not supported in some browsers](https://caniuse.com/#feat=mdn-api_canvasrenderingcontext2d_filter) (notably, Opera and Safari).
|
|
1068
1141
|
|
|
1069
|
-
### alphaBars and fillAlpha won't work with Radial on Firefox {docsify-ignore}
|
|
1142
|
+
### alphaBars and fillAlpha won't work with Radial on Firefox <!-- {docsify-ignore} -->
|
|
1070
1143
|
|
|
1071
1144
|
On Firefox, [`alphaBars`](#alphaBars-boolean) and [`fillAlpha`](#fillalpha-number) won't work with [`radial`](#radial-boolean) visualization when using hardware acceleration, due to [this bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1164912).
|
|
1072
1145
|
|
|
@@ -1075,10 +1148,75 @@ On Firefox, [`alphaBars`](#alphaBars-boolean) and [`fillAlpha`](#fillalpha-numbe
|
|
|
1075
1148
|
Safari's implementation of Web Audio won't return analyzer data for live streams, as documented in [this bug report](https://bugs.webkit.org/show_bug.cgi?id=195043).
|
|
1076
1149
|
|
|
1077
1150
|
|
|
1151
|
+
## Troubleshooting
|
|
1152
|
+
|
|
1153
|
+
Common problems and solutions. Remember to check the browser console for error messages.
|
|
1154
|
+
|
|
1155
|
+
### Error message: `Cannot use import statement outside a module` <!-- {docsify-ignore} -->
|
|
1156
|
+
|
|
1157
|
+
The `import` statement must be inside a `script` which has the `type="module"` property (and no `type="text/javascript"`), like so:
|
|
1158
|
+
|
|
1159
|
+
```html
|
|
1160
|
+
<script type="module">
|
|
1161
|
+
import AudioMotionAnalyzer from 'https://cdn.skypack.dev/audiomotion-analyzer?min';
|
|
1162
|
+
|
|
1163
|
+
// your code here
|
|
1164
|
+
</script>
|
|
1165
|
+
```
|
|
1166
|
+
|
|
1167
|
+
Or
|
|
1168
|
+
|
|
1169
|
+
```html
|
|
1170
|
+
<script src="main.js" type="module"></script>
|
|
1171
|
+
```
|
|
1172
|
+
|
|
1173
|
+
### Error message: `MediaElementAudioSource outputs zeroes due to CORS access restrictions` <!-- {docsify-ignore} -->
|
|
1174
|
+
|
|
1175
|
+
Make sure the media element (`audio` or `video` tag) connected to **audioMotion-analyzer** has the `crossorigin = "anonymous"` property, like so:
|
|
1176
|
+
|
|
1177
|
+
```html
|
|
1178
|
+
<audio id="myAudio" src="https://example.com/stream" controls crossorigin="anonymous"></audio>
|
|
1179
|
+
```
|
|
1180
|
+
|
|
1181
|
+
You can also set the `crossOrigin` (mind the uppercase "O") property via JavaScript, like so:
|
|
1182
|
+
|
|
1183
|
+
```js
|
|
1184
|
+
myAudio.crossOrigin = 'anonymous';
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1187
|
+
### Sound only plays after the user clicks somewhere on the page. <!-- {docsify-ignore} -->
|
|
1188
|
+
|
|
1189
|
+
**audioMotion-analyzer** automatically unlocks the audio context on the first click on the page,
|
|
1190
|
+
since browsers' autoplay policy requires audio output to be initiated on user gesture only.
|
|
1191
|
+
|
|
1192
|
+
However, if you're using an `audio` or `video` element with the `controls` property, clicks on those native media
|
|
1193
|
+
controls can't be detected, so the audio will only be enabled if/when the user clicks somewhere else.
|
|
1194
|
+
|
|
1195
|
+
Two possible solutions: **1)** make **sure** your users have to click somewhere else before using the media controls,
|
|
1196
|
+
like a "power on" button, or simply clicking to select a song from a list will do; or **2)** don't use the native
|
|
1197
|
+
controls at all, and create your own custom 'Play' and 'Stop' buttons. A very simple example:
|
|
1198
|
+
|
|
1199
|
+
```html
|
|
1200
|
+
<audio id="myAudio" src="track.mp3" crossorigin="anonymous"></audio> <!-- do not add the 'controls' property! -->
|
|
1201
|
+
|
|
1202
|
+
<button id="play"> Play </button>
|
|
1203
|
+
<button id="stop"> Stop </button>
|
|
1204
|
+
```
|
|
1205
|
+
|
|
1206
|
+
```js
|
|
1207
|
+
const myAudio = document.getElementById('audio');
|
|
1208
|
+
|
|
1209
|
+
document.getElementById('play').addEventListener( 'click', () => myAudio.play() );
|
|
1210
|
+
document.getElementById('stop').addEventListener( 'click', () => myAudio.pause() );
|
|
1211
|
+
```
|
|
1212
|
+
|
|
1213
|
+
|
|
1078
1214
|
## References and acknowledgments
|
|
1079
1215
|
|
|
1216
|
+
* Thanks to my wife, Virginia, for her never-ending love and support! 💞
|
|
1080
1217
|
* Thanks to [Yuji Koike](http://www.ykcircus.com) for his awesome [Soniq Viewer for iOS](https://itunes.apple.com/us/app/soniq-viewer/id448343005), which inspired me to create **audioMotion**
|
|
1081
1218
|
* [HTML Canvas Reference @W3Schools](https://www.w3schools.com/tags/ref_canvas.asp)
|
|
1219
|
+
* [Web Audio API specification](https://webaudio.github.io/web-audio-api/)
|
|
1082
1220
|
* [Web Audio API documentation @MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API)
|
|
1083
1221
|
* [What does the FFT data in the Web Audio API correspond to?](https://stackoverflow.com/a/14789992/2370385)
|
|
1084
1222
|
* [Equations for equal-tempered scale frequencies](http://pages.mtu.edu/~suits/NoteFreqCalcs.html)
|
|
@@ -1107,5 +1245,5 @@ And if you're feeling generous, maybe:
|
|
|
1107
1245
|
|
|
1108
1246
|
## License
|
|
1109
1247
|
|
|
1110
|
-
audioMotion-analyzer copyright (c) 2018-
|
|
1248
|
+
audioMotion-analyzer copyright (c) 2018-2022 [Henrique Avila Vianna](https://henriquevianna.com)<br>
|
|
1111
1249
|
Licensed under the [GNU Affero General Public License, version 3 or later](https://www.gnu.org/licenses/agpl.html).
|
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
|
+
"version": "4.0.0-beta.1",
|
|
5
5
|
"main": "./src/audioMotion-analyzer.js",
|
|
6
6
|
"module": "./src/audioMotion-analyzer.js",
|
|
7
7
|
"types": "./src/index.d.ts",
|