shithub: sox

Download patch

ref: 64dc1479b2f3fd3248b58b9a65caf62129ef06b2
parent: 8a376c3c99401f239c80abbac11111a673aa2e1a
author: cbagwell <cbagwell>
date: Sat Feb 27 18:01:00 EST 1999

Adding ALSA supportt

--- a/Changelog
+++ b/Changelog
@@ -22,6 +22,8 @@
   o Fixed a couple cross-platform compiler issues.
   o Jimen Ching has added support for "configure" in to SOX.  Finally,
     a good solution to cross-platform compiling!
+  o Jimen Ching has added native support for the ALSA driver to play
+    and record audio from. (jching@flex.com)
   o Minor correction for -r example in manual page.
   o Renamed sox.sh to soxeffect and rewrote.  Symbolic links can be made
     from this file to the name of a sox effect.  It will then run that
--- a/INSTALL
+++ b/INSTALL
@@ -1,10 +1,5 @@
-SOX: Sound Tools Installation
+SoX: Sound eXchange Installation
 
-October 16, 1998
-
-The sox program is just a batch utility that reads & writes
-files.  It's very easy to port to new computers.
-
 This distribution will compile and run on most Unix systems.
 It was originally developed on a Unix/386 machine running AT&T V.3.2
 but it currently developed under Linux.  With little work it should
@@ -11,9 +6,30 @@
 work with most SVR4 systems, BSD-derived Unix's and DOS systems that
 use the GNU tool set.
 
-Sox supports the following operating systems.  Use the listed
-Makefile when compiling.
+Compiling
+---------
 
