audiomotion-analyzer 3.6.0 → 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!
@@ -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
- - [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)
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 --save audiomotion-analyzer
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
  &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>
@@ -121,6 +125,7 @@ options = {<br>
121
125
  &emsp;&emsp;[gradient](#gradient-string): **'classic'**,<br>
122
126
  &emsp;&emsp;[height](#height-number): *undefined*,<br>
123
127
  &emsp;&emsp;[ledBars](#ledbars-boolean): **false**,<br>
128
+ &emsp;&emsp;[linearAmplitude](#linearamplitude-boolean): **false**,<br>
124
129
  &emsp;&emsp;[lineWidth](#linewidth-number): **0**,<br>
125
130
  &emsp;&emsp;[loRes](#lores-boolean): **false**,<br>
126
131
  &emsp;&emsp;[lumiBars](#lumibars-boolean): **false**,<br>
@@ -130,6 +135,7 @@ options = {<br>
130
135
  &emsp;&emsp;[minFreq](#minfreq-number): **20**,<br>
131
136
  &emsp;&emsp;[mirror](#mirror-number): **0**,<br>
132
137
  &emsp;&emsp;[mode](#mode-number): **0**,<br>
138
+ &emsp;&emsp;[noteLabels](#notelabels-boolean): **false**,<br>
133
139
  &emsp;&emsp;[onCanvasDraw](#oncanvasdraw-function): *undefined*,<br>
134
140
  &emsp;&emsp;[onCanvasResize](#oncanvasresize-function): *undefined*,<br>
135
141
  &emsp;&emsp;[outlineBars](#outlinebars-boolean): **false**,<br>
@@ -141,7 +147,6 @@ options = {<br>
141
147
  &emsp;&emsp;[reflexRatio](#reflexratio-number): **0**,<br>
142
148
  &emsp;&emsp;[showBgColor](#showbgcolor-boolean): **true**,<br>
143
149
  &emsp;&emsp;[showFPS](#showfps-boolean): **false**,<br>
144
- &emsp;&emsp;[showLeds](#showleds-deprecated): **false**, // DEPRECATED - use ledBars instead<br>
145
150
  &emsp;&emsp;[showPeaks](#showpeaks-boolean): **true**,<br>
146
151
  &emsp;&emsp;[showScaleX](#showscalex-boolean): **true**,<br>
147
152
  &emsp;&emsp;[showScaleY](#showscaley-boolean): **false**,<br>
@@ -186,10 +191,10 @@ only one of them needs to be connected to the speakers, otherwise the volume wil
186
191
 
187
192
  After instantiation, use [`connectOutput()`](#connectoutput-node-) and [`disconnectOutput()`](#disconnectoutput-node-) to connect or disconnect the output from the speakers (or other nodes).
188
193
 
189
- Defaults to **true**.
190
-
191
194
  See also [`connectedTo`](#connectedto-array-read-only).
192
195
 
196
+ Defaults to **true**.
197
+
193
198
  #### `fsElement` *HTMLElement object*
194
199
 
195
200
  *Available since v3.4.0*
@@ -232,6 +237,18 @@ Defaults to **false**.
232
237
 
233
238
  !> [See related known issue](#alphabars-and-fillalpha-wont-work-with-radial-on-firefox)
234
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
+
235
252
  ### `audioCtx` *AudioContext object* *(Read only)*
236
253
 
237
254
  [*AudioContext*](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) used by **audioMotion-analyzer**.
@@ -310,10 +327,6 @@ By default, **audioMotion-analyzer** is connected to the *AudioContext* `destina
310
327
 
311
328
  See also [`connectOutput()`](#connectoutput-node-).
312
329
 
313
- ### `energy` **(DEPRECATED)**
314
-
315
- **This property will be removed in version 4.0.0** - Use [`getEnergy()`](#getenergy-preset-startfreq-endfreq-) instead.
316
-
317
330
  ### `fftSize` *number*
318
331
 
319
332
  Number of samples used for the FFT performed by the [*AnalyzerNode*](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode).
@@ -396,10 +409,6 @@ See [`toggleFullscreen()`](#togglefullscreen).
396
409
 
397
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*.
398
411
 
399
- ### `isLedDisplay` **(DEPRECATED)**
400
-
401
- **This property will be removed in version 4.0.0** - Use [`isLedBars`](#isledbars-boolean-read-only) instead.
402
-
403
412
  ### `isLumiBars` *boolean* *(Read only)*
404
413
 
405
414
  *Available since v3.0.0*
@@ -437,6 +446,15 @@ For effect priority when combined with other settings, see [`isLedBars`](#isledb
437
446
 
438
447
  Defaults to **false**.
439
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
+
440
458
  ### `lineWidth` *number*
441
459
 
442
460
  *Available since v2.0.0*
@@ -542,6 +560,16 @@ mode | description | notes
542
560
 
543
561
  Defaults to **0**.
544
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
+
545
573
  ### `outlineBars` *boolean*
546
574
 
547
575
  *Available since v3.6.0*
@@ -564,27 +592,25 @@ Defaults to **false**.
564
592
 
565
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.
566
594
 
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
595
  ### `pixelRatio` *number* *(Read only)*
572
596
 
573
597
  Current [devicePixelRatio](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio).
574
598
  This is usually **1** for standard displays and **2** for retina / Hi-DPI screens.
575
599
 
576
- 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.
577
601
 
578
- 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)).
579
603
 
580
604
  ### `radial` *boolean*
581
605
 
582
606
  *Available since v2.4.0*
583
607
 
584
- 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).
585
612
 
586
- When radial mode is active, [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean) have no effect, and
587
- also [`showPeaks`](#showpeaks-boolean) has no effect in radial **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.
588
614
 
589
615
  See also [`spinSpeed`](#spinspeed-number).
590
616
 
@@ -654,30 +680,35 @@ and setting `showBgColor` to ***true*** will make the "unlit" LEDs visible inste
654
680
 
655
681
  *true* to display the current frame rate. Defaults to **false**.
656
682
 
657
- ### `showLeds` **(DEPRECATED)**
658
-
659
- **This property will be removed in version 4.0.0** - Use [`ledBars`](#ledbars-boolean) instead.
660
-
661
683
  ### `showPeaks` *boolean*
662
684
 
663
685
  *true* to show amplitude peaks for each frequency. Defaults to **true**.
664
686
 
665
687
  ### `showScaleX` *boolean*
666
688
 
667
- *Available since v3.0.0*
689
+ *Available since v3.0.0 - this property was named `showScale` in earlier versions*
668
690
 
669
- *true* to display the frequency (Hz) scale on the X axis. Defaults to **true**.
691
+ *true* to display scale labels on the X axis.
670
692
 
671
- *NOTE: this property was named `showScale` in versions prior to v3.0.0*
693
+ See also [`noteLabels`](#notelabels-boolean).
694
+
695
+ Defaults to **true**.
672
696
 
673
697
  ### `showScaleY` *boolean*
674
698
 
675
699
  *Available since v2.4.0*
676
700
 
677
- *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.
678
702
 
679
703
  This option has no effect when [`radial`](#radial-boolean) or [`lumiBars`](#lumibars-boolean) are set to *true*.
680
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
+
681
712
  ### `smoothing` *number*
682
713
 
683
714
  Sets the analyzer's [smoothingTimeConstant](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant).
@@ -910,7 +941,7 @@ Please note that `hold` and `value` will have only one element when [`stereo`](#
910
941
 
911
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.
912
943
 
913
- ### `getEnergy( [preset | startFreq], [endFreq] )`
944
+ ### `getEnergy( [preset | startFreq [, endFreq] ] )`
914
945
 
915
946
  *Available since v3.2.0*
916
947
 
@@ -992,7 +1023,7 @@ if necessary, the led count is decreased until both the led segment and the vert
992
1023
 
993
1024
  You can try different values in the [fluid demo](https://audiomotion.dev/demo/fluid.html).
994
1025
 
995
- **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.**
996
1027
 
997
1028
  ### `setOptions( [options] )`
998
1029
 
@@ -1051,12 +1082,12 @@ ERR_UNKNOWN_GRADIENT | User tried to [select a gradient](#gradient-string)
1051
1082
 
1052
1083
  ## Known Issues
1053
1084
 
1054
- ### reflexBright won't work on some browsers {docsify-ignore}
1085
+ ### reflexBright won't work on some browsers <!-- {docsify-ignore} -->
1055
1086
 
1056
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,
1057
1088
  which is [currently not supported in some browsers](https://caniuse.com/#feat=mdn-api_canvasrenderingcontext2d_filter) (notably, Opera and Safari).
1058
1089
 
1059
- ### alphaBars and fillAlpha won't work with Radial on Firefox {docsify-ignore}
1090
+ ### alphaBars and fillAlpha won't work with Radial on Firefox <!-- {docsify-ignore} -->
1060
1091
 
1061
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).
1062
1093
 
@@ -1065,10 +1096,75 @@ On Firefox, [`alphaBars`](#alphaBars-boolean) and [`fillAlpha`](#fillalpha-numbe
1065
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).
1066
1097
 
1067
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
+
1068
1162
  ## References and acknowledgments
1069
1163
 
1164
+ * Thanks to my wife, Virginia, for her never-ending love and support! 💞
1070
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**
1071
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/)
1072
1168
  * [Web Audio API documentation @MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API)
1073
1169
  * [What does the FFT data in the Web Audio API correspond to?](https://stackoverflow.com/a/14789992/2370385)
1074
1170
  * [Equations for equal-tempered scale frequencies](http://pages.mtu.edu/~suits/NoteFreqCalcs.html)
@@ -1097,5 +1193,5 @@ And if you're feeling generous, maybe:
1097
1193
 
1098
1194
  ## License
1099
1195
 
1100
- 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>
1101
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.6.0",
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",