@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
68 lines (67 loc) • 2.03 kB
JavaScript
;
import { Chebyshev } from "tone/build/esm/effect/Chebyshev";
const DEFAULTS = { order: 4, oversample: "none" };
const OVER_SAMPLE_TYPES = ["2x", "4x", "none"];
import { TypedAudioNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { effectParamsOptions } from "./utils/EffectsController";
const paramCallback = (node) => {
ChebyshevAudioNode.PARAM_CALLBACK_updateEffect(node);
};
class ChebyshevAudioParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param order */
this.order = ParamConfig.INTEGER(DEFAULTS.order, {
range: [1, 100],
rangeLocked: [true, true],
...effectParamsOptions(paramCallback)
});
/** @param oversample */
this.oversample = ParamConfig.INTEGER(OVER_SAMPLE_TYPES.indexOf(DEFAULTS.oversample), {
menu: {
entries: OVER_SAMPLE_TYPES.map((name, value) => ({ name, value }))
}
});
}
}
const ParamsConfig = new ChebyshevAudioParamsConfig();
export class ChebyshevAudioNode extends TypedAudioNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "chebyshev";
}
initializeNode() {
this.io.inputs.setCount(1);
}
cook(inputContents) {
const audioBuilder = inputContents[0];
const effect = this._effect();
const inputNode = audioBuilder.audioNode();
if (inputNode) {
inputNode.connect(effect);
}
audioBuilder.setAudioNode(effect);
this.setAudioBuilder(audioBuilder);
}
_effect() {
return this.__effect__ = this.__effect__ || this._createEffect();
}
_createEffect() {
return new Chebyshev({
order: this.pv.order,
oversample: OVER_SAMPLE_TYPES[this.pv.oversample]
});
}
static PARAM_CALLBACK_updateEffect(node) {
node._updateEffect();
}
_updateEffect() {
const effect = this._effect();
effect.order = this.pv.order;
effect.oversample = OVER_SAMPLE_TYPES[this.pv.oversample];
}
}