#!/bin/sh
# Play a sound file through a parametric or shelving EQ, with optional inskip,
# amp scaling and other parameters.  Just like "eq", except that freq and gain
# are controlled by mouse motion.  Only works for mono and stereo files.
#
# NOTE: Only works with RTcmix v4
#
# JGG, 9/25/04

if [ $# -lt 3 ]
then
   echo  Usage: `basename $0` file type maxcf maxgain Q [inskip [ampmult]]
   echo "       (type: 1-parametric, 2-lowshelf, 3-highshelf;"
   echo "       maxcf in Hz; maxgain in dB)"
   exit 1
fi

flags='-q'

script='
inskip = 0; amp = 1;
infile = s_arg(0);
type = i_arg(1);
maxcf = f_arg(2);
maxgain = f_arg(3);
cf = makeconnection("mouse", "x", 10, maxcf, 1000, lag=75, "freq", "Hz", 0);
eqgain = makeconnection("mouse", "y", -maxgain, maxgain, 0, lag, "gain", "dB");
Q = f_arg(4);
if (n_arg() > 5) {
   inskip = f_arg(5);
   if (n_arg() > 6) {
      amp = f_arg(6);
   }
}

if (type == 1) {
   print("type: 1 (parametric)");
   type = 4
}
else if (type == 2) {
   print("type: 2 (low shelf)");
   type = 2
}
else if (type == 3) {
   print("type: 3 (high shelf)");
   type = 3
}
printf("Q: %f\n", Q);
printf("inskip: %f\n", inskip);
printf("ampmult: %f\n", amp);

rtsetparams(44100, 2, 512);
load("EQ");
rtinput(infile);
chans = CHANS();
dur = DUR() - inskip;
reset(10000);
setline_size(10000);
ramp = .02
setline(0,0, ramp,1, dur-ramp,1, dur,0);
makegen(3, 18, 10, 0,Q, 1,Q);
if (chans == 1) {
   EQ(0, inskip, dur, amp, type, 0, .5, 0, cf, Q, eqgain)
}
else {
   EQ(0, inskip, dur, amp, type, 0, 1, 0, cf, Q, eqgain)
   EQ(0, inskip, dur, amp, type, 1, 0, 0, cf, Q, eqgain)
}
'
echo $script | CMIX $flags $*

