Skip to content

Commit

Permalink
Merge pull request #726 from tidalcycles/reverb-perf-pitfall
Browse files Browse the repository at this point in the history
fix: reverb regenerate loophole
  • Loading branch information
felixroos authored Oct 6, 2023
2 parents 0b888ac + 4718bfa commit e2569ed
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/superdough/reverb.mjs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ if (typeof AudioContext !== 'undefined') {
AudioContext.prototype.generateReverb = reverbGen.generateReverb;
AudioContext.prototype.createReverb = function (duration, fade, lp, dim) {
const convolver = this.createConvolver();
convolver.generate = (d, fade, lp, dim) => {
convolver.generate = (d = 2, fade = 0.1, lp = 15000, dim = 1000) => {
this.generateReverb(
{
audioContext: this,
25 changes: 16 additions & 9 deletions packages/superdough/superdough.mjs
Original file line number Diff line number Diff line change
@@ -108,7 +108,9 @@ function getDelay(orbit, delaytime, delayfeedback, t) {

let reverbs = {};

function getReverb(orbit, duration = 2, fade, lp, dim) {
let hasChanged = (now, before) => now !== undefined && now !== before;

function getReverb(orbit, duration, fade, lp, dim) {
// If no reverb has been created for a given orbit, create one
if (!reverbs[orbit]) {
const ac = getAudioContext();
@@ -118,11 +120,16 @@ function getReverb(orbit, duration = 2, fade, lp, dim) {
}

if (
reverbs[orbit].duration !== duration ||
reverbs[orbit].fade !== fade ||
reverbs[orbit].lp !== lp ||
reverbs[orbit].dim !== dim
hasChanged(duration, reverbs[orbit].duration) ||
hasChanged(fade, reverbs[orbit].fade) ||
hasChanged(lp, reverbs[orbit].lp) ||
hasChanged(dim, reverbs[orbit].dim)
) {
// 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);
}

@@ -223,10 +230,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,
velocity = 1,
analyze, // analyser wet
fft = 8, // fftSize 0 - 10

0 comments on commit e2569ed

Please sign in to comment.