summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2005-10-23 18:39:45 +0000
committerSimon Howard2005-10-23 18:39:45 +0000
commitf12587122d8e22cac6a02cd9788a792a02301f28 (patch)
treee75d5b92a3c52bfb03c5877751ad283a04eb046a /src
parent3cd87afdf465b3ecb3d9711161d3c40564b4583f (diff)
downloadchocolate-doom-f12587122d8e22cac6a02cd9788a792a02301f28.tar.gz
chocolate-doom-f12587122d8e22cac6a02cd9788a792a02301f28.tar.bz2
chocolate-doom-f12587122d8e22cac6a02cd9788a792a02301f28.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/i_sound.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/i_sound.c b/src/i_sound.c
index 0c93f540..76c456b8 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);
}