File tree 1 file changed +12
-11
lines changed
1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 1
- function AudioAnalyser ( audio , fftSize ) {
1
+ class AudioAnalyser {
2
2
3
- this . analyser = audio . context . createAnalyser ( ) ;
4
- this . analyser . fftSize = fftSize !== undefined ? fftSize : 2048 ;
3
+ constructor ( audio , fftSize ) {
5
4
6
- this . data = new Uint8Array ( this . analyser . frequencyBinCount ) ;
5
+ this . analyser = audio . context . createAnalyser ( ) ;
6
+ this . analyser . fftSize = fftSize !== undefined ? fftSize : 2048 ;
7
7
8
- audio . getOutput ( ) . connect ( this . analyser ) ;
8
+ this . data = new Uint8Array ( this . analyser . frequencyBinCount ) ;
9
9
10
- }
10
+ audio . getOutput ( ) . connect ( this . analyser ) ;
11
+
12
+ }
11
13
12
- Object . assign ( AudioAnalyser . prototype , {
13
14
14
- getFrequencyData : function ( ) {
15
+ getFrequencyData ( ) {
15
16
16
17
this . analyser . getByteFrequencyData ( this . data ) ;
17
18
18
19
return this . data ;
19
20
20
- } ,
21
+ }
21
22
22
- getAverageFrequency : function ( ) {
23
+ getAverageFrequency ( ) {
23
24
24
25
let value = 0 ;
25
26
const data = this . getFrequencyData ( ) ;
@@ -34,6 +35,6 @@ Object.assign( AudioAnalyser.prototype, {
34
35
35
36
}
36
37
37
- } ) ;
38
+ }
38
39
39
40
export { AudioAnalyser } ;
You can’t perform that action at this time.
0 commit comments