]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_mix.c
fix very stupid typo in input merging when cl_movement is 0
[xonotic/darkplaces.git] / snd_mix.c
index 0e4dada06e3248d9f37a835ca326d6a907389f2c..dc2a147402a58b0c06fcacea31ae6d62e7f2b868 100644 (file)
--- a/snd_mix.c
+++ b/snd_mix.c
@@ -32,7 +32,6 @@ typedef struct portable_samplepair_s
 portable_sampleframe_t paintbuffer[PAINTBUFFER_SIZE];
 
 
-// FIXME: this desyncs with the video too easily
 extern void SCR_CaptureVideo_SoundFrame(unsigned char *bufstereo16le, size_t length, int rate);
 static void S_CaptureAVISound(size_t length)
 {
@@ -40,7 +39,7 @@ static void S_CaptureAVISound(size_t length)
        unsigned char out[PAINTBUFFER_SIZE * 4];
        unsigned char* out_ptr;
 
-       if (!cls.capturevideo_active)
+       if (!cls.capturevideo.active)
                return;
 
        // write the sound buffer as little endian 16bit interleaved stereo
@@ -68,7 +67,7 @@ static unsigned int S_TransferPaintBuffer(snd_ringbuffer_t* rb, unsigned int sta
        // Lock submitbuffer
        if (!simsound && !SndSys_LockRenderBuffer())
                return 0;
-       
+
        partialend = starttime;
        while (partialend < endtime)  // handle recirculating buffer issues
        {
@@ -91,102 +90,46 @@ static unsigned int S_TransferPaintBuffer(snd_ringbuffer_t* rb, unsigned int sta
                        short *snd_out = (short*)rb_ptr;
                        if (rb->format.channels == 8)  // 7.1 surround
                        {
-                               if (snd_swapstereo.value)
-                               {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[3], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[2], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[4], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[5], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[6], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[7], 32767);
-                                       }
-                               }
-                               else
+                               for (i = 0;i < nbframes;i++, painted_ptr++)
                                {
-                                       for (i = 0;i < nbframes;i++, painted_ptr++)
-                                       {
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[2], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[3], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[4], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[5], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[6], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[7], 32767);
-                                       }
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[2], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[3], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[4], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[5], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[6], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[7], 32767);
                                }
                        }
                        else if (rb->format.channels == 6)  // 5.1 surround
                        {
-                               if (snd_swapstereo.value)
-                               {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[3], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[2], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[4], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[5], 32767);
-                                       }
-                               }
-                               else
+                               for (i = 0; i < nbframes; i++, painted_ptr++)
                                {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[2], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[3], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[4], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[5], 32767);
-                                       }
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[2], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[3], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[4], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[5], 32767);
                                }
                        }
                        else if (rb->format.channels == 4)  // 4.0 surround
                        {
-                               if (snd_swapstereo.value)
-                               {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[3], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[2], 32767);
-                                       }
-                               }
-                               else
+                               for (i = 0; i < nbframes; i++, painted_ptr++)
                                {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[2], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[3], 32767);
-                                       }
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[2], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[3], 32767);
                                }
                        }
                        else if (rb->format.channels == 2)  // 2.0 stereo
                        {
-                               if (snd_swapstereo.value)
-                               {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
-                                       }
-                               }
-                               else
+                               for (i = 0; i < nbframes; i++, painted_ptr++)
                                {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
-                                               *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
-                                       }
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[0], 32767);
+                                       *snd_out++ = bound(-32768, painted_ptr->sample[1], 32767);
                                }
                        }
                        else if (rb->format.channels == 1)  // 1.0 mono
@@ -203,102 +146,46 @@ static unsigned int S_TransferPaintBuffer(snd_ringbuffer_t* rb, unsigned int sta
                        unsigned char *snd_out = (unsigned char*)rb_ptr;
                        if (rb->format.channels == 8)  // 7.1 surround
                        {
-                               if (snd_swapstereo.value)
-                               {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[3] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[2] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[4] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[5] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[6] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[7] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                       }
-                               }
-                               else
+                               for (i = 0; i < nbframes; i++, painted_ptr++)
                                {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[2] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[3] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[4] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[5] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[6] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[7] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                       }
+                                       val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[2] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[3] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[4] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[5] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[6] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[7] >> 8) + 128; *snd_out++ = bound(0, val, 255);
                                }
                        }
                        else if (rb->format.channels == 6)  // 5.1 surround
                        {
-                               if (snd_swapstereo.value)
-                               {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[3] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[2] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[4] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[5] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                       }
-                               }
-                               else
+                               for (i = 0; i < nbframes; i++, painted_ptr++)
                                {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[2] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[3] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[4] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[5] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                       }
+                                       val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[2] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[3] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[4] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[5] >> 8) + 128; *snd_out++ = bound(0, val, 255);
                                }
                        }
                        else if (rb->format.channels == 4)  // 4.0 surround
                        {
-                               if (snd_swapstereo.value)
-                               {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[3] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[2] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                       }
-                               }
-                               else
+                               for (i = 0; i < nbframes; i++, painted_ptr++)
                                {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[2] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[3] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                       }
+                                       val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[2] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[3] >> 8) + 128; *snd_out++ = bound(0, val, 255);
                                }
                        }
                        else if (rb->format.channels == 2)  // 2.0 stereo
                        {
-                               if (snd_swapstereo.value)
-                               {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                       }
-                               }
-                               else
+                               for (i = 0; i < nbframes; i++, painted_ptr++)
                                {
-                                       for (i = 0; i < nbframes; i++, painted_ptr++)
-                                       {
-                                               val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                               val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
-                                       }
+                                       val = (painted_ptr->sample[0] >> 8) + 128; *snd_out++ = bound(0, val, 255);
+                                       val = (painted_ptr->sample[1] >> 8) + 128; *snd_out++ = bound(0, val, 255);
                                }
                        }
                        else if (rb->format.channels == 1)  // 1.0 mono
@@ -355,7 +242,7 @@ static qboolean SND_PaintChannel (channel_t *ch, unsigned int count)
        if (sb == NULL)
        {
                Con_DPrintf("SND_PaintChannel: ERROR: can't get sound buffer from sfx \"%s\"\n",
-                                       ch->sfx->name, count);
+                                       ch->sfx->name); // , count); // or add this? FIXME
        }
        else
        {