diff -aur esound-0.2.36/Makefile.in esound-0.2.36-separate_devices/Makefile.in
--- esound-0.2.36/Makefile.in	2005-06-07 03:04:14.000000000 +0200
+++ esound-0.2.36-separate_devices/Makefile.in	2007-06-30 11:15:04.000000000 +0200
@@ -81,13 +81,13 @@
 esdPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
 PROGRAMS = $(bin_PROGRAMS) $(esd_PROGRAMS)
 am__esd_SOURCES_DIST = esd.c clients.c filter.c mix.c players.c \
-	proto.c samples.c getopt.c getopt1.c util.c esd-config.h \
+	proto.c samples.c getopt.c getopt1.c        esd-config.h \
 	esd-server.h
 am__objects_1 = getopt.$(OBJEXT) getopt1.$(OBJEXT)
 @NEED_GETOPT_TRUE@am__objects_2 = $(am__objects_1)
 am_esd_OBJECTS = esd.$(OBJEXT) clients.$(OBJEXT) filter.$(OBJEXT) \
 	mix.$(OBJEXT) players.$(OBJEXT) proto.$(OBJEXT) \
-	samples.$(OBJEXT) $(am__objects_2) util.$(OBJEXT)
+	samples.$(OBJEXT) $(am__objects_2)
 esd_OBJECTS = $(am_esd_OBJECTS)
 am__DEPENDENCIES_2 = libesd.la $(am__DEPENDENCIES_1)
 esd_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
@@ -145,7 +145,7 @@
 @AMDEP_TRUE@	./$(DEPDIR)/libesd_la-genrand.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/libesd_la-util.Plo ./$(DEPDIR)/mix.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/players.Po ./$(DEPDIR)/proto.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/samples.Po ./$(DEPDIR)/util.Po
+@AMDEP_TRUE@	./$(DEPDIR)/samples.Po
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) \
@@ -391,7 +391,6 @@
 	proto.c		\
 	samples.c	\
 	$(getopt_src)   \
-	util.c		\
 	esd-config.h	\
 	esd-server.h
 
@@ -422,7 +421,7 @@
 	esdplay.c
 
 LDADD = libesd.la $(AUDIOFILE_LIBS)
-esd_LDADD = $(WRAP_LIB) $(LDADD)
+esd_LDADD = $(WRAP_LIB) $(LDADD) $(SOUND_LIBS)
 m4datadir = $(datadir)/aclocal
 m4data_DATA = esd.m4
 esdconfdir = $(sysconfdir)
@@ -676,7 +675,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/players.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proto.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/samples.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
diff -aur esound-0.2.36/audio.c esound-0.2.36-separate_devices/audio.c
--- esound-0.2.36/audio.c	2005-01-17 02:45:14.000000000 +0100
+++ esound-0.2.36-separate_devices/audio.c	2007-06-30 11:51:27.000000000 +0200
@@ -12,7 +12,8 @@
 /* globals */
 esd_format_t esd_audio_format = ESD_BITS16 | ESD_STEREO;
 int esd_audio_rate = ESD_DEFAULT_RATE;
-char *esd_audio_device = NULL; /* aux device spec: /dev/dsp2, lineout, etc. */
+char *esd_audio_in_device = NULL; /* aux device spec: /dev/dsp2, lineout, etc. */
+char *esd_audio_out_device = NULL; /* aux device spec: /dev/dsp2, lineout, etc. */
 
 /* the audio device, /dev/dsp, file descriptor */
 static int esd_audio_fd = -1;
diff -aur esound-0.2.36/audio_coreaudio.c esound-0.2.36-separate_devices/audio_coreaudio.c
--- esound-0.2.36/audio_coreaudio.c	2003-06-18 14:12:23.000000000 +0200
+++ esound-0.2.36-separate_devices/audio_coreaudio.c	2007-07-01 12:11:35.000000000 +0200
@@ -12,6 +12,8 @@
  */
 
 #include <CoreAudio/CoreAudio.h>
+#include <CoreServices/CoreServices.h>
+#include <AudioUnit/AudioUnit.h>
 #include <limits.h>
 #include <pthread.h>
 
@@ -86,11 +88,108 @@
 
   return (kAudioHardwareNoError);
 }
