mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-28 20:43:08 +00:00
77 lines
2 KiB
TypeScript
77 lines
2 KiB
TypeScript
|
import { Delay } from "Tone/core";
|
||
|
import { Param } from "Tone/core/context/Param";
|
||
|
import { optionsFromArguments } from "Tone/core/util/Defaults";
|
||
|
import { readOnly } from "Tone/core/util/Interface";
|
||
|
import { FeedbackEffect, FeedbackEffectOptions } from "./FeedbackEffect";
|
||
|
|
||
|
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
|
||
|
* var feedbackDelay = new FeedbackDelay("8n", 0.5).toMaster();
|
||
|
* var tom = new Tone.MembraneSynth({
|
||
|
* "octaves" : 4,
|
||
|
* "pitchDecay" : 0.1
|
||
|
* }).connect(feedbackDelay);
|
||
|
* tom.triggerAttackRelease("A2","32n");
|
||
|
*/
|
||
|
export class FeedbackDelay extends FeedbackEffect<FeedbackDelayOptions> {
|
||
|
|
||
|
/**
|
||
|
* the delay node
|
||
|
*/
|
||
|
private _delayNode: Delay;
|
||
|
|
||
|
/**
|
||
|
* The delayTime of the DelayNode.
|
||
|
*/
|
||
|
delayTime: Param<Time>;
|
||
|
|
||
|
constructor(delayTime?: Time, feedback?: NormalRange);
|
||
|
constructor(options?: Partial<FeedbackDelayOptions>);
|
||
|
constructor() {
|
||
|
|
||
|
super(optionsFromArguments(FeedbackDelay.getDefaults(), arguments, ["delayTime", "feedback"]));
|
||
|
const options = optionsFromArguments(FeedbackDelay.getDefaults(), arguments, ["delayTime", "feedback"]);
|
||
|
|
||
|
this._delayNode = new Delay({
|
||
|
context: this.context,
|
||
|
delayTime: options.delayTime,
|
||
|
maxDelay: options.maxDelay,
|
||
|
});
|
||
|
this._internalChannels.push(this._delayNode);
|
||
|
|
||
|
/**
|
||
|
* The delayTime of the DelayNode.
|
||
|
* @type {Time}
|
||
|
* @signal
|
||
|
*/
|
||
|
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;
|
||
|
}
|
||
|
}
|