]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_mix.c
default r_lerpsprites to 0 because it causes flickering
[xonotic/darkplaces.git] / snd_mix.c
index ebf166544c8ba7c435d83c15e720c4b977eebc30..ec3de1b7b6961351e2d6c039d1ac32cd356fc294 100644 (file)
--- a/snd_mix.c
+++ b/snd_mix.c
@@ -22,42 +22,29 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "snd_main.h"
 
 
-typedef struct portable_samplepair_s
-{
-       int sample[SND_LISTENERS];
-} portable_sampleframe_t;
-
-// LordHavoc: was 512, expanded to 2048
-#define        PAINTBUFFER_SIZE 2048
 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(unsigned char *bufstereo16le, size_t length, int rate);
+extern void SCR_CaptureVideo_SoundFrame(const portable_sampleframe_t *paintbuffer, size_t length);
 static void S_CaptureAVISound(size_t length)
 {
        size_t i;
-       unsigned char out[PAINTBUFFER_SIZE * 4];
-       unsigned char* out_ptr;
+       unsigned int j;
 
        if (!cls.capturevideo.active)
                return;
 
-       // write the sound buffer as little endian 16bit interleaved stereo
-       for(i = 0, out_ptr = out; i < length; i++, out_ptr += 4)
+       // undo whatever swapping the channel layout (swapstereo, ALSA) did
+       for(j = 0; j < snd_speakerlayout.channels; ++j)
        {
-               int n0, n1;
-
-               n0 = paintbuffer[i].sample[0];
-               n0 = bound(-32768, n0, 32767);
-               out_ptr[0] = (unsigned char)n0;
-               out_ptr[1] = (unsigned char)(n0 >> 8);
-
-               n1 = paintbuffer[i].sample[1];
-               n1 = bound(-32768, n1, 32767);
-               out_ptr[2] = (unsigned char)n1;
-               out_ptr[3] = (unsigned char)(n1 >> 8);
+               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(out, length, snd_renderbuffer->format.speed);
+
+       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)
@@ -118,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
        {
@@ -174,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);
        }
 }
 
@@ -455,7 +450,7 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes)
        unsigned int i;
        channel_t *ch;
        unsigned int frames;
-       unsigned char *outbytes = stream;
+       unsigned char *outbytes = (unsigned char *) stream;
 
        // mix as many times as needed to fill the requested buffer
        while (bufferframes)
@@ -487,7 +482,7 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes)
                        if (ch->pos < 0)
                        {
                                count = -ch->pos;
-                               count = min(count, frames);
+                               count = min(count, frames - ltime);
                                ch->pos += count;
                                ltime += count;
                        }
@@ -513,7 +508,7 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes)
                                                ch->pos = 0;
                                        else
                                        {
-                                               S_StopChannel (ch - channels);
+                                               S_StopChannel (ch - channels, false);
                                                break;
                                        }
                                }