audiomotion-analyzer 3.5.1 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -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), but I later decided to make just
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 based on the equal tempered scale
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!
@@ -45,12 +45,14 @@ What users are saying:
45
45
  ## Live code examples
46
46
 
47
47
  - [Quick and easy spectrum analyzer](https://codepen.io/hvianna/pen/pobMLNL)
48
- - [Complete visualization options](https://codepen.io/hvianna/pen/LYREBYQ)
49
48
  - [Using microphone input](https://codepen.io/hvianna/pen/VwKZgEE)
50
- - [Custom callback function](https://codepen.io/hvianna/pen/LYZwdvG)
51
49
  - [Creating additional effects with `getEnergy()`](https://codepen.io/hvianna/pen/poNmVYo)
52
50
  - [No canvas example](https://codepen.io/hvianna/pen/ZEKWWJb) (create your own visualization using analyzer data)
53
- - [Integration with Pizzicato library](https://codesandbox.io/s/9y6qb) - see [this discussion](https://github.com/hvianna/audioMotion-analyzer/issues/10) for more info
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)
55
+ - [See more code examples on CodePen](https://codepen.io/collection/ABbbKr)
54
56
 
55
57
  ## Usage
56
58
 
@@ -72,7 +74,7 @@ Or download the [latest version](https://github.com/hvianna/audioMotion-analyzer
72
74
  Install as a dependency:
73
75
 
74
76
  ```console
75
- $ npm i --save audiomotion-analyzer
77
+ $ npm i audiomotion-analyzer
76
78
  ```
77
79
 
78
80
  Use ES6 import syntax:
@@ -111,6 +113,8 @@ Valid properties and default values are shown below.
111
113
  Properties marked as *constructor only* can only be set by the constructor call, the others can also be set anytime via [`setOptions()`](#setoptions-options-) method.
112
114
 
113
115
  options = {<br>
116
+ &emsp;&emsp;[alphaBars](#alphabars-boolean): **false**,<br>
117
+ &emsp;&emsp;[ansiBands](#ansibands-boolean): **false**,<br>
114
118
  &emsp;&emsp;[audioCtx](#audioctx-audiocontext-object): *undefined*, // constructor only<br>
115
119
  &emsp;&emsp;[barSpace](#barspace-number): **0.1**,<br>
116
120
  &emsp;&emsp;[bgAlpha](#bgalpha-number): **0.7**,<br>
@@ -120,6 +124,8 @@ options = {<br>
120
124
  &emsp;&emsp;[fsElement](#fselement-htmlelement-object): *undefined*, // constructor only<br>
121
125
  &emsp;&emsp;[gradient](#gradient-string): **'classic'**,<br>
122
126
  &emsp;&emsp;[height](#height-number): *undefined*,<br>
127
+ &emsp;&emsp;[ledBars](#ledbars-boolean): **false**,<br>
128
+ &emsp;&emsp;[linearAmplitude](#linearamplitude-boolean): **false**,<br>
123
129
  &emsp;&emsp;[lineWidth](#linewidth-number): **0**,<br>
124
130
  &emsp;&emsp;[loRes](#lores-boolean): **false**,<br>
125
131
  &emsp;&emsp;[lumiBars](#lumibars-boolean): **false**,<br>
@@ -129,8 +135,10 @@ options = {<br>
129
135
  &emsp;&emsp;[minFreq](#minfreq-number): **20**,<br>
130
136
  &emsp;&emsp;[mirror](#mirror-number): **0**,<br>
131
137
  &emsp;&emsp;[mode](#mode-number): **0**,<br>
138
+ &emsp;&emsp;[noteLabels](#notelabels-boolean): **false**,<br>
132
139
  &emsp;&emsp;[onCanvasDraw](#oncanvasdraw-function): *undefined*,<br>
133
140
  &emsp;&emsp;[onCanvasResize](#oncanvasresize-function): *undefined*,<br>
141
+ &emsp;&emsp;[outlineBars](#outlinebars-boolean): **false**,<br>
134
142
  &emsp;&emsp;[overlay](#overlay-boolean): **false**,<br>
135
143
  &emsp;&emsp;[radial](#radial-boolean): **false**,<br>
136
144
  &emsp;&emsp;[reflexAlpha](#reflexalpha-number): **0.15**,<br>
@@ -139,7 +147,6 @@ options = {<br>
139
147
  &emsp;&emsp;[reflexRatio](#reflexratio-number): **0**,<br>
140
148
  &emsp;&emsp;[showBgColor](#showbgcolor-boolean): **true**,<br>
141
149
  &emsp;&emsp;[showFPS](#showfps-boolean): **false**,<br>
142
- &emsp;&emsp;[showLeds](#showleds-boolean): **false**,<br>
143
150
  &emsp;&emsp;[showPeaks](#showpeaks-boolean): **true**,<br>
144
151
  &emsp;&emsp;[showScaleX](#showscalex-boolean): **true**,<br>
145
152
  &emsp;&emsp;[showScaleY](#showscaley-boolean): **false**,<br>
@@ -184,10 +191,10 @@ only one of them needs to be connected to the speakers, otherwise the volume wil
184
191
 
185
192
  After instantiation, use [`connectOutput()`](#connectoutput-node-) and [`disconnectOutput()`](#disconnectoutput-node-) to connect or disconnect the output from the speakers (or other nodes).
186
193
 
187
- Defaults to **true**.
188
-
189
194
  See also [`connectedTo`](#connectedto-array-read-only).
190
195
 
196
+ Defaults to **true**.
197
+
191
198
  #### `fsElement` *HTMLElement object*
192
199
 
193
200
  *Available since v3.4.0*
@@ -216,6 +223,32 @@ Defaults to **true**, so the analyzer will start running right after initializat
216
223
 
217
224
  ## Properties
218
225
 
226
+ ### `alphaBars` *boolean*
227
+
228
+ *Available since v3.6.0*
229
+
230
+ When set to *true* each bar's amplitude affects its opacity, i.e., higher bars are rendered more opaque while shorter bars are more transparent.
231
+
232
+ This is similar to the [`lumiBars`](#lumibars-boolean) effect, but bars' amplitudes are preserved and it also works on **Discrete** [mode](#mode-number) and [radial](#radial-boolean) visualization.
233
+
234
+ For effect priority when combined with other settings, see [`isAlphaBars`](#isalphabars-boolean-read-only).
235
+
236
+ Defaults to **false**.
237
+
238
+ !> [See related known issue](#alphabars-and-fillalpha-wont-work-with-radial-on-firefox)
239
+
240
+ ### `ansiBands` *boolean*
241
+
242
+ *Available since v4.0.0*
243
+
244
+ When set to *true* uses ANSI/IEC preferred frequencies to generate the bands for [octave bands modes](#mode-number).
245
+ 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).
246
+
247
+ 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
248
+ the center of each band is perfectly tuned to a musical note.
249
+
250
+ Defaults to **false**.
251
+
219
252
  ### `audioCtx` *AudioContext object* *(Read only)*
220
253
 
221
254
  [*AudioContext*](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) used by **audioMotion-analyzer**.
@@ -247,7 +280,7 @@ See also the [fluid demo](/demo/fluid.html) and the [multi-instance demo](/demo/
247
280
 
248
281
  *Available since v2.0.0*
249
282
 
250
- Customize the spacing between bars in [octave bands modes](#mode-number).
283
+ Customize the spacing between bars in **octave bands** [modes](#mode-number).
251
284
 
252
285
  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.
253
286
 
@@ -255,7 +288,7 @@ For example, `barSpace = 0.5` will use half the width available to each band for
255
288
  On the other hand, `barSpace = 2` will set a fixed spacing of 2 pixels, independent of the width of bars.
256
289
  Prefer proportional spacing to obtain consistent results among different resolutions and screen sizes.
257
290
 
258
- `barSpace = 0` will effectively show contiguous bars, except when [`showLeds`](#showleds-boolean) is *true*, in which case a minimum spacing is enforced
291
+ `barSpace = 0` will effectively show contiguous bars, except when [`ledBars`](#ledbars-boolean) is *true*, in which case a minimum spacing is enforced
259
292
  (this can be customized via [`setLedParams()`](#setledparams-params-) method).
260
293
 
261
294
  Defaults to **0.1**.
@@ -294,12 +327,6 @@ By default, **audioMotion-analyzer** is connected to the *AudioContext* `destina
294
327
 
295
328
  See also [`connectOutput()`](#connectoutput-node-).
296
329
 
297
- ### `energy` **(DEPRECATED)**
298
-
299
- **This property will be removed in version 4.0.0**
300
-
301
- Use [`getEnergy()`](#getenergy-preset-startfreq-endfreq-) instead.
302
-
303
330
  ### `fftSize` *number*
304
331
 
305
332
  Number of samples used for the FFT performed by the [*AnalyzerNode*](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode).
@@ -313,15 +340,17 @@ Defaults to **8192**.
313
340
 
314
341
  *Available since v2.0.0*
315
342
 
316
- Opacity of the area fill in **Line / Area graph** visualization ([`mode`](#mode-number) 10).
343
+ Opacity of the area fill in **Graph** [mode](#mode-number), or inner fill of bars in **octave bands** modes when [`outlineBars`](#outlinebars-boolean) is *true*.
317
344
 
318
345
  It must be a number between 0 (completely transparent) and 1 (completely opaque).
319
346
 
320
- Please note that this affects only the area fill. The line (when [`lineWidth`](#linewidth-number) > 0) is always drawn at full opacity.
347
+ Please note that the line stroke (when [`lineWidth`](#linewidth-number) > 0) is always drawn at full opacity, regardless of the `fillAlpha` value.
348
+
349
+ Also, for octave bands modes, [`alphaBars`](#alphabars-boolean) set to *true* takes precedence over `fillAlpha`.
321
350
 
322
351
  Defaults to **1**.
323
352
 
324
- !> [See related known issue](#fillalpha-and-radial-mode-on-firefox)
353
+ !> [See related known issue](#alphabars-and-fillalpha-wont-work-with-radial-on-firefox)
325
354
 
326
355
  ### `fps` *number* *(Read only)*
327
356
 
@@ -355,47 +384,82 @@ Nominal dimensions of the analyzer.
355
384
 
356
385
  If one or both of these are `undefined`, the analyzer will try to adjust to the container's width and/or height.
357
386
  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).
358
- This should be considered the minimum dimensions for proper visualization of all available modes with the [LED effect](#showleds-boolean) on.
387
+ This should be considered the minimum dimensions for proper visualization of all available modes with the [LED effect](#ledbars-boolean) on.
359
388
 
360
389
  You can set both values at once using the [`setCanvasSize()`](#setcanvassize-width-height-) method.
361
390
 
362
391
  ?> You can read the actual canvas dimensions at any time directly from the [`canvas`](#canvas-htmlcanvaselement-object-read-only) object.
363
392
 
393
+ ### `isAlphaBars` *boolean* *(Read only)*
394
+
395
+ *Available since v3.6.0*
396
+
397
+ ***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 octave bands modes, in which case [`lumiBars`](#lumibars-boolean) must be set to *false* or [`radial`](#radial-boolean) must be set to *true*.
399
+
364
400
  ### `isFullscreen` *boolean* *(Read only)*
365
401
 
366
- *true* when the analyzer is being displayed in fullscreen, or *false* otherwise.
402
+ ***true*** when the analyzer is being displayed in fullscreen, or ***false*** otherwise.
367
403
 
368
404
  See [`toggleFullscreen()`](#togglefullscreen).
369
405
 
370
- ### `isLedDisplay` *boolean* *(Read only)*
406
+ ### `isLedBars` *boolean* *(Read only)*
371
407
 
372
- *Available since v3.0.0*
408
+ *Available since v3.6.0* (formerly `isLedDisplay`)
373
409
 
374
- *true* when the LED effect is effectively being displayed, i.e., [`showLeds`](#showleds-boolean) is set to *true* and [`mode`](#mode-number) is set to one of the octave bands modes and [`radial`](#radial-boolean) is *false*.
410
+ ***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*.
375
411
 
376
412
  ### `isLumiBars` *boolean* *(Read only)*
377
413
 
378
414
  *Available since v3.0.0*
379
415
 
380
- *true* when the luminance bars effect is effectively being displayed, i.e., [`lumiBars`](#lumibars-boolean) is set to *true* and [`mode`](#mode-number) is set to one of the octave bands modes and [`radial`](#radial-boolean) is *false*.
416
+ ***true*** when luminance bars are effectively being displayed, i.e., [`lumiBars`](#lumibars-boolean) is set to *true* and [`mode`](#mode-number) is set to an octave bands mode and [`radial`](#radial-boolean) is *false*.
381
417
 
382
418
  ### `isOctaveBands` *boolean* *(Read only)*
383
419
 
384
420
  *Available since v3.0.0*
385
421
 
386
- *true* when [`mode`](#mode-number) is set to one of the octave bands modes.
422
+ ***true*** when [`mode`](#mode-number) is set to one of the octave bands modes.
387
423
 
388
424
  ### `isOn` *boolean* *(Read only)*
389
425
 
390
- *true* if the analyzer process is running, or *false* if it's stopped.
426
+ ***true*** if the analyzer process is running, or *false* if it's stopped.
391
427
 
392
428
  See [`toggleAnalyzer()`](#toggleanalyzer-boolean-).
393
429
 
430
+ ### `isOutlineBars` *boolean* *(Read only)*
431
+
432
+ *Available since v3.6.0*
433
+
434
+ ***true*** when outlined bars are effectively being displayed, i.e., [`outlineBars`](#outlinebars-boolean) is set to *true*, [`mode`](#mode-number) is set to
435
+ one of the octave bands modes and both [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) are set to *false*, or [`radial`](#radial-boolean) is set to *true*.
436
+
437
+ ### `ledBars` *boolean*
438
+
439
+ *Available since v3.6.0* (formerly `showLeds`)
440
+
441
+ *true* to activate a vintage LEDs display effect. Only effective for **octave bands** [modes](#mode-number).
442
+
443
+ This effect can be customized via [`setLedParams()`](#setledparams-params-) method.
444
+
445
+ For effect priority when combined with other settings, see [`isLedBars`](#isledbars-boolean-read-only).
446
+
447
+ Defaults to **false**.
448
+
449
+ ### `linearAmplitude` *boolean*
450
+
451
+ *Available since v4.0.0*
452
+
453
+ When set to *true* uses linear values, instead of decibels, for displaying bars' amplitudes.
454
+ This may improve the visualization of predominant tones, especially at higher frequencies, but it will make the entire spectrum look much quieter.
455
+
456
+ Defaults to **false**.
457
+
394
458
  ### `lineWidth` *number*
395
459
 
396
460
  *Available since v2.0.0*
397
461
 
398
- Line width for the **Line / Area graph** visualization ([`mode`](#mode-number) 10).
462
+ Line width for **Graph** [mode](#mode-number), or outline stroke in **octave bands** modes when [`outlineBars`](#outlinebars-boolean) is *true*.
399
463
 
400
464
  For the line to be distinguishable, set also [`fillAlpha`](#fillalpha-number) < 1.
401
465
 
@@ -422,10 +486,14 @@ This will prevent the canvas size from changing, when switching the low resoluti
422
486
 
423
487
  *Available since v1.1.0*
424
488
 
425
- This is only effective for [visualization modes](#mode-number) 1 to 8 (octave bands).
489
+ This is only effective for **octave bands** [modes](#mode-number).
426
490
 
427
491
  When set to *true* all analyzer bars will be displayed at full height with varying luminance (opacity, actually) instead.
428
492
 
493
+ `lumiBars` takes precedence over [`alphaBars`](#alphabars-boolean) and [`outlineBars`](#outlinebars-boolean), except in [`radial`](#radial-boolean) visualization.
494
+
495
+ For effect priority when combined with other settings, see [`isLumiBars`](#islumibars-boolean-read-only).
496
+
429
497
  Defaults to **false**.
430
498
 
431
499
  ### `maxDecibels` *number*
@@ -472,9 +540,9 @@ Defaults to **0**.
472
540
 
473
541
  Current visualization mode.
474
542
 
475
- + **Discrete frequencies** mode provides the highest resolution, allowing you to visualize individual frequencies provided by the [FFT](https://en.wikipedia.org/wiki/Fast_Fourier_transform);
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;
476
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);
477
- + **Line / Area graph** mode uses the discrete frequencies data to draw a filled shape and/or a continuous line (see [`fillAlpha`](#fillalpha-number) and [`lineWidth`](#linewidth-number) properties).
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).
478
546
 
479
547
  mode | description | notes
480
548
  ------:|:-------------:|------
@@ -488,10 +556,30 @@ mode | description | notes
488
556
  7 | Half octave bands |
489
557
  8 | Full octave bands |
490
558
  9 | *(not valid)* | *reserved*
491
- 10 | Line / Area graph | *added in v1.1.0*
559
+ 10 | Graph | *added in v1.1.0*
492
560
 
493
561
  Defaults to **0**.
494
562
 
563
+ ### `noteLabels` *boolean*
564
+
565
+ *Available since v4.0.0*
566
+
567
+ 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
+
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.
570
+
571
+ Defaults to **false**.
572
+
573
+ ### `outlineBars` *boolean*
574
+
575
+ *Available since v3.6.0*
576
+
577
+ When *true* and [`mode`](#mode-number) is set to one of the **octave bands** modes, draws outlined bars with customizable [`fillAlpha`](#fillalpha-number) and [`lineWidth`](#linewidth-number).
578
+
579
+ For effect priority when combined with other settings, see [`isOutlineBars`](#isoutlinebars-boolean-read-only).
580
+
581
+ Defaults to **false**.
582
+
495
583
  ### `overlay` *boolean*
496
584
 
497
585
  *Available since v2.2.0*
@@ -504,35 +592,31 @@ Defaults to **false**.
504
592
 
505
593
  ?> 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.
506
594
 
507
- ### `peakEnergy` **(DEPRECATED)**
508
-
509
- **This property will be removed in version 4.0.0**
510
-
511
- Use [`getEnergy('peak')`](#getenergy-preset-startfreq-endfreq-) instead.
512
-
513
595
  ### `pixelRatio` *number* *(Read only)*
514
596
 
515
597
  Current [devicePixelRatio](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio).
516
598
  This is usually **1** for standard displays and **2** for retina / Hi-DPI screens.
517
599
 
518
- You can refer to this value to adjust any additional drawings done in the canvas (via [callback function](#oncanvasdraw-function)).
600
+ 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.
519
601
 
520
- When [`loRes`](#lores-boolean) is *true* `pixelRatio` is halved, i.e. **0.5** for standard displays and **1** for retina / Hi-DPI.
602
+ You can refer to this value to adjust any additional drawings done in the canvas (via [callback function](#oncanvasdraw-function)).
521
603
 
522
604
  ### `radial` *boolean*
523
605
 
524
606
  *Available since v2.4.0*
525
607
 
526
- When *true*, the spectrum analyzer is rendered as a circle, with radial frequency bars spreading from the center of the canvas.
608
+ When *true*, the spectrum analyzer is rendered in a circular shape, with radial frequency bars spreading from its center.
609
+
610
+ In radial visualization, [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) effects are disabled, and
611
+ [`showPeaks`](#showpeaks-boolean) has no effect for [**Graph** mode](#mode-number).
527
612
 
528
- When radial mode is active, [`lumiBars`](#lumibars-boolean) and [`showLeds`](#showleds-boolean) have no effect, and
529
- also [`showPeaks`](#showpeaks-boolean) has no effect in **Line / Area graph** mode.
613
+ When [`stereo`](#stereo-boolean) is *true*, a larger diameter is used and the right channel bars are rendered towards the center of the analyzer.
530
614
 
531
615
  See also [`spinSpeed`](#spinspeed-number).
532
616
 
533
617
  Defaults to **false**.
534
618
 
535
- !> [See related known issue](#fillalpha-and-radial-mode-on-firefox)
619
+ !> [See related known issue](#alphabars-and-fillalpha-wont-work-with-radial-on-firefox)
536
620
 
537
621
  ### `reflexAlpha` *number*
538
622
 
@@ -589,41 +673,42 @@ or transparent when [`overlay`](#overlay-boolean) is ***true***.
589
673
 
590
674
  Defaults to **true**.
591
675
 
592
- ?> Please note that when [`overlay`](#overlay-boolean) is ***false*** and [`showLeds`](#showleds-boolean) is ***true***, the background color will always be black,
676
+ ?> Please note that when [`overlay`](#overlay-boolean) is ***false*** and [`ledBars`](#ledbars-boolean) is ***true***, the background color will always be black,
593
677
  and setting `showBgColor` to ***true*** will make the "unlit" LEDs visible instead.
594
678
 
595
679
  ### `showFPS` *boolean*
596
680
 
597
681
  *true* to display the current frame rate. Defaults to **false**.
598
682
 
599
- ### `showLeds` *boolean*
600
-
601
- *true* to activate a vintage LEDs display effect. Only effective for [visualization modes](#mode-number) 1 to 8 (octave bands).
602
-
603
- This effect can be customized via [`setLedParams()`](#setledparams-params-) method.
604
-
605
- Defaults to **false**.
606
-
607
683
  ### `showPeaks` *boolean*
608
684
 
609
685
  *true* to show amplitude peaks for each frequency. Defaults to **true**.
610
686
 
611
687
  ### `showScaleX` *boolean*
612
688
 
613
- *Available since v3.0.0*
689
+ *Available since v3.0.0 - this property was named `showScale` in earlier versions*
614
690
 
615
- *true* to display the frequency (Hz) scale on the X axis. Defaults to **true**.
691
+ *true* to display scale labels on the X axis.
616
692
 
617
- *NOTE: this property was named `showScale` in versions prior to v3.0.0*
693
+ See also [`noteLabels`](#notelabels-boolean).
694
+
695
+ Defaults to **true**.
618
696
 
619
697
  ### `showScaleY` *boolean*
620
698
 
621
699
  *Available since v2.4.0*
622
700
 
623
- *true* to display the level (dB) scale on the Y axis. Defaults to **false**.
701
+ *true* to display the level/amplitude scale on the Y axis.
624
702
 
625
703
  This option has no effect when [`radial`](#radial-boolean) or [`lumiBars`](#lumibars-boolean) are set to *true*.
626
704
 
705
+ When [`linearAmplitude`](#linearamplitude-boolean) is set to *false* (default), labels are shown in decibels (dB);
706
+ otherwise, values represent a percentage (0-100%) of the maximum amplitude.
707
+
708
+ See also [`minDecibels`](#mindecibels-number) and [`maxDecibels`](#maxdecibels-number).
709
+
710
+ Defaults to **false**.
711
+
627
712
  ### `smoothing` *number*
628
713
 
629
714
  Sets the analyzer's [smoothingTimeConstant](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant).
@@ -856,7 +941,7 @@ Please note that `hold` and `value` will have only one element when [`stereo`](#
856
941
 
857
942
  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.
858
943
 
859
- ### `getEnergy( [preset | startFreq], [endFreq] )`
944
+ ### `getEnergy( [preset | startFreq [, endFreq] ] )`
860
945
 
861
946
  *Available since v3.2.0*
862
947
 
@@ -915,7 +1000,7 @@ Sets the desired frequency range. Values are expressed in Hz (Hertz).
915
1000
 
916
1001
  *Available since v3.2.0*
917
1002
 
918
- Customize parameters used to create the [LEDs display effect](#showleds-boolean).
1003
+ Customize parameters used to create the [LEDs display effect](#ledbars-boolean).
919
1004
 
920
1005
  `params` should be an object with the following structure:
921
1006
 
@@ -938,7 +1023,7 @@ if necessary, the led count is decreased until both the led segment and the vert
938
1023
 
939
1024
  You can try different values in the [fluid demo](https://audiomotion.dev/demo/fluid.html).
940
1025
 
941
- **If called with no arguments or any invalid property, disables previously set parameters.**
1026
+ **If called with no arguments or any invalid property, clears custom parameters previously set.**
942
1027
 
943
1028
  ### `setOptions( [options] )`
944
1029
 
@@ -997,24 +1082,89 @@ ERR_UNKNOWN_GRADIENT | User tried to [select a gradient](#gradient-string)
997
1082
 
998
1083
  ## Known Issues
999
1084
 
1000
- ### reflexBright won't work on some browsers {docsify-ignore}
1085
+ ### reflexBright won't work on some browsers <!-- {docsify-ignore} -->
1001
1086
 
1002
1087
  [`reflexBright`](#reflexbright-number) feature relies on the [`filter`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/filter) property of the Canvas API,
1003
1088
  which is [currently not supported in some browsers](https://caniuse.com/#feat=mdn-api_canvasrenderingcontext2d_filter) (notably, Opera and Safari).
1004
1089
 
1005
- ### fillAlpha and radial mode on Firefox {docsify-ignore}
1090
+ ### alphaBars and fillAlpha won't work with Radial on Firefox <!-- {docsify-ignore} -->
1006
1091
 
1007
- On Firefox, [`fillAlpha`](#fillalpha-number) may not work properly for [`radial`](#radial-boolean) visualization, due to [this bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1164912).
1092
+ 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).
1008
1093
 
1009
1094
  ### Visualization of live streams won't work on Safari {docsify-ignore}
1010
1095
 
1011
1096
  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).
1012
1097
 
1013
1098
 
1099
+ ## Troubleshooting
1100
+
1101
+ Common problems and solutions. Remember to check the browser console for error messages.
1102
+
1103
+ ### Error message: `Cannot use import statement outside a module` <!-- {docsify-ignore} -->
1104
+
1105
+ The `import` statement must be inside a `script` which has the `type="module"` property (and no `type="text/javascript"`), like so:
1106
+
1107
+ ```html
1108
+ <script type="module">
1109
+ import AudioMotionAnalyzer from 'https://cdn.skypack.dev/audiomotion-analyzer?min';
1110
+
1111
+ // your code here
1112
+ </script>
1113
+ ```
1114
+
1115
+ Or
1116
+
1117
+ ```html
1118
+ <script src="main.js" type="module"></script>
1119
+ ```
1120
+
1121
+ ### Error message: `MediaElementAudioSource outputs zeroes due to CORS access restrictions` <!-- {docsify-ignore} -->
1122
+
1123
+ Make sure the media element (`audio` or `video` tag) connected to **audioMotion-analyzer** has the `crossorigin = "anonymous"` property, like so:
1124
+
1125
+ ```html
1126
+ <audio id="myAudio" src="https://example.com/stream" controls crossorigin="anonymous"></audio>
1127
+ ```
1128
+
1129
+ You can also set the `crossOrigin` (mind the uppercase "O") property via JavaScript, like so:
1130
+
1131
+ ```js
1132
+ myAudio.crossOrigin = 'anonymous';
1133
+ ```
1134
+
1135
+ ### Sound only plays after the user clicks somewhere on the page. <!-- {docsify-ignore} -->
1136
+
1137
+ **audioMotion-analyzer** automatically unlocks the audio context on the first click on the page,
1138
+ since browsers' autoplay policy requires audio output to be initiated on user gesture only.
1139
+
1140
+ However, if you're using an `audio` or `video` element with the `controls` property, clicks on those native media
1141
+ controls can't be detected, so the audio will only be enabled if/when the user clicks somewhere else.
1142
+
1143
+ Two possible solutions: **1)** make **sure** your users have to click somewhere else before using the media controls,
1144
+ 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 'Play' and 'Stop' buttons. A very simple example:
1146
+
1147
+ ```html
1148
+ <audio id="myAudio" src="track.mp3" crossorigin="anonymous"></audio> <!-- do not add the 'controls' property! -->
1149
+
1150
+ <button id="play"> Play </button>
1151
+ <button id="stop"> Stop </button>
1152
+ ```
1153
+
1154
+ ```js
1155
+ const myAudio = document.getElementById('audio');
1156
+
1157
+ document.getElementById('play').addEventListener( 'click', () => myAudio.play() );
1158
+ document.getElementById('stop').addEventListener( 'click', () => myAudio.pause() );
1159
+ ```
1160
+
1161
+
1014
1162
  ## References and acknowledgments
1015
1163
 
1164
+ * Thanks to my wife, Virginia, for her never-ending love and support! 💞
1016
1165
  * 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**
1017
1166
  * [HTML Canvas Reference @W3Schools](https://www.w3schools.com/tags/ref_canvas.asp)
1167
+ * [Web Audio API specification](https://webaudio.github.io/web-audio-api/)
1018
1168
  * [Web Audio API documentation @MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API)
1019
1169
  * [What does the FFT data in the Web Audio API correspond to?](https://stackoverflow.com/a/14789992/2370385)
1020
1170
  * [Equations for equal-tempered scale frequencies](http://pages.mtu.edu/~suits/NoteFreqCalcs.html)
@@ -1030,16 +1180,18 @@ See [Changelog.md](Changelog.md)
1030
1180
 
1031
1181
  ## Get in touch!
1032
1182
 
1033
- If you create something cool with this project, or simply think it's useful, I would like to know! Please drop me an e-mail at hvianna@gmail.com
1183
+ If you create something cool with **audioMotion-analyzer**, or simply think it's useful, I would love to know! Please drop me an e-mail at hvianna@gmail.com
1034
1184
 
1035
- If you have a feature request or code suggestion, please see [CONTRIBUTING.md](CONTRIBUTING.md)
1185
+ For feature requests, suggestions or feedback, please see the [CONTRIBUTING.md](CONTRIBUTING.md) file.
1036
1186
 
1037
- And if you're feeling generous you can [buy me a coffee on Ko-fi](https://ko-fi.com/Q5Q6157GZ) :grin::coffee:
1187
+ And if you're feeling generous, maybe:
1038
1188
 
1039
- [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Q5Q6157GZ)
1189
+ * [Buy me a coffee](https://ko-fi.com/Q5Q6157GZ) on Ko-fi ☕😁
1190
+ * Gift me something from my [Bandcamp wishlist](https://bandcamp.com/henriquevianna/wishlist) 🎁🥰
1191
+ * Tip me via [Brave Rewards](https://brave.com/brave-rewards/) using Brave browser 🤓
1040
1192
 
1041
1193
 
1042
1194
  ## License
1043
1195
 
1044
- audioMotion-analyzer copyright (c) 2018-2021 [Henrique Avila Vianna](https://henriquevianna.com)<br>
1196
+ audioMotion-analyzer copyright (c) 2018-2022 [Henrique Avila Vianna](https://henriquevianna.com)<br>
1045
1197
  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": "3.5.1",
4
+ "version": "4.0.0-beta.0",
5
5
  "main": "./src/audioMotion-analyzer.js",
6
6
  "module": "./src/audioMotion-analyzer.js",
7
7
  "types": "./src/index.d.ts",