Trying to understand how Convolution2 works

Hi guys, i’m trying to understand the examples of convolution2 in the help file but i can’t figure out what b.zero mean for the buffer and also b.set, can you help me with thiat? thankyou !


( // allocate three buffers
b = Buffer.alloc(s,2048);
c = Buffer.alloc(s,2048);
d = Buffer.alloc(s,2048);

b.zero;
c.zero;
d.zero;
)

(
50.do({ |it| c.set(20*it+10, 1.0.rand); });
3.do({ |it| b.set(400*it+100, 1); });
20.do({ |it| d.set(40*it+20, 1); });
)


(
SynthDef("conv-test", { |out, kernel, trig = 0|
    var input;

    input = Impulse.ar(1);

    //must have power of two framesize
    Out.ar(out, Convolution2.ar(input, kernel, trig, 2048, 0.5));
}).add

)


x = Synth.new("conv-test",[\kernel,b.bufnum]);

// changing the buffer number:
x.set(\kernel,c.bufnum);
x.set(\trig,0);
x.set(\trig,1); // after this trigger, the change will take effect.
x.set(\kernel,d.bufnum);
x.set(\trig,0);
x.set(\trig,1); // after this trigger, the change will take effect.

d.zero;
40.do({ |it| d.set(20*it+10, 1); });// changing the buffers' contents
x.set(\trig,0);
x.set(\trig,1); // after this trigger, the change will take effect.

x.set(\kernel,b.bufnum);
x.set(\trig,0);
x.set(\trig,1); // after this trigger, the change will take effect.

another thing: in the example it says that after trig:1 the change will take effect, but i don’t hear nothing different

I think the .zero fill the buffer with 0’s

https://doc.sccode.org/Classes/Buffer.html#-zero

Rather than tell you what they mean, its probably more useful show you how to figure this out for yourself.

Once b has been defined, so after …

b = Buffer.alloc(s,2048);
c = Buffer.alloc(s,2048);
d = Buffer.alloc(s,2048);

… this block of code has been run.
You are then able to figuure out what class b is, you can do this with .class, e.g…

b.class

From there, you can directly open the help docs…

b.class.help

Now the help docs are structured in, at least, two parts, class methods, and instance methods.
Class methods are called with the class name prefixed, e.g., Bus.alloc, where Bus is the class and alloc the class method (you have Buffers here, but you can do it with every object/class). However, since you already have a instance of a buffer (b is the instance) you need to check under instance methods.

There are two entries under zero:

.zero(completionMessage)
.zeroMsg(completionMessage)

Only zeroMsg has a description, why, probably a mistake, but most often than not if a method is followed by Msg, its is just a part of the implementation used to send a message to the server, so you the description for .zeroMsg holds for zero

Sets all values in this buffer to 0.0.

Arguments:
completionMessage	
A valid OSC message or a Function which will return one. A Function will be passed this Buffer as an argument when evaluated.

The argument is optional. Also, you should use zero over zeroMsg as the latter is used to send a command to the server, which you’d have to do yourself.

You should be able to follow this with set and all other methods.

Thank you vey much! I tough Msg was another method. This helped me a lot .