diff --git a/packages/core/controls.mjs b/packages/core/controls.mjs index a03658a8..a14f06df 100644 --- a/packages/core/controls.mjs +++ b/packages/core/controls.mjs @@ -1214,6 +1214,17 @@ const generic_params = [ * @name waveloss */ ['waveloss'], + /* + * + * Noise crackle density + * + * @name density + * @param {number | Pattern} density between 0 and x + * @example + * s("crackle*4").density("<0.01 0.04 0.2 0.5>".slow(4)) + * + */ + ['density'], // TODO: midi effects? ['dur'], // ['modwheel'], @@ -1308,7 +1319,7 @@ const generic_params = [ ]; // TODO: slice / splice https://www.youtube.com/watch?v=hKhPdO0RKDQ&list=PL2lW1zNIIwj3bDkh-Y3LUGDuRcoUigoDs&index=13 -controls.createParam = function (names) { +controls.createParam = function(names) { const name = Array.isArray(names) ? names[0] : names; var withVal; @@ -1332,7 +1343,7 @@ controls.createParam = function (names) { const func = (...pats) => sequence(...pats).withValue(withVal); - const setter = function (...pats) { + const setter = function(...pats) { if (!pats.length) { return this.fmap(withVal); } diff --git a/packages/superdough/noise.mjs b/packages/superdough/noise.mjs index 6a2d418c..8993f470 100644 --- a/packages/superdough/noise.mjs +++ b/packages/superdough/noise.mjs @@ -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; diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index 00e2f42c..ed133366 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -241,6 +241,7 @@ export const superdough = async (value, deadline, hapDuration) => { source, gain = 0.8, postgain = 1, + density = 0.03, // filters ftype = '12db', fanchor = 0.5, diff --git a/packages/superdough/synth.mjs b/packages/superdough/synth.mjs index 53f462d5..edc3c01e 100644 --- a/packages/superdough/synth.mjs +++ b/packages/superdough/synth.mjs @@ -36,7 +36,8 @@ export function registerSynthSounds() { if (waveforms.includes(s)) { sound = getOscillator(s, t, value); } else { - sound = getNoiseOscillator(s, t, 0.002); + let { density } = value; + sound = getNoiseOscillator(s, t, density); } let { node: o, stop, triggerRelease } = sound; diff --git a/website/src/pages/learn/synths.mdx b/website/src/pages/learn/synths.mdx index 432276ef..abb74c2f 100644 --- a/website/src/pages/learn/synths.mdx +++ b/website/src/pages/learn/synths.mdx @@ -42,6 +42,10 @@ Some amount of pink noise can also be added to any oscillator by using the `nois ").scope()`} /> +You can also use the `crackle` type to play some subtle noise crackles. You can control noise amount by using the `density` parameter: + + + ### Additive Synthesis To tame the harsh sound of the basic waveforms, we can set the `n` control to limit the overtones of the waveform: