]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_alsa.c
eliminated qbyte type, now uses unsigned char throughout the engine for this purpose
[xonotic/darkplaces.git] / snd_alsa.c
index 709d8314543705a4cfa6e3bec63c964de4fb2d46..95310d84f2e413d9f60aaa9be6cd8859f9f40f3c 100644 (file)
@@ -29,9 +29,9 @@
 #include <alsa/asoundlib.h>
 
 #include "quakedef.h"
+#include "snd_main.h"
 
 static int                     snd_inited;
-static int                     snd_blocked = 0;
 static snd_pcm_uframes_t buffer_size;
 
 static const char  *pcmname = NULL;
@@ -49,11 +49,13 @@ qboolean SNDDMA_Init (void)
        snd_pcm_hw_params_alloca (&hw);
        snd_pcm_sw_params_alloca (&sw);
 
+// COMMANDLINEOPTION: Linux ALSA Sound: -sndpcm <devicename> selects which pcm device to us, default is "default"
        if ((i=COM_CheckParm("-sndpcm"))!=0)
                pcmname=com_argv[i+1];
        if (!pcmname)
                pcmname = "default";
 
+// COMMANDLINEOPTION: Linux ALSA Sound: -sndbits <number> sets sound precision to 8 or 16 bit (email me if you want others added)
        if ((i=COM_CheckParm("-sndbits")) != 0)
        {
                bps = atoi(com_argv[i+1]);
@@ -64,6 +66,7 @@ qboolean SNDDMA_Init (void)
                }
        }
 
+// COMMANDLINEOPTION: Linux ALSA Sound: -sndspeed <hz> chooses 44100 hz, 22100 hz, or 11025 hz sound output rate
        if ((i=COM_CheckParm("-sndspeed")) != 0)
        {
                rate = atoi(com_argv[i+1]);
@@ -74,22 +77,24 @@ qboolean SNDDMA_Init (void)
                }
        }
 
+// COMMANDLINEOPTION: Linux ALSA Sound: -sndmono sets sound output to mono
        if ((i=COM_CheckParm("-sndmono")) != 0)
                stereo=0;
+// COMMANDLINEOPTION: Linux ALSA Sound: -sndstereo sets sound output to stereo
        if ((i=COM_CheckParm("-sndstereo")) != 0)
                stereo=1;
 
        err = snd_pcm_open (&pcm, pcmname, SND_PCM_STREAM_PLAYBACK,
                                                  SND_PCM_NONBLOCK);
        if (0 > err) {
-               Sys_Printf ("Error: audio open error: %s\n", snd_strerror (err));
+               Con_Printf ("Error: audio open error: %s\n", snd_strerror (err));
                return 0;
        }
-       Sys_Printf ("ALSA: Using PCM %s.\n", pcmname);
+       Con_Printf ("ALSA: Using PCM %s.\n", pcmname);
 
        err = snd_pcm_hw_params_any (pcm, hw);
        if (0 > err) {
-               Sys_Printf ("ALSA: error setting hw_params_any. %s\n",
+               Con_Printf ("ALSA: error setting hw_params_any. %s\n",
                                        snd_strerror (err));
                goto error;
        }
@@ -97,7 +102,7 @@ qboolean SNDDMA_Init (void)
        err = snd_pcm_hw_params_set_access (pcm, hw,
                                                                                  SND_PCM_ACCESS_MMAP_INTERLEAVED);
        if (0 > err) {
-               Sys_Printf ("ALSA: Failure to set noninterleaved PCM access. %s\n"
+               Con_Printf ("ALSA: Failure to set noninterleaved PCM access. %s\n"
                                        "Note: Interleaved is not supported\n",
                                        snd_strerror (err));
                goto error;
@@ -113,7 +118,7 @@ qboolean SNDDMA_Init (void)
                                                                                                                 SND_PCM_FORMAT_U8))) {
                                bps = 8;
                        } else {
-                               Sys_Printf ("ALSA: no useable formats. %s\n",
+                               Con_Printf ("ALSA: no useable formats. %s\n",
                                                        snd_strerror (err));
                                goto error;
                        }
@@ -124,13 +129,13 @@ qboolean SNDDMA_Init (void)
                                                                                                  SND_PCM_FORMAT_U8 :
                                                                                                  SND_PCM_FORMAT_S16);
                        if (0 > err) {
-                               Sys_Printf ("ALSA: no usable formats. %s\n",
+                               Con_Printf ("ALSA: no usable formats. %s\n",
                                                        snd_strerror (err));
                                goto error;
                        }
                        break;
                default:
-                       Sys_Printf ("ALSA: desired format not supported\n");
+                       Con_Printf ("ALSA: desired format not supported\n");
                        goto error;
        }
 
