mgokg commited on
Commit
06df230
·
verified ·
1 Parent(s): 93f353c

Upload analyser.ts

Browse files
Files changed (1) hide show
  1. analyser.ts +28 -0
analyser.ts ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Analyser class for live audio visualisation.
7
+ */
8
+ export class Analyser {
9
+ private analyser: AnalyserNode;
10
+ private bufferLength = 0;
11
+ private dataArray: Uint8Array;
12
+
13
+ constructor(node: AudioNode) {
14
+ this.analyser = node.context.createAnalyser();
15
+ this.analyser.fftSize = 32;
16
+ this.bufferLength = this.analyser.frequencyBinCount;
17
+ this.dataArray = new Uint8Array(this.bufferLength);
18
+ node.connect(this.analyser);
19
+ }
20
+
21
+ update() {
22
+ this.analyser.getByteFrequencyData(this.dataArray);
23
+ }
24
+
25
+ get data() {
26
+ return this.dataArray;
27
+ }
28
+ }