]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_alsa.c
add apparently not yet working optimization flags to Mem_ExpandableArray function...
[xonotic/darkplaces.git] / snd_alsa.c
index e4a9ffe0897c528f89e8b1a84c2f03c2f4d97a76..4ac8b1a702adf9f5ac908f5acfba74d516540607 100644 (file)
 
 // ALSA module, used by Linux
 
+#include "quakedef.h"
 
 #include <alsa/asoundlib.h>
 
-#include "quakedef.h"
 #include "snd_main.h"
 
 
@@ -63,7 +63,7 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested)
 
                if (suggested != NULL)
                {
-                       memcpy (suggested, requested, sizeof (suggested));
+                       memcpy (suggested, requested, sizeof (*suggested));
 
                        if (requested->width < 1)
                                suggested->width = 1;
@@ -73,16 +73,16 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested)
                        Con_Printf ("SndSys_Init: suggesting sound width = %hu\n",
                                                suggested->width);
                }
-               
+
                return false;
     }
-       
+
        if (pcm_handle != NULL)
        {
                Con_Print ("SndSys_Init: WARNING: Init called before Shutdown!\n");
                SndSys_Shutdown ();
        }
-       
+
        // Determine the name of the PCM handle we'll use
        switch (requested->channels)
        {
@@ -105,7 +105,7 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested)
                pcm_name = com_argv[i + 1];
 
        // Open the audio device
-       Con_DPrintf ("SndSys_Init: PCM device is \"%s\"\n", pcm_name);
+       Con_Printf ("SndSys_Init: PCM device is \"%s\"\n", pcm_name);
        err = snd_pcm_open (&pcm_handle, pcm_name, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
        if (err != 0)
        {
@@ -113,7 +113,7 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested)
                                        pcm_name, snd_strerror (err));
                return false;
        }
-       
+
        // Allocate the hardware parameters
        err = snd_pcm_hw_params_malloc (&hw_params);
        if (err != 0)
@@ -201,14 +201,15 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested)
        snd_renderbuffer = Snd_CreateRingBuffer(requested, 0, NULL);
        expected_delay = 0;
        alsasoundtime = 0;
-       alsaspeakerlayout = true;
-       
+       if (snd_channellayout.integer == SND_CHANNELLAYOUT_AUTO)
+               Cvar_SetValueQuick (&snd_channellayout, SND_CHANNELLAYOUT_ALSA);
+
        return true;
 
 
 // It's not very clean, but it avoids a lot of duplicated code.
 init_error:
-       
+
        if (hw_params != NULL)
                snd_pcm_hw_params_free (hw_params);
        SndSys_Shutdown ();
@@ -254,11 +255,11 @@ static qboolean SndSys_Recover (int err_num)
        // We can only do something on underrun ("broken pipe") errors
        if (err_num != -EPIPE)
                return false;
-                       
+
        err = snd_pcm_prepare (pcm_handle);
        if (err != 0)
        {
-               Con_DPrintf ("SndSys_Recover: unable to recover (%s)\n",
+               Con_Printf ("SndSys_Recover: unable to recover (%s)\n",
                                         snd_strerror (err));
 
                // TOCHECK: should we stop the playback ?
@@ -282,7 +283,7 @@ static snd_pcm_sframes_t SndSys_Write (const unsigned char* buffer, unsigned int
        written = snd_pcm_writei (pcm_handle, buffer, nbframes);
        if (written < 0)
        {
-               if (developer.integer >= 100)
+               if (developer.integer >= 1000 && vid_activewindow)
                        Con_Printf ("SndSys_Write: audio write returned %ld (%s)!\n",
                                                 written, snd_strerror (written));
 
@@ -294,7 +295,12 @@ static snd_pcm_sframes_t SndSys_Write (const unsigned char* buffer, unsigned int
                                                         written, snd_strerror (written));
                }
        }
-       
+       if (written > 0)
+       {
+               snd_renderbuffer->startframe += written;
+               expected_delay += written;
+       }
+
        return written;
 }
 
@@ -311,7 +317,7 @@ void SndSys_Submit (void)
        unsigned int startoffset, factor;
        snd_pcm_uframes_t limit, nbframes;
        snd_pcm_sframes_t written;
-       
+
        if (pcm_handle == NULL ||
                snd_renderbuffer->startframe == snd_renderbuffer->endframe)
                return;
@@ -324,14 +330,9 @@ void SndSys_Submit (void)
        if (nbframes > limit)
        {
                written = SndSys_Write (&snd_renderbuffer->ring[startoffset * factor], limit);
-               if (written < 0)
+               if (written < 0 || (snd_pcm_uframes_t)written != limit)
                        return;
-               snd_renderbuffer->startframe += written;
-               expected_delay += written;
 
-               if ((snd_pcm_uframes_t)written != limit)
-                       return;
-               
                nbframes -= limit;
                startoffset = 0;
        }
@@ -339,9 +340,6 @@ void SndSys_Submit (void)
        written = SndSys_Write (&snd_renderbuffer->ring[startoffset * factor], nbframes);
        if (written < 0)
                return;
-
-       snd_renderbuffer->startframe += written;
-       expected_delay += written;
 }
 
 
@@ -363,7 +361,7 @@ unsigned int SndSys_GetSoundTime (void)
        err = snd_pcm_delay (pcm_handle, &delay);
        if (err != 0)
        {
-               if (developer.integer >= 100)
+               if (developer.integer >= 1000 && vid_activewindow)
                        Con_DPrintf ("SndSys_GetSoundTime: can't get playback delay (%s)\n",
                                                 snd_strerror (err));
 
@@ -388,9 +386,9 @@ unsigned int SndSys_GetSoundTime (void)
        else
                timediff = expected_delay - delay;
        expected_delay = delay;
-       
+
        alsasoundtime += (unsigned int)timediff;
-       
+
        return alsasoundtime;
 }