Skip to content

Commit

Permalink
remove looping sounds quirk (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiangreffrath committed Apr 6, 2023
1 parent 0ff8bdb commit 7338fec
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 68 deletions.
4 changes: 0 additions & 4 deletions src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -2416,10 +2416,6 @@ void G_Ticker(void)
gamestate == GS_INTERMISSION ? WI_Ticker() :
gamestate == GS_FINALE ? F_Ticker() :
gamestate == GS_DEMOSCREEN ? D_PageTicker() : (void) 0;

// [FG] stop looping sounds if P_Ticker() didn't run through
if (leveltime == oldleveltime)
S_StopLoopSounds();
}

//
Expand Down
3 changes: 1 addition & 2 deletions src/i_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ int I_GetSfxLumpNum(sfxinfo_t *sfx)
// active sounds, which is maintained as a given number
// of internal channels. Returns a free channel.
//
int I_StartSound(sfxinfo_t *sound, int vol, int sep, int pitch, boolean loop)
int I_StartSound(sfxinfo_t *sound, int vol, int sep, int pitch)
{
static unsigned int id = 0;
int channel;
Expand Down Expand Up @@ -361,7 +361,6 @@ int I_StartSound(sfxinfo_t *sound, int vol, int sep, int pitch, boolean loop)
I_UpdateSoundParams(channel, vol, sep);

alSourcei(source, AL_BUFFER, buffer);
alSourcei(source, AL_LOOPING, loop ? AL_TRUE : AL_FALSE);
if (pitch != NORM_PITCH)
{
alSourcef(source, AL_PITCH, steptable[pitch]);
Expand Down
2 changes: 1 addition & 1 deletion src/i_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void I_SetChannels(void);
int I_GetSfxLumpNum(sfxinfo_t *sfxinfo);

// Starts a sound in a particular sound channel.
int I_StartSound(sfxinfo_t *sound, int vol, int sep, int pitch, boolean loop);
int I_StartSound(sfxinfo_t *sound, int vol, int sep, int pitch);

// Stops a sound channel.
void I_StopSound(int handle);
Expand Down
4 changes: 2 additions & 2 deletions src/p_ceilng.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void T_MoveCeiling (ceiling_t* ceiling)
case genSilentCrusher:
break;
default:
S_LoopSound((mobj_t *)&ceiling->sector->soundorg, sfx_stnmov, 8);
S_StartSound((mobj_t *)&ceiling->sector->soundorg, sfx_stnmov);
break;
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ void T_MoveCeiling (ceiling_t* ceiling)
case genSilentCrusher:
break;
default:
S_LoopSound((mobj_t *)&ceiling->sector->soundorg, sfx_stnmov, 8);
S_StartSound((mobj_t *)&ceiling->sector->soundorg, sfx_stnmov);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/p_floor.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void T_MoveFloor(floormove_t* floor)
);

if (!(leveltime&7)) // make the floormove sound
S_LoopSound((mobj_t *)&floor->sector->soundorg, sfx_stnmov, 8);
S_StartSound((mobj_t *)&floor->sector->soundorg, sfx_stnmov);

if (res == pastdest) // if destination height is reached
{
Expand Down Expand Up @@ -393,7 +393,7 @@ void T_MoveElevator(elevator_t* elevator)

// make floor move sound
if (!(leveltime&7))
S_LoopSound((mobj_t *)&elevator->sector->soundorg, sfx_stnmov, 8);
S_StartSound((mobj_t *)&elevator->sector->soundorg, sfx_stnmov);

if (res == pastdest) // if destination height acheived
{
Expand Down
2 changes: 1 addition & 1 deletion src/p_plats.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void T_PlatRaise(plat_t* plat)
|| plat->type == raiseToNearestAndChange)
{
if (!(leveltime&7))
S_LoopSound((mobj_t *)&plat->sector->soundorg, sfx_stnmov, 8);
S_StartSound((mobj_t *)&plat->sector->soundorg, sfx_stnmov);
}

// if encountered an obstacle, and not a crush type, reverse direction
Expand Down
61 changes: 7 additions & 54 deletions src/s_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ typedef struct channel_s
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
boolean loop;
int loop_timeout;
} channel_t;

// the set of channels available
Expand Down Expand Up @@ -118,20 +116,6 @@ static void S_StopChannel(int cnum)
}
}

void S_StopLoopSounds (void)
{
int cnum;

if (!nosfxparm)
{
for (cnum = 0; cnum < numChannels; ++cnum)
{
if (channels[cnum].sfxinfo && channels[cnum].loop)
S_StopChannel(cnum);
}
}
}

