]> code.delx.au - gnu-emacs/blobdiff - src/sound.c
Merge from emacs-23; up to 2010-06-09T17:54:28Z!albinus@detlef.
[gnu-emacs] / src / sound.c
index 6fa6f54891714469346d9d06c51e1e61f495c62a..794c8e64e54fdf80cad36e052af1070fc003a9a5 100644 (file)
@@ -1,6 +1,5 @@
 /* sound.c -- sound support.
-   Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1998-1999, 2001-2011 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -56,9 +55,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 /* BEGIN: Non Windows Includes */
 #ifndef WINDOWSNT
 
-#ifndef MSDOS
 #include <sys/ioctl.h>
-#endif
 
 /* FreeBSD has machine/soundcard.h.  Voxware sound driver docs mention
    sys/soundcard.h.  So, let's try whatever's there.  */
@@ -86,8 +83,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* BEGIN: Windows Specific Includes */
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <limits.h>
 #include <windows.h>
 #include <mmsystem.h>
@@ -99,10 +94,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Symbols.  */
 
-extern Lisp_Object QCfile, QCdata;
-Lisp_Object QCvolume, QCdevice;
-Lisp_Object Qsound;
-Lisp_Object Qplay_sound_functions;
+static Lisp_Object QCvolume, QCdevice;
+static Lisp_Object Qsound;
+static Lisp_Object Qplay_sound_functions;
 
 /* Indices of attributes in a sound attributes vector.  */
 
@@ -115,9 +109,11 @@ enum sound_attr
   SOUND_ATTR_SENTINEL
 };
 
-static void alsa_sound_perror (char *, int) NO_RETURN;
-static void sound_perror (char *) NO_RETURN;
-static void sound_warning (char *);
+#ifdef HAVE_ALSA
+static void alsa_sound_perror (const char *, int) NO_RETURN;
+#endif
+static void sound_perror (const char *) NO_RETURN;
+static void sound_warning (const char *);
 static int parse_sound (Lisp_Object, Lisp_Object *);
 
 /* END: Common Definitions */
@@ -239,11 +235,11 @@ struct sound_device
 
   /* Return a preferred data size in bytes to be sent to write (below)
      each time.  2048 is used if this is NULL.  */
-  int (* period_size) (struct sound_device *sd);
+  EMACS_INT (* period_size) (struct sound_device *sd);
 
   /* Write NYBTES bytes from BUFFER to device SD.  */
   void (* write) (struct sound_device *sd, const char *buffer,
-                  int nbytes);
+                  EMACS_INT nbytes);
 
   /* A place for devices to store additional data.  */
   void *data;
@@ -285,8 +281,8 @@ struct sound
 /* These are set during `play-sound-internal' so that sound_cleanup has
    access to them.  */
 
-struct sound_device *current_sound_device;
-struct sound *current_sound;
+static struct sound_device *current_sound_device;
+static struct sound *current_sound;
 
 /* Function prototypes.  */
 
@@ -295,7 +291,7 @@ static void vox_configure (struct sound_device *);
 static void vox_close (struct sound_device *sd);
 static void vox_choose_format (struct sound_device *, struct sound *);
 static int vox_init (struct sound_device *);
-static void vox_write (struct sound_device *, const char *, int);
+static void vox_write (struct sound_device *, const char *, EMACS_INT);
 static void find_sound_type (struct sound *);
 static u_int32_t le2hl (u_int32_t);
 static u_int16_t le2hs (u_int16_t);
@@ -328,7 +324,7 @@ static int do_play_sound (const char *, unsigned long);
 /* Like perror, but signals an error.  */
 
 static void
