@thi.ng/colored-noise 0.3.22 → 1.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-10-28T19:08:39Z
3
+ - **Last updated**: 2022-11-23T22:46:54Z
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,17 @@ 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
+ # [1.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/colored-noise@1.0.0) (2022-11-23)
13
+
14
+ #### 🛑 Breaking changes
15
+
16
+ - [#363](https://github.com/thi-ng/umbrella/issues/363) add ColoredNoiseOpts ([b2d1d13](https://github.com/thi-ng/umbrella/commit/b2d1d13))
17
+ - BREAKING CHANGE: replace generator args with uniform options object
18
+ - add `ColoredNoiseOpts` config interface
19
+ - update all generators
20
+ - update tools/examples
21
+ - update readme
22
+
12
23
  ## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/colored-noise@0.3.0) (2021-11-17)
13
24
 
14
25
  #### 🚀 Features
@@ -32,9 +43,9 @@ and/or version bumps of transitive dependencies.
32
43
 
33
44
  #### ♻️ Refactoring
34
45
 
35
- - update imports in all tests/pkgs ([effd591](https://github.com/thi-ng/umbrella/commit/effd591))
36
46
  - update imports in all pkgs ([5fa2b6f](https://github.com/thi-ng/umbrella/commit/5fa2b6f))
37
47
  - add .js suffix for all relative imports
48
+ - update imports in all tests/pkgs ([effd591](https://github.com/thi-ng/umbrella/commit/effd591))
38
49
 
39
50
  ## [0.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/colored-noise@0.2.0) (2021-10-12)
40
51
 
@@ -55,11 +66,11 @@ and/or version bumps of transitive dependencies.
55
66
 
56
67
  #### ♻️ Refactoring
57
68
 
58
- - minor pkg restructure (various) ([47f88d2](https://github.com/thi-ng/umbrella/commit/47f88d2))
59
- - update imports ([c0d9e17](https://github.com/thi-ng/umbrella/commit/c0d9e17))
60
- - update all test stubs ([f2d6d53](https://github.com/thi-ng/umbrella/commit/f2d6d53))
61
69
  - update all tests in _all_ pkgs ([8b582bc](https://github.com/thi-ng/umbrella/commit/8b582bc))
62
70
  - update all to use [@thi.ng/testament](https://github.com/thi-ng/umbrella/tree/main/packages/testament)
71
+ - update all test stubs ([f2d6d53](https://github.com/thi-ng/umbrella/commit/f2d6d53))
72
+ - update imports ([c0d9e17](https://github.com/thi-ng/umbrella/commit/c0d9e17))
73
+ - minor pkg restructure (various) ([47f88d2](https://github.com/thi-ng/umbrella/commit/47f88d2))
63
74
 
64
75
  ### [0.1.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/colored-noise@0.1.1) (2020-09-13)
65
76
 
package/README.md CHANGED
@@ -375,7 +375,7 @@ node --experimental-repl-await
375
375
  > const coloredNoise = await import("@thi.ng/colored-noise");
376
376
  ```
377
377
 
378
- Package sizes (gzipped, pre-treeshake): ESM: 538 bytes
378
+ Package sizes (gzipped, pre-treeshake): ESM: 562 bytes
379
379
 
380
380
  ## Dependencies
381
381
 
@@ -415,7 +415,7 @@ import { take } from "@thi.ng/transducers";
415
415
  // custom config
416
416
  import { XsAdd } from "@thi.ng/random";
417
417
 
418
- [...take(20, red(16, 1, new XsAdd(0xdecafbad)))]
418
+ [...take(20, red({ bins: 16, scale: 1, rnd: new XsAdd(0xdecafbad) }))]
419
419
  // [ -0.17761799097704192, -0.10240132532836904, -0.1103387340810939, ...]
420
420
  ```
421
421
 
@@ -431,7 +431,7 @@ const FS = 44100;
431
431
 
432
432
  const signal = product(
433
433
  // wrap green noise as IGen
434
- iterable(green(16), 0),
434
+ iterable(green({ bins: 16 }), 0),
435
435
  // apply gain envelope
436
436
  adsr({ a: 0.005 * FS, d: 0.2 * FS, s: 0 })
437
437
  );
package/api.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { INorm } from "@thi.ng/random";
2
+ export interface ColoredNoiseOpts {
3
+ /**
4
+ * Number of spectral accumulation bins.
5
+ *
6
+ * @remarks
7
+ * This option will be ignored by the {@link white} noise generator.
8
+ *
9
+ * Default value for {@link pink} noise is 8, for others 2.
10
+ */
11
+ bins: number;
12
+ /**
13
+ * Amplitude scale factor.
14
+ *
15
+ * @defaultValue 1
16
+ */
17
+ scale: number;
18
+ /**
19
+ * PRNG implementation (see thi.ng/random for further details & implementations)
20
+ *
21
+ * @default SYSTEM (aka Math.random)
22
+ */
23
+ rnd: INorm;
24
+ }
25
+ export declare const DEFAULT_OPTS: ColoredNoiseOpts;
26
+ //# sourceMappingURL=api.d.ts.map
package/api.js ADDED
@@ -0,0 +1,6 @@
1
+ import { SYSTEM } from "@thi.ng/random/system";
2
+ export const DEFAULT_OPTS = {
3
+ bins: 2,
4
+ scale: 1,
5
+ rnd: SYSTEM,
6
+ };
package/blue.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import type { INorm } from "@thi.ng/random";
1
+ import { ColoredNoiseOpts } from "./api.js";
2
2
  /**
3
3
  * High-pass filtered noise. Opposite of {@link red}.
4
4
  *
5
- * @param n -
6
- * @param scale -
7
- * @param rnd -
5
+ * @param opts -
8
6
  */
9
- export declare function blue(n?: number, scale?: number, rnd?: INorm): Generator<number, void, unknown>;
7
+ export declare function blue(opts?: Partial<ColoredNoiseOpts>): Generator<number, void, unknown>;
10
8
  //# sourceMappingURL=blue.d.ts.map
package/blue.js CHANGED
@@ -1,18 +1,20 @@
1
- import { SYSTEM } from "@thi.ng/random/system";
1
+ import { DEFAULT_OPTS } from "./api.js";
2
2
  import { preseed, sum } from "./utils.js";
3
3
  /**
4
4
  * High-pass filtered noise. Opposite of {@link red}.
5
5
  *
6
- * @param n -
7
- * @param scale -
8
- * @param rnd -
6
+ * @param opts -
9
7
  */
10
- export function* blue(n = 2, scale = 1, rnd = SYSTEM) {
11
- const state = preseed(n, scale, rnd);
8
+ export function* blue(opts) {
9
+ const { bins, scale, rnd } = {
10
+ ...DEFAULT_OPTS,
11
+ ...opts,
12
+ };
13
+ const state = preseed(bins, scale, rnd);
12
14
  state.forEach((x, i) => (state[i] = i & 1 ? x : -x));
13
- const invN = 1 / n;
15
+ const invN = 1 / bins;
14
16
  let acc = sum(state);
15
- for (let i = 0, sign = -1; true; ++i >= n && (i = 0)) {
17
+ for (let i = 0, sign = -1; true; ++i >= bins && (i = 0)) {
16
18
  acc -= state[i];
17
19
  acc += state[i] = sign * rnd.norm(scale);
18
20
  sign ^= 0xfffffffe;
package/green.d.ts CHANGED
@@ -1,11 +1,9 @@
1
- import type { INorm } from "@thi.ng/random";
1
+ import type { ColoredNoiseOpts } from "./api.js";
2
2
  /**
3
3
  * Band-pass filtered noise (interleaved blue noise). Opposite of
4
4
  * {@link violet}.
5
5
  *
6
- * @param n -
7
- * @param scale -
8
- * @param rnd -
6
+ * @param opts -
9
7
  */
10
- export declare const green: (n?: number, scale?: number, rnd?: INorm) => Generator<number, void, unknown>;
8
+ export declare const green: (opts?: Partial<ColoredNoiseOpts>) => Generator<number, void, unknown>;
11
9
  //# sourceMappingURL=green.d.ts.map
package/green.js CHANGED
@@ -1,12 +1,9 @@
1
- import { SYSTEM } from "@thi.ng/random/system";
2
1
  import { blue } from "./blue.js";
3
2
  import { interleave } from "./utils.js";
4
3
  /**
5
4
  * Band-pass filtered noise (interleaved blue noise). Opposite of
6
5
  * {@link violet}.
7
6
  *
8
- * @param n -
9
- * @param scale -
10
- * @param rnd -
7
+ * @param opts -
11
8
  */
12
- export const green = (n = 2, scale = 1, rnd = SYSTEM) => interleave(blue(n, scale, rnd), blue(n, scale, rnd));
9
+ export const green = (opts) => interleave(blue(opts), blue(opts));
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./api.js";
1
2
  export * from "./blue.js";
2
3
  export * from "./green.js";
3
4
  export * from "./pink.js";
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./api.js";
1
2
  export * from "./blue.js";
2
3
  export * from "./green.js";
3
4
  export * from "./pink.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/colored-noise",
3
- "version": "0.3.22",
3
+ "version": "1.0.0",
4
4
  "description": "Customizable O(1) ES6 generators for colored noise",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,21 +34,21 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/binary": "^3.3.8",
38
- "@thi.ng/random": "^3.3.13"
37
+ "@thi.ng/binary": "^3.3.10",
38
+ "@thi.ng/random": "^3.3.15"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@microsoft/api-extractor": "^7.33.5",
42
- "@thi.ng/api": "^8.4.4",
43
- "@thi.ng/dsp": "^4.2.19",
44
- "@thi.ng/dsp-io-wav": "^2.1.25",
45
- "@thi.ng/testament": "^0.3.4",
46
- "@thi.ng/text-canvas": "^2.4.14",
47
- "@thi.ng/transducers": "^8.3.20",
48
- "@thi.ng/vectors": "^7.5.21",
42
+ "@thi.ng/api": "^8.4.6",
43
+ "@thi.ng/dsp": "^4.2.22",
44
+ "@thi.ng/dsp-io-wav": "^2.1.28",
45
+ "@thi.ng/testament": "^0.3.5",
46
+ "@thi.ng/text-canvas": "^2.4.17",
47
+ "@thi.ng/transducers": "^8.3.23",
48
+ "@thi.ng/vectors": "^7.5.24",
49
49
  "rimraf": "^3.0.2",
50
50
  "tools": "^0.0.1",
51
- "typedoc": "^0.23.18",
51
+ "typedoc": "^0.23.20",
52
52
  "typescript": "^4.8.4"
53
53
  },
54
54
  "keywords": [
@@ -74,13 +74,16 @@
74
74
  "node": ">=12.7"
75
75
  },
76
76
  "files": [
77
- "*.js",
78
- "*.d.ts"
77
+ "./*.js",
78
+ "./*.d.ts"
79
79
  ],
80
80
  "exports": {
81
81
  ".": {
82
82
  "default": "./index.js"
83
83
  },
84
+ "./api": {
85
+ "default": "./api.js"
86
+ },
84
87
  "./blue": {
85
88
  "default": "./blue.js"
86
89
  },
@@ -108,5 +111,5 @@
108
111
  ],
109
112
  "year": 2015
110
113
  },
111
- "gitHead": "41e59c7ad9bf24bb0230a5f60d05715e0fc1c1e6\n"
114
+ "gitHead": "044ee6a3895720fc78e115032d4d831b63510929\n"
112
115
  }
package/pink.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { INorm } from "@thi.ng/random";
1
+ import { ColoredNoiseOpts } from "./api.js";
2
2
  /**
3
3
  * Exponential decay (1/f) noise, based on Voss-McCarthy algorithm.
4
4
  *
@@ -11,9 +11,7 @@ import type { INorm } from "@thi.ng/random";
11
11
  * - https://www.dsprelated.com/showarticle/908.php
12
12
  * - https://www.firstpr.com.au/dsp/pink-noise/#Voss-McCartney
13
13
  *
14
- * @param n -
15
- * @param scale -
16
- * @param rnd -
14
+ * @param opts -
17
15
  */
18
- export declare function pink(n?: number, scale?: number, rnd?: INorm): Generator<number, void, unknown>;
16
+ export declare function pink(opts?: Partial<ColoredNoiseOpts>): Generator<number, void, unknown>;
19
17
  //# sourceMappingURL=pink.d.ts.map
package/pink.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ctz32 } from "@thi.ng/binary/count";
2
- import { SYSTEM } from "@thi.ng/random/system";
2
+ import { DEFAULT_OPTS } from "./api.js";
3
3
  import { preseed, sum } from "./utils.js";
4
4
  /**
5
5
  * Exponential decay (1/f) noise, based on Voss-McCarthy algorithm.
@@ -13,16 +13,19 @@ import { preseed, sum } from "./utils.js";
13
13
  * - https://www.dsprelated.com/showarticle/908.php
14
14
  * - https://www.firstpr.com.au/dsp/pink-noise/#Voss-McCartney
15
15
  *
16
- * @param n -
17
- * @param scale -
18
- * @param rnd -
16
+ * @param opts -
19
17
  */
20
- export function* pink(n = 8, scale = 1, rnd = SYSTEM) {
21
- const state = preseed(n, scale, rnd);
22
- const invN = 1 / n;
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;
23
26
  let acc = sum(state);
24
27
  for (let i = 0; true; i = (i + 1) >>> 0) {
25
- const id = ctz32(i) % n;
28
+ const id = ctz32(i) % bins;
26
29
  acc -= state[id];
27
30
  acc += state[id] = rnd.norm(scale);
28
31
  yield acc * invN;
package/red.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import type { INorm } from "@thi.ng/random";
1
+ import { ColoredNoiseOpts } from "./api.js";
2
2
  /**
3
3
  * Low-pass filtered noise (same as brown noise). Opposite of {@link blue}.
4
4
  *
5
- * @param n -
6
- * @param scale -
7
- * @param rnd -
5
+ * @param opts -
8
6
  */
9
- export declare function red(n?: number, scale?: number, rnd?: INorm): Generator<number, void, unknown>;
7
+ export declare function red(opts?: Partial<ColoredNoiseOpts>): Generator<number, void, unknown>;
10
8
  //# sourceMappingURL=red.d.ts.map
package/red.js CHANGED
@@ -1,17 +1,19 @@
1
- import { SYSTEM } from "@thi.ng/random/system";
1
+ import { DEFAULT_OPTS } from "./api.js";
2
2
  import { preseed, sum } from "./utils.js";
3
3
  /**
4
4
  * Low-pass filtered noise (same as brown noise). Opposite of {@link blue}.
5
5
  *
6
- * @param n -
7
- * @param scale -
8
- * @param rnd -
6
+ * @param opts -
9
7
  */
10
- export function* red(n = 2, scale = 1, rnd = SYSTEM) {
11
- const state = preseed(n, scale, rnd);
12
- const invN = 1 / n;
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;
13
15
  let acc = sum(state);
14
- for (let i = 0; true; ++i >= n && (i = 0)) {
16
+ for (let i = 0; true; ++i >= bins && (i = 0)) {
15
17
  acc -= state[i];
16
18
  acc += state[i] = rnd.norm(scale);
17
19
  yield acc * invN;
package/violet.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import type { INorm } from "@thi.ng/random";
1
+ import type { ColoredNoiseOpts } from "./api.js";
2
2
  /**
3
3
  * Band-stop filtered noise (interleaved red noise). Opposite of {@link green}.
4
4
  *
5
- * @param n -
6
- * @param scale -
7
- * @param rnd -
5
+ * @param opts -
8
6
  */
9
- export declare const violet: (n?: number, scale?: number, rnd?: INorm) => Generator<number, void, unknown>;
7
+ export declare const violet: (opts?: Partial<ColoredNoiseOpts>) => Generator<number, void, unknown>;
10
8
  //# sourceMappingURL=violet.d.ts.map
package/violet.js CHANGED
@@ -1,11 +1,8 @@
1
- import { SYSTEM } from "@thi.ng/random/system";
2
1
  import { red } from "./red.js";
3
2
  import { interleave } from "./utils.js";
4
3
  /**
5
4
  * Band-stop filtered noise (interleaved red noise). Opposite of {@link green}.
6
5
  *
7
- * @param n -
8
- * @param scale -
9
- * @param rnd -
6
+ * @param opts -
10
7
  */
11
- export const violet = (n = 2, scale = 1, rnd = SYSTEM) => interleave(red(n, scale, rnd), red(n, scale, rnd));
8
+ export const violet = (opts) => interleave(red(opts), red(opts));
package/white.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import type { INorm } from "@thi.ng/random";
1
+ import { ColoredNoiseOpts } from "./api.js";
2
2
  /**
3
3
  * Unfiltered noise w/ uniform distribution. Merely yields samples from
4
4
  * given PRNG.
5
5
  *
6
- * @param scale -
7
- * @param rnd -
6
+ * @param opts -
8
7
  */
9
- export declare function white(scale?: number, rnd?: INorm): Generator<number, void, unknown>;
8
+ export declare function white(opts?: Partial<ColoredNoiseOpts>): Generator<number, void, unknown>;
10
9
  //# sourceMappingURL=white.d.ts.map
package/white.js CHANGED
@@ -1,12 +1,12 @@
1
- import { SYSTEM } from "@thi.ng/random/system";
1
+ import { DEFAULT_OPTS } from "./api.js";
2
2
  /**
3
3
  * Unfiltered noise w/ uniform distribution. Merely yields samples from
4
4
  * given PRNG.
5
5
  *
6
- * @param scale -
7
- * @param rnd -
6
+ * @param opts -
8
7
  */
9
- export function* white(scale = 1, rnd = SYSTEM) {
8
+ export function* white(opts) {
9
+ const { scale, rnd } = { ...DEFAULT_OPTS, ...opts };
10
10
  while (true) {
11
11
  yield rnd.norm(scale);
12
12
  }