Mercurial > hg > xemacs-beta
comparison src/sunplay.c @ 563:183866b06e0b
[xemacs-hg @ 2001-05-24 07:50:48 by ben]
Makefile.in.in, abbrev.c, alloc.c, buffer.c, bytecode.c, callint.c, callproc.c, casetab.c, chartab.c, cmdloop.c, cmds.c, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console.c, data.c, database.c, debug.c, device-gtk.c, device-msw.c, device-tty.c, device-x.c, device.c, dialog-gtk.c, dialog-msw.c, dialog-x.c, dialog.c, dired-msw.c, dired.c, doc.c, doprnt.c, dragdrop.c, editfns.c, eldap.c, eldap.h, elhash.c, emacs-widget-accessors.c, emacs.c, emodules.c, esd.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, filelock.c, floatfns.c, fns.c, font-lock.c, frame-gtk.c, frame-x.c, frame.c, general-slots.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-gtk.c, gui-x.c, gui.c, gutter.c, hpplay.c, indent.c, input-method-xlib.c, insdel.c, intl.c, keymap.c, libsst.c, libsst.h, linuxplay.c, lisp.h, lread.c, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, miscplay.c, miscplay.h, mule-ccl.c, mule-charset.c, mule-wnnfns.c, mule.c, nas.c, ntplay.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, ralloc.c, rangetab.c, redisplay.c, scrollbar.c, search.c, select-gtk.c, select-x.c, select.c, sgiplay.c, sheap.c, sound.c, specifier.c, sunplay.c, symbols.c, symeval.h, symsinit.h, syntax.c, sysdep.c, toolbar-msw.c, toolbar.c, tooltalk.c, ui-byhand.c, ui-gtk.c, undo.c, unexaix.c, unexapollo.c, unexconvex.c, unexec.c, widget.c, win32.c, window.c:
-- defsymbol -> DEFSYMBOL.
-- add an error type to all errors.
-- eliminate the error functions in eval.c that let you just
use Qerror as the type.
-- redo the error API to be more consistent, sensibly named,
and easier to use.
-- redo the error hierarchy somewhat. create new errors:
structure-formation-error, gui-error, invalid-constant,
stack-overflow, out-of-memory, process-error, network-error,
sound-error, printing-unreadable-object, base64-conversion-
error; coding-system-error renamed to text-conversion error;
some others.
-- fix Mule problems in error strings in emodules.c, tooltalk.c.
-- fix error handling in mswin open-network-stream.
-- Mule-ize all sound files and clean up the headers.
-- nativesound.h -> sound.h and used for all sound files.
-- move some shared stuff into glyphs-shared.c: first attempt
at eliminating some of the massive GTK code duplication.
xemacs.mak: add glyphs-shared.c.
xemacs-faq.texi: document how to debug X errors
subr.el: fix doc string to reflect reality
author | ben |
---|---|
date | Thu, 24 May 2001 07:51:33 +0000 |
parents | abe6d1db359e |
children | 13e3d7ae7155 |
comparison
equal
deleted
inserted
replaced
562:c775bd016b32 | 563:183866b06e0b |
---|---|
13 ** implied warranty. | 13 ** implied warranty. |
14 */ | 14 */ |
15 | 15 |
16 /* Synched up with: Not in FSF. */ | 16 /* Synched up with: Not in FSF. */ |
17 | 17 |
18 #ifdef HAVE_CONFIG_H | 18 /* This file Mule-ized by Ben Wing, 5-15-01. */ |
19 | |
19 #include <config.h> | 20 #include <config.h> |
20 #endif | 21 #include "lisp.h" |
21 | 22 #include "sound.h" |
22 #if __STDC__ || defined(STDC_HEADERS) | 23 |
23 #include <stdlib.h> | 24 #include "sysdep.h" |
24 #include <unistd.h> | 25 #include "sysfile.h" |
25 #include <fcntl.h> /* for open() */ | 26 #include "syssignal.h" |
26 #endif | |
27 | |
28 #include <stdio.h> | |
29 #include <string.h> | |
30 #ifndef emacs | |
31 #include <sys/signal.h> | |
32 #endif | |
33 #include <sys/fcntl.h> | |
34 #include <sys/file.h> | |
35 | 27 |
36 #include <multimedia/libaudio.h> | 28 #include <multimedia/libaudio.h> |
37 #include <multimedia/audio_device.h> | 29 #include <multimedia/audio_device.h> |
38 | |
39 #ifdef emacs | |
40 # include <config.h> | |
41 # include "lisp.h" | |
42 # include "sysdep.h" | |
43 # include <errno.h> | |
44 # include "nativesound.h" | |
45 #include "syssignal.h" | |
46 # define perror(string) \ | |
47 message("audio: %s, %s ", string, strerror (errno)) | |
48 # define warn(str) message ("audio: %s ", GETTEXT (str)) | |
49 #else /* !emacs */ | |
50 # define warn(str) fprintf (stderr, "%s\n", (str)) | |
51 #endif /* emacs */ | |
52 | 30 |
53 static SIGTYPE (*sighup_handler) (int sig); | 31 static SIGTYPE (*sighup_handler) (int sig); |
54 static SIGTYPE (*sigint_handler) (int sig); | 32 static SIGTYPE (*sigint_handler) (int sig); |
55 static SIGTYPE sighandler (int sig); | 33 static SIGTYPE sighandler (int sig); |
56 | 34 |
62 static int reset_volume_p, reset_device_p; | 40 static int reset_volume_p, reset_device_p; |
63 static double old_volume; | 41 static double old_volume; |
64 static Audio_hdr dev_hdr; | 42 static Audio_hdr dev_hdr; |
65 | 43 |
66 static int | 44 static int |
67 init_device (int volume, unsigned char *data, int fd, | 45 init_device (int volume, UChar_Binary *data, int fd, |
68 unsigned int *header_length) | 46 unsigned int *header_length) |
69 { | 47 { |
70 #ifdef SUNOS4_0_3 | 48 #ifdef SUNOS4_0_3 |
71 if (header_length) *header_length = 0; | 49 if (header_length) *header_length = 0; |
72 return 0; | 50 return 0; |
78 | 56 |
79 if (data && fd) abort (); /* one or the other */ | 57 if (data && fd) abort (); /* one or the other */ |
80 | 58 |
81 if (AUDIO_SUCCESS != audio_get_play_config (audio_fd, &dev_hdr)) | 59 if (AUDIO_SUCCESS != audio_get_play_config (audio_fd, &dev_hdr)) |
82 { | 60 { |
83 perror ("Not a valid audio device"); | 61 sound_perror ("Not a valid audio device"); |
84 return 1; | 62 return 1; |
85 } | 63 } |
86 | 64 |
87 if (AUDIO_SUCCESS != (data | 65 if (AUDIO_SUCCESS != (data |
88 ? audio_decode_filehdr (data, &file_hdr, header_length) | 66 ? audio_decode_filehdr (data, &file_hdr, header_length) |
89 : audio_read_filehdr (fd, &file_hdr, 0, 0))) | 67 : audio_read_filehdr (fd, &file_hdr, 0, 0))) |
90 { | 68 { |
91 if (data) | 69 if (data) |
92 perror ("invalid audio data"); | 70 sound_perror ("invalid audio data"); |
93 else | 71 else |
94 perror ("invalid audio file"); | 72 sound_perror ("invalid audio file"); |
95 return 1; | 73 return 1; |
96 } | 74 } |
97 | 75 |
98 audio_flush_play (audio_fd); | 76 audio_flush_play (audio_fd); |
99 | 77 |
103 new_hdr = file_hdr; | 81 new_hdr = file_hdr; |
104 reset_device_p = 1; | 82 reset_device_p = 1; |
105 initialized_device_p = 1; | 83 initialized_device_p = 1; |
106 if (AUDIO_SUCCESS != audio_set_play_config (audio_fd, &new_hdr)) | 84 if (AUDIO_SUCCESS != audio_set_play_config (audio_fd, &new_hdr)) |
107 { | 85 { |
108 char buf1 [100], buf2 [100], buf3 [250]; | 86 Extbyte buf1 [100], buf2 [100], buf3 [250]; |
109 audio_enc_to_str (&file_hdr, buf1); | 87 audio_enc_to_str (&file_hdr, buf1); |
110 audio_enc_to_str (&new_hdr, buf2); | 88 audio_enc_to_str (&new_hdr, buf2); |
111 sprintf (buf3, "wanted %s, got %s", buf1, buf2); | 89 sprintf (buf3, "wanted %s, got %s", buf1, buf2); |
112 warn (buf3); | 90 sound_warn (buf3); |
113 return 1; | 91 return 1; |
114 } | 92 } |
115 } | 93 } |
116 | 94 |
117 if (volume < 0 || volume > 100) | 95 if (volume < 0 || volume > 100) |
118 { | 96 { |
119 char buf [255]; | 97 Extbyte buf [255]; |
120 sprintf (buf, "volume must be between 0 and 100 (not %d)", volume); | 98 sprintf (buf, "volume must be between 0 and 100 (not %d)", volume); |
121 warn (buf); | 99 sound_warn (buf); |
122 return 1; | 100 return 1; |
123 } | 101 } |
124 { | 102 { |
125 /* set the volume; scale it to 0.0 - 1.0 */ | 103 /* set the volume; scale it to 0.0 - 1.0 */ |
126 double V = (volume / 100.0); | 104 double V = (volume / 100.0); |
147 audio_set_play_gain (audio_fd, &old_volume); | 125 audio_set_play_gain (audio_fd, &old_volume); |
148 } | 126 } |
149 | 127 |
150 | 128 |
151 void | 129 void |
152 play_sound_file (char *sound_file, int volume) | 130 play_sound_file (Extbyte *sound_file, int volume) |
153 { | 131 { |
154 int rrtn, wrtn; | 132 int rrtn, wrtn; |
155 unsigned char buf [255]; | 133 UChar_Binary buf [255]; |
156 int file_fd; | 134 int file_fd; |
157 | 135 |
158 audio_fd = audio_open (); | 136 audio_fd = audio_open (); |
159 | 137 |
160 if (audio_fd < 0) | 138 if (audio_fd < 0) |
161 { | 139 { |
162 perror ("open /dev/audio"); | 140 sound_perror ("open /dev/audio"); |
163 return; | 141 return; |
164 } | 142 } |
165 | 143 |
166 /* where to find the proto for signal()... */ | 144 /* where to find the proto for signal()... */ |
167 sighup_handler = (SIGTYPE (*) (int)) signal (SIGHUP, sighandler); | 145 sighup_handler = (SIGTYPE (*) (int)) signal (SIGHUP, sighandler); |
168 sigint_handler = (SIGTYPE (*) (int)) signal (SIGINT, sighandler); | 146 sigint_handler = (SIGTYPE (*) (int)) signal (SIGINT, sighandler); |
169 | 147 |
170 file_fd = open (sound_file, O_RDONLY, 0); | 148 file_fd = open (sound_file, O_RDONLY, 0); |
171 if (file_fd < 0) | 149 if (file_fd < 0) |
172 { | 150 { |
173 perror (sound_file); | 151 sound_perror (sound_file); |
174 goto END_OF_PLAY; | 152 goto END_OF_PLAY; |
175 } | 153 } |
176 | 154 |
177 if (init_device (volume, (unsigned char *) 0, file_fd, (unsigned int *) 0)) | 155 if (init_device (volume, (UChar_Binary *) 0, file_fd, (unsigned int *) 0)) |
178 goto END_OF_PLAY; | 156 goto END_OF_PLAY; |
179 | 157 |
180 while (1) | 158 while (1) |
181 { | 159 { |
182 rrtn = read (file_fd, (char *) buf, sizeof (buf)); | 160 rrtn = read (file_fd, (Char_Binary *) buf, sizeof (buf)); |
183 if (rrtn < 0) | 161 if (rrtn < 0) |
184 { | 162 { |
185 perror ("read"); | 163 sound_perror ("read"); |
186 goto END_OF_PLAY; | 164 goto END_OF_PLAY; |
187 } | 165 } |
188 if (rrtn == 0) | 166 if (rrtn == 0) |
189 break; | 167 break; |
190 | 168 |
191 while (1) | 169 while (1) |
192 { | 170 { |
193 wrtn = write (audio_fd, (char *) buf, rrtn); | 171 wrtn = write (audio_fd, (Char_Binary *) buf, rrtn); |
194 if (wrtn < 0) | 172 if (wrtn < 0) |
195 { | 173 { |
196 perror ("write"); | 174 sound_perror ("write"); |
197 goto END_OF_PLAY; | 175 goto END_OF_PLAY; |
198 } | 176 } |
199 if (wrtn != 0) | 177 if (wrtn != 0) |
200 break; | 178 break; |
201 | 179 |
202 if (AUDIO_ERR_INTERRUPTED == audio_drain (audio_fd, 1)) | 180 if (AUDIO_ERR_INTERRUPTED == audio_drain (audio_fd, 1)) |
203 goto END_OF_PLAY; | 181 goto END_OF_PLAY; |
204 } | 182 } |
205 if (wrtn != rrtn) | 183 if (wrtn != rrtn) |
206 { | 184 { |
207 char warn_buf [255]; | 185 Extbyte warn_buf [255]; |
208 sprintf (warn_buf, "play: rrtn = %d, wrtn = %d", rrtn, wrtn); | 186 sprintf (warn_buf, "play: rrtn = %d, wrtn = %d", rrtn, wrtn); |
209 warn (warn_buf); | 187 sound_warn (warn_buf); |
210 goto END_OF_PLAY; | 188 goto END_OF_PLAY; |
211 } | 189 } |
212 } | 190 } |
213 | 191 |
214 END_OF_PLAY: | 192 END_OF_PLAY: |
226 signal (SIGINT, sigint_handler); | 204 signal (SIGINT, sigint_handler); |
227 } | 205 } |
228 | 206 |
229 | 207 |
230 int | 208 int |
231 play_sound_data (unsigned char *data, int length, int volume) | 209 play_sound_data (UChar_Binary *data, int length, int volume) |
232 { | 210 { |
233 int wrtn, start = 0; | 211 int wrtn, start = 0; |
234 unsigned int ilen; | 212 unsigned int ilen; |
235 int result = 0; | 213 int result = 0; |
236 | 214 |
237 audio_fd = -1; | 215 audio_fd = -1; |
238 | 216 |
239 if (length == 0) return 0; | 217 if (length == 0) return 0; |
240 | 218 |
241 /* this is just to get a better error message */ | 219 /* this is just to get a better error message */ |
242 if (strncmp (".snd\0", (char *) data, 4)) | 220 if (strncmp (".snd\0", (Char_Binary *) data, 4)) |
243 { | 221 { |
244 warn ("Not valid audio data (bad magic number)"); | 222 sound_warn ("Not valid audio data (bad magic number)"); |
245 goto END_OF_PLAY; | 223 goto END_OF_PLAY; |
246 } | 224 } |
247 if (length <= sizeof (Audio_hdr)) | 225 if (length <= sizeof (Audio_hdr)) |
248 { | 226 { |
249 warn ("Not valid audio data (too short)"); | 227 sound_warn ("Not valid audio data (too short)"); |
250 goto END_OF_PLAY; | 228 goto END_OF_PLAY; |
251 } | 229 } |
252 | 230 |
253 audio_fd = audio_open (); | 231 audio_fd = audio_open (); |
254 if (audio_fd < 0) | 232 if (audio_fd < 0) |
266 if (length <= 1) | 244 if (length <= 1) |
267 goto END_OF_PLAY; | 245 goto END_OF_PLAY; |
268 | 246 |
269 while (1) | 247 while (1) |
270 { | 248 { |
271 wrtn = write (audio_fd, (char *) (data+start), length-start); | 249 wrtn = write (audio_fd, (Char_Binary *) (data+start), length-start); |
272 if (wrtn < 0) | 250 if (wrtn < 0) |
273 { | 251 { |
274 perror ("write"); | 252 sound_perror ("write"); |
275 goto END_OF_PLAY; | 253 goto END_OF_PLAY; |
276 } | 254 } |
277 if (wrtn != 0) | 255 if (wrtn != 0) |
278 { | 256 { |
279 start += wrtn; | 257 start += wrtn; |
282 if (AUDIO_ERR_INTERRUPTED == audio_drain (audio_fd, 1)) | 260 if (AUDIO_ERR_INTERRUPTED == audio_drain (audio_fd, 1)) |
283 goto END_OF_PLAY; | 261 goto END_OF_PLAY; |
284 } | 262 } |
285 if (wrtn != length) | 263 if (wrtn != length) |
286 { | 264 { |
287 char buf [255]; | 265 Extbyte buf [255]; |
288 sprintf (buf, "play: rrtn = %d, wrtn = %d", length, wrtn); | 266 sprintf (buf, "play: rrtn = %d, wrtn = %d", length, wrtn); |
289 warn (buf); | 267 sound_warn (buf); |
290 goto END_OF_PLAY; | 268 goto END_OF_PLAY; |
291 } | 269 } |
292 | 270 |
293 result = 1; | 271 result = 1; |
294 | 272 |