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