]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_mix.c
r_water_scissormode: 0 = none, 1 = glScissor, 2 = glScissor and frustum culling
[xonotic/darkplaces.git] / snd_mix.c
index 1e013f4eb1b7e10fe7b3f45d636a3719cbbeffff..74a13671146855228c92ca6dbcfb9580a1fde464 100644 (file)
--- a/snd_mix.c
+++ b/snd_mix.c
@@ -23,15 +23,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 
 static portable_sampleframe_t paintbuffer[PAINTBUFFER_SIZE];
+static portable_sampleframe_t paintbuffer_unswapped[PAINTBUFFER_SIZE];
 
+extern speakerlayout_t snd_speakerlayout; // for querying the listeners
 
 extern void SCR_CaptureVideo_SoundFrame(const portable_sampleframe_t *paintbuffer, size_t length);
 static void S_CaptureAVISound(size_t length)
 {
+       size_t i;
+       unsigned int j;
+
        if (!cls.capturevideo.active)
                return;
 
-       SCR_CaptureVideo_SoundFrame(paintbuffer, length);
+       // undo whatever swapping the channel layout (swapstereo, ALSA) did
+       for(j = 0; j < snd_speakerlayout.channels; ++j)
+       {
+               unsigned int j0 = snd_speakerlayout.listeners[j].channel_unswapped;
+               for(i = 0; i < length; ++i)
+                       paintbuffer_unswapped[i].sample[j0] = paintbuffer[i].sample[j];
+       }
+
+       SCR_CaptureVideo_SoundFrame(paintbuffer_unswapped, length);
 }
 
 static void S_ConvertPaintBuffer(const portable_sampleframe_t *painted_ptr, void *rb_ptr, int nbframes, int width, int channels)
@@ -92,6 +105,10 @@ static void S_ConvertPaintBuffer(const portable_sampleframe_t *painted_ptr, void
                                *snd_out++ = bound(-32768, val, 32767);
                        }
                }
+
+               // noise is really really annoying
+               if (cls.timedemo)
+                       memset(rb_ptr, 0, nbframes * channels * width);
        }
        else  // 8bit
        {
@@ -148,6 +165,10 @@ static void S_ConvertPaintBuffer(const portable_sampleframe_t *painted_ptr, void
                                *snd_out++ = bound(0, val, 255);
                        }
                }
+
+               // noise is really really annoying
+               if (cls.timedemo)
+                       memset(rb_ptr, 128, nbframes * channels);
        }
 }
 
@@ -162,23 +183,13 @@ CHANNEL MIXING
 
 static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint, unsigned int count)
 {
-       int snd_vol, vol[SND_LISTENERS];
+       int vol[SND_LISTENERS];
        const snd_buffer_t *sb;
        unsigned int i, sb_offset;
 
-       // If this channel manages its own volume
-       if (ch->flags & CHANNELFLAG_FULLVOLUME)
-               snd_vol = 256;
-       else
-               snd_vol = (int)(volume.value * 256);
-
-       // calculate mixing volumes based on channel volumes and volume cvar
-       // also limit the volumes to values that won't clip
+       // move to the stack (do we need to?)
        for (i = 0;i < SND_LISTENERS;i++)
-       {
-               vol[i] = ch->listener_volume[i] * snd_vol;
-               vol[i] = bound(0, vol[i], 65536);
-       }
+               vol[i] = ch->listener_volume[i];
 
        // if volumes are all zero, just return
        for (i = 0;i < SND_LISTENERS;i++)
@@ -251,7 +262,7 @@ static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint,
                                        for (i = 0;i < count;i++)
                                        {
                                                paint[i].sample[0] += (samples[0] * vol[0]) >> 8;
-                                               paint[i].sample[1] += (samples[1] * vol[1]) >> 8;
+                                               paint[i].sample[1] += (samples[1] * vol[1] * ch->prologic_invert) >> 8;
                                                samples += 2;
                                        }
                                }
@@ -302,7 +313,7 @@ static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint,
                                        for (i = 0;i < count;i++)
                                        {
                                                paint[i].sample[0] += (samples[0] * vol[0]) >> 8;
-                                               paint[i].sample[1] += (samples[0] * vol[1]) >> 8;
+                                               paint[i].sample[1] += (samples[0] * vol[1] * ch->prologic_invert) >> 8;
                                                samples += 1;
                                        }
                                }
@@ -361,7 +372,7 @@ static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint,
                                        for (i = 0;i < count;i++)
                                        {
                                                paint[i].sample[0] += (samples[0] * vol[0]) >> 16;
-                                               paint[i].sample[1] += (samples[1] * vol[1]) >> 16;
+                                               paint[i].sample[1] += (samples[1] * vol[1] * ch->prologic_invert) >> 16;
                                                samples += 2;
                                        }
                                }
@@ -412,7 +423,7 @@ static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint,
                                        for (i = 0;i < count;i++)
                                        {
                                                paint[i].sample[0] += (samples[0] * vol[0]) >> 16;
-                                               paint[i].sample[1] += (samples[0] * vol[1]) >> 16;
+                                               paint[i].sample[1] += (samples[0] * vol[1] * ch->prologic_invert) >> 16;
                                                samples += 1;
                                        }
                                }
@@ -446,8 +457,8 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes)
                for (i = 0; i < total_channels ; i++, ch++)
                {
                        sfx_t *sfx;
-                       unsigned int ltime;
-                       unsigned int count;
+                       int ltime;
+                       int count;
 
                        sfx = ch->sfx;
                        if (sfx == NULL)
@@ -461,16 +472,16 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes)
                        if (ch->pos < 0)
                        {
                                count = -ch->pos;
-                               count = min(count, frames - ltime);
+                               count = min(count, (int)frames - ltime);
                                ch->pos += count;
                                ltime += count;
                        }
 
-                       while (ltime < frames)
+                       while (ltime < (int)frames)
                        {
                                // paint up to end of buffer or of input, whichever is lower
                                count = sfx->total_length - ch->pos;
-                               count = bound(0, count, frames - ltime);
+                               count = bound(0, count, (int)frames - ltime);
                                if (count)
                                {
                                        SND_PaintChannel (ch, paintbuffer + ltime, count);