]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
changed loopstart from signed to unsigned, now un-looped sounds are
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 14 May 2007 09:33:26 +0000 (09:33 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 14 May 2007 09:33:26 +0000 (09:33 +0000)
represented with loopstart == total_length

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7272 d7cf8633-e32d-0410-b094-e92efae38249

snd_main.c
snd_main.h
snd_mix.c
snd_ogg.c
snd_wav.c

index 7cb7d55e3eb77fad9df7a4773c8034948ea88ee7..1734baeac2246df6ed7e55c73ebcc865dd6efcb2 100644 (file)
@@ -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);
        }
index 47a580a93dcf1fc98f2334671fd40f0ea2c03a90..1d6011ab909a9ff3950af7950452c508b5f15ec1 100644 (file)
@@ -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
 };
index 43be3651016ccc3ab9aa161d26c4d138131f833e..43bca9d9dfdd8de6cf1165219ea8905ddea66f81 100644 (file)
--- 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);
index 5b3e3c761b9b6d04f7bcb5b2138a6e8249caf852..4e1a713d4b86e47a56ad2fa57c0d7ad81e9f5ca1 100644 (file)
--- 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);
index d96c8199ee69cf307709312150d767f360528532..c40986e2dcc87b4b0c45e5adc1e3a1e3c1ec31a6 100644 (file)
--- 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);