diff options
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/sound.c | 22 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index d55e2a29b78..5451b1189e3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2007-03-06 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | * sound.c (wav_play): Check header->data_length to see how much we | ||
| 4 | shall read. | ||
| 5 | (alsa_period_size): Convert ALSA period size in frames to bytes. | ||
| 6 | (alsa_write): Return if frames is zero. | ||
| 7 | |||
| 1 | 2007-03-06 Kenichi Handa <handa@m17n.org> | 8 | 2007-03-06 Kenichi Handa <handa@m17n.org> |
| 2 | 9 | ||
| 3 | * xselect.c (Vselection_coding_system): Documentation improved. | 10 | * xselect.c (Vselection_coding_system): Documentation improved. |
diff --git a/src/sound.c b/src/sound.c index 7fb79e64048..5a27e7a6232 100644 --- a/src/sound.c +++ b/src/sound.c | |||
| @@ -621,12 +621,18 @@ wav_play (s, sd) | |||
| 621 | char *buffer; | 621 | char *buffer; |
| 622 | int nbytes; | 622 | int nbytes; |
| 623 | int blksize = sd->period_size ? sd->period_size (sd) : 2048; | 623 | int blksize = sd->period_size ? sd->period_size (sd) : 2048; |
| 624 | int data_left = header->data_length; | ||
| 624 | 625 | ||
| 625 | buffer = (char *) alloca (blksize); | 626 | buffer = (char *) alloca (blksize); |
| 626 | lseek (s->fd, sizeof *header, SEEK_SET); | 627 | lseek (s->fd, sizeof *header, SEEK_SET); |
| 627 | 628 | while (data_left > 0 | |
| 628 | while ((nbytes = emacs_read (s->fd, buffer, blksize)) > 0) | 629 | && (nbytes = emacs_read (s->fd, buffer, blksize)) > 0) |
| 629 | sd->write (sd, buffer, nbytes); | 630 | { |
| 631 | /* Don't play possible garbage at the end of file */ | ||
| 632 | if (data_left < nbytes) nbytes = data_left; | ||
| 633 | data_left -= nbytes; | ||
| 634 | sd->write (sd, buffer, nbytes); | ||
| 635 | } | ||
| 630 | 636 | ||
| 631 | if (nbytes < 0) | 637 | if (nbytes < 0) |
| 632 | sound_perror ("Error reading sound file"); | 638 | sound_perror ("Error reading sound file"); |
| @@ -986,7 +992,8 @@ alsa_period_size (sd) | |||
| 986 | struct sound_device *sd; | 992 | struct sound_device *sd; |
| 987 | { | 993 | { |
| 988 | struct alsa_params *p = (struct alsa_params *) sd->data; | 994 | struct alsa_params *p = (struct alsa_params *) sd->data; |
| 989 | return p->period_size; | 995 | int fact = snd_pcm_format_size (sd->format, 1) * sd->channels; |
| 996 | return p->period_size * (fact > 0 ? fact : 1); | ||
| 990 | } | 997 | } |
| 991 | 998 | ||
| 992 | static void | 999 | static void |
| @@ -1209,9 +1216,10 @@ alsa_write (sd, buffer, nbytes) | |||
| 1209 | 1216 | ||
| 1210 | while (nwritten < nbytes) | 1217 | while (nwritten < nbytes) |
| 1211 | { | 1218 | { |
| 1212 | err = snd_pcm_writei (p->handle, | 1219 | snd_pcm_uframes_t frames = (nbytes - nwritten)/fact; |
| 1213 | buffer + nwritten, | 1220 | if (frames == 0) break; |
| 1214 | (nbytes - nwritten)/fact); | 1221 | |
| 1222 | err = snd_pcm_writei (p->handle, buffer + nwritten, frames); | ||
| 1215 | if (err < 0) | 1223 | if (err < 0) |
| 1216 | { | 1224 | { |
| 1217 | if (err == -EPIPE) | 1225 | if (err == -EPIPE) |