-
+  
 #define ARCH_esd_audio_devices
 const char *esd_audio_devices()
 {
-    return "coreaudio API only";
+  int i;
+  int ret;
+  int numDevices;
+  AudioDeviceID *devices;
+  static char buffer[8192];
+  UInt32 size;
+  Boolean writable;
+  strlcpy(buffer, "\n", sizeof(buffer));
+  ret = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, &writable);
+  if (!ret) {
+    numDevices = size / sizeof(AudioDeviceID);
+    devices = (AudioDeviceID *) malloc(size);
+    if (devices) {
+      memset(devices, 0, size);
+      ret = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, devices);
+      if (!ret)
+        for (i = 0; i < numDevices; i++) {
+          char *name;
+          ret = AudioDeviceGetPropertyInfo(devices[i], 0, FALSE, kAudioDevicePropertyDeviceName, &size, NULL);
+          if (!ret && size) {
+            name = (char *) malloc(size);
+            if (name) {
+              ret = AudioDeviceGetProperty(devices[i], 0, FALSE, kAudioDevicePropertyDeviceName, &size, name);
+	      if (!ret) {
+                strlcat(buffer, "output: ", sizeof(buffer));
+                strlcat(buffer, name, sizeof(buffer));
+                strlcat(buffer, "\n", sizeof(buffer));
+              }
+              free(name);
+            }
+          }
+          ret = AudioDeviceGetPropertyInfo(devices[i], 0, TRUE, kAudioDevicePropertyDeviceName, &size, NULL);
+          if (!ret && size) {
+            name = (char *) malloc(size);
+            if (name) {
+              ret = AudioDeviceGetProperty(devices[i], 0, TRUE, kAudioDevicePropertyDeviceName, &size, name);
+	      if (!ret) {
+                strlcat(buffer, "input: ", sizeof(buffer));
+                strlcat(buffer, name, sizeof(buffer));
+                strlcat(buffer, "\n", sizeof(buffer));
+              }
+              free(name);
+            }
+          }
+        }
+      free(devices);
+    }
+  }
+  return buffer;
+}
+
+int find_device(char *look_name, Boolean isInput, AudioDeviceID *device)
+{  
+  UInt32 size;
+  Boolean writable;
+  int ret;
+  int i;
+  Boolean found = FALSE;
+  memset(device, 0, sizeof(AudioDeviceID));
+  if (look_name && strlen(look_name)) {
+    AudioDeviceID *devices;
+    int numDevices;
+    ret = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, &writable);
+    if (!ret) {
+      numDevices = size / sizeof(AudioDeviceID);
+      devices = (AudioDeviceID *) malloc(size);
+      if (devices) {
+        memset(devices, 0, size);
+        ret = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, devices);
+        if (!ret)
+          for (i = 0; i < numDevices; i++) {
+            char *name;
+            ret = AudioDeviceGetPropertyInfo(devices[i], 0, isInput, kAudioDevicePropertyDeviceName, &size, NULL);
+            if (!ret && size) {
+              name = (char *) malloc(size);
+              if (name) {
+                ret = AudioDeviceGetProperty(devices[i], 0, isInput, kAudioDevicePropertyDeviceName, &size, name);
+		if (!(ret || strcmp(look_name, name))) {
+		  *device = devices[i];
+	          found = TRUE;
+		  free(name);
+		  break;
+		}
+                free(name);
+              }
+            }
+	  }
+	free(devices);
+      }
+    }    
+  }
+  if (!found) {
+    // wrong name given or none given at all, try default input/output device
+    ret = AudioHardwareGetPropertyInfo(isInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice, &size, &writable);
+    if (!ret && size)
+      ret = AudioHardwareGetProperty(isInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice, &size, device);
+  }
+  return ret;
 }
 
 /*
@@ -116,12 +215,8 @@
     return (0);
   }
 
-  /********************** playback section ***************************/
-  /* get default output device */
-  propertySize = sizeof(gOutputDeviceID);
-  status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
-	                            &propertySize,
-				    &gOutputDeviceID);
+  status = find_device(esd_audio_out_device, FALSE, &gOutputDeviceID);
+
   if (status) {
     fprintf(stderr, "get default output device failed, status = %d\n",
 	    (int)status);
@@ -206,11 +301,8 @@
   }
 
   /********************** record section ***************************/
