@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.
Files changed (66) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -1
  3. package/add.js +24 -38
  4. package/addg.js +4 -19
  5. package/adsr.js +148 -156
  6. package/agen.js +17 -21
  7. package/allpass.js +37 -38
  8. package/alt.js +26 -22
  9. package/anti-alias.js +8 -37
  10. package/api.js +0 -1
  11. package/aproc.js +24 -30
  12. package/biquad.js +188 -184
  13. package/bounce.js +15 -16
  14. package/complex.js +4 -1
  15. package/const.js +12 -13
  16. package/convert.js +18 -64
  17. package/cosine.js +43 -48
  18. package/curve.js +12 -41
  19. package/dcblock.js +9 -10
  20. package/delay.js +100 -111
  21. package/feedback-delay.js +23 -30
  22. package/fft.js +188 -334
  23. package/filter-delay.js +23 -27
  24. package/filter-response.js +22 -33
  25. package/foldback.js +26 -35
  26. package/impulse-train.js +35 -37
  27. package/impulse.js +27 -42
  28. package/integrator.js +27 -32
  29. package/internal/ensure.js +4 -1
  30. package/internal/take.js +8 -5
  31. package/iterable.js +32 -43
  32. package/line.js +10 -25
  33. package/madd.js +25 -40
  34. package/mapg.js +77 -69
  35. package/merge.js +18 -20
  36. package/mix.js +20 -16
  37. package/mul.js +24 -38
  38. package/multiplex.js +15 -11
  39. package/onepole.js +41 -42
  40. package/osc-additive.js +25 -53
  41. package/osc-cos.js +4 -1
  42. package/osc-dsf.js +15 -52
  43. package/osc-mix.js +6 -20
  44. package/osc-parabolic.js +4 -13
  45. package/osc-rect.js +6 -8
  46. package/osc-saw.js +4 -1
  47. package/osc-sin.js +4 -1
  48. package/osc-tri.js +4 -1
  49. package/osc-wavetable.js +12 -9
  50. package/osc.js +40 -74
  51. package/package.json +13 -10
  52. package/pan.js +23 -29
  53. package/pink-noise.js +35 -57
  54. package/pipe.js +6 -4
  55. package/power.js +40 -96
  56. package/product.js +5 -4
  57. package/reciprocal.js +20 -22
  58. package/ref.js +24 -20
  59. package/serial.js +59 -60
  60. package/sincos.js +45 -61
  61. package/sum.js +5 -4
  62. package/svf.js +74 -78
  63. package/sweep.js +4 -27
  64. package/waveshaper.js +41 -60
  65. package/white-noise.js +17 -23
  66. 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
