From 087c96690cbc912a6eeca0555d5bf1ffaa6c2daf Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 14 May 2007 09:33:26 +0000 Subject: [PATCH] changed loopstart from signed to unsigned, now un-looped sounds are represented with loopstart == total_length git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7272 d7cf8633-e32d-0410-b094-e92efae38249 --- snd_main.c | 6 +++--- snd_main.h | 4 ++-- snd_mix.c | 16 +++++++++------- snd_ogg.c | 4 ++-- snd_wav.c | 3 ++- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/snd_main.c b/snd_main.c index 7cb7d55e..1734baea 100644 --- a/snd_main.c +++ b/snd_main.c @@ -268,7 +268,7 @@ static void S_SoundList_f (void) size = sfx->memsize; format = sfx->fetcher->getfmt(sfx); Con_Printf ("%c%c%c%c(%2db, %6s) %8i : %s\n", - (sfx->loopstart >= 0) ? 'L' : ' ', + (sfx->loopstart < sfx->total_length) ? 'L' : ' ', (sfx->flags & SFXFLAG_STREAMED) ? 'S' : ' ', (sfx->locks > 0) ? 'K' : ' ', (sfx->flags & SFXFLAG_PERMANENTLOCK) ? 'P' : ' ', @@ -1075,7 +1075,7 @@ channel_t *SND_PickChannel(int entnum, int entchannel) continue; // don't override looped sounds - if ((ch->flags & CHANNELFLAG_FORCELOOP) || ch->sfx->loopstart >= 0) + if ((ch->flags & CHANNELFLAG_FORCELOOP) || ch->sfx->loopstart < ch->sfx->total_length) continue; life_left = ch->sfx->total_length - ch->pos; @@ -1169,7 +1169,7 @@ void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, // If it's a static sound if (isstatic) { - if (sfx->loopstart == -1) + if (sfx->loopstart >= sfx->total_length) Con_DPrintf("Quake compatibility warning: Static sound \"%s\" is not looped\n", sfx->name); target_chan->dist_mult = attenuation / (64.0f * snd_soundradius.value); } diff --git a/snd_main.h b/snd_main.h index 47a580a9..1d6011ab 100644 --- a/snd_main.h +++ b/snd_main.h @@ -71,8 +71,8 @@ struct sfx_s // freed at level change by S_ServerSounds. unsigned int flags; // cf SFXFLAG_* defines - int loopstart; // in sample frames. -1 if not looped - int total_length; // in sample frames + unsigned int loopstart; // in sample frames. equals total_length if not looped + unsigned int total_length; // in sample frames const snd_fetcher_t *fetcher; void *fetcher_data; // Per-sfx data for the sound fetching functions }; diff --git a/snd_mix.c b/snd_mix.c index 43be3651..43bca9d9 100644 --- a/snd_mix.c +++ b/snd_mix.c @@ -512,7 +512,7 @@ void S_PaintChannels (snd_ringbuffer_t* rb, unsigned int starttime, unsigned int { sfx_t *sfx; unsigned int ltime; - int count; + unsigned int count; sfx = ch->sfx; if (sfx == NULL) @@ -526,7 +526,7 @@ void S_PaintChannels (snd_ringbuffer_t* rb, unsigned int starttime, unsigned int if (ch->pos < 0) { count = -ch->pos; - count = min(count, (int)(partialend - ltime)); + count = min(count, partialend - ltime); ch->pos += count; ltime += count; } @@ -535,19 +535,21 @@ void S_PaintChannels (snd_ringbuffer_t* rb, unsigned int starttime, unsigned int { // paint up to end of buffer or of input, whichever is lower count = sfx->total_length - ch->pos; - count = bound(0, count, (int)(partialend - ltime)); + count = bound(0, count, partialend - ltime); if (count) { - SND_PaintChannel (ch, (unsigned int)count); + SND_PaintChannel (ch, count); ch->pos += count; ltime += count; } // if at end of sfx, loop or stop the channel - if (ch->pos >= sfx->total_length) + if (ch->pos >= (int)sfx->total_length) { - if (sfx->loopstart >= 0 || (ch->flags & CHANNELFLAG_FORCELOOP)) - ch->pos = bound(0, sfx->loopstart, (int)sfx->total_length - 1); + if (sfx->loopstart < sfx->total_length) + ch->pos = sfx->loopstart; + else if (ch->flags & CHANNELFLAG_FORCELOOP) + ch->pos = 0; else { S_StopChannel (ch - channels); diff --git a/snd_ogg.c b/snd_ogg.c index 5b3e3c76..4e1a713d 100644 --- a/snd_ogg.c +++ b/snd_ogg.c @@ -682,9 +682,9 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *sfx) sfx->fetcher_data = per_sfx; sfx->fetcher = &ogg_fetcher; - sfx->loopstart = -1; sfx->flags |= SFXFLAG_STREAMED; sfx->total_length = (int)((size_t)len / (per_sfx->format.channels * 2) * ((double)snd_renderbuffer->format.speed / per_sfx->format.speed)); + sfx->loopstart = sfx->total_length; } else { @@ -728,7 +728,7 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *sfx) sfx->total_length = sb->nbframes; sfx->memsize += sb->maxframes * sb->format.channels * sb->format.width + sizeof (*sb) - sizeof (sb->samples); - sfx->loopstart = -1; + sfx->loopstart = sfx->total_length; sfx->flags &= ~SFXFLAG_STREAMED; qov_clear (&vf); diff --git a/snd_wav.c b/snd_wav.c index d96c8199..c40986e2 100644 --- a/snd_wav.c +++ b/snd_wav.c @@ -332,9 +332,10 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *sfx) sfx->memsize += sb->maxframes * sb->format.channels * sb->format.width + sizeof (*sb) - sizeof (sb->samples); if (info.loopstart < 0) - sfx->loopstart = -1; + sfx->loopstart = sfx->total_length; else sfx->loopstart = (double)info.loopstart * (double)snd_renderbuffer->format.speed / (double)sb->format.speed; + sfx->loopstart = min(sfx->loopstart, sfx->total_length); sfx->flags &= ~SFXFLAG_STREAMED; Mem_Free (data); -- 2.39.2