UNPKG

@polygonjs/polygonjs

Version:

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

61 lines (60 loc) 1.69 kB
"use strict"; import { PitchShift } from "tone/build/esm/effect/PitchShift"; const DEFAULTS = { // delayTime: 0, // feedback: 0, pitch: 0 }; import { TypedAudioNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { effectParamsOptions } from "./utils/EffectsController"; const paramCallback = (node) => { PitchShiftAudioNode.PARAM_CALLBACK_updateEffect(node); }; class PitchShiftAudioParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param The interval to transpose the incoming signal by */ this.pitch = ParamConfig.FLOAT(DEFAULTS.pitch, { range: [-10, 10], rangeLocked: [false, false], ...effectParamsOptions(paramCallback) }); } } const ParamsConfig = new PitchShiftAudioParamsConfig(); export class PitchShiftAudioNode extends TypedAudioNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "pitchShift"; } 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 PitchShift(this.pv.pitch); } static PARAM_CALLBACK_updateEffect(node) { node._updateEffect(); } _updateEffect() { const effect = this._effect(); effect.pitch = this.pv.pitch; } }