[winecfg] add sound driver test

Robert Reif reif at earthlink.net
Sun Nov 13 18:30:17 CST 2005


Changelog:
- add a simple sound driver test

Download the test wave file from:

http://csr.slightofcode.com/wine/testsound1.wav

and copy it to programs/winecfg and rename it to winecfg.wav.

Thanks to Randall Walls for the wave file.

To Do:
- better driver loading and status as requested by Eric Pouech
- update rc files for other languages
-------------- next part --------------
Index: programs/winecfg/En.rc
===================================================================
RCS file: /home/wine/wine/programs/winecfg/En.rc,v
retrieving revision 1.54
diff -p -u -r1.54 En.rc
--- programs/winecfg/En.rc	27 Oct 2005 11:24:02 -0000	1.54
+++ programs/winecfg/En.rc	14 Nov 2005 00:17:25 -0000
@@ -157,13 +157,14 @@ BEGIN
     COMBOBOX	IDC_AUDIO_DRIVER,70,18,85,85,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
     PUSHBUTTON	"Autodetect",IDC_AUDIO_AUTODETECT,170,20,49,14
     PUSHBUTTON	"Configure",IDC_AUDIO_CONFIGURE,170,40,49,14
-    PUSHBUTTON	"Control Panel",IDC_AUDIO_CONTROL_PANEL,170,60,49,14
+    PUSHBUTTON	"Test",IDC_AUDIO_TEST,170,60,49,14
+    PUSHBUTTON	"Control Panel",IDC_AUDIO_CONTROL_PANEL,170,80,49,14
 
-    GROUPBOX    " DirectSound ",IDC_STATIC,8,75,244,120
+    GROUPBOX    " DirectSound ",IDC_STATIC,8,95,244,120
 
-    LTEXT	"Hardware Acceleration: ",IDC_STATIC,15,85,90,10
-    COMBOBOX	IDC_DSOUND_HW_ACCEL,100,83,150,70,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
-    CONTROL     "Driver Emulation",IDC_DSOUND_DRV_EMUL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,100,230,10
+    LTEXT	"Hardware Acceleration: ",IDC_STATIC,15,105,90,10
+    COMBOBOX	IDC_DSOUND_HW_ACCEL,100,103,150,70,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+    CONTROL     "Driver Emulation",IDC_DSOUND_DRV_EMUL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,120,230,10
 
 END
 
@@ -197,6 +198,8 @@ BEGIN
     IDS_WINECFG_TITLE       "Wine configuration"
     IDS_THEMEFILE           "Theme files"
     IDS_THEMEFILE_SELECT    "Select a theme file"
+    IDS_AUDIO_DONE          "Done playing test sound."
+    IDS_AUDIO_ERROR         "Couldn't play test sound. "
 END
 
 
Index: programs/winecfg/Makefile.in
===================================================================
RCS file: /home/wine/wine/programs/winecfg/Makefile.in,v
retrieving revision 1.15
diff -p -u -r1.15 Makefile.in
--- programs/winecfg/Makefile.in	24 Aug 2005 10:59:40 -0000	1.15
+++ programs/winecfg/Makefile.in	14 Nov 2005 00:17:25 -0000
@@ -4,7 +4,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = winecfg.exe
 APPMODE   = -mwindows
-IMPORTS   = comdlg32 comctl32 shell32 ole32 winmm shlwapi uxtheme user32 advapi32 kernel32
+IMPORTS   = comdlg32 comctl32 shell32 ole32 shlwapi uxtheme user32 advapi32 kernel32
 
 C_SRCS = \
 	appdefaults.c \
@@ -21,7 +21,7 @@ C_SRCS = \
 
 RC_SRCS = winecfg.rc
 RC_BINSRC = winecfg.rc
-RC_BINARIES = idb_wine.bmp 
+RC_BINARIES = idb_wine.bmp winecfg.wav 
 
 @MAKE_PROG_RULES@
 