-sound_perror (char *msg)
+sound_perror (const char *msg)
 {
   int saved_errno = errno;
 
@@ -346,9 +342,9 @@ sound_perror (char *msg)
 /* Display a warning message.  */
 
 static void
-sound_warning (char *msg)
+sound_warning (const char *msg)
 {
-  message (msg);
+  message ("%s", msg);
 }
 
 
@@ -464,8 +460,8 @@ sound_cleanup (Lisp_Object arg)
     current_sound_device->close (current_sound_device);
   if (current_sound->fd > 0)
     emacs_close (current_sound->fd);
-  free (current_sound_device);
-  free (current_sound);
+  xfree (current_sound_device);
+  xfree (current_sound);
 
   return Qnil;
 }
@@ -480,7 +476,7 @@ sound_cleanup (Lisp_Object arg)
 static u_int32_t
 le2hl (u_int32_t value)
 {
-#ifdef WORDS_BIG_ENDIAN
+#ifdef WORDS_BIGENDIAN
   unsigned char *p = (unsigned char *) &value;
   value = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
 #endif
@@ -494,7 +490,7 @@ le2hl (u_int32_t value)
 static u_int16_t
 le2hs (u_int16_t value)
 {
-#ifdef WORDS_BIG_ENDIAN
+#ifdef WORDS_BIGENDIAN
   unsigned char *p = (unsigned char *) &value;
   value = p[0] + (p[1] << 8);
 #endif
@@ -508,7 +504,7 @@ le2hs (u_int16_t value)
 static u_int32_t
 be2hl (u_int32_t value)
 {
-#ifndef WORDS_BIG_ENDIAN
+#ifndef WORDS_BIGENDIAN
   unsigned char *p = (unsigned char *) &value;
   value = p[3] + (p[2] << 8) + (p[1] << 16) + (p[0] << 24);
 #endif
@@ -522,10 +518,9 @@ be2hl (u_int32_t value)
    to host byte-order.  */
 
 static u_int16_t
-be2hs (value)
-     u_int16_t value;
+be2hs (u_int16_t value)
 {
-#ifndef WORDS_BIG_ENDIAN
+#ifndef WORDS_BIGENDIAN
   unsigned char *p = (unsigned char *) &value;
   value = p[1] + (p[0] << 8);
 #endif
@@ -550,7 +545,7 @@ wav_init (struct sound *s)
   struct wav_header *header = (struct wav_header *) s->header;
 
   if (s->header_size < sizeof *header
-      || bcmp (s->header, "RIFF", 4) != 0)
+      || memcmp (s->header, "RIFF", 4) != 0)
     return 0;
 
   /* WAV files are in little-endian order.  Convert the header
@@ -600,14 +595,14 @@ wav_play (struct sound *s, struct sound_device *sd)
      files I found so far.  If someone feels inclined to implement the
      whole RIFF-WAVE spec, please do.  */
   if (STRINGP (s->data))
-    sd->write (sd, SDATA (s->data) + sizeof *header,
+    sd->write (sd, SSDATA (s->data) + sizeof *header,
               SBYTES (s->data) - sizeof *header);
   else
     {
       char *buffer;
-      int nbytes;
-      int blksize = sd->period_size ? sd->period_size (sd) : 2048;
-      int data_left = header->data_length;
+      EMACS_INT nbytes = 0;
+      EMACS_INT blksize = sd->period_size ? sd->period_size (sd) : 2048;
+      EMACS_INT data_left = header->data_length;
 
       buffer = (char *) alloca (blksize);
       lseek (s->fd, sizeof *header, SEEK_SET);
@@ -658,7 +653,7 @@ au_init (struct sound *s)
   struct au_header *header = (struct au_header *) s->header;
 
   if (s->header_size < sizeof *header
-      || bcmp (s->header, ".snd", 4) != 0)
+      || memcmp (s->header, ".snd", 4) != 0)
     return 0;
 
   header->magic_number = be2hl (header->magic_number);
@@ -691,13 +686,13 @@ au_play (struct sound *s, struct sound_device *sd)
   sd->configure (sd);
 
   if (STRINGP (s->data))
-    sd->write (sd, SDATA (s->data) + header->data_offset,
+    sd->write (sd, SSDATA (s->data) + header->data_offset,
               SBYTES (s->data) - header->data_offset);
   else
     {
-      int blksize = sd->period_size ? sd->period_size (sd) : 2048;
+      EMACS_INT blksize = sd->period_size ? sd->period_size (sd) : 2048;
       char *buffer;
-      int nbytes;
+      EMACS_INT nbytes;
 
       /* Seek */
       lseek (s->fd, header->data_offset, SEEK_SET);
@@ -727,7 +722,7 @@ au_play (struct sound *s, struct sound_device *sd)
 static void
 vox_open (struct sound_device *sd)
 {
-  char *file;
+  const char *file;
 
   /* Open the sound device.  Default is /dev/dsp.  */
   if (sd->file)
@@ -872,7 +867,7 @@ vox_choose_format (struct sound_device *sd, struct sound *s)
 static int
 vox_init (struct sound_device *sd)
 {
-  char *file;
+  const char *file;
   int fd;
 
   /* Open the sound device.  Default is /dev/dsp.  */
@@ -900,10 +895,9 @@ vox_init (struct sound_device *sd)
 /* Write NBYTES bytes from BUFFER to device SD.  */
 
 static void
-vox_write (struct sound_device *sd, const char *buffer, int nbytes)
+vox_write (struct sound_device *sd, const char *buffer, EMACS_INT nbytes)
 {
-  int nwritten = emacs_write (sd->fd, buffer, nbytes);
-  if (nwritten < 0)
+  if (emacs_write (sd->fd, buffer, nbytes) != nbytes)
     sound_perror ("Error writing to sound device");
 }
 
@@ -915,7 +909,7 @@ vox_write (struct sound_device *sd, const char *buffer, int nbytes)
 /* This driver is available on GNU/Linux. */
 
 static void
-alsa_sound_perror (char *msg, int err)
+alsa_sound_perror (const char *msg, int err)
 {
   error ("%s: %s", msg, snd_strerror (err));
 }
@@ -934,7 +928,7 @@ struct alsa_params
 static void
 alsa_open (struct sound_device *sd)
 {
-  char *file;
+  const char *file;
   struct alsa_params *p;
   int err;
 
@@ -958,7 +952,7 @@ alsa_open (struct sound_device *sd)
     alsa_sound_perror (file, err);
 }
 
-static int
+static EMACS_INT
 alsa_period_size (struct sound_device *sd)
 {
   struct alsa_params *p = (struct alsa_params *) sd->data;
@@ -1056,7 +1050,7 @@ alsa_configure (struct sound_device *sd)
       int chn;
       snd_mixer_t *handle;
       snd_mixer_elem_t *e;
-      char *file = sd->file ? sd->file : DEFAULT_ALSA_SOUND_DEVICE;
+      const char *file = sd->file ? sd->file : DEFAULT_ALSA_SOUND_DEVICE;
 
       if (snd_mixer_open (&handle, 0) >= 0)
         {
@@ -1100,7 +1094,7 @@ alsa_close (struct sound_device *sd)
           snd_pcm_drain (p->handle);
           snd_pcm_close (p->handle);
         }
-      free (p);
+      xfree (p);
     }
 }
 
@@ -1109,7 +1103,6 @@ alsa_close (struct sound_device *sd)
 static void
 alsa_choose_format (struct sound_device *sd, struct sound *s)
 {
-  struct alsa_params *p = (struct alsa_params *) sd->data;
   if (s->type == RIFF)
     {
       struct wav_header *h = (struct wav_header *) s->header;
@@ -1162,13 +1155,13 @@ alsa_choose_format (struct sound_device *sd, struct sound *s)
 /* Write NBYTES bytes from BUFFER to device SD.  */
 
 static void
-alsa_write (struct sound_device *sd, const char *buffer, int nbytes)
+alsa_write (struct sound_device *sd, const char *buffer, EMACS_INT nbytes)
 {
   struct alsa_params *p = (struct alsa_params *) sd->data;
 
   /* The the third parameter to snd_pcm_writei is frames, not bytes. */
   int fact = snd_pcm_format_size (sd->format, 1) * sd->channels;
-  int nwritten = 0;
+  EMACS_INT nwritten = 0;
   int err;
 
   while (nwritten < nbytes)
@@ -1209,7 +1202,8 @@ alsa_write (struct sound_device *sd, const char *buffer, int nbytes)
 }
 
 static void
-snd_error_quiet (const char *file, int line, const char *function, int err, const char *fmt)
+snd_error_quiet (const char *file, int line, const char *function, int err,
+                const char *fmt)
 {
 }
 
@@ -1219,7 +1213,7 @@ snd_error_quiet (const char *file, int line, const char *function, int err, cons
 static int
 alsa_init (struct sound_device *sd)
 {
-  char *file;
+  const char *file;
   snd_pcm_t *handle;
   int err;
 
@@ -1266,9 +1260,7 @@ alsa_init (struct sound_device *sd)
   }
 
 static int
-do_play_sound (psz_file, ui_volume)
-     const char *psz_file;
-     unsigned long ui_volume;
+do_play_sound (const char *psz_file, unsigned long ui_volume)
 {
   int i_result = 0;
   MCIERROR mci_error = 0;
@@ -1353,8 +1345,7 @@ DEFUN ("play-sound-internal", Fplay_sound_internal, Splay_sound_internal, 1, 1,
        doc: /* Play sound SOUND.
 
 Internal use only, use `play-sound' instead.  */)
-     (sound)
-     Lisp_Object sound;
+  (Lisp_Object sound)
 {
   Lisp_Object attrs[SOUND_ATTR_SENTINEL];
   int count = SPECPDL_INDEX ();
@@ -1380,9 +1371,9 @@ Internal use only, use `play-sound' instead.  */)
   file = Qnil;
   GCPRO2 (sound, file);
   current_sound_device = (struct sound_device *) xmalloc (sizeof (struct sound_device));
-  bzero (current_sound_device, sizeof (struct sound_device));
+  memset (current_sound_device, 0, sizeof (struct sound_device));
   current_sound = (struct sound *) xmalloc (sizeof (struct sound));
-  bzero (current_sound, sizeof (struct sound));
+  memset (current_sound, 0, sizeof (struct sound));
   record_unwind_protect (sound_cleanup, Qnil);
   current_sound->header = (char *) alloca (MAX_SOUND_HEADER_BYTES);
 
@@ -1405,7 +1396,8 @@ Internal use only, use `play-sound' instead.  */)
     {
       current_sound->data = attrs[SOUND_DATA];
       current_sound->header_size = min (MAX_SOUND_HEADER_BYTES, SBYTES (current_sound->data));
-      bcopy (SDATA (current_sound->data), current_sound->header, current_sound->header_size);
+      memcpy (current_sound->header, SDATA (current_sound->data),
+             current_sound->header_size);
     }
 
   /* Find out the type of sound.  Give up if we can't tell.  */
@@ -1416,7 +1408,7 @@ Internal use only, use `play-sound' instead.  */)
     {
       int len = SCHARS (attrs[SOUND_DEVICE]);
       current_sound_device->file = (char *) alloca (len + 1);
-      strcpy (current_sound_device->file, SDATA (attrs[SOUND_DEVICE]));
+      strcpy (current_sound_device->file, SSDATA (attrs[SOUND_DEVICE]));
     }
 
   if (INTEGERP (attrs[SOUND_VOLUME]))
@@ -1504,6 +1496,3 @@ init_sound (void)
 }
 
 #endif /* HAVE_SOUND */
-
-/* arch-tag: dd850ad8-0433-4e2c-9cba-b7aeeccc0dbd
-   (do not change this comment) */