2019-07-25 17:32:34 +00:00
|
|
|
import { Delay } from "../core/context/Delay";
|
|
|
|
import { Param } from "../core/context/Param";
|
2019-07-30 19:35:27 +00:00
|
|
|
import { NormalRange, Time } from "../core/type/Units";
|
2019-07-25 17:32:34 +00:00
|
|
|
import { optionsFromArguments } from "../core/util/Defaults";
|
|
|
|
import { readOnly } from "../core/util/Interface";
|
2019-09-14 22:12:44 +00:00
|
|
|
import { FeedbackEffect, FeedbackEffectOptions } from "./FeedbackEffect";
|
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
|
2019-07-25 15:32:56 +00:00
|
|
|
* var feedbackDelay = new FeedbackDelay("8n", 0.5).toDestination();
|
2019-07-25 14:46:28 +00:00
|
|
|
* var tom = new Tone.MembraneSynth({
|
2019-09-14 20:39:18 +00:00
|
|
|
* "octaves" : 4,
|
|
|
|
* "pitchDecay" : 0.1
|
2019-07-25 14:46:28 +00:00
|
|
|
* }).connect(feedbackDelay);
|
|
|
|
* 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
|
|
|
*/
|
2019-07-25 15:19:53 +00:00
|
|
|
readonly delayTime: Param<Time>;
|
2019-07-25 14:46:28 +00:00
|
|
|
|
|
|
|
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.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;
|
|
|
|
}
|
|
|
|
}
|