audiomotion-analyzer 5.0.0-alpha.0 → 5.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +323 -202
- package/dist/index.js +311 -244
- package/package.json +4 -4
- package/src/audioMotion-analyzer.js +307 -240
- package/src/index.d.ts +35 -23
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## About
|
|
2
2
|
|
|
3
|
-
> **WARNING:** code in **alpha** stage is subject to major, drastic changes! **DO NOT USE THIS IN PRODUCTION!**
|
|
3
|
+
> **WARNING:** code in **alpha** stage is subject to major, drastic changes! **DO NOT USE THIS VERSION IN PRODUCTION!**
|
|
4
4
|
|
|
5
5
|
**audioMotion-analyzer** is a high-resolution real-time audio spectrum analyzer built upon **Web Audio** and **Canvas** JavaScript APIs.
|
|
6
6
|
|
|
@@ -32,7 +32,7 @@ What users are saying:
|
|
|
32
32
|
+ Logarithmic, linear and perceptual (Bark and Mel) frequency scales, with customizable range
|
|
33
33
|
+ Visualization of discrete FFT frequencies or up to 240 frequency bands (supports ANSI and equal-tempered octave bands)
|
|
34
34
|
+ Decibel and linear amplitude scales, with customizable sensitivity
|
|
35
|
-
+ Optional A, B, C
|
|
35
|
+
+ Optional weighting filters (A, B, C and D-weighting, ITU-R 468, 3dB and 4.5dB per octave tilt)
|
|
36
36
|
+ Additional effects: LED bars, radial spectrum, variable opacity bars, mirroring and reflection
|
|
37
37
|
+ Choose from 5 built-in color themes or easily add your own!
|
|
38
38
|
+ Fullscreen support, ready for retina / HiDPI displays
|
|
@@ -80,11 +80,11 @@ const { AudioMotionAnalyzer } = require('audioMotion-analyzer');
|
|
|
80
80
|
|
|
81
81
|
### In the browser using native ES6 module (ESM) <!-- {docsify-ignore} -->
|
|
82
82
|
|
|
83
|
-
Load from
|
|
83
|
+
Load from jsDelivr CDN:
|
|
84
84
|
|
|
85
85
|
```html
|
|
86
86
|
<script type="module">
|
|
87
|
-
import AudioMotionAnalyzer from 'https://cdn.
|
|
87
|
+
import AudioMotionAnalyzer from 'https://cdn.jsdelivr.net/npm/audiomotion-analyzer@alpha/+esm';
|
|
88
88
|
// your code here
|
|
89
89
|
</script>
|
|
90
90
|
```
|
|
@@ -93,10 +93,10 @@ Or download the [latest version](https://github.com/hvianna/audioMotion-analyzer
|
|
|
93
93
|
|
|
94
94
|
### In the browser using global variable <!-- {docsify-ignore} -->
|
|
95
95
|
|
|
96
|
-
Load from
|
|
96
|
+
Load from jsDelivr CDN:
|
|
97
97
|
|
|
98
98
|
```html
|
|
99
|
-
<script src="https://
|
|
99
|
+
<script src="https://cdn.jsdelivr.net/npm/audiomotion-analyzer@alpha"></script>
|
|
100
100
|
<script>
|
|
101
101
|
// available as AudioMotionAnalyzer global
|
|
102
102
|
</script>
|
|
@@ -141,37 +141,35 @@ property | type | default | notes
|
|
|
141
141
|
--------------------------------------|-----------|---------|-------------------------------
|
|
142
142
|
[`alphaBars`](#alphabars) | *string* | `"off"` |
|
|
143
143
|
[`ansiBands`](#ansibands) | *boolean* | `false` |
|
|
144
|
-
[`audioCtx`](#audioctx) | *AudioContext
|
|
144
|
+
[`audioCtx`](#audioctx) | *AudioContext* | *creates new object* | constructor only
|
|
145
145
|
[`barSpace`](#barspace) | *number* | `0.1` |
|
|
146
|
-
[`canvas`](#canvas) | *HTMLCanvasElement
|
|
146
|
+
[`canvas`](#canvas) | *HTMLCanvasElement* | *creates new object* | constructor only
|
|
147
147
|
[`channelLayout`](#channellayout) | *string* | `"single"` |
|
|
148
148
|
[`colorMode`](#colormode) | *string* | `"gradient"` |
|
|
149
149
|
[`connectSpeakers`](#connectspeakers) | *boolean* | `true` | constructor only
|
|
150
150
|
[`fftSize`](#fftsize) | *number* | `8192` |
|
|
151
151
|
[`fillAlpha`](#fillalpha) | *number* | `0.5` |
|
|
152
152
|
[`frequencyScale`](#frequencyscale) | *string* | `"log"` |
|
|
153
|
-
[`fsElement`](#fselement) | *HTMLElement
|
|
153
|
+
[`fsElement`](#fselement) | *HTMLElement* | [`canvas`](#canvas) | constructor only
|
|
154
154
|
[`height`](#height) | *number* or *undefined* | `undefined` |
|
|
155
155
|
[`ledBars`](#ledbars) | *string* | `"off"` |
|
|
156
156
|
[`linearAmplitude`](#linearamplitude) | *boolean* | `false` |
|
|
157
157
|
[`linearBoost`](#linearboost) | *number* | `1` |
|
|
158
158
|
[`lineWidth`](#linewidth) | *number* | `1` |
|
|
159
159
|
[`loRes`](#lores) | *boolean* | `false` |
|
|
160
|
-
[`maxDecibels`](#maxdecibels) | *number* | `-
|
|
160
|
+
[`maxDecibels`](#maxdecibels) | *number* | `-30` |
|
|
161
161
|
[`maxFPS`](#maxfps) | *number* | `0` |
|
|
162
162
|
[`maxFreq`](#maxfreq) | *number* | `22000` |
|
|
163
|
-
[`minDecibels`](#mindecibels) | *number* | `-
|
|
163
|
+
[`minDecibels`](#mindecibels) | *number* | `-90` |
|
|
164
164
|
[`minFreq`](#minfreq) | *number* | `20` |
|
|
165
165
|
[`mirror`](#mirror) | *number* | `0` |
|
|
166
166
|
[`mode`](#mode) | *string* | `"bars"` |
|
|
167
|
-
[`noteLabels`](#notelabels) | *boolean* | `false` |
|
|
168
167
|
[`onCanvasDraw`](#oncanvasdraw) | *function* or *undefined* | `undefined` |
|
|
169
168
|
[`onCanvasResize`](#oncanvasresize) | *function* or *undefined* | `undefined` |
|
|
170
169
|
[`outlineBars`](#outlinebars) | *boolean* | `false` |
|
|
171
170
|
[`peakDecayTime`](#peakdecaytime) | *number* | `750` |
|
|
172
171
|
[`peakHoldTime`](#peakholdtime) | *number* | `500` |
|
|
173
172
|
[`peakLine`](#peakline) | *boolean* | `false` |
|
|
174
|
-
[`peaks`](#peaks) | *string* | `"drop"` |
|
|
175
173
|
[`radial`](#radial) | *number* | `0` |
|
|
176
174
|
[`radius`](#radius) | *number* | `0.5` |
|
|
177
175
|
[`reflexAlpha`](#reflexalpha) | *number* | `0.15` |
|
|
@@ -181,16 +179,17 @@ property | type | default | notes
|
|
|
181
179
|
[`roundBars`](#roundbars) | *boolean* | `false` |
|
|
182
180
|
[`showFPS`](#showfps) | *boolean* | `false` |
|
|
183
181
|
[`showLedMask`](#showledmask) | *boolean* | `true` |
|
|
184
|
-
[`
|
|
185
|
-
[`
|
|
186
|
-
[`
|
|
187
|
-
[`
|
|
182
|
+
[`showPeaks`](#showpeaks) | *string* | `"drop"` |
|
|
183
|
+
[`showScaleX`](#showscalex) | *string* | `"freqs"` |
|
|
184
|
+
[`showScaleY`](#showscaley) | *string* | `"off"` |
|
|
185
|
+
[`smoothing`](#smoothing) | *number* | `0.7` |
|
|
186
|
+
[`source`](#source) | *AudioNode*, *HTMLMediaElement* or *MediaStream* | *none* | constructor only
|
|
188
187
|
[`spinSpeed`](#spinspeed) | *number* | `0` |
|
|
189
188
|
[`spreadGradient`](#spreadgradient) | *boolean* | `false` |
|
|
190
189
|
[`start`](#start) | *boolean* | `true` | constructor only
|
|
191
190
|
[`useCanvas`](#usecanvas) | *boolean* | `true` |
|
|
192
191
|
[`volume`](#volume) | *number* | `1` |
|
|
193
|
-
[`weightingFilter`](#weightingFilter) | *string* | `""` |
|
|
192
|
+
[`weightingFilter`](#weightingFilter) | *string* | `"none"` |
|
|
194
193
|
[`width`](#width) | *number* or *undefined* | `undefined` |
|
|
195
194
|
|
|
196
195
|
### Constructor-specific options
|
|
@@ -225,7 +224,7 @@ If not defined, a new Canvas will be created. After instantiation, you can obtai
|
|
|
225
224
|
|
|
226
225
|
**Value:** a *boolean* value. The default value is `true`.
|
|
227
226
|
|
|
228
|
-
Whether or not to connect the analyzer output to the speakers (technically, the *AudioContext* `destination` node).
|
|
227
|
+
Whether or not to connect the analyzer output to the speakers (technically, the *AudioContext* [`destination`](https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/destination) node).
|
|
229
228
|
|
|
230
229
|
Some scenarios where you may want to set this to `false`:
|
|
231
230
|
|
|
@@ -255,9 +254,9 @@ After instantiation, [`fsElement`](#fselement-read-only) is available as a read-
|
|
|
255
254
|
|
|
256
255
|
#### `source`
|
|
257
256
|
|
|
258
|
-
**Value:** an [*AudioNode*](https://developer.mozilla.org/en-US/docs/Web/API/AudioNode)
|
|
257
|
+
**Value:** an [*AudioNode*](https://developer.mozilla.org/en-US/docs/Web/API/AudioNode), [*HTMLMediaElement*](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement) or [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream) object.
|
|
259
258
|
|
|
260
|
-
If `source` is specified, connects
|
|
259
|
+
If `source` is specified, connects the provided *AudioNode*, HTML media element (`<audio>` or `<video>` elements) or *MediaStream* object to the analyzer.
|
|
261
260
|
|
|
262
261
|
At least one audio source is required for the analyzer to work. You can also connect audio sources after instantiation, using the [`connectInput()`](#connectinput) method.
|
|
263
262
|
|
|
@@ -306,6 +305,14 @@ import {
|
|
|
306
305
|
FILTER_C,
|
|
307
306
|
FILTER_D,
|
|
308
307
|
FILTER_468,
|
|
308
|
+
LABELS_X_CUSTOM,
|
|
309
|
+
LABELS_X_FREQS,
|
|
310
|
+
LABELS_X_FREQS_CUSTOM,
|
|
311
|
+
LABELS_X_NOTES,
|
|
312
|
+
LABELS_X_OFF,
|
|
313
|
+
LABELS_Y_DB,
|
|
314
|
+
LABELS_Y_PERCENT,
|
|
315
|
+
LABELS_Y_OFF,
|
|
309
316
|
LAYOUT_COMBINED,
|
|
310
317
|
LAYOUT_HORIZONTAL,
|
|
311
318
|
LAYOUT_SINGLE,
|
|
@@ -318,9 +325,9 @@ import {
|
|
|
318
325
|
PEAKS_DROP,
|
|
319
326
|
PEAKS_FADE,
|
|
320
327
|
PEAKS_OFF,
|
|
321
|
-
|
|
328
|
+
RADIAL_INWARD,
|
|
322
329
|
RADIAL_OFF,
|
|
323
|
-
|
|
330
|
+
RADIAL_OUTWARD,
|
|
324
331
|
REASON_CREATE,
|
|
325
332
|
REASON_FULLSCREENCHANGE,
|
|
326
333
|
REASON_LORES,
|
|
@@ -371,8 +378,6 @@ Only effective when [`frequencyScale`](#frequencyScale) is set to `"log"` and [`
|
|
|
371
378
|
|
|
372
379
|
When using the equal-tempered scale, the center frequency of each band is tuned to a standard musical note.
|
|
373
380
|
|
|
374
|
-
See also [`noteLabels`](#notelabels).
|
|
375
|
-
|
|
376
381
|
### `audioCtx` *(read only)*
|
|
377
382
|
|
|
378
383
|
The [*AudioContext*](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) used by **audioMotion-analyzer** for audio processing.
|
|
@@ -550,7 +555,7 @@ value | [Constant](#constants) | Description | Scale preview (10Hz - 24kHz
|
|
|
550
555
|
`"log"` | `SCALE_LOG` | Logarithmic scale | 
|
|
551
556
|
`"mel"` | `SCALE_MEL` | Mel scale | 
|
|
552
557
|
|
|
553
|
-
Logarithmic scale allows visualization of proper **octave bands** (see [`bandResolution`](#bandresolution)) and it's also recommended when using [`
|
|
558
|
+
Logarithmic scale allows visualization of proper **octave bands** (see [`bandResolution`](#bandresolution)) and it's also recommended when using [`showScaleX`](#showscalex) set to `"notes"`.
|
|
554
559
|
|
|
555
560
|
[*Bark*](https://en.wikipedia.org/wiki/Bark_scale) and [*Mel*](https://en.wikipedia.org/wiki/Mel_scale) are perceptual pitch scales, which may provide better visualization of mid-range frequencies, when compared to log or linear scales.
|
|
556
561
|
|
|
@@ -715,7 +720,7 @@ This will prevent the canvas size from changing, when switching the low resoluti
|
|
|
715
720
|
|
|
716
721
|
### `maxDecibels`
|
|
717
722
|
|
|
718
|
-
**Value:** a *number*. The default value is `-
|
|
723
|
+
**Value:** a *number*. The default value is `-30`.
|
|
719
724
|
|
|
720
725
|
Maximum amplitude value, in decibels, represented in the Y-axis of the analyzer.
|
|
721
726
|
|
|
@@ -749,7 +754,7 @@ See also [`minFreq`](#minfreq) and [`setFreqRange()`](#setfreqrange).
|
|
|
749
754
|
|
|
750
755
|
### `minDecibels`
|
|
751
756
|
|
|
752
|
-
**Value:** a *number*. The default value is `-
|
|
757
|
+
**Value:** a *number*. The default value is `-90`.
|
|
753
758
|
|
|
754
759
|
Minimum amplitude value, in decibels, represented in the Y-axis of the analyzer.
|
|
755
760
|
|
|
@@ -804,17 +809,6 @@ See also [`bandResolution`](#bandresolution).
|
|
|
804
809
|
> 1 through 8 | "bars" | 9 *minus* legacy mode
|
|
805
810
|
> 10 | "graph" | 0
|
|
806
811
|
|
|
807
|
-
### `noteLabels`
|
|
808
|
-
|
|
809
|
-
*Available since v4.0.0*
|
|
810
|
-
|
|
811
|
-
**Value:** a *boolean* value. The default value is `false`.
|
|
812
|
-
|
|
813
|
-
Whether to displays musical note labels instead of frequency values, in the X-axis (when [`showScaleX`](#showscalex) is `true`).
|
|
814
|
-
|
|
815
|
-
For best visualization in [octave bands modes](#mode), make sure [`frequencyScale`](#frequencyscale) is set to `"log"`
|
|
816
|
-
and [`ansiBands`](#ansibands) is set to `false`, so bands are tuned to the equal temperament musical scale.
|
|
817
|
-
|
|
818
812
|
### `onCanvasDraw`
|
|
819
813
|
|
|
820
814
|
**Value:** a *function* or *undefined*. The default value is `undefined`.
|
|
@@ -924,7 +918,7 @@ For effect priority when combined with other settings, see [`isOutlineBars`](#is
|
|
|
924
918
|
|
|
925
919
|
**Value:** a *number*. The default value is `750`.
|
|
926
920
|
|
|
927
|
-
Time in milliseconds for peaks to fall down from maximum amplitude to zero, or to completely fade out (when [`
|
|
921
|
+
Time in milliseconds for peaks to fall down from maximum amplitude to zero, or to completely fade out (when [`showPeaks`](#showpeaks) is set to `"fade"`).
|
|
928
922
|
|
|
929
923
|
It must be a number greater than or equal to zero. Invalid values are ignored.
|
|
930
924
|
|
|
@@ -940,7 +934,7 @@ Time in milliseconds for peaks to hold their value before they begin to fall or
|
|
|
940
934
|
|
|
941
935
|
It must be a number greater than or equal to zero. Invalid values are ignored.
|
|
942
936
|
|
|
943
|
-
See also [`
|
|
937
|
+
See also [`peakDecayTime`](#peakdecaytime) and [`showPeaks`](#showpeaks).
|
|
944
938
|
|
|
945
939
|
### `peakLine`
|
|
946
940
|
|
|
@@ -952,23 +946,7 @@ Determines the line width used to connect the amplitude peaks, when [`mode`](#mo
|
|
|
952
946
|
|
|
953
947
|
A value of `0` means no line.
|
|
954
948
|
|
|
955
|
-
Please note that [`
|
|
956
|
-
|
|
957
|
-
### `peaks`
|
|
958
|
-
|
|
959
|
-
*Available since v5.0.0; formerly `showPeaks` (since v1.0.0)*
|
|
960
|
-
|
|
961
|
-
**Value:** a *string*. The default value is `"drop"`.
|
|
962
|
-
|
|
963
|
-
Determines the display and behavior of amplitude peaks.
|
|
964
|
-
|
|
965
|
-
value | [Constant](#constants) | Description
|
|
966
|
-
---------|------------------------|--------------
|
|
967
|
-
`"off"` | `PEAKS_OFF` | Disable display of amplitude peaks (including [`peakLine`](#peakline))
|
|
968
|
-
`"drop"` | `PEAKS_DROP` | Display peaks that fall down over time
|
|
969
|
-
`"fade"` | `PEAKS_FADE` | Display peaks that fade out over time
|
|
970
|
-
|
|
971
|
-
See also [`peakDecayTime`](#peakdecaytime) and [`peakHoldTime`](#peakholdtime).
|
|
949
|
+
Please note that [`showPeaks`](#showpeaks) must be set to either `"drop"` or `"fade"`, although peak lines will always display the *"drop"* behavior.
|
|
972
950
|
|
|
973
951
|
### `pixelRatio` *(read only)*
|
|
974
952
|
|
|
@@ -991,9 +969,9 @@ Whether to render the spectrum analyzer as a circle with radial bars.
|
|
|
991
969
|
|
|
992
970
|
value | [Constant](#constants) | Description
|
|
993
971
|
------|------------------------|----------------
|
|
994
|
-
`0` | `RADIAL_OFF`
|
|
995
|
-
`1` | `
|
|
996
|
-
`-1` | `
|
|
972
|
+
`0` | `RADIAL_OFF` | Disables radial
|
|
973
|
+
`1` | `RADIAL_OUTWARD` | Bars grow towards the edges of the screen
|
|
974
|
+
`-1` | `RADIAL_INWARD` | Bars grow towards the center of the screen
|
|
997
975
|
|
|
998
976
|
When [`channelLayout`](#channellayout) is set to `"dual-vertical"`, left channel bars grow outwards and right channel bars grow inwards, so both `1` and `-1` values have the same effect.
|
|
999
977
|
|
|
@@ -1092,38 +1070,63 @@ Whether to display the "unlit" LED elements. Has no effect when [`ledBars`](#led
|
|
|
1092
1070
|
:----------------------:|:-----------------------:
|
|
1093
1071
|
 | 
|
|
1094
1072
|
|
|
1073
|
+
### `showPeaks`
|
|
1074
|
+
|
|
1075
|
+
**Value:** a *string*. The default value is `"drop"`.
|
|
1076
|
+
|
|
1077
|
+
Determines the display and behavior of amplitude peaks.
|
|
1078
|
+
|
|
1079
|
+
value | [Constant](#constants) | Description
|
|
1080
|
+
---------|------------------------|--------------
|
|
1081
|
+
`"off"` | `PEAKS_OFF` | Disable display of amplitude peaks and [`peakLine`](#peakline)
|
|
1082
|
+
`"drop"` | `PEAKS_DROP` | Display peaks that fall down over time
|
|
1083
|
+
`"fade"` | `PEAKS_FADE` | Display peaks that fade out over time
|
|
1084
|
+
|
|
1085
|
+
See also [`peakDecayTime`](#peakdecaytime) and [`peakHoldTime`](#peakholdtime).
|
|
1086
|
+
|
|
1095
1087
|
### `showScaleX`
|
|
1096
1088
|
|
|
1097
1089
|
*Available since v3.0.0; formerly `showScale` (since v1.0.0)*
|
|
1098
1090
|
|
|
1099
|
-
**Value:** a *
|
|
1091
|
+
**Value:** a *string*. The default value is `"freqs"`.
|
|
1100
1092
|
|
|
1101
1093
|
Whether to display scale labels on the X-axis.
|
|
1102
1094
|
|
|
1103
|
-
|
|
1095
|
+
Value | [Constant](#constants) | Description
|
|
1096
|
+
-----------------|-------------------------|---------------
|
|
1097
|
+
`"off"` | `LABELS_X_OFF` | Do not display scale labels on the X-axis.
|
|
1098
|
+
`"custom"` | `LABELS_X_CUSTOM` | Display custom `labels` defined via [`setScaleX()`](#setscalex).
|
|
1099
|
+
`"freqs"` | `LABELS_X_FREQS` | Display octaves center frequencies - see also [`ansiBands`](#ansibands).
|
|
1100
|
+
`"freqs-custom"` | `LABELS_X_FREQS_CUSTOM` | Display center frequencies and any additional custom labels.
|
|
1101
|
+
`"notes"` | `LABELS_X_NOTES` | Display musical note labels.
|
|
1104
1102
|
|
|
1105
|
-
|
|
1103
|
+
Several display properties of the scale can be customized via [`setScaleX()`](#setscalex) method.
|
|
1104
|
+
|
|
1105
|
+
?> For best results of `"notes"` setting in [octave bands modes](#bandresolution), make sure [`frequencyScale`](#frequencyscale) is set to `"log"` and [`ansiBands`](#ansibands) is set to `false`, so bands are tuned to the equal temperament musical scale.
|
|
1106
1106
|
|
|
1107
1107
|
### `showScaleY`
|
|
1108
1108
|
|
|
1109
1109
|
*Available since v2.4.0*
|
|
1110
1110
|
|
|
1111
|
-
**Value:** a *
|
|
1111
|
+
**Value:** a *string*. The default value is `"off"`.
|
|
1112
1112
|
|
|
1113
1113
|
Whether to display the level/amplitude scale on the Y-axis.
|
|
1114
1114
|
|
|
1115
|
-
|
|
1115
|
+
Value | [Constant](#constants) | Description
|
|
1116
|
+
------------|------------------------|---------------
|
|
1117
|
+
`"off"` | `LABELS_Y_OFF` | Do not display scale labels on the Y-axis.
|
|
1118
|
+
`"db"` | `LABELS_Y_DB` | Display labels in decibels.
|
|
1119
|
+
`"percent"` | `LABELS_Y_PERCENT` | Display labels in percent values.
|
|
1116
1120
|
|
|
1117
|
-
|
|
1118
|
-
otherwise, values represent a percentage (0-100%) of the maximum amplitude.
|
|
1121
|
+
This option has no effect when [`radial`](#radial) is active or [`alphaBars`](#alphabars) is set to `"full"`.
|
|
1119
1122
|
|
|
1120
|
-
Several properties of the scale can be customized via [`
|
|
1123
|
+
Several display properties of the scale can be customized via [`setScaleY()`](#setscaley) method.
|
|
1121
1124
|
|
|
1122
1125
|
See also [`minDecibels`](#mindecibels) and [`maxDecibels`](#maxdecibels).
|
|
1123
1126
|
|
|
1124
1127
|
### `smoothing`
|
|
1125
1128
|
|
|
1126
|
-
**Value:** a *number*. The default value is `0.
|
|
1129
|
+
**Value:** a *number*. The default value is `0.7`.
|
|
1127
1130
|
|
|
1128
1131
|
Determines the analyzer's [smoothingTimeConstant](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant).
|
|
1129
1132
|
|
|
@@ -1188,27 +1191,28 @@ Please note that changing the volume on the audio element will affect the amplit
|
|
|
1188
1191
|
|
|
1189
1192
|
*Available since v4.0.0*
|
|
1190
1193
|
|
|
1191
|
-
[Weighting filter](https://en.wikipedia.org/wiki/Weighting_filter) applied to analyzer data, for spectrum visualization
|
|
1194
|
+
[Weighting filter](https://en.wikipedia.org/wiki/Weighting_filter) applied to analyzer data, for spectrum visualization.
|
|
1195
|
+
Each filter applies a different curve of gain/attenuation to specific frequency ranges, but the general idea is to adjust the
|
|
1196
|
+
visualization of frequencies to the sensitivity of the human ear.
|
|
1197
|
+
|
|
1198
|
+
**Value:** a *string*. The default value is `"none"`.
|
|
1192
1199
|
|
|
1193
1200
|
<img src="img/weigthing-filters-curves.png" class="align-right">
|
|
1194
1201
|
|
|
1195
|
-
|
|
1202
|
+
Value | [Constant](#constants) | Description
|
|
1203
|
+
------------|------------------------|---------------
|
|
1204
|
+
`"none"` | `FILTER_NONE` | No weighting applied (default)
|
|
1205
|
+
`"a"` | `FILTER_A` | A-weighting
|
|
1206
|
+
`"b"` | `FILTER_B` | B-weighting
|
|
1207
|
+
`"c"` | `FILTER_C` | C-weighting
|
|
1208
|
+
`"d"` | `FILTER_D` | D-weighting
|
|
1209
|
+
`"468"` | `FILTER_468` | ITU-R 468 weighting
|
|
1210
|
+
`"tilt3"` | `FILTER_TILT3` | 3dB per octave tilt
|
|
1211
|
+
`"tilt4.5"` | `FILTER_TILT45` | 4.5dB per octave tilt
|
|
1196
1212
|
|
|
1197
|
-
|
|
1198
|
-
--------|------------------------|---------------
|
|
1199
|
-
`""` | `FILTER_NONE` | No weighting applied (default)
|
|
1200
|
-
`"A"` | `FILTER_A` | A-weighting
|
|
1201
|
-
`"B"` | `FILTER_B` | B-weighting
|
|
1202
|
-
`"C"` | `FILTER_C` | C-weighting
|
|
1203
|
-
`"D"` | `FILTER_D` | D-weighting
|
|
1204
|
-
`"468"` | `FILTER_468` | ITU-R 468 weighting
|
|
1213
|
+
?> Refer to the [**weighting filters viewer tool**](/tools/weighting-filters.html) for filter response tables and an interactive version of the graph seen above.
|
|
1205
1214
|
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
Each filter applies a different curve of gain/attenuation to specific frequency ranges, but the general idea is to adjust the
|
|
1209
|
-
visualization of frequencies to the sensitivity of the human ear.
|
|
1210
|
-
|
|
1211
|
-
Refer to the [weighting filters viewer tool](/tools/weighting-filters.html) for response tables and an interactive version of the curves graph seen below.
|
|
1215
|
+
!> Weighting filters only affect the spectrum visualization, **NOT** the audio output.
|
|
1212
1216
|
|
|
1213
1217
|
### `width`
|
|
1214
1218
|
|
|
@@ -1232,77 +1236,121 @@ Since this is a static property, you should always access it as `AudioMotionAnal
|
|
|
1232
1236
|
|
|
1233
1237
|
## Methods
|
|
1234
1238
|
|
|
1235
|
-
### `connectInput(
|
|
1239
|
+
### `connectInput()`
|
|
1236
1240
|
|
|
1237
1241
|
*Available since v3.0.0*
|
|
1238
1242
|
|
|
1239
|
-
Connects an
|
|
1240
|
-
|
|
1243
|
+
Connects an audio source to the analyzer.
|
|
1244
|
+
|
|
1245
|
+
**Syntax:**
|
|
1246
|
+
|
|
1247
|
+
```js
|
|
1248
|
+
connectInput(source)
|
|
1249
|
+
```
|
|
1250
|
+
|
|
1251
|
+
Parameter | type | description
|
|
1252
|
+
----------|------|---------------
|
|
1253
|
+
`source` | *object* | an [AudioNode](https://developer.mozilla.org/en-US/docs/Web/API/AudioNode) (or any of its descendants), [HTMLMediaElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement) or [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream) object
|
|
1254
|
+
|
|
1255
|
+
When `source` is an *HTMLMediaElement* or *MediaStream*, a [MediaElementAudioSourceNode](https://developer.mozilla.org/en-US/docs/Web/API/MediaElementAudioSourceNode)
|
|
1256
|
+
or [MediaStreamAudioSourceNode](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioSourceNode) object will be created, respectivelly.
|
|
1241
1257
|
|
|
1242
|
-
If `source` is
|
|
1243
|
-
for that element; if `source` is an *AudioNode* instance, it returns the `source` object itself; if it's neither an [ERR_INVALID_AUDIO_SOURCE](#custom-errors) error is thrown.
|
|
1258
|
+
If `source` is not a valid object, an [`ERR_INVALID_AUDIO_SOURCE`](#custom-errors) error is thrown.
|
|
1244
1259
|
|
|
1245
|
-
|
|
1260
|
+
**Return value:** an *AudioNode* object, representing the actual audio node connected.
|
|
1246
1261
|
|
|
1247
|
-
|
|
1262
|
+
See also [`disconnectInput()`](#disconnectinput) and [`connectedSources`](#connectedsources-read-only).
|
|
1263
|
+
|
|
1264
|
+
### `connectOutput()`
|
|
1248
1265
|
|
|
1249
1266
|
*Available since v3.0.0*
|
|
1250
1267
|
|
|
1251
1268
|
This method allows connecting the analyzer **output** to other audio processing modules that use the Web Audio API.
|
|
1252
1269
|
|
|
1253
|
-
|
|
1270
|
+
**Syntax:**
|
|
1271
|
+
|
|
1272
|
+
```js
|
|
1273
|
+
connectOutput()
|
|
1274
|
+
connectOutput(node)
|
|
1275
|
+
```
|
|
1276
|
+
|
|
1277
|
+
Parameter | type | description
|
|
1278
|
+
----------|------|---------------
|
|
1279
|
+
`node` | [*AudioNode*](https://developer.mozilla.org/en-US/docs/Web/API/AudioNode) | If not specified, output is connected to the speakers (the *AudioContext* `destination` node).
|
|
1254
1280
|
|
|
1255
|
-
By default, the analyzer is connected to the speakers upon instantiation, unless you set [`connectSpeakers: false`](#connectspeakers) in the constructor options.
|
|
1281
|
+
By default, the analyzer is already connected to the speakers upon instantiation, unless you set [`connectSpeakers: false`](#connectspeakers) in the constructor options.
|
|
1256
1282
|
|
|
1257
|
-
|
|
1283
|
+
**Return value:** none (`undefined`).
|
|
1258
1284
|
|
|
1259
|
-
|
|
1285
|
+
See also [`disconnectOutput()`](#disconnectoutput) and [`connectedTo`](#connectedto-read-only).
|
|
1260
1286
|
|
|
1261
1287
|
### `destroy()`
|
|
1262
1288
|
|
|
1263
1289
|
*Available since v4.2.0*
|
|
1264
1290
|
|
|
1265
|
-
Destroys the **audioMotion-analyzer** instance and
|
|
1291
|
+
Destroys the **audioMotion-analyzer** instance and releases resources. A destroyed analyzer cannot be started again.
|
|
1292
|
+
|
|
1293
|
+
**Syntax:**
|
|
1294
|
+
|
|
1295
|
+
```js
|
|
1296
|
+
destroy()
|
|
1297
|
+
```
|
|
1266
1298
|
|
|
1267
1299
|
This method:
|
|
1268
1300
|
|
|
1269
1301
|
+ Stops the analyzer data processing and animation;
|
|
1270
1302
|
+ Disconnects all input and output nodes;
|
|
1271
1303
|
+ Clears event listeners and callback functions;
|
|
1272
|
-
+ Stops the *AudioContext* created by this instance (won't affect context provided to the [constructor](#constructor) via [`audioCtx`](#audioctx
|
|
1304
|
+
+ Stops the *AudioContext* created by this instance (won't affect context provided to the [constructor](#constructor) via [`audioCtx`](#audioctx) property or an *AudioNode* [`source`](#source));
|
|
1273
1305
|
+ Removes the [`canvas`](#canvas-htmlcanvaselement-object-read-only) from the DOM.
|
|
1274
1306
|
|
|
1275
1307
|
See usage example in the [minimal demo](/demo/minimal.html).
|
|
1276
1308
|
|
|
1309
|
+
**Return value:** none (`undefined`).
|
|
1310
|
+
|
|
1277
1311
|
See also [`isDestroyed`](#isdestroyed-read-only).
|
|
1278
1312
|
|
|
1279
|
-
### `disconnectInput(
|
|
1313
|
+
### `disconnectInput()`
|
|
1280
1314
|
|
|
1281
1315
|
*Available since v3.0.0; `stopTracks` parameter since v4.2.0*
|
|
1282
1316
|
|
|
1283
1317
|
Disconnects audio source nodes previously connected to the analyzer.
|
|
1284
1318
|
|
|
1285
|
-
|
|
1286
|
-
|
|
1319
|
+
**Syntax:**
|
|
1320
|
+
|
|
1321
|
+
```js
|
|
1322
|
+
disconnectInput()
|
|
1323
|
+
disconnectInput(sources)
|
|
1324
|
+
disconnectInput(sources, stopTracks)
|
|
1325
|
+
```
|
|
1287
1326
|
|
|
1288
|
-
|
|
1289
|
-
|
|
1327
|
+
Parameter | type | description
|
|
1328
|
+
-------------|------|---------------
|
|
1329
|
+
`sources` | *object* or *array* | a previously connected [AudioNode](https://developer.mozilla.org/en-US/docs/Web/API/AudioNode), [HTMLMediaElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement) or [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream), or an array of such objects. **When [*falsy*](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), all connected sources are disconnected.**
|
|
1330
|
+
`stopTracks` | *boolean* | if `true`, permanently stops all audio tracks from any [*MediaStream*](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream)s being disconnected.
|
|
1290
1331
|
|
|
1291
|
-
|
|
1292
|
-
created for it. The node reference is returned by [`connectInput()`](#connectinput-source-), or can be obtained from [`connectedSources`](#connectedsources-array-read-only)
|
|
1293
|
-
if the element was connected via [`source`](#source-htmlmediaelement-or-audionode-object) constructor option.
|
|
1332
|
+
**Return value:** none (`undefined`).
|
|
1294
1333
|
|
|
1295
|
-
### `disconnectOutput(
|
|
1334
|
+
### `disconnectOutput()`
|
|
1296
1335
|
|
|
1297
1336
|
*Available since v3.0.0*
|
|
1298
1337
|
|
|
1299
1338
|
Disconnects the analyzer output from previously connected audio nodes.
|
|
1300
1339
|
|
|
1301
|
-
|
|
1340
|
+
**Syntax:**
|
|
1302
1341
|
|
|
1303
|
-
|
|
1342
|
+
```js
|
|
1343
|
+
disconnectOutput()
|
|
1344
|
+
disconnectOutput(node)
|
|
1345
|
+
```
|
|
1304
1346
|
|
|
1305
|
-
|
|
1347
|
+
Parameter | type | description
|
|
1348
|
+
----------|------|---------------
|
|
1349
|
+
`node` | *AudioNode* | must be a connected *AudioNode*. If not specified, analyzer output is disconnected from all nodes, **including the speakers!**
|
|
1350
|
+
|
|
1351
|
+
**Return value:** none (`undefined`).
|
|
1352
|
+
|
|
1353
|
+
See also [`connectOutput()`](#connectoutput).
|
|
1306
1354
|
|
|
1307
1355
|
### `getBars()`
|
|
1308
1356
|
|
|
@@ -1325,7 +1373,7 @@ Returns an array with current data for each analyzer bar. Each array element is
|
|
|
1325
1373
|
`peak` and `value` elements are floats between 0 and 1, relative to the lowest and highest volume levels defined by [`minDecibels`](#mindecibels) and [`maxDecibels`](#maxdecibels).
|
|
1326
1374
|
|
|
1327
1375
|
`hold` values are integers and indicate the hold time (in frames) for the current peak.
|
|
1328
|
-
Negative values mean the peak is currently
|
|
1376
|
+
Negative values mean the peak is currently falling down or fading out.
|
|
1329
1377
|
|
|
1330
1378
|
Please note that `hold` and `value` will have only one element when [`channelLayout`](#channellayout-string) is set to *'single'*, but `peak` is always a two-element array.
|
|
1331
1379
|
|
|
@@ -1393,11 +1441,39 @@ Callbacks and [constructor-specific properties](#constructor-specific-options) a
|
|
|
1393
1441
|
|
|
1394
1442
|
See also [`setOptions()`](#setoptions).
|
|
1395
1443
|
|
|
1444
|
+
### `getScaleX()`
|
|
1445
|
+
|
|
1446
|
+
*Available since v5.0.0*
|
|
1447
|
+
|
|
1448
|
+
Returns the display properties of the X-axis scale.
|
|
1449
|
+
|
|
1450
|
+
**Syntax:**
|
|
1451
|
+
|
|
1452
|
+
```js
|
|
1453
|
+
getScaleX()
|
|
1454
|
+
```
|
|
1455
|
+
|
|
1456
|
+
**Return value:** an *object* - see [`setScaleX()`](#setscalex) for object structure.
|
|
1457
|
+
|
|
1458
|
+
### `getScaleY()`
|
|
1459
|
+
|
|
1460
|
+
*Available since v5.0.0*
|
|
1461
|
+
|
|
1462
|
+
Returns the display properties of the Y-axis scale.
|
|
1463
|
+
|
|
1464
|
+
**Syntax:**
|
|
1465
|
+
|
|
1466
|
+
```js
|
|
1467
|
+
getScaleY()
|
|
1468
|
+
```
|
|
1469
|
+
|
|
1470
|
+
**Return value:** an *object* - see [`setScaleY()`](#setscaley) for object structure.
|
|
1471
|
+
|
|
1396
1472
|
### `getTheme()`
|
|
1397
1473
|
|
|
1398
1474
|
*Available since v5.0.0*
|
|
1399
1475
|
|
|
1400
|
-
Returns the name of the theme
|
|
1476
|
+
Returns the name of the active theme, and optionally the state of theme modifiers, for the given channel.
|
|
1401
1477
|
|
|
1402
1478
|
**Syntax:**
|
|
1403
1479
|
|
|
@@ -1462,6 +1538,35 @@ Returns the names of available themes, including built-in and custom registered
|
|
|
1462
1538
|
|
|
1463
1539
|
**Return value:** an *array* of *string*s.
|
|
1464
1540
|
|
|
1541
|
+
### `getThemeModifiers()`
|
|
1542
|
+
|
|
1543
|
+
*Available since v5.0.0*
|
|
1544
|
+
|
|
1545
|
+
Returns the state of theme modifiers for the given channel.
|
|
1546
|
+
|
|
1547
|
+
**Syntax:**
|
|
1548
|
+
|
|
1549
|
+
```js
|
|
1550
|
+
getThemeModifiers()
|
|
1551
|
+
getThemeModifiers(channel)
|
|
1552
|
+
getThemeModifiers(modifier, channel)
|
|
1553
|
+
```
|
|
1554
|
+
|
|
1555
|
+
Parameter | type | description
|
|
1556
|
+
-----------|----------|-----------------
|
|
1557
|
+
`modifier` | *string* | *(optional)* desired modifier - if undefined, returns an object with all modifiers
|
|
1558
|
+
`channel` | *number* | *(optional)* channel to set (`0` = left, `1` = right) - if not specified, considers channel 0
|
|
1559
|
+
|
|
1560
|
+
**Return value:** a *boolean* representing the state of the selected modifier, when `modifier` is specified;
|
|
1561
|
+
otherwise, an *object* with the structure below:
|
|
1562
|
+
|
|
1563
|
+
property | type | description
|
|
1564
|
+
-------------|-----------|---------------
|
|
1565
|
+
`horizontal` | *boolean* | If `true`, the color gradient is rendered horizontally, instead of vertically
|
|
1566
|
+
`revert` | *boolean* | If `true`, reverses the order in which theme colors are applied
|
|
1567
|
+
|
|
1568
|
+
See also [`getTheme()`](#gettheme) and [`setThemeModifiers()`](#setthememodifiers).
|
|
1569
|
+
|
|
1465
1570
|
### `registerTheme()`
|
|
1466
1571
|
|
|
1467
1572
|
*Available since v5.0.0; formerly `registerGradient()` (since v1.0.0)*
|
|
@@ -1486,7 +1591,7 @@ property | type | description
|
|
|
1486
1591
|
`colorStops` | *array* | **At least one array element is required.** Each one must be either a *string* (color in CSS format), or an *object* (see below).
|
|
1487
1592
|
`peakColor` | *string* | Optional; if defined, **all peaks** will be painted this color, regardless of their levels.
|
|
1488
1593
|
|
|
1489
|
-
**`colorStops`
|
|
1594
|
+
**`colorStops` entry object structure:**
|
|
1490
1595
|
|
|
1491
1596
|
property | type | description
|
|
1492
1597
|
---------|--------|-------------
|
|
@@ -1619,153 +1724,148 @@ setSensitivity(minDecibels, maxDecibels)
|
|
|
1619
1724
|
|
|
1620
1725
|
**Return value:** none (`undefined`).
|
|
1621
1726
|
|
|
1622
|
-
### `
|
|
1727
|
+
### `setScaleX()`
|
|
1623
1728
|
|
|
1624
1729
|
*Available since v5.0.0*
|
|
1625
1730
|
|
|
1626
|
-
|
|
1731
|
+
Customize the appearance of the X-axis scale and labels.
|
|
1627
1732
|
|
|
1628
1733
|
**Syntax:**
|
|
1629
1734
|
|
|
1630
1735
|
```js
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
setTheme(themeObject, channel)
|
|
1736
|
+
setScaleX()
|
|
1737
|
+
setScaleX(options)
|
|
1634
1738
|
```
|
|
1635
1739
|
|
|
1636
|
-
|
|
1637
|
-
--------------|--------|------------------
|
|
1638
|
-
`name` | *string* or *array* | theme name, or an array of theme names - must be a name as returned by [`getThemeList()`](#getthemelist)
|
|
1639
|
-
`modifiers` | *object* | *(optional)* a modifiers object, as returned by [`getThemeModifiers()`](#getthememodifiers)
|
|
1640
|
-
`themeObject` | *object* or *array* | a theme object, as returned by [`getTheme()`](#gettheme) or an array of such objects
|
|
1641
|
-
`channel` | *number* | *(optional)* channel to set (`0` = left, `1` = right)
|
|
1740
|
+
**If called with no argument, all properties will be reset to their default values.**
|
|
1642
1741
|
|
|
1643
|
-
|
|
1644
|
-
When using a single `name` or `themeObject`, if `channel` is not specified, the same theme will be applied to both channels.
|
|
1742
|
+
If `options` is defined, it should be an object with the structure below (all properties are optional).
|
|
1645
1743
|
|
|
1646
|
-
|
|
1744
|
+
property | type | description | default
|
|
1745
|
+
-------------------|-----------|-------------|---------
|
|
1746
|
+
`backgroundColor` | *string* | Background color of the X-axis. Any valid CSS color format is acceptable. Use a blank string or `"transparent"` for fully transparent background | `"#0008"`
|
|
1747
|
+
`color` | *string* | Color of labels | `"#fff"`
|
|
1748
|
+
`fontSize` | *number* | Font size for labels. Values between `0.0` and `1.0` (recommended for responsivity) represent a fraction of one tenth of the smallest canvas dimension (width or height). A minimum of 10px is enforced for the computed size. Values greater than `1` are interpreted as fixed pixel sizes. | `0.15`
|
|
1749
|
+
`highlightColor` | *string* | Color used to highlight *C* notes when [`showScaleX`](#showscalex) is set to `"notes"`, and for labels highlighted via `labels` property (see below) | `"#4f4"`
|
|
1750
|
+
`labels` | *array* | Custom labels displayed when [`showScaleX`](#showscalex) is set to `"custom"` or `"freqs-custom"`. Each element of the array must be either a number, representing the frequency in Hz, or an array of **[ <frequency> *(number)*, <label> *(string)*, <highlight> *(boolean, optional)* ]** (see example below) | octaves center frequencies
|
|
1751
|
+
`overlay` | *boolean* | Whether the X-axis should overlay the bottom of the analyzer area | `false`
|
|
1647
1752
|
|
|
1648
1753
|
**Return value:** none (`undefined`).
|
|
1649
1754
|
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
### `setThemeModifiers()`
|
|
1653
|
-
|
|
1654
|
-
**Syntax:**
|
|
1755
|
+
**Example usage:**
|
|
1655
1756
|
|
|
1656
1757
|
```js
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1758
|
+
audioMotion.setScaleX({
|
|
1759
|
+
backgroundColor: '', // transparent background on the axis bar
|
|
1760
|
+
labels: [
|
|
1761
|
+
[ 440, 'A4', true ], // highlight "A4" label at 440 Hz
|
|
1762
|
+
800, // additional label at 800 Hz
|
|
1763
|
+
[ 3000, '|' ], // just a tick mark at 3 kHz
|
|
1764
|
+
],
|
|
1765
|
+
});
|
|
1660
1766
|
```
|
|
1661
1767
|
|
|
1662
|
-
|
|
1663
|
-
--------------|--------|------------------
|
|
1664
|
-
`modifier` | *string* | modifier to set (see below)
|
|
1665
|
-
`state` | *boolean* | desired state for selected modifier
|
|
1666
|
-
`modifiersObject` | *object* | modifiers object, as returned by [`getThemeModifiers()`](#getthememodifiers)
|
|
1667
|
-
`channel` | *number* | *(optional)* channel to set (`0` = left, `1` = right)
|
|
1768
|
+
See also [`showScaleX`](#showscalex).
|
|
1668
1769
|
|
|
1669
|
-
|
|
1670
|
-
---------|----------------
|
|
1671
|
-
`"horizontal"` | Renders the color gradient horizontally across the screen, instead of vertically - has no effect in [`radial`](#radial) spectrum or when [`ledBars`](#ledbars) is set to `"vintage"`
|
|
1672
|
-
`"revert"` | Reverts the order of the theme colors
|
|
1673
|
-
|
|
1674
|
-
**Return value:** none (`undefined`).
|
|
1675
|
-
|
|
1676
|
-
### `setXAxis()`
|
|
1770
|
+
### `setScaleY()`
|
|
1677
1771
|
|
|
1678
1772
|
*Available since v5.0.0*
|
|
1679
1773
|
|
|
1680
|
-
Customize the appearance of the
|
|
1774
|
+
Customize the appearance of the Y-axis scale and labels.
|
|
1681
1775
|
|
|
1682
1776
|
**Syntax:**
|
|
1683
1777
|
|
|
1684
1778
|
```js
|
|
1685
|
-
|
|
1686
|
-
|
|
1779
|
+
setScaleY()
|
|
1780
|
+
setScaleY(options)
|
|
1687
1781
|
```
|
|
1688
1782
|
|
|
1689
|
-
**If called with no argument, all properties will be reset to their default values.**
|
|
1783
|
+
**If called with no argument, all properties will be reset to their default values.**
|
|
1690
1784
|
|
|
1691
1785
|
If `options` is defined, it should be an object with the structure below (all properties are optional).
|
|
1692
1786
|
|
|
1693
1787
|
property | type | description | default
|
|
1694
1788
|
-------------------|-----------|-------------|---------
|
|
1695
|
-
`
|
|
1696
|
-
`
|
|
1697
|
-
`
|
|
1698
|
-
`
|
|
1699
|
-
`
|
|
1700
|
-
`
|
|
1701
|
-
`
|
|
1789
|
+
`color` | *string* | Color of labels and lines | `"#888"`
|
|
1790
|
+
`dbInterval` | *number* | Interval between labels, in decibels. Applied when [`showScaleY`](#showscaley) is set to `"db"`. | `6`
|
|
1791
|
+
`fontSize` | *number* | Font size for labels. Values between `0.0` and `1.0` (recommended for responsivity) represent a fraction of one tenth of the smallest canvas dimension (width or height). A minimum of 10px is enforced for the computed size. Values greater than `1` are interpreted as fixed pixel sizes. | `0.15`
|
|
1792
|
+
`lineDash` | *array* | Line style. See [format reference](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash) | `[2,4]`
|
|
1793
|
+
`operation` | *string* | Compositing operation used to draw labels and lines. See [Reference](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation). **Note: some operations may hinder or prevent the proper visualization of analyzer graphs.** | `"destination-over"`
|
|
1794
|
+
`percentInterval` | *number* | Interval between labels, in percentage values. Applied when [`showScaleY`](#showscaley) is set to `"percent"` | `20`
|
|
1795
|
+
`showSubdivisions` | *boolean* | Whether to show subdivision lines between two labels | `true`
|
|
1796
|
+
`showUnit` | *boolean* | Whether to display the scale unit ("dB" or "%") at the top of the axis | `true`
|
|
1797
|
+
`subLineColor` | *string* | Line color used for subdivisions | `"#555"`
|
|
1798
|
+
`subLineDash` | *array* | Line style for subdivisions (see `lineDash` above) | `[2,8]`
|
|
1702
1799
|
|
|
1703
1800
|
**Return value:** none (`undefined`).
|
|
1704
1801
|
|
|
1705
1802
|
**Example usage:**
|
|
1706
1803
|
|
|
1707
1804
|
```js
|
|
1708
|
-
audioMotion.
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
[ 440, 'A4', true ], // highlight A4 label at 440 Hz
|
|
1713
|
-
800, // additional label at 800 Hz
|
|
1714
|
-
[ 3000, '|' ], // just a tick mark at 3 kHz
|
|
1715
|
-
],
|
|
1805
|
+
audioMotion.setScaleY({
|
|
1806
|
+
percentInterval: 10,
|
|
1807
|
+
operation: 'screen',
|
|
1808
|
+
showSubdivisions: false,
|
|
1716
1809
|
});
|
|
1717
1810
|
```
|
|
1718
1811
|
|
|
1719
|
-
|
|
1720
|
-
>
|
|
1721
|
-
> - The axis height also defines the labels font size (half its value). A minimum of 20 pixels is enforced for the computed `height` value;
|
|
1722
|
-
> - Custom labels are not displayed when [`noteLabels`](#notelabels) is *true*.
|
|
1812
|
+
See also [`showScaleY`](#showscaley).
|
|
1723
1813
|
|
|
1724
|
-
### `
|
|
1814
|
+
### `setTheme()`
|
|
1725
1815
|
|
|
1726
1816
|
*Available since v5.0.0*
|
|
1727
1817
|
|
|
1728
|
-
|
|
1818
|
+
Sets the color theme for one or both analyzer channels.
|
|
1729
1819
|
|
|
1730
1820
|
**Syntax:**
|
|
1731
1821
|
|
|
1732
1822
|
```js
|
|
1733
|
-
|
|
1734
|
-
|
|
1823
|
+
setTheme(name, channel)
|
|
1824
|
+
setTheme(name, modifiers, channel)
|
|
1825
|
+
setTheme(themeObject, channel)
|
|
1735
1826
|
```
|
|
1736
1827
|
|
|
1737
|
-
|
|
1828
|
+
Parameter | type | description
|
|
1829
|
+
--------------|--------|------------------
|
|
1830
|
+
`name` | *string* or *array* | theme name, or an array of theme names - must be a name as returned by [`getThemeList()`](#getthemelist)
|
|
1831
|
+
`modifiers` | *object* | *(optional)* a modifiers object, as returned by [`getThemeModifiers()`](#getthememodifiers)
|
|
1832
|
+
`themeObject` | *object* or *array* | a theme object, as returned by [`getTheme()`](#gettheme) or an array of such objects
|
|
1833
|
+
`channel` | *number* | *(optional)* channel to set (`0` = left, `1` = right)
|
|
1738
1834
|
|
|
1739
|
-
|
|
1835
|
+
When passing arrays for `name` or `themeObject` you can assign different themes to each channel at once.
|
|
1836
|
+
When using a single `name` or `themeObject`, if `channel` is not specified, the same theme will be applied to both channels.
|
|
1740
1837
|
|
|
1741
|
-
|
|
1742
|
-
-----------------|---------|-------------|---------
|
|
1743
|
-
color | string | Color of labels and lines | `"#888"`
|
|
1744
|
-
dbInterval | number | Interval between labels, in decibels - used when [`linearAmplitude`](#linearamplitude) is *false* | `10`
|
|
1745
|
-
linearInterval | number | Interval between labels, in percentage values - used when [`linearAmplitude`](#linearamplitude) is *true* | `20`
|
|
1746
|
-
lineDash | array | Line style - [format reference](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash) | `[2,4]`
|
|
1747
|
-
operation | array | Compositing operation used to draw labels and lines - [Reference](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation) | `"destination-over"`
|
|
1748
|
-
showSubdivisions | array | Whether to show subdivision lines between two labels | `true`
|
|
1749
|
-
subLineColor | string | Line color used for subdivisions | `"#555"`
|
|
1750
|
-
subLineDash | array | Line style for subdivisions (see `lineDash` above) | `[2,8]``
|
|
1751
|
-
width | number | Width of the Y-axis; a number between `0.0` and `1.0` represents a fraction of the canvas width or height, whichever is smaller; numbers greater than `1` represent a fixed value in pixels | `0.03`
|
|
1838
|
+
!> Note that when setting theme modifiers, properties not defined in the passed object will be reset to their default values. To selectively enable or disable modifiers while preserving others, use [`setThemeModifiers( name, state )`](#setthememodifiers).
|
|
1752
1839
|
|
|
1753
1840
|
**Return value:** none (`undefined`).
|
|
1754
1841
|
|
|
1755
|
-
|
|
1842
|
+
See also [`channelLayout`](#channellayout), [`registerTheme()`](#registertheme) and [`spreadGradient`](#spreadgradient).
|
|
1843
|
+
|
|
1844
|
+
### `setThemeModifiers()`
|
|
1845
|
+
|
|
1846
|
+
**Syntax:**
|
|
1756
1847
|
|
|
1757
1848
|
```js
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
showSubdivisions: false,
|
|
1762
|
-
});
|
|
1849
|
+
setThemeModifiers()
|
|
1850
|
+
setThemeModifiers(modifier, state, channel)
|
|
1851
|
+
setThemeModifiers(modifiersObject, channel)
|
|
1763
1852
|
```
|
|
1764
1853
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1854
|
+
Parameter | type | description
|
|
1855
|
+
--------------|--------|------------------
|
|
1856
|
+
`modifier` | *string* | modifier to set (see below)
|
|
1857
|
+
`state` | *boolean* | desired state for selected modifier
|
|
1858
|
+
`modifiersObject` | *object* | modifiers object, as returned by [`getThemeModifiers()`](#getthememodifiers)
|
|
1859
|
+
`channel` | *number* | *(optional)* channel to set (`0` = left, `1` = right)
|
|
1860
|
+
|
|
1861
|
+
Modifier | description
|
|
1862
|
+
---------|----------------
|
|
1863
|
+
`"horizontal"` | Renders the color gradient horizontally across the screen, instead of vertically - has no effect in [`radial`](#radial) spectrum or when [`ledBars`](#ledbars) is set to `"vintage"`
|
|
1864
|
+
`"revert"` | Reverts the order of the theme colors
|
|
1865
|
+
|
|
1866
|
+
**Return value:** none (`undefined`).
|
|
1867
|
+
|
|
1868
|
+
See also [`toggleThemeModifier()`](#togglethememodifier) and [`setTheme()`](#settheme).
|
|
1769
1869
|
|
|
1770
1870
|
### `start()`
|
|
1771
1871
|
|
|
@@ -1823,6 +1923,27 @@ You can set the [`fsElement`](#fselement-htmlelement-object) constructor option
|
|
|
1823
1923
|
|
|
1824
1924
|
?> Fullscreen requests must be triggered by user action, like a key press or mouse click, so you must call this method from within a user-generated event handler.
|
|
1825
1925
|
|
|
1926
|
+
### `toggleThemeModifier()`
|
|
1927
|
+
|
|
1928
|
+
*Available since v5.0.0*
|
|
1929
|
+
|
|
1930
|
+
Toggles the state of a theme modifier for the given channel.
|
|
1931
|
+
|
|
1932
|
+
**Syntax:**
|
|
1933
|
+
|
|
1934
|
+
```js
|
|
1935
|
+
toggleThemeModifier(modifier, channel)
|
|
1936
|
+
```
|
|
1937
|
+
|
|
1938
|
+
Parameter | type | description
|
|
1939
|
+
-----------|----------|-----------------
|
|
1940
|
+
`modifier` | *string* | desired modifier
|
|
1941
|
+
`channel` | *number* | *(optional)* desired channel (`0` = left, `1` = right) - **if not specified, toggles modifier on both channels**
|
|
1942
|
+
|
|
1943
|
+
**Return value:** none (`undefined`).
|
|
1944
|
+
|
|
1945
|
+
See also [`setThemeModifiers()`](#setthememodifiers) and [`setTheme()`](#settheme).
|
|
1946
|
+
|
|
1826
1947
|
|
|
1827
1948
|
## Custom Errors
|
|
1828
1949
|
|
|
@@ -1865,7 +1986,7 @@ The `import` statement must be inside a `script` which has the `type="module"` p
|
|
|
1865
1986
|
|
|
1866
1987
|
```html
|
|
1867
1988
|
<script type="module">
|
|
1868
|
-
import AudioMotionAnalyzer from 'https://cdn.
|
|
1989
|
+
import AudioMotionAnalyzer from 'https://cdn.jsdelivr.net/npm/audiomotion-analyzer@alpha/+esm';
|
|
1869
1990
|
|
|
1870
1991
|
// your code here
|
|
1871
1992
|
</script>
|
|
@@ -1894,7 +2015,7 @@ myAudio.crossOrigin = 'anonymous';
|
|
|
1894
2015
|
### Sound only plays after the user clicks somewhere on the page. <!-- {docsify-ignore} -->
|
|
1895
2016
|
|
|
1896
2017
|
Browser autoplay policy dictates that audio output can only be initiated by a user gesture, and this policy is enforced by Web Audio API
|
|
1897
|
-
by putting [*AudioContext*](#audioctx-
|
|
2018
|
+
by putting [*AudioContext*](#audioctx-read-only) objects into *suspended* mode if they're not created on user action.
|
|
1898
2019
|
|
|
1899
2020
|
**audioMotion-analyzer** tries to automatically start its *AudioContext* on the first click on the page. However, if you're using an `audio`
|
|
1900
2021
|
or `video` element with the `controls` property, clicks on those native media controls cannot be detected by JavaScript, so the audio will
|