Merge from trunk.
[bpt/emacs.git] / src / sound.c
index c0741f2..9e15caa 100644 (file)
@@ -94,9 +94,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Symbols.  */
 
-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.  */
 
@@ -226,7 +226,7 @@ struct sound_device
   /* Close device SD.  */
   void (* close) (struct sound_device *sd);
 
-  /* Configure SD accoring to device-dependent parameters.  */
+  /* Configure SD according to device-dependent parameters.  */
   void (* configure) (struct sound_device *device);
 
   /* Choose a device-dependent format for outputting sound S.  */
@@ -235,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.  */
-  size_t (* period_size) (struct sound_device *sd);
+  ptrdiff_t (* period_size) (struct sound_device *sd);
 
   /* Write NYBTES bytes from BUFFER to device SD.  */
   void (* write) (struct sound_device *sd, const char *buffer,
-                  size_t nbytes);
+                  ptrdiff_t nbytes);
 
   /* A place for devices to store additional data.  */
   void *data;
@@ -281,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.  */
 
@@ -291,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 *, size_t);
+static void vox_write (struct sound_device *, const char *, ptrdiff_t);
 static void find_sound_type (struct sound *);
 static u_int32_t le2hl (u_int32_t);
 static u_int16_t le2hs (u_int16_t);
@@ -600,9 +600,9 @@ wav_play (struct sound *s, struct sound_device *sd)
   else
     {
       char *buffer;
-      ssize_t nbytes = 0;
-      size_t blksize = sd->period_size ? sd->period_size (sd) : 2048;
-      size_t data_left = header->data_length;
+      ptrdiff_t nbytes = 0;
+      ptrdiff_t blksize = sd->period_size ? sd->period_size (sd) : 2048;
+      ptrdiff_t data_left = header->data_length;
 
       buffer = (char *) alloca (blksize);
       lseek (s->fd, sizeof *header, SEEK_SET);
@@ -690,9 +690,9 @@ au_play (struct sound *s, struct sound_device *sd)
               SBYTES (s->data) - header->data_offset);
   else
     {
-      size_t blksize = sd->period_size ? sd->period_size (sd) : 2048;
+      ptrdiff_t blksize = sd->period_size ? sd->period_size (sd) : 2048;
       char *buffer;
-      ssize_t nbytes;
+      ptrdiff_t nbytes;
 
       /* Seek */
       lseek (s->fd, header->data_offset, SEEK_SET);
@@ -895,7 +895,7 @@ 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, size_t nbytes)
+vox_write (struct sound_device *sd, const char *buffer, ptrdiff_t nbytes)
 {
   if (emacs_write (sd->fd, buffer, nbytes) != nbytes)
     sound_perror ("Error writing to sound device");
@@ -952,7 +952,7 @@ alsa_open (struct sound_device *sd)
     alsa_sound_perror (file, err);
 }
 
-static size_t
+static ptrdiff_t
 alsa_period_size (struct sound_device *sd)
 {
   struct alsa_params *p = (struct alsa_params *) sd->data;
@@ -1013,7 +1013,7 @@ alsa_configure (struct sound_device *sd)
 
   err = snd_pcm_hw_params_get_buffer_size (p->hwparams, &buffer_size);
   if (err < 0)
-    alsa_sound_perror("Unable to get buffer size for playback", err);
+    alsa_sound_perror ("Unable to get buffer size for playback", err);
 
   err = snd_pcm_sw_params_current (p->handle, p->swparams);
   if (err < 0)
@@ -1071,7 +1071,7 @@ alsa_configure (struct sound_device *sd)
                       snd_mixer_selem_set_playback_volume (e, chn, vol);
                   }
               }
-          snd_mixer_close(handle);
+          snd_mixer_close (handle);
         }
     }
 }
@@ -1155,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, size_t nbytes)
+alsa_write (struct sound_device *sd, const char *buffer, ptrdiff_t 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;
-  size_t nwritten = 0;
+  ptrdiff_t nwritten = 0;
   int err;
 
   while (nwritten < nbytes)
@@ -1182,7 +1182,7 @@ alsa_write (struct sound_device *sd, const char *buffer, size_t nbytes)
           else if (err == -ESTRPIPE)
             {
               while ((err = snd_pcm_resume (p->handle)) == -EAGAIN)
-                sleep(1);      /* wait until the suspend flag is released */
+                sleep (1);     /* wait until the suspend flag is released */
               if (err < 0)
                 {
                   err = snd_pcm_prepare (p->handle);
@@ -1348,7 +1348,7 @@ Internal use only, use `play-sound' instead.  */)
   (Lisp_Object sound)
 {
   Lisp_Object attrs[SOUND_ATTR_SENTINEL];
-  int count = SPECPDL_INDEX ();
+  ptrdiff_t count = SPECPDL_INDEX ();
 
 #ifndef WINDOWSNT
   Lisp_Object file;
@@ -1447,7 +1447,7 @@ Internal use only, use `play-sound' instead.  */)
     }
   else if (FLOATP (attrs[SOUND_VOLUME]))
     {
-      ui_volume_tmp = (unsigned long) XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;
+      ui_volume_tmp = XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;
     }
   /*
     Based on some experiments I have conducted, a value of 100 or less
@@ -1477,14 +1477,10 @@ Internal use only, use `play-sound' instead.  */)
 void
 syms_of_sound (void)
 {
-  QCdevice = intern_c_string(":device");
-  staticpro (&QCdevice);
-  QCvolume = intern_c_string (":volume");
-  staticpro (&QCvolume);
-  Qsound = intern_c_string ("sound");
-  staticpro (&Qsound);
-  Qplay_sound_functions = intern_c_string ("play-sound-functions");
-  staticpro (&Qplay_sound_functions);
+  DEFSYM (QCdevice, ":device");
+  DEFSYM (QCvolume, ":volume");
+  DEFSYM (Qsound, "sound");
+  DEFSYM (Qplay_sound_functions, "play-sound-functions");
 
   defsubr (&Splay_sound_internal);
 }