Synth.replace - Using the same buffer?

Hi there,

I have several synthdefs that all use a audio (.wav) buffers. What I now want to do is to replace an existing synth with new synth but using the same buffer.

Each synthdef has the same signature (i.e. control argument ordering), with one argument being the buffer num which the synth should use. So on the client side, I load the audio into a buffer, when completed, I create a synth using the buffer number.

This works wonderfully if I add synths and remove synths. Each time the buffer is unloaded and a new buffer is loaded, new sound is played, all good.

To replace synths, I stumbled across Synth.replace. It works well enough, replacing synth but using the first buffer that is loaded. So each replacement eventually sounds like the first buffer loaded. And weirdly, this will also happen if I remove the first synth, i.e. that originally used that buffer.

I can’t for the life of me think what the problem could be especially since I do the following:

synth = Synth.replace(synth, newSynthDef, nil, sameID: true);

i.e. I pass no arguments to the new synth, I assume it uses the existing values of the old synth. My previous attempt was:

synth.getn(0, 8, { |args|
    synth = Synth.replace(
        sameID: true);

i.e. explicitly obtaining the args. But this had the same affect as no arguments.

And that’s what I don’t understand, if I pass no arguments, I have the same results as when I pass those arguments.

Any ideas greatly appreciated :slight_smile:


Could you post a minimal example that demonstrates your problem? Its hard to understand what you are asking because of your choice of language, i.e.,

… do you mean allocated and then freed on the server?

That being said, I suspect it might be this block …

… the variables args is just an array of values, there are no control names here. You should instead pass in some thing like [\someControlName, 2], rather than [2] which is what you have now.

Yes you are completely correct, it was that using args as it comes from getn, or using nil for the args had the same effect: none of the controls values were correctly set. Instead I did this:

synth.getn(0, 14, { |args|
    var newArgs = [
        \arg0,      args[0],
        \arg1,      args[1],
        \bufnum,    args[11],

    synth = Synth.replace(
        sameID: true);

and it now works charmingly!

What I meant with the buffer loading, was this bit of code:

var action = { |buffer|
    var initArgs  = List.newUsing([
        "bufnum",    buffer.bufnum,

    var synth     =, initArgs.asArray);
};, filename, action: action);

i.e. waiting until the buffer is filled on the server side and then defining the synth.