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

@ -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);
}

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;

View File

@ -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,

View File

@ -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;

View File

@ -42,6 +42,10 @@ Some amount of pink noise can also be added to any oscillator by using the `nois
<MiniRepl client:idle tune={`note("c3").noise("<0.1 0.25 0.5>").scope()`} />
You can also use the `crackle` type to play some subtle noise crackles. You can control noise amount by using the `density` parameter:
<JsDoc client:idle name="density" h={0} />
### Additive Synthesis
To tame the harsh sound of the basic waveforms, we can set the `n` control to limit the overtones of the waveform: