Make building under stricter warning flags somewhat cleaner.
[bpt/emacs.git] / src / sound.c
1 /* sound.c -- sound support.
2 Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* Written by Gerd Moellmann <gerd@gnu.org>. Tested with Luigi's
21 driver on FreeBSD 2.2.7 with a SoundBlaster 16. */
22
23 /*
24 Modified by Ben Key <Bkey1@tampabay.rr.com> to add a partial
25 implementation of the play-sound specification for Windows.
26
27 Notes:
28 In the Windows implementation of play-sound-internal only the
29 :file and :volume keywords are supported. The :device keyword,
30 if present, is ignored. The :data keyword, if present, will
31 cause an error to be generated.
32
33 The Windows implementation of play-sound is implemented via the
34 Win32 API functions mciSendString, waveOutGetVolume, and
35 waveOutSetVolume which are exported by Winmm.dll.
36 */
37
38 #include <config.h>
39
40 #if defined HAVE_SOUND
41
42 /* BEGIN: Common Includes */
43 #include <fcntl.h>
44 #include <unistd.h>
45 #include <sys/types.h>
46 #include <errno.h>
47 #include <setjmp.h>
48 #include "lisp.h"
49 #include "dispextern.h"
50 #include "atimer.h"
51 #include <signal.h>
52 #include "syssignal.h"
53 /* END: Common Includes */
54
55
56 /* BEGIN: Non Windows Includes */
57 #ifndef WINDOWSNT
58
59 #ifndef MSDOS
60 #include <sys/ioctl.h>
61 #endif
62
63 /* FreeBSD has machine/soundcard.h. Voxware sound driver docs mention
64 sys/soundcard.h. So, let's try whatever's there. */
65
66 #ifdef HAVE_MACHINE_SOUNDCARD_H
67 #include <machine/soundcard.h>
68 #endif
69 #ifdef HAVE_SYS_SOUNDCARD_H
70 #include <sys/soundcard.h>
71 #endif
72 #ifdef HAVE_SOUNDCARD_H
73 #include <soundcard.h>
74 #endif
75 #ifdef HAVE_ALSA
76 #ifdef ALSA_SUBDIR_INCLUDE
77 #include <alsa/asoundlib.h>
78 #else
79 #include <asoundlib.h>
80 #endif /* ALSA_SUBDIR_INCLUDE */
81 #endif /* HAVE_ALSA */
82
83 /* END: Non Windows Includes */
84
85 #else /* WINDOWSNT */
86
87 /* BEGIN: Windows Specific Includes */
88 #include <stdio.h>
89 #include <stdlib.h>
90 #include <string.h>
91 #include <limits.h>
92 #include <windows.h>
93 #include <mmsystem.h>
94 /* END: Windows Specific Includes */
95
96 #endif /* WINDOWSNT */
97
98 /* BEGIN: Common Definitions */
99
100 /* Symbols. */
101
102 extern Lisp_Object QCfile, QCdata;
103 Lisp_Object QCvolume, QCdevice;
104 Lisp_Object Qsound;
105 Lisp_Object Qplay_sound_functions;
106
107 /* Indices of attributes in a sound attributes vector. */
108
109 enum sound_attr
110 {
111 SOUND_FILE,
112 SOUND_DATA,
113 SOUND_DEVICE,
114 SOUND_VOLUME,
115 SOUND_ATTR_SENTINEL
116 };
117
118 #ifdef HAVE_ALSA
119 static void alsa_sound_perror (char *, int) NO_RETURN;
120 #endif
121 static void sound_perror (char *) NO_RETURN;
122 static void sound_warning (char *);
123 static int parse_sound (Lisp_Object, Lisp_Object *);
124
125 /* END: Common Definitions */
126
127 /* BEGIN: Non Windows Definitions */
128 #ifndef WINDOWSNT
129
130 #ifndef DEFAULT_SOUND_DEVICE
131 #define DEFAULT_SOUND_DEVICE "/dev/dsp"
132 #endif
133 #ifndef DEFAULT_ALSA_SOUND_DEVICE
134 #define DEFAULT_ALSA_SOUND_DEVICE "default"
135 #endif
136
137
138 /* Structure forward declarations. */
139
140 struct sound;
141 struct sound_device;
142
143 /* The file header of RIFF-WAVE files (*.wav). Files are always in
144 little-endian byte-order. */
145
146 struct wav_header
147 {
148 u_int32_t magic;
149 u_int32_t length;
150 u_int32_t chunk_type;
151 u_int32_t chunk_format;
152 u_int32_t chunk_length;
153 u_int16_t format;
154 u_int16_t channels;
155 u_int32_t sample_rate;
156 u_int32_t bytes_per_second;
157 u_int16_t sample_size;
158 u_int16_t precision;
159 u_int32_t chunk_data;
160 u_int32_t data_length;
161 };
162
163 /* The file header of Sun adio files (*.au). Files are always in
164 big-endian byte-order. */
165
166 struct au_header
167 {
168 /* ASCII ".snd" */
169 u_int32_t magic_number;
170
171 /* Offset of data part from start of file. Minimum value is 24. */
172 u_int32_t data_offset;
173
174 /* Size of data part, 0xffffffff if unknown. */
175 u_int32_t data_size;
176
177 /* Data encoding format.
178 1 8-bit ISDN u-law
179 2 8-bit linear PCM (REF-PCM)
180 3 16-bit linear PCM
181 4 24-bit linear PCM
182 5 32-bit linear PCM
183 6 32-bit IEEE floating-point
184 7 64-bit IEEE floating-point
185 23 8-bit u-law compressed using CCITT 0.721 ADPCM voice data
186 encoding scheme. */
187 u_int32_t encoding;
188
189 /* Number of samples per second. */
190 u_int32_t sample_rate;
191
192 /* Number of interleaved channels. */
193 u_int32_t channels;
194 };
195
196 /* Maximum of all sound file headers sizes. */
197
198 #define MAX_SOUND_HEADER_BYTES \
199 max (sizeof (struct wav_header), sizeof (struct au_header))
200
201 /* Interface structure for sound devices. */
202
203 struct sound_device
204 {
205 /* The name of the device or null meaning use a default device name. */
206 char *file;
207
208 /* File descriptor of the device. */
209 int fd;
210
211 /* Device-dependent format. */
212 int format;
213
214 /* Volume (0..100). Zero means unspecified. */
215 int volume;
216
217 /* Sample size. */
218 int sample_size;
219
220 /* Sample rate. */
221 int sample_rate;
222
223 /* Bytes per second. */
224 int bps;
225
226 /* 1 = mono, 2 = stereo, 0 = don't set. */
227 int channels;
228
229 /* Open device SD. */
230 void (* open) (struct sound_device *sd);
231
232 /* Close device SD. */
233 void (* close) (struct sound_device *sd);
234
235 /* Configure SD accoring to device-dependent parameters. */
236 void (* configure) (struct sound_device *device);
237
238 /* Choose a device-dependent format for outputting sound S. */
239 void (* choose_format) (struct sound_device *sd,
240 struct sound *s);
241
242 /* Return a preferred data size in bytes to be sent to write (below)
243 each time. 2048 is used if this is NULL. */
244 int (* period_size) (struct sound_device *sd);
245
246 /* Write NYBTES bytes from BUFFER to device SD. */
247 void (* write) (struct sound_device *sd, const char *buffer,
248 int nbytes);
249
250 /* A place for devices to store additional data. */
251 void *data;
252 };
253
254 /* An enumerator for each supported sound file type. */
255
256 enum sound_type
257 {
258 RIFF,
259 SUN_AUDIO
260 };
261
262 /* Interface structure for sound files. */
263
264 struct sound
265 {
266 /* The type of the file. */
267 enum sound_type type;
268
269 /* File descriptor of a sound file. */
270 int fd;
271
272 /* Pointer to sound file header. This contains header_size bytes
273 read from the start of a sound file. */
274 char *header;
275
276 /* Number of bytes raed from sound file. This is always <=
277 MAX_SOUND_HEADER_BYTES. */
278 int header_size;
279
280 /* Sound data, if a string. */
281 Lisp_Object data;
282
283 /* Play sound file S on device SD. */
284 void (* play) (struct sound *s, struct sound_device *sd);
285 };
286
287 /* These are set during `play-sound-internal' so that sound_cleanup has
288 access to them. */
289
290 struct sound_device *current_sound_device;
291 struct sound *current_sound;
292
293 /* Function prototypes. */
294
295 static void vox_open (struct sound_device *);
296 static void vox_configure (struct sound_device *);
297 static void vox_close (struct sound_device *sd);
298 static void vox_choose_format (struct sound_device *, struct sound *);
299 static int vox_init (struct sound_device *);
300 static void vox_write (struct sound_device *, const char *, int);
301 static void find_sound_type (struct sound *);
302 static u_int32_t le2hl (u_int32_t);
303 static u_int16_t le2hs (u_int16_t);
304 static u_int32_t be2hl (u_int32_t);
305 static int wav_init (struct sound *);
306 static void wav_play (struct sound *, struct sound_device *);
307 static int au_init (struct sound *);
308 static void au_play (struct sound *, struct sound_device *);
309
310 #if 0 /* Currently not used. */
311 static u_int16_t be2hs (u_int16_t);
312 #endif
313
314 /* END: Non Windows Definitions */
315 #else /* WINDOWSNT */
316
317 /* BEGIN: Windows Specific Definitions */
318 static int do_play_sound (const char *, unsigned long);
319 /*
320 END: Windows Specific Definitions */
321 #endif /* WINDOWSNT */
322
323 \f
324 /***********************************************************************
325 General
326 ***********************************************************************/
327
328 /* BEGIN: Common functions */
329
330 /* Like perror, but signals an error. */
331
332 static void
333 sound_perror (char *msg)
334 {
335 int saved_errno = errno;
336
337 turn_on_atimers (1);
338 #ifdef SIGIO
339 sigunblock (sigmask (SIGIO));
340 #endif
341 if (saved_errno != 0)
342 error ("%s: %s", msg, strerror (saved_errno));
343 else
344 error ("%s", msg);
345 }
346
347
348 /* Display a warning message. */
349
350 static void
351 sound_warning (char *msg)
352 {
353 message (msg);
354 }
355
356
357 /* Parse sound specification SOUND, and fill ATTRS with what is
358 found. Value is non-zero if SOUND Is a valid sound specification.
359 A valid sound specification is a list starting with the symbol
360 `sound'. The rest of the list is a property list which may
361 contain the following key/value pairs:
362
363 - `:file FILE'
364
365 FILE is the sound file to play. If it isn't an absolute name,
366 it's searched under `data-directory'.
367
368 - `:data DATA'
369
370 DATA is a string containing sound data. Either :file or :data
371 may be present, but not both.
372
373 - `:device DEVICE'
374
375 DEVICE is the name of the device to play on, e.g. "/dev/dsp2".
376 If not specified, a default device is used.
377
378 - `:volume VOL'
379
380 VOL must be an integer in the range [0, 100], or a float in the
381 range [0, 1]. */
382
383 static int
384 parse_sound (Lisp_Object sound, Lisp_Object *attrs)
385 {
386 /* SOUND must be a list starting with the symbol `sound'. */
387 if (!CONSP (sound) || !EQ (XCAR (sound), Qsound))
388 return 0;
389
390 sound = XCDR (sound);
391 attrs[SOUND_FILE] = Fplist_get (sound, QCfile);
392 attrs[SOUND_DATA] = Fplist_get (sound, QCdata);
393 attrs[SOUND_DEVICE] = Fplist_get (sound, QCdevice);
394 attrs[SOUND_VOLUME] = Fplist_get (sound, QCvolume);
395
396 #ifndef WINDOWSNT
397 /* File name or data must be specified. */
398 if (!STRINGP (attrs[SOUND_FILE])
399 && !STRINGP (attrs[SOUND_DATA]))
400 return 0;
401 #else /* WINDOWSNT */
402 /*
403 Data is not supported in Windows. Therefore a
404 File name MUST be supplied.
405 */
406 if (!STRINGP (attrs[SOUND_FILE]))
407 {
408 return 0;
409 }
410 #endif /* WINDOWSNT */
411
412 /* Volume must be in the range 0..100 or unspecified. */
413 if (!NILP (attrs[SOUND_VOLUME]))
414 {
415 if (INTEGERP (attrs[SOUND_VOLUME]))
416 {
417 if (XINT (attrs[SOUND_VOLUME]) < 0
418 || XINT (attrs[SOUND_VOLUME]) > 100)
419 return 0;
420 }
421 else if (FLOATP (attrs[SOUND_VOLUME]))
422 {
423 if (XFLOAT_DATA (attrs[SOUND_VOLUME]) < 0
424 || XFLOAT_DATA (attrs[SOUND_VOLUME]) > 1)
425 return 0;
426 }
427 else
428 return 0;
429 }
430
431 #ifndef WINDOWSNT
432 /* Device must be a string or unspecified. */
433 if (!NILP (attrs[SOUND_DEVICE])
434 && !STRINGP (attrs[SOUND_DEVICE]))
435 return 0;
436 #endif /* WINDOWSNT */
437 /*
438 Since device is ignored in Windows, it does not matter
439 what it is.
440 */
441 return 1;
442 }
443
444 /* END: Common functions */
445
446 /* BEGIN: Non Windows functions */
447 #ifndef WINDOWSNT
448
449 /* Find out the type of the sound file whose file descriptor is FD.
450 S is the sound file structure to fill in. */
451
452 static void
453 find_sound_type (struct sound *s)
454 {
455 if (!wav_init (s) && !au_init (s))
456 error ("Unknown sound format");
457 }
458
459
460 /* Function installed by play-sound-internal with record_unwind_protect. */
461
462 static Lisp_Object
463 sound_cleanup (Lisp_Object arg)
464 {
465 if (current_sound_device->close)
466 current_sound_device->close (current_sound_device);
467 if (current_sound->fd > 0)
468 emacs_close (current_sound->fd);
469 free (current_sound_device);
470 free (current_sound);
471
472 return Qnil;
473 }
474
475 /***********************************************************************
476 Byte-order Conversion
477 ***********************************************************************/
478
479 /* Convert 32-bit value VALUE which is in little-endian byte-order
480 to host byte-order. */
481
482 static u_int32_t
483 le2hl (u_int32_t value)
484 {
485 #ifdef WORDS_BIG_ENDIAN
486 unsigned char *p = (unsigned char *) &value;
487 value = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
488 #endif
489 return value;
490 }
491
492
493 /* Convert 16-bit value VALUE which is in little-endian byte-order
494 to host byte-order. */
495
496 static u_int16_t
497 le2hs (u_int16_t value)
498 {
499 #ifdef WORDS_BIG_ENDIAN
500 unsigned char *p = (unsigned char *) &value;
501 value = p[0] + (p[1] << 8);
502 #endif
503 return value;
504 }
505
506
507 /* Convert 32-bit value VALUE which is in big-endian byte-order
508 to host byte-order. */
509
510 static u_int32_t
511 be2hl (u_int32_t value)
512 {
513 #ifndef WORDS_BIG_ENDIAN
514 unsigned char *p = (unsigned char *) &value;
515 value = p[3] + (p[2] << 8) + (p[1] << 16) + (p[0] << 24);
516 #endif
517 return value;
518 }
519
520
521 #if 0 /* Currently not used. */
522
523 /* Convert 16-bit value VALUE which is in big-endian byte-order
524 to host byte-order. */
525
526 static u_int16_t
527 be2hs (u_int16_t value)
528 {
529 #ifndef WORDS_BIG_ENDIAN
530 unsigned char *p = (unsigned char *) &value;
531 value = p[1] + (p[0] << 8);
532 #endif
533 return value;
534 }
535
536 #endif /* 0 */
537
538 /***********************************************************************
539 RIFF-WAVE (*.wav)
540 ***********************************************************************/
541
542 /* Try to initialize sound file S from S->header. S->header
543 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the
544 sound file. If the file is a WAV-format file, set up interface
545 functions in S and convert header fields to host byte-order.
546 Value is non-zero if the file is a WAV file. */
547
548 static int
549 wav_init (struct sound *s)
550 {
551 struct wav_header *header = (struct wav_header *) s->header;
552
553 if (s->header_size < sizeof *header
554 || memcmp (s->header, "RIFF", 4) != 0)
555 return 0;
556
557 /* WAV files are in little-endian order. Convert the header
558 if on a big-endian machine. */
559 header->magic = le2hl (header->magic);
560 header->length = le2hl (header->length);
561 header->chunk_type = le2hl (header->chunk_type);
562 header->chunk_format = le2hl (header->chunk_format);
563 header->chunk_length = le2hl (header->chunk_length);
564 header->format = le2hs (header->format);
565 header->channels = le2hs (header->channels);
566 header->sample_rate = le2hl (header->sample_rate);
567 header->bytes_per_second = le2hl (header->bytes_per_second);
568 header->sample_size = le2hs (header->sample_size);
569 header->precision = le2hs (header->precision);
570 header->chunk_data = le2hl (header->chunk_data);
571 header->data_length = le2hl (header->data_length);
572
573 /* Set up the interface functions for WAV. */
574 s->type = RIFF;
575 s->play = wav_play;
576
577 return 1;
578 }
579
580
581 /* Play RIFF-WAVE audio file S on sound device SD. */
582
583 static void
584 wav_play (struct sound *s, struct sound_device *sd)
585 {
586 struct wav_header *header = (struct wav_header *) s->header;
587
588 /* Let the device choose a suitable device-dependent format
589 for the file. */
590 sd->choose_format (sd, s);
591
592 /* Configure the device. */
593 sd->sample_size = header->sample_size;
594 sd->sample_rate = header->sample_rate;
595 sd->bps = header->bytes_per_second;
596 sd->channels = header->channels;
597 sd->configure (sd);
598
599 /* Copy sound data to the device. The WAV file specification is
600 actually more complex. This simple scheme worked with all WAV
601 files I found so far. If someone feels inclined to implement the
602 whole RIFF-WAVE spec, please do. */
603 if (STRINGP (s->data))
604 sd->write (sd, SDATA (s->data) + sizeof *header,
605 SBYTES (s->data) - sizeof *header);
606 else
607 {
608 char *buffer;
609 int nbytes;
610 int blksize = sd->period_size ? sd->period_size (sd) : 2048;
611 int data_left = header->data_length;
612
613 buffer = (char *) alloca (blksize);
614 lseek (s->fd, sizeof *header, SEEK_SET);
615 while (data_left > 0
616 && (nbytes = emacs_read (s->fd, buffer, blksize)) > 0)
617 {
618 /* Don't play possible garbage at the end of file */
619 if (data_left < nbytes) nbytes = data_left;
620 data_left -= nbytes;
621 sd->write (sd, buffer, nbytes);
622 }
623
624 if (nbytes < 0)
625 sound_perror ("Error reading sound file");
626 }
627 }
628
629
630 /***********************************************************************
631 Sun Audio (*.au)
632 ***********************************************************************/
633
634 /* Sun audio file encodings. */
635
636 enum au_encoding
637 {
638 AU_ENCODING_ULAW_8 = 1,
639 AU_ENCODING_8,
640 AU_ENCODING_16,
641 AU_ENCODING_24,
642 AU_ENCODING_32,
643 AU_ENCODING_IEEE32,
644 AU_ENCODING_IEEE64,
645 AU_COMPRESSED = 23,
646 AU_ENCODING_ALAW_8 = 27
647 };
648
649
650 /* Try to initialize sound file S from S->header. S->header
651 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the
652 sound file. If the file is a AU-format file, set up interface
653 functions in S and convert header fields to host byte-order.
654 Value is non-zero if the file is an AU file. */
655
656 static int
657 au_init (struct sound *s)
658 {
659 struct au_header *header = (struct au_header *) s->header;
660
661 if (s->header_size < sizeof *header
662 || memcmp (s->header, ".snd", 4) != 0)
663 return 0;
664
665 header->magic_number = be2hl (header->magic_number);
666 header->data_offset = be2hl (header->data_offset);
667 header->data_size = be2hl (header->data_size);
668 header->encoding = be2hl (header->encoding);
669 header->sample_rate = be2hl (header->sample_rate);
670 header->channels = be2hl (header->channels);
671
672 /* Set up the interface functions for AU. */
673 s->type = SUN_AUDIO;
674 s->play = au_play;
675
676 return 1;
677 }
678
679
680 /* Play Sun audio file S on sound device SD. */
681
682 static void
683 au_play (struct sound *s, struct sound_device *sd)
684 {
685 struct au_header *header = (struct au_header *) s->header;
686
687 sd->sample_size = 0;
688 sd->sample_rate = header->sample_rate;
689 sd->bps = 0;
690 sd->channels = header->channels;
691 sd->choose_format (sd, s);
692 sd->configure (sd);
693
694 if (STRINGP (s->data))
695 sd->write (sd, SDATA (s->data) + header->data_offset,
696 SBYTES (s->data) - header->data_offset);
697 else
698 {
699 int blksize = sd->period_size ? sd->period_size (sd) : 2048;
700 char *buffer;
701 int nbytes;
702
703 /* Seek */
704 lseek (s->fd, header->data_offset, SEEK_SET);
705
706 /* Copy sound data to the device. */
707 buffer = (char *) alloca (blksize);
708 while ((nbytes = emacs_read (s->fd, buffer, blksize)) > 0)
709 sd->write (sd, buffer, nbytes);
710
711 if (nbytes < 0)
712 sound_perror ("Error reading sound file");
713 }
714 }
715
716
717 /***********************************************************************
718 Voxware Driver Interface
719 ***********************************************************************/
720
721 /* This driver is available on GNU/Linux, and the free BSDs. FreeBSD
722 has a compatible own driver aka Luigi's driver. */
723
724
725 /* Open device SD. If SD->file is non-null, open that device,
726 otherwise use a default device name. */
727
728 static void
729 vox_open (struct sound_device *sd)
730 {
731 char *file;
732
733 /* Open the sound device. Default is /dev/dsp. */
734 if (sd->file)
735 file = sd->file;
736 else
737 file = DEFAULT_SOUND_DEVICE;
738
739 sd->fd = emacs_open (file, O_WRONLY, 0);
740 if (sd->fd < 0)
741 sound_perror (file);
742 }
743
744
745 /* Configure device SD from parameters in it. */
746
747 static void
748 vox_configure (struct sound_device *sd)
749 {
750 int val;
751
752 xassert (sd->fd >= 0);
753
754 /* On GNU/Linux, it seems that the device driver doesn't like to be
755 interrupted by a signal. Block the ones we know to cause
756 troubles. */
757 turn_on_atimers (0);
758 #ifdef SIGIO
759 sigblock (sigmask (SIGIO));
760 #endif
761
762 val = sd->format;
763 if (ioctl (sd->fd, SNDCTL_DSP_SETFMT, &sd->format) < 0
764 || val != sd->format)
765 sound_perror ("Could not set sound format");
766
767 val = sd->channels != 1;
768 if (ioctl (sd->fd, SNDCTL_DSP_STEREO, &val) < 0
769 || val != (sd->channels != 1))
770 sound_perror ("Could not set stereo/mono");
771
772 /* I think bps and sampling_rate are the same, but who knows.
773 Check this. and use SND_DSP_SPEED for both. */
774 if (sd->sample_rate > 0)
775 {
776 val = sd->sample_rate;
777 if (ioctl (sd->fd, SNDCTL_DSP_SPEED, &sd->sample_rate) < 0)
778 sound_perror ("Could not set sound speed");
779 else if (val != sd->sample_rate)
780 sound_warning ("Could not set sample rate");
781 }
782
783 if (sd->volume > 0)
784 {
785 int volume = sd->volume & 0xff;
786 volume |= volume << 8;
787 /* This may fail if there is no mixer. Ignore the failure. */
788 ioctl (sd->fd, SOUND_MIXER_WRITE_PCM, &volume);
789 }
790
791 turn_on_atimers (1);
792 #ifdef SIGIO
793 sigunblock (sigmask (SIGIO));
794 #endif
795 }
796
797
798 /* Close device SD if it is open. */
799
800 static void
801 vox_close (struct sound_device *sd)
802 {
803 if (sd->fd >= 0)
804 {
805 /* On GNU/Linux, it seems that the device driver doesn't like to
806 be interrupted by a signal. Block the ones we know to cause
807 troubles. */
808 #ifdef SIGIO
809 sigblock (sigmask (SIGIO));
810 #endif
811 turn_on_atimers (0);
812
813 /* Flush sound data, and reset the device. */
814 ioctl (sd->fd, SNDCTL_DSP_SYNC, NULL);
815
816 turn_on_atimers (1);
817 #ifdef SIGIO
818 sigunblock (sigmask (SIGIO));
819 #endif
820
821 /* Close the device. */
822 emacs_close (sd->fd);
823 sd->fd = -1;
824 }
825 }
826
827
828 /* Choose device-dependent format for device SD from sound file S. */
829
830 static void
831 vox_choose_format (struct sound_device *sd, struct sound *s)
832 {
833 if (s->type == RIFF)
834 {
835 struct wav_header *h = (struct wav_header *) s->header;
836 if (h->precision == 8)
837 sd->format = AFMT_U8;
838 else if (h->precision == 16)
839 sd->format = AFMT_S16_LE;
840 else
841 error ("Unsupported WAV file format");
842 }
843 else if (s->type == SUN_AUDIO)
844 {
845 struct au_header *header = (struct au_header *) s->header;
846 switch (header->encoding)
847 {
848 case AU_ENCODING_ULAW_8:
849 case AU_ENCODING_IEEE32:
850 case AU_ENCODING_IEEE64:
851 sd->format = AFMT_MU_LAW;
852 break;
853
854 case AU_ENCODING_8:
855 case AU_ENCODING_16:
856 case AU_ENCODING_24:
857 case AU_ENCODING_32:
858 sd->format = AFMT_S16_LE;
859 break;
860
861 default:
862 error ("Unsupported AU file format");
863 }
864 }
865 else
866 abort ();
867 }
868
869
870 /* Initialize device SD. Set up the interface functions in the device
871 structure. */
872
873 static int
874 vox_init (struct sound_device *sd)
875 {
876 char *file;
877 int fd;
878
879 /* Open the sound device. Default is /dev/dsp. */
880 if (sd->file)
881 file = sd->file;
882 else
883 file = DEFAULT_SOUND_DEVICE;
884 fd = emacs_open (file, O_WRONLY, 0);
885 if (fd >= 0)
886 emacs_close (fd);
887 else
888 return 0;
889
890 sd->fd = -1;
891 sd->open = vox_open;
892 sd->close = vox_close;
893 sd->configure = vox_configure;
894 sd->choose_format = vox_choose_format;
895 sd->write = vox_write;
896 sd->period_size = NULL;
897
898 return 1;
899 }
900
901 /* Write NBYTES bytes from BUFFER to device SD. */
902
903 static void
904 vox_write (struct sound_device *sd, const char *buffer, int nbytes)
905 {
906 int nwritten = emacs_write (sd->fd, buffer, nbytes);
907 if (nwritten < 0)
908 sound_perror ("Error writing to sound device");
909 }
910
911 #ifdef HAVE_ALSA
912 /***********************************************************************
913 ALSA Driver Interface
914 ***********************************************************************/
915
916 /* This driver is available on GNU/Linux. */
917
918 static void
919 alsa_sound_perror (char *msg, int err)
920 {
921 error ("%s: %s", msg, snd_strerror (err));
922 }
923
924 struct alsa_params
925 {
926 snd_pcm_t *handle;
927 snd_pcm_hw_params_t *hwparams;
928 snd_pcm_sw_params_t *swparams;
929 snd_pcm_uframes_t period_size;
930 };
931
932 /* Open device SD. If SD->file is non-null, open that device,
933 otherwise use a default device name. */
934
935 static void
936 alsa_open (struct sound_device *sd)
937 {
938 char *file;
939 struct alsa_params *p;
940 int err;
941
942 /* Open the sound device. Default is "default". */
943 if (sd->file)
944 file = sd->file;
945 else
946 file = DEFAULT_ALSA_SOUND_DEVICE;
947
948 p = xmalloc (sizeof (*p));
949 p->handle = NULL;
950 p->hwparams = NULL;
951 p->swparams = NULL;
952
953 sd->fd = -1;
954 sd->data = p;
955
956
957 err = snd_pcm_open (&p->handle, file, SND_PCM_STREAM_PLAYBACK, 0);
958 if (err < 0)
959 alsa_sound_perror (file, err);
960 }
961
962 static int
963 alsa_period_size (struct sound_device *sd)
964 {
965 struct alsa_params *p = (struct alsa_params *) sd->data;
966 int fact = snd_pcm_format_size (sd->format, 1) * sd->channels;
967 return p->period_size * (fact > 0 ? fact : 1);
968 }
969
970 static void
971 alsa_configure (struct sound_device *sd)
972 {
973 int val, err, dir;
974 unsigned uval;
975 struct alsa_params *p = (struct alsa_params *) sd->data;
976 snd_pcm_uframes_t buffer_size;
977
978 xassert (p->handle != 0);
979
980 err = snd_pcm_hw_params_malloc (&p->hwparams);
981 if (err < 0)
982 alsa_sound_perror ("Could not allocate hardware parameter structure", err);
983
984 err = snd_pcm_sw_params_malloc (&p->swparams);
985 if (err < 0)
986 alsa_sound_perror ("Could not allocate software parameter structure", err);
987
988 err = snd_pcm_hw_params_any (p->handle, p->hwparams);
989 if (err < 0)
990 alsa_sound_perror ("Could not initialize hardware parameter structure", err);
991
992 err = snd_pcm_hw_params_set_access (p->handle, p->hwparams,
993 SND_PCM_ACCESS_RW_INTERLEAVED);
994 if (err < 0)
995 alsa_sound_perror ("Could not set access type", err);
996
997 val = sd->format;
998 err = snd_pcm_hw_params_set_format (p->handle, p->hwparams, val);
999 if (err < 0)
1000 alsa_sound_perror ("Could not set sound format", err);
1001
1002 uval = sd->sample_rate;
1003 err = snd_pcm_hw_params_set_rate_near (p->handle, p->hwparams, &uval, 0);
1004 if (err < 0)
1005 alsa_sound_perror ("Could not set sample rate", err);
1006
1007 val = sd->channels;
1008 err = snd_pcm_hw_params_set_channels (p->handle, p->hwparams, val);
1009 if (err < 0)
1010 alsa_sound_perror ("Could not set channel count", err);
1011
1012 err = snd_pcm_hw_params (p->handle, p->hwparams);
1013 if (err < 0)
1014 alsa_sound_perror ("Could not set parameters", err);
1015
1016
1017 err = snd_pcm_hw_params_get_period_size (p->hwparams, &p->period_size, &dir);
1018 if (err < 0)
1019 alsa_sound_perror ("Unable to get period size for playback", err);
1020
1021 err = snd_pcm_hw_params_get_buffer_size (p->hwparams, &buffer_size);
1022 if (err < 0)
1023 alsa_sound_perror("Unable to get buffer size for playback", err);
1024
1025 err = snd_pcm_sw_params_current (p->handle, p->swparams);
1026 if (err < 0)
1027 alsa_sound_perror ("Unable to determine current swparams for playback",
1028 err);
1029
1030 /* Start the transfer when the buffer is almost full */
1031 err = snd_pcm_sw_params_set_start_threshold (p->handle, p->swparams,
1032 (buffer_size / p->period_size)
1033 * p->period_size);
1034 if (err < 0)
1035 alsa_sound_perror ("Unable to set start threshold mode for playback", err);
1036
1037 /* Allow the transfer when at least period_size samples can be processed */
1038 err = snd_pcm_sw_params_set_avail_min (p->handle, p->swparams, p->period_size);
1039 if (err < 0)
1040 alsa_sound_perror ("Unable to set avail min for playback", err);
1041
1042 err = snd_pcm_sw_params (p->handle, p->swparams);
1043 if (err < 0)
1044 alsa_sound_perror ("Unable to set sw params for playback\n", err);
1045
1046 snd_pcm_hw_params_free (p->hwparams);
1047 p->hwparams = NULL;
1048 snd_pcm_sw_params_free (p->swparams);
1049 p->swparams = NULL;
1050
1051 err = snd_pcm_prepare (p->handle);
1052 if (err < 0)
1053 alsa_sound_perror ("Could not prepare audio interface for use", err);
1054
1055 if (sd->volume > 0)
1056 {
1057 int chn;
1058 snd_mixer_t *handle;
1059 snd_mixer_elem_t *e;
1060 char *file = sd->file ? sd->file : DEFAULT_ALSA_SOUND_DEVICE;
1061
1062 if (snd_mixer_open (&handle, 0) >= 0)
1063 {
1064 if (snd_mixer_attach (handle, file) >= 0
1065 && snd_mixer_load (handle) >= 0
1066 && snd_mixer_selem_register (handle, NULL, NULL) >= 0)
1067 for (e = snd_mixer_first_elem (handle);
1068 e;
1069 e = snd_mixer_elem_next (e))
1070 {
1071 if (snd_mixer_selem_has_playback_volume (e))
1072 {
1073 long pmin, pmax, vol;
1074 snd_mixer_selem_get_playback_volume_range (e, &pmin, &pmax);
1075 vol = pmin + (sd->volume * (pmax - pmin)) / 100;
1076
1077 for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++)
1078 snd_mixer_selem_set_playback_volume (e, chn, vol);
1079 }
1080 }
1081 snd_mixer_close(handle);
1082 }
1083 }
1084 }
1085
1086
1087 /* Close device SD if it is open. */
1088
1089 static void
1090 alsa_close (struct sound_device *sd)
1091 {
1092 struct alsa_params *p = (struct alsa_params *) sd->data;
1093 if (p)
1094 {
1095 if (p->hwparams)
1096 snd_pcm_hw_params_free (p->hwparams);
1097 if (p->swparams)
1098 snd_pcm_sw_params_free (p->swparams);
1099 if (p->handle)
1100 {
1101 snd_pcm_drain (p->handle);
1102 snd_pcm_close (p->handle);
1103 }
1104 free (p);
1105 }
1106 }
1107
1108 /* Choose device-dependent format for device SD from sound file S. */
1109
1110 static void
1111 alsa_choose_format (struct sound_device *sd, struct sound *s)
1112 {
1113 struct alsa_params *p = (struct alsa_params *) sd->data;
1114 if (s->type == RIFF)
1115 {
1116 struct wav_header *h = (struct wav_header *) s->header;
1117 if (h->precision == 8)
1118 sd->format = SND_PCM_FORMAT_U8;
1119 else if (h->precision == 16)
1120 sd->format = SND_PCM_FORMAT_S16_LE;
1121 else
1122 error ("Unsupported WAV file format");
1123 }
1124 else if (s->type == SUN_AUDIO)
1125 {
1126 struct au_header *header = (struct au_header *) s->header;
1127 switch (header->encoding)
1128 {
1129 case AU_ENCODING_ULAW_8:
1130 sd->format = SND_PCM_FORMAT_MU_LAW;
1131 break;
1132 case AU_ENCODING_ALAW_8:
1133 sd->format = SND_PCM_FORMAT_A_LAW;
1134 break;
1135 case AU_ENCODING_IEEE32:
1136 sd->format = SND_PCM_FORMAT_FLOAT_BE;
1137 break;
1138 case AU_ENCODING_IEEE64:
1139 sd->format = SND_PCM_FORMAT_FLOAT64_BE;
1140 break;
1141 case AU_ENCODING_8:
1142 sd->format = SND_PCM_FORMAT_S8;
1143 break;
1144 case AU_ENCODING_16:
1145 sd->format = SND_PCM_FORMAT_S16_BE;
1146 break;
1147 case AU_ENCODING_24:
1148 sd->format = SND_PCM_FORMAT_S24_BE;
1149 break;
1150 case AU_ENCODING_32:
1151 sd->format = SND_PCM_FORMAT_S32_BE;
1152 break;
1153
1154 default:
1155 error ("Unsupported AU file format");
1156 }
1157 }
1158 else
1159 abort ();
1160 }
1161
1162
1163 /* Write NBYTES bytes from BUFFER to device SD. */
1164
1165 static void
1166 alsa_write (struct sound_device *sd, const char *buffer, int nbytes)
1167 {
1168 struct alsa_params *p = (struct alsa_params *) sd->data;
1169
1170 /* The the third parameter to snd_pcm_writei is frames, not bytes. */
1171 int fact = snd_pcm_format_size (sd->format, 1) * sd->channels;
1172 int nwritten = 0;
1173 int err;
1174
1175 while (nwritten < nbytes)
1176 {
1177 snd_pcm_uframes_t frames = (nbytes - nwritten)/fact;
1178 if (frames == 0) break;
1179
1180 err = snd_pcm_writei (p->handle, buffer + nwritten, frames);
1181 if (err < 0)
1182 {
1183 if (err == -EPIPE)
1184 { /* under-run */
1185 err = snd_pcm_prepare (p->handle);
1186 if (err < 0)
1187 alsa_sound_perror ("Can't recover from underrun, prepare failed",
1188 err);
1189 }
1190 else if (err == -ESTRPIPE)
1191 {
1192 while ((err = snd_pcm_resume (p->handle)) == -EAGAIN)
1193 sleep(1); /* wait until the suspend flag is released */
1194 if (err < 0)
1195 {
1196 err = snd_pcm_prepare (p->handle);
1197 if (err < 0)
1198 alsa_sound_perror ("Can't recover from suspend, "
1199 "prepare failed",
1200 err);
1201 }
1202 }
1203 else
1204 alsa_sound_perror ("Error writing to sound device", err);
1205
1206 }
1207 else
1208 nwritten += err * fact;
1209 }
1210 }
1211
1212 static void
1213 snd_error_quiet (const char *file, int line, const char *function, int err,
1214 const char *fmt)
1215 {
1216 }
1217
1218 /* Initialize device SD. Set up the interface functions in the device
1219 structure. */
1220
1221 static int
1222 alsa_init (struct sound_device *sd)
1223 {
1224 char *file;
1225 snd_pcm_t *handle;
1226 int err;
1227
1228 /* Open the sound device. Default is "default". */
1229 if (sd->file)
1230 file = sd->file;
1231 else
1232 file = DEFAULT_ALSA_SOUND_DEVICE;
1233
1234 snd_lib_error_set_handler ((snd_lib_error_handler_t) snd_error_quiet);
1235 err = snd_pcm_open (&handle, file, SND_PCM_STREAM_PLAYBACK, 0);
1236 snd_lib_error_set_handler (NULL);
1237 if (err < 0)
1238 return 0;
1239 snd_pcm_close (handle);
1240
1241 sd->fd = -1;
1242 sd->open = alsa_open;
1243 sd->close = alsa_close;
1244 sd->configure = alsa_configure;
1245 sd->choose_format = alsa_choose_format;
1246 sd->write = alsa_write;
1247 sd->period_size = alsa_period_size;
1248
1249 return 1;
1250 }
1251
1252 #endif /* HAVE_ALSA */
1253
1254
1255 /* END: Non Windows functions */
1256 #else /* WINDOWSNT */
1257
1258 /* BEGIN: Windows specific functions */
1259
1260 #define SOUND_WARNING(fun, error, text) \
1261 { \
1262 char buf[1024]; \
1263 char err_string[MAXERRORLENGTH]; \
1264 fun (error, err_string, sizeof (err_string)); \
1265 _snprintf (buf, sizeof (buf), "%s\nError: %s", \
1266 text, err_string); \
1267 sound_warning (buf); \
1268 }
1269
1270 static int
1271 do_play_sound (const char *psz_file, unsigned long ui_volume)
1272 {
1273 int i_result = 0;
1274 MCIERROR mci_error = 0;
1275 char sz_cmd_buf[520] = {0};
1276 char sz_ret_buf[520] = {0};
1277 MMRESULT mm_result = MMSYSERR_NOERROR;
1278 unsigned long ui_volume_org = 0;
1279 BOOL b_reset_volume = FALSE;
1280
1281 memset (sz_cmd_buf, 0, sizeof (sz_cmd_buf));
1282 memset (sz_ret_buf, 0, sizeof (sz_ret_buf));
1283 sprintf (sz_cmd_buf,
1284 "open \"%s\" alias GNUEmacs_PlaySound_Device wait",
1285 psz_file);
1286 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, sizeof (sz_ret_buf), NULL);
1287 if (mci_error != 0)
1288 {
1289 SOUND_WARNING (mciGetErrorString, mci_error,
1290 "The open mciSendString command failed to open "
1291 "the specified sound file.");
1292 i_result = (int) mci_error;
1293 return i_result;
1294 }
1295 if ((ui_volume > 0) && (ui_volume != UINT_MAX))
1296 {
1297 mm_result = waveOutGetVolume ((HWAVEOUT) WAVE_MAPPER, &ui_volume_org);
1298 if (mm_result == MMSYSERR_NOERROR)
1299 {
1300 b_reset_volume = TRUE;
1301 mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume);
1302 if (mm_result != MMSYSERR_NOERROR)
1303 {
1304 SOUND_WARNING (waveOutGetErrorText, mm_result,
1305 "waveOutSetVolume failed to set the volume level "
1306 "of the WAVE_MAPPER device.\n"
1307 "As a result, the user selected volume level will "
1308 "not be used.");
1309 }
1310 }
1311 else
1312 {
1313 SOUND_WARNING (waveOutGetErrorText, mm_result,
1314 "waveOutGetVolume failed to obtain the original "
1315 "volume level of the WAVE_MAPPER device.\n"
1316 "As a result, the user selected volume level will "
1317 "not be used.");
1318 }
1319 }
1320 memset (sz_cmd_buf, 0, sizeof (sz_cmd_buf));
1321 memset (sz_ret_buf, 0, sizeof (sz_ret_buf));
1322 strcpy (sz_cmd_buf, "play GNUEmacs_PlaySound_Device wait");
1323 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, sizeof (sz_ret_buf), NULL);
1324 if (mci_error != 0)
1325 {
1326 SOUND_WARNING (mciGetErrorString, mci_error,
1327 "The play mciSendString command failed to play the "
1328 "opened sound file.");
1329 i_result = (int) mci_error;
1330 }
1331 memset (sz_cmd_buf, 0, sizeof (sz_cmd_buf));
1332 memset (sz_ret_buf, 0, sizeof (sz_ret_buf));
1333 strcpy (sz_cmd_buf, "close GNUEmacs_PlaySound_Device wait");
1334 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, sizeof (sz_ret_buf), NULL);
1335 if (b_reset_volume == TRUE)
1336 {
1337 mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume_org);
1338 if (mm_result != MMSYSERR_NOERROR)
1339 {
1340 SOUND_WARNING (waveOutGetErrorText, mm_result,
1341 "waveOutSetVolume failed to reset the original volume "
1342 "level of the WAVE_MAPPER device.");
1343 }
1344 }
1345 return i_result;
1346 }
1347
1348 /* END: Windows specific functions */
1349
1350 #endif /* WINDOWSNT */
1351
1352 DEFUN ("play-sound-internal", Fplay_sound_internal, Splay_sound_internal, 1, 1, 0,
1353 doc: /* Play sound SOUND.
1354
1355 Internal use only, use `play-sound' instead. */)
1356 (Lisp_Object sound)
1357 {
1358 Lisp_Object attrs[SOUND_ATTR_SENTINEL];
1359 int count = SPECPDL_INDEX ();
1360
1361 #ifndef WINDOWSNT
1362 Lisp_Object file;
1363 struct gcpro gcpro1, gcpro2;
1364 Lisp_Object args[2];
1365 #else /* WINDOWSNT */
1366 int len = 0;
1367 Lisp_Object lo_file = {0};
1368 char * psz_file = NULL;
1369 unsigned long ui_volume_tmp = UINT_MAX;
1370 unsigned long ui_volume = UINT_MAX;
1371 int i_result = 0;
1372 #endif /* WINDOWSNT */
1373
1374 /* Parse the sound specification. Give up if it is invalid. */
1375 if (!parse_sound (sound, attrs))
1376 error ("Invalid sound specification");
1377
1378 #ifndef WINDOWSNT
1379 file = Qnil;
1380 GCPRO2 (sound, file);
1381 current_sound_device = (struct sound_device *) xmalloc (sizeof (struct sound_device));
1382 memset (current_sound_device, 0, sizeof (struct sound_device));
1383 current_sound = (struct sound *) xmalloc (sizeof (struct sound));
1384 memset (current_sound, 0, sizeof (struct sound));
1385 record_unwind_protect (sound_cleanup, Qnil);
1386 current_sound->header = (char *) alloca (MAX_SOUND_HEADER_BYTES);
1387
1388 if (STRINGP (attrs[SOUND_FILE]))
1389 {
1390 /* Open the sound file. */
1391 current_sound->fd = openp (Fcons (Vdata_directory, Qnil),
1392 attrs[SOUND_FILE], Qnil, &file, Qnil);
1393 if (current_sound->fd < 0)
1394 sound_perror ("Could not open sound file");
1395
1396 /* Read the first bytes from the file. */
1397 current_sound->header_size
1398 = emacs_read (current_sound->fd, current_sound->header,
1399 MAX_SOUND_HEADER_BYTES);
1400 if (current_sound->header_size < 0)
1401 sound_perror ("Invalid sound file header");
1402 }
1403 else
1404 {
1405 current_sound->data = attrs[SOUND_DATA];
1406 current_sound->header_size = min (MAX_SOUND_HEADER_BYTES, SBYTES (current_sound->data));
1407 memcpy (current_sound->header, SDATA (current_sound->data),
1408 current_sound->header_size);
1409 }
1410
1411 /* Find out the type of sound. Give up if we can't tell. */
1412 find_sound_type (current_sound);
1413
1414 /* Set up a device. */
1415 if (STRINGP (attrs[SOUND_DEVICE]))
1416 {
1417 int len = SCHARS (attrs[SOUND_DEVICE]);
1418 current_sound_device->file = (char *) alloca (len + 1);
1419 strcpy (current_sound_device->file, SDATA (attrs[SOUND_DEVICE]));
1420 }
1421
1422 if (INTEGERP (attrs[SOUND_VOLUME]))
1423 current_sound_device->volume = XFASTINT (attrs[SOUND_VOLUME]);
1424 else if (FLOATP (attrs[SOUND_VOLUME]))
1425 current_sound_device->volume = XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;
1426
1427 args[0] = Qplay_sound_functions;
1428 args[1] = sound;
1429 Frun_hook_with_args (2, args);
1430
1431 #ifdef HAVE_ALSA
1432 if (!alsa_init (current_sound_device))
1433 #endif
1434 if (!vox_init (current_sound_device))
1435 error ("No usable sound device driver found");
1436
1437 /* Open the device. */
1438 current_sound_device->open (current_sound_device);
1439
1440 /* Play the sound. */
1441 current_sound->play (current_sound, current_sound_device);
1442
1443 /* Clean up. */
1444 UNGCPRO;
1445
1446 #else /* WINDOWSNT */
1447
1448 lo_file = Fexpand_file_name (attrs[SOUND_FILE], Qnil);
1449 len = XSTRING (lo_file)->size;
1450 psz_file = (char *) alloca (len + 1);
1451 strcpy (psz_file, XSTRING (lo_file)->data);
1452 if (INTEGERP (attrs[SOUND_VOLUME]))
1453 {
1454 ui_volume_tmp = XFASTINT (attrs[SOUND_VOLUME]);
1455 }
1456 else if (FLOATP (attrs[SOUND_VOLUME]))
1457 {
1458 ui_volume_tmp = (unsigned long) XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;
1459 }
1460 /*
1461 Based on some experiments I have conducted, a value of 100 or less
1462 for the sound volume is much too low. You cannot even hear it.
1463 A value of UINT_MAX indicates that you wish for the sound to played
1464 at the maximum possible volume. A value of UINT_MAX/2 plays the
1465 sound at 50% maximum volume. Therefore the value passed to do_play_sound
1466 (and thus to waveOutSetVolume) must be some fraction of UINT_MAX.
1467 The following code adjusts the user specified volume level appropriately.
1468 */
1469 if ((ui_volume_tmp > 0) && (ui_volume_tmp <= 100))
1470 {
1471 ui_volume = ui_volume_tmp * (UINT_MAX / 100);
1472 }
1473 i_result = do_play_sound (psz_file, ui_volume);
1474
1475 #endif /* WINDOWSNT */
1476
1477 unbind_to (count, Qnil);
1478 return Qnil;
1479 }
1480 \f
1481 /***********************************************************************
1482 Initialization
1483 ***********************************************************************/
1484
1485 void
1486 syms_of_sound (void)
1487 {
1488 QCdevice = intern_c_string(":device");
1489 staticpro (&QCdevice);
1490 QCvolume = intern_c_string (":volume");
1491 staticpro (&QCvolume);
1492 Qsound = intern_c_string ("sound");
1493 staticpro (&Qsound);
1494 Qplay_sound_functions = intern_c_string ("play-sound-functions");
1495 staticpro (&Qplay_sound_functions);
1496
1497 defsubr (&Splay_sound_internal);
1498 }
1499
1500
1501 void
1502 init_sound (void)
1503 {
1504 }
1505
1506 #endif /* HAVE_SOUND */
1507
1508 /* arch-tag: dd850ad8-0433-4e2c-9cba-b7aeeccc0dbd
1509 (do not change this comment) */