@thi.ng/dsp 4.6.16 → 4.6.17
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 +1 -1
- package/README.md +1 -1
- package/add.js +24 -38
- package/addg.js +4 -19
- package/adsr.js +148 -156
- package/agen.js +17 -21
- package/allpass.js +37 -38
- package/alt.js +26 -22
- package/anti-alias.js +8 -37
- package/api.js +0 -1
- package/aproc.js +24 -30
- package/biquad.js +188 -184
- package/bounce.js +15 -16
- package/complex.js +4 -1
- package/const.js +12 -13
- package/convert.js +18 -64
- package/cosine.js +43 -48
- package/curve.js +12 -41
- package/dcblock.js +9 -10
- package/delay.js +100 -111
- package/feedback-delay.js +23 -30
- package/fft.js +188 -334
- package/filter-delay.js +23 -27
- package/filter-response.js +22 -33
- package/foldback.js +26 -35
- package/impulse-train.js +35 -37
- package/impulse.js +27 -42
- package/integrator.js +27 -32
- package/internal/ensure.js +4 -1
- package/internal/take.js +8 -5
- package/iterable.js +32 -43
- package/line.js +10 -25
- package/madd.js +25 -40
- package/mapg.js +77 -69
- package/merge.js +18 -20
- package/mix.js +20 -16
- package/mul.js +24 -38
- package/multiplex.js +15 -11
- package/onepole.js +41 -42
- package/osc-additive.js +25 -53
- package/osc-cos.js +4 -1
- package/osc-dsf.js +15 -52
- package/osc-mix.js +6 -20
- package/osc-parabolic.js +4 -13
- package/osc-rect.js +6 -8
- package/osc-saw.js +4 -1
- package/osc-sin.js +4 -1
- package/osc-tri.js +4 -1
- package/osc-wavetable.js +12 -9
- package/osc.js +40 -74
- package/package.json +12 -9
- package/pan.js +23 -29
- package/pink-noise.js +35 -57
- package/pipe.js +6 -4
- package/power.js +40 -96
- package/product.js +5 -4
- package/reciprocal.js +20 -22
- package/ref.js +24 -20
- package/serial.js +59 -60
- package/sincos.js +45 -61
- package/sum.js +5 -4
- package/svf.js +74 -78
- package/sweep.js +4 -27
- package/waveshaper.js +41 -60
- package/white-noise.js +17 -23
- package/window.js +67 -52
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/add.js
CHANGED
|
@@ -1,40 +1,26 @@
|
|
|
1
1
|
import { AGen } from "./agen.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
_start;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.reset();
|
|
23
|
-
}
|
|
24
|
-
copy() {
|
|
25
|
-
return new Add(this._step, this._start, this._clamp);
|
|
26
|
-
}
|
|
27
|
-
reset() {
|
|
28
|
-
this._val = this._start - this._step;
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
next() {
|
|
32
|
-
let v = this._val + this._step;
|
|
33
|
-
return (this._val =
|
|
34
|
-
this._clamp !== undefined
|
|
35
|
-
? this._start < this._clamp
|
|
36
|
-
? Math.min(v, this._clamp)
|
|
37
|
-
: Math.max(v, this._clamp)
|
|
38
|
-
: v);
|
|
39
|
-
}
|
|
2
|
+
const add = (step, start, clamp) => new Add(step, start, clamp);
|
|
3
|
+
class Add extends AGen {
|
|
4
|
+
constructor(_step = 1, _start = 0, _clamp) {
|
|
5
|
+
super(0);
|
|
6
|
+
this._step = _step;
|
|
7
|
+
this._start = _start;
|
|
8
|
+
this._clamp = _clamp;
|
|
9
|
+
this.reset();
|
|
10
|
+
}
|
|
11
|
+
copy() {
|
|
12
|
+
return new Add(this._step, this._start, this._clamp);
|
|
13
|
+
}
|
|
14
|
+
reset() {
|
|
15
|
+
this._val = this._start - this._step;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
next() {
|
|
19
|
+
let v = this._val + this._step;
|
|
20
|
+
return this._val = this._clamp !== void 0 ? this._start < this._clamp ? Math.min(v, this._clamp) : Math.max(v, this._clamp) : v;
|
|
21
|
+
}
|
|
40
22
|
}
|
|
23
|
+
export {
|
|
24
|
+
Add,
|
|
25
|
+
add
|
|
26
|
+
};
|
package/addg.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
1
|
import { MapG1 } from "./mapg.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @remarks
|
|
7
|
-
* Note this is different to {@link sum}, which merely sums given
|
|
8
|
-
* argument gens for each step, but doesn't for a reduction like this
|
|
9
|
-
* gen.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* addg(constant(1), 10).take(5)
|
|
14
|
-
* // [ 10, 11, 12, 13, 14 ]
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @param step -
|
|
18
|
-
* @param start -
|
|
19
|
-
*/
|
|
20
|
-
export const addG = (step, start = 0) => new MapG1((a, b) => a + b, step, start - step.deref());
|
|
2
|
+
const addG = (step, start = 0) => new MapG1((a, b) => a + b, step, start - step.deref());
|
|
3
|
+
export {
|
|
4
|
+
addG
|
|
5
|
+
};
|
package/adsr.js
CHANGED
|
@@ -2,164 +2,156 @@ import { clamp01 } from "@thi.ng/math/interval";
|
|
|
2
2
|
import { add } from "./add.js";
|
|
3
3
|
import { AGen } from "./agen.js";
|
|
4
4
|
import { curve } from "./curve.js";
|
|
5
|
-
var EnvPhase
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})(EnvPhase ||
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.
|
|
5
|
+
var EnvPhase = /* @__PURE__ */ ((EnvPhase2) => {
|
|
6
|
+
EnvPhase2[EnvPhase2["ATTACK"] = 0] = "ATTACK";
|
|
7
|
+
EnvPhase2[EnvPhase2["DECAY"] = 1] = "DECAY";
|
|
8
|
+
EnvPhase2[EnvPhase2["SUSTAIN"] = 2] = "SUSTAIN";
|
|
9
|
+
EnvPhase2[EnvPhase2["RELEASE"] = 3] = "RELEASE";
|
|
10
|
+
EnvPhase2[EnvPhase2["IDLE"] = 4] = "IDLE";
|
|
11
|
+
return EnvPhase2;
|
|
12
|
+
})(EnvPhase || {});
|
|
13
|
+
const adsr = (opts) => new ADSR(opts);
|
|
14
|
+
class ADSR extends AGen {
|
|
15
|
+
_phase;
|
|
16
|
+
_curve;
|
|
17
|
+
_atime;
|
|
18
|
+
_dtime;
|
|
19
|
+
_rtime;
|
|
20
|
+
_acurve;
|
|
21
|
+
_dcurve;
|
|
22
|
+
_sustain;
|
|
23
|
+
_speriod;
|
|
24
|
+
_gain;
|
|
25
|
+
constructor(opts) {
|
|
26
|
+
super(0);
|
|
27
|
+
opts = {
|
|
28
|
+
a: 0,
|
|
29
|
+
d: 0,
|
|
30
|
+
s: 1,
|
|
31
|
+
r: 0,
|
|
32
|
+
acurve: 0.1,
|
|
33
|
+
dcurve: 1e-3,
|
|
34
|
+
slen: Infinity,
|
|
35
|
+
gain: 1,
|
|
36
|
+
...opts
|
|
37
|
+
};
|
|
38
|
+
this.setAttack(opts.a);
|
|
39
|
+
this.setDecay(opts.d);
|
|
40
|
+
this.setRelease(opts.r);
|
|
41
|
+
this.setSustain(opts.s, opts.slen);
|
|
42
|
+
this.setCurveA(opts.acurve);
|
|
43
|
+
this.setCurveD(opts.dcurve);
|
|
44
|
+
this.setGain(opts.gain);
|
|
45
|
+
this.reset();
|
|
46
|
+
}
|
|
47
|
+
copy() {
|
|
48
|
+
return new ADSR({
|
|
49
|
+
a: this._atime,
|
|
50
|
+
d: this._dtime,
|
|
51
|
+
s: this._sustain,
|
|
52
|
+
r: this._rtime,
|
|
53
|
+
acurve: this._acurve,
|
|
54
|
+
dcurve: this._dcurve,
|
|
55
|
+
gain: this._gain,
|
|
56
|
+
slen: this._speriod
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
reset() {
|
|
60
|
+
this._phase = 0 /* ATTACK */;
|
|
61
|
+
this._curve = curve(0, 1, this._atime + 1, this._acurve, true);
|
|
62
|
+
this._val = 0;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
release() {
|
|
66
|
+
if (this._phase < 3 /* RELEASE */) {
|
|
67
|
+
this._phase = 3 /* RELEASE */;
|
|
68
|
+
this._curve = curve(
|
|
69
|
+
this._sustain,
|
|
70
|
+
0,
|
|
71
|
+
this._rtime + 1,
|
|
72
|
+
this._dcurve,
|
|
73
|
+
true
|
|
74
|
+
);
|
|
70
75
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
76
|
+
}
|
|
77
|
+
isSustained() {
|
|
78
|
+
return this._phase === 2 /* SUSTAIN */;
|
|
79
|
+
}
|
|
80
|
+
isDone() {
|
|
81
|
+
return this._phase === 4 /* IDLE */;
|
|
82
|
+
}
|
|
83
|
+
next() {
|
|
84
|
+
let v;
|
|
85
|
+
switch (this._phase) {
|
|
86
|
+
case 4 /* IDLE */:
|
|
87
|
+
return 0;
|
|
88
|
+
case 0 /* ATTACK */:
|
|
89
|
+
v = this._curve.next();
|
|
90
|
+
if (v >= 1) {
|
|
91
|
+
v = 1;
|
|
92
|
+
this._phase = 1 /* DECAY */;
|
|
93
|
+
this._curve = curve(
|
|
94
|
+
1,
|
|
95
|
+
this._sustain,
|
|
96
|
+
this._dtime + 1,
|
|
97
|
+
this._dcurve,
|
|
98
|
+
true
|
|
99
|
+
);
|
|
93
100
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
break;
|
|
114
|
-
case EnvPhase.DECAY:
|
|
115
|
-
v = this._curve.next();
|
|
116
|
-
if (v <= this._sustain) {
|
|
117
|
-
v = this._sustain;
|
|
118
|
-
this._phase = EnvPhase.SUSTAIN;
|
|
119
|
-
this._curve = add(1, 1);
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
case EnvPhase.SUSTAIN:
|
|
123
|
-
if (this._curve.next() >= this._speriod) {
|
|
124
|
-
this.release();
|
|
125
|
-
}
|
|
126
|
-
return this._val;
|
|
127
|
-
case EnvPhase.RELEASE:
|
|
128
|
-
v = this._curve.next();
|
|
129
|
-
if (v < 0) {
|
|
130
|
-
v = 0;
|
|
131
|
-
this._phase = EnvPhase.IDLE;
|
|
132
|
-
}
|
|
101
|
+
break;
|
|
102
|
+
case 1 /* DECAY */:
|
|
103
|
+
v = this._curve.next();
|
|
104
|
+
if (v <= this._sustain) {
|
|
105
|
+
v = this._sustain;
|
|
106
|
+
this._phase = 2 /* SUSTAIN */;
|
|
107
|
+
this._curve = add(1, 1);
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
case 2 /* SUSTAIN */:
|
|
111
|
+
if (this._curve.next() >= this._speriod) {
|
|
112
|
+
this.release();
|
|
113
|
+
}
|
|
114
|
+
return this._val;
|
|
115
|
+
case 3 /* RELEASE */:
|
|
116
|
+
v = this._curve.next();
|
|
117
|
+
if (v < 0) {
|
|
118
|
+
v = 0;
|
|
119
|
+
this._phase = 4 /* IDLE */;
|
|
133
120
|
}
|
|
134
|
-
return (this._val = v * this._gain);
|
|
135
|
-
}
|
|
136
|
-
setAttack(steps) {
|
|
137
|
-
this._atime = Math.max(steps, 0);
|
|
138
|
-
}
|
|
139
|
-
setDecay(steps) {
|
|
140
|
-
this._dtime = Math.max(steps, 0);
|
|
141
|
-
}
|
|
142
|
-
setRelease(steps) {
|
|
143
|
-
this._rtime = Math.max(steps, 0);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Sets sustain level & duration. If the latter is omitted, the
|
|
147
|
-
* current value will be retained.
|
|
148
|
-
*
|
|
149
|
-
* @param level -
|
|
150
|
-
* @param duration -
|
|
151
|
-
*/
|
|
152
|
-
setSustain(level, duration) {
|
|
153
|
-
this._sustain = clamp01(level);
|
|
154
|
-
duration !== undefined && (this._speriod = duration);
|
|
155
|
-
}
|
|
156
|
-
setCurveA(ratio) {
|
|
157
|
-
this._acurve = Math.max(ratio, 1e-9);
|
|
158
|
-
}
|
|
159
|
-
setCurveD(ratio) {
|
|
160
|
-
this._dcurve = Math.max(ratio, 1e-9);
|
|
161
|
-
}
|
|
162
|
-
setGain(gain) {
|
|
163
|
-
this._gain = gain;
|
|
164
121
|
}
|
|
122
|
+
return this._val = v * this._gain;
|
|
123
|
+
}
|
|
124
|
+
setAttack(steps) {
|
|
125
|
+
this._atime = Math.max(steps, 0);
|
|
126
|
+
}
|
|
127
|
+
setDecay(steps) {
|
|
128
|
+
this._dtime = Math.max(steps, 0);
|
|
129
|
+
}
|
|
130
|
+
setRelease(steps) {
|
|
131
|
+
this._rtime = Math.max(steps, 0);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Sets sustain level & duration. If the latter is omitted, the
|
|
135
|
+
* current value will be retained.
|
|
136
|
+
*
|
|
137
|
+
* @param level -
|
|
138
|
+
* @param duration -
|
|
139
|
+
*/
|
|
140
|
+
setSustain(level, duration) {
|
|
141
|
+
this._sustain = clamp01(level);
|
|
142
|
+
duration !== void 0 && (this._speriod = duration);
|
|
143
|
+
}
|
|
144
|
+
setCurveA(ratio) {
|
|
145
|
+
this._acurve = Math.max(ratio, 1e-9);
|
|
146
|
+
}
|
|
147
|
+
setCurveD(ratio) {
|
|
148
|
+
this._dcurve = Math.max(ratio, 1e-9);
|
|
149
|
+
}
|
|
150
|
+
setGain(gain) {
|
|
151
|
+
this._gain = gain;
|
|
152
|
+
}
|
|
165
153
|
}
|
|
154
|
+
export {
|
|
155
|
+
ADSR,
|
|
156
|
+
adsr
|
|
157
|
+
};
|
package/agen.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { __take } from "./internal/take.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*[Symbol.iterator]() {
|
|
17
|
-
while (true)
|
|
18
|
-
yield this.next();
|
|
19
|
-
}
|
|
20
|
-
take(num, out = [], idx = 0) {
|
|
21
|
-
return __take(this, num, out, idx);
|
|
22
|
-
}
|
|
2
|
+
class AGen {
|
|
3
|
+
constructor(_val) {
|
|
4
|
+
this._val = _val;
|
|
5
|
+
}
|
|
6
|
+
deref() {
|
|
7
|
+
return this._val;
|
|
8
|
+
}
|
|
9
|
+
*[Symbol.iterator]() {
|
|
10
|
+
while (true)
|
|
11
|
+
yield this.next();
|
|
12
|
+
}
|
|
13
|
+
take(num, out = [], idx = 0) {
|
|
14
|
+
return __take(this, num, out, idx);
|
|
15
|
+
}
|
|
23
16
|
}
|
|
17
|
+
export {
|
|
18
|
+
AGen
|
|
19
|
+
};
|
package/allpass.js
CHANGED
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
import { PI, QUARTER_PI } from "@thi.ng/math/api";
|
|
2
2
|
import { clamp05 } from "@thi.ng/math/interval";
|
|
3
3
|
import { AProc } from "./aproc.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
freq
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
setFreq(freq) {
|
|
39
|
-
this._freq = clamp05(freq);
|
|
40
|
-
this._coeff = Math.tan(freq * PI - QUARTER_PI);
|
|
41
|
-
}
|
|
4
|
+
const allpass = (freq) => new AllPass1(freq);
|
|
5
|
+
class AllPass1 extends AProc {
|
|
6
|
+
_freq;
|
|
7
|
+
_coeff;
|
|
8
|
+
_z1;
|
|
9
|
+
constructor(freq) {
|
|
10
|
+
super(0);
|
|
11
|
+
this.setFreq(freq);
|
|
12
|
+
this.reset();
|
|
13
|
+
}
|
|
14
|
+
reset() {
|
|
15
|
+
this._z1 = 0;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
next(x) {
|
|
19
|
+
const { _coeff, _z1 } = this;
|
|
20
|
+
x -= _z1 * _coeff;
|
|
21
|
+
this._z1 = x;
|
|
22
|
+
return x * _coeff + _z1;
|
|
23
|
+
}
|
|
24
|
+
low(x) {
|
|
25
|
+
return (x + this.next(x)) * 0.5;
|
|
26
|
+
}
|
|
27
|
+
high(x) {
|
|
28
|
+
return (x - this.next(x)) * 0.5;
|
|
29
|
+
}
|
|
30
|
+
freq() {
|
|
31
|
+
return this._freq;
|
|
32
|
+
}
|
|
33
|
+
setFreq(freq) {
|
|
34
|
+
this._freq = clamp05(freq);
|
|
35
|
+
this._coeff = Math.tan(freq * PI - QUARTER_PI);
|
|
36
|
+
}
|
|
42
37
|
}
|
|
38
|
+
export {
|
|
39
|
+
AllPass1,
|
|
40
|
+
allpass
|
|
41
|
+
};
|
package/alt.js
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { AGen } from "./agen.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
_b;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return (this._val = (this._flip = !this._flip) ? this._b : this._a);
|
|
23
|
-
}
|
|
2
|
+
const alt = (n = 1) => new Alt(n, -n);
|
|
3
|
+
const altT = (a, b) => new Alt(a, b);
|
|
4
|
+
const altB = (x = true) => new Alt(x, !x);
|
|
5
|
+
class Alt extends AGen {
|
|
6
|
+
constructor(_a, _b) {
|
|
7
|
+
super(_b);
|
|
8
|
+
this._a = _a;
|
|
9
|
+
this._b = _b;
|
|
10
|
+
}
|
|
11
|
+
_flip = true;
|
|
12
|
+
copy() {
|
|
13
|
+
return new Alt(this._a, this._b);
|
|
14
|
+
}
|
|
15
|
+
reset() {
|
|
16
|
+
this._flip = true;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
next() {
|
|
20
|
+
return this._val = (this._flip = !this._flip) ? this._b : this._a;
|
|
21
|
+
}
|
|
24
22
|
}
|
|
23
|
+
export {
|
|
24
|
+
Alt,
|
|
25
|
+
alt,
|
|
26
|
+
altB,
|
|
27
|
+
altT
|
|
28
|
+
};
|
package/anti-alias.js
CHANGED
|
@@ -1,38 +1,9 @@
|
|
|
1
1
|
import { HALF_PI } from "@thi.ng/math/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* -
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @param i - curr octave [1..n]
|
|
11
|
-
*/
|
|
12
|
-
export const gibbs = (n, i) => Math.cos(((i - 1) * HALF_PI) / n) ** 2;
|
|
13
|
-
/**
|
|
14
|
-
* Fejér weight for `k`-th harmonic in a Fourier series of length `n`.
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* Used for attenuating the {@link gibbs} factor when summing a Fourier series.
|
|
18
|
-
* Linearly attentuates higher harmonics, with the first bin receiving a weight
|
|
19
|
-
* on 1 and the last bin `1/n`.
|
|
20
|
-
*
|
|
21
|
-
* @param k -
|
|
22
|
-
* @param n -
|
|
23
|
-
*/
|
|
24
|
-
export const fejer = (k, n) => (n - k) / n;
|
|
25
|
-
/**
|
|
26
|
-
* Polynomial attenuation to create bandlimited version of a signal.
|
|
27
|
-
*
|
|
28
|
-
* - http://research.spa.aalto.fi/publications/papers/smc2010-phaseshaping/
|
|
29
|
-
* - http://www.kvraudio.com/forum/viewtopic.php?t=375517
|
|
30
|
-
*
|
|
31
|
-
* @param dt - time step
|
|
32
|
-
* @param t - normalized phase
|
|
33
|
-
*/
|
|
34
|
-
export const polyBLEP = (dt, t) => t < dt
|
|
35
|
-
? ((t /= dt), t + t - t * t - 1)
|
|
36
|
-
: t > 1 - dt
|
|
37
|
-
? ((t = (t - 1) / dt), t * t + t + t + 1)
|
|
38
|
-
: 0;
|
|
2
|
+
const gibbs = (n, i) => Math.cos((i - 1) * HALF_PI / n) ** 2;
|
|
3
|
+
const fejer = (k, n) => (n - k) / n;
|
|
4
|
+
const polyBLEP = (dt, t) => t < dt ? (t /= dt, t + t - t * t - 1) : t > 1 - dt ? (t = (t - 1) / dt, t * t + t + t + 1) : 0;
|
|
5
|
+
export {
|
|
6
|
+
fejer,
|
|
7
|
+
gibbs,
|
|
8
|
+
polyBLEP
|
|
9
|
+
};
|
package/api.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|