-
Notifications
You must be signed in to change notification settings - Fork 0
/
iir-filter.js
49 lines (39 loc) · 1.1 KB
/
iir-filter.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
import React from "react";
import RConnectableNode from "./../base/connectable-node.js";
import PropTypes from "prop-types";
export default class RIIRFilter extends RConnectableNode {
constructor(props) {
super(props);
this.params = {};
}
componentWillMount() {
super.componentWillMount();
if (!this.node) {
this.node = this.context.audio.createIIRFilter({
feedback: this.props.feedback,
feedforward: this.props.feedforward,
});
this.context.nodes.set(this.props.identifier, this.node);
}
this.updateParams = this.updateParams.bind(this);
this.updateParams(this.props);
}
render() {
if (typeof this.props.children === "function") {
const filterProxy = Object.freeze({
getFrequencyResponse: (frequencyHz, magResponse, phaseResponse) => {
return this.node.getFrequencyResponse(
frequencyHz,
magResponse,
phaseResponse
);
},
});
this.props.children(filterProxy);
}
return super.render();
}
}
RIIRFilter.propTypes = {
children: PropTypes.func,
};