@thi.ng/dsp 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -1
- package/add.d.ts +3 -2
- package/add.js +3 -0
- package/adsr.d.ts +3 -2
- package/adsr.js +12 -0
- package/alt.d.ts +3 -2
- package/alt.js +3 -0
- package/aproc.d.ts +2 -1
- package/aproc.js +3 -0
- package/const.d.ts +3 -1
- package/const.js +3 -0
- package/delay.d.ts +4 -3
- package/delay.js +9 -2
- package/feedback-delay.d.ts +3 -1
- package/feedback-delay.js +3 -0
- package/filter-delay.d.ts +2 -2
- package/filter-delay.js +2 -2
- package/impulse-train.d.ts +3 -2
- package/impulse-train.js +3 -0
- package/impulse.d.ts +3 -2
- package/impulse.js +3 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/integrator.d.ts +3 -2
- package/integrator.js +3 -0
- package/internal/ensure.d.ts +4 -0
- package/internal/ensure.js +3 -0
- package/madd.d.ts +3 -2
- package/madd.js +3 -0
- package/merge.d.ts +11 -0
- package/merge.js +16 -0
- package/mix.d.ts +15 -4
- package/mix.js +26 -6
- package/mul.d.ts +3 -2
- package/mul.js +3 -0
- package/package.json +4 -4
- package/pan.d.ts +22 -0
- package/pan.js +33 -0
- package/pipe.d.ts +1 -1
- package/pipe.js +4 -19
- package/ref.d.ts +16 -0
- package/ref.js +22 -0
- package/sincos.d.ts +3 -2
- package/sincos.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-09-
|
|
3
|
+
- **Last updated**: 2023-09-28T05:58:33Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,24 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [4.6.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dsp@4.6.0) (2023-09-28)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add IXform impl for AProc2 ([5aa6c9b](https://github.com/thi-ng/umbrella/commit/5aa6c9b))
|
|
17
|
+
- add ICopy impls for various IGen's ([7894cd4](https://github.com/thi-ng/umbrella/commit/7894cd4))
|
|
18
|
+
- add merge(), mix(), pan() ([314e9b2](https://github.com/thi-ng/umbrella/commit/314e9b2))
|
|
19
|
+
- add refG()/refP() wrappers ([99f4535](https://github.com/thi-ng/umbrella/commit/99f4535))
|
|
20
|
+
|
|
21
|
+
#### 🩹 Bug fixes
|
|
22
|
+
|
|
23
|
+
- enforce integer delay time ([5c21b00](https://github.com/thi-ng/umbrella/commit/5c21b00))
|
|
24
|
+
- return delayed value in Delay.next() ([f2b08db](https://github.com/thi-ng/umbrella/commit/f2b08db))
|
|
25
|
+
|
|
26
|
+
#### ♻️ Refactoring
|
|
27
|
+
|
|
28
|
+
- simplify pipe() to reuse serial() ([90910bc](https://github.com/thi-ng/umbrella/commit/90910bc))
|
|
29
|
+
|
|
12
30
|
## [4.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dsp@4.5.0) (2023-09-15)
|
|
13
31
|
|
|
14
32
|
#### 🚀 Features
|
package/add.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IReset } from "@thi.ng/api";
|
|
1
|
+
import type { ICopy, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AGen } from "./agen.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new `Add` gen using given `step` (default: 1.0) and `start`
|
|
@@ -11,11 +11,12 @@ import { AGen } from "./agen.js";
|
|
|
11
11
|
* @param clamp -
|
|
12
12
|
*/
|
|
13
13
|
export declare const add: (step?: number, start?: number, clamp?: number) => Add;
|
|
14
|
-
export declare class Add extends AGen<number> implements IReset {
|
|
14
|
+
export declare class Add extends AGen<number> implements ICopy<Add>, IReset {
|
|
15
15
|
protected _step: number;
|
|
16
16
|
protected _start: number;
|
|
17
17
|
protected _clamp?: number | undefined;
|
|
18
18
|
constructor(_step?: number, _start?: number, _clamp?: number | undefined);
|
|
19
|
+
copy(): Add;
|
|
19
20
|
reset(): this;
|
|
20
21
|
next(): number;
|
|
21
22
|
}
|
package/add.js
CHANGED
package/adsr.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IReset } from "@thi.ng/api";
|
|
1
|
+
import type { ICopy, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AGen } from "./agen.js";
|
|
3
3
|
import type { IGen } from "./api.js";
|
|
4
4
|
declare const enum EnvPhase {
|
|
@@ -71,7 +71,7 @@ export interface ADSROpts {
|
|
|
71
71
|
* @param opts -
|
|
72
72
|
*/
|
|
73
73
|
export declare const adsr: (opts?: Partial<ADSROpts>) => ADSR;
|
|
74
|
-
export declare class ADSR extends AGen<number> implements IReset {
|
|
74
|
+
export declare class ADSR extends AGen<number> implements ICopy<ADSR>, IReset {
|
|
75
75
|
protected _phase: EnvPhase;
|
|
76
76
|
protected _curve: IGen<number>;
|
|
77
77
|
protected _atime: number;
|
|
@@ -83,6 +83,7 @@ export declare class ADSR extends AGen<number> implements IReset {
|
|
|
83
83
|
protected _speriod: number;
|
|
84
84
|
protected _gain: number;
|
|
85
85
|
constructor(opts?: Partial<ADSROpts>);
|
|
86
|
+
copy(): ADSR;
|
|
86
87
|
reset(): this;
|
|
87
88
|
release(): void;
|
|
88
89
|
isSustained(): boolean;
|
package/adsr.js
CHANGED
|
@@ -58,6 +58,18 @@ export class ADSR extends AGen {
|
|
|
58
58
|
this.setGain(opts.gain);
|
|
59
59
|
this.reset();
|
|
60
60
|
}
|
|
61
|
+
copy() {
|
|
62
|
+
return new ADSR({
|
|
63
|
+
a: this._atime,
|
|
64
|
+
d: this._dtime,
|
|
65
|
+
s: this._sustain,
|
|
66
|
+
r: this._rtime,
|
|
67
|
+
acurve: this._acurve,
|
|
68
|
+
dcurve: this._dcurve,
|
|
69
|
+
gain: this._gain,
|
|
70
|
+
slen: this._speriod,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
61
73
|
reset() {
|
|
62
74
|
this._phase = EnvPhase.ATTACK;
|
|
63
75
|
this._curve = curve(0, 1, this._atime + 1, this._acurve, true);
|
package/alt.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type { IReset } from "@thi.ng/api";
|
|
1
|
+
import type { ICopy, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AGen } from "./agen.js";
|
|
3
3
|
export declare const alt: (n?: number) => Alt<number>;
|
|
4
4
|
export declare const altT: <T>(a: T, b: T) => Alt<T>;
|
|
5
5
|
export declare const altB: (x?: boolean) => Alt<boolean>;
|
|
6
|
-
export declare class Alt<T> extends AGen<T> implements IReset {
|
|
6
|
+
export declare class Alt<T> extends AGen<T> implements ICopy<Alt<T>>, IReset {
|
|
7
7
|
protected _a: T;
|
|
8
8
|
protected _b: T;
|
|
9
9
|
protected _flip: boolean;
|
|
10
10
|
constructor(_a: T, _b: T);
|
|
11
|
+
copy(): Alt<T>;
|
|
11
12
|
reset(): this;
|
|
12
13
|
next(): T;
|
|
13
14
|
}
|
package/alt.js
CHANGED
package/aproc.d.ts
CHANGED
|
@@ -15,10 +15,11 @@ export declare abstract class AProc<A, B> implements IProc<A, B>, IXform<A, B> {
|
|
|
15
15
|
/**
|
|
16
16
|
* Similar to {@link AProc}, but for processors with 2 inputs.
|
|
17
17
|
*/
|
|
18
|
-
export declare abstract class AProc2<A, B, C> implements IProc2<A, B, C> {
|
|
18
|
+
export declare abstract class AProc2<A, B, C> implements IProc2<A, B, C>, IXform<[A, B], C> {
|
|
19
19
|
protected _val: C;
|
|
20
20
|
constructor(_val: C);
|
|
21
21
|
deref(): C;
|
|
22
22
|
abstract next(a: A, b: B): C;
|
|
23
|
+
xform(): import("@thi.ng/transducers").Transducer<[A, B], C>;
|
|
23
24
|
}
|
|
24
25
|
//# sourceMappingURL=aproc.d.ts.map
|
package/aproc.js
CHANGED
package/const.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ICopy } from "@thi.ng/api";
|
|
1
2
|
import { AGen } from "./agen.js";
|
|
2
3
|
/**
|
|
3
4
|
* Returns new gen yielding always the same given value `x`.
|
|
@@ -5,7 +6,8 @@ import { AGen } from "./agen.js";
|
|
|
5
6
|
* @param x -
|
|
6
7
|
*/
|
|
7
8
|
export declare const constant: <T>(x: T) => Const<T>;
|
|
8
|
-
export declare class Const<T> extends AGen<T> {
|
|
9
|
+
export declare class Const<T> extends AGen<T> implements ICopy<Const<T>> {
|
|
10
|
+
copy(): Const<T>;
|
|
9
11
|
next(): T;
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=const.d.ts.map
|
package/const.js
CHANGED
package/delay.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fn0, IClear, ILength, IReset } from "@thi.ng/api";
|
|
1
|
+
import type { Fn0, IClear, ICopy, ILength, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AProc } from "./aproc.js";
|
|
3
3
|
/**
|
|
4
4
|
* Delay line of length `n` for numeric values.
|
|
@@ -16,7 +16,7 @@ export declare const delayT: <T>(n: number, off: T | Fn0<T>) => Delay<T>;
|
|
|
16
16
|
* Ring buffer / delay line for arbitrary values w/ support for tapping
|
|
17
17
|
* at any delay time (within configured buffer size).
|
|
18
18
|
*/
|
|
19
|
-
export declare class Delay<T> extends AProc<T, T> implements IClear, ILength, IReset {
|
|
19
|
+
export declare class Delay<T> extends AProc<T, T> implements IClear, ICopy<Delay<T>>, ILength, IReset {
|
|
20
20
|
protected _empty: T | Fn0<T>;
|
|
21
21
|
protected _buf: T[];
|
|
22
22
|
protected _rpos: number;
|
|
@@ -33,6 +33,7 @@ export declare class Delay<T> extends AProc<T, T> implements IClear, ILength, IR
|
|
|
33
33
|
constructor(n: number, _empty: T | Fn0<T>);
|
|
34
34
|
get length(): number;
|
|
35
35
|
clear(): void;
|
|
36
|
+
copy(): Delay<T>;
|
|
36
37
|
/**
|
|
37
38
|
* Alias for {@link Delay.clear}
|
|
38
39
|
*/
|
|
@@ -58,7 +59,7 @@ export declare class Delay<T> extends AProc<T, T> implements IClear, ILength, IR
|
|
|
58
59
|
*/
|
|
59
60
|
multiTap(t: ArrayLike<number>, out?: T[]): T[];
|
|
60
61
|
/**
|
|
61
|
-
* Progresses read & write pos, stores
|
|
62
|
+
* Progresses read & write pos, stores new value and returns delayed value.
|
|
62
63
|
*
|
|
63
64
|
* @param x -
|
|
64
65
|
*/
|
package/delay.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isFunction } from "@thi.ng/checks/is-function";
|
|
2
|
+
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
2
3
|
import { wrap } from "@thi.ng/math/interval";
|
|
3
4
|
import { AProc } from "./aproc.js";
|
|
4
5
|
/**
|
|
@@ -30,6 +31,9 @@ export class Delay extends AProc {
|
|
|
30
31
|
constructor(n, _empty) {
|
|
31
32
|
super(isFunction(_empty) ? _empty() : _empty);
|
|
32
33
|
this._empty = _empty;
|
|
34
|
+
if (n < 1)
|
|
35
|
+
illegalArgs("delay size must be >= 1");
|
|
36
|
+
n >>>= 0;
|
|
33
37
|
this._wpos = n - 1;
|
|
34
38
|
this._rpos = 0;
|
|
35
39
|
this._buf = new Array(n);
|
|
@@ -49,6 +53,9 @@ export class Delay extends AProc {
|
|
|
49
53
|
this._buf.fill(_empty);
|
|
50
54
|
}
|
|
51
55
|
}
|
|
56
|
+
copy() {
|
|
57
|
+
return new Delay(this._buf.length, this._empty);
|
|
58
|
+
}
|
|
52
59
|
/**
|
|
53
60
|
* Alias for {@link Delay.clear}
|
|
54
61
|
*/
|
|
@@ -86,14 +93,14 @@ export class Delay extends AProc {
|
|
|
86
93
|
return out;
|
|
87
94
|
}
|
|
88
95
|
/**
|
|
89
|
-
* Progresses read & write pos, stores
|
|
96
|
+
* Progresses read & write pos, stores new value and returns delayed value.
|
|
90
97
|
*
|
|
91
98
|
* @param x -
|
|
92
99
|
*/
|
|
93
100
|
next(x) {
|
|
94
101
|
this.step();
|
|
95
102
|
this._buf[this._wpos] = x;
|
|
96
|
-
return
|
|
103
|
+
return (this._val = this._buf[this._rpos]);
|
|
97
104
|
}
|
|
98
105
|
/**
|
|
99
106
|
* Moves read & write cursors one step forward. Useful for skipping
|
package/feedback-delay.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Delay } from "./delay.js";
|
|
2
|
+
import type { ICopy } from "@thi.ng/api";
|
|
2
3
|
/**
|
|
3
4
|
* Extension of {@link Delay} which adds sum delayed value multiplied
|
|
4
5
|
* with `feedback` for each new input.
|
|
@@ -10,9 +11,10 @@ import { Delay } from "./delay.js";
|
|
|
10
11
|
* @param feedback - feedback factor (default: 0.5)
|
|
11
12
|
*/
|
|
12
13
|
export declare const feedbackDelay: (n: number, feedback?: number) => FeedbackDelay;
|
|
13
|
-
export declare class FeedbackDelay extends Delay<number> {
|
|
14
|
+
export declare class FeedbackDelay extends Delay<number> implements ICopy<FeedbackDelay> {
|
|
14
15
|
protected _feedback: number;
|
|
15
16
|
constructor(n: number, _feedback?: number);
|
|
17
|
+
copy(): FeedbackDelay;
|
|
16
18
|
next(x: number): number;
|
|
17
19
|
feedback(): number;
|
|
18
20
|
setFeedback(feedback: number): void;
|
package/feedback-delay.js
CHANGED
|
@@ -17,6 +17,9 @@ export class FeedbackDelay extends Delay {
|
|
|
17
17
|
this._feedback = _feedback;
|
|
18
18
|
this.setFeedback(_feedback);
|
|
19
19
|
}
|
|
20
|
+
copy() {
|
|
21
|
+
return new FeedbackDelay(this._buf.length, this._feedback);
|
|
22
|
+
}
|
|
20
23
|
next(x) {
|
|
21
24
|
return super.next(x + this._buf[this._rpos] * this._feedback);
|
|
22
25
|
}
|
package/filter-delay.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { IProc } from "./api.js";
|
|
2
2
|
import { Delay } from "./delay.js";
|
|
3
3
|
/**
|
|
4
|
-
* Extension of {@link feedbackDelay} with additional filter/proc
|
|
5
|
-
*
|
|
4
|
+
* Extension of {@link feedbackDelay} with an additional filter/proc applied to
|
|
5
|
+
* the feedback itself (e.g. a low pass filter).
|
|
6
6
|
*
|
|
7
7
|
* @param n - delay length
|
|
8
8
|
* @param filter - IProc applied to feedback
|
package/filter-delay.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { clamp01 } from "@thi.ng/math/interval";
|
|
2
2
|
import { Delay } from "./delay.js";
|
|
3
3
|
/**
|
|
4
|
-
* Extension of {@link feedbackDelay} with additional filter/proc
|
|
5
|
-
*
|
|
4
|
+
* Extension of {@link feedbackDelay} with an additional filter/proc applied to
|
|
5
|
+
* the feedback itself (e.g. a low pass filter).
|
|
6
6
|
*
|
|
7
7
|
* @param n - delay length
|
|
8
8
|
* @param filter - IProc applied to feedback
|
package/impulse-train.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IReset } from "@thi.ng/api";
|
|
1
|
+
import type { ICopy, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AGen } from "./agen.js";
|
|
3
3
|
/**
|
|
4
4
|
* https://en.wikipedia.org/wiki/Dirac_comb
|
|
@@ -9,13 +9,14 @@ import { AGen } from "./agen.js";
|
|
|
9
9
|
export declare const impulseTrain: (period: number, start?: number) => ImpulseTrain<number>;
|
|
10
10
|
export declare const impulseTrainT: <T>(on: T, off: T, period: number, start?: number) => ImpulseTrain<T>;
|
|
11
11
|
export declare const impulseTrainB: (period: number, start?: number) => ImpulseTrain<boolean>;
|
|
12
|
-
export declare class ImpulseTrain<T> extends AGen<T> implements IReset {
|
|
12
|
+
export declare class ImpulseTrain<T> extends AGen<T> implements ICopy<ImpulseTrain<T>>, IReset {
|
|
13
13
|
protected _on: T;
|
|
14
14
|
protected _off: T;
|
|
15
15
|
protected _period: number;
|
|
16
16
|
protected _pos: number;
|
|
17
17
|
protected _startpos: number;
|
|
18
18
|
constructor(_on: T, _off: T, _period: number, _pos?: number);
|
|
19
|
+
copy(): ImpulseTrain<T>;
|
|
19
20
|
reset(): this;
|
|
20
21
|
next(): T;
|
|
21
22
|
}
|
package/impulse-train.js
CHANGED
|
@@ -17,6 +17,9 @@ export class ImpulseTrain extends AGen {
|
|
|
17
17
|
this._pos = _pos;
|
|
18
18
|
this._startpos = --this._pos;
|
|
19
19
|
}
|
|
20
|
+
copy() {
|
|
21
|
+
return new ImpulseTrain(this._on, this._off, this._period, this._startpos + 1);
|
|
22
|
+
}
|
|
20
23
|
reset() {
|
|
21
24
|
this._val = this._off;
|
|
22
25
|
this._pos = this._startpos;
|
package/impulse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IReset } from "@thi.ng/api";
|
|
1
|
+
import type { ICopy, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AGen } from "./agen.js";
|
|
3
3
|
/**
|
|
4
4
|
* Numeric version of {@link impulseT}, using given `on` (default: 1) as
|
|
@@ -22,10 +22,11 @@ export declare const impulseT: <T>(on: T, off: T) => Impulse<T>;
|
|
|
22
22
|
* @param start -
|
|
23
23
|
*/
|
|
24
24
|
export declare const impulseB: (start?: boolean) => Impulse<boolean>;
|
|
25
|
-
export declare class Impulse<T> extends AGen<T> implements IReset {
|
|
25
|
+
export declare class Impulse<T> extends AGen<T> implements ICopy<Impulse<T>>, IReset {
|
|
26
26
|
protected _on: T;
|
|
27
27
|
protected _off: T;
|
|
28
28
|
constructor(_on: T, _off: T);
|
|
29
|
+
copy(): Impulse<T>;
|
|
29
30
|
reset(): this;
|
|
30
31
|
next(): T;
|
|
31
32
|
}
|
package/impulse.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./iterable.js";
|
|
|
28
28
|
export * from "./line.js";
|
|
29
29
|
export * from "./madd.js";
|
|
30
30
|
export * from "./mapg.js";
|
|
31
|
+
export * from "./merge.js";
|
|
31
32
|
export * from "./mix.js";
|
|
32
33
|
export * from "./mul.js";
|
|
33
34
|
export * from "./multiplex.js";
|
|
@@ -43,11 +44,13 @@ export * from "./osc-sin.js";
|
|
|
43
44
|
export * from "./osc-tri.js";
|
|
44
45
|
export * from "./osc-wavetable.js";
|
|
45
46
|
export * from "./osc.js";
|
|
47
|
+
export * from "./pan.js";
|
|
46
48
|
export * from "./pink-noise.js";
|
|
47
49
|
export * from "./pipe.js";
|
|
48
50
|
export * from "./power.js";
|
|
49
51
|
export * from "./product.js";
|
|
50
52
|
export * from "./reciprocal.js";
|
|
53
|
+
export * from "./ref.js";
|
|
51
54
|
export * from "./serial.js";
|
|
52
55
|
export * from "./sincos.js";
|
|
53
56
|
export * from "./sum.js";
|
package/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./iterable.js";
|
|
|
28
28
|
export * from "./line.js";
|
|
29
29
|
export * from "./madd.js";
|
|
30
30
|
export * from "./mapg.js";
|
|
31
|
+
export * from "./merge.js";
|
|
31
32
|
export * from "./mix.js";
|
|
32
33
|
export * from "./mul.js";
|
|
33
34
|
export * from "./multiplex.js";
|
|
@@ -43,11 +44,13 @@ export * from "./osc-sin.js";
|
|
|
43
44
|
export * from "./osc-tri.js";
|
|
44
45
|
export * from "./osc-wavetable.js";
|
|
45
46
|
export * from "./osc.js";
|
|
47
|
+
export * from "./pan.js";
|
|
46
48
|
export * from "./pink-noise.js";
|
|
47
49
|
export * from "./pipe.js";
|
|
48
50
|
export * from "./power.js";
|
|
49
51
|
export * from "./product.js";
|
|
50
52
|
export * from "./reciprocal.js";
|
|
53
|
+
export * from "./ref.js";
|
|
51
54
|
export * from "./serial.js";
|
|
52
55
|
export * from "./sincos.js";
|
|
53
56
|
export * from "./sum.js";
|
package/integrator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IReset } from "@thi.ng/api";
|
|
1
|
+
import type { ICopy, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AProc } from "./aproc.js";
|
|
3
3
|
/**
|
|
4
4
|
* Leaky integrator.
|
|
@@ -8,10 +8,11 @@ import { AProc } from "./aproc.js";
|
|
|
8
8
|
* @param coeff - leak (default: 1)
|
|
9
9
|
*/
|
|
10
10
|
export declare const integrator: (coeff?: number, start?: number) => Integrator;
|
|
11
|
-
export declare class Integrator extends AProc<number, number> implements IReset {
|
|
11
|
+
export declare class Integrator extends AProc<number, number> implements ICopy<Integrator>, IReset {
|
|
12
12
|
protected _coeff: number;
|
|
13
13
|
protected _start: number;
|
|
14
14
|
constructor(_coeff?: number, _start?: number);
|
|
15
|
+
copy(): Integrator;
|
|
15
16
|
reset(): this;
|
|
16
17
|
next(x: number): number;
|
|
17
18
|
coeff(): number;
|
package/integrator.js
CHANGED
package/madd.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IReset } from "@thi.ng/api";
|
|
1
|
+
import type { ICopy, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AGen } from "./agen.js";
|
|
3
3
|
/**
|
|
4
4
|
* Returns new multiply-add gen producing `y(t) = factor * y(t-1) +
|
|
@@ -11,12 +11,13 @@ import { AGen } from "./agen.js";
|
|
|
11
11
|
* @param clamp - optional final value
|
|
12
12
|
*/
|
|
13
13
|
export declare const madd: (factor?: number, start?: number, offset?: number, clamp?: number) => MAdd;
|
|
14
|
-
export declare class MAdd extends AGen<number> implements IReset {
|
|
14
|
+
export declare class MAdd extends AGen<number> implements ICopy<MAdd>, IReset {
|
|
15
15
|
protected _factor: number;
|
|
16
16
|
protected _start: number;
|
|
17
17
|
protected _offset: number;
|
|
18
18
|
protected _clamp?: number | undefined;
|
|
19
19
|
constructor(_factor?: number, _start?: number, _offset?: number, _clamp?: number | undefined);
|
|
20
|
+
copy(): MAdd;
|
|
20
21
|
reset(): this;
|
|
21
22
|
next(): number;
|
|
22
23
|
}
|
package/madd.js
CHANGED
|
@@ -19,6 +19,9 @@ export class MAdd extends AGen {
|
|
|
19
19
|
this._clamp = _clamp;
|
|
20
20
|
this.reset();
|
|
21
21
|
}
|
|
22
|
+
copy() {
|
|
23
|
+
return new MAdd(this._factor, this._start, this._offset, this._clamp);
|
|
24
|
+
}
|
|
22
25
|
reset() {
|
|
23
26
|
this._val = (this._start - this._offset) / this._factor;
|
|
24
27
|
return this;
|
package/merge.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AGen } from "./agen.js";
|
|
2
|
+
import { type IGen } from "./api.js";
|
|
3
|
+
export declare const merge: (...channels: IGen<number>[]) => Merge<number>;
|
|
4
|
+
export declare const mergeT: <T>(channels: IGen<T>[], init: T) => Merge<T>;
|
|
5
|
+
export declare class Merge<T> extends AGen<T[]> {
|
|
6
|
+
protected _channels: IGen<T>[];
|
|
7
|
+
constructor(_channels: IGen<T>[], init: T);
|
|
8
|
+
channel(i: number): IGen<T>;
|
|
9
|
+
next(): T[];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=merge.d.ts.map
|
package/merge.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AGen } from "./agen.js";
|
|
2
|
+
import {} from "./api.js";
|
|
3
|
+
export const merge = (...channels) => new Merge(channels, 0);
|
|
4
|
+
export const mergeT = (channels, init) => new Merge(channels, init);
|
|
5
|
+
export class Merge extends AGen {
|
|
6
|
+
constructor(_channels, init) {
|
|
7
|
+
super(new Array(_channels.length).fill(init));
|
|
8
|
+
this._channels = _channels;
|
|
9
|
+
}
|
|
10
|
+
channel(i) {
|
|
11
|
+
return this._channels[i];
|
|
12
|
+
}
|
|
13
|
+
next() {
|
|
14
|
+
return this._channels.map((x) => x.next());
|
|
15
|
+
}
|
|
16
|
+
}
|
package/mix.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
import type { IGen } from "./api.js";
|
|
1
2
|
import { AProc2 } from "./aproc.js";
|
|
3
|
+
import type { NumericArray } from "@thi.ng/api";
|
|
4
|
+
export declare const mix: (t?: number) => Mix;
|
|
2
5
|
export declare class Mix extends AProc2<number, number, number> {
|
|
3
|
-
protected _t: number
|
|
4
|
-
constructor(
|
|
5
|
-
get mix(): number
|
|
6
|
-
set mix(
|
|
6
|
+
protected _t: IGen<number>;
|
|
7
|
+
constructor(t?: number | IGen<number>);
|
|
8
|
+
get mix(): number | IGen<number>;
|
|
9
|
+
set mix(t: number | IGen<number>);
|
|
7
10
|
next(a: number, b: number): number;
|
|
8
11
|
}
|
|
12
|
+
export declare const mix2: (t?: number) => Mix2;
|
|
13
|
+
export declare class Mix2 extends AProc2<NumericArray, NumericArray, NumericArray> {
|
|
14
|
+
protected _t: IGen<number>;
|
|
15
|
+
constructor(t?: number | IGen<number>);
|
|
16
|
+
get mix(): number | IGen<number>;
|
|
17
|
+
set mix(t: number | IGen<number>);
|
|
18
|
+
next(a: NumericArray, b: NumericArray): number[];
|
|
19
|
+
}
|
|
9
20
|
//# sourceMappingURL=mix.d.ts.map
|
package/mix.js
CHANGED
|
@@ -1,17 +1,37 @@
|
|
|
1
1
|
import { clamp01 } from "@thi.ng/math/interval";
|
|
2
|
+
import { mix as $mix } from "@thi.ng/math/mix";
|
|
2
3
|
import { AProc2 } from "./aproc.js";
|
|
4
|
+
import { __ensureGenN } from "./internal/ensure.js";
|
|
5
|
+
export const mix = (t) => new Mix(t);
|
|
3
6
|
export class Mix extends AProc2 {
|
|
4
|
-
constructor(
|
|
7
|
+
constructor(t = 0.5) {
|
|
5
8
|
super(0);
|
|
6
|
-
this.
|
|
9
|
+
this.mix = t;
|
|
7
10
|
}
|
|
8
11
|
get mix() {
|
|
9
|
-
return this._t;
|
|
12
|
+
return this._t.deref();
|
|
10
13
|
}
|
|
11
|
-
set mix(
|
|
12
|
-
this._t = clamp01
|
|
14
|
+
set mix(t) {
|
|
15
|
+
this._t = __ensureGenN(t, clamp01);
|
|
13
16
|
}
|
|
14
17
|
next(a, b) {
|
|
15
|
-
return (this._val = a + (b - a) * this._t);
|
|
18
|
+
return (this._val = a + (b - a) * this._t.next());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export const mix2 = (t) => new Mix2(t);
|
|
22
|
+
export class Mix2 extends AProc2 {
|
|
23
|
+
constructor(t = 0.5) {
|
|
24
|
+
super([0, 0]);
|
|
25
|
+
this.mix = t;
|
|
26
|
+
}
|
|
27
|
+
get mix() {
|
|
28
|
+
return this._t.deref();
|
|
29
|
+
}
|
|
30
|
+
set mix(t) {
|
|
31
|
+
this._t = __ensureGenN(t, clamp01);
|
|
32
|
+
}
|
|
33
|
+
next(a, b) {
|
|
34
|
+
const t = this._t.next();
|
|
35
|
+
return (this._val = [$mix(a[0], b[0], t), $mix(a[1], b[1], t)]);
|
|
16
36
|
}
|
|
17
37
|
}
|
package/mul.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IReset } from "@thi.ng/api";
|
|
1
|
+
import type { ICopy, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AGen } from "./agen.js";
|
|
3
3
|
/**
|
|
4
4
|
* Returns new multiply gen, producing `y(t) = factor * y(t-1)`, using
|
|
@@ -11,11 +11,12 @@ import { AGen } from "./agen.js";
|
|
|
11
11
|
* @param clamp -
|
|
12
12
|
*/
|
|
13
13
|
export declare const mul: (factor?: number, start?: number, clamp?: number) => Mul;
|
|
14
|
-
export declare class Mul extends AGen<number> implements IReset {
|
|
14
|
+
export declare class Mul extends AGen<number> implements ICopy<Mul>, IReset {
|
|
15
15
|
protected _factor: number;
|
|
16
16
|
protected _start: number;
|
|
17
17
|
protected _clamp?: number | undefined;
|
|
18
18
|
constructor(_factor?: number, _start?: number, _clamp?: number | undefined);
|
|
19
|
+
copy(): Mul;
|
|
19
20
|
reset(): this;
|
|
20
21
|
next(): number;
|
|
21
22
|
}
|
package/mul.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/dsp",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@thi.ng/checks": "^3.4.5",
|
|
39
39
|
"@thi.ng/errors": "^2.3.5",
|
|
40
40
|
"@thi.ng/math": "^5.6.1",
|
|
41
|
-
"@thi.ng/random": "^3.6.
|
|
42
|
-
"@thi.ng/transducers": "^8.7.
|
|
41
|
+
"@thi.ng/random": "^3.6.5",
|
|
42
|
+
"@thi.ng/transducers": "^8.7.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@microsoft/api-extractor": "^7.36.4",
|
|
@@ -275,5 +275,5 @@
|
|
|
275
275
|
],
|
|
276
276
|
"year": 2015
|
|
277
277
|
},
|
|
278
|
-
"gitHead": "
|
|
278
|
+
"gitHead": "6323ad527d62cfbda1a22d921f34a9b6436ea297\n"
|
|
279
279
|
}
|
package/pan.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IGen } from "./api.js";
|
|
2
|
+
import { AProc } from "./aproc.js";
|
|
3
|
+
import type { NumericArray } from "@thi.ng/api";
|
|
4
|
+
/**
|
|
5
|
+
* Positions and converts a mono signal into a stereo signal using given `pos`
|
|
6
|
+
* in the [-1..1] range to control the panning (-1 = left, +1 = right).
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Reference:
|
|
10
|
+
* https://www.musicdsp.org/en/latest/Effects/255-stereo-field-rotation-via-transformation-matrix.html
|
|
11
|
+
*
|
|
12
|
+
* @param pos
|
|
13
|
+
*/
|
|
14
|
+
export declare const pan: (pos?: number | IGen<number>) => Pan;
|
|
15
|
+
export declare class Pan extends AProc<number, NumericArray> {
|
|
16
|
+
protected _pos: IGen<number>;
|
|
17
|
+
constructor(pos?: number | IGen<number>);
|
|
18
|
+
get pos(): number | IGen<number>;
|
|
19
|
+
set pos(pos: number | IGen<number>);
|
|
20
|
+
next(x: number): NumericArray;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=pan.d.ts.map
|
package/pan.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { QUARTER_PI } from "@thi.ng/math/api";
|
|
2
|
+
import { clamp11 } from "@thi.ng/math/interval";
|
|
3
|
+
import { AProc } from "./aproc.js";
|
|
4
|
+
import { __ensureGenN } from "./internal/ensure.js";
|
|
5
|
+
/**
|
|
6
|
+
* Positions and converts a mono signal into a stereo signal using given `pos`
|
|
7
|
+
* in the [-1..1] range to control the panning (-1 = left, +1 = right).
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Reference:
|
|
11
|
+
* https://www.musicdsp.org/en/latest/Effects/255-stereo-field-rotation-via-transformation-matrix.html
|
|
12
|
+
*
|
|
13
|
+
* @param pos
|
|
14
|
+
*/
|
|
15
|
+
export const pan = (pos) => new Pan(pos);
|
|
16
|
+
export class Pan extends AProc {
|
|
17
|
+
constructor(pos = 0) {
|
|
18
|
+
super([0, 0]);
|
|
19
|
+
this.pos = pos;
|
|
20
|
+
}
|
|
21
|
+
get pos() {
|
|
22
|
+
return this._pos.deref();
|
|
23
|
+
}
|
|
24
|
+
set pos(pos) {
|
|
25
|
+
this._pos = __ensureGenN(pos, clamp11);
|
|
26
|
+
}
|
|
27
|
+
next(x) {
|
|
28
|
+
const pos = this._pos.next() * QUARTER_PI;
|
|
29
|
+
const s = x * Math.sin(pos);
|
|
30
|
+
const c = x * Math.cos(pos);
|
|
31
|
+
return [c - s, s + c];
|
|
32
|
+
}
|
|
33
|
+
}
|
package/pipe.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IGen, IProc } from "./api.js";
|
|
2
2
|
/**
|
|
3
3
|
* Higher order generator. Composes a new {@link IGen} from given source gen and
|
|
4
|
-
* a number of {@link IProc}s (processed in series,
|
|
4
|
+
* a number of {@link IProc}s (processed in series, using {@link serial}).
|
|
5
5
|
*
|
|
6
6
|
* @param src -
|
|
7
7
|
* @param proc -
|
package/pipe.js
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import { MapG1 } from "./mapg.js";
|
|
2
|
+
import { serial } from "./serial.js";
|
|
2
3
|
export function pipe(src, ...procs) {
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
case 1:
|
|
7
|
-
fn = (x) => a.next(x);
|
|
8
|
-
break;
|
|
9
|
-
case 2:
|
|
10
|
-
fn = (x) => b.next(a.next(x));
|
|
11
|
-
break;
|
|
12
|
-
case 3:
|
|
13
|
-
fn = (x) => c.next(b.next(a.next(x)));
|
|
14
|
-
break;
|
|
15
|
-
case 4:
|
|
16
|
-
fn = (x) => d.next(c.next(b.next(a.next(x))));
|
|
17
|
-
break;
|
|
18
|
-
default:
|
|
19
|
-
fn = (x) => procs.reduce((x, p) => p.next(x), x);
|
|
20
|
-
}
|
|
21
|
-
return new MapG1(fn, src, null);
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
const proc = serial(...procs);
|
|
6
|
+
return new MapG1(proc.next.bind(proc), src, null);
|
|
22
7
|
}
|
package/ref.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AGen } from "./agen.js";
|
|
2
|
+
import type { IGen, IProc } from "./api.js";
|
|
3
|
+
import { AProc } from "./aproc.js";
|
|
4
|
+
export declare const refG: <T>(src: IGen<T>) => RefG<T>;
|
|
5
|
+
export declare class RefG<T> extends AGen<T> {
|
|
6
|
+
protected _src: IGen<T>;
|
|
7
|
+
constructor(_src: IGen<T>);
|
|
8
|
+
next(): T;
|
|
9
|
+
}
|
|
10
|
+
export declare const refP: <A, B>(src: IProc<A, B>) => RefP<A, B>;
|
|
11
|
+
export declare class RefP<A, B> extends AProc<A, B> {
|
|
12
|
+
protected _src: IProc<A, B>;
|
|
13
|
+
constructor(_src: IProc<A, B>);
|
|
14
|
+
next(): B;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ref.d.ts.map
|
package/ref.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AGen } from "./agen.js";
|
|
2
|
+
import { AProc } from "./aproc.js";
|
|
3
|
+
export const refG = (src) => new RefG(src);
|
|
4
|
+
export class RefG extends AGen {
|
|
5
|
+
constructor(_src) {
|
|
6
|
+
super(_src.deref());
|
|
7
|
+
this._src = _src;
|
|
8
|
+
}
|
|
9
|
+
next() {
|
|
10
|
+
return this._src.deref();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const refP = (src) => new RefP(src);
|
|
14
|
+
export class RefP extends AProc {
|
|
15
|
+
constructor(_src) {
|
|
16
|
+
super(_src.deref());
|
|
17
|
+
this._src = _src;
|
|
18
|
+
}
|
|
19
|
+
next() {
|
|
20
|
+
return this._src.deref();
|
|
21
|
+
}
|
|
22
|
+
}
|
package/sincos.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IReset } from "@thi.ng/api";
|
|
1
|
+
import type { ICopy, IReset } from "@thi.ng/api";
|
|
2
2
|
import { AGen } from "./agen.js";
|
|
3
3
|
/**
|
|
4
4
|
* Generator of sine & cosine values of given frequency in the form of
|
|
@@ -17,13 +17,14 @@ import { AGen } from "./agen.js";
|
|
|
17
17
|
* @param freq - normalized freq
|
|
18
18
|
* @param amp - amplitude (default: 1)
|
|
19
19
|
*/
|
|
20
|
-
export declare class SinCos extends AGen<number[]> implements IReset {
|
|
20
|
+
export declare class SinCos extends AGen<number[]> implements ICopy<SinCos>, IReset {
|
|
21
21
|
protected _freq: number;
|
|
22
22
|
protected _amp: number;
|
|
23
23
|
protected _f: number;
|
|
24
24
|
protected _s: number;
|
|
25
25
|
protected _c: number;
|
|
26
26
|
constructor(_freq: number, _amp?: number);
|
|
27
|
+
copy(): SinCos;
|
|
27
28
|
reset(): this;
|
|
28
29
|
next(): number[];
|
|
29
30
|
freq(): number;
|