@audio/synth-noise 1.1.1 → 2.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/audio.d.ts +35 -0
- package/audio.js +2 -1
- package/colors.d.ts +9 -0
- package/colors.js +22 -11
- package/package.json +11 -6
package/audio.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Generated from the audio.js manifest (params metadata is the source of truth).
|
|
2
|
+
// Regenerate: node tools/dts.js in @audio/compile. Do not edit by hand.
|
|
3
|
+
|
|
4
|
+
/** Automatable number — scalar, `t => value` fn, or breakpoint curve {t, v} */
|
|
5
|
+
type Auto = number | ((t: number) => number) | { t: number[], v: number[] }
|
|
6
|
+
/** Per-block param values as delivered by hosts (numbers arrive as 1-length Float32Array) */
|
|
7
|
+
type Live = Record<string, Float32Array | string | boolean>
|
|
8
|
+
type Ctx = { sampleRate: number, maxBlockSize: number, maxChannels: number, currentTime: number, duration?: number, events?: readonly any[], emit?: (name: string, ...args: any[]) => void, [k: string]: unknown }
|
|
9
|
+
type Process = (inputs: Float32Array[][], outputs: Float32Array[][], params: Live) => void
|
|
10
|
+
|
|
11
|
+
/** Chainable-host options for 'noise' */
|
|
12
|
+
export interface NoiseOptions {
|
|
13
|
+
/** default "white" */
|
|
14
|
+
"color"?: "white" | "pink" | "brown" | "blue" | "violet"
|
|
15
|
+
/** 1..65536 (default 1) */
|
|
16
|
+
"seed"?: Auto
|
|
17
|
+
/** 0..1 (default 0.8) */
|
|
18
|
+
"gain"?: Auto
|
|
19
|
+
at?: number | string
|
|
20
|
+
duration?: number | string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export declare const noise: {
|
|
24
|
+
(ctx: Ctx): Process
|
|
25
|
+
channels: {"inputs":[],"outputs":"any"}
|
|
26
|
+
streaming: false
|
|
27
|
+
params: {
|
|
28
|
+
/** default "white" */
|
|
29
|
+
"color": { type: "enum", values: ["white","pink","brown","blue","violet"], default: "white" }
|
|
30
|
+
/** 1..65536 (default 1) */
|
|
31
|
+
"seed": { type: "number", default: 1 }
|
|
32
|
+
/** 0..1 (default 0.8) */
|
|
33
|
+
"gain": { type: "number", default: 0.8 }
|
|
34
|
+
}
|
|
35
|
+
}
|
package/audio.js
CHANGED
|
@@ -12,7 +12,8 @@ export const noise = (ctx) => {
|
|
|
12
12
|
const n = out[0].length
|
|
13
13
|
const fn = colors[params.color]
|
|
14
14
|
for (let c = 0; c < out.length; c++) {
|
|
15
|
-
|
|
15
|
+
// colors API is seconds (family convention); n/fs·fs rounds back to exactly n samples
|
|
16
|
+
const d = fn(n / ctx.sampleRate, { fs: ctx.sampleRate, seed: (params.seed[0] | 0) + c * 7919 }) // independent per channel
|
|
16
17
|
const g = params.gain[0]
|
|
17
18
|
for (let i = 0; i < n; i++) out[c][i] = d[i] * g
|
|
18
19
|
}
|
package/colors.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type NoiseOpts = { seed?: number, fs?: number }
|
|
2
|
+
export function white(duration?: number, opts?: NoiseOpts): Float32Array
|
|
3
|
+
export function pink(duration?: number, opts?: NoiseOpts): Float32Array
|
|
4
|
+
export function brown(duration?: number, opts?: NoiseOpts & { leak?: number }): Float32Array
|
|
5
|
+
export function blue(duration?: number, opts?: NoiseOpts): Float32Array
|
|
6
|
+
export function violet(duration?: number, opts?: NoiseOpts): Float32Array
|
|
7
|
+
export { default as pinkNoise } from './pink-noise.js'
|
|
8
|
+
/** Seeded noise generator — duration in seconds (family convention: (duration, opts)) */
|
|
9
|
+
export default function noise(duration?: number, opts?: NoiseOpts & { color?: 'white' | 'pink' | 'brown' | 'blue' | 'violet' }): Float32Array
|
package/colors.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
// Colors of noise — seeded, deterministic generators with defined spectral slopes:
|
|
2
2
|
// white 0 dB/oct · pink −3 (Kellet filter) · brown −6 (leaky integration) ·
|
|
3
3
|
// blue +3 (differentiated pink) · violet +6 (differentiated white).
|
|
4
|
+
//
|
|
5
|
+
// Public API is (duration, opts) in SECONDS — the family convention every other
|
|
6
|
+
// generator follows (osc, chirp, fm…). Sample-count cores stay private: the
|
|
7
|
+
// differentiators (blue, violet) need exact n+1-sample sources.
|
|
4
8
|
|
|
5
9
|
import pinkNoise from './pink-noise.js'
|
|
10
|
+
export { default as pinkNoise } from './pink-noise.js'
|
|
6
11
|
|
|
7
12
|
function lcg (seed) {
|
|
8
13
|
let s = seed >>> 0 || 1
|
|
@@ -18,20 +23,20 @@ function normalize (d, peak = 0.9) {
|
|
|
18
23
|
return d
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
function whiteN (n, seed) {
|
|
22
27
|
let rand = lcg(seed)
|
|
23
28
|
let d = new Float32Array(n)
|
|
24
29
|
for (let i = 0; i < n; i++) d[i] = rand() * 0.9
|
|
25
30
|
return d
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
let d = Float64Array.from(
|
|
33
|
+
function pinkN (n, seed) {
|
|
34
|
+
let d = Float64Array.from(whiteN(n, seed))
|
|
30
35
|
pinkNoise(d, {})
|
|
31
36
|
return normalize(Float32Array.from(d))
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
function brownN (n, seed, leak) {
|
|
35
40
|
let rand = lcg(seed)
|
|
36
41
|
let d = new Float32Array(n)
|
|
37
42
|
let y = 0
|
|
@@ -39,23 +44,29 @@ export function brown (n, { seed = 1, leak = 0.999 } = {}) {
|
|
|
39
44
|
return normalize(d)
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
let p =
|
|
47
|
+
function blueN (n, seed) {
|
|
48
|
+
let p = pinkN(n + 1, seed)
|
|
44
49
|
let d = new Float32Array(n)
|
|
45
50
|
for (let i = 0; i < n; i++) d[i] = p[i + 1] - p[i]
|
|
46
51
|
return normalize(d)
|
|
47
52
|
}
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
let w =
|
|
54
|
+
function violetN (n, seed) {
|
|
55
|
+
let w = whiteN(n + 1, seed)
|
|
51
56
|
let d = new Float32Array(n)
|
|
52
57
|
for (let i = 0; i < n; i++) d[i] = w[i + 1] - w[i]
|
|
53
58
|
return normalize(d)
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
export
|
|
61
|
+
export function white (duration = 1, { seed = 1, fs = 44100 } = {}) { return whiteN(Math.round(duration * fs), seed) }
|
|
62
|
+
export function pink (duration = 1, { seed = 1, fs = 44100 } = {}) { return pinkN(Math.round(duration * fs), seed) }
|
|
63
|
+
export function brown (duration = 1, { seed = 1, leak = 0.999, fs = 44100 } = {}) { return brownN(Math.round(duration * fs), seed, leak) }
|
|
64
|
+
export function blue (duration = 1, { seed = 1, fs = 44100 } = {}) { return blueN(Math.round(duration * fs), seed) }
|
|
65
|
+
export function violet (duration = 1, { seed = 1, fs = 44100 } = {}) { return violetN(Math.round(duration * fs), seed) }
|
|
66
|
+
|
|
67
|
+
/** noise(duration, { color: 'white'|'pink'|'brown'|'blue'|'violet', seed, fs }) — seconds */
|
|
68
|
+
export default function noise (duration = 1, { color = 'white', ...opts } = {}) {
|
|
58
69
|
const GEN = { white, pink, brown, blue, violet }
|
|
59
70
|
if (!GEN[color]) throw new RangeError(`noise: unknown color "${color}"`)
|
|
60
|
-
return GEN[color](
|
|
71
|
+
return GEN[color](duration, opts)
|
|
61
72
|
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/synth-noise",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Colors of noise — white, pink (Kellet), brown, blue, violet; seeded, slope-verified",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"main": "
|
|
7
|
+
"main": "colors.js",
|
|
8
8
|
"exports": {
|
|
9
|
-
".": "./
|
|
9
|
+
".": "./colors.js",
|
|
10
10
|
"./colors": "./colors.js",
|
|
11
11
|
"./pink": "./pink-noise.js",
|
|
12
|
-
"./audio":
|
|
12
|
+
"./audio": {
|
|
13
|
+
"types": "./audio.d.ts",
|
|
14
|
+
"default": "./audio.js"
|
|
15
|
+
},
|
|
13
16
|
"./package.json": "./package.json"
|
|
14
17
|
},
|
|
15
18
|
"files": [
|
|
16
19
|
"pink-noise.js",
|
|
17
20
|
"pink-noise.d.ts",
|
|
18
21
|
"colors.js",
|
|
19
|
-
"audio.js"
|
|
22
|
+
"audio.js",
|
|
23
|
+
"audio.d.ts",
|
|
24
|
+
"colors.d.ts"
|
|
20
25
|
],
|
|
21
26
|
"keywords": [
|
|
22
27
|
"audio",
|
|
@@ -33,6 +38,6 @@
|
|
|
33
38
|
"publishConfig": {
|
|
34
39
|
"access": "public"
|
|
35
40
|
},
|
|
36
|
-
"types": "
|
|
41
|
+
"types": "colors.d.ts",
|
|
37
42
|
"audio": "./audio.js"
|
|
38
43
|
}
|