“X = Y + Z” is just a normal mix-down.
“X = Y - Z” is mix-down after inverting one track (to make it -ve).
“X = Y / Z” will inevitably involve division by zero
“X = Y * Z” can be done using this Nyquist code on a stereo track …
In Audacity, the variable TRACK is used to pass the selected audio from the audio track to Nyquist.
The left channel of a stereo track can be accessed with:
(aref *track* 0)
and the right channel with:
(aref *track* 1)
The arithmetic operators “+ - * /” only work with numbers, not sounds. For sounds, use the functions “sum diff mult”.
Division is problematic because sounds usually oscillate around zero, and division by zero is an error. Even if you can guarantee that no sample values will be zero, it is still problematic because sample values should be in the floating point range +/- 1, so dividing one sound by another will usually produce extremely large values that are massively off the scale. If you can guarantee that the divisor is never zero, and that the result of your function will be in the range +/- 1, then you can use the Nyquist function “recip”, which computes 1/x for each sample x.
Some examples. In each case the result is returned to both left and right channels.
To get the sum of the left and right channels (a simple mix)