[chocolate-doom] 01/07: Reproduce the behavior when playing a sound at a sample rate which is not 11025 or 22050Hz. This is to "fix" a bug in Scientist 2: however, it does not fix the playing of sounds, only silence them. I tested Vanilla Doom and this is how it behaves when it receives sound effects with odd sample rates. The bug here is actually in the Scientist 2 WAD, which has sound effects that have the wrong sample rate.

Jonathan Dowland jmtd at moszumanska.debian.org
Mon Jan 30 15:07:09 UTC 2017


This is an automated email from the git hooks/post-receive script.

jmtd pushed a commit to annotated tag chocolate-doom-0.1.2
in repository chocolate-doom.

commit f12587122d8e22cac6a02cd9788a792a02301f28
Author: Simon Howard <fraggle at gmail.com>
Date:   Sun Oct 23 18:39:45 2005 +0000

    Reproduce the behavior when playing a sound at a sample rate which
    is not 11025 or 22050Hz. This is to "fix" a bug in Scientist 2:
    however, it does not fix the playing of sounds, only silence
    them. I tested Vanilla Doom and this is how it behaves when it
    receives sound effects with odd sample rates. The bug here is
    actually in the Scientist 2 WAD, which has sound effects that
    have the wrong sample rate.
    
    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 221
---
 NEWS          |  3 +++
 src/i_sound.c | 44 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index 05fb101..5be4f22 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,7 @@
 
+    Silence sounds at odd sample rates (rather than bombing out); this
+        is the way Vanilla Doom behaves.
+
 0.1.1 (2005-10-18):
     Display startup "banners" if they have been modified through 
         dehacked.
diff --git a/src/i_sound.c b/src/i_sound.c
index 0c93f54..76c456b 100644
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_sound.c 196 2005-10-15 16:58:31Z fraggle $
+// $Id: i_sound.c 221 2005-10-23 18:39:45Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,15 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.22  2005/10/23 18:39:45  fraggle
+// Reproduce the behavior when playing a sound at a sample rate which
+// is not 11025 or 22050Hz.  This is to "fix" a bug in Scientist 2:
+// however, it does not fix the playing of sounds, only silence
+// them.  I tested Vanilla Doom and this is how it behaves when it
+// receives sound effects with odd sample rates.  The bug here is
+// actually in the Scientist 2 WAD, which has sound effects that
+// have the wrong sample rate.
+//
 // Revision 1.21  2005/10/15 16:58:31  fraggle
 // Fix MIDI music not pausing when using SDL_mixer's native MIDI playback.
 // The SDL_mixer native MIDI code does not pause music properly - use
@@ -101,7 +110,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_sound.c 196 2005-10-15 16:58:31Z fraggle $";
+rcsid[] = "$Id: i_sound.c 221 2005-10-23 18:39:45Z fraggle $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -197,15 +206,12 @@ static void ExpandSoundData(byte *data, int samplerate, int length,
             expanded[i * 4 + 1] = expanded[i * 4 + 3] = (sample >> 8) & 0xff;
         }
     }
-    else
-    {
-        I_Error("Unsupported sample rate %i", samplerate);
-    }
 }
 
 // Load and convert a sound effect
+// Returns true if successful
 
-static void CacheSFX(int sound)
+static boolean CacheSFX(int sound)
 {
     int lumpnum;
     int samplerate;
@@ -220,6 +226,17 @@ static void CacheSFX(int sound)
 
     samplerate = (data[3] << 8) | data[2];
     length = (data[5] << 8) | data[4];
+
+    if (samplerate != 11025 && samplerate != 22050)
+    {
+        // Sounds with unsupported sound rates are not played
+        // in Vanilla Doom.  As far as I know there are no other
+        // supported sound sample rates apart from these two, but
+        // it is possible there are others.
+
+        return false;
+    }
+
     expanded_length = (length * 4)  * (22050 / samplerate);
 
     sound_chunks[sound].allocated = 1;
@@ -233,13 +250,16 @@ static void CacheSFX(int sound)
     // don't need the original lump any more
   
     Z_ChangeTag(data, PU_CACHE);
+
+    return true;
 }
 
 static Mix_Chunk *getsfx(int sound)
 {
     if (sound_chunks[sound].abuf == NULL)
     {
-        CacheSFX(sound);
+        if (!CacheSFX(sound))
+            return NULL;
     }
     else
     {
@@ -321,6 +341,11 @@ I_StartSound
 
     chunk = getsfx(id);
 
+    if (chunk == NULL)
+    {
+        return -1;
+    }
+
     // play sound
 
     Mix_PlayChannelTimed(channel, chunk, 0, -1);
@@ -353,6 +378,9 @@ int I_SoundIsPlaying(int handle)
     if (!sound_initialised) 
         return false;
 
+    if (handle < 0)
+        return false;
+
     return Mix_Playing(handle);
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/chocolate-doom.git



More information about the Pkg-games-commits mailing list