-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyser.js
54 lines (45 loc) · 1.39 KB
/
analyser.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
52
53
54
import React from "react";
import RConnectableNode from "./../base/connectable-node.js";
import PropTypes from "prop-types";
export default class RAnalyser extends RConnectableNode {
constructor(props) {
super(props);
this.params = {
fftSize: this.props.fftSize,
minDecibels: this.props.minDecibels,
maxDecibels: this.props.maxDecibels,
smoothingTimeConstant: this.props.smoothingTimeConstant,
};
}
componentWillMount() {
super.componentWillMount();
if (!this.node) {
this.node = this.context.audio.createAnalyser();
this.context.nodes.set(this.props.identifier, this.node);
}
this.updateParams = this.updateParams.bind(this);
this.updateParams(this.props);
}
render() {
const analyserProxy = Object.freeze({
getFloatFrequencyData: (array) => {
return this.node.getFloatFrequencyData(array);
},
getByteFrequencyData: (array) => {
return this.node.getByteFrequencyData(array);
},
getFloatTimeDomainData: (array) => {
return this.node.getFloatTimeDomainData(array);
},
getByteTimeDomainData: (array) => {
return this.node.getByteTimeDomainData(array);
},
frequencyBinCount: this.node.frequencyBinCount,
});
this.props.children(analyserProxy);
return super.render();
}
}
RAnalyser.propTypes = {
children: PropTypes.func.isRequired,
};