comparison src/sound.c @ 5118:e0db3c197671 ben-lisp-object

merge up to latest default branch, doesn't compile yet
author Ben Wing <ben@xemacs.org>
date Sat, 26 Dec 2009 21:18:49 -0600
parents fb73a2046d3e
children 19a72041c5ed
comparison
equal deleted inserted replaced
5117:3742ea8250b5 5118:e0db3c197671
62 #else 62 #else
63 #define USED_IF_HAVE_NATIVE_OR_NAS(decl) UNUSED (decl) 63 #define USED_IF_HAVE_NATIVE_OR_NAS(decl) UNUSED (decl)
64 #endif 64 #endif
65 65
66 #if defined(HAVE_NATIVE_SOUND) || defined(HAVE_NAS_SOUND) \ 66 #if defined(HAVE_NATIVE_SOUND) || defined(HAVE_NAS_SOUND) \
67 || defined(HAVE_ESD_SOUND) 67 || defined(HAVE_ALSA_SOUND) || defined(HAVE_ESD_SOUND)
68 #define USED_IF_HAVE_ANY(decl) decl 68 #define USED_IF_HAVE_ANY(decl) decl
69 #else 69 #else
70 #define USED_IF_HAVE_ANY(decl) UNUSED (decl) 70 #define USED_IF_HAVE_ANY(decl) UNUSED (decl)
71 #endif
72
73 #ifdef HAVE_ALSA_SOUND
74 extern int alsa_play_sound_file (const Extbyte *file, int vol);
75 extern int alsa_play_sound_data (const Binbyte *data, int length, int vol);
76 # define DEVICE_CONNECTED_TO_ALSA_P(x) 1 /* #### better check */
71 #endif 77 #endif
72 78
73 #ifdef HAVE_ESD_SOUND 79 #ifdef HAVE_ESD_SOUND
74 extern int esd_play_sound_file (Extbyte *file, int vol); 80 extern int esd_play_sound_file (Extbyte *file, int vol);
75 extern int esd_play_sound_data (Binbyte *data, size_t length, int vol); 81 extern int esd_play_sound_data (Binbyte *data, size_t length, int vol);
76 # define DEVICE_CONNECTED_TO_ESD_P(x) 1 /* #### better check */ 82 # define DEVICE_CONNECTED_TO_ESD_P(x) 1 /* #### better check */
83 #endif
84
85 #ifdef HAVE_NAS_SOUND
86 extern int nas_play_sound_file (Extbyte *name, int volume);
87 extern int nas_play_sound_data (Binbyte *data, int length, int volume);
88 extern int nas_wait_for_sounds (void);
89 extern Extbyte *nas_init_play (Display *);
77 #endif 90 #endif
78 91
79 Fixnum bell_volume; 92 Fixnum bell_volume;
80 Fixnum bell_inhibit_time; 93 Fixnum bell_inhibit_time;
81 Lisp_Object Vsound_alist; 94 Lisp_Object Vsound_alist;
82 Lisp_Object Vsynchronous_sounds; 95 Lisp_Object Vsynchronous_sounds;
83 Lisp_Object Vnative_sound_only_on_console; 96 Lisp_Object Vnative_sound_only_on_console;
84 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound; 97 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound;
85 Lisp_Object Qsound_error; 98 Lisp_Object Qsound_error;
86
87
88 #ifdef HAVE_NAS_SOUND
89 extern int nas_play_sound_file (Extbyte *name, int volume);
90 extern int nas_play_sound_data (Binbyte *data, int length, int volume);
91 extern int nas_wait_for_sounds (void);
92 extern Extbyte *nas_init_play (Display *);
93 #endif
94 99
95 DOESNT_RETURN 100 DOESNT_RETURN
96 report_sound_error (const Ascbyte *string, Lisp_Object data) 101 report_sound_error (const Ascbyte *string, Lisp_Object data)
97 { 102 {
98 report_error_with_errno (Qsound_error, string, data); 103 report_error_with_errno (Qsound_error, string, data);
108 */ 113 */
109 (file, volume, USED_IF_HAVE_ANY (device))) 114 (file, volume, USED_IF_HAVE_ANY (device)))
110 { 115 {
111 /* This function can call lisp */ 116 /* This function can call lisp */
112 int vol; 117 int vol;
113 #if defined (HAVE_NATIVE_SOUND) || defined (HAVE_NAS_SOUND) \ 118 #if defined (HAVE_NATIVE_SOUND) || defined (HAVE_ALSA_SOUND) || \
114 || defined (HAVE_ESD_SOUND) 119 defined (HAVE_NAS_SOUND) || defined (HAVE_ESD_SOUND)
115 struct device *d = decode_device (device); 120 struct device *d = decode_device (device);
116 #endif 121 #endif
117 struct gcpro gcpro1; 122 struct gcpro gcpro1;
118 123
119 CHECK_STRING (file); 124 CHECK_STRING (file);
145 signal_continuable_error (Qfile_error, 150 signal_continuable_error (Qfile_error,
146 "File is unreadable", file); 151 "File is unreadable", file);
147 } 152 }
148 } 153 }
149 UNGCPRO; 154 UNGCPRO;
155
156 #ifdef HAVE_ALSA_SOUND
157 if (DEVICE_CONNECTED_TO_ALSA_P (d))
158 {
159 Extbyte *fileext;
160
161 LISP_STRING_TO_EXTERNAL (file, fileext, Qfile_name);
162 /* #### ALSA code should allow specification of a device. */
163 if (alsa_play_sound_file (fileext, vol))
164 return Qnil;
165 }
166 #endif
150 167
151 #ifdef HAVE_NAS_SOUND 168 #ifdef HAVE_NAS_SOUND
152 if (DEVICE_CONNECTED_TO_NAS_P (d)) 169 if (DEVICE_CONNECTED_TO_NAS_P (d))
153 { 170 {
154 Extbyte *fileext; 171 Extbyte *fileext;
353 370
354 vol = (INT_OR_FLOATP (volume) ? (int) XFLOATINT (volume) : bell_volume); 371 vol = (INT_OR_FLOATP (volume) ? (int) XFLOATINT (volume) : bell_volume);
355 pit = (INT_OR_FLOATP (pitch) ? (int) XFLOATINT (pitch) : -1); 372 pit = (INT_OR_FLOATP (pitch) ? (int) XFLOATINT (pitch) : -1);
356 dur = (INT_OR_FLOATP (duration) ? (int) XFLOATINT (duration) : -1); 373 dur = (INT_OR_FLOATP (duration) ? (int) XFLOATINT (duration) : -1);
357 374
358 /* If the sound is a string, and we're connected to Nas, do that. 375 /* If the sound is a string, and we're connected to ALSA, NAS, or ESD, do
359 Else if the sound is a string, and we're on console, play it natively. 376 that. Else if the sound is a string, and we're on console, play it
360 Else just beep. 377 natively. Else just beep.
361 */ 378 */
379 #ifdef HAVE_ALSA_SOUND
380 if (DEVICE_CONNECTED_TO_ALSA_P (d) && STRINGP (sound))
381 {
382 Binbyte *soundext;
383 Bytecount soundextlen;
384
385 TO_EXTERNAL_FORMAT (LISP_STRING, sound,
386 ALLOCA, (soundext, soundextlen),
387 Qbinary);
388 if (alsa_play_sound_data (soundext, soundextlen, vol))
389 return Qnil;
390 }
391 #endif /* HAVE_ALSA_SOUND */
392
362 #ifdef HAVE_NAS_SOUND 393 #ifdef HAVE_NAS_SOUND
363 if (DEVICE_CONNECTED_TO_NAS_P (d) && STRINGP (sound)) 394 if (DEVICE_CONNECTED_TO_NAS_P (d) && STRINGP (sound))
364 { 395 {
365 Binbyte *soundext; 396 Binbyte *soundext;
366 Bytecount soundextlen; 397 Bytecount soundextlen;
421 DEFUN ("device-sound-enabled-p", Fdevice_sound_enabled_p, 0, 1, 0, /* 452 DEFUN ("device-sound-enabled-p", Fdevice_sound_enabled_p, 0, 1, 0, /*
422 Return t if DEVICE is able to play sound. Defaults to selected device. 453 Return t if DEVICE is able to play sound. Defaults to selected device.
423 */ 454 */
424 (USED_IF_HAVE_NATIVE_OR_NAS (device))) 455 (USED_IF_HAVE_NATIVE_OR_NAS (device)))
425 { 456 {
457 #ifdef HAVE_ALSA_SOUND
458 if (DEVICE_CONNECTED_TO_ALSA_P (decode_device (device)))
459 return Qt;
460 #endif
426 #ifdef HAVE_NAS_SOUND 461 #ifdef HAVE_NAS_SOUND
427 if (DEVICE_CONNECTED_TO_NAS_P (decode_device (device))) 462 if (DEVICE_CONNECTED_TO_NAS_P (decode_device (device)))
428 return Qt; 463 return Qt;
429 #endif 464 #endif
430 #ifdef HAVE_NATIVE_SOUND 465 #ifdef HAVE_NATIVE_SOUND
553 #ifdef HAVE_NATIVE_SOUND 588 #ifdef HAVE_NATIVE_SOUND
554 589
555 static void 590 static void
556 init_native_sound (struct device *d) 591 init_native_sound (struct device *d)
557 { 592 {
558 if (DEVICE_TTY_P (d) || DEVICE_STREAM_P (d) || DEVICE_MSWINDOWS_P(d)) 593 if (!(DEVICE_X_P(d) || DEVICE_GTK_P(d)))
559 DEVICE_ON_CONSOLE_P (d) = 1; 594 DEVICE_ON_CONSOLE_P (d) = 1;
560 #ifdef HAVE_X_WINDOWS 595 #ifdef HAVE_X_WINDOWS
561 else 596 else
562 { 597 {
563 /* When running on a machine with native sound support, we cannot use 598 /* When running on a machine with native sound support, we cannot use
603 struct hostent *h = gethostbyname (dpyname); 638 struct hostent *h = gethostbyname (dpyname);
604 if (!h) 639 if (!h)
605 DEVICE_ON_CONSOLE_P (d) = 0; 640 DEVICE_ON_CONSOLE_P (d) = 0;
606 else 641 else
607 { 642 {
608 Extbyte hn [255]; 643 Extbyte *hn = alloca_array (Extbyte, strlen (h->h_name) + 1);
609 struct hostent *l; 644 struct hostent *l;
610 strcpy (hn, h->h_name); 645 strcpy (hn, h->h_name);
611 l = gethostbyname (localname); 646 l = gethostbyname (localname);
612 DEVICE_ON_CONSOLE_P (d) = (l && !(strcmp (l->h_name, hn))); 647 DEVICE_ON_CONSOLE_P (d) = (l && !(strcmp (l->h_name, hn)));
613 } 648 }
652 687
653 688
654 void 689 void
655 vars_of_sound (void) 690 vars_of_sound (void)
656 { 691 {
692 #ifdef HAVE_ALSA_SOUND
693 Fprovide (intern ("alsa-sound"));
694 #endif
657 #ifdef HAVE_NATIVE_SOUND 695 #ifdef HAVE_NATIVE_SOUND
658 Fprovide (intern ("native-sound")); 696 Fprovide (intern ("native-sound"));
659 #endif 697 #endif
660 #ifdef HAVE_NAS_SOUND 698 #ifdef HAVE_NAS_SOUND
661 Fprovide (intern ("nas-sound")); 699 Fprovide (intern ("nas-sound"));