#!/usr/bin/env bash

o=/tmp/$$.dat
trap "rm -f $o" EXIT

#Calculate the spectral slope of the main microphone
#signal.

# ORD=/home/mint/gpk
err="$0: OXIVOICE needs to be set in the environment.  Try /home/mint/gpk/voicing."
OV=${OXIVOICE:?$err}
# PATH=$OV:${OXIROOT:-$ORD}/bin:$PATH

rewrite=0
if test "$1" = '-rewrite'
then
  rewrite=1
fi

for n in $(select_fiat_entries.py -show "'%s/%s' % (d, f)" DB.fiat)
do
    echo 'Working on' $n
    if test ! -s $n.dat
    then
      g_die "No data: $n" || exit 1
    # elif test $rewrite = 1 -o $n.dat -nt $n.ssl.dat -o $n.dat -nt $n.ssl.sd
    elif test $rewrite = 1 -o $n.dat -nt $n.ssl.dat
    then
      # rm -f $o $n.ssl.dat $n.ssl.sd
      rm -f $o $n.ssl.dat
      python $OV/s_slope3.py -barkf -dexp 0 -noclip -fmin 300 -fmax 3000 -dt 0.010 -f $n.dat -c 0 -o $o ||
		g_die "s_slope3 fails!" || exit 1
      imop -write BITPIX=-32 r $o = $n.ssl.dat
      # imop -write BITPIX=-32 r $o = $n.ssl.sd
    fi
done

