Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit e54449f

Browse files
committed
white brown pink noise + crackle alias for dust
1 parent d743570 commit e54449f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

packages/supradough/dough.mjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,51 @@ export class Dust {
108108
update = (density) => (Math.random() < density * ISR ? Math.random() : 0);
109109
}
110110

111+
export class WhiteNoise {
112+
update() {
113+
return Math.random() * 2 - 1;
114+
}
115+
}
116+
117+
export class BrownNoise {
118+
constructor() {
119+
this.out = 0;
120+
}
121+
update() {
122+
let white = Math.random() * 2 - 1;
123+
this.out = (this.out + 0.02 * white) / 1.02;
124+
return this.out;
125+
}
126+
}
127+
128+
export class PinkNoise {
129+
constructor() {
130+
this.b0 = 0;
131+
this.b1 = 0;
132+
this.b2 = 0;
133+
this.b3 = 0;
134+
this.b4 = 0;
135+
this.b5 = 0;
136+
this.b6 = 0;
137+
}
138+
139+
update() {
140+
const white = Math.random() * 2 - 1;
141+
142+
this.b0 = 0.99886 * this.b0 + white * 0.0555179;
143+
this.b1 = 0.99332 * this.b1 + white * 0.0750759;
144+
this.b2 = 0.969 * this.b2 + white * 0.153852;
145+
this.b3 = 0.8665 * this.b3 + white * 0.3104856;
146+
this.b4 = 0.55 * this.b4 + white * 0.5329522;
147+
this.b5 = -0.7616 * this.b5 - white * 0.016898;
148+
149+
const pink = this.b0 + this.b1 + this.b2 + this.b3 + this.b4 + this.b5 + this.b6 + white * 0.5362;
150+
this.b6 = white * 0.115926;
151+
152+
return pink * 0.11;
153+
}
154+
}
155+
111156
export class Impulse {
112157
phase = 1;
113158
update(freq) {
@@ -369,7 +414,11 @@ let oscillators = {
369414
pulse: PulseOsc,
370415
pulze: PulzeOsc,
371416
dust: Dust,
417+
crackle: Dust,
372418
impulse: Impulse,
419+
white: WhiteNoise,
420+
brown: BrownNoise,
421+
pink: PinkNoise,
373422
};
374423

375424
const defaultDefaultValues = {

0 commit comments

Comments
 (0)