@thi.ng/dsp 4.6.16 → 4.6.18
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 +13 -10
- 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/osc.js
CHANGED
|
@@ -3,78 +3,44 @@ import { Add, add } from "./add.js";
|
|
|
3
3
|
import { AGen } from "./agen.js";
|
|
4
4
|
import { Const } from "./const.js";
|
|
5
5
|
import { sum } from "./sum.js";
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* modOsc(sin, 0.01, osc(rect, 0.1, 0.2))
|
|
42
|
-
*
|
|
43
|
-
* // AM sin osc using rect osc as amplitude modulator
|
|
44
|
-
* modOsc(sin, 0.01, 0, osc(rect, 0.1, 0.2))
|
|
45
|
-
*
|
|
46
|
-
* // FM & AM sin osc using rect osc as fmod and saw as amod
|
|
47
|
-
* modOsc(sin, 0.01, osc(rect, 0.1, 0.2), osc(saw, 0.05))
|
|
48
|
-
*
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @param osc - stateless main osc
|
|
52
|
-
* @param freq - main osc freq
|
|
53
|
-
* @param fmod - freq modulator
|
|
54
|
-
* @param amod` - normalized freq
|
|
55
|
-
* @param dc` - DC offset / center value
|
|
56
|
-
* @param phase - normalized start phase
|
|
57
|
-
*/
|
|
58
|
-
export const modOsc = (osc, freq, fmod, amod = 1, dc, phase) => new Osc(osc, sum(isNumber(fmod) ? new Const(fmod) : fmod, isNumber(freq) ? add(freq) : freq), amod, dc, phase);
|
|
59
|
-
export class Osc extends AGen {
|
|
60
|
-
_osc;
|
|
61
|
-
_dc;
|
|
62
|
-
_phase;
|
|
63
|
-
_amp;
|
|
64
|
-
constructor(_osc, freq, amp = 1, _dc = 0, phase = 0) {
|
|
65
|
-
super(0);
|
|
66
|
-
this._osc = _osc;
|
|
67
|
-
this._dc = _dc;
|
|
68
|
-
isNumber(freq) ? this.setFreq(freq, phase) : this.setFreq(freq);
|
|
69
|
-
this.setAmp(amp);
|
|
70
|
-
}
|
|
71
|
-
next() {
|
|
72
|
-
return (this._val = this._osc(this._phase.next(), 1, this._amp.next(), this._dc));
|
|
73
|
-
}
|
|
74
|
-
setFreq(freq, phase) {
|
|
75
|
-
this._phase = isNumber(freq) ? new Add(freq, phase || 0) : freq;
|
|
76
|
-
}
|
|
77
|
-
setAmp(amp) {
|
|
78
|
-
this._amp = isNumber(amp) ? new Const(amp) : amp;
|
|
79
|
-
}
|
|
6
|
+
const osc = (osc2, freq, amp, dc, phase) => new Osc(osc2, freq, amp, dc, phase);
|
|
7
|
+
const modOsc = (osc2, freq, fmod, amod = 1, dc, phase) => new Osc(
|
|
8
|
+
osc2,
|
|
9
|
+
sum(
|
|
10
|
+
isNumber(fmod) ? new Const(fmod) : fmod,
|
|
11
|
+
isNumber(freq) ? add(freq) : freq
|
|
12
|
+
),
|
|
13
|
+
amod,
|
|
14
|
+
dc,
|
|
15
|
+
phase
|
|
16
|
+
);
|
|
17
|
+
class Osc extends AGen {
|
|
18
|
+
constructor(_osc, freq, amp = 1, _dc = 0, phase = 0) {
|
|
19
|
+
super(0);
|
|
20
|
+
this._osc = _osc;
|
|
21
|
+
this._dc = _dc;
|
|
22
|
+
isNumber(freq) ? this.setFreq(freq, phase) : this.setFreq(freq);
|
|
23
|
+
this.setAmp(amp);
|
|
24
|
+
}
|
|
25
|
+
_phase;
|
|
26
|
+
_amp;
|
|
27
|
+
next() {
|
|
28
|
+
return this._val = this._osc(
|
|
29
|
+
this._phase.next(),
|
|
30
|
+
1,
|
|
31
|
+
this._amp.next(),
|
|
32
|
+
this._dc
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
setFreq(freq, phase) {
|
|
36
|
+
this._phase = isNumber(freq) ? new Add(freq, phase || 0) : freq;
|
|
37
|
+
}
|
|
38
|
+
setAmp(amp) {
|
|
39
|
+
this._amp = isNumber(amp) ? new Const(amp) : amp;
|
|
40
|
+
}
|
|
80
41
|
}
|
|
42
|
+
export {
|
|
43
|
+
Osc,
|
|
44
|
+
modOsc,
|
|
45
|
+
osc
|
|
46
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/dsp",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.18",
|
|
4
4
|
"description": "Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc internal",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,15 +35,16 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/checks": "^3.4.
|
|
38
|
-
"@thi.ng/errors": "^2.4.
|
|
39
|
-
"@thi.ng/math": "^5.7.
|
|
40
|
-
"@thi.ng/random": "^3.6.
|
|
41
|
-
"@thi.ng/transducers": "^8.8.
|
|
38
|
+
"@thi.ng/api": "^8.9.13",
|
|
39
|
+
"@thi.ng/checks": "^3.4.13",
|
|
40
|
+
"@thi.ng/errors": "^2.4.7",
|
|
41
|
+
"@thi.ng/math": "^5.7.8",
|
|
42
|
+
"@thi.ng/random": "^3.6.19",
|
|
43
|
+
"@thi.ng/transducers": "^8.8.16"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@microsoft/api-extractor": "^7.38.3",
|
|
47
|
+
"esbuild": "^0.19.8",
|
|
45
48
|
"rimraf": "^5.0.5",
|
|
46
49
|
"tools": "^0.0.1",
|
|
47
50
|
"typedoc": "^0.25.4",
|
|
@@ -81,7 +84,7 @@
|
|
|
81
84
|
"access": "public"
|
|
82
85
|
},
|
|
83
86
|
"engines": {
|
|
84
|
-
"node": ">=
|
|
87
|
+
"node": ">=18"
|
|
85
88
|
},
|
|
86
89
|
"files": [
|
|
87
90
|
"./*.js",
|
|
@@ -282,5 +285,5 @@
|
|
|
282
285
|
],
|
|
283
286
|
"year": 2015
|
|
284
287
|
},
|
|
285
|
-
"gitHead": "
|
|
288
|
+
"gitHead": "25a42a81fac8603a1e440a7aa8bc343276211ff4\n"
|
|
286
289
|
}
|
package/pan.js
CHANGED
|
@@ -2,33 +2,27 @@ import { QUARTER_PI } from "@thi.ng/math/api";
|
|
|
2
2
|
import { clamp11 } from "@thi.ng/math/interval";
|
|
3
3
|
import { AProc } from "./aproc.js";
|
|
4
4
|
import { __ensureGenN } from "./internal/ensure.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
set pos(pos) {
|
|
26
|
-
this._pos = __ensureGenN(pos, clamp11);
|
|
27
|
-
}
|
|
28
|
-
next(x) {
|
|
29
|
-
const pos = this._pos.next() * QUARTER_PI;
|
|
30
|
-
const s = x * Math.sin(pos);
|
|
31
|
-
const c = x * Math.cos(pos);
|
|
32
|
-
return [c - s, s + c];
|
|
33
|
-
}
|
|
5
|
+
const pan = (pos) => new Pan(pos);
|
|
6
|
+
class Pan extends AProc {
|
|
7
|
+
_pos;
|
|
8
|
+
constructor(pos = 0) {
|
|
9
|
+
super([0, 0]);
|
|
10
|
+
this.pos = pos;
|
|
11
|
+
}
|
|
12
|
+
get pos() {
|
|
13
|
+
return this._pos.deref();
|
|
14
|
+
}
|
|
15
|
+
set pos(pos) {
|
|
16
|
+
this._pos = __ensureGenN(pos, clamp11);
|
|
17
|
+
}
|
|
18
|
+
next(x) {
|
|
19
|
+
const pos = this._pos.next() * QUARTER_PI;
|
|
20
|
+
const s = x * Math.sin(pos);
|
|
21
|
+
const c = x * Math.cos(pos);
|
|
22
|
+
return [c - s, s + c];
|
|
23
|
+
}
|
|
34
24
|
}
|
|
25
|
+
export {
|
|
26
|
+
Pan,
|
|
27
|
+
pan
|
|
28
|
+
};
|
package/pink-noise.js
CHANGED
|
@@ -1,62 +1,40 @@
|
|
|
1
1
|
import { SYSTEM } from "@thi.ng/random/system";
|
|
2
2
|
import { AGen } from "./agen.js";
|
|
3
3
|
const AMP = [3.8024, 2.9694, 2.597, 3.087, 3.4006];
|
|
4
|
-
const PROB = [
|
|
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
|
-
_amp;
|
|
34
|
-
_bins;
|
|
35
|
-
_psum;
|
|
36
|
-
constructor(_gain = 1, _rnd = SYSTEM, _amp = AMP, prob = PROB) {
|
|
37
|
-
super(0);
|
|
38
|
-
this._gain = _gain;
|
|
39
|
-
this._rnd = _rnd;
|
|
40
|
-
this._amp = _amp;
|
|
41
|
-
this._gain /= _amp.reduce((acc, x) => acc + x, 0);
|
|
42
|
-
this._psum = prob.reduce((acc, x, i) => (acc.push(i > 0 ? acc[i - 1] + x : x), acc), []);
|
|
43
|
-
this._bins = [0, 0, 0, 0, 0];
|
|
44
|
-
}
|
|
45
|
-
reset() {
|
|
46
|
-
this._bins.fill(0);
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
next() {
|
|
50
|
-
const { _bins, _rnd, _amp, _psum } = this;
|
|
51
|
-
const bin = _rnd.float();
|
|
52
|
-
for (let i = 0; i < 5; i++) {
|
|
53
|
-
if (bin <= _psum[i]) {
|
|
54
|
-
_bins[i] = _rnd.norm(_amp[i]);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return (this._val =
|
|
59
|
-
this._gain *
|
|
60
|
-
(_bins[0] + _bins[1] + _bins[2] + _bins[3] + _bins[4]));
|
|
4
|
+
const PROB = [198e-5, 0.0128, 0.049, 0.17, 0.682];
|
|
5
|
+
const pinkNoise = (gain, rnd, amp, prob) => new PinkNoise(gain, rnd, amp, prob);
|
|
6
|
+
class PinkNoise extends AGen {
|
|
7
|
+
constructor(_gain = 1, _rnd = SYSTEM, _amp = AMP, prob = PROB) {
|
|
8
|
+
super(0);
|
|
9
|
+
this._gain = _gain;
|
|
10
|
+
this._rnd = _rnd;
|
|
11
|
+
this._amp = _amp;
|
|
12
|
+
this._gain /= _amp.reduce((acc, x) => acc + x, 0);
|
|
13
|
+
this._psum = prob.reduce(
|
|
14
|
+
(acc, x, i) => (acc.push(i > 0 ? acc[i - 1] + x : x), acc),
|
|
15
|
+
[]
|
|
16
|
+
);
|
|
17
|
+
this._bins = [0, 0, 0, 0, 0];
|
|
18
|
+
}
|
|
19
|
+
_bins;
|
|
20
|
+
_psum;
|
|
21
|
+
reset() {
|
|
22
|
+
this._bins.fill(0);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
next() {
|
|
26
|
+
const { _bins, _rnd, _amp, _psum } = this;
|
|
27
|
+
const bin = _rnd.float();
|
|
28
|
+
for (let i = 0; i < 5; i++) {
|
|
29
|
+
if (bin <= _psum[i]) {
|
|
30
|
+
_bins[i] = _rnd.norm(_amp[i]);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
61
33
|
}
|
|
34
|
+
return this._val = this._gain * (_bins[0] + _bins[1] + _bins[2] + _bins[3] + _bins[4]);
|
|
35
|
+
}
|
|
62
36
|
}
|
|
37
|
+
export {
|
|
38
|
+
PinkNoise,
|
|
39
|
+
pinkNoise
|
|
40
|
+
};
|
package/pipe.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { MapG1 } from "./mapg.js";
|
|
2
2
|
import { serial } from "./serial.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return new MapG1(proc.next.bind(proc), src, null);
|
|
3
|
+
function pipe(src, ...procs) {
|
|
4
|
+
const proc = serial(...procs);
|
|
5
|
+
return new MapG1(proc.next.bind(proc), src, null);
|
|
7
6
|
}
|
|
7
|
+
export {
|
|
8
|
+
pipe
|
|
9
|
+
};
|
package/power.js
CHANGED
|
@@ -1,102 +1,46 @@
|
|
|
1
1
|
import { isNumber } from "@thi.ng/checks/is-number";
|
|
2
2
|
import { isComplex } from "./complex.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let sum = 0;
|
|
10
|
-
for (let i = window.length; i-- > 0;) {
|
|
11
|
-
sum += window[i];
|
|
12
|
-
}
|
|
13
|
-
return sum;
|
|
3
|
+
const integralT = (window) => {
|
|
4
|
+
let sum = 0;
|
|
5
|
+
for (let i = window.length; i-- > 0; ) {
|
|
6
|
+
sum += window[i];
|
|
7
|
+
}
|
|
8
|
+
return sum;
|
|
14
9
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let sum = 0;
|
|
22
|
-
for (let i = window.length; i-- > 0;) {
|
|
23
|
-
sum += window[i] ** 2;
|
|
24
|
-
}
|
|
25
|
-
return sum;
|
|
10
|
+
const integralTSquared = (window) => {
|
|
11
|
+
let sum = 0;
|
|
12
|
+
for (let i = window.length; i-- > 0; ) {
|
|
13
|
+
sum += window[i] ** 2;
|
|
14
|
+
}
|
|
15
|
+
return sum;
|
|
26
16
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
let sum = 0;
|
|
34
|
-
for (let i = real.length; i-- > 0;) {
|
|
35
|
-
sum += Math.hypot(real[i], img[i]);
|
|
36
|
-
}
|
|
37
|
-
return sum;
|
|
17
|
+
const integralF = ([real, img]) => {
|
|
18
|
+
let sum = 0;
|
|
19
|
+
for (let i = real.length; i-- > 0; ) {
|
|
20
|
+
sum += Math.hypot(real[i], img[i]);
|
|
21
|
+
}
|
|
22
|
+
return sum;
|
|
38
23
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
24
|
+
const integralFSquared = ([real, img]) => {
|
|
25
|
+
let sum = 0;
|
|
26
|
+
for (let i = real.length; i-- > 0; ) {
|
|
27
|
+
sum += real[i] ** 2 + img[i] ** 2;
|
|
28
|
+
}
|
|
29
|
+
return sum;
|
|
30
|
+
};
|
|
31
|
+
const powerScale = (scale, base = 1) => isNumber(scale) ? scale : base / integralT(scale);
|
|
32
|
+
const invPowerScale = (scale, base = 1) => isNumber(scale) ? scale : integralT(scale) / base;
|
|
33
|
+
const powerSumSquared = (window) => isComplex(window) ? integralFSquared(window) / window[0].length : integralTSquared(window);
|
|
34
|
+
const powerMeanSquared = (window) => powerSumSquared(window) / (isComplex(window) ? window[0].length : window.length);
|
|
35
|
+
const powerTimeIntegral = (window, fs) => (isComplex(window) ? integralFSquared(window) : integralTSquared(window)) / fs;
|
|
36
|
+
export {
|
|
37
|
+
integralF,
|
|
38
|
+
integralFSquared,
|
|
39
|
+
integralT,
|
|
40
|
+
integralTSquared,
|
|
41
|
+
invPowerScale,
|
|
42
|
+
powerMeanSquared,
|
|
43
|
+
powerScale,
|
|
44
|
+
powerSumSquared,
|
|
45
|
+
powerTimeIntegral
|
|
50
46
|
};
|
|
51
|
-
/**
|
|
52
|
-
* If `scale` is a number, returns it. Else returns `base / integralT(scale)`.
|
|
53
|
-
*
|
|
54
|
-
* @param scale -
|
|
55
|
-
* @param base -
|
|
56
|
-
*/
|
|
57
|
-
export const powerScale = (scale, base = 1) => isNumber(scale) ? scale : base / integralT(scale);
|
|
58
|
-
/**
|
|
59
|
-
* If `scale` is a number, returns it. Else returns `integralT(scale) / base`.
|
|
60
|
-
*
|
|
61
|
-
* @param scale -
|
|
62
|
-
* @param base -
|
|
63
|
-
*/
|
|
64
|
-
export const invPowerScale = (scale, base = 1) => isNumber(scale) ? scale : integralT(scale) / base;
|
|
65
|
-
/**
|
|
66
|
-
* Computes sum squared power of given time or frequency domain window.
|
|
67
|
-
*
|
|
68
|
-
* @remarks
|
|
69
|
-
* References:
|
|
70
|
-
* - http://www.it.uom.gr/teaching/linearalgebra/NumericalRecipiesInC/c13-4.pdf
|
|
71
|
-
* - http://www.hep.ucl.ac.uk/~rjn/saltStuff/fftNormalisation.pdf
|
|
72
|
-
*
|
|
73
|
-
* @param window -
|
|
74
|
-
*/
|
|
75
|
-
export const powerSumSquared = (window) => isComplex(window)
|
|
76
|
-
? integralFSquared(window) / window[0].length
|
|
77
|
-
: integralTSquared(window);
|
|
78
|
-
/**
|
|
79
|
-
* Computes mean squared power of given time or frequency domain window.
|
|
80
|
-
*
|
|
81
|
-
* @remarks
|
|
82
|
-
* References:
|
|
83
|
-
* - http://www.it.uom.gr/teaching/linearalgebra/NumericalRecipiesInC/c13-4.pdf
|
|
84
|
-
* - http://www.hep.ucl.ac.uk/~rjn/saltStuff/fftNormalisation.pdf
|
|
85
|
-
*
|
|
86
|
-
* @param window -
|
|
87
|
-
*/
|
|
88
|
-
export const powerMeanSquared = (window) => powerSumSquared(window) /
|
|
89
|
-
(isComplex(window) ? window[0].length : window.length);
|
|
90
|
-
/**
|
|
91
|
-
* Computes time-integral squared power of given time or frequency domain
|
|
92
|
-
* window.
|
|
93
|
-
*
|
|
94
|
-
* @remarks
|
|
95
|
-
* References:
|
|
96
|
-
* - http://www.it.uom.gr/teaching/linearalgebra/NumericalRecipiesInC/c13-4.pdf
|
|
97
|
-
* - http://www.hep.ucl.ac.uk/~rjn/saltStuff/fftNormalisation.pdf
|
|
98
|
-
*
|
|
99
|
-
* @param window -
|
|
100
|
-
*/
|
|
101
|
-
export const powerTimeIntegral = (window, fs) => (isComplex(window) ? integralFSquared(window) : integralTSquared(window)) /
|
|
102
|
-
fs;
|
package/product.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MapG2, MapG3 } from "./mapg.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
? new MapG3((a, b, c) => a * b * c, a, b, c, 0)
|
|
5
|
-
: new MapG2((a, b) => a * b, a, b, 0);
|
|
2
|
+
function product(a, b, c) {
|
|
3
|
+
return c ? new MapG3((a2, b2, c2) => a2 * b2 * c2, a, b, c, 0) : new MapG2((a2, b2) => a2 * b2, a, b, 0);
|
|
6
4
|
}
|
|
5
|
+
export {
|
|
6
|
+
product
|
|
7
|
+
};
|
package/reciprocal.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { AGen } from "./agen.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
next() {
|
|
21
|
-
this._n += this._step;
|
|
22
|
-
return (this._val = 1 / this._n);
|
|
23
|
-
}
|
|
2
|
+
const reciprocal = (step) => new Reciprocal(step);
|
|
3
|
+
class Reciprocal extends AGen {
|
|
4
|
+
constructor(_step = 1) {
|
|
5
|
+
super(1);
|
|
6
|
+
this._step = _step;
|
|
7
|
+
this.reset();
|
|
8
|
+
}
|
|
9
|
+
_n;
|
|
10
|
+
reset() {
|
|
11
|
+
this._n = 1 - this._step;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
next() {
|
|
15
|
+
this._n += this._step;
|
|
16
|
+
return this._val = 1 / this._n;
|
|
17
|
+
}
|
|
24
18
|
}
|
|
19
|
+
export {
|
|
20
|
+
Reciprocal,
|
|
21
|
+
reciprocal
|
|
22
|
+
};
|
package/ref.js
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { AGen } from "./agen.js";
|
|
2
2
|
import { AProc } from "./aproc.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
3
|
+
const refG = (src) => new RefG(src);
|
|
4
|
+
class RefG extends AGen {
|
|
5
|
+
constructor(_src) {
|
|
6
|
+
super(_src.deref());
|
|
7
|
+
this._src = _src;
|
|
8
|
+
}
|
|
9
|
+
next() {
|
|
10
|
+
return this._src.deref();
|
|
11
|
+
}
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
13
|
+
const refP = (src) => new RefP(src);
|
|
14
|
+
class RefP extends AProc {
|
|
15
|
+
constructor(_src) {
|
|
16
|
+
super(_src.deref());
|
|
17
|
+
this._src = _src;
|
|
18
|
+
}
|
|
19
|
+
next() {
|
|
20
|
+
return this._src.deref();
|
|
21
|
+
}
|
|
24
22
|
}
|
|
23
|
+
export {
|
|
24
|
+
RefG,
|
|
25
|
+
RefP,
|
|
26
|
+
refG,
|
|
27
|
+
refP
|
|
28
|
+
};
|