+The perfered method for compiling sox is to use the "configure" scripts
+compatible with most unix systems that contain "/bin/sh" or equivelent
+(even the Win95/NT Cygwin setup will work with this).
+
+To compile SoX on these platforms run the following commands:
+
+    ./configure
+    make
+    make install
+
+You should then have a working version of sox in sox directory.
+If your actively developing SoX, you may optionally wish to run 
+"make depend" after configure to create a detailed dependiency list.
+
+If your system works with the "configure" script then you may skip
+to the Testing section.
+
+If your system does not work with the configure scripts then there are
+several canned "Makefile"'s that you can use.  The following systems
+have a canned Makefile:
+
     AMIGA      Makefile.ami (hasn't been verified lately)
     DOS        Makefile.dos (Borland and Turbo C, almost Microsoft C++)
 	    or Makefile.unx (using GCC compatible compiler)
@@ -30,9 +46,9 @@
 make -f Makefile.name      or
 make -fmakefile.name
 
-Before compiling you will need to edit the Makefile and uncomment 
-the compiler define section related to your operating system
-and possibly comment out any previous system defines.
+Before compiling with a canned Makefile you will need to edit the 
+Makefile and uncomment the compiler define section related to your 
+operating system and possibly comment out any previous system defines.
 
 There are a few additional defines available for your operating 
 system to add things such as sound playing support.  This is 
@@ -45,6 +61,15 @@
 After installing the GSM library you must point to this file by
 commenting and modifying the appropriate section of the Makefile.
 
+If you're processing lots of u-law or a-law files, you should
+define FAST_ULAW_COMPRESSION and/or FAST_ALAW_COMPRESSION in your 
+Makefile.  These substitute a table-based method for the standard method.
+The tables are 32K, so if you don't want them, you don't have to
+use them.
+
+Testing
+-------
+
 After successfully compiling SOX, try translating a sound file.
 If you can play one of the supported sound file formats,
 translate 'monkey.voc' to your format (we'll use 'xxx'):
@@ -58,18 +83,11 @@
 	sox monkey.voc -r 12500 -s -w monkey.xxx 
 
 If monkey.xxx plays properly (it's a very short monkey screech),
-congratulations!  SOX works.  Now you should run the 'tests.sh'
-shell script to exercise various test scenarios.  It should
-print nothing out.  You can only run this script under Unix.
-It shows alternate uses of the (far too) many options to sox.
-After that, 'testall.sh' tests most of the implemented file
-handlers to make sure that some portability issue haven't popped up.
+congratulations!  SoX works.  Now you should run the "tests.sh"
+shell script if your running under a unix varient to exercise 
+various test scenarios.  It should print nothing out.  You can also
+run tests.bat under DOS for similar tests. 
 
-After testing with a sound file, try compiling sox with the
-optimizer (-O instead of -g).  It should run a little faster.
-
-If you're processing lots of u-law or a-law files, you should
-define FAST_ULAW_COMPRESSION and/or FAST_ALAW_COMPRESSION in your 
-Makefile.  These substitute a table-based method for the standard method.
-The tables are 32K, so if you don't want them, you don't have to
-use them.
+After that, "testall.sh" ("testall.bat for DOS) tests most of the 
+implemented file handlers to make sure that some portability issue 
+haven't popped up
--- a/Makefile.ami
+++ b/Makefile.ami
@@ -16,7 +16,7 @@
 ## rewrite this makefile for 'smake'.
 ##
 
-FSRC	= 8svx.c aiff.c au.c auto.c cdr.c cvsd.c dat.c g711.c g721.c \
+FSRC	= 8svx.c aiff.c alsa.c au.c auto.c cdr.c cvsd.c dat.c g711.c g721.c \
 	  g723_24.c g723_40.c g72x.c gsm.c hcom.c maud.c oss.c raw.c \
 	  sbdsp.c sf.c smp.c sndrtool.c sunaudio.c tx16w.c voc.c wav.c wve.c
 
@@ -49,7 +49,7 @@
 FILES     = $(MISC) $(HEADERS) $(SOURCES) $(AMIGA) $(DOS) $(VMS) \
 	    $(SKEL) $(TESTS)
 
-FOBJ	= 8svx.o aiff.o au.o auto.o cdr.o cvsd.o dat.o g711.o g721.o \
+FOBJ	= 8svx.o aiff.o alsa.o au.o auto.o cdr.o cvsd.o dat.o g711.o g721.o \
 	  g723_24.o g723_40.o g72x.o gsm.o hcom.o maud.o oss.o raw.o \
 	  sbdsp.o sf.o smp.o sndrtool.o sunaudio.o tx16w.o voc.o wav.o wve.o
 
--- a/Makefile.dos
+++ b/Makefile.dos
@@ -10,7 +10,7 @@
 # Need object files to know what libst.lib depends on.  All .c files
 # are compiled from default rules of make.
 
-FOBJ	= 8svx.obj aiff.obj au.obj auto.obj cdr.obj cvsd.obj dat.obj \
+FOBJ	= 8svx.obj aiff.obj alsa.obj au.obj auto.obj cdr.obj cvsd.obj dat.obj \
 	  g711.obj g721.obj g723_24.obj g723_40.obj g72x.obj gsm.obj \
 	  hcom.obj maud.obj oss.obj raw.obj sbdsp.obj sf.obj smp.obj \
 	  sndrtool.obj sunaudio.obj tx16w.obj voc.obj wav.obj wve.obj
--- a/Makefile.os9
+++ b/Makefile.os9
@@ -12,7 +12,8 @@
 LFLAGS	=	$(CFLAGS) -l=/dd/lib/sys_clib.l
 CC		=	cc
 
-FOBJ	= $(RDIR)/8svx.r $(RDIR)/aiff.r $(RDIR)/au.r $(RDIR)/auto.r \
+FOBJ	= $(RDIR)/8svx.r $(RDIR)/aiff.r $(RDIR)/alsa.r $(RDIR)/au.r 
+	  $(RDIR)/auto.r \
 	  $(RDIR)/cdr.r $(RDIR)/cvsd.r $(RDIR)/dat.r $(RDIR)/g711.r \
 	  $(RDIR)/g721.r $(RDIR)/g723_24.r $(RDIR)/g723_40.r \
 	  $(RDIR)/g72x.r $(RDIR)/gsm.r $(RDIR)/hcom.r $(RDIR)/maud.r \
--- a/Makefile.unx
+++ b/Makefile.unx
@@ -27,7 +27,7 @@
 
 ##############################################################################
 
-FSRC	= 8svx.c aiff.c au.c auto.c cdr.c cvsd.c dat.c g711.c g721.c \
+FSRC	= 8svx.c aiff.c alsa.c au.c auto.c cdr.c cvsd.c dat.c g711.c g721.c \
 	  g723_24.c g723_40.c g72x.c gsm.c hcom.c maud.c oss.c raw.c \
 	  sbdsp.c sf.c smp.c sndrtool.c sunaudio.c tx16w.c voc.c wav.c wve.c
 
@@ -68,7 +68,7 @@
 
 ##############################################################################
 
-FOBJ	= 8svx.o aiff.o au.o auto.o cdr.o cvsd.o dat.o g711.o g721.o \
+FOBJ	= 8svx.o aiff.o alsa.o au.o auto.o cdr.o cvsd.o dat.o g711.o g721.o \
 	  g723_24.o g723_40.o g72x.o gsm.o hcom.o maud.o oss.o raw.o \
 	  sbdsp.o sf.o smp.o sndrtool.o sunaudio.o tx16w.o voc.o wav.o wve.o
 
@@ -139,15 +139,19 @@
 # If you have the GSM 6.10 libraries installed then uncomment the follow
 # 4 lines, and change to reflect your installation paths.
 #
-#GSM_PRE_LIBS	= -L/usr/local/lib
-#GSM_POST_LIBS	= -lgsm
-#GSM_INCLUDES	= -I/usr/local/include/
-#GSM_DEFINES	= -DHAS_GSM
+# GSM_PRE_LIBS	= -L/usr/local/lib
+# GSM_POST_LIBS	= -lgsm
+# GSM_INCLUDES	= -I/usr/local/include/
+# GSM_DEFINES	= -DHAS_GSM
 
 # For sound support on machines that include the OSS sound driver
 # (such as Linux) then uncomment the following line.
 #
-#PLAYER_DEFINES	= -DOSS_PLAYER
+# PLAYER_DEFINES = -DOSS_PLAYER
+
+# For sound support using the ALSA driver then uncomment the following line.
+#
+# PLAYER_DEFINES = - DALSA_PLAYER
 
 # For sound support under SunOS and Solaris then uncomment the following line.
 #
--- a/README
+++ b/README
@@ -1,7 +1,7 @@
-		SOX: Sound eXchange
+		SoX: Sound eXchange
 
 
-SOX (also known as Sound eXchange) translates sound samples between different
+SoX (also known as Sound eXchange) translates sound samples between different
 file formats, and optionally performs various sound effects.  
 
 This release understands:
@@ -72,29 +72,28 @@
 but until that time I will keep pushing its development forward.
 
 Caveats:
-SOX is intended as the Swiss Army knife of sound processing tools.  It 
+SoX is intended as the Swiss Army knife of sound processing tools.  It 
 doesn't do anything very well, but sooner or later it comes in very handy.
-SOX is really only usable day-to-day if you hide the wacky options with 
+SoX is really only usable day-to-day if you hide the wacky options with 
 one-line shell scripts.
 
 Installing:
-Unless your using a precompiled binary version, you will need to use
-the Amiga, DOS, OS9, or Unix Makefile as appropriate to compile SOX.
-Please read the Makefile's for several options that may need to be customized 
-for your setup.  See the INSTALL file for more detailed instructions.
+Unless your using a precompiled binary version, you will need to compile
+SoX as described in the INSTALL file.  Please read that file for further
+instructions.
 
 Now, read TIPS, CHEAT.eft and CHEAT.  These give a background on how
-SOX deals with sound files and how to convert this format
+SoX deals with sound files and how to convert this format
 to that format, and apply various effects with examples for the most 
 popular formats.
 
-SOX uses file suffices to determine the nature of a sound sample file.
+SoX uses file suffices to determine the nature of a sound sample file.
 If it finds the suffix in its list, it uses the appropriate read
 or write handler to deal with that file.  You may override the suffix
 by giving a different type via the '-t type' argument.  See the manual
 page for more information.
 
-SOX has an auto-detect feature that attempts to figure out
+SoX has an auto-detect feature that attempts to figure out
 the nature of an unmarked sound sample.  It works very well.
 This is the 'auto' file format.
 
@@ -109,11 +108,11 @@
 
 If you have bug fixes/enhancements, please send it to me as I would like
 to coordinate the releases.  Please document your changes.  I don't 
-possess every kind of computer currently sold, and SOX is now beyond 
+possess every kind of computer currently sold, and SoX is now beyond 
 the phase where I can understand and test most of your contributions.
 
-The majority of SOX features and source code are contributed
-by you the user.  Thank you very much for making SOX a success!
+The majority of SoX features and source code are contributed
+by you the user.  Thank you very much for making SoX a success!
 
 	Creator:
 		Lance Norskog		thinman@meer.net (inactive currently)
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# From configure.in configure.in 0.2
+# From configure.in configure.in 0.3
 # Guess values for system-dependent variables and create Makefiles.
 # Generated automatically using autoconf version 2.12 
 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
@@ -580,7 +580,9 @@
 # Check whether --with-alsa_dsp or --without-alsa_dsp was given.
 if test "${with_alsa_dsp+set}" = set; then
   withval="$with_alsa_dsp"
-  alsa_dsp=yes
+  alsa_dsp="$withval"
+else
+  alsa_dsp=auto
 fi
 
 
@@ -587,7 +589,9 @@
 # Check whether --with-oss_dsp or --without-oss_dsp was given.
 if test "${with_oss_dsp+set}" = set; then
   withval="$with_oss_dsp"
-  oss_dsp=yes
+  oss_dsp="$withval"
+else
+  oss_dsp=auto
 fi
 
 
@@ -594,7 +598,9 @@
 # Check whether --with-sun_audio or --without-sun_audio was given.
 if test "${with_sun_audio+set}" = set; then
   withval="$with_sun_audio"
-  sun_audio=yes
+  sun_audio="$withval"
+else
+  sun_audio=auto
 fi
 
 
@@ -646,7 +652,7 @@
 fi
 
 echo $ac_n "checking host system type""... $ac_c" 1>&6
-echo "configure:650: checking host system type" >&5
+echo "configure:656: checking host system type" >&5
 
 host_alias=$host
 case "$host_alias" in
@@ -667,7 +673,7 @@
 echo "$ac_t""$host" 1>&6
 
 echo $ac_n "checking target system type""... $ac_c" 1>&6
-echo "configure:671: checking target system type" >&5
+echo "configure:677: checking target system type" >&5
 
 target_alias=$target
 case "$target_alias" in
@@ -685,7 +691,7 @@
 echo "$ac_t""$target" 1>&6
 
 echo $ac_n "checking build system type""... $ac_c" 1>&6
-echo "configure:689: checking build system type" >&5
+echo "configure:695: checking build system type" >&5
 
 build_alias=$build
 case "$build_alias" in
@@ -734,7 +740,7 @@
 # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:738: checking for $ac_word" >&5
+echo "configure:744: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -763,7 +769,7 @@
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:767: checking for $ac_word" >&5
+echo "configure:773: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -811,7 +817,7 @@
 fi
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:815: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:821: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
@@ -821,11 +827,11 @@
 cross_compiling=$ac_cv_prog_cc_cross
 
 cat > conftest.$ac_ext <<EOF
-#line 825 "configure"
+#line 831 "configure"
 #include "confdefs.h"
 main(){return(0);}
 EOF
-if { (eval echo configure:829: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:835: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
@@ -845,12 +851,12 @@
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:849: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:855: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:854: checking whether we are using GNU C" >&5
+echo "configure:860: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -859,7 +865,7 @@
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:863: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:869: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
@@ -874,7 +880,7 @@
   ac_save_CFLAGS="$CFLAGS"
   CFLAGS=
   echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:878: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:884: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -904,7 +910,7 @@
 # Extract the first word of "ranlib", so it can be a program name with args.
 set dummy ranlib; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:908: checking for $ac_word" >&5
+echo "configure:914: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -941,7 +947,7 @@
 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
 # ./install, which can be erroneously created by make from ./install.sh.
 echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:945: checking for a BSD compatible install" >&5
+echo "configure:951: checking for a BSD compatible install" >&5
 if test -z "$INSTALL"; then
 if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -993,7 +999,7 @@
 
 
 echo $ac_n "checking for gsm_create in -lgsm""... $ac_c" 1>&6
-echo "configure:997: checking for gsm_create in -lgsm" >&5
+echo "configure:1003: checking for gsm_create in -lgsm" >&5
 ac_lib_var=`echo gsm'_'gsm_create | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1001,7 +1007,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lgsm  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1005 "configure"
+#line 1011 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1012,7 +1018,7 @@
 gsm_create()
 ; return 0; }
 EOF
-if { (eval echo configure:1016: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1022: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1054,7 +1060,7 @@
 
 
 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:1058: checking how to run the C preprocessor" >&5
+echo "configure:1064: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
   CPP=
@@ -1069,13 +1075,13 @@
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 1073 "configure"
+#line 1079 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1079: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1085: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   :
@@ -1086,13 +1092,13 @@
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 1090 "configure"
+#line 1096 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1096: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1102: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   :
@@ -1118,17 +1124,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1122: checking for $ac_hdr" >&5
+echo "configure:1128: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1127 "configure"
+#line 1133 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1132: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1138: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1159,12 +1165,12 @@
 for ac_func in getopt
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1163: checking for $ac_func" >&5
+echo "configure:1169: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1168 "configure"
+#line 1174 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -1187,7 +1193,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1191: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1197: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -1215,12 +1221,12 @@
 for ac_func in strerror memmove
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1219: checking for $ac_func" >&5
+echo "configure:1225: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1224 "configure"
+#line 1230 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -1243,7 +1249,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1247: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1253: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -1269,8 +1275,10 @@
 
 
 
-echo $ac_n "checking whether /dev/snd/pcm00 is functional (ALSA)""... $ac_c" 1>&6
-echo "configure:1274: checking whether /dev/snd/pcm00 is functional (ALSA)" >&5
+if test "$alsa_dsp" = auto
+then
+	echo $ac_n "checking whether /dev/snd/pcm00 is functional (ALSA)""... $ac_c" 1>&6
+echo "configure:1282: checking whether /dev/snd/pcm00 is functional (ALSA)" >&5
 if eval "test \"`echo '$''{'ac_cv_dev_alsa_dsp'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1278,23 +1286,23 @@
   ac_cv_dev_alsa_dsp=no
 else
   cat > conftest.$ac_ext <<EOF
-#line 1282 "configure"
+#line 1290 "configure"
 #include "confdefs.h"
 
-		int
-		main()
-			{
-			int fd = open("/dev/snd/pcm00", 0);
-			if (fd != -1)
+			int
+			main()
 				{
-				close(fd);
-				return 0;
+				int fd = open("/dev/snd/pcm00", 0);
+				if (fd != -1)
+					{
+					close(fd);
+					return 0;
+					}
+				return 1;
 				}
-			return 1;
-			}
-		
+			
 EOF
-if { (eval echo configure:1298: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1306: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   ac_cv_dev_alsa_dsp=yes
 else
@@ -1306,23 +1314,26 @@
 rm -fr conftest*
 fi
 
-	
+		
 fi
 
 echo "$ac_t""$ac_cv_dev_alsa_dsp" 1>&6
-if test "$ac_cv_dev_alsa_dsp" = yes; then alsa_dsp=yes; fi
+
+	if test "$ac_cv_dev_alsa_dsp" = yes
+	then
+		alsa_dsp=yes
+	fi
+fi
 if test "$alsa_dsp" = yes
 then
 	CFLAGS="$CFLAGS -DALSA_PLAYER"
 	NEED_ALSA=1
-	if test "$ac_cv_dev_alsa_dsp" = no
-	then
-		echo "configure: warning: Force support for /dev/snd/pcm00 (ALSA)" 1>&2
-	fi
 fi
 
-echo $ac_n "checking whether /dev/dsp is functional (OSS)""... $ac_c" 1>&6
-echo "configure:1326: checking whether /dev/dsp is functional (OSS)" >&5
+if test "$oss_dsp" = auto
+then
+	echo $ac_n "checking whether /dev/dsp is functional (OSS)""... $ac_c" 1>&6
+echo "configure:1337: checking whether /dev/dsp is functional (OSS)" >&5
 if eval "test \"`echo '$''{'ac_cv_dev_oss_dsp'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1330,23 +1341,23 @@
   ac_cv_dev_oss_dsp=no
 else
   cat > conftest.$ac_ext <<EOF
-#line 1334 "configure"
+#line 1345 "configure"
 #include "confdefs.h"
 
-		int
-		main()
-			{
-			int fd = open("/dev/dsp", 0);
-			if (fd != -1)
+			int
+			main()
 				{
-				close(fd);
-				return 0;
+				int fd = open("/dev/dsp", 0);
+				if (fd != -1)
+					{
+					close(fd);
+					return 0;
+					}
+				return 1;
 				}
-			return 1;
-			}
-		
+			
 EOF
-if { (eval echo configure:1350: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1361: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   ac_cv_dev_oss_dsp=yes
 else
@@ -1358,23 +1369,25 @@
 rm -fr conftest*
 fi
 
-	
+		
 fi
 
 echo "$ac_t""$ac_cv_dev_oss_dsp" 1>&6
-if test "$ac_cv_dev_oss_dsp" = yes; then oss_dsp=yes; fi
+	if test "$ac_cv_dev_oss_dsp" = yes
+	then
+		oss_dsp=yes
+	fi
+fi
 if test "$oss_dsp" = yes
 then
 	CFLAGS="$CFLAGS -DOSS_PLAYER"
 	NEED_OSS=1
-	if test "$ac_cv_dev_oss_dsp" = no
-	then
-		echo "configure: warning: Force support for /dev/dsp (OSS)" 1>&2
-	fi
 fi
 
-echo $ac_n "checking whether /dev/audio is functional (SUN, etc)""... $ac_c" 1>&6
-echo "configure:1378: checking whether /dev/audio is functional (SUN, etc)" >&5
+if test "$sun_audio" = auto
+then
+	echo $ac_n "checking whether /dev/audio is functional (SUN, etc)""... $ac_c" 1>&6
+echo "configure:1391: checking whether /dev/audio is functional (SUN, etc)" >&5
 if eval "test \"`echo '$''{'ac_cv_dev_sun_audio'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1382,23 +1395,23 @@
   ac_cv_dev_sun_audio=no
 else
   cat > conftest.$ac_ext <<EOF
-#line 1386 "configure"
+#line 1399 "configure"
 #include "confdefs.h"
 
-		int
-		main()
-			{
-			int fd = open("/dev/audio", 0);
-			if (fd != -1)
+			int
+			main()
 				{
-				close(fd);
-				return 0;
+				int fd = open("/dev/audio", 0);
+				if (fd != -1)
+					{
+					close(fd);
+					return 0;
+					}
+				return 1;
 				}
-			return 1;
-			}
-		
+			
 EOF
-if { (eval echo configure:1402: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1415: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   ac_cv_dev_sun_audio=yes
 else
@@ -1410,19 +1423,52 @@
 rm -fr conftest*
 fi
 
-	
+		
 fi
 
 echo "$ac_t""$ac_cv_dev_sun_audio" 1>&6
-if test "$ac_cv_dev_sun_audio" = yes; then sun_audio=yes; fi
+	if test "$ac_cv_dev_sun_audio" = yes
+	then
+		ac_safe=`echo "audioio.h" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for audioio.h""... $ac_c" 1>&6
+echo "configure:1435: checking for audioio.h" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1440 "configure"
+#include "confdefs.h"
+#include <audioio.h>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1445: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=yes"
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  sun_audio=yes
+else
+  echo "$ac_t""no" 1>&6
+echo "configure: warning: No audioio.h to compile with SUN /dev/audio" 1>&2
+fi
+
+	fi
+fi
 if test "$sun_audio" = yes
 then
 	CFLAGS="$CFLAGS -DSUNAUDIO_PLAYER"
 	NEED_SUNAU=1
-	if test "$ac_cv_dev_sun_audio" = no
-	then
-		echo "configure: warning: Force support for /dev/audio (SUN, etc)" 1>&2
-	fi
 fi
 
 
@@ -1722,6 +1768,8 @@
 rm -fr confdefs* $ac_clean_files
 test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1
 
+
+touch .depend
 
 echo
 echo "Configure finished.  Do 'make depend; make' to compile SOX."
--- a/configure.in
+++ b/configure.in
@@ -3,7 +3,7 @@
 dnl configure.in
 dnl
 
-AC_REVISION([configure.in 0.2])
+AC_REVISION([configure.in 0.3])
 AC_INIT(sox.c)
 dnl AC_CONFIG_HEADER(config.h)
 
@@ -37,15 +37,18 @@
 
 AC_ARG_WITH(alsa_dsp,
 	[  --with-alsa-dsp         Force support for /dev/snd/pcm00 (ALSA)],
-	[alsa_dsp=yes])
+	[alsa_dsp="$withval"],
+	[alsa_dsp=auto])
 
 AC_ARG_WITH(oss_dsp,
 	[  --with-oss-dsp          Force support for /dev/dsp (OSS)],
-	[oss_dsp=yes])
+	[oss_dsp="$withval"],
+	[oss_dsp=auto])
 
 AC_ARG_WITH(sun_audio,
 	[  --with-sun-audio        Force support for /dev/audio (SUN, etc)],
-	[sun_audio=yes])
+	[sun_audio="$withval"],
+	[sun_audio=auto])
 
 dnl Set host type
 
@@ -109,100 +112,109 @@
 
 dnl Checks for system services.
 
-AC_CACHE_CHECK(
-	[whether /dev/snd/pcm00 is functional (ALSA)],
-	ac_cv_dev_alsa_dsp,
-	AC_TRY_RUN(
-		[
-		int
-		main()
-			{
-			int fd = open("/dev/snd/pcm00", 0);
-			if (fd != -1)
+if test "$alsa_dsp" = auto
+then
+	AC_CACHE_CHECK(
+		[whether /dev/snd/pcm00 is functional (ALSA)],
+		ac_cv_dev_alsa_dsp,
+		AC_TRY_RUN(
+			[
+			int
+			main()
 				{
-				close(fd);
-				return 0;
+				int fd = open("/dev/snd/pcm00", 0);
+				if (fd != -1)
+					{
+					close(fd);
+					return 0;
+					}
+				return 1;
 				}
-			return 1;
-			}
-		],
-		ac_cv_dev_alsa_dsp=yes,
-		ac_cv_dev_alsa_dsp=no,
-		ac_cv_dev_alsa_dsp=no)
-	)
-if test "$ac_cv_dev_alsa_dsp" = yes; then alsa_dsp=yes; fi
+			],
+			ac_cv_dev_alsa_dsp=yes,
+			ac_cv_dev_alsa_dsp=no,
+			ac_cv_dev_alsa_dsp=no)
+		)
+
+	if test "$ac_cv_dev_alsa_dsp" = yes
+	then
+		alsa_dsp=yes
+	fi
+fi
 if test "$alsa_dsp" = yes
 then
 	CFLAGS="$CFLAGS -DALSA_PLAYER"
 	NEED_ALSA=1
-	if test "$ac_cv_dev_alsa_dsp" = no
-	then
-		AC_MSG_WARN([Force support for /dev/snd/pcm00 (ALSA)])
-	fi
 fi
 
-AC_CACHE_CHECK(
-	[whether /dev/dsp is functional (OSS)],
-	ac_cv_dev_oss_dsp,
-	AC_TRY_RUN(
-		[
-		int
-		main()
-			{
-			int fd = open("/dev/dsp", 0);
-			if (fd != -1)
+if test "$oss_dsp" = auto
+then
+	AC_CACHE_CHECK(
+		[whether /dev/dsp is functional (OSS)],
+		ac_cv_dev_oss_dsp,
+		AC_TRY_RUN(
+			[
+			int
+			main()
 				{
-				close(fd);
-				return 0;
+				int fd = open("/dev/dsp", 0);
+				if (fd != -1)
+					{
+					close(fd);
+					return 0;
+					}
+				return 1;
 				}
-			return 1;
-			}
-		],
-		ac_cv_dev_oss_dsp=yes,
-		ac_cv_dev_oss_dsp=no,
-		ac_cv_dev_oss_dsp=no)
-	)
-if test "$ac_cv_dev_oss_dsp" = yes; then oss_dsp=yes; fi
+			],
+			ac_cv_dev_oss_dsp=yes,
+			ac_cv_dev_oss_dsp=no,
+			ac_cv_dev_oss_dsp=no)
+		)
+	if test "$ac_cv_dev_oss_dsp" = yes
+	then
+		oss_dsp=yes
+	fi
+fi
 if test "$oss_dsp" = yes
 then
 	CFLAGS="$CFLAGS -DOSS_PLAYER"
 	NEED_OSS=1
-	if test "$ac_cv_dev_oss_dsp" = no
-	then
-		AC_MSG_WARN([Force support for /dev/dsp (OSS)])
-	fi
 fi
 
-AC_CACHE_CHECK(
-	[whether /dev/audio is functional (SUN, etc)],
-	ac_cv_dev_sun_audio,
-	AC_TRY_RUN(
-		[
-		int
-		main()
-			{
-			int fd = open("/dev/audio", 0);
-			if (fd != -1)
+if test "$sun_audio" = auto
+then
+	AC_CACHE_CHECK(
+		[whether /dev/audio is functional (SUN, etc)],
+		ac_cv_dev_sun_audio,
+		AC_TRY_RUN(
+			[
+			int
+			main()
 				{
-				close(fd);
-				return 0;
+				int fd = open("/dev/audio", 0);
+				if (fd != -1)
+					{
+					close(fd);
+					return 0;
+					}
+				return 1;
 				}
-			return 1;
-			}
-		],
-		ac_cv_dev_sun_audio=yes,
-		ac_cv_dev_sun_audio=no,
-		ac_cv_dev_sun_audio=no)
-	)
-if test "$ac_cv_dev_sun_audio" = yes; then sun_audio=yes; fi
+			],
+			ac_cv_dev_sun_audio=yes,
+			ac_cv_dev_sun_audio=no,
+			ac_cv_dev_sun_audio=no)
+		)
+	if test "$ac_cv_dev_sun_audio" = yes
+	then
+		AC_CHECK_HEADER(audioio.h,
+			sun_audio=yes,
+			AC_WARN([No audioio.h to compile with SUN /dev/audio]))
+	fi
+fi
 if test "$sun_audio" = yes
 then
 	CFLAGS="$CFLAGS -DSUNAUDIO_PLAYER"
 	NEED_SUNAU=1
-	if test "$ac_cv_dev_sun_audio" = no
-	then
-		AC_MSG_WARN([Force support for /dev/audio (SUN, etc)])
-	fi
 fi
 
 dnl The end
--- a/sox.1
+++ b/sox.1
@@ -9,9 +9,9 @@
 .if t .sp .5v
 .if n .sp
 ..
-.TH SOX 1 "September 6, 1998"
+.TH SoX 1 "September 6, 1998"
 .SH NAME
-sox \- SOund eXchange : universal sound sample translator
+sox \- Sound eXchange : universal sound sample translator
 .SH SYNOPSIS
 .B sox \fIinfile outfile \fB
 .br
@@ -280,7 +280,7 @@
 Values are normalized so that the maximum and minimum
 are 1.00 and -1.00.  This file format can be used to
 create data files for external programs such as
-FFT analyzers or graph routines.  SOX can also convert
+FFT analyzers or graph routines.  SoX can also convert
 a file in this format back into one of the other file
 formats.
 .TP 10
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -8,6 +8,7 @@
 
 SHELL = /bin/sh
 srcdir = @srcdir@
+prefix = @prefix@
 
 # Shell commands.
 
@@ -51,7 +52,9 @@
 OSSSRC_1    = oss.c
 SUNAUSRC_0  =
 SUNAUSRC_1  = sunaudio.c
-EXTRASRCS   = $(OSSSRC_$(NEED_OSS)) $(SUNAUSRC_$(NEED_SUNAU))
+ALSASRC_0   =
+ALSASRC_1   = alsa.c
+EXTRASRCS   = $(OSSSRC_$(NEED_OSS)) $(SUNAUSRC_$(NEED_SUNAU)) $(ALSASRC_$(NEED_ALSA))
 
 LIBSRCS	= $(FSRC) $(ESRC) handlers.c libst.c misc.c util.c $(EXTRASRCS)
 
@@ -70,7 +73,9 @@
 OSSOBJ_1    = oss.o
 SUNAUOBJ_0  =
 SUNAUOBJ_1  = sunaudio.o
-EXTRAOBJS   = $(OSSOBJ_$(NEED_OSS)) $(SUNAUOBJ_$(NEED_SUNAU))
+ALSAOBJ_0   =
+ALSAOBJ_1   = alsa.o
+EXTRAOBJS   = $(OSSOBJ_$(NEED_OSS)) $(SUNAUOBJ_$(NEED_SUNAU)) $(ALSAOBJ_$(NEED_ALSA))
 
 LIBOBJS = $(FOBJ) $(EOBJ) handlers.o libst.o misc.o util.o $(EXTRAOBJS)
 
--- /dev/null
+++ b/src/alsa.c
@@ -1,0 +1,226 @@
+#if	defined(ALSA_PLAYER)
+/*
+ * Copyright 1997 Jimen Ching And Sundry Contributors
+ * This source code is freely redistributable and may be used for
+ * any purpose.  This copyright notice must be maintained.
+ * Jimen Ching And Sundry Contributors are not
+ * responsible for the consequences of using this software.
+ */
+
+/* Direct to ALSA sound driver
+ *
+ * added by Jimen Ching (jching@flex.com) 19990207
+ * based on info grabed from aplay.c in alsa-utils package.
+ */
+
+#include <malloc.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <linux/asound.h>
+#include <sys/ioctl.h>
+#include "st.h"
+#include "libst.h"
+
+char *get_style(style)
+int style;
+{
+    switch(style)
+    {
+	case UNSIGNED: return "UNSIGNED";
+	case SIGN2: return "SIGNED LINEAR 2's Comp";
+	case ULAW: return "uLaw";
+	case ALAW: return "aLaw";
+	case ADPCM: return "ADPCM";
+	default: return "unknown";
+    }
+}
+
+/*
+ * Do anything required before you start reading samples.
+ * Read file header.
+ *	Find out sampling rate,
+ *	size and style of samples,
+ *	mono/stereo/quad.
+ */
+void alsastartread(ft)
+ft_t ft;
+{
+    int bps, fmt, size;
+    snd_pcm_record_info_t r_info;
+    snd_pcm_format_t format;
+    snd_pcm_record_params_t r_params;
+
+    memset(&r_info, 0, sizeof(r_info));
+    ioctl(fileno(ft->fp), SND_PCM_IOCTL_RECORD_INFO, &r_info);
+    ft->file.count = 0;
+    ft->file.eof = 0;
+    ft->file.size = r_info.buffer_size;
+    if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
+	fail("unable to allocate output buffer of size %d", ft->file.size);
+    }
+    if (ft->info.rate < r_info.min_rate) ft->info.rate = 2 * r_info.min_rate;
+    else if (ft->info.rate > r_info.max_rate) ft->info.rate = r_info.max_rate;
+    if (ft->info.channels == -1) ft->info.channels = r_info.min_channels;
+    else if (ft->info.channels > r_info.max_channels) ft->info.channels = r_info.max_channels;
+    if (ft->info.size == -1) {
+	if ((r_info.hw_formats & SND_PCM_FMT_U8) || (r_info.hw_formats & SND_PCM_FMT_S8))
+	    ft->info.size = BYTE;
+	else
+	    ft->info.size = WORD;
+    }
+    if (ft->info.style == -1) {
+	if ((r_info.hw_formats & SND_PCM_FMT_S16_LE) || (r_info.hw_formats & SND_PCM_FMT_S8))
+	    ft->info.style = SIGN2;
+	else
+	    ft->info.style = UNSIGNED;
+    }
+    if (ft->info.size == BYTE) {
+	switch (ft->info.style)
+	{
+	    case SIGN2:
+		if (!(r_info.hw_formats & SND_PCM_FMT_S8))
+		    fail("ALSA driver does not support signed byte samples");
+		fmt = SND_PCM_SFMT_S8;
+		break;
+	    case UNSIGNED:
+		if (!(r_info.hw_formats & SND_PCM_FMT_U8))
+		    fail("ALSA driver does not support unsigned byte samples");
+		fmt = SND_PCM_SFMT_U8;
+		break;
+	    default:
+		fail("Hardware does not support %s output", get_style(ft->info.style));
+		break;
+	}
+    }
+    else {
+	switch (ft->info.style)
+	{
+	    case SIGN2:
+		if (!(r_info.hw_formats & SND_PCM_FMT_S16_LE))
+		    fail("ALSA driver does not support signed word samples");
+		fmt = SND_PCM_SFMT_S16_LE;
+		break;
+	    case UNSIGNED:
+		if (!(r_info.hw_formats & SND_PCM_FMT_U16_LE))
+		    fail("ALSA driver does not support unsigned word samples");
+		fmt = SND_PCM_SFMT_U16_LE;
+		break;
+	    default:
+		fail("Hardware does not support %s output", get_style(ft->info.style));
+		break;
+	}
+    }
+
+    memset(&format, 0, sizeof(format));
+    format.format = fmt;
+    format.rate = ft->info.rate;
+    format.channels = ft->info.channels;
+    ioctl(fileno(ft->fp), SND_PCM_IOCTL_RECORD_FORMAT, &format);
+
+    size = ft->file.size;
+    bps = format.rate * format.channels;
+    if (ft->info.size == WORD) bps <<= 1;
+    bps >>= 2;
+    while (size > bps) size >>= 1;
+    if (size < 16) size = 16;
+    memset(&r_params, 0, sizeof(r_params));
+    r_params.fragment_size = size;
+    r_params.fragments_min = 1;
+    ioctl(fileno(ft->fp), SND_PCM_IOCTL_RECORD_PARAMS, &r_params);
+
+    sigintreg(ft);	/* Prepare to catch SIGINT */
+}
+
+void alsastartwrite(ft)
+ft_t ft;
+{
+    int bps, fmt, size;
+    snd_pcm_playback_info_t p_info;
+    snd_pcm_format_t format;
+    snd_pcm_playback_params_t p_params;
+
+    memset(&p_info, 0, sizeof(p_info));
+    ioctl(fileno(ft->fp), SND_PCM_IOCTL_PLAYBACK_INFO, &p_info);
+    ft->file.count = 0;
+    ft->file.eof = 0;
+    ft->file.size = p_info.buffer_size;
+    if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
+	fail("unable to allocate output buffer of size %d", ft->file.size);
+    }
+    if (ft->info.rate < p_info.min_rate) ft->info.rate = 2 * p_info.min_rate;
+    else if (ft->info.rate > p_info.max_rate) ft->info.rate = p_info.max_rate;
+    if (ft->info.channels == -1) ft->info.channels = p_info.min_channels;
+    else if (ft->info.channels > p_info.max_channels) ft->info.channels = p_info.max_channels;
+    if (ft->info.size == -1) {
+	if ((p_info.hw_formats & SND_PCM_FMT_U8) || (p_info.hw_formats & SND_PCM_FMT_S8))
+	    ft->info.size = BYTE;
+	else
+	    ft->info.size = WORD;
+    }
+    if (ft->info.style == -1) {
+	if ((p_info.hw_formats & SND_PCM_FMT_S16_LE) || (p_info.hw_formats & SND_PCM_FMT_S8))
+	    ft->info.style = SIGN2;
+	else
+	    ft->info.style = UNSIGNED;
+    }
+    if (ft->info.size == BYTE) {
+	switch (ft->info.style)
+	{
+	    case SIGN2:
+		if (!(p_info.hw_formats & SND_PCM_FMT_S8))
+		    fail("ALSA driver does not support signed byte samples");
+		fmt = SND_PCM_SFMT_S8;
+		break;
+	    case UNSIGNED:
+		if (!(p_info.hw_formats & SND_PCM_FMT_U8))
+		    fail("ALSA driver does not support unsigned byte samples");
+		fmt = SND_PCM_SFMT_U8;
+		break;
+	    default:
+		fail("Hardware does not support %s output", get_style(ft->info.style));
+		break;
+	}
+    }
+    else {
+	switch (ft->info.style)
+	{
+	    case SIGN2:
+		if (!(p_info.hw_formats & SND_PCM_FMT_S16_LE))
+		    fail("ALSA driver does not support signed word samples");
+		fmt = SND_PCM_SFMT_S16_LE;
+		break;
+	    case UNSIGNED:
+		if (!(p_info.hw_formats & SND_PCM_FMT_U16_LE))
+		    fail("ALSA driver does not support unsigned word samples");
+		fmt = SND_PCM_SFMT_U16_LE;
+		break;
+	    default:
+		fail("Hardware does not support %s output", get_style(ft->info.style));
+		break;
+	}
+    }
+
+    memset(&format, 0, sizeof(format));
+    format.format = fmt;
+    format.rate = ft->info.rate;
+    format.channels = ft->info.channels;
+    ioctl(fileno(ft->fp), SND_PCM_IOCTL_PLAYBACK_FORMAT, &format);
+
+    size = ft->file.size;
+    bps = format.rate * format.channels;
+    if (ft->info.size == WORD) bps <<= 1;
+    bps >>= 2;
+    while (size > bps) size >>= 1;
+    if (size < 16) size = 16;
+    memset(&p_params, 0, sizeof(p_params));
+    p_params.fragment_size = size;
+    p_params.fragments_max = -1;
+    p_params.fragments_room = 1;
+    ioctl(fileno(ft->fp), SND_PCM_IOCTL_PLAYBACK_PARAMS, &p_params);
+
+    sigintreg(ft);
+}
+
+#endif
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -34,6 +34,15 @@
 extern void alstartread();
 extern void alstartwrite();
 
+#if	defined(ALSA_PLAYER)
+char *alsanames[] = {
+	"alsa",
+	(char *) 0
+};
+extern void alsastartread();
+extern void alsastartwrite();
+#endif
+
 char *aunames[] = {
 	"au",
 #ifdef	NeXT
@@ -321,6 +330,11 @@
 	{alnames, FILE_STEREO,
 		alstartread, rawread, rawstopread, 	   /* a-law byte raw */
 		alstartwrite, rawwrite, rawstopwrite},	
+#if	defined(ALSA_PLAYER)
+	{alsanames, FILE_STEREO,
+		alsastartread, rawread, rawstopread,      /* /dev/snd/pcmXX */
+		alsastartwrite, rawwrite, rawstopwrite},
+#endif
 	{aunames, FILE_STEREO,
 		austartread, auread, rawstopread,      /* SPARC .AU w/header */
 		austartwrite, auwrite, austopwrite},	
--- a/src/util.c
+++ b/src/util.c
@@ -12,6 +12,7 @@
 #include "patchlvl.h"
 #include <string.h>
 #include <ctype.h>
+#include <signal.h>
 
 #ifdef __STDC__
 #include <stdarg.h>
@@ -272,3 +273,27 @@
 			ft->filename); */
 }
 
+static ft_t ft_queue[2];
+
+void
+sigint(s)
+int s;
+{
+    if (s == SIGINT) {
+	if (ft_queue[0])
+	    ft_queue[0]->file.eof = 1;
+	if (ft_queue[1])
+	    ft_queue[1]->file.eof = 1;
+    }
+}
+
+void
+sigintreg(ft)
+ft_t ft;
+{
+    if (ft_queue[0] == 0)
+	ft_queue[0] = ft;
+    else
+	ft_queue[1] = ft;
+    signal(SIGINT, sigint);
+}