UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

75 lines (74 loc) 2.3 kB
"use strict"; import { Chorus } from "tone/build/esm/effect/Chorus"; const DEFAULTS = { delayTime: 3.5, depth: 0.7, feedback: 0, frequency: 1.5, spread: 180, type: "sine", wet: 0.5 }; import { TypedAudioNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { effectParamsOptions } from "./utils/EffectsController"; const paramCallback = (node) => { ChorusAudioNode.PARAM_CALLBACK_updateEffect(node); }; class ChorusAudioParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param The frequency of the LFO. */ this.frequency = ParamConfig.FLOAT(DEFAULTS.frequency, { range: [0, 10], rangeLocked: [true, false] // no callback allowed for frequency as it is a readonly property // ...effectParamsOptions(paramCallback), }); /** The delay of the chorus effect in ms */ this.delayTime = ParamConfig.FLOAT(DEFAULTS.delayTime, { range: [0, 1], rangeLocked: [true, false], ...effectParamsOptions(paramCallback) }); /** The depth of the chorus */ this.depth = ParamConfig.FLOAT(DEFAULTS.depth, { range: [0, 1], rangeLocked: [true, false], ...effectParamsOptions(paramCallback) }); } } const ParamsConfig = new ChorusAudioParamsConfig(); export class ChorusAudioNode extends TypedAudioNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "chorus"; } 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 Chorus({ frequency: this.pv.frequency, delayTime: this.pv.delayTime, depth: this.pv.depth }); } static PARAM_CALLBACK_updateEffect(node) { node._updateEffect(); } _updateEffect() { const effect = this._effect(); effect.delayTime = this.pv.delayTime; effect.depth = this.pv.depth; } }