diff options
| author | Richard M. Stallman | 2006-05-03 23:26:40 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2006-05-03 23:26:40 +0000 |
| commit | 8e6ec322ba352f54735042a8d5ba2e738dfc78fb (patch) | |
| tree | b6b3074fec899f914a78d4d47f7467aac46522a9 /src | |
| parent | 58af1784740cec880872818b074b9aaf3d09704d (diff) | |
| download | emacs-8e6ec322ba352f54735042a8d5ba2e738dfc78fb.tar.gz emacs-8e6ec322ba352f54735042a8d5ba2e738dfc78fb.zip | |
(Fplay_sound_internal): Dynamically allocate
current_sound_device and current_sound.
(sound_cleanup): Free them.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sound.c | 71 |
1 files changed, 29 insertions, 42 deletions
diff --git a/src/sound.c b/src/sound.c index c1d5c40e9bb..0fbeceb4b9e 100644 --- a/src/sound.c +++ b/src/sound.c | |||
| @@ -452,13 +452,12 @@ static Lisp_Object | |||
| 452 | sound_cleanup (arg) | 452 | sound_cleanup (arg) |
| 453 | Lisp_Object arg; | 453 | Lisp_Object arg; |
| 454 | { | 454 | { |
| 455 | if (current_sound_device) | 455 | if (current_sound_device->close) |
| 456 | { | 456 | current_sound_device->close (current_sound_device); |
| 457 | if (current_sound_device->close) | 457 | if (current_sound->fd > 0) |
| 458 | current_sound_device->close (current_sound_device); | 458 | emacs_close (current_sound->fd); |
| 459 | if (current_sound->fd > 0) | 459 | free (current_sound_device); |
| 460 | emacs_close (current_sound->fd); | 460 | free (current_sound); |
| 461 | } | ||
| 462 | 461 | ||
| 463 | return Qnil; | 462 | return Qnil; |
| 464 | } | 463 | } |
| @@ -991,8 +990,6 @@ Internal use only, use `play-sound' instead.\n */) | |||
| 991 | #ifndef WINDOWSNT | 990 | #ifndef WINDOWSNT |
| 992 | Lisp_Object file; | 991 | Lisp_Object file; |
| 993 | struct gcpro gcpro1, gcpro2; | 992 | struct gcpro gcpro1, gcpro2; |
| 994 | struct sound_device sd; | ||
| 995 | struct sound s; | ||
| 996 | Lisp_Object args[2]; | 993 | Lisp_Object args[2]; |
| 997 | #else /* WINDOWSNT */ | 994 | #else /* WINDOWSNT */ |
| 998 | int len = 0; | 995 | int len = 0; |
| @@ -1010,48 +1007,50 @@ Internal use only, use `play-sound' instead.\n */) | |||
| 1010 | #ifndef WINDOWSNT | 1007 | #ifndef WINDOWSNT |
| 1011 | file = Qnil; | 1008 | file = Qnil; |
| 1012 | GCPRO2 (sound, file); | 1009 | GCPRO2 (sound, file); |
| 1013 | bzero (&sd, sizeof sd); | 1010 | current_sound_device = (struct sound_device *) xmalloc (sizeof (struct sound_device)); |
| 1014 | bzero (&s, sizeof s); | 1011 | bzero (current_sound_device, sizeof (struct sound_device)); |
| 1015 | current_sound_device = &sd; | 1012 | current_sound = (struct sound *) xmalloc (sizeof (struct sound)); |
| 1016 | current_sound = &s; | 1013 | bzero (current_sound, sizeof (struct sound)); |
| 1017 | record_unwind_protect (sound_cleanup, Qnil); | 1014 | record_unwind_protect (sound_cleanup, Qnil); |
| 1018 | s.header = (char *) alloca (MAX_SOUND_HEADER_BYTES); | 1015 | current_sound->header = (char *) alloca (MAX_SOUND_HEADER_BYTES); |
| 1019 | 1016 | ||
| 1020 | if (STRINGP (attrs[SOUND_FILE])) | 1017 | if (STRINGP (attrs[SOUND_FILE])) |
| 1021 | { | 1018 | { |
| 1022 | /* Open the sound file. */ | 1019 | /* Open the sound file. */ |
| 1023 | s.fd = openp (Fcons (Vdata_directory, Qnil), | 1020 | current_sound->fd = openp (Fcons (Vdata_directory, Qnil), |
| 1024 | attrs[SOUND_FILE], Qnil, &file, Qnil); | 1021 | attrs[SOUND_FILE], Qnil, &file, Qnil); |
| 1025 | if (s.fd < 0) | 1022 | if (current_sound->fd < 0) |
| 1026 | sound_perror ("Could not open sound file"); | 1023 | sound_perror ("Could not open sound file"); |
| 1027 | 1024 | ||
| 1028 | /* Read the first bytes from the file. */ | 1025 | /* Read the first bytes from the file. */ |
| 1029 | s.header_size = emacs_read (s.fd, s.header, MAX_SOUND_HEADER_BYTES); | 1026 | current_sound->header_size |
| 1030 | if (s.header_size < 0) | 1027 | = emacs_read (current_sound->fd, current_sound->header, |
| 1028 | MAX_SOUND_HEADER_BYTES); | ||
| 1029 | if (current_sound->header_size < 0) | ||
| 1031 | sound_perror ("Invalid sound file header"); | 1030 | sound_perror ("Invalid sound file header"); |
| 1032 | } | 1031 | } |
| 1033 | else | 1032 | else |
| 1034 | { | 1033 | { |
| 1035 | s.data = attrs[SOUND_DATA]; | 1034 | current_sound->data = attrs[SOUND_DATA]; |
| 1036 | s.header_size = min (MAX_SOUND_HEADER_BYTES, SBYTES (s.data)); | 1035 | current_sound->header_size = min (MAX_SOUND_HEADER_BYTES, SBYTES (current_sound->data)); |
| 1037 | bcopy (SDATA (s.data), s.header, s.header_size); | 1036 | bcopy (SDATA (current_sound->data), current_sound->header, current_sound->header_size); |
| 1038 | } | 1037 | } |
| 1039 | 1038 | ||
| 1040 | /* Find out the type of sound. Give up if we can't tell. */ | 1039 | /* Find out the type of sound. Give up if we can't tell. */ |
| 1041 | find_sound_type (&s); | 1040 | find_sound_type (current_sound); |
| 1042 | 1041 | ||
| 1043 | /* Set up a device. */ | 1042 | /* Set up a device. */ |
| 1044 | if (STRINGP (attrs[SOUND_DEVICE])) | 1043 | if (STRINGP (attrs[SOUND_DEVICE])) |
| 1045 | { | 1044 | { |
| 1046 | int len = SCHARS (attrs[SOUND_DEVICE]); | 1045 | int len = SCHARS (attrs[SOUND_DEVICE]); |
| 1047 | sd.file = (char *) alloca (len + 1); | 1046 | current_sound_device->file = (char *) alloca (len + 1); |
| 1048 | strcpy (sd.file, SDATA (attrs[SOUND_DEVICE])); | 1047 | strcpy (current_sound_device->file, SDATA (attrs[SOUND_DEVICE])); |
| 1049 | } | 1048 | } |
| 1050 | 1049 | ||
| 1051 | if (INTEGERP (attrs[SOUND_VOLUME])) | 1050 | if (INTEGERP (attrs[SOUND_VOLUME])) |
| 1052 | sd.volume = XFASTINT (attrs[SOUND_VOLUME]); | 1051 | current_sound_device->volume = XFASTINT (attrs[SOUND_VOLUME]); |
| 1053 | else if (FLOATP (attrs[SOUND_VOLUME])) | 1052 | else if (FLOATP (attrs[SOUND_VOLUME])) |
| 1054 | sd.volume = XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100; | 1053 | current_sound_device->volume = XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100; |
| 1055 | 1054 | ||
| 1056 | args[0] = Qplay_sound_functions; | 1055 | args[0] = Qplay_sound_functions; |
| 1057 | args[1] = sound; | 1056 | args[1] = sound; |
| @@ -1060,27 +1059,15 @@ Internal use only, use `play-sound' instead.\n */) | |||
| 1060 | /* There is only one type of device we currently support, the VOX | 1059 | /* There is only one type of device we currently support, the VOX |
| 1061 | sound driver. Set up the device interface functions for that | 1060 | sound driver. Set up the device interface functions for that |
| 1062 | device. */ | 1061 | device. */ |
| 1063 | vox_init (&sd); | 1062 | vox_init (current_sound_device); |
| 1064 | 1063 | ||
| 1065 | /* Open the device. */ | 1064 | /* Open the device. */ |
| 1066 | sd.open (&sd); | 1065 | current_sound_device->open (current_sound_device); |
| 1067 | 1066 | ||
| 1068 | /* Play the sound. */ | 1067 | /* Play the sound. */ |
| 1069 | s.play (&s, &sd); | 1068 | current_sound->play (current_sound, current_sound_device); |
| 1070 | |||
| 1071 | /* Close the input file, if any. */ | ||
| 1072 | if (!STRINGP (s.data)) | ||
| 1073 | { | ||
| 1074 | emacs_close (s.fd); | ||
| 1075 | s.fd = -1; | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | /* Close the device. */ | ||
| 1079 | sd.close (&sd); | ||
| 1080 | 1069 | ||
| 1081 | /* Clean up. */ | 1070 | /* Clean up. */ |
| 1082 | current_sound_device = NULL; | ||
| 1083 | current_sound = NULL; | ||
| 1084 | UNGCPRO; | 1071 | UNGCPRO; |
| 1085 | 1072 | ||
| 1086 | #else /* WINDOWSNT */ | 1073 | #else /* WINDOWSNT */ |