Clicks when changing BufRd buffers [Solved]

Hi all, I’m using BufRd to index into buffers which I replace constantly with modified versions of themselves. While a synth is running these buffers are being indexed by a looping phasor ~t, so when a buffer is replaced by another one (of the same length) the indexing continues where the previous one left off. An example:

SynthDef(\fm, {
        // these are all buffers that get updated
	arg amp, freq, ratio, index, pan;

	var freq_ =, freq, *;
	var ratio_ =, ratio, *;
	var index_ =, index, *;
	var amp_ =, amp, *;
	var pan_ =, pan, *;

	var mod =*ratio_)*index_;
	var sig = + mod) * amp_;,, pan_));

The buffer files themselves are being overwritten, and when the new one is ready this gets called to free the old one and load the new:

bufferDict.add(buffName ->, filePath, action: {|b|
    synthDict[synthName].set(synthParam, b)}));

I understand that there will be clicks if there are discontinuities between the values of the previous and the new buffers, and using Lag doesn’t help as it also smooths changes in the actual indexed values. The problem is that I keep getting audible pops and clicks, even when a buffer is replaced by an identical one (and so there is no discontinuity with the previous value). As I am live coding these buffers and replacing them all the time, this gets pretty annoying.

Why are there discontinuities even when a buffer with a constant value is replaced by an identical one? Is it that I’m freeing the old one before the new is loaded?

As soon as I finished writing this it dawned on me that it probably was the freeing-before-loading thing, I tested it and I was right!

var oldBuff = bufferDict[buffName];
bufferDict.add(buffName ->, filePath, action: { |b|
	synthDict[synthName].set(synthParam, b);;

Solved my own problem before anyone even read this post, there must be some kind of badge for that!

As a bonus question (and so this thread doesn’t die in vain): How could I use Lag to smooth changes only when the buffer is changed and not in between changes?

+1 :slight_smile:

IMO the clean solution for this is crossfading between playing buffers. E.g. you could crossfade between two channels with SelectX and exchange the silently-playing buffer on occasion, then fade back.
Besides SelectX you could use DX ugens from miSCellaneous_lib quark. In contrast to SelectX you can crossfade arbitrarily between many signals resp. playing buffers, with SelectX you must slide over the neighbours if the array is larger.