Esound support

Peter Åstrand astrand at cendio.se
Mon Aug 1 09:29:54 CDT 2005


Hi. This patch implements Esound sound support. See 
http://bugs.winehq.com/show_bug.cgi?id=326 for details. Can it be applied?

Index: ChangeLog
===================================================================
RCS file: /home/wine/wine/ChangeLog,v
retrieving revision 1.96
diff -u -r1.96 ChangeLog
--- ChangeLog	25 Jul 2005 12:22:04 -0000	1.96
+++ ChangeLog	1 Aug 2005 13:02:04 -0000
@@ -1,4 +1,8 @@
-----------------------------------------------------------------
+2005-08-01 Peter Astrand <astrand at cendio.se>
+	* configure.ac, dlls/Makefile.in, include/config.h.in, programs/winecfg/audio.c, 
+	programs/winecfg/properties.c: Implemented EsounD sound support (#326). 
+
+	----------------------------------------------------------------
  2005-07-25  Alexandre Julliard  <julliard at winehq.com>

  	* dlls/comctl32/updown.c: Frank Richter <frank.richter at gmail.com>
Index: configure.ac
===================================================================
RCS file: /home/wine/wine/configure.ac,v
retrieving revision 1.383
diff -u -r1.383 configure.ac
--- configure.ac	29 Jul 2005 14:18:58 -0000	1.383
+++ configure.ac	1 Aug 2005 13:02:05 -0000
@@ -712,6 +712,27 @@
      CFLAGS="$save_CFLAGS"
  fi

+dnl **** Check for EsounD ****
+AC_PATH_PROG(ESDCONFIG, esd-config)
+if test x$ESDCONFIG != x -a x$ESDCONFIG != x'"$ESDCONFIG"';
+then
+    ESD_CFLAGS=""
+    for i in `$ESDCONFIG --cflags`
+    do
+      case "$i" in
+        -I*) ESD_CFLAGS="$ESD_CFLAGS $i";;
+      esac
+    done
+    ESD_LIBS=`$ESDCONFIG --libs`
+    save_CFLAGS="$CFLAGS"
+    CFLAGS="$CFLAGS $ESD_CFLAGS"
+    AC_CHECK_LIB(esd,esd_open_sound,
+        [AC_SUBST(ESDLIBS, $ESD_LIBS)
+         AC_SUBST(ESDINCL, $ESD_CFLAGS)
+         AC_DEFINE(HAVE_ESD, 1, [Define if you have EsounD sound server])])
+    CFLAGS="$save_CFLAGS"
+fi
+
  dnl **** Check for ALSA 1.x ****
  AC_SUBST(ALSALIBS,"")
  AC_CHECK_HEADERS(alsa/asoundlib.h sys/asoundlib.h, break)
@@ -1738,6 +1759,7 @@
  dlls/winmm/winealsa/Makefile
  dlls/winmm/winearts/Makefile
  dlls/winmm/wineaudioio/Makefile
+dlls/winmm/wineesd/Makefile
  dlls/winmm/winejack/Makefile
  dlls/winmm/winenas/Makefile
  dlls/winmm/wineoss/Makefile
@@ -1833,11 +1855,11 @@

  if test -z "$ALSALIBS" -a -z "$ARTSC_LIBS" -a -z "$AUDIOIOLIBS" -a \
          -z "$ac_cv_lib_soname_jack" -a -z "$NASLIBS" -a \
-        "$ac_cv_c_opensoundsystem" = "no"
+        "$ac_cv_c_opensoundsystem" = "no" -a -z "$ESD_LIBS"
  then
      echo "*** No sound system was found. Windows applications will be silent."
      echo "*** The currently supported sound systems are:"
-    echo "*** ALSA, ARTS, AudioIO, Jack, NAS and OSS"
+    echo "*** ALSA, ARTS, EsounD, AudioIO, Jack, NAS and OSS"
  fi

  echo
Index: dlls/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/Makefile.in,v
retrieving revision 1.252
diff -u -r1.252 Makefile.in
--- dlls/Makefile.in	27 Jul 2005 15:42:41 -0000	1.252
+++ dlls/Makefile.in	1 Aug 2005 13:02:07 -0000
@@ -163,6 +163,7 @@
  	winmm/winealsa \
  	winmm/winearts \
  	winmm/wineaudioio \
+	winmm/wineesd \
  	winmm/winejack \
  	winmm/winenas \
  	winmm/wineoss \
@@ -401,6 +402,7 @@
  	winearts.drv.so \
  	wineaudioio.drv.so \
  	winedos.dll.so \
+	wineesd.drv.so \
  	winejack.drv.so \
  	winemp3.acm.so \
  	winenas.drv.so \
@@ -951,6 +953,9 @@
  wprocs.dll.so : winedos.dll.so
  	$(RM) $@ && $(LN_S) winedos.dll.so $@

+wineesd.drv.so: winmm/wineesd/wineesd.drv.so
+	$(RM) $@ && $(LN_S) winmm/wineesd/wineesd.drv.so $@
+
  winejack.drv.so: winmm/winejack/winejack.drv.so
  	$(RM) $@ && $(LN_S) winmm/winejack/winejack.drv.so $@

@@ -1752,6 +1757,7 @@
  winmm/wineaudioio/wineaudioio.drv.so: winmm/wineaudioio
  wined3d/wined3d.dll.so: wined3d
  winedos/winedos.dll.so: winedos
+winmm/wineesd/wineesd.drv.so: winmm/wineesd
  winmm/winejack/winejack.drv.so: winmm/winejack
  msacm/winemp3/winemp3.acm.so: msacm/winemp3
  winmm/winenas/winenas.drv.so: winmm/winenas
Index: include/config.h.in
===================================================================
RCS file: /home/wine/wine/include/config.h.in,v
retrieving revision 1.225
diff -u -r1.225 config.h.in
--- include/config.h.in	29 Jul 2005 14:18:58 -0000	1.225
+++ include/config.h.in	1 Aug 2005 13:02:11 -0000
@@ -86,6 +86,9 @@
  /* Define to 1 if you have the `epoll_create' function. */
  #undef HAVE_EPOLL_CREATE

+/* Define if you have EsounD sound server */
+#undef HAVE_ESD
+
  /* Define to 1 if you have the `ffs' function. */
  #undef HAVE_FFS

Index: programs/winecfg/audio.c
===================================================================
RCS file: /home/wine/wine/programs/winecfg/audio.c,v
retrieving revision 1.13
diff -u -r1.13 audio.c
--- programs/winecfg/audio.c	11 Jul 2005 10:24:28 -0000	1.13
+++ programs/winecfg/audio.c	1 Aug 2005 13:02:13 -0000
@@ -201,6 +201,15 @@
      numFound++;
    }

+  /* try to detect EsounD */
+  argv_new[2] = "ps awx|grep esd|grep -v grep|grep esd > /dev/null";
+  if(!spawnvp(_P_WAIT, "/bin/sh", argv_new))
+  {
+    driversFound[numFound] = "esd";
+    name[numFound] = "EsounD";
+    numFound++;
+  }
+
    /* try to detect jack */
    argv_new[2] = "ps awx|grep jackd|grep -v grep|grep jackd > /dev/null";
    if(!spawnvp(_P_WAIT, "/bin/sh", argv_new))
