UNPKG

@polygonjs/polygonjs

Version:

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

54 lines (53 loc) 1.58 kB
"use strict"; import { BitCrusher } from "tone/build/esm/effect/BitCrusher"; const DEFAULTS = { bits: 4 }; import { TypedAudioNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; class BitCrusherAudioParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param bits */ this.bits = ParamConfig.INTEGER(DEFAULTS.bits, { range: [1, 16], rangeLocked: [true, true] // ...effectParamsOptions(paramCallback), }); } } const ParamsConfig = new BitCrusherAudioParamsConfig(); export class BitCrusherAudioNode extends TypedAudioNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "bitCrusher"; } initializeNode() { this.io.inputs.setCount(1); } cook(inputContents) { const audioBuilder = inputContents[0]; const effect = new BitCrusher(this.pv.bits); const inputNode = audioBuilder.audioNode(); if (inputNode) { inputNode.connect(effect); } audioBuilder.setAudioNode(effect); this.setAudioBuilder(audioBuilder); } // private __effect__: BitCrusher | undefined; // private _effect() { // return (this.__effect__ = this.__effect__ || this._createEffect()); // } // private _createEffect() { // return new BitCrusher(this.pv.bits); // } // static PARAM_CALLBACK_updateEffect(node: BitCrusherAudioNode) { // node._updateEffect(); // } // private _updateEffect() { // const effect = this._effect(); // effect.bits = this.pv.bits; // } }