shithub: choc

Download patch

ref: 770fb3d7c7c23bc9b101ebbf314b142a440f6637
parent: 5f4628dcc6400e64f62ad7c3afaac2046f8b1e9a
author: Simon Howard <fraggle@gmail.com>
date: Fri Aug 3 18:17:15 EDT 2007

Fix 'pop' at the end of sound effects caused by an audio conversion bug.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 943

--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -199,13 +199,19 @@
     // If the header specifies that the length of the sound is greater than
     // the length of the lump itself, this is an invalid sound lump
 
-    if (length - 8 > lumplen)
+    if (length > lumplen - 8)
     {
         return false;
     }
 
-    expanded_length = (uint32_t) ((((uint64_t) length) * 4 * mixer_freq) / samplerate);
+    // Sample rate conversion
 
+    expanded_length = (uint32_t) ((((uint64_t) length) * mixer_freq) / samplerate);
+
+    // Double up twice: 8 -> 16 bit and mono -> stereo
+
+    expanded_length *= 4;
+
     sound_chunks[sound].allocated = 1;
     sound_chunks[sound].alen = expanded_length;
     sound_chunks[sound].abuf 
@@ -214,7 +220,7 @@
 
     ExpandSoundData(data + 8, 
                     samplerate, 
-                    length - 8, 
+                    length, 
                     &sound_chunks[sound]);
 
     // don't need the original lump any more