Commutativity of signals multiplication

Is the binary operation of multiplication not commutative in SC, when applied to signals? BeIow, should not the result “sound” the same? :thinking:

// Why doesn't this
{Decay.ar(Impulse.ar(1), mul:PinkNoise.ar(0.5))}.play
// sounds the same as this?
{Decay.ar(PinkNoise.ar(0.5), mul:Impulse.ar(1))}.play

The first argument of Decay.ar is a trigger signal. The mul argument is applied to the output of Decay.ar, and not to the trigger input.

I would recommend not to use the mul and add arguments at all. They come from a time where sclang did not have the necessary SynthDef optimizations. Modern SC version recognize patterns like x * a + b and automatically turn it into MulAdd UGens.

Instead write it like this:

// This
{ Decay.ar(Impulse.ar(1)) * PinkNoise.ar(0.5) }.play
// is obviously not the same as this
{ Decay.ar(PinkNoise.ar(0.5)) * Impulse.ar(1) }.play

IMO this is much better to read. Now it should be obvious why these two SynthDefs cannot be equivalent.

2 Likes