@@ -143,7 +148,7 @@ qboolean SNDDMA_Init (void)
                                                                                                                                         1))) {
                                stereo = 0;
                        } else {
-                               Sys_Printf ("ALSA: no usable channels. %s\n",
+                               Con_Printf ("ALSA: no usable channels. %s\n",
                                                        snd_strerror (err));
                                goto error;
                        }
@@ -152,13 +157,13 @@ qboolean SNDDMA_Init (void)
                case 1:
                        err = snd_pcm_hw_params_set_channels (pcm, hw, stereo ? 2 : 1);
                        if (0 > err) {
-                               Sys_Printf ("ALSA: no usable channels. %s\n",
+                               Con_Printf ("ALSA: no usable channels. %s\n",
                                                        snd_strerror (err));
                                goto error;
                        }
                        break;
                default:
-                       Sys_Printf ("ALSA: desired channels not supported\n");
+                       Con_Printf ("ALSA: desired channels not supported\n");
                        goto error;
        }
 
@@ -180,7 +185,7 @@ qboolean SNDDMA_Init (void)
                                        if (0 <= err) {
                                                frag_size = 8 * bps;
                                        } else {
-                                               Sys_Printf ("ALSA: no usable rates. %s\n",
+                                               Con_Printf ("ALSA: no usable rates. %s\n",
                                                                        snd_strerror (err));
                                                goto error;
                                        }
@@ -192,50 +197,50 @@ qboolean SNDDMA_Init (void)
                case 44100:
                        err = snd_pcm_hw_params_set_rate_near (pcm, hw, &rate, 0);
                        if (0 > err) {
-                               Sys_Printf ("ALSA: desired rate %i not supported. %s\n", rate,
+                               Con_Printf ("ALSA: desired rate %i not supported. %s\n", rate,
                                                        snd_strerror (err));
                                goto error;
                        }
                        frag_size = 8 * bps * rate / 11025;
                        break;
                default:
-                       Sys_Printf ("ALSA: desired rate %i not supported.\n", rate);
+                       Con_Printf ("ALSA: desired rate %i not supported.\n", rate);
                        goto error;
        }
 
        err = snd_pcm_hw_params_set_period_size_near (pcm, hw, &frag_size, 0);
        if (0 > err) {
-               Sys_Printf ("ALSA: unable to set period size near %i. %s\n",
+               Con_Printf ("ALSA: unable to set period size near %i. %s\n",
                                        (int) frag_size, snd_strerror (err));
                goto error;
        }
        err = snd_pcm_hw_params (pcm, hw);
        if (0 > err) {
-               Sys_Printf ("ALSA: unable to install hw params: %s\n",
+               Con_Printf ("ALSA: unable to install hw params: %s\n",
                                        snd_strerror (err));
                goto error;
        }
        err = snd_pcm_sw_params_current (pcm, sw);
        if (0 > err) {
-               Sys_Printf ("ALSA: unable to determine current sw params. %s\n",
+               Con_Printf ("ALSA: unable to determine current sw params. %s\n",
                                        snd_strerror (err));
                goto error;
        }
        err = snd_pcm_sw_params_set_start_threshold (pcm, sw, ~0U);
        if (0 > err) {
-               Sys_Printf ("ALSA: unable to set playback threshold. %s\n",
+               Con_Printf ("ALSA: unable to set playback threshold. %s\n",
                                        snd_strerror (err));
                goto error;
        }
        err = snd_pcm_sw_params_set_stop_threshold (pcm, sw, ~0U);
        if (0 > err) {
-               Sys_Printf ("ALSA: unable to set playback stop threshold. %s\n",
+               Con_Printf ("ALSA: unable to set playback stop threshold. %s\n",
                                        snd_strerror (err));
                goto error;
        }
        err = snd_pcm_sw_params (pcm, sw);
        if (0 > err) {
-               Sys_Printf ("ALSA: unable to install sw params. %s\n",
+               Con_Printf ("ALSA: unable to install sw params. %s\n",
                                        snd_strerror (err));
                goto error;
        }
@@ -246,7 +251,7 @@ qboolean SNDDMA_Init (void)
 
        err = snd_pcm_hw_params_get_buffer_size (hw, &buffer_size);
        if (0 > err) {
-               Sys_Printf ("ALSA: unable to get buffer size. %s\n",
+               Con_Printf ("ALSA: unable to get buffer size. %s\n",
                                        snd_strerror (err));
                goto error;
        }
@@ -277,7 +282,7 @@ int SNDDMA_GetDMAPos (void)
        offset *= shm->format.channels;
        nframes *= shm->format.channels;
        shm->samplepos = offset;
-       shm->buffer = areas->addr;
+       shm->buffer = (unsigned char *)areas->addr;
        return shm->samplepos;
 }
 
@@ -302,9 +307,6 @@ void SNDDMA_Submit (void)
        snd_pcm_uframes_t nframes;
        snd_pcm_uframes_t offset;
 
-       if (snd_blocked)
-               return;
-
        nframes = count / shm->format.channels;
 
        snd_pcm_avail_update (pcm);