@thi.ng/dsp
Version:
Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils
109 lines • 3.39 kB
TypeScript
import type { ICopy, IReset } from "@thi.ng/api";
import { AGen } from "./agen.js";
import type { IGen } from "./api.js";
/** @internal */
declare const enum EnvPhase {
ATTACK = 0,
DECAY = 1,
SUSTAIN = 2,
RELEASE = 3,
IDLE = 4
}
export interface ADSROpts {
/**
* Attack time (in samples). Default: 0
*/
a: number;
/**
* Decay time (in samples). Default: 0
*/
d: number;
/**
* Sustain level/gain (in `[0,1]` range). Default: 1
*/
s: number;
/**
* Release time (in samples). Default: 0
*/
r: number;
/**
* Attack curvature. Recommended range [0.0001 .. 10000]
* (curved -> linear). Default: 0.1
*/
acurve: number;
/**
* Decay & release curvature. Recommended range [0.0001 .. 10000]
* (curved -> linear). Default: 0.1
*/
dcurve: number;
/**
* Sustain phase duration (in samples). Default: Infinity. If a
* finite value, then release phase is triggered automatically, else
* needs to be triggered manually via {@link ADSR.release}.
*/
slen: number;
/**
* Overall envelope gain / multiplier. Default: 1
*/
gain: number;
}
/**
* Time based ADSR envelope gen with customizable exponential attack, decay and
* release curves.
*
* @remarks
* The attack, decay and release options are to be given in samples (`num =
* time_in_seconds * sample_rate`). Unless the sustain length (`slen` opt) is
* finite (default: ∞), the release phase of the envelope MUST be triggered
* manually by calling {@link ADSR.release}. If only attack & decay phases are
* required, initialize the sustain level to zero and configure `dcurve` to
* adjust falloff shape.
*
* The envelope can be re-used & restarted by calling {@link ADSR.reset}. This
* will move the internal state back to the beginning of the attack phase and
* start producing a new envelope with current settings. Note: Any changes done
* to the envelope parameters are only guaranteed to be fully applied after
* reset.
*
* The `acurve` and `dcurve` options can be used to control the exponential
* curvature of the attack, decay and release phases. Recommended range
* `[0.0001,100]` (curved -> linear).
*
* @param opts -
*/
export declare const adsr: (opts?: Partial<ADSROpts>) => ADSR;
export declare class ADSR extends AGen<number> implements ICopy<ADSR>, IReset {
protected _phase: EnvPhase;
protected _curve: IGen<number>;
protected _atime: number;
protected _dtime: number;
protected _rtime: number;
protected _acurve: number;
protected _dcurve: number;
protected _sustain: number;
protected _speriod: number;
protected _gain: number;
constructor(opts?: Partial<ADSROpts>);
copy(): ADSR;
reset(): this;
release(): void;
isSustained(): boolean;
isDone(): boolean;
next(): number;
setAttack(steps: number): void;
setDecay(steps: number): void;
setRelease(steps: number): void;
/**
* Sets sustain level & duration. If the latter is omitted, the
* current value will be retained.
*
* @param level -
* @param duration -
*/
setSustain(level: number, duration?: number): void;
setCurveA(ratio: number): void;
setCurveD(ratio: number): void;
setGain(gain: number): void;
}
export {};
//# sourceMappingURL=adsr.d.ts.map