Fixing density and adding documentation

This commit is contained in:
Raphael Forment 2023-11-17 13:18:49 +01:00
parent 476bda812e
commit fb28083ce6
5 changed files with 22 additions and 4 deletions

View file

@ -35,7 +35,8 @@ function getNoiseBuffer(type, density) {
output[i] *= 0.11;
b6 = white * 0.115926;
} else if (type === 'crackle') {
if (Math.random() < (Math.random() * (density - 0.001) + density).toFixed(4)) {
const probability = density * 0.01
if (Math.random() < probability) {
output[i] = Math.random() * 2 - 1;
} else {
output[i] = 0;