aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2013-06-19 00:36:20 -0700
committerPaul Eggert2013-06-19 00:36:20 -0700
commitbbc51b1565e360a9dfdae900a47de5db91af6957 (patch)
tree8ce4ed20d0c05b7f9037f9dca8eff1d91072ce55
parent2285bd27abf63a460d7025b2e5579f67cdd2e6fb (diff)
downloademacs-bbc51b1565e360a9dfdae900a47de5db91af6957.tar.gz
emacs-bbc51b1565e360a9dfdae900a47de5db91af6957.zip
* sound.c: Integer cleanups.
Remove unnecessary forward decls. (struct sound_device): The 'file' member is now a Lisp_Object, not a char *, so that we needn't invoke alloca on a huge size. (Fplay_sound_internal): Adjust to this. (string_default): New function. (vox_open, vox_init, alsa_open, alsa_configure, alsa_init): Use it to adjust to the struct sound_device change. (parse_sound, wav_init, au_init, alsa_init): Use bool for booleans. (be2hs) [0]: Remove.
-rw-r--r--src/ChangeLog11
-rw-r--r--src/sound.c98
2 files changed, 44 insertions, 65 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4d39cc70c23..ecc9ff99e82 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,16 @@
12013-06-19 Paul Eggert <eggert@cs.ucla.edu> 12013-06-19 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * sound.c: Integer cleanups.
4 Remove unnecessary forward decls.
5 (struct sound_device): The 'file' member is now a Lisp_Object, not
6 a char *, so that we needn't invoke alloca on a huge size.
7 (Fplay_sound_internal): Adjust to this.
8 (string_default): New function.
9 (vox_open, vox_init, alsa_open, alsa_configure, alsa_init):
10 Use it to adjust to the struct sound_device change.
11 (parse_sound, wav_init, au_init, alsa_init): Use bool for booleans.
12 (be2hs) [0]: Remove.
13
3 * syntax.c (skip_chars): Don't use uninitialized storage 14 * syntax.c (skip_chars): Don't use uninitialized storage
4 when searching a multibyte buffer for characters that are not in a 15 when searching a multibyte buffer for characters that are not in a
5 unibyte string that contains non-ASCII characters. 16 unibyte string that contains non-ASCII characters.
diff --git a/src/sound.c b/src/sound.c
index 9c472fb0263..e640dace40f 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -181,8 +181,8 @@ struct au_header
181 181
182struct sound_device 182struct sound_device
183{ 183{
184 /* The name of the device or null meaning use a default device name. */ 184 /* If a string, the name of the device; otherwise use a default. */
185 char *file; 185 Lisp_Object file;
186 186
187 /* File descriptor of the device. */ 187 /* File descriptor of the device. */
188 int fd; 188 int fd;
@@ -271,25 +271,12 @@ static struct sound *current_sound;
271 271
272/* Function prototypes. */ 272/* Function prototypes. */
273 273
274static void vox_open (struct sound_device *);
275static void vox_configure (struct sound_device *);
276static void vox_close (struct sound_device *sd);
277static void vox_choose_format (struct sound_device *, struct sound *);
278static int vox_init (struct sound_device *);
279static void vox_write (struct sound_device *, const char *, ptrdiff_t); 274static void vox_write (struct sound_device *, const char *, ptrdiff_t);
280static void find_sound_type (struct sound *); 275static bool wav_init (struct sound *);
281static u_int32_t le2hl (u_int32_t);
282static u_int16_t le2hs (u_int16_t);
283static u_int32_t be2hl (u_int32_t);
284static int wav_init (struct sound *);
285static void wav_play (struct sound *, struct sound_device *); 276static void wav_play (struct sound *, struct sound_device *);
286static int au_init (struct sound *); 277static bool au_init (struct sound *);
287static void au_play (struct sound *, struct sound_device *); 278static void au_play (struct sound *, struct sound_device *);
288 279
289#if 0 /* Currently not used. */
290static u_int16_t be2hs (u_int16_t);
291#endif
292
293/* END: Non Windows Definitions */ 280/* END: Non Windows Definitions */
294#else /* WINDOWSNT */ 281#else /* WINDOWSNT */
295 282
@@ -338,6 +325,15 @@ sound_warning (const char *msg)
338} 325}
339 326
340 327
328/* Return S's value as a string if S is a string, otherwise DEFAULT_VALUE. */
329
330static char const *
331string_default (Lisp_Object s, char const *default_value)
332{
333 return STRINGP (s) ? SSDATA (s) : default_value;
334}
335
336
341/* Parse sound specification SOUND, and fill ATTRS with what is 337/* Parse sound specification SOUND, and fill ATTRS with what is
342 found. Value is non-zero if SOUND Is a valid sound specification. 338 found. Value is non-zero if SOUND Is a valid sound specification.
343 A valid sound specification is a list starting with the symbol 339 A valid sound specification is a list starting with the symbol
@@ -364,7 +360,7 @@ sound_warning (const char *msg)
364 VOL must be an integer in the range [0, 100], or a float in the 360 VOL must be an integer in the range [0, 100], or a float in the
365 range [0, 1]. */ 361 range [0, 1]. */
366 362
367static int 363static bool
368parse_sound (Lisp_Object sound, Lisp_Object *attrs) 364parse_sound (Lisp_Object sound, Lisp_Object *attrs)
369{ 365{
370 /* SOUND must be a list starting with the symbol `sound'. */ 366 /* SOUND must be a list starting with the symbol `sound'. */
@@ -527,9 +523,9 @@ be2hs (u_int16_t value)
527 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the 523 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the
528 sound file. If the file is a WAV-format file, set up interface 524 sound file. If the file is a WAV-format file, set up interface
529 functions in S and convert header fields to host byte-order. 525 functions in S and convert header fields to host byte-order.
530 Value is non-zero if the file is a WAV file. */ 526 Value is true if the file is a WAV file. */
531 527
532static int 528static bool
533wav_init (struct sound *s) 529wav_init (struct sound *s)
534{ 530{
535 struct wav_header *header = (struct wav_header *) s->header; 531 struct wav_header *header = (struct wav_header *) s->header;
@@ -635,9 +631,9 @@ enum au_encoding
635 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the 631 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the
636 sound file. If the file is a AU-format file, set up interface 632 sound file. If the file is a AU-format file, set up interface
637 functions in S and convert header fields to host byte-order. 633 functions in S and convert header fields to host byte-order.
638 Value is non-zero if the file is an AU file. */ 634 Value is true if the file is an AU file. */
639 635
640static int 636static bool
641au_init (struct sound *s) 637au_init (struct sound *s)
642{ 638{
643 struct au_header *header = (struct au_header *) s->header; 639 struct au_header *header = (struct au_header *) s->header;
@@ -706,20 +702,14 @@ au_play (struct sound *s, struct sound_device *sd)
706 has a compatible own driver aka Luigi's driver. */ 702 has a compatible own driver aka Luigi's driver. */
707 703
708 704
709/* Open device SD. If SD->file is non-null, open that device, 705/* Open device SD. If SD->file is a string, open that device,
710 otherwise use a default device name. */ 706 otherwise use a default device name. */
711 707
712static void 708static void
713vox_open (struct sound_device *sd) 709vox_open (struct sound_device *sd)
714{ 710{
715 const char *file;
716
717 /* Open the sound device (eg /dev/dsp). */ 711 /* Open the sound device (eg /dev/dsp). */
718 if (sd->file) 712 char const *file = string_default (sd->file, DEFAULT_SOUND_DEVICE);
719 file = sd->file;
720 else
721 file = DEFAULT_SOUND_DEVICE;
722
723 sd->fd = emacs_open (file, O_WRONLY, 0); 713 sd->fd = emacs_open (file, O_WRONLY, 0);
724 if (sd->fd < 0) 714 if (sd->fd < 0)
725 sound_perror (file); 715 sound_perror (file);
@@ -862,18 +852,12 @@ vox_choose_format (struct sound_device *sd, struct sound *s)
862/* Initialize device SD. Set up the interface functions in the device 852/* Initialize device SD. Set up the interface functions in the device
863 structure. */ 853 structure. */
864 854
865static int 855static bool
866vox_init (struct sound_device *sd) 856vox_init (struct sound_device *sd)
867{ 857{
868 const char *file;
869 int fd;
870
871 /* Open the sound device (eg /dev/dsp). */ 858 /* Open the sound device (eg /dev/dsp). */
872 if (sd->file) 859 char const *file = string_default (sd->file, DEFAULT_SOUND_DEVICE);
873 file = sd->file; 860 int fd = emacs_open (file, O_WRONLY, 0);
874 else
875 file = DEFAULT_SOUND_DEVICE;
876 fd = emacs_open (file, O_WRONLY, 0);
877 if (fd >= 0) 861 if (fd >= 0)
878 emacs_close (fd); 862 emacs_close (fd);
879 else 863 else
@@ -924,23 +908,17 @@ struct alsa_params
924 snd_pcm_uframes_t period_size; 908 snd_pcm_uframes_t period_size;
925}; 909};
926 910
927/* Open device SD. If SD->file is non-null, open that device, 911/* Open device SD. If SD->file is a string, open that device,
928 otherwise use a default device name. */ 912 otherwise use a default device name. */
929 913
930static void 914static void
931alsa_open (struct sound_device *sd) 915alsa_open (struct sound_device *sd)
932{ 916{
933 const char *file;
934 struct alsa_params *p;
935 int err;
936
937 /* Open the sound device. Default is "default". */ 917 /* Open the sound device. Default is "default". */
938 if (sd->file) 918 struct alsa_params *p = xmalloc (sizeof *p);
939 file = sd->file; 919 char const *file = string_default (sd->file, DEFAULT_ALSA_SOUND_DEVICE);
940 else 920 int err;
941 file = DEFAULT_ALSA_SOUND_DEVICE;
942 921
943 p = xmalloc (sizeof *p);
944 p->handle = NULL; 922 p->handle = NULL;
945 p->hwparams = NULL; 923 p->hwparams = NULL;
946 p->swparams = NULL; 924 p->swparams = NULL;
@@ -1052,10 +1030,10 @@ alsa_configure (struct sound_device *sd)
1052 int chn; 1030 int chn;
1053 snd_mixer_t *handle; 1031 snd_mixer_t *handle;
1054 snd_mixer_elem_t *e; 1032 snd_mixer_elem_t *e;
1055 const char *file = sd->file ? sd->file : DEFAULT_ALSA_SOUND_DEVICE;
1056
1057 if (snd_mixer_open (&handle, 0) >= 0) 1033 if (snd_mixer_open (&handle, 0) >= 0)
1058 { 1034 {
1035 char const *file = string_default (sd->file,
1036 DEFAULT_ALSA_SOUND_DEVICE);
1059 if (snd_mixer_attach (handle, file) >= 0 1037 if (snd_mixer_attach (handle, file) >= 0
1060 && snd_mixer_load (handle) >= 0 1038 && snd_mixer_load (handle) >= 0
1061 && snd_mixer_selem_register (handle, NULL, NULL) >= 0) 1039 && snd_mixer_selem_register (handle, NULL, NULL) >= 0)
@@ -1212,19 +1190,14 @@ snd_error_quiet (const char *file, int line, const char *function, int err,
1212/* Initialize device SD. Set up the interface functions in the device 1190/* Initialize device SD. Set up the interface functions in the device
1213 structure. */ 1191 structure. */
1214 1192
1215static int 1193static bool
1216alsa_init (struct sound_device *sd) 1194alsa_init (struct sound_device *sd)
1217{ 1195{
1218 const char *file; 1196 /* Open the sound device. Default is "default". */
1197 char const *file = string_default (sd->file, DEFAULT_ALSA_SOUND_DEVICE);
1219 snd_pcm_t *handle; 1198 snd_pcm_t *handle;
1220 int err; 1199 int err;
1221 1200
1222 /* Open the sound device. Default is "default". */
1223 if (sd->file)
1224 file = sd->file;
1225 else
1226 file = DEFAULT_ALSA_SOUND_DEVICE;
1227
1228 snd_lib_error_set_handler ((snd_lib_error_handler_t) snd_error_quiet); 1201 snd_lib_error_set_handler ((snd_lib_error_handler_t) snd_error_quiet);
1229 err = snd_pcm_open (&handle, file, SND_PCM_STREAM_PLAYBACK, 0); 1202 err = snd_pcm_open (&handle, file, SND_PCM_STREAM_PLAYBACK, 0);
1230 snd_lib_error_set_handler (NULL); 1203 snd_lib_error_set_handler (NULL);
@@ -1404,12 +1377,7 @@ Internal use only, use `play-sound' instead. */)
1404 find_sound_type (current_sound); 1377 find_sound_type (current_sound);
1405 1378
1406 /* Set up a device. */ 1379 /* Set up a device. */
1407 if (STRINGP (attrs[SOUND_DEVICE])) 1380 current_sound_device->file = attrs[SOUND_DEVICE];
1408 {
1409 int len = SCHARS (attrs[SOUND_DEVICE]);
1410 current_sound_device->file = alloca (len + 1);
1411 strcpy (current_sound_device->file, SSDATA (attrs[SOUND_DEVICE]));
1412 }
1413 1381
1414 if (INTEGERP (attrs[SOUND_VOLUME])) 1382 if (INTEGERP (attrs[SOUND_VOLUME]))
1415 current_sound_device->volume = XFASTINT (attrs[SOUND_VOLUME]); 1383 current_sound_device->volume = XFASTINT (attrs[SOUND_VOLUME]);