- * Higher order oscillator gen, wrapping a {@link StatelessOscillator} function
8
- * and supporting either constant or {@link IGen}-based frequency and amplitude,
9
- * thus allowing for FM/AM modulation. Furthermore, a constant `dc` offset
10
- * (center value) and/or start `phase` can be specified (both default to: 0).
11
- *
12
- * @remarks
13
- * If `freq` is a number, it must be given as normalized frequency (same for
14
- * `phase`). If `freq` is an `IGen`, it must be configured to produce normalized
15
- * frequency values (e.g. if using an `Osc` by setting its `amp` to a normalized
16
- * freq and its `dc` offset to `baseFreq * TAU`). Also see {@link fmodOsc} for
17
- * syntax sugar. The `phase` arg is only used if `freq` is NOT an `IGen`.
18
- *
19
- * The oscillator initializes to zero and its
20
- * [`IDeref`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html).deref}
21
- * value is only available / valid after the first invocation of
22
- * {@link IGen.next}.
23
- *
24
- * @param osc - stateless osc
25
- * @param freq - normalized freq
26
- * @param amp - amplitude
27
- * @param dc - DC offset / center value
28
- * @param phase - normalized start phase
29
- */
30
- export const osc = (osc, freq, amp, dc, phase) => new Osc(osc, freq, amp, dc, phase);
31
- /**
32
- * Syntax sugar for creating frequency modulated `Osc` gens.
33
- *
34
- * @remarks
35
- * The `fmod` value defines the +/- normalized frequency modulation
36
- * range, added to the main oscillator `freq`.
37
- *
38
- * @example
39
- * ```ts
40
- * // FM sin osc using rect osc as frequency modulator
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.16",
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 clean && tsc --declaration",
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.11",
37
- "@thi.ng/checks": "^3.4.11",
38
- "@thi.ng/errors": "^2.4.5",
39
- "@thi.ng/math": "^5.7.6",
40
- "@thi.ng/random": "^3.6.17",
41
- "@thi.ng/transducers": "^8.8.14"
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": ">=12.7"
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": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
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
- * 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
- _pos;
18
- constructor(pos = 0) {
19
- super([0, 0]);
20
- this.pos = pos;
21
- }
22
- get pos() {
23
- return this._pos.deref();
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 = [0.00198, 0.0128, 0.049, 0.17, 0.682];
5
- /**
6
- * Pink noise generator with customizable frequency distribution. The
7
- * default config produces a power spectrum roughly following the `1/f`
8
- * pink characteristic.
9
- *
10
- * @remarks
11
- * Custom frequency/power distributions can be obtained by providing
12
- * `amp` and `prob`ability tuples for the 5 internal bins used to
13
- * compute the noise. `amp` defines per-bin power contributions, the
14
- * latter bin update probabilities.
15
- *
16
- * Resulting noise values are normalized to given `gain`, which itself
17
- * is scale relative to the sum of given `amp` values.
18
- *
19
- * References:
20
- * - http://web.archive.org/web/20160513114217/http://home.earthlink.net/~ltrammell/tech/newpink.htm
21
- * - http://web.archive.org/web/20160515145318if_/http://home.earthlink.net/~ltrammell/tech/pinkalg.htm
22
- * - https://www.musicdsp.org/en/latest/Synthesis/220-trammell-pink-noise-c-class.html
23
- *
24
- * @param gain -
25
- * @param rnd -
26
- * @param amp -
27
- * @param prob -
28
- */
29
- export const pinkNoise = (gain, rnd, amp, prob) => new PinkNoise(gain, rnd, amp, prob);
30
- export class PinkNoise extends AGen {
31
- _gain;
32
- _rnd;
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
- export function pipe(src, ...procs) {
4
- // @ts-ignore
5
- const proc = serial(...procs);
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
- * Computes the sum of the given array.
5
- *
6
- * @param window -
7
- */
8
- export const integralT = (window) => {
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
- * Computes the squared sum of given array.
17
- *
18
- * @param window -
19
- */
20
- export const integralTSquared = (window) => {
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
- * Computes the `sum(|c(i)|)` for given complex array.
29
- *
30
- * @param window -
31
- */
32
- export const integralF = ([real, img]) => {
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
- * Computes the `sum(|c(i)|^2)` for given complex array.
41
- *
42
- * @param window -
43
- */
44
- export const integralFSquared = ([real, img]) => {
45
- let sum = 0;
46
- for (let i = real.length; i-- > 0;) {
47
- sum += real[i] ** 2 + img[i] ** 2;
48
- }
49
- return sum;
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
- export function product(a, b, c) {
3
- return c
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
- * Returns a gen which yield sequence `y(t) = 1 / (y(t - 1) + step)`.
4
- *
5
- * @param step -
6
- */
7
- export const reciprocal = (step) => new Reciprocal(step);
8
- export class Reciprocal extends AGen {
9
- _step;
10
- _n;
11
- constructor(_step = 1) {
12
- super(1);
13
- this._step = _step;
14
- this.reset();
15
- }
16
- reset() {
17
- this._n = 1 - this._step;
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
- export const refG = (src) => new RefG(src);
4
- export class RefG extends AGen {
5
- _src;
6
- constructor(_src) {
7
- super(_src.deref());
8
- this._src = _src;
9
- }
10
- next() {
11
- return this._src.deref();
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
- export const refP = (src) => new RefP(src);
15
- export class RefP extends AProc {
16
- _src;
17
- constructor(_src) {
18
- super(_src.deref());
19
- this._src = _src;
20
- }
21
- next() {
22
- return this._src.deref();
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
+ };