Index: programs/winecfg/audio.c
===================================================================
RCS file: /home/wine/wine/programs/winecfg/audio.c,v
retrieving revision 1.15
diff -p -u -r1.15 audio.c
--- programs/winecfg/audio.c	3 Nov 2005 19:31:45 -0000	1.15
+++ programs/winecfg/audio.c	14 Nov 2005 00:17:25 -0000
@@ -52,6 +52,68 @@ static const char* DSound_HW_Accels[] = 
   NULL
 };
 
+static HINSTANCE hWINMM = 0;
+static BOOL has_winmm = FALSE;
+
+HDRVR (WINAPI * pOpenDriverA)(LPCSTR lpDriverName, LPCSTR lpSectionName, LONG lParam);
+LRESULT (WINAPI *pSendDriverMessage)(HDRVR hdrvr, UINT msg, LONG lParam1, LONG lParam2);
+LRESULT (WINAPI *pCloseDriver)(HDRVR hdrvr, LONG lParam1, LONG lParam2);
+BOOL (WINAPI *pPlaySound)(LPCSTR pszSound, HMODULE hmod, DWORD fdwSound);
+
+static void loadWinmm()
+{
+    has_winmm = FALSE;
+
+    /* unload the current sound driver if present */
+    if (hWINMM)
+        while (FreeLibrary(hWINMM));
+    
+    hWINMM = LoadLibrary("winmm.dll");
+    if (!hWINMM) {
+        MessageBox(NULL, "Couldn't load winmm.dll", "Error", MB_OK | MB_ICONERROR);
+        return;
+    }
+
+    pOpenDriverA = (void*)GetProcAddress(hWINMM, "OpenDriverA");
+    pSendDriverMessage = (void*)GetProcAddress(hWINMM, "SendDriverMessage");
+    pCloseDriver = (void*)GetProcAddress(hWINMM, "CloseDriver");
+    pPlaySound = (void*)GetProcAddress(hWINMM, "PlaySound");
+
+    if (!pOpenDriverA || !pSendDriverMessage || !pCloseDriver || !pPlaySound)
+    {
+        MessageBox(NULL, "Couldn't load entried from  winmm.dll", "Error", MB_OK | MB_ICONERROR);
+        return;
+    }
+
+    has_winmm = TRUE;
+}
+
+/* play a wave file from a resource */
+static void testAudioDriver(HWND hDlg)
+{ 
+    if (has_winmm) {
+         WCHAR title[64];
+
+         LoadStringW(GetModuleHandle(NULL), IDS_WINECFG_TITLE, title,
+             sizeof(title)/sizeof(title[0]));
+
+         if (pPlaySound("#300", NULL, SND_RESOURCE)) {
+             WCHAR wave_done[64];
+
+             LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_DONE,
+                 wave_done, sizeof(wave_done)/sizeof(wave_done[0]));
+             MessageBoxW(hDlg, wave_done, title, MB_OK);
+             pPlaySound(NULL, NULL, SND_RESOURCE);
+         } else {
+             WCHAR wave_error[64];
+
+             LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_ERROR,
+                 wave_error, sizeof(wave_error)/sizeof(wave_error[0]));
+             MessageBoxW(hDlg, wave_error, title, MB_OK);
+         }
+     }
+}
+
 /* Select the correct entry in the combobox based on drivername */
 static void selectAudioDriver(HWND hDlg, const char *drivername)
 {
@@ -78,6 +140,9 @@ static void configureAudioDriver(HWND hD
   int i;
   const AUDIO_DRIVER *pAudioDrv = NULL;
 
+  if (!has_winmm)
+    return;
+
   if ((pAudioDrv = getAudioDrivers()))
   {
     for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++)
@@ -89,19 +154,19 @@ static void configureAudioDriver(HWND hD
           HDRVR hdrvr;
 	  char wine_driver[MAX_NAME_LENGTH + 8];
 	  sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
-          hdrvr = OpenDriverA(wine_driver, 0, 0);
+          hdrvr = pOpenDriverA(wine_driver, 0, 0);
 	  if (hdrvr != 0)
 	  {
-	    if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
+	    if (pSendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
 	    {
               DRVCONFIGINFO dci;
               LONG lRes;
               dci.dwDCISize = sizeof (dci);
               dci.lpszDCISectionName = NULL;
               dci.lpszDCIAliasName = NULL;
-              lRes = SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG)&dci);
+              lRes = pSendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG)&dci);
 	    }
-	    CloseDriver(hdrvr, 0, 0);
+	    pCloseDriver(hdrvr, 0, 0);
 	  }
           else
           {
@@ -125,6 +190,8 @@ static void initAudioDlg (HWND hDlg)
 
     WINE_TRACE("\n");
 
+    loadWinmm();
+
     pAudioDrv = getAudioDrivers ();
     for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++) {
         SendDlgItemMessage (hDlg, IDC_AUDIO_DRIVER, CB_ADDSTRING, 
@@ -272,6 +339,9 @@ AudioDlgProc (HWND hDlg, UINT uMsg, WPAR
 		configureAudioDriver(hDlg, (char*)pAudioDrv[selected_driver].szDriver);
 	     }
 	     break;
+          case IDC_AUDIO_TEST:
+             testAudioDriver(hDlg);
+             break;
           case IDC_AUDIO_CONTROL_PANEL:
 	     MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
              break;
@@ -305,6 +375,7 @@ AudioDlgProc (HWND hDlg, UINT uMsg, WPAR
 	      SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
 	      break;
 	    case PSN_APPLY:
+              loadWinmm(); /* load the new driver */
               apply();
 	      SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
 	      break;
Index: programs/winecfg/resource.h
===================================================================
RCS file: /home/wine/wine/programs/winecfg/resource.h,v
retrieving revision 1.33
diff -p -u -r1.33 resource.h
--- programs/winecfg/resource.h	27 Oct 2005 11:24:02 -0000	1.33
+++ programs/winecfg/resource.h	14 Nov 2005 00:17:26 -0000
@@ -39,6 +39,8 @@
 #define IDS_WINECFG_TITLE               13
 #define IDS_THEMEFILE                   14
 #define IDS_THEMEFILE_SELECT            15
+#define IDS_AUDIO_DONE                  16
+#define IDS_AUDIO_ERROR                 17
 #define IDD_MAINDLG                     101
 #define IDB_WINE                        104
 #define IDD_ABOUTCFG                    107
@@ -50,6 +52,7 @@
 #define IDD_DRIVE_EDIT                  114
 #define IDD_APPEARANCE                  115
 #define IDB_WINE_LOGO                   200
+#define IDR_WAVE                        300
 #define IDC_TABABOUT                    1001
 #define IDC_APPLYBTN                    1002
 #define IDC_WINVER                      1012
@@ -136,9 +139,10 @@
 #define IDC_AUDIO_AUTODETECT            1300
 #define IDC_AUDIO_DRIVER                1301
 #define IDC_AUDIO_CONFIGURE             1302
-#define IDC_AUDIO_CONTROL_PANEL         1303
-#define IDC_DSOUND_HW_ACCEL             1304
-#define IDC_DSOUND_DRV_EMUL             1305
+#define IDC_AUDIO_TEST                  1303
+#define IDC_AUDIO_CONTROL_PANEL         1304
+#define IDC_DSOUND_HW_ACCEL             1305
+#define IDC_DSOUND_DRV_EMUL             1306
 
 /* appearance tab */
 #define IDC_THEME_COLORCOMBO            1401
Index: programs/winecfg/winecfg.rc
===================================================================
RCS file: /home/wine/wine/programs/winecfg/winecfg.rc,v
retrieving revision 1.24
diff -p -u -r1.24 winecfg.rc
--- programs/winecfg/winecfg.rc	13 Oct 2005 14:24:52 -0000	1.24
+++ programs/winecfg/winecfg.rc	14 Nov 2005 00:17:27 -0000
@@ -963,3 +963,5 @@ IDB_WINE BITMAP idb_wine.bmp
  '1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B'
  '1B 1B 1B 1B 00 00'
 } */
+
+IDR_WAVE WAVE DISCARDABLE winecfg.wav


More information about the wine-patches mailing list