#!/bin/sh 
# sfbits -- returns wordsize of a soundfile
# metacharacters can be used on command line but must be preceded by a \
# A.S. revised 1/1/04 to use Csound sndinfo rather than Schottsteadt's sndinfo

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

  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"`
 BITS=`echo $SNDINFO |  awk ' { print $4 }' #  | sed -e 's/,//g'`
echo $BITS $i
done