//
// S_AdjustSoundParams
//
Expand Down Expand Up @@ -220,8 +204,7 @@ static int S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source,
// Note that a higher priority number means lower priority!
//
static int S_getChannel(const mobj_t *origin, sfxinfo_t *sfxinfo,
int priority, int singularity,
boolean loop, int loop_timeout)
int priority, int singularity)
{
// channel number to use
int cnum;
Expand All @@ -235,19 +218,8 @@ static int S_getChannel(const mobj_t *origin, sfxinfo_t *sfxinfo,
// haleyjd 06/12/08: only if subchannel matches
for (cnum = 0; cnum < numChannels; ++cnum)
{
if (!channels[cnum].sfxinfo)
continue;

// [FG] looping sounds don't interrupt each other
if (channels[cnum].sfxinfo == sfxinfo &&
channels[cnum].origin == origin &&
channels[cnum].loop && loop)
{
channels[cnum].loop_timeout = loop_timeout;
return -1;
}

if (channels[cnum].singularity == singularity &&
if (channels[cnum].sfxinfo &&
channels[cnum].singularity == singularity &&
channels[cnum].origin == origin)
{
S_StopChannel(cnum);
Expand Down Expand Up @@ -277,15 +249,12 @@ static int S_getChannel(const mobj_t *origin, sfxinfo_t *sfxinfo,
}


static void S_StartSoundEx(const mobj_t *origin, int sfx_id, int loop_timeout)
void S_StartSound(const mobj_t *origin, int sfx_id)
{
int sep, pitch, o_priority, priority, singularity, cnum, handle;
int volumeScale = 127;
int volume = snd_SfxVolume;
sfxinfo_t *sfx;
const boolean loop = loop_timeout > 0;

loop_timeout += gametic;

//jff 1/22/98 return if sound is not enabled
if(nosfxparm)
Expand Down Expand Up @@ -361,7 +330,7 @@ static void S_StartSoundEx(const mobj_t *origin, int sfx_id, int loop_timeout)
}

// try to find a channel
if((cnum = S_getChannel(origin, sfx, priority, singularity, loop, loop_timeout)) < 0)
if((cnum = S_getChannel(origin, sfx, priority, singularity)) < 0)
return;

#ifdef RANGECHECK
Expand All @@ -376,7 +345,7 @@ static void S_StartSoundEx(const mobj_t *origin, int sfx_id, int loop_timeout)
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, volume, sep, pitch, loop);
handle = I_StartSound(sfx, volume, sep, pitch);

// haleyjd: check to see if the sound was started
if(handle >= 0)
Expand All @@ -392,23 +361,11 @@ static void S_StartSoundEx(const mobj_t *origin, int sfx_id, int loop_timeout)
channels[cnum].priority = priority; // scaled priority
channels[cnum].singularity = singularity;
channels[cnum].idnum = I_SoundID(handle); // unique instance id
channels[cnum].loop = loop;
channels[cnum].loop_timeout = loop_timeout;
}
else // haleyjd: the sound didn't start, so clear the channel info
memset(&channels[cnum], 0, sizeof(channel_t));
}

void S_StartSound(const mobj_t *origin, int sfx_id)
{
S_StartSoundEx(origin, sfx_id, 0);
}

void S_LoopSound(const mobj_t *origin, int sfx_id, int timeout)
{
S_StartSoundEx(origin, sfx_id, timeout);
}

//
// S_StopSound
//
Expand Down Expand Up @@ -506,11 +463,7 @@ void S_UpdateSounds(const mobj_t *listener)

if(sfx)
{
if (c->loop && gametic > c->loop_timeout)
{
S_StopChannel(cnum);
}
else if (I_SoundIsPlaying(c->handle))
if (I_SoundIsPlaying(c->handle))
{
// initialize parameters
int volume = snd_SfxVolume;
Expand Down
2 changes: 0 additions & 2 deletions src/s_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ void S_Start(void);
// using <sound_id> from sounds.h
//
void S_StartSound(const mobj_t *origin, int sound_id);
void S_LoopSound(const mobj_t *origin, int sound_id, int timeout);

// Stop sound for thing at <origin>
void S_StopSound(const mobj_t *origin);
void S_StopLoopSounds(void);

// [FG] play sounds in full length
extern boolean full_sounds;
Expand Down

0 comments on commit 7338fec

Please sign in to comment.