-  /* get default input device */
-  propertySize = sizeof(gInputDeviceID);
-  status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
-	                            &propertySize,
-				    &gInputDeviceID);
+  status = find_device(esd_audio_in_device, TRUE, &gInputDeviceID);
+
   if (status) {
     fprintf(stderr, "get default input device failed, status = %d\n",
 	    (int)status);
diff -aur esound-0.2.36/configure esound-0.2.36-separate_devices/configure
--- esound-0.2.36/configure	2005-06-07 03:04:13.000000000 +0200
+++ esound-0.2.36-separate_devices/configure	2007-07-01 14:59:19.000000000 +0200
@@ -23611,7 +23611,7 @@
 #define DRIVER_COREAUDIO 1
 _ACEOF
 
-      SOUND_LIBS="-Wl,-framework -Wl,CoreAudio"
+      SOUND_LIBS="-Wl,-framework,CoreAudio -Wl,-framework,CoreServices"
    fi
 
    if test "x$enable_arts" = "xyes" ; then
diff -aur esound-0.2.36/docs/Makefile.in esound-0.2.36-separate_devices/docs/Makefile.in
--- esound-0.2.36/docs/Makefile.in	2005-06-07 03:04:14.000000000 +0200
+++ esound-0.2.36-separate_devices/docs/Makefile.in	2007-06-30 11:19:28.000000000 +0200
@@ -455,13 +455,13 @@
 @HAVE_JW_TRUE@install-data-local:
 @HAVE_JW_TRUE@	$(mkinstalldirs) $(DESTDIR)$(htmldir)
 @HAVE_JW_TRUE@	files=`cd html && echo *.html`; \
-@HAVE_JW_TRUE@	test "$$files" || for f in $$files; do \
-@HAVE_JW_TRUE@	  cp -p $$f $(DESTDIR)$(htmldir)/$$f; \
+@HAVE_JW_TRUE@	test "$$files" && for f in $$files; do \
+@HAVE_JW_TRUE@	  cp -p html/$$f $(DESTDIR)$(htmldir)/$$f; \
 @HAVE_JW_TRUE@	done
 
 @HAVE_JW_TRUE@uninstall-local:
 @HAVE_JW_TRUE@	files=`cd html && echo *.html`; \
-@HAVE_JW_TRUE@	test "$$files" || for f in $$files; do \
+@HAVE_JW_TRUE@	test "$$files" && for f in $$files; do \
 @HAVE_JW_TRUE@	  rm -rf $(DESTDIR)$(htmldir)/$$f; \
 @HAVE_JW_TRUE@	done
 @HAVE_JW_TRUE@	if test -d $(DESTDIR)$(htmldir); then rmdir $(DESTDIR)$(htmldir); fi
diff -aur esound-0.2.36/esd.c esound-0.2.36-separate_devices/esd.c
--- esound-0.2.36/esd.c	2005-05-26 03:02:52.000000000 +0200
+++ esound-0.2.36-separate_devices/esd.c	2007-06-30 13:29:50.000000000 +0200
@@ -35,6 +35,13 @@
 /* max arguments (argc + tokenized esd.conf) can't be more than this */
 #define MAX_OPTS 128
 
+#if defined (__APPLE__)
+#include <mach/mach.h>
+#include <mach/thread_policy.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
 typedef const char *(*audio_devices_t)(void);
 typedef int (*audio_open_t)(void);
 typedef void (*audio_close_t)(void);
@@ -641,6 +648,29 @@
     int default_format = ESD_BITS16 | ESD_STEREO;
     /* end test scaffolding parameters */
 
+#if defined (__APPLE__)
+    /* get realtime priority */
+    {
+	struct thread_time_constraint_policy ttcpolicy;
+	int bus_speed, mib [2] = { CTL_HW, HW_BUS_FREQ };
+	size_t len;   
+
+	len = sizeof (bus_speed);
+	sysctl (mib, 2, &bus_speed, &len, NULL, 0);
+
+	/* Is it enough? */
+	ttcpolicy.period = bus_speed / 120;
+	ttcpolicy.computation = bus_speed / 2400;
+	ttcpolicy.constraint = bus_speed / 1200;
+	ttcpolicy.preemptible = 1;
+
+	thread_policy_set (mach_thread_self (),
+			   THREAD_TIME_CONSTRAINT_POLICY,
+			   (int*)&ttcpolicy,
+			   THREAD_TIME_CONSTRAINT_POLICY_COUNT);
+    }
+#endif
+
     programname = *argv;
 
 #ifdef DRIVER_ARTS
@@ -689,17 +719,27 @@
     }
        
     /* parse all args */
