diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 11 | ||||
| -rw-r--r-- | src/sound.c | 98 |
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 @@ | |||
| 1 | 2013-06-19 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2013-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 | ||
| 182 | struct sound_device | 182 | struct 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 | ||
| 274 | static void vox_open (struct sound_device *); | ||
| 275 | static void vox_configure (struct sound_device *); | ||
| 276 | static void vox_close (struct sound_device *sd); | ||
| 277 | static void vox_choose_format (struct sound_device *, struct sound *); | ||
| 278 | static int vox_init (struct sound_device *); | ||
| 279 | static void vox_write (struct sound_device *, const char *, ptrdiff_t); | 274 | static void vox_write (struct sound_device *, const char *, ptrdiff_t); |
| 280 | static void find_sound_type (struct sound *); | 275 | static bool wav_init (struct sound *); |
| 281 | static u_int32_t le2hl (u_int32_t); | ||
| 282 | static u_int16_t le2hs (u_int16_t); | ||
| 283 | static u_int32_t be2hl (u_int32_t); | ||
| 284 | static int wav_init (struct sound *); | ||
| 285 | static void wav_play (struct sound *, struct sound_device *); | 276 | static void wav_play (struct sound *, struct sound_device *); |
| 286 | static int au_init (struct sound *); | 277 | static bool au_init (struct sound *); |
| 287 | static void au_play (struct sound *, struct sound_device *); | 278 | static void au_play (struct sound *, struct sound_device *); |
| 288 | 279 | ||
| 289 | #if 0 /* Currently not used. */ | ||
| 290 | static 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 | |||
| 330 | static char const * | ||
| 331 | string_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 | ||
| 367 | static int | 363 | static bool |
| 368 | parse_sound (Lisp_Object sound, Lisp_Object *attrs) | 364 | parse_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 | ||
| 532 | static int | 528 | static bool |
| 533 | wav_init (struct sound *s) | 529 | wav_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 | ||
| 640 | static int | 636 | static bool |
| 641 | au_init (struct sound *s) | 637 | au_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 | ||
| 712 | static void | 708 | static void |
| 713 | vox_open (struct sound_device *sd) | 709 | vox_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 | ||
| 865 | static int | 855 | static bool |
| 866 | vox_init (struct sound_device *sd) | 856 | vox_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 | ||
| 930 | static void | 914 | static void |
| 931 | alsa_open (struct sound_device *sd) | 915 | alsa_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 | ||
| 1215 | static int | 1193 | static bool |
| 1216 | alsa_init (struct sound_device *sd) | 1194 | alsa_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]); |