2019-07-25 14:46:28 +00:00
|
|
|
import { Gain } from "../core/context/Gain";
|
|
|
|
import { Param } from "../core/context/Param";
|
2019-07-30 19:35:27 +00:00
|
|
|
import { NormalRange } from "../core/type/Units";
|
2019-07-25 14:46:28 +00:00
|
|
|
import { readOnly } from "../core/util/Interface";
|
|
|
|
import { Effect, EffectOptions } from "./Effect";
|
|
|
|
|
|
|
|
export interface FeedbackEffectOptions extends EffectOptions {
|
|
|
|
/**
|
|
|
|
* The feedback from the output back to the input
|
|
|
|
* ```
|
|
|
|
* +---<--------<---+
|
|
|
|
* | |
|
|
|
|
* | +----------+ |
|
|
|
|
* +--> feedback +>-+
|
|
|
|
* +----------+
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
feedback: NormalRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FeedbackEffect provides a loop between an audio source and its own output.
|
|
|
|
* This is a base-class for feedback effects.
|
|
|
|
*/
|
|
|
|
export abstract class FeedbackEffect<Options extends FeedbackEffectOptions> extends Effect<Options> {
|
|
|
|
|
2019-09-04 22:38:04 +00:00
|
|
|
readonly name: string = "FeedbackEffect";
|
2019-07-25 14:46:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the gain which controls the feedback
|
|
|
|
*/
|
|
|
|
private _feedbackGain: Gain<NormalRange>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The amount of signal which is fed back into the effect input.
|
|
|
|
*/
|
|
|
|
feedback: Param<NormalRange>;
|
|
|
|
|
|
|
|
constructor(options: FeedbackEffectOptions) {
|
|
|
|
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
this._feedbackGain = new Gain({
|
|
|
|
context: this.context,
|
|
|
|
gain: options.feedback,
|
|
|
|
units: "normalRange",
|
|
|
|
});
|
|
|
|
|
|
|
|
this.feedback = this._feedbackGain.gain;
|
|
|
|
readOnly(this, "feedback");
|
|
|
|
|
|
|
|
// the feedback loop
|
|
|
|
this.effectReturn.chain(this._feedbackGain, this.effectSend);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getDefaults(): FeedbackEffectOptions {
|
|
|
|
return Object.assign(Effect.getDefaults(), {
|
|
|
|
feedback: 0.125,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dispose(): this {
|
|
|
|
super.dispose();
|
|
|
|
this._feedbackGain.dispose();
|
|
|
|
this.feedback.dispose();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|