Index: programs/winecfg/properties.c
===================================================================
RCS file: /home/wine/wine/programs/winecfg/properties.c,v
retrieving revision 1.12
diff -u -r1.12 properties.c
--- programs/winecfg/properties.c	27 Jun 2005 09:48:06 -0000	1.12
+++ programs/winecfg/properties.c	1 Aug 2005 13:02:13 -0000
@@ -60,6 +60,7 @@
  static const AUDIO_DRIVER sAudioDrivers[] = {
    {"ALSA", "alsa"},
    {"aRts", "arts"},
+  {"EsounD", "esd"},
    {"OSS", "oss"},
    {"JACK", "jack"},
    {"NAS", "nas"},
--- /dev/null	2005-07-31 20:23:43.921776544 +0200
+++ dlls/winmm/wineesd/.cvsignore	2005-07-10 23:26:44.000000000 +0200
@@ -0,0 +1,2 @@
+Makefile
+wineesd.drv.dbg.c
--- /dev/null	2005-07-31 20:23:43.921776544 +0200
+++ dlls/winmm/wineesd/Makefile.in	2005-07-10 23:26:44.000000000 +0200
@@ -0,0 +1,16 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+MODULE    = wineesd.drv
+IMPORTS   = winmm user32 kernel32
+EXTRAINCL = @ESDINCL@
+EXTRALIBS = @ESDLIBS@ -ldxguid -luuid
+
+C_SRCS = \
+	esound.c \
+	audio.c
+
+ at MAKE_DLL_RULES@
+
+### Dependencies:
--- /dev/null	2005-07-31 20:23:43.921776544 +0200
+++ dlls/winmm/wineesd/audio.c	2005-07-11 01:11:33.000000000 +0200
@@ -0,0 +1,2145 @@
+/* -*- tab-width: 8; c-basic-offset: 4 -*- */
+/*
+ * Wine Driver for EsounD Sound Server
+ * http://www.tux.org/~ricdude/EsounD.html
+ *
+ * Copyright 1994 Martin Ayotte
+ *           1999 Eric Pouech (async playing in waveOut/waveIn)
+ *	     2000 Eric Pouech (loops in waveOut)
+ *	     2004 Zhangrong Huang (EsounD version of this file)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* NOTE:
+ *    with esd we cannot stop the audio that is already in
+ *    the servers buffer.
+ *
+ * FIXME:
+ *	pause in waveOut does not work correctly in loop mode
+ *
+ *	does something need to be done in for WaveIn DirectSound?
+ *
+ */
+
+/*#define EMULATE_SB16*/
+
+#include "config.h"
+
+#include <math.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#include <fcntl.h>
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winerror.h"
+#include "wine/winuser16.h"
+#include "mmddk.h"
+#include "dsound.h"
+#include "dsdriver.h"
+#include "esound.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(wave);
+
+#ifdef HAVE_ESD
+
+#include <esd.h>
+
+/* define if you want to use esd_monitor_stream instead of
+ * esd_record_stream for waveIn stream
+ */
+/*#define WID_USE_ESDMON*/
+
+#define BUFFER_REFILL_THRESHOLD 4
+
+#define MAX_WAVEOUTDRV 	(10)
+#define MAX_WAVEINDRV 	(10)
+
+/* state diagram for waveOut writing:
+ *
+ * +---------+-------------+---------------+---------------------------------+
+ * |  state  |  function   |     event     |            new state	     |
+ * +---------+-------------+---------------+---------------------------------+
+ * |	     | open()	   |		   | STOPPED		       	     |
+ * | PAUSED  | write()	   | 		   | PAUSED		       	     |
+ * | STOPPED | write()	   | <thrd create> | PLAYING		  	     |
+ * | PLAYING | write()	   | HEADER        | PLAYING		  	     |
+ * | (other) | write()	   | <error>       |		       		     |
+ * | (any)   | pause()	   | PAUSING	   | PAUSED		       	     |
+ * | PAUSED  | restart()   | RESTARTING    | PLAYING (if no thrd => STOPPED) |
+ * | (any)   | reset()	   | RESETTING     | STOPPED		      	     |
+ * | (any)   | close()	   | CLOSING	   | CLOSED		      	     |
+ * +---------+-------------+---------------+---------------------------------+
+ */
+
+/* states of the playing device */
+#define	WINE_WS_PLAYING		0
+#define	WINE_WS_PAUSED		1
+#define	WINE_WS_STOPPED		2
+#define WINE_WS_CLOSED		3
+
+/* events to be send to device */
+enum win_wm_message {
+    WINE_WM_PAUSING = WM_USER + 1, WINE_WM_RESTARTING, WINE_WM_RESETTING, WINE_WM_HEADER,
+    WINE_WM_UPDATE, WINE_WM_BREAKLOOP, WINE_WM_CLOSING, WINE_WM_STARTING, WINE_WM_STOPPING
+};
+
+typedef struct {
+    enum win_wm_message 	msg;	/* message identifier */
+    DWORD	                param;  /* parameter for this message */
+    HANDLE	                hEvent;	/* if message is synchronous, handle of event for synchro */
+} RING_MSG;
+
+/* implement an in-process message ring for better performance
+ * (compared to passing thru the server)
+ * this ring will be used by the input (resp output) record (resp playback) routine
+ */
+#define ESD_RING_BUFFER_INCREMENT      64
+typedef struct {
+    RING_MSG			* messages;
+    int                         ring_buffer_size;
+    int				msg_tosave;
+    int				msg_toget;
+    HANDLE			msg_event;
+    CRITICAL_SECTION		msg_crst;
+} ESD_MSG_RING;
+
+typedef struct {
+    volatile int		state;			/* one of the WINE_WS_ manifest constants */
+    WAVEOPENDESC		waveDesc;
+    WORD			wFlags;
+    PCMWAVEFORMAT		format;
+    WAVEOUTCAPSA		caps;
+    char                        interface_name[32];
+
+    DWORD			dwSleepTime;		/* Num of milliseconds to sleep between filling the dsp buffers */
+
+    /* esd information */
+    int				esd_fd;		/* the socket fd we get from esd when opening a stream for playing */
+    int				bytes_per_frame;
+    DWORD                       dwBufferSize;           /* size of whole buffer in bytes */
+
+    char*			sound_buffer;
+    long			buffer_size;
+
+    DWORD			volume_left;		/* volume control information */
+    DWORD			volume_right;
+
+    LPWAVEHDR			lpQueuePtr;		/* start of queued WAVEHDRs (waiting to be notified) */
+    LPWAVEHDR			lpPlayPtr;		/* start of not yet fully played buffers */
+    DWORD			dwPartialOffset;	/* Offset of not yet written bytes in lpPlayPtr */
+
+    LPWAVEHDR			lpLoopPtr;              /* pointer of first buffer in loop, if any */
+    DWORD			dwLoops;		/* private copy of loop counter */
+
+    DWORD			dwPlayedTotal;		/* number of bytes actually played since opening */
+    DWORD                       dwWrittenTotal;         /* number of bytes written to the audio device since opening */
+
+    /* synchronization stuff */
+    HANDLE			hStartUpEvent;
+    HANDLE			hThread;
+    DWORD			dwThreadID;
+    ESD_MSG_RING		msgRing;
+} WINE_WAVEOUT;
+
+typedef struct {
+    volatile int		state;			/* one of the WINE_WS_ manifest constants */
+    WAVEOPENDESC		waveDesc;
+    WORD			wFlags;
+    PCMWAVEFORMAT		format;
+    WAVEINCAPSA			caps;
+    char                        interface_name[32];
+
+    /* esd information */
+    int				esd_fd;		/* the socket fd we get from esd when opening a stream for recording */
+    int				bytes_per_frame;
+
+    LPWAVEHDR			lpQueuePtr;
+    DWORD			dwRecordedTotal;
+
+    /* synchronization stuff */
+    HANDLE			hStartUpEvent;
+    HANDLE			hThread;
+    DWORD			dwThreadID;
+    ESD_MSG_RING		msgRing;
+} WINE_WAVEIN;
+
+static char* esd_host;	/* the esd host */
+
+static WINE_WAVEOUT	WOutDev   [MAX_WAVEOUTDRV];
+static WINE_WAVEIN	WInDev    [MAX_WAVEINDRV];
+
+static DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv);
+static DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc);
+
+/* These strings used only for tracing */
+static const char *wodPlayerCmdString[] = {
+    "WINE_WM_PAUSING",
+    "WINE_WM_RESTARTING",
+    "WINE_WM_RESETTING",
+    "WINE_WM_HEADER",
+    "WINE_WM_UPDATE",
+    "WINE_WM_BREAKLOOP",
+    "WINE_WM_CLOSING",
+    "WINE_WM_STARTING",
+    "WINE_WM_STOPPING",
+};
+
+/*======================================================================*
+ *                  Low level WAVE implementation			*
+ *======================================================================*/
+
+/* Volume functions derived from Alsaplayer source */
+/* length is the number of 16 bit samples */
+void volume_effect16(void *bufin, void* bufout, int length, int left,
+		int right, int 	nChannels)
+{
+  short *d_out = (short *)bufout;
+  short *d_in = (short *)bufin;
+  int i, v;
+
+/*
+  TRACE("length == %d, nChannels == %d\n", length, nChannels);
+*/
+
+  if (right == -1) right = left;
+
+  for(i = 0; i < length; i+=(nChannels))
+  {
+    v = (int) ((*(d_in++) * left) / 100);
+    *(d_out++) = (v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
+    if(nChannels == 2)
+    {
+      v = (int) ((*(d_in++) * right) / 100);
+      *(d_out++) = (v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
+    }
+  }
+}
+
+/* length is the number of 8 bit samples */
+void volume_effect8(void *bufin, void* bufout, int length, int left,
+		int right, int 	nChannels)
+{
+  BYTE *d_out = (BYTE *)bufout;
+  BYTE *d_in = (BYTE *)bufin;
+  int i, v;
+
+/*
+  TRACE("length == %d, nChannels == %d\n", length, nChannels);
+*/
+
+  if (right == -1) right = left;
+
+  for(i = 0; i < length; i+=(nChannels))
+  {
+    v = (BYTE) ((*(d_in++) * left) / 100);
+    *(d_out++) = (v>255) ? 255 : ((v<0) ? 0 : v);
+    if(nChannels == 2)
+    {
+      v = (BYTE) ((*(d_in++) * right) / 100);
+      *(d_out++) = (v>255) ? 255 : ((v<0) ? 0 : v);
+    }
+  }
+}
+
+/******************************************************************
+ *		ESD_CloseWaveOutDevice
+ *
+ */
+void		ESD_CloseWaveOutDevice(WINE_WAVEOUT* wwo)
+{
+	esd_close(wwo->esd_fd); 	/* close the esd socket fd */
+	wwo->esd_fd = -1;
+
+  /* free up the buffer we use for volume and reset the size */
+  if(wwo->sound_buffer)
+  {
+    HeapFree(GetProcessHeap(), 0, wwo->sound_buffer);
+    wwo->sound_buffer = NULL;
+  }
+
+  wwo->buffer_size = 0;
+}
+
+/******************************************************************
+ *		ESD_CloseWaveInDevice
+ *
+ */
+void		ESD_CloseWaveInDevice(WINE_WAVEIN* wwi)
+{
+	esd_close(wwi->esd_fd); 	/* close the esd socket fd */
+	wwi->esd_fd = -1;
+}
+
+/******************************************************************
+ *		ESD_WaveClose
+ */
+LONG		ESD_WaveClose(void)
+{
+    int iDevice;
+
+    /* close all open devices */
+    for(iDevice = 0; iDevice < MAX_WAVEOUTDRV; iDevice++)
+    {
+      if(WOutDev[iDevice].esd_fd != -1)
+      {
+        ESD_CloseWaveOutDevice(&WOutDev[iDevice]);
+      }
+    }
+
+    for(iDevice = 0; iDevice < MAX_WAVEINDRV; iDevice++)
+    {
+      if(WInDev[iDevice].esd_fd != -1)
+      {
+        ESD_CloseWaveInDevice(&WInDev[iDevice]);
+      }
+    }
+
+    return 1;
+}
+
+/******************************************************************
+ *		ESD_WaveInit
+ *
+ * Initialize internal structures from ESD server info
+ */
+LONG ESD_WaveInit(void)
+{
+    int 	i;
+	int 	fd;
+
+    TRACE("called\n");
+
+    /* FIXME: Maybe usefully to set the esd host. */
+    esd_host = NULL;
+
+    /* Testing whether the esd host is alive. */
+    if ((fd = esd_open_sound(esd_host)) < 0)
+    {
+	WARN("esd_open_sound() failed (%d)\n", errno);
+	return -1;
+    }
+    esd_close(fd);
+
+    /* initialize all device handles to -1 */
+    for (i = 0; i < MAX_WAVEOUTDRV; ++i)
+    {
+	WOutDev[i].esd_fd = -1;
+	memset(&WOutDev[i].caps, 0, sizeof(WOutDev[i].caps)); /* zero out
+							caps values */
+    /* FIXME: some programs compare this string against the content of the registry
+     * for MM drivers. The names have to match in order for the program to work
+     * (e.g. MS win9x mplayer.exe)
+     */
+#ifdef EMULATE_SB16
+    	WOutDev[i].caps.wMid = 0x0002;
+    	WOutDev[i].caps.wPid = 0x0104;
+    	strcpy(WOutDev[i].caps.szPname, "SB16 Wave Out");
+#else
+    	WOutDev[i].caps.wMid = 0x00FF; 	/* Manufac ID */
+    	WOutDev[i].caps.wPid = 0x0001; 	/* Product ID */
+    /*    strcpy(WOutDev[i].caps.szPname, "OpenSoundSystem WAVOUT Driver");*/
+    	strcpy(WOutDev[i].caps.szPname, "CS4236/37/38");
+#endif
+        snprintf(WOutDev[i].interface_name, sizeof(WOutDev[i].interface_name), "wineesd: %d", i);
+
+    	WOutDev[i].caps.vDriverVersion = 0x0100;
+    	WOutDev[i].caps.dwFormats = 0x00000000;
+    	WOutDev[i].caps.dwSupport = WAVECAPS_VOLUME;
+
+    	WOutDev[i].caps.wChannels = 2;
+    	WOutDev[i].caps.dwSupport |= WAVECAPS_LRVOLUME;
+
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_4M08;
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_4S08;
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_4S16;
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_4M16;
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_2M08;
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_2S08;
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_2M16;
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_2S16;
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_1M08;
+    	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_1S08;
+	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_1M16;
+	WOutDev[i].caps.dwFormats |= WAVE_FORMAT_1S16;
+    }
+
+    for (i = 0; i < MAX_WAVEINDRV; ++i)
+    {
+	WInDev[i].esd_fd = -1;
+	memset(&WInDev[i].caps, 0, sizeof(WInDev[i].caps)); /* zero out
+							caps values */
+    /* FIXME: some programs compare this string against the content of the registry
+     * for MM drivers. The names have to match in order for the program to work
+     * (e.g. MS win9x mplayer.exe)
+     */
+#ifdef EMULATE_SB16
+    	WInDev[i].caps.wMid = 0x0002;
+    	WInDev[i].caps.wPid = 0x0104;
+    	strcpy(WInDev[i].caps.szPname, "SB16 Wave In");
+#else
+	WInDev[i].caps.wMid = 0x00FF;
+	WInDev[i].caps.wPid = 0x0001;
+	strcpy(WInDev[i].caps.szPname,"CS4236/37/38");
+#endif
+        snprintf(WInDev[i].interface_name, sizeof(WInDev[i].interface_name), "wineesd: %d", i);
+
+	WInDev[i].caps.vDriverVersion = 0x0100;
+   	WInDev[i].caps.dwFormats = 0x00000000;
+
+    	WInDev[i].caps.wChannels = 2;
+
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_4M08;
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_4S08;
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_4S16;
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_4M16;
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_2M08;
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_2S08;
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_2M16;
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_2S16;
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_1M08;
+    	WInDev[i].caps.dwFormats |= WAVE_FORMAT_1S08;
+	WInDev[i].caps.dwFormats |= WAVE_FORMAT_1M16;
+	WInDev[i].caps.dwFormats |= WAVE_FORMAT_1S16;
+
+	WInDev[i].caps.wReserved1 = 0;
+    }
+    return 0;
+}
+
+/******************************************************************
+ *		ESD_InitRingMessage
+ *
+ * Initialize the ring of messages for passing between driver's caller and playback/record
+ * thread
+ */
+static int ESD_InitRingMessage(ESD_MSG_RING* mr)
+{
+    mr->msg_toget = 0;
+    mr->msg_tosave = 0;
+    mr->msg_event = CreateEventA(NULL, FALSE, FALSE, NULL);
+    mr->ring_buffer_size = ESD_RING_BUFFER_INCREMENT;
+    mr->messages = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,mr->ring_buffer_size * sizeof(RING_MSG));
+    InitializeCriticalSection(&mr->msg_crst);
+    return 0;
+}
+
+/******************************************************************
+ *		ESD_DestroyRingMessage
+ *
+ */
+static int ESD_DestroyRingMessage(ESD_MSG_RING* mr)
+{
+    CloseHandle(mr->msg_event);
+    HeapFree(GetProcessHeap(),0,mr->messages);
+    mr->messages=NULL;
+    DeleteCriticalSection(&mr->msg_crst);
+    return 0;
+}
+
+/******************************************************************
+ *		ESD_AddRingMessage
+ *
+ * Inserts a new message into the ring (should be called from DriverProc derivated routines)
+ */
+static int ESD_AddRingMessage(ESD_MSG_RING* mr, enum win_wm_message msg, DWORD param, BOOL wait)
+{
+    HANDLE      hEvent = INVALID_HANDLE_VALUE;
+
+    EnterCriticalSection(&mr->msg_crst);
+    if ((mr->msg_toget == ((mr->msg_tosave + 1) % mr->ring_buffer_size)))
+    {
+	int old_ring_buffer_size = mr->ring_buffer_size;
+	mr->ring_buffer_size += ESD_RING_BUFFER_INCREMENT;
+	TRACE("mr->ring_buffer_size=%d\n",mr->ring_buffer_size);
+	mr->messages = HeapReAlloc(GetProcessHeap(),0,mr->messages, mr->ring_buffer_size * sizeof(RING_MSG));
+	/* Now we need to rearrange the ring buffer so that the new
+	   buffers just allocated are in between mr->msg_tosave and
+	   mr->msg_toget.
+	*/
+	if (mr->msg_tosave < mr->msg_toget)
+	{
+	    memmove(&(mr->messages[mr->msg_toget + ESD_RING_BUFFER_INCREMENT]),
+		    &(mr->messages[mr->msg_toget]),
+		    sizeof(RING_MSG)*(old_ring_buffer_size - mr->msg_toget)
+		    );
+	    mr->msg_toget += ESD_RING_BUFFER_INCREMENT;
+	}
+    }
+    if (wait)
+    {
+        hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
+        if (hEvent == INVALID_HANDLE_VALUE)
+        {
+            ERR("can't create event !?\n");
+            LeaveCriticalSection(&mr->msg_crst);
+            return 0;
+        }
+        if (mr->msg_toget != mr->msg_tosave && mr->messages[mr->msg_toget].msg != WINE_WM_HEADER)
+            FIXME("two fast messages in the queue!!!!\n");
+
+        /* fast messages have to be added at the start of the queue */
+        mr->msg_toget = (mr->msg_toget + mr->ring_buffer_size - 1) % mr->ring_buffer_size;
+
+        mr->messages[mr->msg_toget].msg = msg;
+        mr->messages[mr->msg_toget].param = param;
+        mr->messages[mr->msg_toget].hEvent = hEvent;
+    }
+    else
+    {
+        mr->messages[mr->msg_tosave].msg = msg;
+        mr->messages[mr->msg_tosave].param = param;
+        mr->messages[mr->msg_tosave].hEvent = INVALID_HANDLE_VALUE;
+        mr->msg_tosave = (mr->msg_tosave + 1) % mr->ring_buffer_size;
+    }
+
+    LeaveCriticalSection(&mr->msg_crst);
+
+    SetEvent(mr->msg_event);    /* signal a new message */
+
+    if (wait)
+    {
+        /* wait for playback/record thread to have processed the message */
+        WaitForSingleObject(hEvent, INFINITE);
+        CloseHandle(hEvent);
+    }
+
+    return 1;
+}
+
+/******************************************************************
+ *		ESD_RetrieveRingMessage
+ *
+ * Get a message from the ring. Should be called by the playback/record thread.
+ */
+static int ESD_RetrieveRingMessage(ESD_MSG_RING* mr,
+                                   enum win_wm_message *msg, DWORD *param, HANDLE *hEvent)
+{
+    EnterCriticalSection(&mr->msg_crst);
+
+    if (mr->msg_toget == mr->msg_tosave) /* buffer empty ? */
+    {
+        LeaveCriticalSection(&mr->msg_crst);
+	return 0;
+    }
+
+    *msg = mr->messages[mr->msg_toget].msg;
+    mr->messages[mr->msg_toget].msg = 0;
+    *param = mr->messages[mr->msg_toget].param;
+    *hEvent = mr->messages[mr->msg_toget].hEvent;
+    mr->msg_toget = (mr->msg_toget + 1) % mr->ring_buffer_size;
+    LeaveCriticalSection(&mr->msg_crst);
+    return 1;
+}
+
+/*======================================================================*
+ *                  Low level WAVE OUT implementation			*
+ *======================================================================*/
+
+/**************************************************************************
+ * 			wodNotifyClient			[internal]
+ */
+static DWORD wodNotifyClient(WINE_WAVEOUT* wwo, WORD wMsg, DWORD dwParam1, DWORD dwParam2)
+{
+    TRACE("wMsg = 0x%04x dwParm1 = %04lX dwParam2 = %04lX\n", wMsg, dwParam1, dwParam2);
+
+    switch (wMsg) {
+    case WOM_OPEN:
+    case WOM_CLOSE:
+    case WOM_DONE:
+	if (wwo->wFlags != DCB_NULL &&
+	    !DriverCallback(wwo->waveDesc.dwCallback, wwo->wFlags, (HDRVR)wwo->waveDesc.hWave,
+			    wMsg, wwo->waveDesc.dwInstance, dwParam1, dwParam2)) {
+	    WARN("can't notify client !\n");
+	    return MMSYSERR_ERROR;
+	}
+	break;
+    default:
+	FIXME("Unknown callback message %u\n", wMsg);
+        return MMSYSERR_INVALPARAM;
+    }
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				wodUpdatePlayedTotal	[internal]
+ *
+ */
+static BOOL wodUpdatePlayedTotal(WINE_WAVEOUT* wwo)
+{
+    /* total played is the bytes written less the bytes to write ;-) */
+    wwo->dwPlayedTotal = wwo->dwWrittenTotal;
+
+    return TRUE;
+}
+
+/**************************************************************************
+ * 				wodPlayer_BeginWaveHdr          [internal]
+ *
+ * Makes the specified lpWaveHdr the currently playing wave header.
+ * If the specified wave header is a begin loop and we're not already in
+ * a loop, setup the loop.
+ */
+static void wodPlayer_BeginWaveHdr(WINE_WAVEOUT* wwo, LPWAVEHDR lpWaveHdr)
+{
+    wwo->lpPlayPtr = lpWaveHdr;
+
+    if (!lpWaveHdr) return;
+
+    if (lpWaveHdr->dwFlags & WHDR_BEGINLOOP) {
+	if (wwo->lpLoopPtr) {
+	    WARN("Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr);
+	    TRACE("Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr);
+	} else {
+	    TRACE("Starting loop (%ldx) with %p\n", lpWaveHdr->dwLoops, lpWaveHdr);
+	    wwo->lpLoopPtr = lpWaveHdr;
+	    /* Windows does not touch WAVEHDR.dwLoops,
+	     * so we need to make an internal copy */
+	    wwo->dwLoops = lpWaveHdr->dwLoops;
+	}
+    }
+    wwo->dwPartialOffset = 0;
+}
+
+/**************************************************************************
+ * 				wodPlayer_PlayPtrNext	        [internal]
+ *
+ * Advance the play pointer to the next waveheader, looping if required.
+ */
+static LPWAVEHDR wodPlayer_PlayPtrNext(WINE_WAVEOUT* wwo)
+{
+    LPWAVEHDR lpWaveHdr = wwo->lpPlayPtr;
+
+    wwo->dwPartialOffset = 0;
+    if ((lpWaveHdr->dwFlags & WHDR_ENDLOOP) && wwo->lpLoopPtr) {
+	/* We're at the end of a loop, loop if required */
+	if (--wwo->dwLoops > 0) {
+	    wwo->lpPlayPtr = wwo->lpLoopPtr;
+	} else {
+	    /* Handle overlapping loops correctly */
+	    if (wwo->lpLoopPtr != lpWaveHdr && (lpWaveHdr->dwFlags & WHDR_BEGINLOOP)) {
+		FIXME("Correctly handled case ? (ending loop buffer also starts a new loop)\n");
+		/* shall we consider the END flag for the closing loop or for
+		 * the opening one or for both ???
+		 * code assumes for closing loop only
+		 */
+	    } else {
+                lpWaveHdr = lpWaveHdr->lpNext;
+            }
+            wwo->lpLoopPtr = NULL;
+            wodPlayer_BeginWaveHdr(wwo, lpWaveHdr);
+	}
+    } else {
+	/* We're not in a loop.  Advance to the next wave header */
+	wodPlayer_BeginWaveHdr(wwo, lpWaveHdr = lpWaveHdr->lpNext);
+    }
+
+    return lpWaveHdr;
+}
+
+/**************************************************************************
+ * 			     wodPlayer_NotifyWait               [internal]
+ * Returns the number of milliseconds to wait before attempting to notify
+ * completion of the specified wavehdr.
+ * This is based on the number of bytes remaining to be written in the
+ * wave.
+ */
+static DWORD wodPlayer_NotifyWait(const WINE_WAVEOUT* wwo, LPWAVEHDR lpWaveHdr)
+{
+    DWORD dwMillis;
+
+    if(lpWaveHdr->reserved < wwo->dwPlayedTotal)
+    {
+	dwMillis = 1;
+    }
+    else
+    {
+        dwMillis = (lpWaveHdr->reserved - wwo->dwPlayedTotal) * 1000 / wwo->format.wf.nAvgBytesPerSec;
+	if(!dwMillis) dwMillis = 1;
+    }
+
+    TRACE("dwMillis = %ld\n", dwMillis);
+
+    return dwMillis;
+}
+
+
+/**************************************************************************
+ * 			     wodPlayer_WriteMaxFrags            [internal]
+ * Writes the maximum number of bytes possible to the DSP and returns
+ * the number of bytes written.
+ */
+static int wodPlayer_WriteMaxFrags(WINE_WAVEOUT* wwo, DWORD* bytes)
+{
+    /* Only attempt to write to free bytes */
+    DWORD dwLength = wwo->lpPlayPtr->dwBufferLength - wwo->dwPartialOffset;
+    int toWrite = min(dwLength, *bytes);
+    int written;
+
+    TRACE("Writing wavehdr %p.%lu[%lu]\n",
+          wwo->lpPlayPtr, wwo->dwPartialOffset, wwo->lpPlayPtr->dwBufferLength);
+
+    /* see if our buffer isn't large enough for the data we are writing */
+    if(wwo->buffer_size < toWrite)
+    {
+      if(wwo->sound_buffer)
+      {
+	wwo->sound_buffer = HeapReAlloc(GetProcessHeap(), 0, wwo->sound_buffer, toWrite);
+	wwo->buffer_size = toWrite;
+      }
+    }
+
+    /* if we don't have a buffer then get one */
+    if(!wwo->sound_buffer)
+    {
+      /* allocate some memory for the buffer */
+      wwo->sound_buffer = HeapAlloc(GetProcessHeap(), 0, toWrite);
+      wwo->buffer_size = toWrite;
+    }
+
+    /* if we don't have a buffer then error out */
+    if(!wwo->sound_buffer)
+    {
+      ERR("error allocating sound_buffer memory\n");
+      return 0;
+    }
+
+    TRACE("toWrite == %d\n", toWrite);
+
+    /* apply volume to the bits */
+    /* for single channel audio streams we only use the LEFT volume */
+    if(wwo->format.wBitsPerSample == 16)
+    {
+      /* apply volume to the buffer we are about to send */
+      /* divide toWrite(bytes) by 2 as volume processes by 16 bits */
+      volume_effect16(wwo->lpPlayPtr->lpData + wwo->dwPartialOffset,
+                wwo->sound_buffer, toWrite>>1, wwo->volume_left,
+		wwo->volume_right, wwo->format.wf.nChannels);
+    } else if(wwo->format.wBitsPerSample == 8)
+    {
+      /* apply volume to the buffer we are about to send */
+      volume_effect8(wwo->lpPlayPtr->lpData + wwo->dwPartialOffset,
+                wwo->sound_buffer, toWrite, wwo->volume_left,
+		wwo->volume_right, wwo->format.wf.nChannels);
+    } else
+    {
+      FIXME("unsupported wwo->format.wBitsPerSample of %d\n",
+        wwo->format.wBitsPerSample);
+    }
+
+    /* send the audio data to esd for playing */
+    written = write(wwo->esd_fd, wwo->sound_buffer, toWrite);
+
+    TRACE("written = %d\n", written);
+
+    if (written <= 0) 
+    {
+      *bytes = 0; /* apparently esd is actually full */
+      return written; /* if we wrote nothing just return */
+    }
+
+    if (written >= dwLength)
+        wodPlayer_PlayPtrNext(wwo);   /* If we wrote all current wavehdr, skip to the next one */
+    else
+        wwo->dwPartialOffset += written;    /* Remove the amount written */
+
+    if (written < toWrite)
+	*bytes = 0;
+    else
+	*bytes -= written;
+
+    wwo->dwWrittenTotal += written; /* update stats on this wave device */
+
+    return written; /* return the number of bytes written */
+}
+
+
+/**************************************************************************
+ * 				wodPlayer_NotifyCompletions	[internal]
+ *
+ * Notifies and remove from queue all wavehdrs which have been played to
+ * the speaker (ie. they have cleared the audio device).  If force is true,
+ * we notify all wavehdrs and remove them all from the queue even if they
+ * are unplayed or part of a loop.
+ */
+static DWORD wodPlayer_NotifyCompletions(WINE_WAVEOUT* wwo, BOOL force)
+{
+    LPWAVEHDR		lpWaveHdr;
+
+    if (wwo->lpQueuePtr) {
+	TRACE("lpWaveHdr=(%p), lpPlayPtr=(%p), lpLoopPtr=(%p), reserved=(%ld), dwWrittenTotal=(%ld), force=(%d)\n", 
+	      wwo->lpQueuePtr,
+	      wwo->lpPlayPtr,
+	      wwo->lpLoopPtr,
+	      wwo->lpQueuePtr->reserved,
+	      wwo->dwWrittenTotal,
+	      force);
+    } else {
+	TRACE("lpWaveHdr=(%p), lpPlayPtr=(%p), lpLoopPtr=(%p),  dwWrittenTotal=(%ld), force=(%d)\n", 
+	      wwo->lpQueuePtr,
+	      wwo->lpPlayPtr,
+	      wwo->lpLoopPtr,
+	      wwo->dwWrittenTotal,
+	      force);
+    }
+
+    /* Start from lpQueuePtr and keep notifying until:
+     * - we hit an unwritten wavehdr
+     * - we hit the beginning of a running loop
+     * - we hit a wavehdr which hasn't finished playing
+     */
+    while ((lpWaveHdr = wwo->lpQueuePtr) &&
+           (force ||
+            (lpWaveHdr != wwo->lpPlayPtr &&
+             lpWaveHdr != wwo->lpLoopPtr &&
+	     lpWaveHdr->reserved <= wwo->dwWrittenTotal))) {
+
+	wwo->lpQueuePtr = lpWaveHdr->lpNext;
+
+	lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
+	lpWaveHdr->dwFlags |= WHDR_DONE;
+
+	wodNotifyClient(wwo, WOM_DONE, (DWORD)lpWaveHdr, 0);
+    }
+    return  (lpWaveHdr && lpWaveHdr != wwo->lpPlayPtr && lpWaveHdr != wwo->lpLoopPtr) ?
+        wodPlayer_NotifyWait(wwo, lpWaveHdr) : INFINITE;
+}
+
+/**************************************************************************
+ * 				wodPlayer_Reset			[internal]
+ *
+ * wodPlayer helper. Resets current output stream.
+ */
+static	void	wodPlayer_Reset(WINE_WAVEOUT* wwo, BOOL reset)
+{
+    wodUpdatePlayedTotal(wwo);
+
+    wodPlayer_NotifyCompletions(wwo, FALSE); /* updates current notify list */
+
+    /* we aren't able to flush any data that has already been written */
+    /* to esd, otherwise we would do the flushing here */
+
+    if (reset) {
+        enum win_wm_message     msg;
+        DWORD                   param;
+        HANDLE                  ev;
+
+	/* remove any buffer */
+	wodPlayer_NotifyCompletions(wwo, TRUE);
+
+	wwo->lpPlayPtr = wwo->lpQueuePtr = wwo->lpLoopPtr = NULL;
+	wwo->state = WINE_WS_STOPPED;
+	wwo->dwPlayedTotal = wwo->dwWrittenTotal = 0;
+
+        wwo->dwPartialOffset = 0;        /* Clear partial wavehdr */
+
+        /* remove any existing message in the ring */
+        EnterCriticalSection(&wwo->msgRing.msg_crst);
+
+        /* return all pending headers in queue */
+        while (ESD_RetrieveRingMessage(&wwo->msgRing, &msg, &param, &ev))
+        {
+	    TRACE("flushing msg\n");
+            if (msg != WINE_WM_HEADER)
+            {
+                FIXME("shouldn't have headers left\n");
+                SetEvent(ev);
+                continue;
+            }
+            ((LPWAVEHDR)param)->dwFlags &= ~WHDR_INQUEUE;
+            ((LPWAVEHDR)param)->dwFlags |= WHDR_DONE;
+
+            wodNotifyClient(wwo, WOM_DONE, param, 0);
+        }
+        ResetEvent(wwo->msgRing.msg_event);
+        LeaveCriticalSection(&wwo->msgRing.msg_crst);
+    } else {
+        if (wwo->lpLoopPtr) {
+            /* complicated case, not handled yet (could imply modifying the loop counter */
+            FIXME("Pausing while in loop isn't correctly handled yet, except strange results\n");
+            wwo->lpPlayPtr = wwo->lpLoopPtr;
+            wwo->dwPartialOffset = 0;
+            wwo->dwWrittenTotal = wwo->dwPlayedTotal; /* this is wrong !!! */
+        } else {
+	    /* the data already written is going to be played, so take */
+	    /* this fact into account here */
+	    wwo->dwPlayedTotal = wwo->dwWrittenTotal;
+        }
+	wwo->state = WINE_WS_PAUSED;
+    }
+}
+
+/**************************************************************************
+ * 		      wodPlayer_ProcessMessages			[internal]
+ */
+static void wodPlayer_ProcessMessages(WINE_WAVEOUT* wwo)
+{
+    LPWAVEHDR           lpWaveHdr;
+    enum win_wm_message	msg;
+    DWORD		param;
+    HANDLE		ev;
+
+    while (ESD_RetrieveRingMessage(&wwo->msgRing, &msg, &param, &ev)) {
+	TRACE("Received %s %lx\n", wodPlayerCmdString[msg - WM_USER - 1], param);
+	switch (msg) {
+	case WINE_WM_PAUSING:
+	    wodPlayer_Reset(wwo, FALSE);
+	    SetEvent(ev);
+	    break;
+	case WINE_WM_RESTARTING:
+	    wwo->state = WINE_WS_PLAYING;
+	    SetEvent(ev);
+	    break;
+	case WINE_WM_HEADER:
+	    lpWaveHdr = (LPWAVEHDR)param;
+
+	    /* insert buffer at the end of queue */
+	    {
+		LPWAVEHDR*	wh;
+		for (wh = &(wwo->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
+		*wh = lpWaveHdr;
+	    }
+            if (!wwo->lpPlayPtr)
+                wodPlayer_BeginWaveHdr(wwo,lpWaveHdr);
+	    if (wwo->state == WINE_WS_STOPPED)
+		wwo->state = WINE_WS_PLAYING;
+	    break;
+	case WINE_WM_RESETTING:
+	    wodPlayer_Reset(wwo, TRUE);
+	    SetEvent(ev);
+	    break;
+        case WINE_WM_UPDATE:
+            wodUpdatePlayedTotal(wwo);
+	    SetEvent(ev);
+            break;
+        case WINE_WM_BREAKLOOP:
+            if (wwo->state == WINE_WS_PLAYING && wwo->lpLoopPtr != NULL) {
+                /* ensure exit at end of current loop */
+                wwo->dwLoops = 1;
+            }
+	    SetEvent(ev);
+            break;
+	case WINE_WM_CLOSING:
+	    /* sanity check: this should not happen since the device must have been reset before */
+	    if (wwo->lpQueuePtr || wwo->lpPlayPtr) ERR("out of sync\n");
+	    wwo->hThread = 0;
+	    wwo->state = WINE_WS_CLOSED;
+	    SetEvent(ev);
+	    ExitThread(0);
+	    /* shouldn't go here */
+	default:
+	    FIXME("unknown message %d\n", msg);
+	    break;
+	}
+    }
+}
+
+/**************************************************************************
+ * 			     wodPlayer_FeedDSP			[internal]
+ * Feed as much sound data as we can into the DSP and return the number of
+ * milliseconds before it will be necessary to feed the DSP again.
+ */
+static DWORD wodPlayer_FeedDSP(WINE_WAVEOUT* wwo)
+{
+    DWORD       availInQ;
+
+    wodUpdatePlayedTotal(wwo);
+    /* better way to set availInQ? */
+    availInQ = ESD_BUF_SIZE;
+    TRACE("availInQ = %ld\n", availInQ);
+
+    /* input queue empty */
+    if (!wwo->lpPlayPtr) {
+        TRACE("Run out of wavehdr:s... flushing\n");
+        return INFINITE;
+    }
+
+#if 0
+    /* no more room... no need to try to feed */
+    if(!availInQ)
+    {
+	TRACE("no more room, no need to try to feed\n");
+	return wwo->dwSleepTime;
+    }
+#endif
+
+    /* Feed from partial wavehdr */
+    if (wwo->lpPlayPtr && wwo->dwPartialOffset != 0)
+    {
+        TRACE("feeding from partial wavehdr\n");
+        wodPlayer_WriteMaxFrags(wwo, &availInQ);
+    }
+
+    /* Feed wavehdrs until we run out of wavehdrs or DSP space */
+    if (!wwo->dwPartialOffset)
+    {
+	while(wwo->lpPlayPtr && availInQ)
+	{
+	    TRACE("feeding waveheaders until we run out of space\n");
+	    /* note the value that dwPlayedTotal will return when this wave finishes playing */
+	    wwo->lpPlayPtr->reserved = wwo->dwWrittenTotal + wwo->lpPlayPtr->dwBufferLength;
+	    TRACE("reserved=(%ld) dwWrittenTotal=(%ld) dwBufferLength=(%ld)\n",
+		  wwo->lpPlayPtr->reserved,
+		  wwo->dwWrittenTotal,
+		  wwo->lpPlayPtr->dwBufferLength
+		);
+	    wodPlayer_WriteMaxFrags(wwo, &availInQ);
+	}
+    }
+
+    if (!wwo->lpPlayPtr) {
+        TRACE("Ran out of wavehdrs\n");
+        return INFINITE;
+    }
+
+    return wwo->dwSleepTime;
+}
+
+
+/**************************************************************************
+ * 				wodPlayer			[internal]
+ */
+static	DWORD	CALLBACK	wodPlayer(LPVOID pmt)
+{
+    WORD	  uDevID = (DWORD)pmt;
+    WINE_WAVEOUT* wwo = (WINE_WAVEOUT*)&WOutDev[uDevID];
+    DWORD         dwNextFeedTime = INFINITE;   /* Time before DSP needs feeding */
+    DWORD         dwNextNotifyTime = INFINITE; /* Time before next wave completion */
+    DWORD         dwSleepTime;
+
+    wwo->state = WINE_WS_STOPPED;
+    SetEvent(wwo->hStartUpEvent);
+
+    for (;;) {
+        /** Wait for the shortest time before an action is required.  If there
+         *  are no pending actions, wait forever for a command.
+         */
+        dwSleepTime = min(dwNextFeedTime, dwNextNotifyTime);
+        TRACE("waiting %lums (%lu,%lu)\n", dwSleepTime, dwNextFeedTime, dwNextNotifyTime);
+        WaitForSingleObject(wwo->msgRing.msg_event, dwSleepTime);
+	wodPlayer_ProcessMessages(wwo);
+	if (wwo->state == WINE_WS_PLAYING) {
+	    dwNextFeedTime = wodPlayer_FeedDSP(wwo);
+	    dwNextNotifyTime = wodPlayer_NotifyCompletions(wwo, FALSE);
+	} else {
+	    dwNextFeedTime = dwNextNotifyTime = INFINITE;
+	}
+    }
+}
+
+/**************************************************************************
+ * 			wodGetDevCaps				[internal]
+ */
+static DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPSA lpCaps, DWORD dwSize)
+{
+    TRACE("(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
+
+    if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
+
+    if (wDevID >= MAX_WAVEOUTDRV) {
+	TRACE("MAX_WAVOUTDRV reached !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    memcpy(lpCaps, &WOutDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				wodOpen				[internal]
+ */
+static DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
+{
+    WINE_WAVEOUT*	wwo;
+    /* output to esound... */
+    int			out_bits = ESD_BITS8, out_channels = ESD_MONO, out_rate;
+    int			out_mode = ESD_STREAM, out_func = ESD_PLAY;
+    esd_format_t	out_format;
+
+    TRACE("(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
+    if (lpDesc == NULL) {
+	WARN("Invalid Parameter !\n");
+	return MMSYSERR_INVALPARAM;
+    }
+    if (wDevID >= MAX_WAVEOUTDRV) {
+	TRACE("MAX_WAVOUTDRV reached !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    /* if this device is already open tell the app that it is allocated */
+    if(WOutDev[wDevID].esd_fd != -1)
+    {
+      TRACE("device already allocated\n");
+      return MMSYSERR_ALLOCATED;
+    }
+
+    /* only PCM format is supported so far... */
+    if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
+	lpDesc->lpFormat->nChannels == 0 ||
+        lpDesc->lpFormat->nSamplesPerSec < DSBFREQUENCY_MIN ||
+        lpDesc->lpFormat->nSamplesPerSec > DSBFREQUENCY_MAX ||
+        (lpDesc->lpFormat->wBitsPerSample!=8 && lpDesc->lpFormat->wBitsPerSample!=16)) {
+	WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
+	     lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
+	     lpDesc->lpFormat->nSamplesPerSec);
+	return WAVERR_BADFORMAT;
+    }
+
+    if (dwFlags & WAVE_FORMAT_QUERY) {
+	TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
+	     lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
+	     lpDesc->lpFormat->nSamplesPerSec);
+	return MMSYSERR_NOERROR;
+    }
+
+    wwo = &WOutDev[wDevID];
+
+    /* direct sound not supported, ignore the flag */
+    dwFlags &= ~WAVE_DIRECTSOUND;
+
+    wwo->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
+
+    memcpy(&wwo->waveDesc, lpDesc, 	     sizeof(WAVEOPENDESC));
+    memcpy(&wwo->format,   lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
+
+    if (wwo->format.wBitsPerSample == 0) {
+	WARN("Resetting zeroed wBitsPerSample\n");
+	wwo->format.wBitsPerSample = 8 *
+	    (wwo->format.wf.nAvgBytesPerSec /
+	     wwo->format.wf.nSamplesPerSec) /
+	    wwo->format.wf.nChannels;
+    }
+
+    if (wwo->format.wBitsPerSample == 8)
+	out_bits = ESD_BITS8;
+    else if (wwo->format.wBitsPerSample == 16)
+	out_bits = ESD_BITS16;
+
+    wwo->bytes_per_frame = (wwo->format.wBitsPerSample * wwo->format.wf.nChannels) / 8;
+
+    if (wwo->format.wf.nChannels == 1)
+	out_channels = ESD_MONO;
+    else if (wwo->format.wf.nChannels == 2)
+	out_channels = ESD_STEREO;
+
+    out_format = out_bits | out_channels | out_mode | out_func;
+    out_rate = (int) wwo->format.wf.nSamplesPerSec;
+	TRACE("esd output format = 0x%08x, rate = %d\n", out_format, out_rate);
+
+    wwo->esd_fd = esd_play_stream(out_format, out_rate, esd_host, "wineesd");
+
+    /* clear these so we don't have any confusion ;-) */
+    wwo->sound_buffer = 0;
+    wwo->buffer_size = 0;
+
+    if(wwo->esd_fd < 0) return MMSYSERR_ALLOCATED;
+
+    wwo->dwBufferSize = ESD_BUF_SIZE;
+    TRACE("Buffer size is now (%ld)\n",wwo->dwBufferSize);
+
+    wwo->dwPlayedTotal = 0;
+    wwo->dwWrittenTotal = 0;
+
+    wwo->dwSleepTime = (1024 * 1000 * BUFFER_REFILL_THRESHOLD) / wwo->format.wf.nAvgBytesPerSec;
+
+    /* Initialize volume to full level */
+    wwo->volume_left = 100;
+    wwo->volume_right = 100;
+
+    ESD_InitRingMessage(&wwo->msgRing);
+
+    /* create player thread */
+    if (!(dwFlags & WAVE_DIRECTSOUND)) {
+	wwo->hStartUpEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
+	wwo->hThread = CreateThread(NULL, 0, wodPlayer, (LPVOID)(DWORD)wDevID, 0, &(wwo->dwThreadID));
+	WaitForSingleObject(wwo->hStartUpEvent, INFINITE);
+	CloseHandle(wwo->hStartUpEvent);
+    } else {
+	wwo->hThread = INVALID_HANDLE_VALUE;
+	wwo->dwThreadID = 0;
+    }
+    wwo->hStartUpEvent = INVALID_HANDLE_VALUE;
+
+    TRACE("esd=0x%lx, dwBufferSize=%ld\n",
+	  (long)wwo->esd_fd, wwo->dwBufferSize);
+
+    TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
+	  wwo->format.wBitsPerSample, wwo->format.wf.nAvgBytesPerSec,
+	  wwo->format.wf.nSamplesPerSec, wwo->format.wf.nChannels,
+	  wwo->format.wf.nBlockAlign);
+
+    return wodNotifyClient(wwo, WOM_OPEN, 0L, 0L);
+}
+
+/**************************************************************************
+ * 				wodClose			[internal]
+ */
+static DWORD wodClose(WORD wDevID)
+{
+    DWORD		ret = MMSYSERR_NOERROR;
+    WINE_WAVEOUT*	wwo;
+
+    TRACE("(%u);\n", wDevID);
+
+    if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].esd_fd == -1) {
+	WARN("bad device ID !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    wwo = &WOutDev[wDevID];
+    if (wwo->lpQueuePtr) {
+	WARN("buffers still playing !\n");
+	ret = WAVERR_STILLPLAYING;
+    } else {
+	TRACE("imhere[3-close]\n");
+	if (wwo->hThread != INVALID_HANDLE_VALUE) {
+	    ESD_AddRingMessage(&wwo->msgRing, WINE_WM_CLOSING, 0, TRUE);
+	}
+
+        ESD_DestroyRingMessage(&wwo->msgRing);
+
+	ESD_CloseWaveOutDevice(wwo);	/* close the stream and clean things up */
+
+	ret = wodNotifyClient(wwo, WOM_CLOSE, 0L, 0L);
+    }
+    return ret;
+}
+
+/**************************************************************************
+ * 				wodWrite			[internal]
+ *
+ */
+static DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+{
+    TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
+
+    /* first, do the sanity checks... */
+    if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].esd_fd == -1) {
+        WARN("bad dev ID !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    if (lpWaveHdr->lpData == NULL || !(lpWaveHdr->dwFlags & WHDR_PREPARED))
+    {
+	TRACE("unprepared\n");
+	return WAVERR_UNPREPARED;
+    }
+
+    if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
+    {
+	TRACE("still playing\n");
+	return WAVERR_STILLPLAYING;
+    }
+
+    lpWaveHdr->dwFlags &= ~WHDR_DONE;
+    lpWaveHdr->dwFlags |= WHDR_INQUEUE;
+    lpWaveHdr->lpNext = 0;
+
+    TRACE("adding ring message\n");
+    ESD_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_HEADER, (DWORD)lpWaveHdr, FALSE);
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				wodPrepare			[internal]
+ */
+static DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+{
+    TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
+
+    if (wDevID >= MAX_WAVEOUTDRV) {
+	WARN("bad device ID !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
+	return WAVERR_STILLPLAYING;
+
+    lpWaveHdr->dwFlags |= WHDR_PREPARED;
+    lpWaveHdr->dwFlags &= ~WHDR_DONE;
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				wodUnprepare			[internal]
+ */
+static DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+{
+    TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
+
+    if (wDevID >= MAX_WAVEOUTDRV) {
+	WARN("bad device ID !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
+	return WAVERR_STILLPLAYING;
+
+    lpWaveHdr->dwFlags &= ~WHDR_PREPARED;
+    lpWaveHdr->dwFlags |= WHDR_DONE;
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 			wodPause				[internal]
+ */
+static DWORD wodPause(WORD wDevID)
+{
+    TRACE("(%u);!\n", wDevID);
+
+    if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].esd_fd == -1) {
+	WARN("bad device ID !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    TRACE("imhere[3-PAUSING]\n");
+    ESD_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_PAUSING, 0, TRUE);
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 			wodRestart				[internal]
+ */
+static DWORD wodRestart(WORD wDevID)
+{
+    TRACE("(%u);\n", wDevID);
+
+    if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].esd_fd == -1) {
+	WARN("bad device ID !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    if (WOutDev[wDevID].state == WINE_WS_PAUSED) {
+	TRACE("imhere[3-RESTARTING]\n");
+	ESD_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_RESTARTING, 0, TRUE);
+    }
+
+    /* FIXME: is NotifyClient with WOM_DONE right ? (Comet Busters 1.3.3 needs this notification) */
+    /* FIXME: Myst crashes with this ... hmm -MM
+       return wodNotifyClient(wwo, WOM_DONE, 0L, 0L);
+    */
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 			wodReset				[internal]
+ */
+static DWORD wodReset(WORD wDevID)
+{
+    TRACE("(%u);\n", wDevID);
+
+    if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].esd_fd == -1) {
+	WARN("bad device ID !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    TRACE("imhere[3-RESET]\n");
+    ESD_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_RESETTING, 0, TRUE);
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				wodGetPosition			[internal]
+ */
+static DWORD wodGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
+{
+    double		time;
+    DWORD		val;
+    WINE_WAVEOUT*	wwo;
+
+    TRACE("(%u, %p, %lu);\n", wDevID, lpTime, uSize);
+
+    if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].esd_fd == -1) {
+	WARN("bad device ID !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    if (lpTime == NULL)	return MMSYSERR_INVALPARAM;
+
+    wwo = &WOutDev[wDevID];
+    ESD_AddRingMessage(&wwo->msgRing, WINE_WM_UPDATE, 0, TRUE);
+    val = wwo->dwPlayedTotal;
+
+    TRACE("wType=%04X wBitsPerSample=%u nSamplesPerSec=%lu nChannels=%u nAvgBytesPerSec=%lu\n",
+	  lpTime->wType, wwo->format.wBitsPerSample,
+	  wwo->format.wf.nSamplesPerSec, wwo->format.wf.nChannels,
+	  wwo->format.wf.nAvgBytesPerSec);
+    TRACE("dwPlayedTotal=%lu\n", val);
+
+    switch (lpTime->wType) {
+    case TIME_BYTES:
+	lpTime->u.cb = val;
+	TRACE("TIME_BYTES=%lu\n", lpTime->u.cb);
+	break;
+    case TIME_SAMPLES:
+	lpTime->u.sample = val * 8 / wwo->format.wBitsPerSample /wwo->format.wf.nChannels;
+	TRACE("TIME_SAMPLES=%lu\n", lpTime->u.sample);
+	break;
+    case TIME_SMPTE:
+	time = (double)val / (double)wwo->format.wf.nAvgBytesPerSec;
+	lpTime->u.smpte.hour = time / (60 * 60);
+	time -= lpTime->u.smpte.hour * (60 * 60);
+	lpTime->u.smpte.min = time / 60;
+	time -= lpTime->u.smpte.min * 60;
+	lpTime->u.smpte.sec = time;
+	time -= lpTime->u.smpte.sec;
+	lpTime->u.smpte.frame = ceil(time * 30);
+	lpTime->u.smpte.fps = 30;
+	TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
+	      lpTime->u.smpte.hour, lpTime->u.smpte.min,
+	      lpTime->u.smpte.sec, lpTime->u.smpte.frame);
+	break;
+    default:
+	FIXME("Format %d not supported ! use TIME_MS !\n", lpTime->wType);
+	lpTime->wType = TIME_MS;
+    case TIME_MS:
+	lpTime->u.ms = val * 1000.0 / wwo->format.wf.nAvgBytesPerSec;
+	TRACE("TIME_MS=%lu\n", lpTime->u.ms);
+	break;
+    }
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				wodBreakLoop			[internal]
+ */
+static DWORD wodBreakLoop(WORD wDevID)
+{
+    TRACE("(%u);\n", wDevID);
+
+    if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].esd_fd == -1) {
+	WARN("bad device ID !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+    ESD_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_BREAKLOOP, 0, TRUE);
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				wodGetVolume			[internal]
+ */
+static DWORD wodGetVolume(WORD wDevID, LPDWORD lpdwVol)
+{
+    DWORD left, right;
+
+    left = WOutDev[wDevID].volume_left;
+    right = WOutDev[wDevID].volume_right;
+
+    TRACE("(%u, %p);\n", wDevID, lpdwVol);
+
+    *lpdwVol = ((left * 0xFFFFl) / 100) + (((right * 0xFFFFl) / 100) <<
+		16);
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				wodSetVolume			[internal]
+ */
+static DWORD wodSetVolume(WORD wDevID, DWORD dwParam)
+{
+    DWORD left, right;
+
+    left  = (LOWORD(dwParam) * 100) / 0xFFFFl;
+    right = (HIWORD(dwParam) * 100) / 0xFFFFl;
+
+    TRACE("(%u, %08lX);\n", wDevID, dwParam);
+
+    WOutDev[wDevID].volume_left = left;
+    WOutDev[wDevID].volume_right = right;
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				wodGetNumDevs			[internal]
+ */
+static	DWORD	wodGetNumDevs(void)
+{
+    return MAX_WAVEOUTDRV;
+}
+
+/**************************************************************************
+ *                              wodDevInterfaceSize             [internal]
+ */
+static DWORD wodDevInterfaceSize(UINT wDevID, LPDWORD dwParam1)
+{
+    TRACE("(%u, %p)\n", wDevID, dwParam1);
+ 
+    *dwParam1 = MultiByteToWideChar(CP_ACP, 0, WOutDev[wDevID].interface_name, -1,
+                                    NULL, 0 ) * sizeof(WCHAR);
+    return MMSYSERR_NOERROR;
+}
+ 
+/**************************************************************************
+ *                              wodDevInterface                 [internal]
+ */
+static DWORD wodDevInterface(UINT wDevID, PWCHAR dwParam1, DWORD dwParam2)
+{
+    if (dwParam2 >= MultiByteToWideChar(CP_ACP, 0, WOutDev[wDevID].interface_name, -1,
+                                        NULL, 0 ) * sizeof(WCHAR))
+    {
+        MultiByteToWideChar(CP_ACP, 0, WOutDev[wDevID].interface_name, -1,
+                            dwParam1, dwParam2 / sizeof(WCHAR));
+        return MMSYSERR_NOERROR;
+    }
+    return MMSYSERR_INVALPARAM;
+}
+ 
+/**************************************************************************
+ * 				wodMessage (WINEESD.@)
+ */
+DWORD WINAPI ESD_wodMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
+			    DWORD dwParam1, DWORD dwParam2)
+{
+    TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
+	  wDevID, wMsg, dwUser, dwParam1, dwParam2);
+
+    switch (wMsg) {
+    case DRVM_INIT:
+    case DRVM_EXIT:
+    case DRVM_ENABLE:
+    case DRVM_DISABLE:
+	/* FIXME: Pretend this is supported */
+	return 0;
+    case WODM_OPEN:	 	return wodOpen		(wDevID, (LPWAVEOPENDESC)dwParam1,	dwParam2);
+    case WODM_CLOSE:	 	return wodClose		(wDevID);
+    case WODM_WRITE:	 	return wodWrite		(wDevID, (LPWAVEHDR)dwParam1,		dwParam2);
+    case WODM_PAUSE:	 	return wodPause		(wDevID);
+    case WODM_GETPOS:	 	return wodGetPosition	(wDevID, (LPMMTIME)dwParam1, 		dwParam2);
+    case WODM_BREAKLOOP: 	return wodBreakLoop     (wDevID);
+    case WODM_PREPARE:	 	return wodPrepare	(wDevID, (LPWAVEHDR)dwParam1, 		dwParam2);
+    case WODM_UNPREPARE: 	return wodUnprepare	(wDevID, (LPWAVEHDR)dwParam1, 		dwParam2);
+    case WODM_GETDEVCAPS:	return wodGetDevCaps	(wDevID, (LPWAVEOUTCAPSA)dwParam1,	dwParam2);
+    case WODM_GETNUMDEVS:	return wodGetNumDevs	();
+    case WODM_GETPITCH:	 	return MMSYSERR_NOTSUPPORTED;
+    case WODM_SETPITCH:	 	return MMSYSERR_NOTSUPPORTED;
+    case WODM_GETPLAYBACKRATE:	return MMSYSERR_NOTSUPPORTED;
+    case WODM_SETPLAYBACKRATE:	return MMSYSERR_NOTSUPPORTED;
+    case WODM_GETVOLUME:	return wodGetVolume	(wDevID, (LPDWORD)dwParam1);
+    case WODM_SETVOLUME:	return wodSetVolume	(wDevID, dwParam1);
+    case WODM_RESTART:		return wodRestart	(wDevID);
+    case WODM_RESET:		return wodReset		(wDevID);
+
+    case DRV_QUERYDEVICEINTERFACESIZE: return wodDevInterfaceSize       (wDevID, (LPDWORD)dwParam1);
+    case DRV_QUERYDEVICEINTERFACE:     return wodDevInterface           (wDevID, (PWCHAR)dwParam1, dwParam2);
+    case DRV_QUERYDSOUNDIFACE:	return wodDsCreate	(wDevID, (PIDSDRIVER*)dwParam1);
+    case DRV_QUERYDSOUNDDESC:	return wodDsDesc	(wDevID, (PDSDRIVERDESC)dwParam1);
+    default:
+	FIXME("unknown message %d!\n", wMsg);
+    }
+    return MMSYSERR_NOTSUPPORTED;
+}
+
+/*======================================================================*
+ *                  Low level WAVE IN implementation			*
+ *======================================================================*/
+
+/**************************************************************************
+ * 				widGetNumDevs			[internal]
+ */
+static	DWORD	widGetNumDevs(void)
+{
+    TRACE("%d \n",MAX_WAVEINDRV);
+    return MAX_WAVEINDRV;
+}
+
+/**************************************************************************
+ *                              widDevInterfaceSize             [internal]
+ */
+static DWORD widDevInterfaceSize(UINT wDevID, LPDWORD dwParam1)
+{
+    TRACE("(%u, %p)\n", wDevID, dwParam1);
+ 
+ 
+    *dwParam1 = MultiByteToWideChar(CP_ACP, 0, WInDev[wDevID].interface_name, -1,
+                                    NULL, 0 ) * sizeof(WCHAR);
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ *                              widDevInterface                 [internal]
+ */
+static DWORD widDevInterface(UINT wDevID, PWCHAR dwParam1, DWORD dwParam2)
+{
+    if (dwParam2 >= MultiByteToWideChar(CP_ACP, 0, WInDev[wDevID].interface_name, -1,
+                                        NULL, 0 ) * sizeof(WCHAR))
+    {
+        MultiByteToWideChar(CP_ACP, 0, WInDev[wDevID].interface_name, -1,
+                            dwParam1, dwParam2 / sizeof(WCHAR));
+        return MMSYSERR_NOERROR;
+    }
+    return MMSYSERR_INVALPARAM;
+}
+
+/**************************************************************************
+ * 			widNotifyClient			[internal]
+ */
+static DWORD widNotifyClient(WINE_WAVEIN* wwi, WORD wMsg, DWORD dwParam1, DWORD dwParam2)
+{
+    TRACE("wMsg = 0x%04x dwParm1 = %04lX dwParam2 = %04lX\n", wMsg, dwParam1, dwParam2);
+
+    switch (wMsg) {
+    case WIM_OPEN:
+    case WIM_CLOSE:
+    case WIM_DATA:
+	if (wwi->wFlags != DCB_NULL &&
+	    !DriverCallback(wwi->waveDesc.dwCallback, wwi->wFlags,
+			    (HDRVR)wwi->waveDesc.hWave, wMsg,
+			    wwi->waveDesc.dwInstance, dwParam1, dwParam2)) {
+	    WARN("can't notify client !\n");
+	    return MMSYSERR_ERROR;
+	}
+	break;
+    default:
+	FIXME("Unknown callback message %u\n", wMsg);
+	return MMSYSERR_INVALPARAM;
+    }
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 			widGetDevCaps				[internal]
+ */
+static DWORD widGetDevCaps(WORD wDevID, LPWAVEINCAPSA lpCaps, DWORD dwSize)
+{
+    TRACE("(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
+
+    if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
+
+    if (wDevID >= MAX_WAVEINDRV) {
+	TRACE("MAX_WAVINDRV reached !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    memcpy(lpCaps, &WInDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				widRecorder			[internal]
+ */
+static	DWORD	CALLBACK	widRecorder(LPVOID pmt)
+{
+    WORD		uDevID = (DWORD)pmt;
+    WINE_WAVEIN*	wwi = (WINE_WAVEIN*)&WInDev[uDevID];
+    WAVEHDR*		lpWaveHdr;
+    DWORD		dwSleepTime;
+    DWORD		bytesRead;
+    enum win_wm_message msg;
+    DWORD		param;
+    HANDLE		ev;
+
+    SetEvent(wwi->hStartUpEvent);
+
+    /* make sleep time to be # of ms to record one packet */
+    dwSleepTime = (1024 * 1000) / wwi->format.wf.nAvgBytesPerSec;
+    TRACE("sleeptime=%ld ms\n", dwSleepTime);
+
+    for(;;) {
+	TRACE("wwi->lpQueuePtr=(%p), wwi->state=(%d)\n",wwi->lpQueuePtr,wwi->state);
+
+	/* read all data is esd input buffer. */
+	if ((wwi->lpQueuePtr != NULL) && (wwi->state == WINE_WS_PLAYING))
+	{
+	    lpWaveHdr = wwi->lpQueuePtr;
+ 
+	    TRACE("read as much as we can\n");
+	    while(wwi->lpQueuePtr)
+	    {
+		TRACE("attempt to read %ld bytes\n",lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded);
+		bytesRead = read(wwi->esd_fd,
+			      lpWaveHdr->lpData + lpWaveHdr->dwBytesRecorded,
+			      lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded);
+		TRACE("bytesRead=%ld\n",bytesRead);
+		if (bytesRead == -1 && errno == EAGAIN)
+			bytesRead = 0;
+		if (bytesRead==0) break; /* So we can stop recording smoothly */
+		if (bytesRead < 0)
+			bytesRead = 0;
+ 
+		lpWaveHdr->dwBytesRecorded	+= bytesRead;
+		wwi->dwRecordedTotal		+= bytesRead;
+
+		/* buffer full. notify client */
+		if (lpWaveHdr->dwBytesRecorded >= lpWaveHdr->dwBufferLength)
+		{
+		    /* must copy the value of next waveHdr, because we have no idea of what
+		     * will be done with the content of lpWaveHdr in callback
+		     */
+		    LPWAVEHDR	lpNext = lpWaveHdr->lpNext;
+
+		    TRACE("waveHdr full.\n");
+ 
+		    lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
+		    lpWaveHdr->dwFlags |=  WHDR_DONE;
+ 
+		    widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
+		    lpWaveHdr = wwi->lpQueuePtr = lpNext;
+		}
+	    }
+	}
+
+	/* wait for dwSleepTime or an event in thread's queue */
+	WaitForSingleObject(wwi->msgRing.msg_event, dwSleepTime);
+
+	while (ESD_RetrieveRingMessage(&wwi->msgRing, &msg, &param, &ev))
+	{
+	    TRACE("msg=%s param=0x%lx\n",wodPlayerCmdString[msg - WM_USER - 1], param);
+	    switch(msg) {
+	    case WINE_WM_PAUSING:
+		wwi->state = WINE_WS_PAUSED;
+
+		/* Put code here to "pause" esd recording
+		 */
+
+		SetEvent(ev);
+		break;
+	    case WINE_WM_STARTING:
+		wwi->state = WINE_WS_PLAYING;
+
+		/* Put code here to "start" esd recording
+		 */
+
+		SetEvent(ev);
+		break;
+	    case WINE_WM_HEADER:
+		lpWaveHdr = (LPWAVEHDR)param;
+		/* insert buffer at end of queue */
+		{
+		    LPWAVEHDR* wh;
+		    int num_headers = 0;
+		    for (wh = &(wwi->lpQueuePtr); *wh; wh = &((*wh)->lpNext))
+		    {
+			num_headers++;
+
+		    }
+		    *wh=lpWaveHdr;
+		}
+		break;
+	    case WINE_WM_STOPPING:
+		if (wwi->state != WINE_WS_STOPPED)
+		{
+
+		    /* Put code here to "stop" esd recording
+		     */
+
+		    /* return current buffer to app */
+		    lpWaveHdr = wwi->lpQueuePtr;
+		    if (lpWaveHdr)
+		    {
+			LPWAVEHDR lpNext = lpWaveHdr->lpNext;
+		        TRACE("stop %p %p\n", lpWaveHdr, lpWaveHdr->lpNext);
+		        lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
+		        lpWaveHdr->dwFlags |= WHDR_DONE;
+		        widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
+		        wwi->lpQueuePtr = lpNext;
+		    }
+		}
+		wwi->state = WINE_WS_STOPPED;
+		SetEvent(ev);
+		break;
+	    case WINE_WM_RESETTING:
+		wwi->state = WINE_WS_STOPPED;
+		wwi->dwRecordedTotal = 0;
+
+		/* return all buffers to the app */
+		for (lpWaveHdr = wwi->lpQueuePtr; lpWaveHdr; lpWaveHdr = lpWaveHdr->lpNext) {
+		    TRACE("reset %p %p\n", lpWaveHdr, lpWaveHdr->lpNext);
+		    lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
+		    lpWaveHdr->dwFlags |= WHDR_DONE;
+
+		    widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
+		}
+		wwi->lpQueuePtr = NULL; 
+		SetEvent(ev);
+		break;
+	    case WINE_WM_CLOSING:
+		wwi->hThread = 0;
+		wwi->state = WINE_WS_CLOSED;
+		SetEvent(ev);
+		ExitThread(0);
+		/* shouldn't go here */
+	    default:
+		FIXME("unknown message %d\n", msg);
+		break;
+	    }
+	}
+    }
+    ExitThread(0);
+    /* just for not generating compilation warnings... should never be executed */
+    return 0;
+}
+
+/**************************************************************************
+ * 				widOpen				[internal]
+ */
+static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
+{
+    WINE_WAVEIN*	wwi;
+    /* input esound... */
+    int			in_bits = ESD_BITS16, in_channels = ESD_STEREO, in_rate;
+#ifdef WID_USE_ESDMON
+    int			in_mode = ESD_STREAM, in_func = ESD_PLAY;
+#else
+    int			in_mode = ESD_STREAM, in_func = ESD_RECORD;
+#endif
+    esd_format_t	in_format;
+    int			mode;
+
+    TRACE("(%u, %p %08lX);\n",wDevID, lpDesc, dwFlags);
+    if (lpDesc == NULL) {
+	WARN("Invalid Parametr (lpDesc == NULL)!\n");
+	return MMSYSERR_INVALPARAM;
+    }
+
+    if (wDevID >= MAX_WAVEINDRV) {
+	TRACE ("MAX_WAVEINDRV reached !\n");
+	return MMSYSERR_BADDEVICEID;
+    }
+
+    /* if this device is already open tell the app that it is allocated */
+    if(WInDev[wDevID].esd_fd != -1)
+    {
+	TRACE("device already allocated\n");
+	return MMSYSERR_ALLOCATED;
+    }
+
+    /* only PCM format is support so far... */
+    if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
+	lpDesc->lpFormat->nChannels == 0 ||
+        lpDesc->lpFormat->nSamplesPerSec < DSBFREQUENCY_MIN ||
+        lpDesc->lpFormat->nSamplesPerSec > DSBFREQUENCY_MAX ||
+        (lpDesc->lpFormat->wBitsPerSample!=8 && lpDesc->lpFormat->wBitsPerSample!=16)) {
+	WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
+	     lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
+	     lpDesc->lpFormat->nSamplesPerSec);
+	return WAVERR_BADFORMAT;
+    }
+
+    if (dwFlags & WAVE_FORMAT_QUERY) {
+	TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
+	     lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
+	     lpDesc->lpFormat->nSamplesPerSec);
+	return MMSYSERR_NOERROR;
+    }
+
+    wwi = &WInDev[wDevID];
+
+    /* direct sound not supported, ignore the flag */
+    dwFlags &= ~WAVE_DIRECTSOUND;
+
+    wwi->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
+ 
+    memcpy(&wwi->waveDesc, lpDesc,           sizeof(WAVEOPENDESC));
+    memcpy(&wwi->format,   lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
+
+    if (wwi->format.wBitsPerSample == 0) {
+	WARN("Resetting zerod wBitsPerSample\n");
+	wwi->format.wBitsPerSample = 8 *
+	    (wwi->format.wf.nAvgBytesPerSec /
+	     wwi->format.wf.nSamplesPerSec) /
+	    wwi->format.wf.nChannels;
+    }
+
+    if (wwi->format.wBitsPerSample == 8)
+	in_bits = ESD_BITS8;
+    else if (wwi->format.wBitsPerSample == 16)
+	in_bits = ESD_BITS16;
+
+    wwi->bytes_per_frame = (wwi->format.wBitsPerSample * wwi->format.wf.nChannels) / 8;
+
+    if (wwi->format.wf.nChannels == 1)
+	in_channels = ESD_MONO;
+    else if (wwi->format.wf.nChannels == 2)
+	in_channels = ESD_STEREO;
+
+    in_format = in_bits | in_channels | in_mode | in_func;
+    in_rate = (int) wwi->format.wf.nSamplesPerSec;
+	TRACE("esd input format = 0x%08x, rate = %d\n", in_format, in_rate);
+
+#ifdef WID_USE_ESDMON
+    wwi->esd_fd = esd_monitor_stream(in_format, in_rate, esd_host, "wineesd");
+#else
+    wwi->esd_fd = esd_record_stream(in_format, in_rate, esd_host, "wineesd");
+#endif
+    TRACE("(wwi->esd_fd=%d)\n",wwi->esd_fd);
+    wwi->state = WINE_WS_STOPPED;
+
+    if (wwi->lpQueuePtr) {
+	WARN("Should have an empty queue (%p)\n", wwi->lpQueuePtr);
+	wwi->lpQueuePtr = NULL;
+    }
+
+    if(wwi->esd_fd < 0) return MMSYSERR_ALLOCATED;
+
+    /* Set the esd socket O_NONBLOCK, so we can stop recording smoothly */
+    mode = fcntl(wwi->esd_fd, F_GETFL);
+    mode |= O_NONBLOCK;
+    fcntl(wwi->esd_fd, F_SETFL, mode);
+
+    wwi->dwRecordedTotal = 0;
+    wwi->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
+
+    ESD_InitRingMessage(&wwi->msgRing);
+
+    /* create recorder thread */
+    if (!(dwFlags & WAVE_DIRECTSOUND)) {
+	wwi->hStartUpEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
+	wwi->hThread = CreateThread(NULL, 0, widRecorder, (LPVOID)(DWORD)wDevID, 0, &(wwi->dwThreadID));
+	WaitForSingleObject(wwi->hStartUpEvent, INFINITE);
+	CloseHandle(wwi->hStartUpEvent);
+    } else {
+	wwi->hThread = INVALID_HANDLE_VALUE;
+	wwi->dwThreadID = 0;
+    }
+    wwi->hStartUpEvent = INVALID_HANDLE_VALUE;
+
+    TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
+	  wwi->format.wBitsPerSample, wwi->format.wf.nAvgBytesPerSec,
+	  wwi->format.wf.nSamplesPerSec, wwi->format.wf.nChannels,
+	  wwi->format.wf.nBlockAlign);
+    return widNotifyClient(wwi, WIM_OPEN, 0L, 0L);
+}
+
+/**************************************************************************
+ * 				widClose			[internal]
+ */
+static DWORD widClose(WORD wDevID)
+{
+    WINE_WAVEIN*	wwi;
+
+    TRACE("(%u);\n", wDevID);
+    if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].state == WINE_WS_CLOSED) {
+	WARN("can't close !\n");
+	return MMSYSERR_INVALHANDLE;
+    }
+
+    wwi = &WInDev[wDevID];
+
+    if (wwi->lpQueuePtr != NULL) {
+	WARN("still buffers open !\n");
+	return WAVERR_STILLPLAYING;
+    }
+
+    ESD_AddRingMessage(&wwi->msgRing, WINE_WM_CLOSING, 0, TRUE);
+    ESD_CloseWaveInDevice(wwi);
+    wwi->state = WINE_WS_CLOSED;
+    ESD_DestroyRingMessage(&wwi->msgRing);
+    return widNotifyClient(wwi, WIM_CLOSE, 0L, 0L);
+}
+
+/**************************************************************************
+ * 				widAddBuffer		[internal]
+ */
+static DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+{
+    TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
+
+    if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].state == WINE_WS_CLOSED) {
+	WARN("can't do it !\n");
+	return MMSYSERR_INVALHANDLE;
+    }
+    if (!(lpWaveHdr->dwFlags & WHDR_PREPARED)) {
+	TRACE("never been prepared !\n");
+	return WAVERR_UNPREPARED;
+    }
+    if (lpWaveHdr->dwFlags & WHDR_INQUEUE) {
+	TRACE("header already in use !\n");
+	return WAVERR_STILLPLAYING;
+    }
+
+    lpWaveHdr->dwFlags |= WHDR_INQUEUE;
+    lpWaveHdr->dwFlags &= ~WHDR_DONE;
+    lpWaveHdr->dwBytesRecorded = 0;
+    lpWaveHdr->lpNext = NULL;
+
+    ESD_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_HEADER, (DWORD)lpWaveHdr, FALSE);
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				widPrepare			[internal]
+ */
+static DWORD widPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+{
+    TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
+
+    if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_INVALHANDLE;
+
+    if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
+	return WAVERR_STILLPLAYING;
+
+    lpWaveHdr->dwFlags |= WHDR_PREPARED;
+    lpWaveHdr->dwFlags &= ~WHDR_DONE;
+    lpWaveHdr->dwBytesRecorded = 0;
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				widUnprepare			[internal]
+ */
+static DWORD widUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+{
+    TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
+    if (wDevID >= MAX_WAVEINDRV) {
+	WARN("bad device ID !\n");
+	return MMSYSERR_INVALHANDLE;
+    }
+
+    if (lpWaveHdr->dwFlags & WHDR_INQUEUE) {
+	TRACE("Still playing...\n");
+	return WAVERR_STILLPLAYING;
+    }
+
+    lpWaveHdr->dwFlags &= ~WHDR_PREPARED;
+    lpWaveHdr->dwFlags |= WHDR_DONE;
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 			widStart				[internal]
+ */
+static DWORD widStart(WORD wDevID)
+{
+    TRACE("(%u);\n", wDevID);
+    if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].state == WINE_WS_CLOSED) {
+	WARN("can't start recording !\n");
+	return MMSYSERR_INVALHANDLE;
+    }
+
+    ESD_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_STARTING, 0, TRUE);
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 			widStop					[internal]
+ */
+static DWORD widStop(WORD wDevID)
+{
+    TRACE("(%u);\n", wDevID);
+    if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].state == WINE_WS_CLOSED) {
+	WARN("can't stop !\n");
+	return MMSYSERR_INVALHANDLE;
+    }
+
+    ESD_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_STOPPING, 0, TRUE);
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 			widReset				[internal]
+ */
+static DWORD widReset(WORD wDevID)
+{
+    TRACE("(%u);\n", wDevID);
+    if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].state == WINE_WS_CLOSED) {
+	WARN("can't reset !\n");
+	return MMSYSERR_INVALHANDLE;
+    }
+    ESD_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_RESETTING, 0, TRUE);
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				widMessage (WINEESD.6)
+ */
+DWORD WINAPI ESD_widMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
+			    DWORD dwParam1, DWORD dwParam2)
+{
+    TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
+	  wDevID, wMsg, dwUser, dwParam1, dwParam2);
+    switch (wMsg) {
+    case DRVM_INIT:
+    case DRVM_EXIT:
+    case DRVM_ENABLE:
+    case DRVM_DISABLE:
+	/* FIXME: Pretend this is supported */
+	return 0;
+    case WIDM_OPEN:	 	return widOpen		(wDevID, (LPWAVEOPENDESC)dwParam1,	dwParam2);
+    case WIDM_CLOSE:		return widClose		(wDevID);
+    case WIDM_ADDBUFFER:	return widAddBuffer	(wDevID, (LPWAVEHDR)dwParam1, dwParam2);
+    case WIDM_PREPARE:		return widPrepare	(wDevID, (LPWAVEHDR)dwParam1, dwParam2);
+    case WIDM_UNPREPARE:	return widUnprepare	(wDevID, (LPWAVEHDR)dwParam1, dwParam2);
+    case WIDM_GETDEVCAPS:	return widGetDevCaps	(wDevID, (LPWAVEINCAPSA)dwParam1,	dwParam2);
+    case WIDM_GETNUMDEVS:	return widGetNumDevs	();
+    case WIDM_RESET:		return widReset		(wDevID);
+    case WIDM_START:		return widStart		(wDevID);
+    case WIDM_STOP:		return widStop		(wDevID);
+    case DRV_QUERYDEVICEINTERFACESIZE: return widDevInterfaceSize       (wDevID, (LPDWORD)dwParam1);
+    case DRV_QUERYDEVICEINTERFACE:     return widDevInterface           (wDevID, (PWCHAR)dwParam1, dwParam2);
+    default:
+	FIXME("unknown message %d!\n", wMsg);
+    }
+    return MMSYSERR_NOTSUPPORTED;
+}
+
+/*======================================================================*
+ *                  Low level DSOUND implementation			*
+ *======================================================================*/
+static DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv)
+{
+    /* we can't perform memory mapping as we don't have a file stream
+	interface with esd like we do with oss */
+    MESSAGE("This sound card's driver does not support direct access\n");
+    MESSAGE("The (slower) DirectSound HEL mode will be used instead.\n");
+    return MMSYSERR_NOTSUPPORTED;
+}
+
+static DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc)
+{
+    memset(desc, 0, sizeof(*desc));
+    strcpy(desc->szDesc, "Wine EsounD DirectSound Driver");
+    strcpy(desc->szDrvname, "wineesd.drv");
+    return MMSYSERR_NOERROR;
+}
+
+#else /* !HAVE_ESD */
+
+/**************************************************************************
+ * 				wodMessage (WINEESD.@)
+ */
+DWORD WINAPI ESD_wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
+			    DWORD dwParam1, DWORD dwParam2)
+{
+    FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
+    return MMSYSERR_NOTENABLED;
+}
+
+/**************************************************************************
+ * 				widMessage (WINEESD.6)
+ */
+DWORD WINAPI ESD_widMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
+			    DWORD dwParam1, DWORD dwParam2)
+{
+    FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
+    return MMSYSERR_NOTENABLED;
+}
+
+#endif /* HAVE_ESD */
--- /dev/null	2005-07-31 20:23:43.921776544 +0200
+++ dlls/winmm/wineesd/esound.c	2005-07-10 23:26:44.000000000 +0200
@@ -0,0 +1,93 @@
+/* -*- tab-width: 8; c-basic-offset: 4 -*- */
+/*
+ * Wine Driver for EsounD Sound Server
+ * http://www.tux.org/~ricdude/EsounD.html
+ *
+ * Copyright 2004 Zhangrong Huang <hzhr at users.sourceforge.net>
+ *
+ * Code massively copied from Eric Pouech's OSS driver
+ * and Chris Morgan aRts driver
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winuser.h"
+#include "mmddk.h"
+#include "esound.h"
+
+#ifdef HAVE_ESD
+static		int esd = 0;
+
+/**************************************************************************
+ * 				ESD_drvOpen			[internal]
+ */
+static	DWORD	ESD_drvOpen(LPSTR str)
+{
+    if (esd)
+	return 0;
+
+    /* I know, this is ugly, but who cares... */
+    esd = 1;
+    return 1;
+}
+
+/**************************************************************************
+ * 				ESD_drvClose			[internal]
+ */
+static	DWORD	ESD_drvClose(DWORD dwDevID)
+{
+    if (esd) {
+	esd = 0;
+	return 1;
+    }
+    return 0;
+}
+#endif /* #ifdef HAVE_ESD */
+
+
+/**************************************************************************
+ * 				DriverProc (WINEESD.@)
+ */
+LONG CALLBACK	ESD_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
+			       DWORD dwParam1, DWORD dwParam2)
+{
+/* EPP     TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n",  */
+/* EPP 	  dwDevID, hDriv, wMsg, dwParam1, dwParam2); */
+
+    switch(wMsg) {
+#ifdef HAVE_ESD
+    case DRV_LOAD:		if (ESD_WaveInit()<0) return 0;
+				return 1;
+    case DRV_FREE:	        return ESD_WaveClose();
+    case DRV_OPEN:		return ESD_drvOpen((LPSTR)dwParam1);
+    case DRV_CLOSE:		return ESD_drvClose(dwDevID);
+    case DRV_ENABLE:		return 1;
+    case DRV_DISABLE:		return 1;
+    case DRV_QUERYCONFIGURE:	return 1;
+    case DRV_CONFIGURE:		MessageBoxA(0, "EsounD MultiMedia Driver!", "EsounD Driver", MB_OK);	return 1;
+    case DRV_INSTALL:		return DRVCNF_RESTART;
+    case DRV_REMOVE:		return DRVCNF_RESTART;
+#endif
+    default:
+	return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
+    }
+}
--- /dev/null	2005-07-31 20:23:43.921776544 +0200
+++ dlls/winmm/wineesd/esound.h	2005-07-10 23:26:44.000000000 +0200
@@ -0,0 +1,34 @@
+/* Definition for EsounD drivers : wine multimedia system
+ *
+ * Copyright 2004 Zhangrong Huang <hzhr at users.sourceforge.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __WINE_ESD_H
+#define __WINE_ESD_H
+
+#ifndef __WINE_CONFIG_H
+# error You must include config.h to use this header
+#endif
+
+#ifdef HAVE_SYS_ERRNO_H
+#include <sys/errno.h>
+#endif
+
+extern LONG ESD_WaveInit(void);
+extern LONG ESD_WaveClose(void);
+
+#endif  /* __WINE_ESD_H */
--- /dev/null	2005-07-31 20:23:43.921776544 +0200
+++ dlls/winmm/wineesd/wineesd.drv.spec	2005-07-10 23:26:44.000000000 +0200
@@ -0,0 +1,3 @@
+@ stdcall DriverProc(long long long long long) ESD_DriverProc
+@ stdcall wodMessage(long long long long long) ESD_wodMessage
+@ stdcall widMessage(long long long long long) ESD_widMessage
--- /dev/null	2005-07-31 20:23:43.921776544 +0200
+++ dlls/winmm/wineesd/Makefile	2005-07-11 00:30:24.000000000 +0200
@@ -0,0 +1,480 @@
+TOPSRCDIR = ../../..
+TOPOBJDIR = ../../..
+SRCDIR    = .
+
+MODULE    = wineesd.drv
+IMPORTS   = winmm user32 kernel32
+EXTRAINCL = 
+EXTRALIBS = -L/usr/lib -lesd -laudiofile -lm -lasound -ldxguid -luuid
+
+C_SRCS = \
+	esound.c \
+	audio.c
+
+
+# Global rules for building dlls     -*-Makefile-*-
+#
+# Each individual makefile should define the following variables:
+# MODULE       : name of the main module being built
+# EXTRALIBS    : extra libraries to link in (optional)
+# SPEC_SRCS16  : interface definition files for 16-bit dlls (optional)
+# SUBSYSTEM    : (optional) subsystem (for native dlls)
+#
+# plus all variables required by the global Make.rules.in
+#
+
+DLLDEFS     = 
+DLLFLAGS    = -D_REENTRANT -fPIC
+DLLEXT      = .so
+IMPLIBEXT   = def
+DEFS        = -D__WINESRC__ $(DLLDEFS) $(EXTRADEFS)
+BASEMODULE  = $(MODULE:%.dll=%)
+MAINSPEC    = $(BASEMODULE).spec
+SPEC_DEF    = lib$(BASEMODULE).def
+WIN16_FILES = $(SPEC_SRCS16:.spec=.spec.o) $(C_SRCS16:.c=.o) $(EXTRA_OBJS16)
+ALL_OBJS    = $(WIN16_FILES) $(OBJS) $(MODULE).dbg.o $(RC_SRCS:.rc=.res)
+ALL_LIBS    = $(LIBWINE) $(EXTRALIBS) $(LIBPORT) $(LDFLAGS) $(LIBS)
+ALL_IMPORTS = $(DELAYIMPORTS) $(IMPORTS)
+IMPLIB_OBJS = $(IMPLIB_SRCS:.c=.o)
+STATICIMPLIB= $(IMPORTLIB:.def=.def.a)
+DLL_LDPATH  = -L$(DLLDIR) $(ALL_IMPORTS:%=-L$(DLLDIR)/%)
+
+all: $(MODULE)$(DLLEXT) $(SUBDIRS)
+
+
+# Global rules shared by all makefiles     -*-Makefile-*-
+#
+# Each individual makefile must define the following variables:
+# TOPSRCDIR    : top-level source directory
+# TOPOBJDIR    : top-level object directory
+# SRCDIR       : source directory for this module
+# MODULE       : name of the module being built
+#
+# Each individual makefile may define the following additional variables:
+# C_SRCS       : C sources for the module
+# C_SRCS16     : 16-bit C sources for the module
+# RC_SRCS      : resource source files
+# EXTRA_SRCS   : extra source files for make depend
+# EXTRA_OBJS   : extra object files
+# IMPORTS      : dlls to import
+# DELAYIMPORTS : dlls to import in delayed mode
+# SUBDIRS      : subdirectories that contain a Makefile
+# EXTRASUBDIRS : subdirectories that do not contain a Makefile
+# INSTALLSUBDIRS : subdirectories to run make install/uninstall into
+
+# First some useful definitions
+
+SHELL     = /bin/sh
+CC        = gcc
+CFLAGS    = -g -O2
+CPPFLAGS  = 
+LIBS      = 
+BISON     = bison
+YACC      = $(BISON) -y
+LEX       = flex
+LEXLIB    = -lfl
+EXEEXT    = 
+OBJEXT    = o
+LIBEXT    = so
+DLLEXT    = .so
+IMPLIBEXT = def
+LDSHARED  = $(CC) -shared $(SONAME:%=-Wl,-soname,%) $(VERSCRIPT:%=-Wl,--version-script=%)
+DLLTOOL   = false
+DLLWRAP   = 
+AR        = ar rc
+RANLIB    = ranlib
+STRIP     = strip
+WINDRES   = false
+LN        = ln
+LN_S      = ln -s
+TOOLSDIR  = $(TOPOBJDIR)
+AS        = as
+LD        = ld
+LDFLAGS   = 
+RM        = rm -f
+MV        = mv
+LINT      = 
+LINTFLAGS = 
+FONTFORGE = false
+INCLUDES     = -I$(SRCDIR) -I. -I$(TOPSRCDIR)/include -I$(TOPOBJDIR)/include $(EXTRAINCL)
+EXTRACFLAGS  = -Wall -pipe -mpreferred-stack-boundary=2 -fno-strict-aliasing -gstabs+ -Wpointer-arith
+ALLCFLAGS    = $(INCLUDES) $(DEFS) $(DLLFLAGS) $(EXTRACFLAGS) $(CPPFLAGS) $(CFLAGS)
+ALLLINTFLAGS = $(INCLUDES) $(DEFS) $(LINTFLAGS)
+IDLFLAGS     = $(INCLUDES) $(DEFS) $(EXTRAIDLFLAGS)
+MKINSTALLDIRS= $(TOPSRCDIR)/tools/mkinstalldirs -m 755
+WINAPI_CHECK = $(TOPSRCDIR)/tools/winapi/winapi_check
+WINEWRAPPER  = $(TOPSRCDIR)/tools/winewrapper
+C2MAN        = $(TOPSRCDIR)/tools/c2man.pl
+RUNTEST      = $(TOPSRCDIR)/tools/runtest
+WINEBUILD    = $(TOOLSDIR)/tools/winebuild/winebuild
+MAKEDEP      = $(TOOLSDIR)/tools/makedep
+MAKECTESTS   = $(TOOLSDIR)/tools/make_ctests
+WRC          = $(TOOLSDIR)/tools/wrc/wrc
+BIN2RES      = $(TOOLSDIR)/tools/bin2res
+WMC          = $(TOOLSDIR)/tools/wmc/wmc
+WIDL         = $(TOOLSDIR)/tools/widl/widl
+WINEGCC      = $(TOOLSDIR)/tools/winegcc/winegcc
+SFNT2FNT     = $(TOOLSDIR)/tools/sfnt2fnt
+FNT2FON      = $(TOOLSDIR)/tools/fnt2fon
+RC           = $(WRC)
+RC16         = $(WRC)
+RCFLAGS      = --nostdinc $(INCLUDES) $(DEFS) $(EXTRARCFLAGS)
+RC16FLAGS    = -O res16 $(RCFLAGS)
+LDPATH       = LD_LIBRARY_PATH="$(TOOLSDIR)/libs/unicode:$$LD_LIBRARY_PATH"
+DLLDIR       = $(TOPOBJDIR)/dlls
+LIBDIR       = $(TOPOBJDIR)/libs
+LIBPORT      = -L$(TOPOBJDIR)/libs/port -lwine_port
+LIBUNICODE   = -L$(TOPOBJDIR)/libs/unicode -lwine_unicode
+LIBWINE      = -L$(TOPOBJDIR)/libs/wine -lwine
+
+
+
+# Installation infos
+
+INSTALL         = /usr/bin/install -c $(INSTALL_FLAGS)
+INSTALL_PROGRAM = ${INSTALL} $(INSTALL_PROGRAM_FLAGS)
+INSTALL_SCRIPT  = ${INSTALL} $(INSTALL_SCRIPT_FLAGS)
+INSTALL_DATA    = ${INSTALL} -m 644 $(INSTALL_DATA_FLAGS)
+prefix          = /usr/local
+exec_prefix     = ${prefix}
+bindir          = ${exec_prefix}/bin
+libdir          = ${exec_prefix}/lib
+datadir         = ${prefix}/share
+infodir         = ${prefix}/info
+mandir          = ${prefix}/man
+sysconfdir      = ${prefix}/etc
+includedir      = ${prefix}/include/wine
+dlldir          = ${exec_prefix}/lib/wine
+prog_manext     = 1
+api_manext      = 3w
+conf_manext     = 5
+CLEAN_FILES     = *.o *.a *.so *.ln *.$(LIBEXT) \\\#*\\\# *~ *% .\\\#* *.bak *.orig *.rej \
+                  *.flc *.spec.c *.dbg.c *.tab.c *.tab.h lex.yy.c core
+
+OBJS = $(C_SRCS:.c=.o) $(EXTRA_OBJS)
+
+RCOBJS = $(RC_SRCS:.rc=.res.o)
+LINTS  = $(C_SRCS:.c=.ln)
+
+# Implicit rules
+
+.SUFFIXES: .mc .rc .mc.rc .res .res.o .spec .spec.c .idl .tlb .h .ok .sfd .ttf
+
+.c.o:
+	$(CC) -c $(ALLCFLAGS) -o $@ $<
+
+.s.o:
+	$(AS) -o $@ $<
+
+.mc.mc.rc:
+	$(LDPATH) $(WMC) -i -U -H /dev/null -o $@ $<
+
+.rc.res:
+	$(LDPATH) $(RC) $(RCFLAGS) -fo$@ $<
+
+.res.res.o:
+	$(WINDRES) -i $< -o $@
+
+.spec.spec.c:
+	$(WINEBUILD) $(DEFS) --dll -o $@ --main-module $(MODULE) --export $<
+
+.idl.h:
+	$(WIDL) $(IDLFLAGS) -h -H $@ $<
+
+.idl.tlb:
+	$(WIDL) $(IDLFLAGS) -t -T $@ $<
+
+.c.ln:
+	$(LINT) -c $(ALLLINTFLAGS) $< || ( $(RM) $@ && exit 1 )
+
+.c.ok:
+	$(RUNTEST) $(RUNTESTFLAGS) $< && touch $@
+
+.sfd.ttf:
+	$(FONTFORGE) -script $(TOPSRCDIR)/fonts/genttf.ff $<
+
+# 'all' target first in case the enclosing Makefile didn't define any target
+
+all: Makefile
+
+filter:
+	@$(TOPSRCDIR)/tools/winapi/make_filter --make $(MAKE) all
+
+.PHONY: all filter
+
+# Rules for resources
+
+$(RC_BINARIES): $(BIN2RES) $(RC_BINSRC)
+	$(BIN2RES) -f -o $@ $(SRCDIR)/$(RC_BINSRC)
+
+$(RC_SRCS:.rc=.res) $(RC_SRCS16:.rc=.res): $(WRC) $(RC_BINARIES) $(RC_TLB)
+
+# Rule for main module debug channels
+
+$(MODULE).dbg.c: $(C_SRCS) $(C_SRCS16) $(WINEBUILD)
+	$(WINEBUILD) $(DEFS) -o $@ --debug -C$(SRCDIR) $(C_SRCS) $(C_SRCS16)
+
+# Rules for makefile
+
+Makefile: Makefile.in $(TOPSRCDIR)/configure
+	@echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
+	@exit 1
+
+# Rule for linting
+
+$(MODULE).ln : $(LINTS)
+	if test "$(LINTS)" ; \
+	then \
+		$(LINT) $(ALLLINTFLAGS) -o$(MODULE) $(LINTS) ; \
+	        $(MV) llib-l$(MODULE).ln $(MODULE).ln ; \
+	else \
+		$(LINT) $(ALLLINTFLAGS) -C$(MODULE) /dev/null ; \
+	fi
+
+lint:: $(MODULE).ln
+
+# Rules for Windows API checking
+
+winapi_check:: dummy
+	$(WINAPI_CHECK) $(WINAPI_CHECK_FLAGS) $(WINAPI_CHECK_EXTRA_FLAGS) .
+
+.PHONY: winapi_check
+
+# Rules for dependencies
+
+$(SUBDIRS:%=%/__depend__): dummy
+	cd `dirname $@` && $(MAKE) depend
+
+depend: $(IDL_SRCS:.idl=.h) $(SUBDIRS:%=%/__depend__)
+	$(MAKEDEP) $(INCLUDES) -C$(SRCDIR) $(C_SRCS) $(C_SRCS16) $(RC_SRCS) $(RC_SRCS16) $(MC_SRCS) $(IDL_SRCS) $(EXTRA_SRCS)
+
+.PHONY: depend $(SUBDIRS:%=%/__depend__)
+
+# Rules for cleaning
+
+$(SUBDIRS:%=%/__clean__): dummy
+	cd `dirname $@` && $(MAKE) clean
+
+$(SUBDIRS:%=%/__testclean__): dummy
+	cd `dirname $@` && $(MAKE) testclean
+
+$(EXTRASUBDIRS:%=%/__clean__): dummy
+	-cd `dirname $@` && $(RM) $(CLEAN_FILES)
+
+testclean:: $(SUBDIRS:%=%/__testclean__)
+
+clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
+	$(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(RC_SRCS16:.rc=.res) $(MC_SRCS:.mc=.mc.rc) $(IDL_SRCS:.idl=.h) $(PROGRAMS) $(RC_BINARIES) $(RC_TLB)
+
+.PHONY: clean testclean $(SUBDIRS:%=%/__clean__) $(SUBDIRS:%=%/__testclean__) $(EXTRASUBDIRS:%=%/__clean__)
+
+# Rules for installing
+
+$(SUBDIRS:%=%/__install__): dummy
+	cd `dirname $@` && $(MAKE) install
+
+$(SUBDIRS:%=%/__install-lib__): dummy
+	cd `dirname $@` && $(MAKE) install-lib
+
+$(SUBDIRS:%=%/__install-dev__): dummy
+	cd `dirname $@` && $(MAKE) install-dev
+
+$(SUBDIRS:%=%/__uninstall__): dummy
+	cd `dirname $@` && $(MAKE) uninstall
+
+install:: $(INSTALLSUBDIRS:%=%/__install__)
+
+uninstall:: $(INSTALLSUBDIRS:%=%/__uninstall__)
+
+.PHONY: install install-lib install-dev uninstall \
+	$(SUBDIRS:%=%/__install__) $(SUBDIRS:%=%/__uninstall__) \
+	$(SUBDIRS:%=%/__install-lib__) $(SUBDIRS:%=%/__install-dev__)
+
+# Rules for checking that no imports are missing
+
+$(SUBDIRS:%=%/__checklink__): dummy
+	@cd `dirname $@` && $(MAKE) checklink
+
+.PHONY: checklink $(SUBDIRS:%=%/__checklink__)
+
+# Rules for testing
+
+$(SUBDIRS:%=%/__test__): dummy
+	@cd `dirname $@` && $(MAKE) test
+
+$(SUBDIRS:%=%/__crosstest__): dummy
+	@cd `dirname $@` && $(MAKE) crosstest
+
+.PHONY: check test crosstest $(SUBDIRS:%=%/__test__) $(SUBDIRS:%=%/__crosstest__)
+
+# Misc. rules
+
+$(MC_SRCS:.mc=.mc.rc): $(WMC)
+
+$(IDL_SRCS:.idl=.h): $(WIDL)
+
+$(RC_TLB:.idl=.tlb): $(WIDL)
+
+$(SUBDIRS): dummy
+	@cd $@ && $(MAKE)
+
+dummy:
+
+.PHONY: dummy $(SUBDIRS)
+
+# End of global rules
+
+# Rules for .so files
+
+$(MODULE).so: $(MAINSPEC) $(ALL_OBJS) Makefile.in
+	$(WINEGCC) -B$(TOOLSDIR)/tools/winebuild -shared $(SRCDIR)/$(MAINSPEC) $(ALL_OBJS) $(SUBSYSTEM:%=-Wb,--subsystem,%) -o $@ $(DLL_LDPATH) $(ALL_IMPORTS:%=-l%) $(DELAYIMPORTS:%=-Wb,-d%) $(ALL_LIBS)
+
+# Rules for .dll files
+
+$(MODULE): $(RCOBJS) $(OBJS) $(MODULE).dbg.o $(SPEC_DEF) Makefile.in
+	$(DLLWRAP) -k --def $(SPEC_DEF) -o $@ $(RCOBJS) $(OBJS) $(MODULE).dbg.o $(DLL_LDPATH) $(ALL_IMPORTS:%=-l%) $(ALL_LIBS)
+
+# Rules for import libraries
+
+.PHONY: implib static_implib $(IMPLIB_OBJS:%=__static_implib__%)
+
+all implib: $(IMPORTLIB) $(IMPLIB_OBJS:%=__static_implib__%)
+
+$(IMPLIB_OBJS:%=__static_implib__%): $(STATICIMPLIB)
+
+lib$(BASEMODULE).def: $(MAINSPEC)
+	$(WINEBUILD) -w --def -o $@ --export $(SRCDIR)/$(MAINSPEC)
+
+lib$(BASEMODULE).def.a: $(IMPLIB_OBJS)
+	$(RM) $@
+	$(AR) $@ $(IMPLIB_OBJS)
+	$(RANLIB) $@
+
+lib$(BASEMODULE).a: $(SPEC_DEF) $(IMPLIB_OBJS)
+	$(DLLTOOL) -k -l $@ -d $(SPEC_DEF)
+	$(AR) $@ $(IMPLIB_OBJS)
+	$(RANLIB) $@
+
+# Rules for checking that no imports are missing
+
+.PHONY: checklink16 $(WIN16_FILES:%=__checklink16__%)
+
+$(WIN16_FILES:%=__checklink16__%): checklink16
+
+checklink16:: $(MAINSPEC).o $(OBJS) $(MODULE).dbg.o dummy
+	$(CC) -o checklink -Wl,-rpath,$(TOPOBJDIR)/libs $(TOPSRCDIR)/dlls/checklink.c $(MAINSPEC).o $(OBJS) $(MODULE).dbg.o -L$(DLLDIR) $(ALL_LIBS) -lm && $(RM) checklink $(MAINSPEC).c $(MAINSPEC).o
+
+checklink:: $(WIN16_FILES:%=__checklink16__%)
+
+# Rules for testing
+
+check test:: $(SUBDIRS:%=%/__test__)
+
+crosstest:: $(SUBDIRS:%=%/__crosstest__)
+
+# Rule to explicitly generate the .spec.c for debugging
+
+$(MAINSPEC).c: $(MAINSPEC) $(ALL_OBJS)
+	$(WINEBUILD) $(DEFS) $(DLLFLAGS) --dll -o $@ --export $(SRCDIR)/$(MAINSPEC) $(SUBSYSTEM:%=--subsystem %) $(ALL_OBJS) $(DLL_LDPATH) $(ALL_IMPORTS:%=-l%) $(DELAYIMPORTS:%=-d%)
+
+# Rules for auto documentation
+
+man: $(C_SRCS)
+	$(C2MAN) -o $(TOPOBJDIR)/documentation/man$(api_manext) -R$(TOPOBJDIR) -C$(SRCDIR) -S$(api_manext) $(INCLUDES) $(MAINSPEC:%=-w %) $(SPEC_SRCS16:%=-w %) $(C_SRCS) $(C_SRCS16)
+
+doc-html: $(C_SRCS)
+	$(C2MAN) -o $(TOPOBJDIR)/documentation/html -R$(TOPOBJDIR) -C$(SRCDIR) $(INCLUDES) -Th $(MAINSPEC:%=-w %) $(SPEC_SRCS16:%=-w %) $(C_SRCS) $(C_SRCS16)
+
+doc-sgml: $(C_SRCS)
+	$(C2MAN) -o $(TOPOBJDIR)/documentation/api-guide -R$(TOPOBJDIR) -C$(SRCDIR) $(INCLUDES) -Ts $(MAINSPEC:%=-w %) $(SPEC_SRCS16:%=-w %) $(C_SRCS) $(C_SRCS16)
+
+.PHONY: man doc-html doc-sgml
+
+# Rules for installation
+
+EXE_SPECS16 = $(SPEC_SRCS16:.exe.spec=.exe)
+DRV_SPECS16 = $(EXE_SPECS16:.drv.spec=.drv)
+ALL_SPECS16 = $(DRV_SPECS16:.spec=.dll)
+
+WIN16_INSTALL = $(ALL_SPECS16:%=_install_/%)
+
+.PHONY: install_lib install_static_implib_def install_static_implib_a
+.PHONY: $(ALL_SPECS16:%=_install_/%) $(IMPORTLIB:%=_install_/%) $(IMPLIB_OBJS:%=_install_static_implib_/%)
+
+$(ALL_SPECS16:%=_install_/%): install_lib
+	cd $(dlldir) && $(RM) `basename $@`$(DLLEXT) && $(LN_S) $(MODULE)$(DLLEXT) `basename $@`$(DLLEXT)
+
+install_lib: $(MODULE)$(DLLEXT)
+	$(MKINSTALLDIRS) $(dlldir)
+	$(INSTALL_PROGRAM) $(MODULE)$(DLLEXT) $(dlldir)/$(MODULE)$(DLLEXT)
+
+$(IMPORTLIB:%=_install_/%): $(IMPORTLIB)
+	$(MKINSTALLDIRS) $(dlldir)
+	$(INSTALL_DATA) $(IMPORTLIB) $(dlldir)/$(IMPORTLIB)
+
+install_static_implib_def: $(STATICIMPLIB)
+	$(MKINSTALLDIRS) $(dlldir)
+	$(INSTALL_DATA) $(STATICIMPLIB) $(dlldir)/$(STATICIMPLIB)
+
+install_static_implib_a:
+
+$(IMPLIB_OBJS:%=_install_static_implib_/%): install_static_implib_$(IMPLIBEXT)
+
+install install-lib:: install_lib $(WIN16_INSTALL)
+
+install install-dev:: $(IMPORTLIB:%=_install_/%) $(IMPLIB_OBJS:%=_install_static_implib_/%)
+
+uninstall::
+	[ ! -d $(dlldir) ] || (cd $(dlldir) && $(RM) $(MODULE)$(DLLEXT) $(IMPORTLIB) $(STATICIMPLIB) $(ALL_SPECS16:%=%$(DLLEXT)))
+
+# Misc. rules
+
+clean::
+	$(RM) $(SPEC_DEF)
+
+$(SPEC_DEF) $(SPEC_SRCS16:.spec=.spec.c): $(WINEBUILD)
+
+# End of global dll rules
+
+### Dependencies:
+esound.o: esound.c ../../../include/config.h ../../../include/windef.h \
+ ../../../include/winnt.h ../../../include/basetsd.h \
+ ../../../include/pshpack2.h ../../../include/poppack.h \
+ ../../../include/pshpack4.h ../../../include/guiddef.h \
+ ../../../include/pshpack8.h ../../../include/winbase.h \
+ ../../../include/winerror.h ../../../include/wingdi.h \
+ ../../../include/winuser.h ../../../include/mmddk.h \
+ ../../../include/mmsystem.h ../../../include/pshpack1.h ./esound.h
+audio.o: audio.c ../../../include/config.h ../../../include/windef.h \
+ ../../../include/winnt.h ../../../include/basetsd.h \
+ ../../../include/pshpack2.h ../../../include/poppack.h \
+ ../../../include/pshpack4.h ../../../include/guiddef.h \
+ ../../../include/pshpack8.h ../../../include/winbase.h \
+ ../../../include/winerror.h ../../../include/wingdi.h \
+ ../../../include/wine/winuser16.h ../../../include/wine/wingdi16.h \
+ ../../../include/wine/winbase16.h ../../../include/winnls.h \
+ ../../../include/wine/windef16.h ../../../include/pshpack1.h \
+ ../../../include/wine/library.h ../../../include/winuser.h \
+ ../../../include/mmddk.h ../../../include/mmsystem.h \
+ ../../../include/dsound.h ../../../include/objbase.h \
+ ../../../include/rpc.h ../../../include/windows.h \
+ ../../../include/winresrc.h ../../../include/commctrl.h \
+ ../../../include/prsht.h ../../../include/dde.h \
+ ../../../include/dlgs.h ../../../include/winver.h \
+ ../../../include/excpt.h ../../../include/wincon.h \
+ ../../../include/winreg.h ../../../include/reason.h \
+ ../../../include/winnetwk.h ../../../include/cderr.h \
+ ../../../include/ddeml.h ../../../include/lzexpand.h \
+ ../../../include/nb30.h ../../../include/shellapi.h \
+ ../../../include/winsock2.h ../../../include/winsock.h \
+ ../../../include/wincrypt.h ../../../include/winspool.h \
+ ../../../include/ole2.h ../../../include/oleauto.h \
+ ../../../include/oaidl.h ../../../include/rpcndr.h \
+ ../../../include/objidl.h ../../../include/unknwn.h \
+ ../../../include/wtypes.h ../../../include/oleidl.h \
+ ../../../include/commdlg.h ../../../include/winsvc.h \
+ ../../../include/mcx.h ../../../include/imm.h \
+ ../../../include/rpcdce.h ../../../include/rpcdcep.h \
+ ../../../include/rpcnterr.h ../../../include/cguid.h \
+ ../../../include/propidl.h ../../../include/dsdriver.h ./esound.h \
+ ../../../include/wine/debug.h


-- 
Peter Åstrand		Chief Developer
Cendio			www.thinlinc.com
Teknikringen 3		www.cendio.se
583 30 Linköping        Phone: +46-13-21 46 00


More information about the wine-patches mailing list