Mercurial > hg > xemacs-beta
comparison src/sunplay.c @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 3ecd8885ac67 |
children | 183866b06e0b |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
31 #include <sys/signal.h> | 31 #include <sys/signal.h> |
32 #endif | 32 #endif |
33 #include <sys/fcntl.h> | 33 #include <sys/fcntl.h> |
34 #include <sys/file.h> | 34 #include <sys/file.h> |
35 | 35 |
36 /* libaudio.h includes a header which defines CONST. We temporarily | |
37 undefine it in order to eliminate a compiler warning. Yes, this is | |
38 a gross hack. */ | |
39 #undef CONST | |
40 #include <multimedia/libaudio.h> | 36 #include <multimedia/libaudio.h> |
41 #include <multimedia/audio_device.h> | 37 #include <multimedia/audio_device.h> |
42 #undef CONST | |
43 #define CONST const | |
44 | 38 |
45 #ifdef emacs | 39 #ifdef emacs |
46 # include <config.h> | 40 # include <config.h> |
47 # include "lisp.h" | 41 # include "lisp.h" |
48 # include "sysdep.h" | 42 # include "sysdep.h" |
49 # include <errno.h> | 43 # include <errno.h> |
44 # include "nativesound.h" | |
50 #include "syssignal.h" | 45 #include "syssignal.h" |
51 # define perror(string) \ | 46 # define perror(string) \ |
52 message("audio: %s, %s ", string, strerror (errno)) | 47 message("audio: %s, %s ", string, strerror (errno)) |
53 # define warn(str) message ("audio: %s ", GETTEXT (str)) | 48 # define warn(str) message ("audio: %s ", GETTEXT (str)) |
54 #else /* !emacs */ | 49 #else /* !emacs */ |
61 | 56 |
62 static int audio_fd; | 57 static int audio_fd; |
63 | 58 |
64 #define audio_open() open ("/dev/audio", (O_WRONLY | O_NONBLOCK), 0) | 59 #define audio_open() open ("/dev/audio", (O_WRONLY | O_NONBLOCK), 0) |
65 | 60 |
61 static int initialized_device_p; | |
66 static int reset_volume_p, reset_device_p; | 62 static int reset_volume_p, reset_device_p; |
67 static double old_volume; | 63 static double old_volume; |
68 static Audio_hdr dev_hdr; | 64 static Audio_hdr dev_hdr; |
69 | |
70 void play_sound_file (char *name, int volume); | |
71 void play_sound_data (unsigned char *data, int length, int volume); | |
72 | 65 |
73 static int | 66 static int |
74 init_device (int volume, unsigned char *data, int fd, | 67 init_device (int volume, unsigned char *data, int fd, |
75 unsigned int *header_length) | 68 unsigned int *header_length) |
76 { | 69 { |
102 return 1; | 95 return 1; |
103 } | 96 } |
104 | 97 |
105 audio_flush_play (audio_fd); | 98 audio_flush_play (audio_fd); |
106 | 99 |
107 if (0 != audio_cmp_hdr (&dev_hdr, &file_hdr)) | 100 if (!initialized_device_p || (0 != audio_cmp_hdr (&dev_hdr, &file_hdr))) |
108 { | 101 { |
109 Audio_hdr new_hdr; | 102 Audio_hdr new_hdr; |
110 new_hdr = file_hdr; | 103 new_hdr = file_hdr; |
111 reset_device_p = 1; | 104 reset_device_p = 1; |
105 initialized_device_p = 1; | |
112 if (AUDIO_SUCCESS != audio_set_play_config (audio_fd, &new_hdr)) | 106 if (AUDIO_SUCCESS != audio_set_play_config (audio_fd, &new_hdr)) |
113 { | 107 { |
114 char buf1 [100], buf2 [100], buf3 [250]; | 108 char buf1 [100], buf2 [100], buf3 [250]; |
115 audio_enc_to_str (&file_hdr, buf1); | 109 audio_enc_to_str (&file_hdr, buf1); |
116 audio_enc_to_str (&new_hdr, buf2); | 110 audio_enc_to_str (&new_hdr, buf2); |
231 signal (SIGHUP, sighup_handler); | 225 signal (SIGHUP, sighup_handler); |
232 signal (SIGINT, sigint_handler); | 226 signal (SIGINT, sigint_handler); |
233 } | 227 } |
234 | 228 |
235 | 229 |
236 void | 230 int |
237 play_sound_data (unsigned char *data, int length, int volume) | 231 play_sound_data (unsigned char *data, int length, int volume) |
238 { | 232 { |
239 int wrtn, start = 0; | 233 int wrtn, start = 0; |
240 unsigned int ilen; | 234 unsigned int ilen; |
235 int result = 0; | |
241 | 236 |
242 audio_fd = -1; | 237 audio_fd = -1; |
243 | 238 |
244 if (length == 0) return; | 239 if (length == 0) return 0; |
245 | 240 |
246 /* this is just to get a better error message */ | 241 /* this is just to get a better error message */ |
247 if (strncmp (".snd\0", (char *) data, 4)) | 242 if (strncmp (".snd\0", (char *) data, 4)) |
248 { | 243 { |
249 warn ("Not valid audio data (bad magic number)"); | 244 warn ("Not valid audio data (bad magic number)"); |
255 goto END_OF_PLAY; | 250 goto END_OF_PLAY; |
256 } | 251 } |
257 | 252 |
258 audio_fd = audio_open (); | 253 audio_fd = audio_open (); |
259 if (audio_fd < 0) | 254 if (audio_fd < 0) |
260 { | 255 return 0; |
261 perror ("open /dev/audio"); | |
262 return; | |
263 } | |
264 | 256 |
265 /* where to find the proto for signal()... */ | 257 /* where to find the proto for signal()... */ |
266 sighup_handler = (SIGTYPE (*) (int)) signal (SIGHUP, sighandler); | 258 sighup_handler = (SIGTYPE (*) (int)) signal (SIGHUP, sighandler); |
267 sigint_handler = (SIGTYPE (*) (int)) signal (SIGINT, sighandler); | 259 sigint_handler = (SIGTYPE (*) (int)) signal (SIGINT, sighandler); |
268 | 260 |
296 sprintf (buf, "play: rrtn = %d, wrtn = %d", length, wrtn); | 288 sprintf (buf, "play: rrtn = %d, wrtn = %d", length, wrtn); |
297 warn (buf); | 289 warn (buf); |
298 goto END_OF_PLAY; | 290 goto END_OF_PLAY; |
299 } | 291 } |
300 | 292 |
293 result = 1; | |
294 | |
301 END_OF_PLAY: | 295 END_OF_PLAY: |
302 | 296 |
303 if (audio_fd > 0) | 297 if (audio_fd > 0) |
304 { | 298 { |
305 reset_device (1); | 299 reset_device (1); |
306 close (audio_fd); | 300 close (audio_fd); |
307 } | 301 } |
308 | 302 |
309 signal (SIGHUP, sighup_handler); | 303 signal (SIGHUP, sighup_handler); |
310 signal (SIGINT, sigint_handler); | 304 signal (SIGINT, sigint_handler); |
305 | |
306 return result; | |
311 } | 307 } |
312 | 308 |
313 /* #### sigcontext doesn't exist in Solaris. This should be updated | 309 /* #### sigcontext doesn't exist in Solaris. This should be updated |
314 to be correct for Solaris. */ | 310 to be correct for Solaris. */ |
315 static void | 311 static SIGTYPE |
316 sighandler (int sig) | 312 sighandler (int sig) |
317 { | 313 { |
318 if (audio_fd > 0) | 314 if (audio_fd > 0) |
319 { | 315 { |
320 reset_device (0); | 316 reset_device (0); |