home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 March / PCWELT_3_2006.ISO / base / 05_common.mo / usr / bin / play < prev    next >
Encoding:
Text File  |  2004-10-15  |  5.2 KB  |  219 lines

  1. #!/bin/sh
  2. # Shell script to play/record sound files to/from unix style sound devices.
  3. # Should auto detect most supported systems.
  4. #
  5. # Originally developed by Chris Bagwell (cbagwell@sprynet.com)
  6. #
  7. #   TODO:  Put each set of fopts and filenames on an array and then 
  8. #          play each filename back with the given effect.h
  9. #
  10. # Change History:
  11. #
  12. #   Major updates have been supplied by Kjetil Torgrim Homme and 
  13. #   Kirk Goff.
  14.  
  15. # Set up path so that it can find Sox if user's path doesn't already
  16. # include it.
  17. prefix=/usr
  18. exec_prefix=${prefix}
  19. bindir=${exec_prefix}/bin
  20.  
  21. # Look for sox in install directory first and then in current direction
  22. # if not found.
  23. PATH="$bindir:.:$PATH"
  24.  
  25. program_name=`basename $0`
  26. program_version="2.0"
  27.  
  28. if [ -z "$1" ]; then
  29.     echo "\
  30. $program_name: too few arguments
  31. Try \`$program_name --help' for more information." 1>&2
  32.     exit 1
  33. fi
  34.  
  35. version()
  36. {
  37.     echo "$program_name (sox) $program_version"
  38.     exit 0
  39. }
  40.  
  41. help()
  42. {
  43.     echo "\
  44. Usage: $program_name [OPTION]... FILE [EFFECT]...
  45. Play/record sound files to/from unix style sound devices.
  46.  
  47.   -c, --channels=CHANNELS      specifies the number of sound channels in FILE
  48.   -d, --device=DEVICE          use DEVICE for input/output
  49.   -f, --format=FORMAT          specifies bit format of sample
  50.                                FORMAT is either s, u, U, A, a, or g
  51.   -r, --rate=RATE              sample rate in hertz of FILE
  52.   -s, --size=SIZE              interpret size of sample
  53.                                SIZE is either b, w, l, f, d, or D
  54.   -t, --type=TYPE              specifies file format of FILE
  55.   -v, --volume=VOLUME          change amplitude
  56.   -x, --xinu                   reverse bit order of sample
  57.                                (only works with 16-bit and 32-bit integer data)
  58.       --file                   next argument is FILE
  59.   -h, --help                   display this help and exit
  60.       --version                output version information and exit
  61.  
  62. EFFECTs are one or more of the following:  avg, band, chorus, copy, cut, 
  63. deemph, echo, echos, flanger, highp, lowp, map, mask, phaser, pick, polyphase
  64. rate, repeat, resample, reverb, reverse, split, stat, vibro.
  65.  
  66. See sox man page for detailed information on supported file types, data
  67. formats, and effect options."
  68.     exit 0
  69. }
  70.  
  71.  
  72. # loop over arguments
  73. while [ $# -ne 0 ]; do
  74.     case "$1" in
  75.     avg|band|bandpass|bandreject|chorus|compand|copy|cut|deemph|earwax|echo|echos|fade|filter|flanger|highp|highpass|lowp|lowpass|map|mask|mcompand|pan|phaser|pick|pitch|polyphase|rate|repeat|resample|reverb|reverse|silence|speed|split|stat|stretch|swap|trim|vibro|vol)
  76.         effects="$@"
  77.         break
  78.         ;;
  79.     -c)
  80.         shift
  81.         fopts="$fopts -c $1"
  82.         ;;
  83.     --channels=*)
  84.         fopts="$fopts -c `echo $1 | sed 's/.*=//'`"
  85.         ;;
  86.     -d)
  87.         shift
  88.         device="$1"
  89.         ;;
  90.     --device=*)
  91.         device=`echo $1 | sed 's/.*=//'`
  92.         ;;
  93.     -f)
  94.         shift
  95.         fopts="$fopts -$1"
  96.         ;;
  97.     --format=*)
  98.         fopts="$fopts -`echo $1 | sed 's/.*=//'`"
  99.         ;;
  100.     -r)
  101.         shift
  102.         fopts="$fopts -r $1"
  103.         ;;
  104.     --rate=*)
  105.         fopts="$fopts -r `echo $1 | sed 's/.*=//'`"
  106.         ;;
  107.     -s)
  108.         shift
  109.         fopts="$fopts -$1"
  110.         ;;
  111.     --size=*)
  112.         fopts="$fopts -`echo $1 | sed 's/.*=//'`"
  113.         ;;
  114.     -t)
  115.         shift
  116.         fopts2="$fopts -t $1"
  117.         ;;
  118.     --type=*)
  119.         fopts2="$fopts -t `echo $1 | sed 's/.*=//'`"
  120.         ;;
  121.     -v)
  122.         shift
  123.         volume="-v $1"
  124.         ;;
  125.     --volume=*)
  126.         volume="-v `echo $1 | sed 's/.*=//'`"
  127.         ;;
  128.     -x|--xinu)
  129.         fopts="$fopts -x"
  130.         ;;
  131.     --file)
  132.         shift
  133.         if [ -z "$filename" ]; then
  134.         filename="$1"
  135.         else
  136.         echo "Filename already given.  Ignoring extra name: $1" 1>&2
  137.         fi
  138.         ;;
  139.     -h)
  140.         help
  141.         ;;
  142.     --help)
  143.         help
  144.         ;;
  145.     --version)
  146.         version
  147.         ;;
  148.     -)
  149.         filename="-"
  150.         ;;
  151.     -*)
  152.         fopts="$fopts $1"
  153.         ;;
  154.     *)
  155.         if [ -z "$filename" ]; then
  156.         filename="$1"
  157.         else
  158.         echo "Filename already given.  Ignoring extra name: $1" 1>&2
  159.         fi
  160.         
  161.         ;;
  162.     esac
  163.     shift
  164. done
  165.  
  166. arch=`uname -s`
  167. case $arch in
  168.   SunOS)
  169.     case `uname -r` in
  170.         # Solaris software can auto-detect hardware capabilities.
  171.         5.*)
  172.         arch_defines="-t sunau"
  173.         ;;
  174.     # For SunOS default to signed words.  Some hardware can only play u-law and would need
  175.     # to be changed here.
  176.     *)
  177.         arch_defines="-t sunau -w -s"
  178.         ;;
  179.     esac
  180.     if [ -z "$device" ]; then
  181.     device="/dev/audio"
  182.     fi
  183.     ;;
  184.   Linux|FreeBSD)
  185.     arch_defines="-t ossdsp"
  186.     if [ -z "$device" ]; then
  187.     device="/dev/dsp"
  188.     fi
  189.     ;;
  190.   NetBSD)
  191.     arch_defines="-t sunau"
  192.     if [ -z "$device" ]; then
  193.         device="/dev/audio"
  194.     fi
  195.     ;;
  196. esac
  197.  
  198. # If user sets AUDIODEV environment variable then force output device
  199. # to by that.  Solaris SunRay's make use of this for sure.
  200. if [ -n "$AUDIODEV" ]; then
  201.     device="$AUDIODEV"
  202. fi
  203.  
  204. # If name is "rec" then record else assume user is wanting to play
  205. # a sound file.
  206. if [ "$program_name" = "rec" ]; then
  207.  
  208.     # Don't send data to stdout if they are reading from it.
  209.     if [ "$filename" = "-" ]; then
  210.       echo "Send break (control-c) to end recording" 1>&2
  211.     else
  212.       echo "Send break (control-c) to end recording"
  213.     fi
  214.     sox $volume $arch_defines $fopts $device $fopts2 "$filename" $effects 
  215.  
  216. else
  217.     sox $volume $fopts $fopts2 "$filename" $arch_defines $device $effects
  218. fi
  219.