#!/bin/sh 
# returns the sampling rate of one or more WAVE or AIFF soundfiles; A.S. Jan 2004
# revised using Csound sndinfo when Schottsteadt sndinfo broke, becoming very slow
# metacharacters can be used on command line but must be preceded by a \

if  ( [ $# == 0 ] ) ; then  # print usage summary
  echo "   sfsr: displays the sampling rate of one or more soundfiles"
  echo "syntax:  sfsr  soundfile1 [soundfile2  soundfileN]"
  echo "   Metacharacters such as * can be used but must be preceded by a \ "
  echo "Example: sfsr mix\*  (this will return sample rates for all soundfiles whose"
  echo 'names begin with the character string "mix") '
  exit 0 ;
fi

cd $SFDIR
for i in $* ; do
    if ( ! ( test -s "${i}" ) ) ; then echo -e  "ERROR: No soundfile named >> ${i} << found. Quitting." ; exit 0 ; fi
                   # exit if input file does not exist
 SNDINFO=`csound -U sndinfo "${i}" 2> /dev/null | grep -e "srate" | grep -e "seconds"`
 SR=`echo $SNDINFO |  awk ' { print $2 }' | sed -e 's/,//g'`

echo $SR  $i
done

