@thi.ng/colored-noise 1.0.39 → 1.0.41

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-09T19:12:03Z
3
+ - **Last updated**: 2023-12-18T13:41:19Z
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.
package/api.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import { SYSTEM } from "@thi.ng/random/system";
2
- export const DEFAULT_OPTS = {
3
- bins: 2,
4
- scale: 1,
5
- rnd: SYSTEM,
2
+ const DEFAULT_OPTS = {
3
+ bins: 2,
4
+ scale: 1,
5
+ rnd: SYSTEM
6
+ };
7
+ export {
8
+ DEFAULT_OPTS
6
9
  };
package/blue.js CHANGED
@@ -1,23 +1,21 @@
1
1
  import { DEFAULT_OPTS } from "./api.js";
2
2
  import { preseed, sum } from "./utils.js";
3
- /**
4
- * High-pass filtered noise. Opposite of {@link red}.
5
- *
6
- * @param opts -
7
- */
8
- export function* blue(opts) {
9
- const { bins, scale, rnd } = {
10
- ...DEFAULT_OPTS,
11
- ...opts,
12
- };
13
- const state = preseed(bins, scale, rnd);
14
- state.forEach((x, i) => (state[i] = i & 1 ? x : -x));
15
- const invN = 1 / bins;
16
- let acc = sum(state);
17
- for (let i = 0, sign = -1; true; ++i >= bins && (i = 0)) {
18
- acc -= state[i];
19
- acc += state[i] = sign * rnd.norm(scale);
20
- sign ^= 0xfffffffe;
21
- yield sign * acc * invN;
22
- }
3
+ function* blue(opts) {
4
+ const { bins, scale, rnd } = {
5
+ ...DEFAULT_OPTS,
6
+ ...opts
7
+ };
8
+ const state = preseed(bins, scale, rnd);
9
+ state.forEach((x, i) => state[i] = i & 1 ? x : -x);
10
+ const invN = 1 / bins;
11
+ let acc = sum(state);
12
+ for (let i = 0, sign = -1; true; ++i >= bins && (i = 0)) {
13
+ acc -= state[i];
14
+ acc += state[i] = sign * rnd.norm(scale);
15
+ sign ^= 4294967294;
16
+ yield sign * acc * invN;
17
+ }
23
18
  }
19
+ export {
20
+ blue
21
+ };
package/green.js CHANGED
@@ -1,9 +1,6 @@
1
1
  import { blue } from "./blue.js";
2
2
  import { interleave } from "./utils.js";
3
- /**
4
- * Band-pass filtered noise (interleaved blue noise). Opposite of
5
- * {@link violet}.
6
- *
7
- * @param opts -
8
- */
9
- export const green = (opts) => interleave(blue(opts), blue(opts));
3
+ const green = (opts) => interleave(blue(opts), blue(opts));
4
+ export {
5
+ green
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/colored-noise",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "Customizable O(1) ES6 generators for colored noise",
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",
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,17 +35,18 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/binary": "^3.3.40",
37
- "@thi.ng/random": "^3.6.17"
38
+ "@thi.ng/binary": "^3.4.1",
39
+ "@thi.ng/random": "^3.6.19"
38
40
  },
39
41
  "devDependencies": {
40
42
  "@microsoft/api-extractor": "^7.38.3",
41
- "@thi.ng/api": "^8.9.11",
42
- "@thi.ng/dsp": "^4.6.16",
43
- "@thi.ng/dsp-io-wav": "^2.1.81",
44
- "@thi.ng/text-canvas": "^2.6.22",
45
- "@thi.ng/transducers": "^8.8.14",
46
- "@thi.ng/vectors": "^7.8.8",
43
+ "@thi.ng/api": "^8.9.13",
44
+ "@thi.ng/dsp": "^4.6.18",
45
+ "@thi.ng/dsp-io-wav": "^2.1.83",
46
+ "@thi.ng/text-canvas": "^2.6.25",
47
+ "@thi.ng/transducers": "^8.8.16",
48
+ "@thi.ng/vectors": "^7.8.11",
49
+ "esbuild": "^0.19.8",
47
50
  "rimraf": "^5.0.5",
48
51
  "tools": "^0.0.1",
49
52
  "typedoc": "^0.25.4",
@@ -69,7 +72,7 @@
69
72
  "access": "public"
70
73
  },
71
74
  "engines": {
72
- "node": ">=12.7"
75
+ "node": ">=18"
73
76
  },
74
77
  "files": [
75
78
  "./*.js",
@@ -109,5 +112,5 @@
109
112
  ],
110
113
  "year": 2015
111
114
  },
112
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
115
+ "gitHead": "25a42a81fac8603a1e440a7aa8bc343276211ff4\n"
113
116
  }
package/pink.js CHANGED
@@ -1,33 +1,22 @@
1
1
  import { ctz32 } from "@thi.ng/binary/count";
2
2
  import { DEFAULT_OPTS } from "./api.js";
3
3
  import { preseed, sum } from "./utils.js";
