Mixing and crossfading

Mixing or blending two things—whether it’s two sounds or two videos—just means taking a certain amount of thing A and a certain amount of thing B and adding them together.

If you take a full dose of A and a full dose of B—let’s say, a full amplitude sine wave and a full amplitude square wave—and add them together, you’d likely end up with a sum that has an amplitude (or a brightness in the case of video) that’s twice as great as either of them alone. That’s why it’s common to scale A and B down by a certain amount (multiply them by some amount less than 1) so that their sum will eventually equal 1. For example if you multiply the sine tone’s amplitude by 0.25 and the square wave’s amplitude by 0.75, the peak amplitude of their sum will not exceed 1 (and the amplitude of the square wave’s contribution to the mix will be 3 times as great as that of the sine wave).

If you gradually change the level (the multiplier factor) of thing A from 1 to 0, it will fade away from full to none. Conversely, if you gradually change the multiplier applied to thing B from 0 to 1, it will fade from off to full on. If you do both things simultaneously, you get a crossfade from A to B. This is commonly achieved by linearly interpolating the amplitude multiplier of thing A from 1 to 0 (using the output of a line~ object as the multiplier, for example) and using 1 minus that amount as the multiplier for thing B. That ensures that A and B will fade in opposite directions, and that the sum of the two multipliers will at all times be 1.

For examples and explanations of abstractions for basic audio mixing/crossfading, see the following two examples from a previous class:
Mix two signals
Mix two signals (more efficiently)

The example patch below employs the second of those two mixing algorithms, encapsulated in a subpatch, and shows the use of the line~ object to cause a crossfade from one sound to another.

linear crossfade between two sounds

Mixing and crossfading are such common operations in audio and video that it makes sense to have an object dedicated to that purpose. In Jitter, the jit.xfade object gives easy control for mixing or crossfading two matrices (i.e., two images). In MSP, the matrix~ object is a controllable multichannel audio mixer. For simply mixing or crossfading two audio signals, you can use matrix~ 2 1 0. as a 2-in/1-out mixer, as in the example patch below (or you can build a mixer yourself easily enough, save it as an abstraction, and reuse it in any patch as in the previous examples above). This example has a pretty similar effect to the one above, but it allows the mixing/crossfading to be controlled by hand via a slider.

MSP mixer object matrix~

The same principles describes above apply when mixing two images or two videos; one image is faded down to 0 brightness while the other is being faded up to full brightness. The jit.xfade object is the visual equivalent of the mix~ and mix2~ audio mixing abstractions linked above. The use of the jit.xfade object to mix/crossfade Jitter matrices is demonstrated in the next example.

Note that these examples all demonstrate a linear mixing system (a linear crossfade from A to B), which is very simple and direct and works for many situations, but may not always be the most desirable way to get from A to B in all circumstances. A straight line is one very special kind of curve—the most direct path possible between two points. One could use any curve of transition other than a straight line. The curve that’s used for mixing two signals is called the law; different laws are used for different effects. Commonly an exponential curve is used, to compensate for our tendency to perceive relative to the logarithm of the stimulus (known as Fechner’s law).