UNPKG

@polygonjs/polygonjs

Version:

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

70 lines (69 loc) 1.95 kB
"use strict"; import { Reverb } from "tone/build/esm/effect/Reverb"; const DEFAULTS = { decay: 1.5, preDelay: 0.01 }; import { TypedAudioNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { effectParamsOptions } from "./utils/EffectsController"; const paramCallback = (node) => { ReverbAudioNode.PARAM_CALLBACK_updateEffect(node); }; class ReverbAudioParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param The duration of the reverb. */ this.decay = ParamConfig.FLOAT(DEFAULTS.decay, { range: [1e-3, 10], rangeLocked: [true, false], ...effectParamsOptions(paramCallback) }); /** The amount of time before the reverb is fully ramped in */ this.preDelay = ParamConfig.FLOAT(DEFAULTS.preDelay, { range: [0, 1], rangeLocked: [true, false], ...effectParamsOptions(paramCallback) }); } } const ParamsConfig = new ReverbAudioParamsConfig(); export class ReverbAudioNode extends TypedAudioNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "reverb"; } 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 Reverb({ decay: this.pv.decay, preDelay: this.pv.preDelay }); } static PARAM_CALLBACK_updateEffect(node) { node._updateEffect(); } _updateEffect() { const effect = this._effect(); effect.decay = this.pv.decay; effect.preDelay = this.pv.preDelay; } }