comparison src/sound.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 8efd647ea9ca
children 57709be46d1b
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
34 34
35 #include "commands.h" 35 #include "commands.h"
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
40 #ifdef HAVE_UNISTD_H
41 #include <unistd.h>
42 #endif
39 43
40 #ifdef HAVE_NATIVE_SOUND 44 #ifdef HAVE_NATIVE_SOUND
41 # include <netdb.h> 45 # include <netdb.h>
42 #endif 46 #endif
43 47
62 Lisp_Object Qnas; 66 Lisp_Object Qnas;
63 #endif 67 #endif
64 68
65 DEFUN ("play-sound-file", Fplay_sound_file, 1, 3, "fSound file name: ", /* 69 DEFUN ("play-sound-file", Fplay_sound_file, 1, 3, "fSound file name: ", /*
66 Play the named sound file on DEVICE's speaker at the specified volume 70 Play the named sound file on DEVICE's speaker at the specified volume
67 (0-100, default specified by the `bell-volume' variable). 71 \(0-100, default specified by the `bell-volume' variable).
68 The sound file must be in the Sun/NeXT U-LAW format except under Linux 72 The sound file must be in the Sun/NeXT U-LAW format except under Linux
69 where WAV files are also supported. 73 where WAV files are also supported.
70 DEVICE defaults to the selected device. 74 DEVICE defaults to the selected device.
71 */ 75 */
72 (file, volume, device)) 76 (file, volume, device))
273 loop_count = 0; 277 loop_count = 0;
274 sound = Qdefault; 278 sound = Qdefault;
275 goto try_it_again; 279 goto try_it_again;
276 } 280 }
277 281
278 282
279 vol = (INT_OR_FLOATP (volume) ? XFLOATINT (volume) : bell_volume); 283 vol = (INT_OR_FLOATP (volume) ? (int) XFLOATINT (volume) : bell_volume);
280 pit = (INT_OR_FLOATP (pitch) ? XFLOATINT (pitch) : -1); 284 pit = (INT_OR_FLOATP (pitch) ? (int) XFLOATINT (pitch) : -1);
281 dur = (INT_OR_FLOATP (duration) ? XFLOATINT (duration) : -1); 285 dur = (INT_OR_FLOATP (duration) ? (int) XFLOATINT (duration) : -1);
282 286
283 /* If the sound is a string, and we're connected to Nas, do that. 287 /* If the sound is a string, and we're connected to Nas, do that.
284 Else if the sound is a string, and we're on console, play it natively. 288 Else if the sound is a string, and we're on console, play it natively.
285 Else just beep. 289 Else just beep.
286 */ 290 */
289 { 293 {
290 CONST Extbyte *soundext; 294 CONST Extbyte *soundext;
291 Extcount soundextlen; 295 Extcount soundextlen;
292 296
293 GET_STRING_BINARY_DATA_ALLOCA (sound, soundext, soundextlen); 297 GET_STRING_BINARY_DATA_ALLOCA (sound, soundext, soundextlen);
294 if (nas_play_sound_data ((char*)soundext, soundextlen, vol)) 298 if (nas_play_sound_data ((unsigned char*)soundext, soundextlen, vol))
295 return Qnil; 299 return Qnil;
296 } 300 }
297 #endif /* HAVE_NAS_SOUND */ 301 #endif /* HAVE_NAS_SOUND */
298 302
299 #ifdef HAVE_NATIVE_SOUND 303 #ifdef HAVE_NATIVE_SOUND
304 Extcount soundextlen; 308 Extcount soundextlen;
305 309
306 GET_STRING_BINARY_DATA_ALLOCA (sound, soundext, soundextlen); 310 GET_STRING_BINARY_DATA_ALLOCA (sound, soundext, soundextlen);
307 /* The sound code doesn't like getting SIGIO interrupts. Unix sucks! */ 311 /* The sound code doesn't like getting SIGIO interrupts. Unix sucks! */
308 stop_interrupts (); 312 stop_interrupts ();
309 play_sound_data ((char*)soundext, soundextlen, vol); 313 play_sound_data ((unsigned char*)soundext, soundextlen, vol);
310 start_interrupts (); 314 start_interrupts ();
311 QUIT; 315 QUIT;
312 return Qnil; 316 return Qnil;
313 } 317 }
314 #endif /* HAVE_NATIVE_SOUND */ 318 #endif /* HAVE_NATIVE_SOUND */
316 DEVMETH (d, ring_bell, (d, vol, pit, dur)); 320 DEVMETH (d, ring_bell, (d, vol, pit, dur));
317 return Qnil; 321 return Qnil;
318 } 322 }
319 323
320 DEFUN ("device-sound-enabled-p", Fdevice_sound_enabled_p, 0, 1, 0, /* 324 DEFUN ("device-sound-enabled-p", Fdevice_sound_enabled_p, 0, 1, 0, /*
321 Return T iff DEVICE is able to play sound. Defaults to selected device. 325 Return t if DEVICE is able to play sound. Defaults to selected device.
322 */ 326 */
323 (device)) 327 (device))
324 { 328 {
325 struct device *d = decode_device(device); 329 struct device *d = decode_device(device);
326 330
327 #ifdef HAVE_NAS_SOUND 331 #ifdef HAVE_NAS_SOUND
328 if ( DEVICE_CONNECTED_TO_NAS_P (d) ) 332 if (DEVICE_CONNECTED_TO_NAS_P (d))
329 return (Qt); 333 return Qt;
330 #endif 334 #endif
331 #ifdef HAVE_NATIVE_SOUND 335 #ifdef HAVE_NATIVE_SOUND
332 if ( DEVICE_ON_CONSOLE_P (d) ) 336 if (DEVICE_ON_CONSOLE_P (d))
333 return (Qt); 337 return Qt;
334 #endif 338 #endif
335 return Qnil; 339 return Qnil;
336 } 340 }
337 341
338 DEFUN ("ding", Fding, 0, 3, 0, /* 342 DEFUN ("ding", Fding, 0, 3, 0, /*
382 #endif 386 #endif
383 return Qnil; 387 return Qnil;
384 } 388 }
385 389
386 DEFUN ("connected-to-nas-p", Fconnected_to_nas_p, 0, 1, 0, /* 390 DEFUN ("connected-to-nas-p", Fconnected_to_nas_p, 0, 1, 0, /*
387 t if connected to NAS server for sounds on DEVICE. 391 Return t if connected to NAS server for sounds on DEVICE.
388 */ 392 */
389 (device)) 393 (device))
390 { 394 {
391 #ifdef HAVE_NAS_SOUND 395 #ifdef HAVE_NAS_SOUND
392 struct device *d = decode_device (device); 396 return DEVICE_CONNECTED_TO_NAS_P (decode_device (device)) ? Qt : Qnil;
393 if (DEVICE_CONNECTED_TO_NAS_P (d))
394 return Qt;
395 else
396 return Qnil;
397 #else 397 #else
398 return Qnil; 398 return Qnil;
399 #endif 399 #endif
400 } 400 }
401 #ifdef HAVE_NAS_SOUND 401 #ifdef HAVE_NAS_SOUND
458 /* We have to call gethostbyname() on the result of gethostname() 458 /* We have to call gethostbyname() on the result of gethostname()
459 because the two aren't guarenteed to be the same name for the 459 because the two aren't guarenteed to be the same name for the
460 same host: on some losing systems, one is a FQDN and the other 460 same host: on some losing systems, one is a FQDN and the other
461 is not. Here in the wide wonderful world of Unix it's rocket 461 is not. Here in the wide wonderful world of Unix it's rocket
462 science to obtain the local hostname in a portable fashion. 462 science to obtain the local hostname in a portable fashion.
463 463
464 And don't forget, gethostbyname() reuses the structure it 464 And don't forget, gethostbyname() reuses the structure it
465 returns, so we have to copy the fucker before calling it 465 returns, so we have to copy the fucker before calling it
466 again. 466 again.
467 467
468 Thank you master, may I have another. 468 Thank you master, may I have another.