]> code.delx.au - gnu-emacs/blobdiff - src/sound.c
[TARGET_API_MAC_CARBON] (mac_do_receive_drag): Don't
[gnu-emacs] / src / sound.c
index 6317b6c6279fc3cfcafd0bff305e9b89287daa57..7fb79e64048d20a4948ff28f273afebb078134c7 100644 (file)
@@ -1,6 +1,6 @@
 /* sound.c -- sound support.
    Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004,
-                 2005, 2006 Free Software Foundation, Inc.
+                 2005, 2006, 2007 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -74,8 +74,12 @@ Boston, MA 02110-1301, USA.  */
 #include <soundcard.h>
 #endif
 #ifdef HAVE_ALSA
+#ifdef ALSA_SUBDIR_INCLUDE
+#include <alsa/asoundlib.h>
+#else
 #include <asoundlib.h>
-#endif
+#endif /* ALSA_SUBDIR_INCLUDE */
+#endif /* HAVE_ALSA */
 
 /* END: Non Windows Includes */
 
@@ -113,7 +117,8 @@ enum sound_attr
   SOUND_ATTR_SENTINEL
 };
 
-static void sound_perror P_ ((char *));
+static void alsa_sound_perror P_ ((char *, int)) NO_RETURN;
+static void sound_perror P_ ((char *)) NO_RETURN;
 static void sound_warning P_ ((char *));
 static int parse_sound P_ ((Lisp_Object, Lisp_Object *));
 
@@ -971,7 +976,8 @@ alsa_open (sd)
   sd->data = p;
 
 
-  if ((err = snd_pcm_open (&p->handle, file, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
+  err = snd_pcm_open (&p->handle, file, SND_PCM_STREAM_PLAYBACK, 0);
+  if (err < 0)
     alsa_sound_perror (file, err);
 }
 
@@ -988,38 +994,46 @@ alsa_configure (sd)
      struct sound_device *sd;
 {
   int val, err, dir;
+  unsigned uval;
   struct alsa_params *p = (struct alsa_params *) sd->data;
   snd_pcm_uframes_t buffer_size;
 
   xassert (p->handle != 0);
 
-  if ((err = snd_pcm_hw_params_malloc (&p->hwparams)) < 0)
+  err = snd_pcm_hw_params_malloc (&p->hwparams);
+  if (err < 0)
     alsa_sound_perror ("Could not allocate hardware parameter structure", err);
 
-  if ((err = snd_pcm_sw_params_malloc (&p->swparams)) < 0)
+  err = snd_pcm_sw_params_malloc (&p->swparams);
+  if (err < 0)
     alsa_sound_perror ("Could not allocate software parameter structure", err);
 
-  if ((err = snd_pcm_hw_params_any (p->handle, p->hwparams)) < 0)
+  err = snd_pcm_hw_params_any (p->handle, p->hwparams);
+  if (err < 0)
     alsa_sound_perror ("Could not initialize hardware parameter structure", err);
 
-  if ((err = snd_pcm_hw_params_set_access (p->handle, p->hwparams,
-                                           SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
+  err = snd_pcm_hw_params_set_access (p->handle, p->hwparams,
+                                      SND_PCM_ACCESS_RW_INTERLEAVED);
+  if (err < 0)
     alsa_sound_perror ("Could not set access type", err);
 
   val = sd->format;
-  if ((err = snd_pcm_hw_params_set_format (p->handle, p->hwparams, val)) < 0) 
+  err = snd_pcm_hw_params_set_format (p->handle, p->hwparams, val);
+  if (err < 0)
     alsa_sound_perror ("Could not set sound format", err);
 
-  val = sd->sample_rate;
-  if ((err = snd_pcm_hw_params_set_rate_near (p->handle, p->hwparams, &val, 0))
-      < 0)
+  uval = sd->sample_rate;
+  err = snd_pcm_hw_params_set_rate_near (p->handle, p->hwparams, &uval, 0);
+  if (err < 0)
     alsa_sound_perror ("Could not set sample rate", err);
-  
+
   val = sd->channels;
-  if ((err = snd_pcm_hw_params_set_channels (p->handle, p->hwparams, val)) < 0)
+  err = snd_pcm_hw_params_set_channels (p->handle, p->hwparams, val);
+  if (err < 0)
     alsa_sound_perror ("Could not set channel count", err);
 
-  if ((err = snd_pcm_hw_params (p->handle, p->hwparams)) < 0)
+  err = snd_pcm_hw_params (p->handle, p->hwparams);
+  if (err < 0)
     alsa_sound_perror ("Could not set parameters", err);
 
 
@@ -1062,10 +1076,11 @@ alsa_configure (sd)
   p->hwparams = NULL;
   snd_pcm_sw_params_free (p->swparams);
   p->swparams = NULL;
-  
-  if ((err = snd_pcm_prepare (p->handle)) < 0)
+
+  err = snd_pcm_prepare (p->handle);
+  if (err < 0)
     alsa_sound_perror ("Could not prepare audio interface for use", err);
-  
+
   if (sd->volume > 0)
     {
       int chn;
@@ -1087,7 +1102,7 @@ alsa_configure (sd)
                     long pmin, pmax;
                     snd_mixer_selem_get_playback_volume_range (e, &pmin, &pmax);
                     long vol = pmin + (sd->volume * (pmax - pmin)) / 100;
-                    
+
                     for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++)
                       snd_mixer_selem_set_playback_volume (e, chn, vol);
                   }
@@ -1113,7 +1128,7 @@ alsa_close (sd)
         snd_pcm_sw_params_free (p->swparams);
       if (p->handle)
         {
-          snd_pcm_drain(p->handle);
+          snd_pcm_drain (p->handle);
           snd_pcm_close (p->handle);
         }
       free (p);
@@ -1194,11 +1209,11 @@ alsa_write (sd, buffer, nbytes)
 
   while (nwritten < nbytes)
     {
-      if ((err = snd_pcm_writei (p->handle,
-                                 buffer + nwritten,
-                                 (nbytes - nwritten)/fact)) < 0)
+      err = snd_pcm_writei (p->handle,
+                            buffer + nwritten,
+                            (nbytes - nwritten)/fact);
+      if (err < 0)
         {
-          fprintf(stderr, "Err %d/%s\n", err, snd_strerror(err));
           if (err == -EPIPE)
             {  /* under-run */
               err = snd_pcm_prepare (p->handle);
@@ -1219,9 +1234,9 @@ alsa_write (sd, buffer, nbytes)
                                        err);
                 }
             }
-          else 
+          else
             alsa_sound_perror ("Error writing to sound device", err);
-          
+
         }
       else
         nwritten += err * fact;
@@ -1259,7 +1274,8 @@ alsa_init (sd)
   err = snd_pcm_open (&handle, file, SND_PCM_STREAM_PLAYBACK, 0);
   snd_lib_error_set_handler (NULL);
   if (err < 0)
-    return 0;
+      return 0;
+  snd_pcm_close (handle);
 
   sd->fd = -1;
   sd->open = alsa_open;
@@ -1362,7 +1378,7 @@ do_play_sound (psz_file, ui_volume)
 DEFUN ("play-sound-internal", Fplay_sound_internal, Splay_sound_internal, 1, 1, 0,
        doc: /* Play sound SOUND.
 
-Internal use only, use `play-sound' instead.\n  */)
+Internal use only, use `play-sound' instead.  */)
      (sound)
      Lisp_Object sound;
 {