4
- /**
5
- * Exponential decay (1/f) noise, based on Voss-McCarthy algorithm.
6
- *
7
- * @remarks
8
- * The number of internal states should be in the [4..32] range (default: 8).
9
- * Due to JS integer limitations, `n` > 32 are meaningless.
10
- *
11
- * References:
12
- *
13
- * - https://www.dsprelated.com/showarticle/908.php
14
- * - https://www.firstpr.com.au/dsp/pink-noise/#Voss-McCartney
15
- *
16
- * @param opts -
17
- */
18
- export function* pink(opts) {
19
- const { bins, scale, rnd } = {
20
- ...DEFAULT_OPTS,
21
- bins: 8,
22
- ...opts,
23
- };
24
- const state = preseed(bins, scale, rnd);
25
- const invN = 1 / bins;
26
- let acc = sum(state);
27
- for (let i = 0; true; i = (i + 1) >>> 0) {
28
- const id = ctz32(i) % bins;
29
- acc -= state[id];
30
- acc += state[id] = rnd.norm(scale);
31
- yield acc * invN;
32
- }
4
+ function* pink(opts) {
5
+ const { bins, scale, rnd } = {
6
+ ...DEFAULT_OPTS,
7
+ bins: 8,
8
+ ...opts
9
+ };
10
+ const state = preseed(bins, scale, rnd);
11
+ const invN = 1 / bins;
12
+ let acc = sum(state);
13
+ for (let i = 0; true; i = i + 1 >>> 0) {
14
+ const id = ctz32(i) % bins;
15
+ acc -= state[id];
16
+ acc += state[id] = rnd.norm(scale);
17
+ yield acc * invN;
18
+ }
33
19
  }
20
+ export {
21
+ pink
22
+ };
package/red.js CHANGED
@@ -1,21 +1,19 @@
1
1
  import { DEFAULT_OPTS } from "./api.js";
2
2
  import { preseed, sum } from "./utils.js";
3
- /**
4
- * Low-pass filtered noise (same as brown noise). Opposite of {@link blue}.
5
- *
6
- * @param opts -
7
- */
8
- export function* red(opts) {
9
- const { bins, scale, rnd } = {
10
- ...DEFAULT_OPTS,
11
- ...opts,
12
- };
13
- const state = preseed(bins, scale, rnd);
14
- const invN = 1 / bins;
15
- let acc = sum(state);
16
- for (let i = 0; true; ++i >= bins && (i = 0)) {
17
- acc -= state[i];
18
- acc += state[i] = rnd.norm(scale);
19
- yield acc * invN;
20
- }
3
+ function* red(opts) {
4
+ const { bins, scale, rnd } = {
5
+ ...DEFAULT_OPTS,
6
+ ...opts
7
+ };
8
+ const state = preseed(bins, scale, rnd);
9
+ const invN = 1 / bins;
10
+ let acc = sum(state);
11
+ for (let i = 0; true; ++i >= bins && (i = 0)) {
12
+ acc -= state[i];
13
+ acc += state[i] = rnd.norm(scale);
14
+ yield acc * invN;
15
+ }
21
16
  }
17
+ export {
18
+ red
19
+ };
package/utils.js CHANGED
@@ -1,17 +1,22 @@
1
- export const preseed = (n, scale, rnd) => {
2
- const state = new Array(n);
3
- for (let i = 0; i < n; i++) {
4
- state[i] = rnd.norm(scale);
5
- }
6
- return state;
1
+ const preseed = (n, scale, rnd) => {
2
+ const state = new Array(n);
3
+ for (let i = 0; i < n; i++) {
4
+ state[i] = rnd.norm(scale);
5
+ }
6
+ return state;
7
7
  };
8
- export const sum = (src) => src.reduce((sum, x) => sum + x, 0);
9
- export function* interleave(a, b) {
10
- const src = [a[Symbol.iterator](), b[Symbol.iterator]()];
11
- for (let i = 0; true; i ^= 1) {
12
- const next = src[i].next();
13
- if (next.done)
14
- return;
15
- yield next.value;
16
- }
8
+ const sum = (src) => src.reduce((sum2, x) => sum2 + x, 0);
9
+ function* interleave(a, b) {
10
+ const src = [a[Symbol.iterator](), b[Symbol.iterator]()];
11
+ for (let i = 0; true; i ^= 1) {
12
+ const next = src[i].next();
13
+ if (next.done)
14
+ return;
15
+ yield next.value;
16
+ }
17
17
  }
18
+ export {
19
+ interleave,
20
+ preseed,
21
+ sum
22
+ };
package/violet.js CHANGED
@@ -1,8 +1,6 @@
1
1
  import { red } from "./red.js";
2
2
  import { interleave } from "./utils.js";
3
- /**
4
- * Band-stop filtered noise (interleaved red noise). Opposite of {@link green}.
5
- *
6
- * @param opts -
7
- */
8
- export const violet = (opts) => interleave(red(opts), red(opts));
3
+ const violet = (opts) => interleave(red(opts), red(opts));
4
+ export {
5
+ violet
6
+ };
package/white.js CHANGED
@@ -1,13 +1,10 @@
1
1
  import { DEFAULT_OPTS } from "./api.js";
2
- /**
3
- * Unfiltered noise w/ uniform distribution. Merely yields samples from
4
- * given PRNG.
5
- *
6
- * @param opts -
7
- */
8
- export function* white(opts) {
9
- const { scale, rnd } = { ...DEFAULT_OPTS, ...opts };
10
- while (true) {
11
- yield rnd.norm(scale);
12
- }
2
+ function* white(opts) {
3
+ const { scale, rnd } = { ...DEFAULT_OPTS, ...opts };
4
+ while (true) {
5
+ yield rnd.norm(scale);
6
+ }
13
7
  }
8
+ export {
9
+ white
10
+ };