comparison src/sound.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 8de8e3f6228a
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
35 35
36 #include "device.h" 36 #include "device.h"
37 #include "redisplay.h" 37 #include "redisplay.h"
38 #include "sysdep.h" 38 #include "sysdep.h"
39 39
40 #ifdef HAVE_UNISTD_H 40 #include "sysfile.h"
41 #include <unistd.h>
42 #endif
43 41
44 #ifdef HAVE_NATIVE_SOUND 42 #ifdef HAVE_NATIVE_SOUND
45 # include <netdb.h> 43 # include "sysproc.h"
44 # include "nativesound.h"
46 #endif 45 #endif
47 46
48 #ifdef HAVE_ESD_SOUND 47 #ifdef HAVE_ESD_SOUND
49 extern int esd_play_sound_file (char *file, int vol); 48 extern int esd_play_sound_file (char *file, int vol);
50 extern int esd_play_sound_data (unsigned char *data, size_t length, int vol); 49 extern int esd_play_sound_data (unsigned char *data, size_t length, int vol);
56 Lisp_Object Vsound_alist; 55 Lisp_Object Vsound_alist;
57 Lisp_Object Vsynchronous_sounds; 56 Lisp_Object Vsynchronous_sounds;
58 Lisp_Object Vnative_sound_only_on_console; 57 Lisp_Object Vnative_sound_only_on_console;
59 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound; 58 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound;
60 59
61 /* These are defined in the appropriate file (sunplay.c, sgiplay.c,
62 or hpplay.c). */
63
64 extern void play_sound_file (char *name, int volume);
65 extern void play_sound_data (unsigned char *data, int length, int volume);
66 60
67 #ifdef HAVE_NAS_SOUND 61 #ifdef HAVE_NAS_SOUND
68 extern int nas_play_sound_file (char *name, int volume); 62 extern int nas_play_sound_file (char *name, int volume);
69 extern int nas_play_sound_data (unsigned char *data, int length, int volume); 63 extern int nas_play_sound_data (unsigned char *data, int length, int volume);
70 extern int nas_wait_for_sounds (void); 64 extern int nas_wait_for_sounds (void);
124 #ifdef HAVE_NAS_SOUND 118 #ifdef HAVE_NAS_SOUND
125 if (DEVICE_CONNECTED_TO_NAS_P (d)) 119 if (DEVICE_CONNECTED_TO_NAS_P (d))
126 { 120 {
127 char *fileext; 121 char *fileext;
128 122
129 TO_EXTERNAL_FORMAT (LISP_STRING, file, 123 LISP_STRING_TO_EXTERNAL (file, fileext, Qfile_name);
130 C_STRING_ALLOCA, fileext,
131 Qfile_name);
132 /* #### NAS code should allow specification of a device. */ 124 /* #### NAS code should allow specification of a device. */
133 if (nas_play_sound_file (fileext, vol)) 125 if (nas_play_sound_file (fileext, vol))
134 return Qnil; 126 return Qnil;
135 } 127 }
136 #endif /* HAVE_NAS_SOUND */ 128 #endif /* HAVE_NAS_SOUND */
137 129
138 #ifdef HAVE_ESD_SOUND 130 #ifdef HAVE_ESD_SOUND
139 if (DEVICE_CONNECTED_TO_ESD_P (d)) 131 if (DEVICE_CONNECTED_TO_ESD_P (d))
140 { 132 {
141 char *fileext; 133 char *fileext;
142 134 int result;
143 TO_EXTERNAL_FORMAT (LISP_STRING, file, 135
144 C_STRING_ALLOCA, fileext, 136 LISP_STRING_TO_EXTERNAL (file, fileext, Qfile_name);
145 Qfile_name); 137
146 if (esd_play_sound_file (fileext, vol)) 138 /* #### ESD uses alarm(). But why should we also stop SIGIO? */
139 stop_interrupts ();
140 result = esd_play_sound_file (fileext, vol);
141 start_interrupts ();
142 if (result)
147 return Qnil; 143 return Qnil;
148 } 144 }
149 #endif /* HAVE_ESD_SOUND */ 145 #endif /* HAVE_ESD_SOUND */
150 146
151 #ifdef HAVE_NATIVE_SOUND 147 #ifdef HAVE_NATIVE_SOUND
152 if (NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d)) 148 if (NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d))
153 { 149 {
154 CONST char *fileext; 150 const char *fileext;
155 151
156 TO_EXTERNAL_FORMAT (LISP_STRING, file, 152 LISP_STRING_TO_EXTERNAL (file, fileext, Qfile_name);
157 C_STRING_ALLOCA, fileext,
158 Qfile_name);
159 /* The sound code doesn't like getting SIGIO interrupts. 153 /* The sound code doesn't like getting SIGIO interrupts.
160 Unix sucks! */ 154 Unix sucks! */
161 stop_interrupts (); 155 stop_interrupts ();
162 play_sound_file ((char *) fileext, vol); 156 play_sound_file ((char *) fileext, vol);
163 start_interrupts (); 157 start_interrupts ();
315 Else just beep. 309 Else just beep.
316 */ 310 */
317 #ifdef HAVE_NAS_SOUND 311 #ifdef HAVE_NAS_SOUND
318 if (DEVICE_CONNECTED_TO_NAS_P (d) && STRINGP (sound)) 312 if (DEVICE_CONNECTED_TO_NAS_P (d) && STRINGP (sound))
319 { 313 {
320 CONST Extbyte *soundext; 314 const Extbyte *soundext;
321 Extcount soundextlen; 315 Extcount soundextlen;
322 316
323 TO_EXTERNAL_FORMAT (LISP_STRING, sound, 317 TO_EXTERNAL_FORMAT (LISP_STRING, sound,
324 ALLOCA, (soundext, soundextlen), 318 ALLOCA, (soundext, soundextlen),
325 Qbinary); 319 Qbinary);
331 #ifdef HAVE_ESD_SOUND 325 #ifdef HAVE_ESD_SOUND
332 if (DEVICE_CONNECTED_TO_ESD_P (d) && STRINGP (sound)) 326 if (DEVICE_CONNECTED_TO_ESD_P (d) && STRINGP (sound))
333 { 327 {
334 Extbyte *soundext; 328 Extbyte *soundext;
335 Extcount soundextlen; 329 Extcount soundextlen;
330 int succes;
336 331
337 TO_EXTERNAL_FORMAT (LISP_STRING, sound, ALLOCA, (soundext, soundextlen), 332 TO_EXTERNAL_FORMAT (LISP_STRING, sound, ALLOCA, (soundext, soundextlen),
338 Qbinary); 333 Qbinary);
339 if (esd_play_sound_data (soundext, soundextlen, vol)) 334
340 return Qnil; 335 /* #### ESD uses alarm(). But why should we also stop SIGIO? */
336 stop_interrupts ();
337 succes = esd_play_sound_data (soundext, soundextlen, vol);
338 start_interrupts ();
339 QUIT;
340 if(succes)
341 return Qnil;
341 } 342 }
342 #endif /* HAVE_ESD_SOUND */ 343 #endif /* HAVE_ESD_SOUND */
343 344
344 #ifdef HAVE_NATIVE_SOUND 345 #ifdef HAVE_NATIVE_SOUND
345 if ((NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d)) 346 if ((NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d))
346 && STRINGP (sound)) 347 && STRINGP (sound))
347 { 348 {
348 CONST Extbyte *soundext; 349 const Extbyte *soundext;
349 Extcount soundextlen; 350 Extcount soundextlen;
351 int succes;
350 352
351 TO_EXTERNAL_FORMAT (LISP_STRING, sound, 353 TO_EXTERNAL_FORMAT (LISP_STRING, sound,
352 ALLOCA, (soundext, soundextlen), 354 ALLOCA, (soundext, soundextlen),
353 Qbinary); 355 Qbinary);
354 /* The sound code doesn't like getting SIGIO interrupts. Unix sucks! */ 356 /* The sound code doesn't like getting SIGIO interrupts. Unix sucks! */
355 stop_interrupts (); 357 stop_interrupts ();
356 play_sound_data ((unsigned char*)soundext, soundextlen, vol); 358 succes = play_sound_data ((unsigned char*)soundext, soundextlen, vol);
357 start_interrupts (); 359 start_interrupts ();
358 QUIT; 360 QUIT;
359 return Qnil; 361 if (succes)
362 return Qnil;
360 } 363 }
361 #endif /* HAVE_NATIVE_SOUND */ 364 #endif /* HAVE_NATIVE_SOUND */
362 365
363 DEVMETH (d, ring_bell, (d, vol, pit, dur)); 366 DEVMETH (d, ring_bell, (d, vol, pit, dur));
364 return Qnil; 367 return Qnil;
402 /* Stop executing a keyboard macro. */ 405 /* Stop executing a keyboard macro. */
403 error ("Keyboard macro terminated by a command ringing the bell"); 406 error ("Keyboard macro terminated by a command ringing the bell");
404 407
405 if (d == last_bell_device && now-last_bell_time < bell_inhibit_time) 408 if (d == last_bell_device && now-last_bell_time < bell_inhibit_time)
406 return Qnil; 409 return Qnil;
407 else if (visible_bell && DEVMETH (d, flash, (d))) 410 else if (!NILP (Vvisible_bell) && DEVMETH (d, flash, (d)))
408 ; 411 ;
409 else 412 else
410 Fplay_sound (sound, Qnil, device); 413 Fplay_sound (sound, Qnil, device);
411 414
412 last_bell_time = now; 415 last_bell_time = now;
445 #ifdef HAVE_NAS_SOUND 448 #ifdef HAVE_NAS_SOUND
446 449
447 static void 450 static void
448 init_nas_sound (struct device *d) 451 init_nas_sound (struct device *d)
449 { 452 {
450 char *error;
451
452 #ifdef HAVE_X_WINDOWS 453 #ifdef HAVE_X_WINDOWS
453 if (DEVICE_X_P (d)) 454 if (DEVICE_X_P (d))
454 { 455 {
455 error = nas_init_play (DEVICE_X_DISPLAY (d)); 456 char *err_message = nas_init_play (DEVICE_X_DISPLAY (d));
456 DEVICE_CONNECTED_TO_NAS_P (d) = !error; 457 DEVICE_CONNECTED_TO_NAS_P (d) = !err_message;
457 /* Print out the message? */ 458 /* Print out the message? */
458 } 459 }
459 #endif /* HAVE_X_WINDOWS */ 460 #endif /* HAVE_X_WINDOWS */
460 } 461 }
461 462
643 Vsynchronous_sounds = Qnil; 644 Vsynchronous_sounds = Qnil;
644 645
645 DEFVAR_LISP ("native-sound-only-on-console", &Vnative_sound_only_on_console /* 646 DEFVAR_LISP ("native-sound-only-on-console", &Vnative_sound_only_on_console /*
646 Non-nil value means play sounds only if XEmacs is running 647 Non-nil value means play sounds only if XEmacs is running
647 on the system console. 648 on the system console.
648 Nil means always always play sounds, even if running on a non-console tty 649 Nil means always play sounds, even if running on a non-console tty
649 or a secondary X display. 650 or a secondary X display.
650 651
651 This variable only applies to native sound support. 652 This variable only applies to native sound support.
652 */ ); 653 */ );
653 Vnative_sound_only_on_console = Qt; 654 Vnative_sound_only_on_console = Qt;