@thi.ng/dsp
Version:
Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils
73 lines • 2.23 kB
TypeScript
import type { Fn0, IClear, ICopy, ILength, IReset } from "@thi.ng/api";
import { AProc } from "./aproc.js";
/**
* Delay line of length `n` for numeric values.
*
* @param n -
*/
export declare const delay: (n: number) => Delay<number>;
/**
* Delay line of length `n` for arbitrary typed values.
*
* @param n -
*/
export declare const delayT: <T>(n: number, off: T | Fn0<T>) => Delay<T>;
/**
* Ring buffer / delay line for arbitrary values w/ support for tapping
* at any delay time (within configured buffer size).
*/
export declare class Delay<T> extends AProc<T, T> implements IClear, ICopy<Delay<T>>, ILength, IReset {
protected _empty: T | Fn0<T>;
protected _buf: T[];
protected _rpos: number;
protected _wpos: number;
/**
* Constructs new delay line of size `n` and initializes all
* elements to `empty`. If the latter is a function, the buffer will
* be initialized with the results of that function (called for each
* element).
*
* @param n -
* @param _empty -
*/
constructor(n: number, _empty: T | Fn0<T>);
get length(): number;
clear(): void;
copy(): Delay<T>;
/**
* Alias for {@link Delay.clear}
*/
reset(): this;
/**
* Returns the delayed value at current read position (i.e. `n`
* samples behind current write pos, where `n` is the length of this
* delay line).
*/
deref(): T;
/**
* Reads value at `t` relative to current write position. `t` should
* be in `(-∞..0)` interval. E.g. `tap(-1)` returns the second
* most recent value written.
*
* @param t -
*/
tap(t: number): T;
/**
* Takes an array of offsets relative to current write position,
* calls {@link Delay.tap} for each, writes results to `out` and
* returns it.
*/
multiTap(t: ArrayLike<number>, out?: T[]): T[];
/**
* Progresses read & write pos, stores new value and returns delayed value.
*
* @param x -
*/
next(x: T): T;
/**
* Moves read & write cursors one step forward. Useful for skipping
* elements and/or to create gaps in the delay line.
*/
step(): void;
}
//# sourceMappingURL=delay.d.ts.map