-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalyserNode.cljs
252 lines (185 loc) · 9.32 KB
/
AnalyserNode.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
(ns web.audio.AnalyserNode
"The AnalyserNode interface represents a node able to provide
frequency and time-domain analysis information. It is an `web.audio.AudioNode`
passes the audio stream unchanged from the input to the output,
allows you to take the generated data, process it, and create
visualizations."
(:refer-clojure :exclude []))
(def constructor
"Constructor.
The AnalyserNode constructor of the Web Audio API creates a new `web.audio.AnalyserNode` object instance.
Inherits parameters from the `web.audio.AudioNodeOptions` dictionary.
\\tcontext
\\tA reference to an `web.audio.AudioContext` or `web.audio.OfflineAudioContext`.
\\toptions Optional
\\t\\tfftSize: The desired initial size of the FFT for frequency-domain analysis.
\\t\\tThe default is 2048.
\\t\\tmaxDecibels: The desired initial maximum power in dB for FFT analysis.
\\t\\tThe default is -30.
\\t\\tminDecibels: The desired initial minimum power in dB for FFT analysis.
\\t\\tThe default is -100.
\\t\\tsmoothingTimeConstant: The desired initial smoothing constant for the FFT analysis. The default is 0.8.
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/AnalyserNode`"
js/AnalyserNode)
(defn get-float-frequency-data
"Method.
The getFloatFrequencyData() method of the `web.audio.AnalyserNode`
copies the current frequency data into a `js.Float32Array` array
into it.
`var audioCtx = new AudioContext();
var analyser = audioCtx.createAnalyser();
var dataArray = new Float32Array(analyser.frequencyBinCount); // Float32Array should be the same length as the frequencyBinCount
void analyser.getFloatFrequencyData(dataArray); // fill the Float32Array with data returned from getFloatFrequencyData()`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getFloatFrequencyData`"
[this & args]
(-> this .-getFloatFrequencyData (.apply this (clj->js args))))
(defn get-byte-frequency-data
"Method.
The getByteFrequencyData() method of the `web.audio.AnalyserNode`
copies the current frequency data into a `js.Uint8Array` (unsigned
array) passed into it.
`var audioCtx = new AudioContext();
var analyser = audioCtx.createAnalyser();
var dataArray = new Uint8Array(analyser.frequencyBinCount); // Uint8Array should be the same length as the frequencyBinCount
void analyser.getByteFrequencyData(dataArray); // fill the Uint8Array with data returned from getByteFrequencyData()`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteFrequencyData`"
[this & args]
(-> this .-getByteFrequencyData (.apply this (clj->js args))))
(defn get-float-time-domain-data
"Method.
The getFloatTimeDomainData() method of the `web.audio.AnalyserNode`
copies the current waveform, or time-domain, data into a `js.Float32Array`
passed into it.
`var audioCtx = new AudioContext();
var analyser = audioCtx.createAnalyser();
var dataArray = new Float32Array(analyser.fftSize); // Float32Array needs to be the same length as the fftSize
analyser.getFloatTimeDomainData(dataArray); // fill the Float32Array with data returned from getFloatTimeDomainData()`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getFloatTimeDomainData`"
[this & args]
(-> this .-getFloatTimeDomainData (.apply this (clj->js args))))
(defn get-byte-time-domain-data
"Method.
The getByteTimeDomainData() method of the `web.audio.AnalyserNode`
copies the current waveform, or time-domain, data into a `js.Uint8Array`
byte array) passed into it.
`const audioCtx = new AudioContext();
const analyser = audioCtx.createAnalyser();
const dataArray = new Uint8Array(analyser.fftSize); // Uint8Array should be the same length as the fftSize
analyser.getByteTimeDomainData(dataArray); // fill the Uint8Array with data returned from getByteTimeDomainData()`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteTimeDomainData`"
[this & args]
(-> this .-getByteTimeDomainData (.apply this (clj->js args))))
(defn fft-size
"Property.
The fftSize property of the `web.audio.AnalyserNode` interface
an unsigned long value and represents the window size in samples
is used when performing a Fast Fourier Transform (FFT) to get
domain data.
`var curValue = analyserNode.fftSize;
analyserNode.fftSize = newValue;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize`"
[this]
(-> this (.-fftSize)))
(defn set-fft-size!
"Property.
The fftSize property of the `web.audio.AnalyserNode` interface
an unsigned long value and represents the window size in samples
is used when performing a Fast Fourier Transform (FFT) to get
domain data.
`var curValue = analyserNode.fftSize;
analyserNode.fftSize = newValue;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize`"
[this val]
(aset this "fftSize" val))
(defn frequency-bin-count
"Property.
The frequencyBinCount read-only property of the `web.audio.AnalyserNode`
is an unsigned integer half that of the `AnalyserNode.fftSize`.
generally equates to the number of data values you will have
play with for the visualization.
`var arrayLength = analyserNode.frequencyBinCount;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/frequencyBinCount`"
[this]
(-> this (.-frequencyBinCount)))
(defn set-frequency-bin-count!
"Property.
The frequencyBinCount read-only property of the `web.audio.AnalyserNode`
is an unsigned integer half that of the `AnalyserNode.fftSize`.
generally equates to the number of data values you will have
play with for the visualization.
`var arrayLength = analyserNode.frequencyBinCount;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/frequencyBinCount`"
[this val]
(aset this "frequencyBinCount" val))
(defn min-decibels
"Property.
The minDecibels property of the `web.audio.AnalyserNode` interface
a double value representing the minimum power value in the scaling
for the FFT analysis data, for conversion to unsigned byte/float
— basically, this specifies the minimum value for the range of
when using getFloatFrequencyData() or getByteFrequencyData().
`var curValue = analyserNode.minDecibels;
analyserNode.minDecibels = newValue;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/minDecibels`"
[this]
(-> this (.-minDecibels)))
(defn set-min-decibels!
"Property.
The minDecibels property of the `web.audio.AnalyserNode` interface
a double value representing the minimum power value in the scaling
for the FFT analysis data, for conversion to unsigned byte/float
— basically, this specifies the minimum value for the range of
when using getFloatFrequencyData() or getByteFrequencyData().
`var curValue = analyserNode.minDecibels;
analyserNode.minDecibels = newValue;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/minDecibels`"
[this val]
(aset this "minDecibels" val))
(defn max-decibels
"Property.
The maxDecibels property of the `web.audio.AnalyserNode` interface
a double value representing the maximum power value in the scaling
for the FFT analysis data, for conversion to unsigned byte/float
— basically, this specifies the maximum value for the range of
when using getFloatFrequencyData() or getByteFrequencyData().
`var curValue = analyserNode.maxDecibels;
analyserNode.maxDecibels = newValue;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/maxDecibels`"
[this]
(-> this (.-maxDecibels)))
(defn set-max-decibels!
"Property.
The maxDecibels property of the `web.audio.AnalyserNode` interface
a double value representing the maximum power value in the scaling
for the FFT analysis data, for conversion to unsigned byte/float
— basically, this specifies the maximum value for the range of
when using getFloatFrequencyData() or getByteFrequencyData().
`var curValue = analyserNode.maxDecibels;
analyserNode.maxDecibels = newValue;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/maxDecibels`"
[this val]
(aset this "maxDecibels" val))
(defn smoothing-time-constant
"Property.
The smoothingTimeConstant property of the `web.audio.AnalyserNode`
is a double value representing the averaging constant with the
analysis frame. It's basically an average between the current
and the last buffer the AnalyserNode processed, and results in
much smoother set of value changes over time.
`var smoothValue = analyserNode.smoothingTimeConstant;
analyserNode.smoothingTimeConstant = newValue;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant`"
[this]
(-> this (.-smoothingTimeConstant)))
(defn set-smoothing-time-constant!
"Property.
The smoothingTimeConstant property of the `web.audio.AnalyserNode`
is a double value representing the averaging constant with the
analysis frame. It's basically an average between the current
and the last buffer the AnalyserNode processed, and results in
much smoother set of value changes over time.
`var smoothValue = analyserNode.smoothingTimeConstant;
analyserNode.smoothingTimeConstant = newValue;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant`"
[this val]
(aset this "smoothingTimeConstant" val))