diff --git a/packages/superdough/reverb.mjs b/packages/superdough/reverb.mjs index 85be19aee..f853d3fbc 100644 --- a/packages/superdough/reverb.mjs +++ b/packages/superdough/reverb.mjs @@ -19,10 +19,9 @@ if (typeof AudioContext !== 'undefined') { AudioContext.prototype.createReverb = function (duration, fade, lp, dim, ir) { const convolver = this.createConvolver(); - convolver.generate = (d, fade, lp, dim, buf) => { + convolver.generate = (d = 2, fade = 0.1, lp = 15000, dim = 1000, buf) => { if (buf) { convolver.buffer = this.adjustLength(d, buf); - return convolver; } else { this.generateReverb( { @@ -42,7 +41,6 @@ if (typeof AudioContext !== 'undefined') { convolver.fade = fade; convolver.lp = lp; convolver.dim = dim; - return convolver; } }; convolver.setIR = (d, fade, lp, dim, buf) => { diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index d7f0b14b7..20edbe331 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -114,6 +114,8 @@ function getDelay(orbit, delaytime, delayfeedback, t) { let reverbs = {}; +let hasChanged = (now, before) => now !== undefined && now !== before; + function getReverb(orbit, duration = 2, fade, lp, dim, ir) { if (!reverbs[orbit]) { const ac = getAudioContext(); @@ -123,13 +125,17 @@ function getReverb(orbit, duration = 2, fade, lp, dim, ir) { } if ( - reverbs[orbit].duration !== duration || - reverbs[orbit].fade !== fade || - reverbs[orbit].ir !== lp || - reverbs[orbit].dim !== dim || - reverbs[orbit].ir !== ir + hasChanged(duration, reverbs[orbit].duration) || + hasChanged(fade, reverbs[orbit].fade) || + hasChanged(lp, reverbs[orbit].lp) || + hasChanged(dim, reverbs[orbit].dim) ) { - reverbs[orbit].generate(duration, fade, lp, dim, ir); + // only regenerate when something has changed + // avoids endless regeneration on things like + // stack(s("a"), s("b").rsize(8)).room(.5) + // this only works when args may stay undefined until here + // setting default values breaks this + reverbs[orbit].generate(duration, fade, lp, dim); } if (reverbs[orbit].ir !== ir) { @@ -235,10 +241,10 @@ export const superdough = async (value, deadline, hapDuration) => { delaytime = 0.25, orbit = 1, room, - roomfade = 0.1, - roomlp = 15000, - roomdim = 1000, - roomsize = 2, + roomfade, + roomlp, + roomdim, + roomsize, ir, i = 0, velocity = 1,