Mix two signals

This demonstrates a linear interpolation algorithm used for achieving a weighted balance of two signals.

Suppose we want a blend (mix) of two sounds, and we would like to be able to specify the balance between the two as a value from 0 to 1, where a balance value of 0 means we get only the first sound, a balance value of 1 means we get only the second sound, and 0.5 means we get an equal mix of the two sounds.

One way to calculate this is
y[n] = x2[n](balance)+x1[n](1-balance)
where x1 and x2 are the two signal values and balance is the weighting value described above.


mix~.maxpat

In this MSP patch (abstraction), the two audio signals come in the first two inlets, and the balance value comes in the right inlet. Note the use of the argument #1, which will be replaced by whatever is typed in as the object’s first argument when it’s created in the parent patch. That allows the programmer to specify an initial balance value when using this abstraction. If the programmer doesn’t type in any argument, the #1 is replaced by 0, by default. The sig~ object provides a constant signal value. So this patch multiplies the sound coming in the first inlet by 1-balance, and it multiplies the sound coming in the second inlet by balance, then adds the two.

If, in the parent patch, the signal in the right inlet is a line~ object going from 0 to 1, the effect will be a linear crossfade between the sound in the first inlet and the sound in the second inlet.