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