]> code.delx.au - gnu-emacs/blobdiff - src/sound.c
(Fbyte_code): Use BEFORE_POTENTIAL_GC and
[gnu-emacs] / src / sound.c
index 51ebc70218a53bd7027b571ee4c80cdf1f642482..2909e8f0f3fbee07dc1c2b0160a42e8166d0b597 100644 (file)
@@ -1,5 +1,5 @@
 /* sound.c -- sound support.
-   Copyright (C) 1998 Free Software Foundation.
+   Copyright (C) 1998, 1999 Free Software Foundation.
 
 This file is part of GNU Emacs.
 
@@ -198,7 +198,7 @@ enum sound_attr
 extern Lisp_Object QCfile;
 Lisp_Object QCvolume, QCdevice;
 Lisp_Object Qsound;
-Lisp_Object Qplay_sound_hook;
+Lisp_Object Qplay_sound_functions;
 
 /* These are set during `play-sound' so that sound_cleanup has
    access to them.  */
@@ -220,12 +220,15 @@ static void find_sound_file_type P_ ((struct sound_file *));
 static u_int32_t le2hl P_ ((u_int32_t));
 static u_int16_t le2hs P_ ((u_int16_t));
 static u_int32_t be2hl P_ ((u_int32_t));
-static u_int16_t be2hs P_ ((u_int16_t));
 static int wav_init P_ ((struct sound_file *));
 static void wav_play P_ ((struct sound_file *, struct sound_device *));
 static int au_init P_ ((struct sound_file *));
 static void au_play P_ ((struct sound_file *, struct sound_device *));
 
+#if 0 /* Currently not used.  */
+static u_int16_t be2hs P_ ((u_int16_t));
+#endif
+
 
 \f
 /***********************************************************************
@@ -260,7 +263,8 @@ sound_perror (msg)
 
    - `:volume VOL'
 
-   VOL must be an integer in the range 0..100.  */
+   VOL must be an integer in the range [0, 100], or a float in the
+   range [0, 1].  */
 
 static int
 parse_sound (sound, attrs)
@@ -283,10 +287,19 @@ parse_sound (sound, attrs)
   /* Volume must be in the range 0..100 or unspecified.  */
   if (!NILP (attrs[SOUND_VOLUME]))
     {
-      if (!INTEGERP (attrs[SOUND_VOLUME]))
-       return 0;
-      if (XINT (attrs[SOUND_VOLUME]) < 0
-         || XINT (attrs[SOUND_VOLUME]) > 100)
+      if (INTEGERP (attrs[SOUND_VOLUME]))
+       {
+         if (XINT (attrs[SOUND_VOLUME]) < 0
+             || XINT (attrs[SOUND_VOLUME]) > 100)
+           return 0;
+       }
+      else if (FLOATP (attrs[SOUND_VOLUME]))
+       {
+         if (XFLOAT_DATA (attrs[SOUND_VOLUME]) < 0
+             || XFLOAT_DATA (attrs[SOUND_VOLUME]) > 1)
+           return 0;
+       }
+      else
        return 0;
     }
 
@@ -322,7 +335,7 @@ sound_cleanup (arg)
     {
       sound_device->close (sound_device);
       if (sound_file->fd > 0)
-       close (sound_file->fd);
+       emacs_close (sound_file->fd);
     }
 }
 
@@ -333,11 +346,9 @@ DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 1, 0,
      Lisp_Object sound;
 {
   Lisp_Object attrs[SOUND_ATTR_SENTINEL];
-  char *header;
   Lisp_Object file;
   struct gcpro gcpro1, gcpro2;
   int nbytes;
-  char *msg;
   struct sound_device sd;
   struct sound_file sf;
   Lisp_Object args[2];
@@ -367,7 +378,7 @@ DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 1, 0,
     sound_perror ("Open sound file");
 
   /* Read the first bytes from the file.  */
-  nbytes = read (sf.fd, sf.header, MAX_SOUND_HEADER_BYTES);
+  nbytes = emacs_read (sf.fd, sf.header, MAX_SOUND_HEADER_BYTES);
   if (nbytes < 0)
     sound_perror ("Reading sound file header");
 
@@ -383,8 +394,10 @@ DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 1, 0,
     }
   if (INTEGERP (attrs[SOUND_VOLUME]))
     sd.volume = XFASTINT (attrs[SOUND_VOLUME]);
+  else if (FLOATP (attrs[SOUND_VOLUME]))
+    sd.volume = XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;
 
-  args[0] = Qplay_sound_hook;
+  args[0] = Qplay_sound_functions;
   args[1] = sound;
   Frun_hook_with_args (make_number (2), args);
 
@@ -392,7 +405,7 @@ DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 1, 0,
   sd.open (&sd);
 
   sf.play (&sf, &sd);
-  close (sf.fd);
+  emacs_close (sf.fd);
   sf.fd = -1;
   sd.close (&sd);
   sound_device = NULL;
@@ -452,6 +465,8 @@ be2hl (value)
 }
 
 
+#if 0 /* Currently not used.  */
+
 /* Convert 16-bit value VALUE which is in big-endian byte-order
    to host byte-order.  */
 
@@ -466,6 +481,7 @@ be2hs (value)
   return value;
 }
 
+#endif /* 0 */
 
 \f
 /***********************************************************************
@@ -541,7 +557,7 @@ wav_play (sf, sd)
   buffer = (char *) alloca (blksize);
   lseek (sf->fd, sizeof *header, SEEK_SET);
   
-  while ((nbytes = read (sf->fd, buffer, blksize)) > 0)
+  while ((nbytes = emacs_read (sf->fd, buffer, blksize)) > 0)
     sd->write (sd, buffer, nbytes);
 
   if (nbytes < 0)
@@ -623,7 +639,7 @@ au_play (sf, sd)
   
   /* Copy sound data to the device.  */
   buffer = (char *) alloca (blksize);
-  while ((nbytes = read (sf->fd, buffer, blksize)) > 0)
+  while ((nbytes = emacs_read (sf->fd, buffer, blksize)) > 0)
     sd->write (sd, buffer, nbytes);
 
   if (nbytes < 0)
@@ -655,7 +671,7 @@ vox_open (sd)
   else
     file = "/dev/dsp";
   
-  sd->fd = open (file, O_WRONLY);
+  sd->fd = emacs_open (file, O_WRONLY, 0);
   if (sd->fd < 0)
     sound_perror (file);
 }
@@ -715,7 +731,7 @@ vox_close (sd)
       ioctl (sd->fd, SNDCTL_DSP_RESET, NULL);
 
       /* Close the device.  */
-      close (sd->fd);
+      emacs_close (sd->fd);
       sd->fd = -1;
     }
 }
@@ -789,7 +805,7 @@ vox_write (sd, buffer, nbytes)
      char *buffer;
      int nbytes;
 {
-  int nwritten = write (sd->fd, buffer, nbytes);
+  int nwritten = emacs_write (sd->fd, buffer, nbytes);
   if (nwritten < 0)
     sound_perror ("Writing to sound device");
 }
@@ -809,8 +825,8 @@ syms_of_sound ()
   staticpro (&QCvolume);
   Qsound = intern ("sound");
   staticpro (&Qsound);
-  Qplay_sound_hook = intern ("play-sound-hook");
-  staticpro (&Qplay_sound_hook);
+  Qplay_sound_functions = intern ("play-sound-functions");
+  staticpro (&Qplay_sound_functions);
 
   defsubr (&Splay_sound);
 }