audiomotion-analyzer 4.2.0 → 4.4.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 +95 -27
- package/package.json +1 -1
- package/src/audioMotion-analyzer.js +426 -312
- package/src/index.d.ts +13 -1
package/README.md
CHANGED
|
@@ -86,13 +86,20 @@ import AudioMotionAnalyzer from 'audiomotion-analyzer';
|
|
|
86
86
|
|
|
87
87
|
## Constructor
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
```js
|
|
90
|
+
new AudioMotionAnalyzer()
|
|
91
|
+
new AudioMotionAnalyzer( container )
|
|
92
|
+
new AudioMotionAnalyzer( container, {options} )
|
|
93
|
+
new AudioMotionAnalyzer( {options} )
|
|
94
|
+
```
|
|
90
95
|
|
|
91
96
|
Creates a new instance of **audioMotion-analyzer**.
|
|
92
97
|
|
|
93
|
-
|
|
98
|
+
`container` is the DOM element into which the canvas created for the analyzer should be inserted.
|
|
94
99
|
|
|
95
|
-
If `
|
|
100
|
+
If not defined, defaults to `document.body`, unless [`canvas`](#canvas-htmlcanvaselement-object) is defined in the options, in which case its parent element will be considered the container.
|
|
101
|
+
|
|
102
|
+
`options` must be an [Options object](#options-object).
|
|
96
103
|
|
|
97
104
|
Usage example:
|
|
98
105
|
|
|
@@ -107,11 +114,14 @@ const audioMotion = new AudioMotionAnalyzer(
|
|
|
107
114
|
|
|
108
115
|
This will insert the analyzer canvas inside the *#container* element and start the visualization of audio coming from the *#audio* element.
|
|
109
116
|
|
|
117
|
+
?> By default, audioMotion will try to use all available container space for the canvas. To prevent it from growing indefinitely, you must either constrain the dimensions of the container via CSS or explicitly define [`height`](#height-number) and/or [`width`](#width-number) properties in the constructor [options](#options-object).
|
|
118
|
+
|
|
110
119
|
### Options object
|
|
111
120
|
|
|
112
121
|
Valid properties and default values are shown below.
|
|
113
122
|
|
|
114
|
-
Properties marked as *constructor only* can only be set
|
|
123
|
+
Properties marked as *constructor only* can only be set in the constructor call, the others can also be set anytime via [`setOptions()`](#setoptions-options-) method or
|
|
124
|
+
directly as [properties](#properties) of the audioMotion instance.
|
|
115
125
|
|
|
116
126
|
options = {<br>
|
|
117
127
|
  [alphaBars](#alphabars-boolean): **false**,<br>
|
|
@@ -119,6 +129,7 @@ options = {<br>
|
|
|
119
129
|
  [audioCtx](#audioctx-audiocontext-object): *undefined*, // constructor only<br>
|
|
120
130
|
  [barSpace](#barspace-number): **0.1**,<br>
|
|
121
131
|
  [bgAlpha](#bgalpha-number): **0.7**,<br>
|
|
132
|
+
  [canvas](#canvas-htmlcanvaselement-object): *undefined*, // constructor only<br>
|
|
122
133
|
  [channelLayout](#channellayout-string): **'single'**,<br>
|
|
123
134
|
  [colorMode](#colormode-string): **'gradient'**,<br>
|
|
124
135
|
  [connectSpeakers](#connectspeakers-boolean): **true**, // constructor only<br>
|
|
@@ -150,6 +161,8 @@ options = {<br>
|
|
|
150
161
|
  [overlay](#overlay-boolean): **false**,<br>
|
|
151
162
|
  [peakLine](#peakline-boolean): **false**,<br>
|
|
152
163
|
  [radial](#radial-boolean): **false**,<br>
|
|
164
|
+
  [radialInvert](#radialinvert-boolean): **false**,<br>
|
|
165
|
+
  [radius](#radius-number): **0.3**,<br>
|
|
153
166
|
  [reflexAlpha](#reflexalpha-number): **0.15**,<br>
|
|
154
167
|
  [reflexBright](#reflexbright-number): **1**,<br>
|
|
155
168
|
  [reflexFit](#reflexfit-boolean): **true**,<br>
|
|
@@ -164,7 +177,7 @@ options = {<br>
|
|
|
164
177
|
  [source](#source-htmlmediaelement-or-audionode-object): *undefined*, // constructor only<br>
|
|
165
178
|
  [spinSpeed](#spinspeed-number): **0**,<br>
|
|
166
179
|
  [splitGradient](#splitgradient-boolean): **false**,<br>
|
|
167
|
-
  [start](#start-boolean): **true
|
|
180
|
+
  [start](#start-boolean): **true**, // constructor only<br>
|
|
168
181
|
  [trueLeds](#trueleds-boolean): **false**,<br>
|
|
169
182
|
  [useCanvas](#usecanvas-boolean): **true**,<br>
|
|
170
183
|
  [volume](#volume-number): **1**,<br>
|
|
@@ -187,6 +200,14 @@ If neither is defined, a new audio context will be created. After instantiation,
|
|
|
187
200
|
|
|
188
201
|
See [this live code](https://codesandbox.io/s/9y6qb) and the [multi-instance demo](/demo/multi.html) for more usage examples.
|
|
189
202
|
|
|
203
|
+
#### `canvas` *HTMLCanvasElement object*
|
|
204
|
+
|
|
205
|
+
*Available since v4.4.0*
|
|
206
|
+
|
|
207
|
+
Allows you to provide an existing [*Canvas*](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) where audioMotion should render its visualizations.
|
|
208
|
+
|
|
209
|
+
If not defined, a new canvas will be created. After instantiation, you can obtain its reference from the [`canvas`](#canvas-htmlcanvaselement-object-read-only) read-only property.
|
|
210
|
+
|
|
190
211
|
#### `connectSpeakers` *boolean*
|
|
191
212
|
|
|
192
213
|
*Available since v3.2.0*
|
|
@@ -321,11 +342,13 @@ Defaults to **0.7**.
|
|
|
321
342
|
|
|
322
343
|
### `canvas` *HTMLCanvasElement object* *(Read only)*
|
|
323
344
|
|
|
324
|
-
[*Canvas*](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) element
|
|
345
|
+
[*Canvas*](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) element where audioMotion renders its visualizations.
|
|
346
|
+
|
|
347
|
+
See also the [`canvas`](#canvas-htmlcanvaselement-object) constructor option.
|
|
325
348
|
|
|
326
349
|
### `canvasCtx` *CanvasRenderingContext2D object* *(Read only)*
|
|
327
350
|
|
|
328
|
-
[2D rendering context](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D) used for drawing in audioMotion's
|
|
351
|
+
[2D rendering context](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D) used for drawing in audioMotion's [`canvas`](#canvas-htmlcanvaselement-object-read-only).
|
|
329
352
|
|
|
330
353
|
### `channelLayout` *string*
|
|
331
354
|
|
|
@@ -333,11 +356,12 @@ Defaults to **0.7**.
|
|
|
333
356
|
|
|
334
357
|
Defines the number and layout of analyzer channels.
|
|
335
358
|
|
|
336
|
-
channelLayout
|
|
337
|
-
|
|
338
|
-
'single'
|
|
339
|
-
'dual-combined'
|
|
340
|
-
'dual-
|
|
359
|
+
channelLayout | Description | Note
|
|
360
|
+
------------------|-------------|------
|
|
361
|
+
'single' | Single channel analyzer, representing the combined output of both left and right channels.
|
|
362
|
+
'dual-combined' | Dual channel analyzer, both channels overlaid. Works best with semi-transparent **Graph** [`mode`](#mode-number) or [`outlineBars`](#outlinebars-boolean).
|
|
363
|
+
'dual-horizontal' | Dual channel, side by side - see [`mirror`](#mirror-number) for additional layout options. | *since v4.3.0*
|
|
364
|
+
'dual-vertical' | Dual channel, left channel at the top half of the canvas and right channel at the bottom.
|
|
341
365
|
|
|
342
366
|
!> When a *dual* layout is selected, any mono (single channel) audio source connected to the analyzer will output sound only from the left speaker,
|
|
343
367
|
unless a stereo source is simultaneously connected to the analyzer, which will force the mono input to be upmixed to stereo.
|
|
@@ -479,13 +503,14 @@ See also [`gradient`](#gradient-string) and [`splitGradient`](#splitgradient-boo
|
|
|
479
503
|
|
|
480
504
|
Nominal dimensions of the analyzer.
|
|
481
505
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
This should be considered the minimum dimensions for proper visualization of all available modes and effects.
|
|
506
|
+
Setting one or both properties to **_undefined_** (default) will trigger the fluid/responsive behavior and the analyzer will try to adjust to the container's height and/or width.
|
|
507
|
+
In that case, it's important that you constrain the dimensions of the container via CSS to prevent the canvas from growing indefinitely.
|
|
485
508
|
|
|
486
509
|
You can set both values at once using the [`setCanvasSize()`](#setcanvassize-width-height-) method.
|
|
487
510
|
|
|
488
|
-
|
|
511
|
+
See also [`onCanvasResize`](#oncanvasresize-function).
|
|
512
|
+
|
|
513
|
+
?> The actual dimensions of the canvas may differ from these values, depending on the device's [pixelRatio](#pixelratio-number-read-only), the [`loRes`](#lores-boolean) setting and while in fullscreen. For the actual pixel values, read `height` and `width` directly from the [`canvas`](#canvas-htmlcanvaselement-object-read-only) object.
|
|
489
514
|
|
|
490
515
|
### `isAlphaBars` *boolean* *(Read only)*
|
|
491
516
|
|
|
@@ -668,15 +693,19 @@ It is preferable to use the [`setFreqRange()`](#setfreqrange-minfreq-maxfreq-) m
|
|
|
668
693
|
|
|
669
694
|
*Available since v3.3.0*
|
|
670
695
|
|
|
671
|
-
|
|
696
|
+
When [`channelLayout`](#channellayout-string) is **dual-horizontal**, this property controls the orientation of the X-axis (frequencies) on both channels.
|
|
697
|
+
|
|
698
|
+
For other layouts, it horizontally mirrors the spectrum image to the left or right side.
|
|
699
|
+
|
|
700
|
+
Valid values are:
|
|
672
701
|
|
|
673
|
-
mirror |
|
|
674
|
-
|
|
675
|
-
-1 |
|
|
676
|
-
0 |
|
|
677
|
-
1 |
|
|
702
|
+
mirror | Description
|
|
703
|
+
:-----:|-------------
|
|
704
|
+
-1 | Low frequencies meet at the center of the screen (mirror left)
|
|
705
|
+
0 | No mirror effect or change to axis orientation (default)
|
|
706
|
+
1 | High frequencies meet at the center of the screen (mirror right)
|
|
678
707
|
|
|
679
|
-
**Note:**
|
|
708
|
+
**Note:** On [`radial`](#radial-boolean) spectrum with channel layouts other than *dual-horizontal*, both `1` and `-1` have the same effect.
|
|
680
709
|
|
|
681
710
|
Defaults to **0**.
|
|
682
711
|
|
|
@@ -766,12 +795,36 @@ In radial view, [`ledBars`](#ledbars-boolean) and [`lumiBars`](#lumibars-boolean
|
|
|
766
795
|
|
|
767
796
|
When [`channelLayout`](#channellayout-string) is set to *'dual-vertical'*, graphs for the right channel are rendered towards the center of the screen.
|
|
768
797
|
|
|
769
|
-
See also [`spinSpeed`](#spinspeed-number).
|
|
798
|
+
See also [`radialInvert`](#radialinvert-boolean), [`radius`](#radius-number) and [`spinSpeed`](#spinspeed-number).
|
|
770
799
|
|
|
771
800
|
Defaults to **false**.
|
|
772
801
|
|
|
773
802
|
!> [See related known issue](#alphabars-and-fillalpha-wont-work-with-radial-on-firefox)
|
|
774
803
|
|
|
804
|
+
### `radialInvert` *boolean*
|
|
805
|
+
|
|
806
|
+
*Available since v4.4.0*
|
|
807
|
+
|
|
808
|
+
When set to *true* (and [`radial`](#radial-boolean) is also *true*) creates a radial spectrum with maximum size and bars growing towards the center of the screen.
|
|
809
|
+
|
|
810
|
+
This property has no effect when [`channelLayout`](#channellayout-string) is set to *'dual-vertical'*.
|
|
811
|
+
|
|
812
|
+
See also [`radius`](#radius-number).
|
|
813
|
+
|
|
814
|
+
Defaults to **false**.
|
|
815
|
+
|
|
816
|
+
### `radius` *number*
|
|
817
|
+
|
|
818
|
+
*Available since v4.4.0*
|
|
819
|
+
|
|
820
|
+
Defines the internal radius of [`radial`](#radial-boolean) spectrum. It should be a number between **0** and **1**.
|
|
821
|
+
|
|
822
|
+
This property has no effect when [`channelLayout`](#channellayout-string) is set to *'dual-vertical'*.
|
|
823
|
+
|
|
824
|
+
When [`radialInvert`](#radialinvert-boolean) is *true*, this property controls how close to the center of the screen the bars can get.
|
|
825
|
+
|
|
826
|
+
Defaults to **0.3**.
|
|
827
|
+
|
|
775
828
|
### `reflexAlpha` *number*
|
|
776
829
|
|
|
777
830
|
*Available since v2.1.0*
|
|
@@ -1208,6 +1261,19 @@ Please note that preset names are case-sensitive. If the specified preset is not
|
|
|
1208
1261
|
|
|
1209
1262
|
Use this method inside your callback function to create additional visual effects. See the [fluid demo](/demo/fluid.html) or [this pen](https://codepen.io/hvianna/pen/poNmVYo) for examples.
|
|
1210
1263
|
|
|
1264
|
+
### `getOptions( [ignore] )`
|
|
1265
|
+
|
|
1266
|
+
*Available since v4.4.0*
|
|
1267
|
+
|
|
1268
|
+
Returns an [**Options object**](#options-object) with all the current analyzer settings.
|
|
1269
|
+
|
|
1270
|
+
`ignore` can be a single property name or an array of property names that should not be included in the returned object.
|
|
1271
|
+
|
|
1272
|
+
Callbacks and [constructor-specific properties](#constructor-specific-options) are NOT included in the object.
|
|
1273
|
+
|
|
1274
|
+
?> If the same [gradient](#gradient-string) is selected for both channels, only the `gradient` property is included in the object; otherwise, only `gradientLeft` and `gradientRight` are included (not `gradient`). If 'gradient' is added to `ignore`, none of the gradient properties will be included.
|
|
1275
|
+
|
|
1276
|
+
See also [`setOptions()`](#setoptions-options-).
|
|
1211
1277
|
|
|
1212
1278
|
### `registerGradient( name, options )`
|
|
1213
1279
|
|
|
@@ -1285,10 +1351,12 @@ You can try different values in the [fluid demo](https://audiomotion.dev/demo/fl
|
|
|
1285
1351
|
|
|
1286
1352
|
Shorthand method for setting several analyzer [properties](#properties) at once.
|
|
1287
1353
|
|
|
1288
|
-
|
|
1354
|
+
`options` must be an [**Options object**](#options-object).
|
|
1289
1355
|
|
|
1290
1356
|
?> If called with no argument (or `options` is *undefined*), resets all configuration options to their default values.
|
|
1291
1357
|
|
|
1358
|
+
See also [`getOptions()`](#getoptions-ignore-).
|
|
1359
|
+
|
|
1292
1360
|
### `setSensitivity( minDecibels, maxDecibels )`
|
|
1293
1361
|
|
|
1294
1362
|
Adjust the analyzer's sensitivity. See [`minDecibels`](#mindecibels-number) and [`maxDecibels`](#maxdecibels-number) properties.
|
|
@@ -1451,7 +1519,7 @@ See [Changelog.md](Changelog.md)
|
|
|
1451
1519
|
|
|
1452
1520
|
## Contributing
|
|
1453
1521
|
|
|
1454
|
-
I kindly request that you only [open an issue](https://github.com/hvianna/audioMotion-analyzer/issues) for submitting
|
|
1522
|
+
I kindly request that you only [open an issue](https://github.com/hvianna/audioMotion-analyzer/issues) for submitting **bug reports**.
|
|
1455
1523
|
|
|
1456
1524
|
If you need help integrating *audioMotion-analyzer* with your project, have ideas for **new features** or any other questions or feedback,
|
|
1457
1525
|
please use the [**Discussions**](https://github.com/hvianna/audioMotion-analyzer/discussions) section on GitHub.
|
|
@@ -1470,5 +1538,5 @@ And if you're feeling generous, maybe:
|
|
|
1470
1538
|
|
|
1471
1539
|
## License
|
|
1472
1540
|
|
|
1473
|
-
audioMotion-analyzer copyright (c) 2018-
|
|
1541
|
+
audioMotion-analyzer copyright (c) 2018-2024 [Henrique Avila Vianna](https://henriquevianna.com)<br>
|
|
1474
1542
|
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.
|
|
4
|
+
"version": "4.4.0",
|
|
5
5
|
"main": "./src/audioMotion-analyzer.js",
|
|
6
6
|
"module": "./src/audioMotion-analyzer.js",
|
|
7
7
|
"types": "./src/index.d.ts",
|