]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_dma.c
rearranged sky rendering code
[xonotic/darkplaces.git] / snd_dma.c
index e5f69677923383002d10219dfed67651f1d31018..d8001f4f39e6cddfc44f3760a9f1f54f82a7c874 100644 (file)
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -64,9 +64,6 @@ int                   num_sfx;
 
 sfx_t          *ambient_sfx[NUM_AMBIENTS];
 
-int            desired_speed = 11025;
-int            desired_bits = 16;
-
 int sound_started=0;
 
 cvar_t bgmvolume = {"bgmvolume", "1", true};
@@ -74,7 +71,7 @@ cvar_t volume = {"volume", "0.7", true};
 
 cvar_t nosound = {"nosound", "0"};
 cvar_t precache = {"precache", "1"};
-cvar_t loadas8bit = {"loadas8bit", "0"};
+//cvar_t loadas8bit = {"loadas8bit", "0"};
 cvar_t bgmbuffer = {"bgmbuffer", "4096"};
 cvar_t ambient_level = {"ambient_level", "0.3"};
 cvar_t ambient_fade = {"ambient_fade", "100"};
@@ -189,7 +186,7 @@ void S_Init (void)
        Cvar_RegisterVariable(&nosound);
        Cvar_RegisterVariable(&volume);
        Cvar_RegisterVariable(&precache);
-       Cvar_RegisterVariable(&loadas8bit);
+//     Cvar_RegisterVariable(&loadas8bit);
        Cvar_RegisterVariable(&bgmvolume);
        Cvar_RegisterVariable(&bgmbuffer);
        Cvar_RegisterVariable(&ambient_level);
@@ -199,11 +196,13 @@ void S_Init (void)
        Cvar_RegisterVariable(&_snd_mixahead);
        Cvar_RegisterVariable(&snd_swapstereo); // LordHavoc: for people with backwards sound wiring
 
+       /*
        if (host_parms.memsize < 0x800000)
        {
                Cvar_Set ("loadas8bit", "1");
                Con_Printf ("loading all sounds as 8bit\n");
        }
+       */
 
 
 
@@ -233,6 +232,9 @@ void S_Init (void)
                shm->buffer = Hunk_AllocName(1<<16, "shmbuf");
        }
 
+       if (!sound_started)
+               return;
+
        Con_Printf ("Sound sampling rate: %i\n", shm->speed);
 
        // provides a tick sound until washed clean
@@ -371,7 +373,7 @@ channel_t *SND_PickChannel(int entnum, int entchannel)
                if (entchannel != 0             // channel 0 never overrides
                && channels[ch_idx].entnum == entnum
                && (channels[ch_idx].entchannel == entchannel || entchannel == -1) )
-               {       // allways override sound from same entity
+               {       // always override sound from same entity
                        first_to_die = ch_idx;
                        break;
                }
@@ -409,7 +411,7 @@ void SND_Spatialize(channel_t *ch)
     vec3_t source_vec;
        sfx_t *snd;
 
-// anything coming from the view entity will allways be full volume
+// anything coming from the view entity will always be full volume
 // LordHavoc: make sounds with ATTN_NONE have no spatialization
        if (ch->entnum == cl.viewentity || ch->dist_mult == 0)
        {
@@ -512,9 +514,12 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
                        continue;
                if (check->sfx == sfx && !check->pos)
                {
-                       skip = rand () % (int)(0.1*shm->speed);
-                       if (skip >= target_chan->end)
-                               skip = target_chan->end - 1;
+                       // LordHavoc: fixed skip calculations
+                       skip = 0.1 * shm->speed;
+                       if (skip > sc->length)
+                               skip = sc->length;
+                       if (skip > 0)
+                               skip = rand() % skip;
                        target_chan->pos += skip;
                        target_chan->end -= skip;
                        break;
@@ -675,26 +680,23 @@ void S_UpdateAmbientSounds (void)
        int                     ambient_channel;
        channel_t       *chan;
 
-       if (!snd_ambient)
-               return;
+       // LordHavoc: kill ambient sounds until proven otherwise
+       for (ambient_channel = 0 ; ambient_channel < NUM_AMBIENTS;ambient_channel++)
+               channels[ambient_channel].sfx = NULL;
 
-// calc ambient sound levels
-       if (!cl.worldmodel)
+       if (!snd_ambient || !cl.worldmodel || ambient_level.value <= 0)
                return;
 
        l = Mod_PointInLeaf (listener_origin, cl.worldmodel);
-       if (!l || !ambient_level.value)
-       {
-               for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
-                       channels[ambient_channel].sfx = NULL;
+       if (!l)
                return;
-       }
 
+// calc ambient sound levels
        for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
        {
                chan = &channels[ambient_channel];      
                chan->sfx = ambient_sfx[ambient_channel];
-       
+
                vol = ambient_level.value * l->ambient_sound_level[ambient_channel];
                if (vol < 8)
                        vol = 0;
@@ -702,13 +704,13 @@ void S_UpdateAmbientSounds (void)
        // don't adjust volume too fast
                if (chan->master_vol < vol)
                {
-                       chan->master_vol += host_frametime * ambient_fade.value;
+                       chan->master_vol += host_realframetime * ambient_fade.value;
                        if (chan->master_vol > vol)
                                chan->master_vol = vol;
                }
                else if (chan->master_vol > vol)
                {
-                       chan->master_vol -= host_frametime * ambient_fade.value;
+                       chan->master_vol -= host_realframetime * ambient_fade.value;
                        if (chan->master_vol < vol)
                                chan->master_vol = vol;
                }
@@ -758,7 +760,7 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
        // try to combine static sounds with a previous channel of the same
        // sound effect so we don't mix five torches every frame
        
-               if (i >= MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS)
+               if (i > MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS)
                {
                // see if it can just use the last one
                        if (combine && combine->sfx == ch->sfx)