annotate src/sound.c @ 110693:754df5a0efe9

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