chiark / gitweb /
Mildly more vigorous uninstall rules
[disorder] / server / speaker-alsa.c
index fa9e6c3d17a9870bd4c256477686140f30635ba4..21a9a75889e0835a312475d030d26b58a06d1b6d 100644 (file)
 /** @file server/speaker-alsa.c
  * @brief Support for @ref BACKEND_ALSA */
 
-#include <config.h>
+#include "common.h"
 
-#if API_ALSA
-
-#include "types.h"
+#if HAVE_ALSA_ASOUNDLIB_H
 
 #include <unistd.h>
 #include <poll.h>
@@ -51,7 +49,6 @@ static void alsa_init(void) {
 static void log_params(snd_pcm_hw_params_t *hwparams,
                        snd_pcm_sw_params_t *swparams) {
   snd_pcm_uframes_t f;
-  unsigned u;
 
   return;                               /* too verbose */
   if(hwparams) {
@@ -62,14 +59,22 @@ static void log_params(snd_pcm_hw_params_t *hwparams,
     info("sw silence_size=%lu", (unsigned long)f);
     snd_pcm_sw_params_get_silence_threshold(swparams, &f);
     info("sw silence_threshold=%lu", (unsigned long)f);
-    snd_pcm_sw_params_get_sleep_min(swparams, &u);
-    info("sw sleep_min=%lu", (unsigned long)u);
+#if HAVE_SND_PCM_SW_PARAMS_GET_SLEEP_MIN
+    {
+      unsigned u;
+
+      snd_pcm_sw_params_get_sleep_min(swparams, &u);
+      info("sw sleep_min=%lu", (unsigned long)u);
+    }
+#endif
     snd_pcm_sw_params_get_start_threshold(swparams, &f);
     info("sw start_threshold=%lu", (unsigned long)f);
     snd_pcm_sw_params_get_stop_threshold(swparams, &f);
     info("sw stop_threshold=%lu", (unsigned long)f);
+#if HAVE_SND_PCM_SW_PARAMS_GET_XFER_ALIGN
     snd_pcm_sw_params_get_xfer_align(swparams, &f);
     info("sw xfer_align=%lu", (unsigned long)f);
+#endif
   }
 }
 
@@ -92,10 +97,6 @@ static void alsa_deactivate(void) {
 
 /** @brief ALSA backend activation */
 static void alsa_activate(void) {
-  /* If we need to change format then close the current device. */
-  if(pcm && !formats_equal(&playing->format, &device_format))
-    alsa_deactivate();
-  /* Now if the sound device is open it must have the right format */
   if(!pcm) {
     snd_pcm_hw_params_t *hwparams;
     snd_pcm_sw_params_t *swparams;
@@ -119,21 +120,21 @@ static void alsa_activate(void) {
     if((err = snd_pcm_hw_params_set_access(pcm, hwparams,
                                            SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
       fatal(0, "error from snd_pcm_hw_params_set_access: %d", err);
-    switch(playing->format.bits) {
+    switch(config->sample_format.bits) {
     case 8:
       sample_format = SND_PCM_FORMAT_S8;
       break;
     case 16:
-      switch(playing->format.byte_format) {
-      case AO_FMT_NATIVE: sample_format = SND_PCM_FORMAT_S16; break;
-      case AO_FMT_LITTLE: sample_format = SND_PCM_FORMAT_S16_LE; break;
-      case AO_FMT_BIG: sample_format = SND_PCM_FORMAT_S16_BE; break;
-        error(0, "unrecognized byte format %d", playing->format.byte_format);
+      switch(config->sample_format.endian) {
+      case ENDIAN_LITTLE: sample_format = SND_PCM_FORMAT_S16_LE; break;
+      case ENDIAN_BIG: sample_format = SND_PCM_FORMAT_S16_BE; break;
+      default:
+        error(0, "unrecognized byte format %d", config->sample_format.endian);
         goto fatal;
       }
       break;
     default:
-      error(0, "unsupported sample size %d", playing->format.bits);
+      error(0, "unsupported sample size %d", config->sample_format.bits);
       goto fatal;
     }
     if((err = snd_pcm_hw_params_set_format(pcm, hwparams,
@@ -142,18 +143,18 @@ static void alsa_activate(void) {
             sample_format, err);
       goto fatal;
     }
-    rate = playing->format.rate;
+    rate = config->sample_format.rate;
     if((err = snd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, 0)) < 0) {
       error(0, "error from snd_pcm_hw_params_set_rate (%d): %d",
-            playing->format.rate, err);
+            config->sample_format.rate, err);
       goto fatal;
     }
-    if(rate != (unsigned)playing->format.rate)
-      info("want rate %d, got %u", playing->format.rate, rate);
-    if((err = snd_pcm_hw_params_set_channels(pcm, hwparams,
-                                             playing->format.channels)) < 0) {
+    if(rate != (unsigned)config->sample_format.rate)
+      info("want rate %d, got %u", config->sample_format.rate, rate);
+    if((err = snd_pcm_hw_params_set_channels
+        (pcm, hwparams, config->sample_format.channels)) < 0) {
       error(0, "error from snd_pcm_hw_params_set_channels (%d): %d",
-            playing->format.channels, err);
+            config->sample_format.channels, err);
       goto fatal;
     }
     pcm_bufsize = 3 * FRAMES;
@@ -176,7 +177,6 @@ static void alsa_activate(void) {
             FRAMES, err);
     if((err = snd_pcm_sw_params(pcm, swparams)) < 0)
       fatal(0, "error calling snd_pcm_sw_params: %d", err);
-    device_format = playing->format;
     D(("acquired audio device"));
     log_params(hwparams, swparams);
     device_state = device_open;
@@ -224,7 +224,7 @@ static size_t alsa_play(size_t frames) {
 static int alsa_slots, alsa_nslots = -1;
 
 /** @brief Fill in poll fd array for ALSA */
-static void alsa_beforepoll(void) {
+static void alsa_beforepoll(int attribute((unused)) *timeoutp) {
   /* We send sample data to ALSA as fast as it can accept it, relying on
    * the fact that it has a relatively small buffer to minimize pause
    * latency. */