white brown pink noise + crackle alias for dust

This commit is contained in:
Felix Roos
2025-06-07 13:24:06 +02:00
parent d743570546
commit e54449f5f7
+49
View File
@@ -108,6 +108,51 @@ export class Dust {
update = (density) => (Math.random() < density * ISR ? Math.random() : 0);
}
export class WhiteNoise {
update() {
return Math.random() * 2 - 1;
}
}
export class BrownNoise {
constructor() {
this.out = 0;
}
update() {
let white = Math.random() * 2 - 1;
this.out = (this.out + 0.02 * white) / 1.02;
return this.out;
}
}
export class PinkNoise {
constructor() {
this.b0 = 0;
this.b1 = 0;
this.b2 = 0;
this.b3 = 0;
this.b4 = 0;
this.b5 = 0;
this.b6 = 0;
}
update() {
const white = Math.random() * 2 - 1;
this.b0 = 0.99886 * this.b0 + white * 0.0555179;
this.b1 = 0.99332 * this.b1 + white * 0.0750759;
this.b2 = 0.969 * this.b2 + white * 0.153852;
this.b3 = 0.8665 * this.b3 + white * 0.3104856;
this.b4 = 0.55 * this.b4 + white * 0.5329522;
this.b5 = -0.7616 * this.b5 - white * 0.016898;
const pink = this.b0 + this.b1 + this.b2 + this.b3 + this.b4 + this.b5 + this.b6 + white * 0.5362;
this.b6 = white * 0.115926;
return pink * 0.11;
}
}
export class Impulse {
phase = 1;
update(freq) {
@@ -369,7 +414,11 @@ let oscillators = {
pulse: PulseOsc,
pulze: PulzeOsc,
dust: Dust,
crackle: Dust,
impulse: Impulse,
white: WhiteNoise,
brown: BrownNoise,
pink: PinkNoise,
};
const defaultDefaultValues = {