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