Imported new Eternity Engine sound code. Applied EE priority/singularity/pitch/volume bug fixes. Fixed conflicts between SDL.h and z_zone.h.

This commit is contained in:
James Haley 2008-06-16 21:52:45 -05:00
parent 9ab0817c7c
commit c2035e5ff7
10 changed files with 1200 additions and 616 deletions

5
.gitignore vendored
View File

@ -15,3 +15,8 @@
.*.swp
.DS_store
# Simulated Subversion default ignores end here
# The contents of the svn:ignore property on the branch root.
/Debug
/WinMBF.opt
/WinMBF.plg
/WinMBF.ncb

View File

@ -29,13 +29,14 @@
static const char
rcsid[] = "$Id: i_main.c,v 1.8 1998/05/15 00:34:03 killough Exp $";
#include "SDL.h" // haleyjd
#include "z_zone.h"
#include "doomdef.h"
#include "m_argv.h"
#include "d_main.h"
#include "i_system.h"
#include "SDL.h" // haleyjd
void I_Quit(void);
// haleyjd: SDL init flags
@ -52,6 +53,34 @@ int main(int argc, char **argv)
myargc = argc;
myargv = argv;
// SoM: From CHOCODOOM Thank you fraggle!!
#ifdef _WIN32
// Allow -gdi as a shortcut for using the windib driver.
//!
// @category video
// @platform windows
//
// Use the Windows GDI driver instead of DirectX.
//
// From the SDL 1.2.10 release notes:
//
// > The "windib" video driver is the default now, to prevent
// > problems with certain laptops, 64-bit Windows, and Windows
// > Vista.
//
// The hell with that.
// SoM: the gdi interface is much faster for windowed modes which are more
// commonly used. Thus, GDI is default.
if(M_CheckParm("-directx"))
putenv("SDL_VIDEODRIVER=directx");
else if(M_CheckParm("-gdi") > 0 || getenv("SDL_VIDEODRIVER") == NULL)
putenv("SDL_VIDEODRIVER=windib");
#endif
// haleyjd: init SDL
if(SDL_Init(INIT_FLAGS) == -1)
{
@ -59,9 +88,6 @@ int main(int argc, char **argv)
return -1;
}
// haleyjd: ignore mouse events at startup
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
// haleyjd: set key repeat properties
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY/2, SDL_DEFAULT_REPEAT_INTERVAL*4);

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,7 @@ extern char* sndserver_filename;
#endif
// Init at program start...
void I_InitSound();
void I_InitSound(void);
// ... update sound buffer and audio device at runtime...
void I_UpdateSound(void);
@ -55,13 +55,14 @@ void I_ShutdownSound(void);
//
// Initialize channels?
void I_SetChannels();
void I_SetChannels(void);
// Get raw data lump index for sound descriptor.
int I_GetSfxLumpNum (sfxinfo_t *sfxinfo);
int I_GetSfxLumpNum(sfxinfo_t *sfxinfo);
// Starts a sound in a particular sound channel.
int I_StartSound(int id, int vol, int sep, int pitch, int priority);
int I_StartSound(sfxinfo_t *sound, int cnum, int vol, int sep, int pitch,
int pri);
// Stops a sound channel.
void I_StopSound(int handle);
@ -75,6 +76,9 @@ int I_SoundIsPlaying(int handle);
// and pitch of a sound channel.
void I_UpdateSoundParams(int handle, int vol, int sep, int pitch);
// haleyjd
int I_SoundID(int handle);
//
// MUSIC I/O
//
@ -89,7 +93,7 @@ void I_PauseSong(int handle);
void I_ResumeSong(int handle);
// Registers a song handle to song data.
int I_RegisterSong(void *data);
int I_RegisterSong(void *data, int size);
// Called by anything that wishes to start music.
// plays a song, and when the song is done,

View File

@ -28,8 +28,6 @@
static const char
rcsid[] = "$Id: i_system.c,v 1.14 1998/05/03 22:33:13 killough Exp $";
#include <stdio.h>
// haleyjd
#ifdef _MSC_VER
#include <conio.h>
@ -38,7 +36,7 @@ rcsid[] = "$Id: i_system.c,v 1.14 1998/05/03 22:33:13 killough Exp $";
#include "SDL.h"
#include "z_zone.h"
#include "i_system.h"
#include "i_sound.h"
#include "doomstat.h"
@ -84,7 +82,7 @@ static Long64 I_GetTime_Scale = 1<<24;
int I_GetTime_Scaled(void)
{
// haleyjd:
return (Long64) I_GetTime_RealTime() * I_GetTime_Scale >> 24;
return (int)((Long64) I_GetTime_RealTime() * I_GetTime_Scale >> 24);
}
static int I_GetTime_FastDemo(void)

View File

