comparison src/sunplay.c @ 406:b8cc9ab3f761 r21-2-33

Import from CVS: tag r21-2-33
author cvs
date Mon, 13 Aug 2007 11:17:09 +0200
parents 74fd4e045ea6
children 697ef44129c6
comparison
equal deleted inserted replaced
405:0e08f63c74d2 406:b8cc9ab3f761
39 #ifdef emacs 39 #ifdef emacs
40 # include <config.h> 40 # include <config.h>
41 # include "lisp.h" 41 # include "lisp.h"
42 # include "sysdep.h" 42 # include "sysdep.h"
43 # include <errno.h> 43 # include <errno.h>
44 # include "nativesound.h"
44 #include "syssignal.h" 45 #include "syssignal.h"
45 # define perror(string) \ 46 # define perror(string) \
46 message("audio: %s, %s ", string, strerror (errno)) 47 message("audio: %s, %s ", string, strerror (errno))
47 # define warn(str) message ("audio: %s ", GETTEXT (str)) 48 # define warn(str) message ("audio: %s ", GETTEXT (str))
48 #else /* !emacs */ 49 #else /* !emacs */
55 56
56 static int audio_fd; 57 static int audio_fd;
57 58
58 #define audio_open() open ("/dev/audio", (O_WRONLY | O_NONBLOCK), 0) 59 #define audio_open() open ("/dev/audio", (O_WRONLY | O_NONBLOCK), 0)
59 60
61 static int initialized_device_p;
60 static int reset_volume_p, reset_device_p; 62 static int reset_volume_p, reset_device_p;
61 static double old_volume; 63 static double old_volume;
62 static Audio_hdr dev_hdr; 64 static Audio_hdr dev_hdr;
63
64 void play_sound_file (char *name, int volume);
65 void play_sound_data (unsigned char *data, int length, int volume);
66 65
67 static int 66 static int
68 init_device (int volume, unsigned char *data, int fd, 67 init_device (int volume, unsigned char *data, int fd,
69 unsigned int *header_length) 68 unsigned int *header_length)
70 { 69 {
96 return 1; 95 return 1;
97 } 96 }
98 97
99 audio_flush_play (audio_fd); 98 audio_flush_play (audio_fd);
100 99
101 if (0 != audio_cmp_hdr (&dev_hdr, &file_hdr)) 100 if (!initialized_device_p || (0 != audio_cmp_hdr (&dev_hdr, &file_hdr)))
102 { 101 {
103 Audio_hdr new_hdr; 102 Audio_hdr new_hdr;
104 new_hdr = file_hdr; 103 new_hdr = file_hdr;
105 reset_device_p = 1; 104 reset_device_p = 1;
105 initialized_device_p = 1;
106 if (AUDIO_SUCCESS != audio_set_play_config (audio_fd, &new_hdr)) 106 if (AUDIO_SUCCESS != audio_set_play_config (audio_fd, &new_hdr))
107 { 107 {
108 char buf1 [100], buf2 [100], buf3 [250]; 108 char buf1 [100], buf2 [100], buf3 [250];
109 audio_enc_to_str (&file_hdr, buf1); 109 audio_enc_to_str (&file_hdr, buf1);
110 audio_enc_to_str (&new_hdr, buf2); 110 audio_enc_to_str (&new_hdr, buf2);
225 signal (SIGHUP, sighup_handler); 225 signal (SIGHUP, sighup_handler);
226 signal (SIGINT, sigint_handler); 226 signal (SIGINT, sigint_handler);
227 } 227 }
228 228
229 229
230 void 230 int
231 play_sound_data (unsigned char *data, int length, int volume) 231 play_sound_data (unsigned char *data, int length, int volume)
232 { 232 {
233 int wrtn, start = 0; 233 int wrtn, start = 0;
234 unsigned int ilen; 234 unsigned int ilen;
235 int result = 0;
235 236
236 audio_fd = -1; 237 audio_fd = -1;
237 238
238 if (length == 0) return; 239 if (length == 0) return 0;
239 240
240 /* this is just to get a better error message */ 241 /* this is just to get a better error message */
241 if (strncmp (".snd\0", (char *) data, 4)) 242 if (strncmp (".snd\0", (char *) data, 4))
242 { 243 {
243 warn ("Not valid audio data (bad magic number)"); 244 warn ("Not valid audio data (bad magic number)");
249 goto END_OF_PLAY; 250 goto END_OF_PLAY;
250 } 251 }
251 252
252 audio_fd = audio_open (); 253 audio_fd = audio_open ();
253 if (audio_fd < 0) 254 if (audio_fd < 0)
254 { 255 return 0;
255 perror ("open /dev/audio");
256 return;
257 }
258 256
259 /* where to find the proto for signal()... */ 257 /* where to find the proto for signal()... */
260 sighup_handler = (SIGTYPE (*) (int)) signal (SIGHUP, sighandler); 258 sighup_handler = (SIGTYPE (*) (int)) signal (SIGHUP, sighandler);
261 sigint_handler = (SIGTYPE (*) (int)) signal (SIGINT, sighandler); 259 sigint_handler = (SIGTYPE (*) (int)) signal (SIGINT, sighandler);
262 260
290 sprintf (buf, "play: rrtn = %d, wrtn = %d", length, wrtn); 288 sprintf (buf, "play: rrtn = %d, wrtn = %d", length, wrtn);
291 warn (buf); 289 warn (buf);
292 goto END_OF_PLAY; 290 goto END_OF_PLAY;
293 } 291 }
294 292
293 result = 1;
294
295 END_OF_PLAY: 295 END_OF_PLAY:
296 296
297 if (audio_fd > 0) 297 if (audio_fd > 0)
298 { 298 {
299 reset_device (1); 299 reset_device (1);
300 close (audio_fd); 300 close (audio_fd);
301 } 301 }
302 302
303 signal (SIGHUP, sighup_handler); 303 signal (SIGHUP, sighup_handler);
304 signal (SIGINT, sigint_handler); 304 signal (SIGINT, sigint_handler);
305
306 return result;
305 } 307 }
306 308
307 /* #### sigcontext doesn't exist in Solaris. This should be updated 309 /* #### sigcontext doesn't exist in Solaris. This should be updated
308 to be correct for Solaris. */ 310 to be correct for Solaris. */
309 static SIGTYPE 311 static SIGTYPE