]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_main.c
DP_QC_GETTIME_CDTRACK: extension to query the playing time of the current cd track.
[xonotic/darkplaces.git] / snd_main.c
index 21cf2033c43886a2769a5da29d2f809cd90089d0..e4a4934a2993458f8044e4bbd6e51e2fa3e00de8 100644 (file)
@@ -254,7 +254,7 @@ static void S_Play_Common (float fvol, float attenuation)
                        i++;
                }
 
-               sfx = S_PrecacheSound (name, true, false);
+               sfx = S_PrecacheSound (name, true, true);
                if (sfx)
                {
                        ch_ind = S_StartSound (-1, 0, sfx, listener_origin, fvol, attenuation);
@@ -1002,13 +1002,13 @@ void S_FreeSfx (sfx_t *sfx, qboolean force)
 
 /*
 ==================
-S_ServerSounds
+S_ClearUsed
 ==================
 */
-void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds)
+void S_ClearUsed (void)
 {
        sfx_t *sfx;
-       sfx_t *sfxnext;
+//     sfx_t *sfxnext;
        unsigned int i;
 
        // Start the ambient sounds and make them loop
@@ -1036,20 +1036,6 @@ void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds)
                        S_UnlockSfx (sfx);
                        sfx->flags &= ~SFXFLAG_SERVERSOUND;
                }
-
-       // Add 1 lock and the SFXFLAG_SERVERSOUND flag to each sfx in "serversound"
-       for (i = 1; i < numsounds; i++)
-       {
-               sfx = S_FindName (serversound[i]);
-               if (sfx != NULL)
-               {
-                       // clear the FILEMISSING flag so that S_LoadSound will try again on a
-                       // previously missing file
-                       sfx->flags &= ~ SFXFLAG_FILEMISSING;
-                       S_LockSfx (sfx);
-                       sfx->flags |= SFXFLAG_SERVERSOUND;
-               }
-       }
 }
 
 /*
@@ -1076,7 +1062,7 @@ void S_PurgeUnused(void)
 S_PrecacheSound
 ==================
 */
-sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean lock)
+sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean serversound)
 {
        sfx_t *sfx;
 
@@ -1095,8 +1081,11 @@ sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean lock)
        // previously missing file
        sfx->flags &= ~ SFXFLAG_FILEMISSING;
 
-       if (lock)
+       if (serversound && !(sfx->flags & SFXFLAG_SERVERSOUND))
+       {
                S_LockSfx (sfx);
+               sfx->flags |= SFXFLAG_SERVERSOUND;
+       }
 
        if (!nosound.integer && snd_precache.integer)
                S_LoadSound(sfx, complain);
@@ -1202,7 +1191,7 @@ channel_t *SND_PickChannel(int entnum, int entchannel)
                {
                        // no sound on this channel
                        first_to_die = ch_idx;
-                       break;
+                       goto emptychan_found;
                }
 
                // don't let monster sounds override player sounds
@@ -1223,7 +1212,10 @@ channel_t *SND_PickChannel(int entnum, int entchannel)
 
        if (first_to_die == -1)
                return NULL;
+       
+       S_StopChannel (first_to_die, true);
 
+emptychan_found:
        return &channels[first_to_die];
 }
 
@@ -1394,7 +1386,19 @@ void SND_Spatialize(channel_t *ch, qboolean isstatic)
 
 void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, vec3_t origin, float fvol, float attenuation, qboolean isstatic)
 {
+       if (!sfx)
+       {
+               Con_Printf("S_PlaySfxOnChannel called with NULL??\n");
+               return;
+       }
        // Initialize the channel
+       // a crash was reported on an in-use channel, so check here...
+       if (target_chan->sfx)
+       {
+               int channelindex = (int)(target_chan - channels);
+               Con_Printf("S_PlaySfxOnChannel(%s): channel %i already in use??  Clearing.\n", sfx->name, channelindex);
+               S_StopChannel (channelindex, true);
+       }
        // We MUST set sfx LAST because otherwise we could crash a threaded mixer
        // (otherwise we'd have to call SndSys_LockRenderBuffer here)
        memset (target_chan, 0, sizeof (*target_chan));
@@ -1594,6 +1598,22 @@ void S_SetChannelVolume (unsigned int ch_ind, float fvol)
        channels[ch_ind].master_vol = (int)(fvol * 255.0f);
 }
 
+float S_GetChannelPosition (unsigned int ch_ind)
+{
+       // note: this is NOT accurate yet
+       int s;
+       channel_t *ch = &channels[ch_ind];
+       sfx_t *sfx = ch->sfx;
+
+       s = ch->pos;
+       /*
+       if(!snd_usethreadedmixing)
+               s += _snd_mixahead.value * S_GetSoundRate();
+       */
+       return (s % sfx->total_length) / (float) S_GetSoundRate();
+}
+
+
 
 /*
 =================