+    esd_port = ESD_DEFAULT_PORT;
     for ( arg = 0 ; arg < num_opts ; arg++ ) {
-	if ( !strcmp( opts[ arg ], "-d" ) ) {
+	if ( !strcmp( opts[ arg ], "-di" ) ) {
 	    if ( ++arg != num_opts ) {
-		esd_audio_device = opts[ arg ];
-		if ( !esd_audio_device ) {
-		    esd_port = ESD_DEFAULT_PORT;
-		    fprintf( stderr, "- could not read device: %s\n",
+		esd_audio_in_device = opts[ arg ];
+		if ( !esd_audio_in_device ) {
+		    fprintf( stderr, "- could not read input device: %s\n",
+			     opts[ arg ] );
+		}
+		fprintf( stderr, "- using input device %s\n",
+			 esd_audio_in_device );
+	    }
+	} else if ( !strcmp( opts[ arg ], "-do" ) ) {
+	    if ( ++arg != num_opts ) {
+		esd_audio_out_device = opts[ arg ];
+		if ( !esd_audio_out_device ) {
+		    fprintf( stderr, "- could not read output device: %s\n",
 			     opts[ arg ] );
 		}
-		fprintf( stderr, "- using device %s\n",
-			 esd_audio_device );
+		fprintf( stderr, "- using output device %s\n",
+			 esd_audio_out_device );
 	    }
 	} else if ( !strcmp( opts[ arg ], "-port" ) ) {
 	    if ( ++arg != num_opts ) {
@@ -788,7 +828,8 @@
 	    fprintf( stderr, "Esound version " VERSION "\n\n");
 	    fprintf( stderr, "Usage: esd [options]\n\n" );
             fprintf( stderr, "  -v --version  print version information\n" );
-	    fprintf( stderr, "  -d DEVICE     force esd to use sound device DEVICE\n" );
+	    fprintf( stderr, "  -di DEVICE     force esd to use input sound device DEVICE\n" );
+	    fprintf( stderr, "  -do DEVICE     force esd to use output sound device DEVICE\n" );
 	    fprintf( stderr, "  -b            run server in 8 bit sound mode\n" );
 	    fprintf( stderr, "  -r RATE       run server at sample rate of RATE\n" );
 	    fprintf( stderr, "  -as SECS      free audio device after SECS of inactivity (-1 to disable)\n" );
diff -aur esound-0.2.36/esd.conf esound-0.2.36-separate_devices/esd.conf
--- esound-0.2.36/esd.conf	2004-08-18 21:01:41.000000000 +0200
+++ esound-0.2.36-separate_devices/esd.conf	2007-06-30 11:15:04.000000000 +0200
@@ -1,6 +1,6 @@
 [esd]
 auto_spawn=1
 spawn_options=-terminate -nobeeps -as 2
-spawn_wait_ms=100
+spawn_wait_ms=999
 # default options are used in spawned and non-spawned mode
 default_options=
diff -aur esound-0.2.36/esd.h esound-0.2.36-separate_devices/esd.h
--- esound-0.2.36/esd.h	2004-08-18 21:01:41.000000000 +0200
+++ esound-0.2.36-separate_devices/esd.h	2007-06-30 11:51:48.000000000 +0200
@@ -314,7 +314,8 @@
 /* audio.c - abstract the sound hardware for cross platform usage */
 extern esd_format_t esd_audio_format;
 extern int esd_audio_rate;
-extern char *esd_audio_device;
+extern char *esd_audio_in_device;
+extern char *esd_audio_out_device;
 
 const char *esd_audio_devices( void );
 int esd_audio_open( void );
diff -aur esound-0.2.36/esd_config.c esound-0.2.36-separate_devices/esd_config.c
--- esound-0.2.36/esd_config.c	2005-05-26 01:50:41.000000000 +0200
+++ esound-0.2.36-separate_devices/esd_config.c	2007-06-30 11:15:04.000000000 +0200
@@ -9,7 +9,7 @@
 int esd_no_spawn=1; /* If we can't even find the system config file,
 		       things are screwed up - don't try to make things
 		       worse. */
-int esd_spawn_wait_ms=100; /* Time to wait trying to connect to an
+int esd_spawn_wait_ms=999; /* Time to wait trying to connect to an
 			      autospawned ESD, in milliseconds. */
 char esd_spawn_options[LINEBUF_SIZE] = "-terminate -nobeeps -as 2";
 
diff -aur esound-0.2.36/esddsp esound-0.2.36-separate_devices/esddsp
--- esound-0.2.36/esddsp	2005-06-07 03:04:30.000000000 +0200
+++ esound-0.2.36-separate_devices/esddsp	2007-06-30 11:40:50.000000000 +0200
@@ -103,7 +103,7 @@
 fi
 
 # setup esd to hijack calls made to /dev/dsp
-prefix=/usr/local
+prefix=/sw
 exec_prefix=${prefix}
 
 LD_PRELOAD="${exec_prefix}/lib/libesddsp.so.0 ${exec_prefix}/lib/libesd.so.0 $LD_PRELOAD"
