UNPKG

@polygonjs/polygonjs

Version:

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

61 lines (60 loc) 1.57 kB
"use strict"; import { Tremolo } from "tone/build/esm/effect/Tremolo"; const DEFAULTS = { depth: 0.5, frequency: 10, spread: 180 // type: "sine" }; import { TypedAudioNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; class TremoloAudioParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param frequency */ this.frequency = ParamConfig.FLOAT(DEFAULTS.frequency, { range: [0, 1e3], rangeLocked: [true, false] }); /** @param depth */ this.depth = ParamConfig.FLOAT(DEFAULTS.depth, { range: [0, 1], rangeLocked: [true, true] }); /** @param spread (degrees) */ this.spread = ParamConfig.FLOAT(DEFAULTS.spread, { range: [-180, 180], rangeLocked: [true, true] }); } } const ParamsConfig = new TremoloAudioParamsConfig(); export class TremoloAudioNode extends TypedAudioNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "tremolo"; } initializeNode() { this.io.inputs.setCount(1); } cook(inputContents) { const audioBuilder = inputContents[0]; const effect = this._createEffect(); const inputNode = audioBuilder.audioNode(); if (inputNode) { inputNode.connect(effect); } audioBuilder.setAudioNode(effect); this.setAudioBuilder(audioBuilder); } _createEffect() { return new Tremolo({ frequency: this.pv.frequency, depth: this.pv.depth, spread: this.pv.spread }); } }