#!/bin/bash


if [ "$#" -lt 1 ] ; then
 echo "Usage: $0 -[mf] wav/*.wav"
 exit 1
fi


DEFAULT_PDA_OPTIONS_MALE="   -shift 0.002 -otype est_binary -fmax 170 -fmin 70 -L -d 1 -P"
DEFAULT_PDA_OPTIONS_FEMALE="   -shift 0.002 -otype est_binary -fmax 310 -fmin 150 -L -d 1 -P"

case "$1" in
   -m) PDA_OPTIONS=$DEFAULT_PDA_OPTIONS_MALE;
       shift ;;
   -f) PDA_OPTIONS=$DEFAULT_PDA_OPTIONS_FEMALE;
       shift ;;
   -*) echo "Usage: $0 -[mf] wav/*.wav";
       exit 1;;
esac


OUTDIR=f0

# to work around strange filesystem problems in 2015 - try removing in later years
chmod ugo+rwx $OUTDIR


CH_TRACK=$ESTDIR/bin/ch_track
PDA=$ESTDIR/bin/pda
SMOOTH_F0=$FESTVOXDIR/src/general/smooth_f0

SMOOTH_F0_OPTIONS="-presmooth -prewindow 0.03"

for file in $* ; do
    bname=`basename $file .wav`;
    echo "Running pda on $bname"
    $PDA $PDA_OPTIONS $file -o $OUTDIR/${bname}.unsmooth.f0 -otype est
    echo " and running smooth_f0 on $bname"
    echo -n " "
    $SMOOTH_F0 $SMOOTH_F0_OPTIONS $OUTDIR/${bname}.unsmooth.f0 -o $OUTDIR/${bname}.f0 -otype est
    rm -f $OUTDIR/${bname}.unsmooth.f0;
done


