]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_dma.c
added CVAR_SAVE and CVAR_NOTIFY flags to cvar_t structure (at the beginning), updated...
[xonotic/darkplaces.git] / snd_dma.c
index e5f69677923383002d10219dfed67651f1d31018..862287355bcf30a71292bb2ee99164277b333f53 100644 (file)
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -64,24 +64,22 @@ 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};
-cvar_t volume = {"volume", "0.7", true};
+// FIXME: make bgmvolume/volume always be registered for sake of config saving, and add check for whether sound is enabled to menu
+cvar_t bgmvolume = {CVAR_SAVE, "bgmvolume", "1"};
+cvar_t volume = {CVAR_SAVE, "volume", "0.7"};
 
-cvar_t nosound = {"nosound", "0"};
-cvar_t precache = {"precache", "1"};
-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"};
-cvar_t snd_noextraupdate = {"snd_noextraupdate", "0"};
-cvar_t snd_show = {"snd_show", "0"};
-cvar_t _snd_mixahead = {"_snd_mixahead", "0.1", true};
-cvar_t snd_swapstereo = {"snd_swapstereo", "0", true};
+cvar_t nosound = {0, "nosound", "0"};
+cvar_t precache = {0, "precache", "1"};
+//cvar_t loadas8bit = {0, "loadas8bit", "0"};
+cvar_t bgmbuffer = {0, "bgmbuffer", "4096"};
+cvar_t ambient_level = {0, "ambient_level", "0.3"};
+cvar_t ambient_fade = {0, "ambient_fade", "100"};
+cvar_t snd_noextraupdate = {0, "snd_noextraupdate", "0"};
+cvar_t snd_show = {0, "snd_show", "0"};
+cvar_t _snd_mixahead = {CVAR_SAVE, "_snd_mixahead", "0.1"};
+cvar_t snd_swapstereo = {CVAR_SAVE, "snd_swapstereo", "0"};
 
 
 // ====================================================================
@@ -189,7 +187,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 +197,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 +233,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 +374,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 +412,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 +515,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 +681,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 +705,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 +761,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)