forked from likethemammal/css-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.js
51 lines (41 loc) · 1.27 KB
/
base.js
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
var Visualizers = Visualizers || {}
Visualizers.Base = {
visualizer: document.getElementById('visualizer'),
AnimationTimer: '',
run: function() {
this.clear();
Visualizers.currentVisualizer = this;
this.init();
var fps = 60
if (this.fps) {
var fps = this.fps;
}
this.AnimationTimer = setInterval(_.bind(this.getData, this), 50 + (60 - this.fps));
},
clear: function() {
var styleSheet = document.getElementById('visualizer-css');
if (styleSheet) {
document.head.removeChild(styleSheet);
}
this.visualizer.innerHTML = '';
},
getData: function() {
if (dancer.isPlaying()) {
var spectrum, waveform;
if (this.onSpectrum) {
spectrum = float32ToArray(dancer.getSpectrum());
this.onSpectrum(spectrum);
}
if (this.onWaveform) {
waveform = float32ToArray(dancer.getWaveform());
this.onWaveform(waveform);
}
}
},
destroy: function() {
clearInterval(this.AnimationTimer);
if (this.onDestroy) {
this.onDestroy();
}
}
};