#!/bin/csh -f
#
# This program generate ramped and damped sine wave.
#	Require AIM tools; tone, merge, ftos, bufwave, ramp.
#			by Akira Nishimura  1995/8/21

set comname = `basename $0`
set tmp = /tmp/$comname"$$"

if($#argv != 4) then
	echo "Usage: $comname generates ramped and damped sine wave."
	echo "  $comname [carrior freq. (Hz)] [mod. freq. (Hz)]"
        echo "         [half life of exponential(ms)] [file name]"
	exit
endif

set sf = "8kHz"
set dur = "1000ms"
set sdur = "500ms"
set amp = "20000"
set ms = "ms"
set hz = "Hz"
@ cf=$argv[1]  # carrior freq.
@ mf=$argv[2]  # moduration freq.

@ per = 1000 / $mf

tone samp=$sf dur=$dur amp=$amp freq=$cf$hz type=float > $tmp.car
echo tone samp=$sf dur=$dur amp=$amp freq=$cf$hz data=float
ramp samp=$sf dur=$dur amp=1 per=$per$ms decay=$argv[3]ms data=float > $tmp.mod
echo ramp samp=$sf dur=$dur amp=1 per=$per$ms decay=$argv[3]ms data=float
/opt/tsumura/aim/bin/merge samp=$sf ope=multiply type=float $tmp.car $tmp.mod > $tmp.mix
echo merge ope=multiply type=float $tmp.car $tmp.mod
ftos $tmp.mix > $tmp.1raw
bufwave samp=$sf frame=1 width=$dur reverse=on $tmp.1raw > $tmp.2raw
tone samp=$sf dur=$sdur amp=0 > $tmp.sil
cat $tmp.1raw > $argv[4].raw
cat $tmp.sil >> $argv[4].raw
cat $tmp.2raw >> $argv[4].raw
rm $tmp.*
