]> git.eshelyaron.com Git - emacs.git/commitdiff
* sound.c (wav_play): Check header->data_length to see how much we
authorJan Djärv <jan.h.d@swipnet.se>
Tue, 6 Mar 2007 12:15:33 +0000 (12:15 +0000)
committerJan Djärv <jan.h.d@swipnet.se>
Tue, 6 Mar 2007 12:15:33 +0000 (12:15 +0000)
shall read.
(alsa_period_size): Convert ALSA period size in frames to bytes.
(alsa_write): Return if frames is zero.

src/ChangeLog
src/sound.c

index d55e2a29b7869be30bf2da6234ce524695540d49..5451b1189e30399dcfcaa4420567e3e215461b02 100644 (file)
@@ -1,3 +1,10 @@
+2007-03-06  Jan Dj\e,Ad\e(Brv  <jan.h.d@swipnet.se>
+
+       * sound.c (wav_play): Check header->data_length to see how much we
+       shall read.
+       (alsa_period_size): Convert ALSA period size in frames to bytes.
+       (alsa_write): Return if frames is zero.
+
 2007-03-06  Kenichi Handa  <handa@m17n.org>
 
        * xselect.c (Vselection_coding_system): Documentation improved.
index 7fb79e64048d20a4948ff28f273afebb078134c7..5a27e7a6232a4fc8cc6878ec3a87a9e477b99aba 100644 (file)
@@ -621,12 +621,18 @@ wav_play (s, sd)
       char *buffer;
       int nbytes;
       int blksize = sd->period_size ? sd->period_size (sd) : 2048;
+      int data_left = header->data_length;
 
       buffer = (char *) alloca (blksize);
       lseek (s->fd, sizeof *header, SEEK_SET);
-
-      while ((nbytes = emacs_read (s->fd, buffer, blksize)) > 0)
-       sd->write (sd, buffer, nbytes);
+      while (data_left > 0
+             && (nbytes = emacs_read (s->fd, buffer, blksize)) > 0)
+        {
+          /* Don't play possible garbage at the end of file */
+          if (data_left < nbytes) nbytes = data_left;
+          data_left -= nbytes;
+          sd->write (sd, buffer, nbytes);
+        }
 
       if (nbytes < 0)
        sound_perror ("Error reading sound file");
@@ -986,7 +992,8 @@ alsa_period_size (sd)
        struct sound_device *sd;
 {
   struct alsa_params *p = (struct alsa_params *) sd->data;
-  return p->period_size;
+  int fact = snd_pcm_format_size (sd->format, 1) * sd->channels;
+  return p->period_size * (fact > 0 ? fact : 1);
 }
 
 static void
@@ -1209,9 +1216,10 @@ alsa_write (sd, buffer, nbytes)
 
   while (nwritten < nbytes)
     {
-      err = snd_pcm_writei (p->handle,
-                            buffer + nwritten,
-                            (nbytes - nwritten)/fact);
+      snd_pcm_uframes_t frames = (nbytes - nwritten)/fact;
+      if (frames == 0) break;
+      
+      err = snd_pcm_writei (p->handle, buffer + nwritten, frames);
       if (err < 0)
         {
           if (err == -EPIPE)