@thi.ng/colored-noise 0.3.23 → 1.0.1
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 +16 -5
- package/README.md +3 -3
- package/api.d.ts +26 -0
- package/api.js +6 -0
- package/blue.d.ts +3 -5
- package/blue.js +10 -8
- package/green.d.ts +3 -5
- package/green.js +2 -5
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +17 -14
- package/pink.d.ts +3 -5
- package/pink.js +11 -8
- package/red.d.ts +3 -5
- package/red.js +10 -8
- package/violet.d.ts +3 -5
- package/violet.js +2 -5
- package/white.d.ts +3 -4
- package/white.js +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-
|
|
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:
|
|
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
package/blue.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ColoredNoiseOpts } from "./api.js";
|
|
2
2
|
/**
|
|
3
3
|
* High-pass filtered noise. Opposite of {@link red}.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param scale -
|
|
7
|
-
* @param rnd -
|
|
5
|
+
* @param opts -
|
|
8
6
|
*/
|
|
9
|
-
export declare function blue(
|
|
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 {
|
|
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
|
|
7
|
-
* @param scale -
|
|
8
|
-
* @param rnd -
|
|
6
|
+
* @param opts -
|
|
9
7
|
*/
|
|
10
|
-
export function* blue(
|
|
11
|
-
const
|
|
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 /
|
|
15
|
+
const invN = 1 / bins;
|
|
14
16
|
let acc = sum(state);
|
|
15
|
-
for (let i = 0, sign = -1; true; ++i >=
|
|
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 {
|
|
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
|
|
7
|
-
* @param scale -
|
|
8
|
-
* @param rnd -
|
|
6
|
+
* @param opts -
|
|
9
7
|
*/
|
|
10
|
-
export declare const green: (
|
|
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
|
|
9
|
-
* @param scale -
|
|
10
|
-
* @param rnd -
|
|
7
|
+
* @param opts -
|
|
11
8
|
*/
|
|
12
|
-
export const green = (
|
|
9
|
+
export const green = (opts) => interleave(blue(opts), blue(opts));
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/colored-noise",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
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.
|
|
38
|
-
"@thi.ng/random": "^3.3.
|
|
37
|
+
"@thi.ng/binary": "^3.3.11",
|
|
38
|
+
"@thi.ng/random": "^3.3.16"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@microsoft/api-extractor": "^7.33.5",
|
|
42
|
-
"@thi.ng/api": "^8.
|
|
43
|
-
"@thi.ng/dsp": "^4.2.
|
|
44
|
-
"@thi.ng/dsp-io-wav": "^2.1.
|
|
45
|
-
"@thi.ng/testament": "^0.3.
|
|
46
|
-
"@thi.ng/text-canvas": "^2.4.
|
|
47
|
-
"@thi.ng/transducers": "^8.3.
|
|
48
|
-
"@thi.ng/vectors": "^7.5.
|
|
42
|
+
"@thi.ng/api": "^8.5.0",
|
|
43
|
+
"@thi.ng/dsp": "^4.2.23",
|
|
44
|
+
"@thi.ng/dsp-io-wav": "^2.1.29",
|
|
45
|
+
"@thi.ng/testament": "^0.3.5",
|
|
46
|
+
"@thi.ng/text-canvas": "^2.4.18",
|
|
47
|
+
"@thi.ng/transducers": "^8.3.24",
|
|
48
|
+
"@thi.ng/vectors": "^7.5.25",
|
|
49
49
|
"rimraf": "^3.0.2",
|
|
50
50
|
"tools": "^0.0.1",
|
|
51
|
-
"typedoc": "^0.23.
|
|
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
|
-
"
|
|
78
|
-
"
|
|
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": "
|
|
114
|
+
"gitHead": "75ec32ff7f1b7b5e72e7a04ace24732cd5d6c774\n"
|
|
112
115
|
}
|
package/pink.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
|
15
|
-
* @param scale -
|
|
16
|
-
* @param rnd -
|
|
14
|
+
* @param opts -
|
|
17
15
|
*/
|
|
18
|
-
export declare function pink(
|
|
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 {
|
|
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
|
|
17
|
-
* @param scale -
|
|
18
|
-
* @param rnd -
|
|
16
|
+
* @param opts -
|
|
19
17
|
*/
|
|
20
|
-
export function* pink(
|
|
21
|
-
const
|
|
22
|
-
|
|
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) %
|
|
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
|
|
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
|
|
6
|
-
* @param scale -
|
|
7
|
-
* @param rnd -
|
|
5
|
+
* @param opts -
|
|
8
6
|
*/
|
|
9
|
-
export declare function red(
|
|
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 {
|
|
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
|
|
7
|
-
* @param scale -
|
|
8
|
-
* @param rnd -
|
|
6
|
+
* @param opts -
|
|
9
7
|
*/
|
|
10
|
-
export function* red(
|
|
11
|
-
const
|
|
12
|
-
|
|
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 >=
|
|
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 {
|
|
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
|
|
6
|
-
* @param scale -
|
|
7
|
-
* @param rnd -
|
|
5
|
+
* @param opts -
|
|
8
6
|
*/
|
|
9
|
-
export declare const violet: (
|
|
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
|
|
8
|
-
* @param scale -
|
|
9
|
-
* @param rnd -
|
|
6
|
+
* @param opts -
|
|
10
7
|
*/
|
|
11
|
-
export const violet = (
|
|
8
|
+
export const violet = (opts) => interleave(red(opts), red(opts));
|
package/white.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import
|
|
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
|
|
7
|
-
* @param rnd -
|
|
6
|
+
* @param opts -
|
|
8
7
|
*/
|
|
9
|
-
export declare function white(
|
|
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 {
|
|
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
|
|
7
|
-
* @param rnd -
|
|
6
|
+
* @param opts -
|
|
8
7
|
*/
|
|
9
|
-
export function* white(
|
|
8
|
+
export function* white(opts) {
|
|
9
|
+
const { scale, rnd } = { ...DEFAULT_OPTS, ...opts };
|
|
10
10
|
while (true) {
|
|
11
11
|
yield rnd.norm(scale);
|
|
12
12
|
}
|