MIX


MIX is the oldest and simplest of the cmix family of instruments. It takes an input file and, well, mixes it to an output file. Since you can change the input file as you go, you can use it to mix a bunch of files together. Because of its panning syntax, MIX is basically outdated, and normally you will want to use the STEREO instrument. But, we include it here mainly for historical reasons.

(There is one minor use for MIX: to extract one channel of a file, without the other channel, using the "-1" panning argument. See below for an example.)

The trickiest part of MIX is the way it handles p4-pN (the channel mix matrix). Thus:

The next (up to 4) arguments are the numbers of the output channel in which to place the input channel as determined by its order in the series. In other words the series, 0 1 1 0 would indicate that you are placing input channel 0 in output channel 0, input channel 1 in output channel 1, input channel 2 in output channel 1, and input channel 3 in output channel 0. If you specify an incorrect number of channels the program will barf. If you want to skip over an input channel simply put a -1 in that field (quoted from Lansky, 1987).

Note that the panning arguments must be either 0 or 1, you cannot use decimal fractions. You can use them with the STEREO instrument.

Also note that the sample scores have no "load()" directive. MIX is the main object ("mix" in the old, disk-based cmix filled the parallel role), and thus does not need to be dynamically-loaded. It is 'always there'. Always.

Syntax:


setline(t0,a0,t1,a1...) /* the amplitude envelope of the output sound in time/amplitude pairs */

MIX(outskip, inskip, duration, amplitude, where_to_put_channel_0, where_to_put_channel_1, ... channelN) /* the duration field, if negative, specifies an absolute endtime in the output soundfile */

Now the scores in comment form:

/* p0 = start_time_in_output; p1 = input_skip; p2 = duration (if negative, endtime); p3 = amp; 
p4-n = channel mix matrix;
   Note:  Don't use makegen slot 1.  It is being used by the "setline" envelope generator. */

An example score:

rtsetparams(44100, 2)
rtinput("/sndh/bob.dole.mono.snd")
setline(0,0, 1, 1)
MIX(0, 0, 7.0, 1, 0, 0)
setline(0, 1, 1, 0)
MIX(0.1, 0, 7.0, 1, 1, 1)

A second example, using a looping structure and random numbers for panning:

rtsetparams(44100, 2)
rtinput("/snd/pablo1.snd")
setline(0,0, .1, 1, 2,0)
reset(44100)
dur = 1;
for(outsk = 0; outsk < 14.0; outsk = outsk + dur) 
        {
	insk = random() * 7.0
	dur = random() * 0.2

	if (random() > 0.5) ch1 = 0
	else ch1 = 1
	if (random() > 0.5) ch2 = 0
	else ch2 = 1
	MIX(outsk, insk, dur, 1, ch1, ch2)
        }

A third score, using the real-time audio input:

set_option("full_duplex_on")
rtsetparams(44100, 2)
rtinput("AUDIO", "MIC", 2)
setline(0,0, 1, 1)
MIX(0, 0, 5, 1, 0, 0)
setline(0, 1, 1, 0)
MIX(0.1, 0, 5, 1, 1, 1)

A fourth score, which will extract only channel 1 from a stereo file, putting it into a mono file:

rtsetparams(44100, 1)
/* note the 1-channel argument */
rtinput("hum_de_dum.aiff")
rtoutput("hum_de_mono.aiff")
setline(0,1, 1, 1)
MIX(0, 0, 6, 1, -1, 0)
/* "skips over" channel 0.  Writes input-channel 1 into output-channel 0  
   (the only available one, as this is a mono output file.)