#!/bin/sh
# Play 2 sound files at the same time, with amp scaling.
# Files must have 1, 2, 4, or 8 channels and must have same sampling rate.
# JGG, 9/9/03

if [ $# -ne 4 ] && [ $# -ne 6 ]
then
	echo	"Usage: `basename $0` file1 amp1 file2 amp2"
	echo	"	OR"
	echo	"       `basename $0` file1 inskip1 amp1 file2 inskip2 amp2"
	echo	"(plays 2 files at the same time)"
	exit 1
fi

flags='-q'

script='
if (n_arg() == 6) {
	file1 = s_arg(0);
	inskip1 = f_arg(1);
	amp1 = f_arg(2);
	file2 = s_arg(3);
	inskip2 = f_arg(4);
	amp2 = f_arg(5);
}
else {
	file1 = s_arg(0);
	inskip1 = 0;
	amp1 = f_arg(1);
	file2 = s_arg(2);
	inskip2 = 0;
	amp2 = f_arg(3);
}
rtinput(file1);
chans1 = CHANS();
sr1 = SR();
rtinput(file2);
chans2 = CHANS();
sr2 = SR();
if (sr1 != sr2) {
	print("File sampling rates must be the same.");
	exit(1);
}
if (chans1 > 8 || chans2 > 8) {
	print("Input files can have no more than 8 channels.");
	exit(1);
}
rtsetparams(sr1, max(chans1, chans2));
rtinput(file1);
dur = DUR() - inskip1;
MIX(0, inskip1, dur, amp1, 0, 1, 2, 3, 4, 5, 6, 7);
rtinput(file2);
dur = DUR() - inskip2;
MIX(0, inskip2, dur, amp2, 0, 1, 2, 3, 4, 5, 6, 7);
'
echo $script | CMIX $flags $*

