Tone.js/Tone/effect/FeedbackDelay.ts

76 lines
2 KiB
TypeScript
Raw Normal View History

import { Delay } from "../core/context/Delay.js";
import { Param } from "../core/context/Param.js";
import { NormalRange, Time } from "../core/type/Units.js";
import { optionsFromArguments } from "../core/util/Defaults.js";
import { readOnly } from "../core/util/Interface.js";
import { FeedbackEffect, FeedbackEffectOptions } from "./FeedbackEffect.js";
2019-07-25 14:46:28 +00:00
interface FeedbackDelayOptions extends FeedbackEffectOptions {
delayTime: Time;
maxDelay: Time;
}
/**
* FeedbackDelay is a DelayNode in which part of output signal is fed back into the delay.
*
* @param delayTime The delay applied to the incoming signal.
* @param feedback The amount of the effected signal which is fed back through the delay.
* @example
* const feedbackDelay = new Tone.FeedbackDelay("8n", 0.5).toDestination();
* const tom = new Tone.MembraneSynth({
2019-10-24 22:01:27 +00:00
* octaves: 4,
* pitchDecay: 0.1
2019-07-25 14:46:28 +00:00
* }).connect(feedbackDelay);
2019-10-24 22:01:27 +00:00
* tom.triggerAttackRelease("A2", "32n");
2019-09-16 14:15:23 +00:00
* @category Effect
2019-07-25 14:46:28 +00:00
*/
export class FeedbackDelay extends FeedbackEffect<FeedbackDelayOptions> {
2019-09-04 23:18:44 +00:00
readonly name: string = "FeedbackDelay";
2019-08-02 20:28:57 +00:00
2019-07-25 14:46:28 +00:00
/**
2019-09-14 20:39:18 +00:00
* the delay node
2019-07-25 14:46:28 +00:00
*/
private _delayNode: Delay;
/**
2019-09-14 20:39:18 +00:00
* The delayTime of the FeedbackDelay.
2019-07-25 14:46:28 +00:00
*/
readonly delayTime: Param<"time">;
2019-07-25 14:46:28 +00:00
constructor(delayTime?: Time, feedback?: NormalRange);
constructor(options?: Partial<FeedbackDelayOptions>);
constructor() {
const options = optionsFromArguments(
FeedbackDelay.getDefaults(),
arguments,
["delayTime", "feedback"]
);
super(options);
2019-07-25 14:46:28 +00:00
this._delayNode = new Delay({
context: this.context,
delayTime: options.delayTime,
maxDelay: options.maxDelay,
});
this.delayTime = this._delayNode.delayTime;
// connect it up
this.connectEffect(this._delayNode);
readOnly(this, "delayTime");
}
static getDefaults(): FeedbackDelayOptions {
return Object.assign(FeedbackEffect.getDefaults(), {
delayTime: 0.25,
maxDelay: 1,
});
}
dispose(): this {
super.dispose();
this._delayNode.dispose();
this.delayTime.dispose();
return this;
}
}