@ -29,12 +29,9 @@
static const char
rcsid[] = "$Id: i_video.c,v 1.12 1998/05/03 22:40:35 killough Exp $";
#include "z_zone.h" /* memory allocation wrappers -- killough */
#include <stdio.h>
#include "SDL.h" // haleyjd
#include "z_zone.h" /* memory allocation wrappers -- killough */
#include "doomstat.h"
#include "v_video.h"
#include "d_main.h"

View File

@ -66,11 +66,17 @@ extern int snd_card, mus_card;
extern boolean nosfxparm, nomusicparm;
//jff end sound enabling variables readable here
typedef struct
typedef struct channel_s
{
sfxinfo_t *sfxinfo; // sound information (if null, channel avail.)
const mobj_t *origin;// origin of sound
int handle; // handle of the sound being played
sfxinfo_t *sfxinfo; // sound information (if null, channel avail.)
const mobj_t *origin; // origin of sound
int volume; // volume scale value for effect -- haleyjd 05/29/06
int pitch; // pitch modifier -- haleyjd 06/03/06
int handle; // handle of the sound being played
int o_priority; // haleyjd 09/27/06: stored priority value
int priority; // current priority value
int singularity; // haleyjd 09/27/06: stored singularity value
int idnum; // haleyjd 09/30/06: unique id num for sound event
} channel_t;
// the set of channels available
@ -103,207 +109,315 @@ int idmusnum;
// Internals.
//
//
// S_StopChannel
//
// Stops a sound channel.
//
static void S_StopChannel(int cnum)
{
if (channels[cnum].sfxinfo)
{
if (I_SoundIsPlaying(channels[cnum].handle))
I_StopSound(channels[cnum].handle); // stop the sound playing
channels[cnum].sfxinfo = 0;
}
#ifdef RANGECHECK
if(cnum < 0 || cnum >= numChannels)
I_Error("S_StopChannel: handle %d out of range\n", cnum);
#endif
if(channels[cnum].sfxinfo)
{
if(I_SoundIsPlaying(channels[cnum].handle))
I_StopSound(channels[cnum].handle); // stop the sound playing
// haleyjd 09/27/06: clear the entire channel
memset(&channels[cnum], 0, sizeof(channel_t));
}
}
//
// S_AdjustSoundParams
//
// Alters a playing sound's volume and stereo separation to account for
// the position and angle of the listener relative to the source.
//
// haleyjd: added channel volume scale value
// haleyjd: added priority scaling
//
static int S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source,
int *vol, int *sep, int *pitch)
int chanvol, int *vol, int *sep, int *pitch,
int *pri)
{
fixed_t adx, ady, dist;
angle_t angle;
fixed_t adx, ady, dist;
angle_t angle;
int basevolume; // haleyjd
// calculate the distance to sound origin
// and clip it if necessary
//
// killough 11/98: scale coordinates down before calculations start
// killough 12/98: use exact distance formula instead of approximation
// haleyjd 08/12/04: we cannot adjust a sound for a NULL listener.
if(!listener)
return 1;
adx = abs((listener->x >> FRACBITS) - (source->x >> FRACBITS));
ady = abs((listener->y >> FRACBITS) - (source->y >> FRACBITS));
// haleyjd 05/29/06: this function isn't supposed to be called for NULL sources
#ifdef RANGECHECK
if(!source)
I_Error("S_AdjustSoundParams: NULL source\n");
#endif
if (ady > adx)
dist = adx, adx = ady, ady = dist;
// calculate the distance to sound origin
// and clip it if necessary
//
// killough 11/98: scale coordinates down before calculations start
// killough 12/98: use exact distance formula instead of approximation
dist = adx ? FixedDiv(adx, finesine[(tantoangle[FixedDiv(ady,adx) >> DBITS]
+ ANG90) >> ANGLETOFINESHIFT]) : 0;
adx = abs((listener->x >> FRACBITS) - (source->x >> FRACBITS));
ady = abs((listener->y >> FRACBITS) - (source->y >> FRACBITS));
if (!dist) // killough 11/98: handle zero-distance as special case
{
if(ady > adx)
dist = adx, adx = ady, ady = dist;
dist = adx ? FixedDiv(adx, finesine[(tantoangle[FixedDiv(ady,adx) >> DBITS]
+ ANG90) >> ANGLETOFINESHIFT]) : 0;
// haleyjd 05/29/06: allow per-channel volume scaling
basevolume = (snd_SfxVolume * chanvol) / 15;
if(!dist) // killough 11/98: handle zero-distance as special case
{
*sep = NORM_SEP;
*vol = snd_SfxVolume;
*vol = basevolume;
return *vol > 0;
}
}
if (dist > S_CLIPPING_DIST >> FRACBITS)
return 0;
if(dist > S_CLIPPING_DIST >> FRACBITS)
return 0;
// angle of source to listener
angle = R_PointToAngle2(listener->x, listener->y, source->x, source->y);
// angle of source to listener
angle = R_PointToAngle2(listener->x, listener->y, source->x, source->y);
if (angle <= listener->angle)
angle += 0xffffffff;
angle -= listener->angle;
angle >>= ANGLETOFINESHIFT;
if(angle <= listener->angle)
angle += 0xffffffff;
angle -= listener->angle;
angle >>= ANGLETOFINESHIFT;
// stereo separation
*sep = NORM_SEP - FixedMul(S_STEREO_SWING>>FRACBITS,finesine[angle]);
// stereo separation
*sep = NORM_SEP - FixedMul(S_STEREO_SWING>>FRACBITS,finesine[angle]);
// volume calculation
*vol = dist < S_CLOSE_DIST >> FRACBITS ? snd_SfxVolume :
snd_SfxVolume * ((S_CLIPPING_DIST>>FRACBITS)-dist) /
S_ATTENUATOR;
// volume calculation
*vol = dist < S_CLOSE_DIST >> FRACBITS ? basevolume :
basevolume * ((S_CLIPPING_DIST>>FRACBITS)-dist) /
S_ATTENUATOR;
// haleyjd 09/27/06: decrease priority with volume attenuation
*pri = *pri + (127 - *vol);
if(*pri > 255) // cap to 255
*pri = 255;
return *vol > 0;
}
//
// S_getChannel :
// If none available, return -1. Otherwise channel #.
//
static int S_getChannel(const void *origin, sfxinfo_t *sfxinfo)
// If none available, return -1. Otherwise channel #.
// haleyjd 09/27/06: fixed priority/singularity bugs
// Note that a higher priority number means lower priority!
//
static int S_getChannel(const mobj_t *origin, sfxinfo_t *sfxinfo,
int priority, int singularity)
{
// channel number to use
int cnum;
channel_t *c;
// channel number to use
int cnum;
int lowestpriority = -1; // haleyjd
int lpcnum = -1;
// Find an open channel
// killough 12/98: replace is_pickup hack with singularity flag
for (cnum=0; cnum<numChannels && channels[cnum].sfxinfo; cnum++)
if (origin && channels[cnum].origin == origin &&
channels[cnum].sfxinfo->singularity == sfxinfo->singularity)
// haleyjd 09/28/06: moved this here. If we kill a sound already
// being played, we can use that channel. There is no need to
// search for a free one again because we already know of one.
// kill old sound
// killough 12/98: replace is_pickup hack with singularity flag
// haleyjd 06/12/08: only if subchannel matches
for(cnum = 0; cnum < numChannels; ++cnum)
{
if(channels[cnum].sfxinfo &&
channels[cnum].singularity == singularity &&
channels[cnum].origin == origin)
{
S_StopChannel(cnum);
break;
S_StopChannel(cnum);
break;
}
}
// None available
if (cnum == numChannels)
{ // Look for lower priority
for (cnum=0 ; cnum<numChannels ; cnum++)
if (channels[cnum].sfxinfo->priority >= sfxinfo->priority)
break;
if (cnum == numChannels)
return -1; // No lower priority. Sorry, Charlie.
// Find an open channel
if(cnum == numChannels)
{
// haleyjd 09/28/06: it isn't necessary to look for playing sounds in
// the same singularity class again, as we just did that above. Here
// we are looking for an open channel. We will also keep track of the
// channel found with the lowest sound priority while doing this.
for(cnum = 0; cnum < numChannels && channels[cnum].sfxinfo; ++cnum)
{
if(channels[cnum].priority > lowestpriority)
{
lowestpriority = channels[cnum].priority;
lpcnum = cnum;
}
}
}
// None available?
if(cnum == numChannels)
{
// Look for lower priority
// haleyjd: we have stored the channel found with the lowest priority
// in the loop above
if(priority > lowestpriority)
return -1; // No lower priority. Sorry, Charlie.
else
S_StopChannel(cnum); // Otherwise, kick out lower priority.
}
{
S_StopChannel(lpcnum); // Otherwise, kick out lowest priority.
cnum = lpcnum;
}
}
c = &channels[cnum]; // channel is decided to be cnum.
c->sfxinfo = sfxinfo;
c->origin = origin;
return cnum;
#ifdef RANGECHECK
if(cnum >= numChannels)
I_Error("S_getChannel: handle %d out of range\n", cnum);
#endif
return cnum;
}
void S_StartSound(const mobj_t *origin, int sfx_id)
{
int sep, pitch, priority, cnum;
int volume = snd_SfxVolume;
sfxinfo_t *sfx;
int sep, pitch, o_priority, priority, singularity, cnum, handle;
int volumeScale = 127;
int volume = snd_SfxVolume;
sfxinfo_t *sfx;
//jff 1/22/98 return if sound is not enabled
if (!snd_card || nosfxparm)
return;
//jff 1/22/98 return if sound is not enabled
if(!snd_card || nosfxparm)
return;
#ifdef RANGECHECK
// check for bogus sound #
if (sfx_id < 1 || sfx_id > NUMSFX)
I_Error("Bad sfx #: %d", sfx_id);
// check for bogus sound #
if(sfx_id < 1 || sfx_id > NUMSFX)
I_Error("Bad sfx #: %d", sfx_id);
#endif
sfx = &S_sfx[sfx_id];
sfx = &S_sfx[sfx_id];
// Initialize sound parameters
if (sfx->link)
{
// Initialize sound parameters
if(sfx->link)
{
pitch = sfx->pitch;
priority = sfx->priority;
volume += sfx->volume;
if (volume < 1)
return;
if (volume >= snd_SfxVolume)
volume = snd_SfxVolume;
}
else
{
volumeScale += sfx->volume;
}
else
pitch = NORM_PITCH;
priority = NORM_PRIORITY;
}
// Check to see if it is audible, modify the params
// killough 3/7/98, 4/25/98: code rearranged slightly
// haleyjd 09/29/06: rangecheck volumeScale now!
if(volumeScale < 0)
volumeScale = 0;
else if(volumeScale > 127)
volumeScale = 127;
if (!origin || origin == players[displayplayer].mo)
sep = NORM_SEP;
else
if (!S_AdjustSoundParams(players[displayplayer].mo, origin, &volume,
&sep, &pitch))
return;
else
if (origin->x == players[displayplayer].mo->x &&
origin->y == players[displayplayer].mo->y)
sep = NORM_SEP;
// haleyjd: modified so that priority value is always used
// haleyjd: also modified to get and store proper singularity value
o_priority = priority = sfx->priority;
singularity = sfx->singularity;
if (pitched_sounds)
{
// Check to see if it is audible, modify the params
// killough 3/7/98, 4/25/98: code rearranged slightly
if(!origin || origin == players[displayplayer].mo)
{
sep = NORM_SEP;
volume = (volume * volumeScale) / 15; // haleyjd 05/29/06: scale volume
if(volume < 1)
return;
if(volume > 127)
volume = 127;
}
else
{
if(!S_AdjustSoundParams(players[displayplayer].mo, origin, volumeScale,
&volume, &sep, &pitch, &priority))
return;
else if(origin->x == players[displayplayer].mo->x &&
origin->y == players[displayplayer].mo->y)
sep = NORM_SEP;
}
if(pitched_sounds)
{
// hacks to vary the sfx pitches
if (sfx_id >= sfx_sawup && sfx_id <= sfx_sawhit)
pitch += 8 - (M_Random()&15);
else
if (sfx_id != sfx_itemup && sfx_id != sfx_tink)
pitch += 16 - (M_Random()&31);
if(sfx_id >= sfx_sawup && sfx_id <= sfx_sawhit)
pitch += 8 - (M_Random()&15);
else if(sfx_id != sfx_itemup && sfx_id != sfx_tink)
pitch += 16 - (M_Random()&31);
if (pitch<0)
pitch = 0;
if(pitch < 0)
pitch = 0;
if (pitch>255)
pitch = 255;
}
if(pitch > 255)
pitch = 255;
}
// kill old sound
// killough 12/98: replace is_pickup hack with singularity flag
for (cnum=0 ; cnum<numChannels ; cnum++)
if (channels[cnum].sfxinfo &&
channels[cnum].sfxinfo->singularity == sfx->singularity &&
channels[cnum].origin == origin)
{
S_StopChannel(cnum);
break;
}
// try to find a channel
if((cnum = S_getChannel(origin, sfx, priority, singularity)) < 0)
return;
// try to find a channel
cnum = S_getChannel(origin, sfx);
#ifdef RANGECHECK
if(cnum < 0 || cnum >= numChannels)
I_Error("S_StartSfxInfo: handle %d out of range\n", cnum);
#endif
if (cnum<0)
return;
channels[cnum].sfxinfo = sfx;
channels[cnum].origin = origin;
while(sfx->link)
sfx = sfx->link; // sf: skip thru link(s)
// Assigns the handle to one of the channels in the mix/output buffer.
handle = I_StartSound(sfx, cnum, volume, sep, pitch, priority);
// haleyjd: check to see if the sound was started
if(handle >= 0)
{
channels[cnum].handle = handle;
// haleyjd 05/29/06: record volume scale value
// haleyjd 06/03/06: record pitch too (wtf is going on here??)
// haleyjd 09/27/06: store priority and singularity values (!!!)
channels[cnum].volume = volumeScale;
channels[cnum].pitch = pitch;
channels[cnum].o_priority = o_priority; // original priority
channels[cnum].priority = priority; // scaled priority
channels[cnum].singularity = singularity;
channels[cnum].idnum = I_SoundID(handle); // unique instance id
}
else // haleyjd: the sound didn't start, so clear the channel info
memset(&channels[cnum], 0, sizeof(channel_t));
// Assigns the handle to one of the channels in the mix/output buffer.
channels[cnum].handle = I_StartSound(sfx_id, volume, sep, pitch, priority);
}
//
// S_StopSound
//
void S_StopSound(const mobj_t *origin)
{
int cnum;
int cnum;
//jff 1/22/98 return if sound is not enabled
if (!snd_card || nosfxparm)
return;
//jff 1/22/98 return if sound is not enabled
if(!snd_card || nosfxparm)
return;
for (cnum=0 ; cnum<numChannels ; cnum++)
if (channels[cnum].sfxinfo && channels[cnum].origin == origin)
for(cnum = 0; cnum < numChannels; ++cnum)
{
if(channels[cnum].sfxinfo && channels[cnum].origin == origin)
{
S_StopChannel(cnum);
break;
S_StopChannel(cnum);
break;
}
}
}
//
@ -312,20 +426,20 @@ void S_StopSound(const mobj_t *origin)
void S_PauseSound(void)
{
if (mus_playing && !mus_paused)
{
if(mus_playing && !mus_paused)
{
I_PauseSong(mus_playing->handle);
mus_paused = true;
}
}
}
void S_ResumeSound(void)
{
if (mus_playing && mus_paused)
{
if(mus_playing && mus_paused)
{
I_ResumeSong(mus_playing->handle);
mus_paused = false;
}
}
}
//
@ -334,50 +448,56 @@ void S_ResumeSound(void)
void S_UpdateSounds(const mobj_t *listener)
{
int cnum;
int cnum;
//jff 1/22/98 return if sound is not enabled
if (!snd_card || nosfxparm)
return;
//jff 1/22/98 return if sound is not enabled
if(!snd_card || nosfxparm)
return;
for (cnum=0 ; cnum<numChannels ; cnum++)
{
for(cnum = 0; cnum < numChannels; ++cnum)
{
channel_t *c = &channels[cnum];
sfxinfo_t *sfx = c->sfxinfo;
if (sfx)
{
if (I_SoundIsPlaying(c->handle))
// haleyjd: has this software channel lost its hardware channel?
if(c->idnum != I_SoundID(c->handle))
{
// clear the channel and keep going
memset(c, 0, sizeof(channel_t));
continue;
}
if(sfx)
{
if(I_SoundIsPlaying(c->handle))
{
// initialize parameters
int volume = snd_SfxVolume;
int pitch = c->pitch; // haleyjd 06/03/06: use channel's pitch!
int sep = NORM_SEP;
int pri = c->o_priority; // haleyjd 09/27/06: priority
// check non-local sounds for distance clipping
// or modify their params
if(c->origin && listener != c->origin) // killough 3/20/98
{
// initialize parameters
int volume = snd_SfxVolume;
int pitch = NORM_PITCH;
int sep = NORM_SEP;
if (sfx->link)
{
pitch = sfx->pitch;
volume += sfx->volume;
if (volume < 1)
{
S_StopChannel(cnum);
continue;
}
else
if (volume > snd_SfxVolume)
volume = snd_SfxVolume;
}
// check non-local sounds for distance clipping
// or modify their params
if (c->origin && listener != c->origin) // killough 3/20/98
if (!S_AdjustSoundParams(listener, c->origin,
&volume, &sep, &pitch))
if(!S_AdjustSoundParams(listener,
c->origin,
c->volume,
&volume,
&sep,
&pitch,
&pri))
S_StopChannel(cnum);
else
else
{
I_UpdateSoundParams(c->handle, volume, sep, pitch);
c->priority = pri; // haleyjd
}
}
else // if channel is allocated but sound has stopped, free it
}
else // if channel is allocated but sound has stopped, free it
S_StopChannel(cnum);
}
}
@ -385,69 +505,75 @@ void S_UpdateSounds(const mobj_t *listener)
void S_SetMusicVolume(int volume)
{
//jff 1/22/98 return if music is not enabled
if (!mus_card || nomusicparm)
return;
//jff 1/22/98 return if music is not enabled
if(!mus_card || nomusicparm)
return;
#ifdef RANGECHECK
if (volume < 0 || volume > 127)
I_Error("Attempt to set music volume at %d", volume);
if(volume < 0 || volume > 16)
I_Error("Attempt to set music volume at %d\n", volume);
#endif
I_SetMusicVolume(127);
I_SetMusicVolume(volume);
snd_MusicVolume = volume;
// haleyjd: I don't think it should do this in SDL
#if 0
I_SetMusicVolume(127);
#endif
I_SetMusicVolume(volume);
snd_MusicVolume = volume;
}
void S_SetSfxVolume(int volume)
{
//jff 1/22/98 return if sound is not enabled
if (!snd_card || nosfxparm)
return;
//jff 1/22/98 return if sound is not enabled
if(!snd_card || nosfxparm)
return;
#ifdef RANGECHECK
if (volume < 0 || volume > 127)
I_Error("Attempt to set sfx volume at %d", volume);
if(volume < 0 || volume > 127)
I_Error("Attempt to set sfx volume at %d", volume);
#endif
snd_SfxVolume = volume;
snd_SfxVolume = volume;
}
void S_ChangeMusic(int musicnum, int looping)
{
musicinfo_t *music;
musicinfo_t *music;
//jff 1/22/98 return if music is not enabled
if (!mus_card || nomusicparm)
return;
//jff 1/22/98 return if music is not enabled
if(!mus_card || nomusicparm)
return;
if (musicnum <= mus_None || musicnum >= NUMMUSIC)
I_Error("Bad music number %d", musicnum);
if(musicnum <= mus_None || musicnum >= NUMMUSIC)
I_Error("Bad music number %d", musicnum);
music = &S_music[musicnum];
music = &S_music[musicnum];
if (mus_playing == music)
return;
if(mus_playing == music)
return;
// shutdown old music
S_StopMusic();
// shutdown old music
S_StopMusic();
// get lumpnum if neccessary
if (!music->lumpnum)
{
// get lumpnum if neccessary
if(!music->lumpnum)
{
char namebuf[9];
sprintf(namebuf, "d_%s", music->name);
music->lumpnum = W_GetNumForName(namebuf);
}
}
// load & register it
music->data = W_CacheLumpNum(music->lumpnum, PU_MUSIC);
music->handle = I_RegisterSong(music->data);
// load & register it
music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC);
// julian: added lump length
music->handle = I_RegisterSong(music->data, W_LumpLength(music->lumpnum));
// play it
I_PlaySong(music->handle, looping);
// play it
I_PlaySong(music->handle, looping);
mus_playing = music;
mus_playing = music;
}
//
@ -455,23 +581,23 @@ void S_ChangeMusic(int musicnum, int looping)
//
void S_StartMusic(int m_id)
{
S_ChangeMusic(m_id, false);
S_ChangeMusic(m_id, false);
}
void S_StopMusic(void)
{
if (!mus_playing)
return;
if(!mus_playing)
return;
if (mus_paused)
I_ResumeSong(mus_playing->handle);
if(mus_paused)
I_ResumeSong(mus_playing->handle);
I_StopSong(mus_playing->handle);
I_UnRegisterSong(mus_playing->handle);
Z_ChangeTag(mus_playing->data, PU_CACHE);
I_StopSong(mus_playing->handle);
I_UnRegisterSong(mus_playing->handle);
Z_ChangeTag(mus_playing->data, PU_CACHE);
mus_playing->data = 0;
mus_playing = 0;
mus_playing->data = NULL;
mus_playing = NULL;
}
//
@ -481,50 +607,57 @@ void S_StopMusic(void)
//
void S_Start(void)
{
int cnum,mnum;
int cnum,mnum;
// kill all playing sounds at start of level
// (trust me - a good idea)
// kill all playing sounds at start of level
// (trust me - a good idea)
//jff 1/22/98 skip sound init if sound not enabled
if (snd_card && !nosfxparm)
for (cnum=0 ; cnum<numChannels ; cnum++)
if (channels[cnum].sfxinfo)
S_StopChannel(cnum);
//jff 1/22/98 return if music is not enabled
if (!mus_card || nomusicparm)
return;
// start new music for the level
mus_paused = 0;
if (idmusnum!=-1)
mnum = idmusnum; //jff 3/17/98 reload IDMUS music if not -1
else
if (gamemode == commercial)
mnum = mus_runnin + gamemap - 1;
else
//jff 1/22/98 skip sound init if sound not enabled
if(snd_card && !nosfxparm)
{
for(cnum = 0; cnum < numChannels; ++cnum)
{
static const int spmus[] = // Song - Who? - Where?
{
mus_e3m4, // American e4m1
mus_e3m2, // Romero e4m2
mus_e3m3, // Shawn e4m3
mus_e1m5, // American e4m4
mus_e2m7, // Tim e4m5
mus_e2m4, // Romero e4m6
mus_e2m6, // J.Anderson e4m7 CHIRON.WAD
mus_e2m5, // Shawn e4m8
mus_e1m9 // Tim e4m9
};
if (gameepisode < 4)
mnum = mus_e1m1 + (gameepisode-1)*9 + gamemap-1;
else
mnum = spmus[gamemap-1];
if(channels[cnum].sfxinfo)
S_StopChannel(cnum);
}
S_ChangeMusic(mnum, true);
}
//jff 1/22/98 return if music is not enabled
if (!mus_card || nomusicparm)
return;
// start new music for the level
mus_paused = 0;
if(idmusnum!=-1)
mnum = idmusnum; //jff 3/17/98 reload IDMUS music if not -1
else
{
if (gamemode == commercial)
mnum = mus_runnin + gamemap - 1;
else
{
static const int spmus[] = // Song - Who? - Where?
{
mus_e3m4, // American e4m1
mus_e3m2, // Romero e4m2
mus_e3m3, // Shawn e4m3
mus_e1m5, // American e4m4
mus_e2m7, // Tim e4m5
mus_e2m4, // Romero e4m6
mus_e2m6, // J.Anderson e4m7 CHIRON.WAD
mus_e2m5, // Shawn e4m8
mus_e1m9 // Tim e4m9
};
if(gameepisode < 4)
mnum = mus_e1m1 + (gameepisode-1)*9 + gamemap-1;
else
mnum = spmus[gamemap-1];
}
}
S_ChangeMusic(mnum, true);
}
//
@ -535,9 +668,9 @@ void S_Start(void)
void S_Init(int sfxVolume, int musicVolume)
{
//jff 1/22/98 skip sound init if sound not enabled
if (snd_card && !nosfxparm)
{
//jff 1/22/98 skip sound init if sound not enabled
if(snd_card && !nosfxparm)
{
printf("S_Init: default sfx volume %d\n", sfxVolume); // killough 8/8/98
// haleyjd
@ -551,12 +684,12 @@ void S_Init(int sfxVolume, int musicVolume)
// killough 10/98:
channels = calloc(numChannels = default_numChannels, sizeof(channel_t));
}
}
S_SetMusicVolume(musicVolume);
S_SetMusicVolume(musicVolume);
// no sounds are playing, and they are not mus_paused
mus_paused = 0;
// no sounds are playing, and they are not mus_paused
mus_paused = 0;
}
//----------------------------------------------------------------------------

View File

@ -77,6 +77,9 @@ struct sfxinfo_struct {
// lump number of sfx
int lumpnum;
// haleyjd 04/23/08: additional caching data
unsigned int alen; // length of converted sound pointed to by data
};
//

View File

@ -85,6 +85,14 @@ void Z_DumpHistory(char *);
#define Z_Realloc(a,b,c,d) (Z_Realloc) (a,b,c,d,__FILE__,__LINE__)
#define Z_CheckHeap() (Z_CheckHeap)(__FILE__,__LINE__)
// Remove all definitions before including system definitions
#undef malloc
#undef free
#undef realloc
#undef calloc
#undef strdup
#define malloc(n) Z_Malloc(n,PU_STATIC,0)
#define free(p) Z_Free(p)
#define realloc(p,n) Z_Realloc(p,n,PU_STATIC,0)

View File

@ -66,7 +66,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "c:\software dev\sdl-1.2.7\include" /I "c:\software dev\sdl_mixer-1.2.5\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "MY_SDL_VER" /D "DOGS" /D "BETA" /D "RANGECHECK" /D "INSTRUMENTED" /YX /FD /GZ /c
# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "c:\software dev\sdl-1.2.12\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "MY_SDL_VER" /D "DOGS" /D "BETA" /D "RANGECHECK" /D "INSTRUMENTED" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@ -85,10 +85,17 @@ LINK32=link.exe
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Group "AM"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Am_map.c
# End Source File
# End Group
# Begin Group "D"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\D_deh.c
@ -105,18 +112,10 @@ SOURCE=.\Source\D_main.c
SOURCE=.\Source\D_net.c
# End Source File
# Begin Source File
# End Group
# Begin Group "F"
SOURCE=.\Source\Doomdef.c
# End Source File
# Begin Source File
SOURCE=.\Source\Doomstat.c
# End Source File
# Begin Source File
SOURCE=.\Source\Dstrings.c
# End Source File
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\F_finale.c
@ -125,10 +124,18 @@ SOURCE=.\Source\F_finale.c
SOURCE=.\Source\F_wipe.c
# End Source File
# End Group
# Begin Group "G"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\G_game.c
# End Source File
# End Group
# Begin Group "HU"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Hu_lib.c
@ -137,6 +144,10 @@ SOURCE=.\Source\Hu_lib.c
SOURCE=.\Source\Hu_stuff.c
# End Source File
# End Group
# Begin Group "I"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\I_main.c
@ -157,10 +168,10 @@ SOURCE=.\Source\I_system.c
SOURCE=.\Source\I_video.c
# End Source File
# Begin Source File
# End Group
# Begin Group "M"
SOURCE=.\Source\Info.c
# End Source File
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\M_argv.c
@ -185,10 +196,10 @@ SOURCE=.\Source\M_misc.c
SOURCE=.\Source\M_random.c
# End Source File
# Begin Source File
# End Group
# Begin Group "P"
SOURCE=.\Source\Mmus2mid.c
# End Source File
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\P_ceilng.c
@ -269,6 +280,10 @@ SOURCE=.\Source\P_tick.c
SOURCE=.\Source\P_user.c
# End Source File
# End Group
# Begin Group "R"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\R_bsp.c
@ -301,6 +316,10 @@ SOURCE=.\Source\R_sky.c
SOURCE=.\Source\R_things.c
# End Source File
# End Group
# Begin Group "S"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\S_sound.c
@ -309,6 +328,10 @@ SOURCE=.\Source\S_sound.c
SOURCE=.\Source\Sounds.c
# End Source File
# End Group
# Begin Group "ST"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\St_lib.c
@ -317,38 +340,86 @@ SOURCE=.\Source\St_lib.c
SOURCE=.\Source\St_stuff.c
# End Source File
# End Group
# Begin Group "V"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\V_video.c
# End Source File
# End Group
# Begin Group "W"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\W_wad.c
# End Source File
# End Group
# Begin Group "WI"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Wi_stuff.c
# End Source File
# End Group
# Begin Group "Z"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Z_zone.c
# End Source File
# End Group
# Begin Group "Doom"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Doomdef.c
# End Source File
# Begin Source File
SOURCE=.\Source\Doomstat.c
# End Source File
# Begin Source File
SOURCE=.\Source\Dstrings.c
# End Source File
# End Group
# Begin Source File
SOURCE=.\Source\Info.c
# End Source File
# Begin Source File
SOURCE=.\Source\Mmus2mid.c
# End Source File
# Begin Source File
SOURCE=.\Source\Tables.c
# End Source File
# Begin Source File
SOURCE=.\Source\V_video.c
# End Source File
# Begin Source File
SOURCE=.\Source\Version.c
# End Source File
# Begin Source File
SOURCE=.\Source\W_wad.c
# End Source File
# Begin Source File
SOURCE=.\Source\Wi_stuff.c
# End Source File
# Begin Source File
SOURCE=.\Source\Z_zone.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Group "AM_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Am_map.h
# End Source File
# End Group
# Begin Group "D_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\D_deh.h
@ -397,6 +468,10 @@ SOURCE=.\Source\D_think.h
SOURCE=.\Source\D_ticcmd.h
# End Source File
# End Group
# Begin Group "Doom_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Doomdata.h
@ -417,6 +492,10 @@ SOURCE=.\Source\Doomtype.h
SOURCE=.\Source\Dstrings.h
# End Source File
# End Group
# Begin Group "F_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\F_finale.h
@ -425,10 +504,18 @@ SOURCE=.\Source\F_finale.h
SOURCE=.\Source\F_wipe.h
# End Source File
# End Group
# Begin Group "G_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\G_game.h
# End Source File
# End Group
# Begin Group "HU_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Hu_lib.h
@ -437,6 +524,10 @@ SOURCE=.\Source\Hu_lib.h
SOURCE=.\Source\Hu_stuff.h
# End Source File
# End Group
# Begin Group "I_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\I_net.h
@ -453,10 +544,10 @@ SOURCE=.\Source\I_system.h
SOURCE=.\Source\I_video.h
# End Source File
# Begin Source File
# End Group
# Begin Group "M_"
SOURCE=.\Source\Info.h
# End Source File
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\M_argv.h
@ -489,10 +580,10 @@ SOURCE=.\Source\M_random.h
SOURCE=.\Source\M_swap.h
# End Source File
# Begin Source File
# End Group
# Begin Group "P_"
SOURCE=.\Source\Mmus2mid.h
# End Source File
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\P_enemy.h
@ -537,6 +628,10 @@ SOURCE=.\Source\P_tick.h
SOURCE=.\Source\P_user.h
# End Source File
# End Group
# Begin Group "R_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\R_bsp.h
@ -577,6 +672,10 @@ SOURCE=.\Source\R_state.h
SOURCE=.\Source\R_things.h
# End Source File
# End Group
# Begin Group "S_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\S_sound.h
@ -585,6 +684,10 @@ SOURCE=.\Source\S_sound.h
SOURCE=.\Source\Sounds.h
# End Source File
# End Group
# Begin Group "ST_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\St_lib.h
@ -593,30 +696,55 @@ SOURCE=.\Source\St_lib.h
SOURCE=.\Source\St_stuff.h
# End Source File
# End Group
# Begin Group "V_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\V_video.h
# End Source File
# End Group
# Begin Group "W_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\W_wad.h
# End Source File
# End Group
# Begin Group "WI_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Wi_stuff.h
# End Source File
# End Group
# Begin Group "Z_"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Source\Z_zone.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\Source\Info.h
# End Source File
# Begin Source File
SOURCE=.\Source\Mmus2mid.h
# End Source File
# Begin Source File
SOURCE=.\Source\Tables.h
# End Source File
# Begin Source File
SOURCE=.\Source\V_video.h
# End Source File
# Begin Source File
SOURCE=.\Source\Version.h
# End Source File
# Begin Source File
SOURCE=.\Source\W_wad.h
# End Source File
# Begin Source File
SOURCE=.\Source\Wi_stuff.h
# End Source File
# Begin Source File
SOURCE=.\Source\Z_zone.h
# End Source File
# End Group
# Begin Group "Resource Files"