[wavemap] fix non pcm bug

Robert Reif reif at earthlink.net
Tue Nov 15 23:25:15 CST 2005


This fixes a bug I introduced in Aug 2004 for non-pcm wave formats.
I was originally seeing crashes with different format tags so I didn't
allow non PCM formats.  The real problem was we were doing
both format tag conversions and sample rate and number of channel
conversions on non PCM formats which was wrong.  This patch
fixes this problem correctly.

Changelog:
 - Only convert bits per sample between different encoding formats.
-------------- next part --------------
Index: dlls/winmm/wavemap/wavemap.c
===================================================================
RCS file: /home/wine/wine/dlls/winmm/wavemap/wavemap.c,v
retrieving revision 1.45
diff -p -u -r1.45 wavemap.c
--- dlls/winmm/wavemap/wavemap.c	2 Sep 2005 12:26:21 -0000	1.45
+++ dlls/winmm/wavemap/wavemap.c	16 Nov 2005 05:07:35 -0000
@@ -194,7 +194,7 @@ static	DWORD	wodOpen(LPDWORD lpdwUser, L
 	}
     }
 
-    if ((dwFlags & WAVE_FORMAT_DIRECT) == 0 && lpDesc->lpFormat->wFormatTag == WAVE_FORMAT_PCM) {
+    if ((dwFlags & WAVE_FORMAT_DIRECT) == 0) {
         WAVEFORMATEX	wfx;
 
         wfx.wFormatTag = WAVE_FORMAT_PCM;
@@ -208,51 +208,63 @@ static	DWORD	wodOpen(LPDWORD lpdwUser, L
                             default: goto error; \
                         }
 
-        /* Our resampling algorithm is quite primitive so first try
-         * to just change the bit depth and number of channels
-         */
-        for (i = ndlo; i < ndhi; i++) {
-            wfx.nSamplesPerSec=lpDesc->lpFormat->nSamplesPerSec;
-            wfx.nChannels = lpDesc->lpFormat->nChannels;
-            TRY(wfx.nSamplesPerSec, 16);
-            TRY(wfx.nSamplesPerSec, 8);
-            wfx.nChannels ^= 3;
-            TRY(wfx.nSamplesPerSec, 16);
-            TRY(wfx.nSamplesPerSec, 8);
-        }
-
-        for (i = ndlo; i < ndhi; i++) {
-            /* first try with same stereo/mono option as source */
-            wfx.nChannels = lpDesc->lpFormat->nChannels;
-            TRY(96000, 16);
-            TRY(48000, 16);
-            TRY(44100, 16);
-            TRY(22050, 16);
-            TRY(11025, 16);
-
-            /* 2^3 => 1, 1^3 => 2, so if stereo, try mono (and the other way around) */
-            wfx.nChannels ^= 3;
-            TRY(96000, 16);
-            TRY(48000, 16);
-            TRY(44100, 16);
-            TRY(22050, 16);
-            TRY(11025, 16);
-
-            /* first try with same stereo/mono option as source */
-            wfx.nChannels = lpDesc->lpFormat->nChannels;
-            TRY(96000, 8);
-            TRY(48000, 8);
-            TRY(44100, 8);
-            TRY(22050, 8);
-            TRY(11025, 8);
+        if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
+            /* Format changed so keep sample rate and number of channels 
+             * the same and just change the bit depth
+             */
+            for (i = ndlo; i < ndhi; i++) {
+                wfx.nSamplesPerSec=lpDesc->lpFormat->nSamplesPerSec;
+                wfx.nChannels = lpDesc->lpFormat->nChannels;
+                TRY(wfx.nSamplesPerSec, 16);
+                TRY(wfx.nSamplesPerSec, 8);
+            }
+        } else {
+            /* Our resampling algorithm is quite primitive so first try
+             * to just change the bit depth and number of channels
+             */
+            for (i = ndlo; i < ndhi; i++) {
+                wfx.nSamplesPerSec=lpDesc->lpFormat->nSamplesPerSec;
+                wfx.nChannels = lpDesc->lpFormat->nChannels;
+                TRY(wfx.nSamplesPerSec, 16);
+                TRY(wfx.nSamplesPerSec, 8);
+                wfx.nChannels ^= 3;
+                TRY(wfx.nSamplesPerSec, 16);
+                TRY(wfx.nSamplesPerSec, 8);
+            }
 
-            /* 2^3 => 1, 1^3 => 2, so if stereo, try mono (and the other way around) */
-            wfx.nChannels ^= 3;
-            TRY(96000, 8);
-            TRY(48000, 8);
-            TRY(44100, 8);
-            TRY(22050, 8);
-            TRY(11025, 8);
+            for (i = ndlo; i < ndhi; i++) {
+                /* first try with same stereo/mono option as source */
+                wfx.nChannels = lpDesc->lpFormat->nChannels;
+                TRY(96000, 16);
+                TRY(48000, 16);
+                TRY(44100, 16);
+                TRY(22050, 16);
+                TRY(11025, 16);
+
+                /* 2^3 => 1, 1^3 => 2, so if stereo, try mono (and the other way around) */
+                wfx.nChannels ^= 3;
+                TRY(96000, 16);
+                TRY(48000, 16);
+                TRY(44100, 16);
+                TRY(22050, 16);
+                TRY(11025, 16);
+
+                /* first try with same stereo/mono option as source */
+                wfx.nChannels = lpDesc->lpFormat->nChannels;
+                TRY(96000, 8);
+                TRY(48000, 8);
+                TRY(44100, 8);
+                TRY(22050, 8);
+                TRY(11025, 8);
+
+                /* 2^3 => 1, 1^3 => 2, so if stereo, try mono (and the other way around) */
+                wfx.nChannels ^= 3;
+                TRY(96000, 8);
+                TRY(48000, 8);
+                TRY(44100, 8);
+                TRY(22050, 8);
+                TRY(11025, 8);
+            }
         }
 #undef TRY
     }


More information about the wine-patches mailing list