Mercurial > emacs
annotate src/sound.c @ 70960:d876c40c06dd
* fileio.c (Fcopy_file): Delete argument MUSTBENEW. Incorporate
the exclusive file-opening functionality into the behavior when
OK-IF-ALREADY-EXISTS is nil.
(Frename_file): Call Fcopy_file without MUSTBENEW argument.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Fri, 26 May 2006 15:18:28 +0000 |
parents | d42f132da9a8 |
children | 47e6374861d1 |
rev | line source |
---|---|
25003 | 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, |
68651
3bd95f4f2941
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64770
diff
changeset
|
3 2005, 2006 Free Software Foundation, Inc. |
25003 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
7 GNU Emacs is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 2, or (at your option) | |
10 any later version. | |
11 | |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GNU Emacs; see the file COPYING. If not, write to | |
64084 | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 Boston, MA 02110-1301, USA. */ | |
25003 | 21 |
22 /* Written by Gerd Moellmann <gerd@gnu.org>. Tested with Luigi's | |
23 driver on FreeBSD 2.2.7 with a SoundBlaster 16. */ | |
24 | |
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
|
25 /* |
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 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
|
27 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
|
28 |
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 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
|
30 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
|
31 :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
|
32 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
|
33 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
|
34 |
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
|
35 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
|
36 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
|
37 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
|
38 */ |
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
|
39 |
25003 | 40 #include <config.h> |
41 | |
42 #if defined HAVE_SOUND | |
43 | |
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
|
44 /* BEGIN: Common Includes */ |
25003 | 45 #include <fcntl.h> |
46 #include <unistd.h> | |
47 #include <sys/types.h> | |
48 #include <errno.h> | |
38297
17465a81d1dd
Include Emacs' header files with #include "...".
Gerd Moellmann <gerd@gnu.org>
parents:
38215
diff
changeset
|
49 #include "lisp.h" |
17465a81d1dd
Include Emacs' header files with #include "...".
Gerd Moellmann <gerd@gnu.org>
parents:
38215
diff
changeset
|
50 #include "dispextern.h" |
17465a81d1dd
Include Emacs' header files with #include "...".
Gerd Moellmann <gerd@gnu.org>
parents:
38215
diff
changeset
|
51 #include "atimer.h" |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
52 #include <signal.h> |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
53 #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
|
54 /* 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
|
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 |
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 /* 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
|
58 #ifndef WINDOWSNT |
25003 | 59 |
39969
21d7408e0d86
Include <sys/ioctl.h> also on systems without <soundcard.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39812
diff
changeset
|
60 #ifndef MSDOS |
21d7408e0d86
Include <sys/ioctl.h> also on systems without <soundcard.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39812
diff
changeset
|
61 #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
|
62 #endif |
21d7408e0d86
Include <sys/ioctl.h> also on systems without <soundcard.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39812
diff
changeset
|
63 |
25003 | 64 /* FreeBSD has machine/soundcard.h. Voxware sound driver docs mention |
65 sys/soundcard.h. So, let's try whatever's there. */ | |
66 | |
67 #ifdef HAVE_MACHINE_SOUNDCARD_H | |
68 #include <machine/soundcard.h> | |
69 #endif | |
70 #ifdef HAVE_SYS_SOUNDCARD_H | |
71 #include <sys/soundcard.h> | |
72 #endif | |
30079
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
73 #ifdef HAVE_SOUNDCARD_H |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
74 #include <soundcard.h> |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
75 #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
|
76 #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
|
77 #include <asoundlib.h> |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
78 #endif |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
79 |
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
|
80 /* 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
|
81 |
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
|
82 #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
|
83 |
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 /* 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
|
85 #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
|
86 #include <stdlib.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
|
87 #include <string.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
|
88 #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
|
89 #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
|
90 #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
|
91 /* 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
|
92 |
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 #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
|
94 |
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 /* 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
|
96 #define abs(X) ((X) < 0 ? -(X) : (X)) |
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 extern Lisp_Object QCfile, QCdata; |
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 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
|
102 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
|
103 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
|
104 |
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 /* 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
|
106 |
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 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
|
108 { |
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_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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 }; |
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
|
115 |
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
|
116 static void sound_perror P_ ((char *)); |
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
|
117 static void sound_warning P_ ((char *)); |
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
|
118 static int parse_sound P_ ((Lisp_Object, Lisp_Object *)); |
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
|
119 |
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
|
120 /* 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
|
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 /* 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
|
123 #ifndef WINDOWSNT |
30079
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
124 |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
125 #ifndef DEFAULT_SOUND_DEVICE |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
126 #define DEFAULT_SOUND_DEVICE "/dev/dsp" |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
127 #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
|
128 #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
|
129 #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
|
130 #endif |
25003 | 131 |
132 | |
133 /* Structure forward declarations. */ | |
134 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
135 struct sound; |
25003 | 136 struct sound_device; |
137 | |
138 /* The file header of RIFF-WAVE files (*.wav). Files are always in | |
139 little-endian byte-order. */ | |
140 | |
141 struct wav_header | |
142 { | |
143 u_int32_t magic; | |
144 u_int32_t length; | |
145 u_int32_t chunk_type; | |
146 u_int32_t chunk_format; | |
147 u_int32_t chunk_length; | |
148 u_int16_t format; | |
149 u_int16_t channels; | |
150 u_int32_t sample_rate; | |
151 u_int32_t bytes_per_second; | |
152 u_int16_t sample_size; | |
153 u_int16_t precision; | |
154 u_int32_t chunk_data; | |
155 u_int32_t data_length; | |
156 }; | |
157 | |
158 /* The file header of Sun adio files (*.au). Files are always in | |
159 big-endian byte-order. */ | |
160 | |
161 struct au_header | |
162 { | |
163 /* ASCII ".snd" */ | |
164 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
|
165 |
25003 | 166 /* Offset of data part from start of file. Minimum value is 24. */ |
167 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
|
168 |
25003 | 169 /* Size of data part, 0xffffffff if unknown. */ |
170 u_int32_t data_size; | |
171 | |
172 /* Data encoding format. | |
173 1 8-bit ISDN u-law | |
174 2 8-bit linear PCM (REF-PCM) | |
175 3 16-bit linear PCM | |
176 4 24-bit linear PCM | |
177 5 32-bit linear PCM | |
178 6 32-bit IEEE floating-point | |
179 7 64-bit IEEE floating-point | |
180 23 8-bit u-law compressed using CCITT 0.721 ADPCM voice data | |
181 encoding scheme. */ | |
182 u_int32_t encoding; | |
183 | |
184 /* Number of samples per second. */ | |
185 u_int32_t sample_rate; | |
186 | |
187 /* Number of interleaved channels. */ | |
188 u_int32_t channels; | |
189 }; | |
190 | |
191 /* Maximum of all sound file headers sizes. */ | |
192 | |
193 #define MAX_SOUND_HEADER_BYTES \ | |
194 max (sizeof (struct wav_header), sizeof (struct au_header)) | |
195 | |
196 /* Interface structure for sound devices. */ | |
197 | |
198 struct sound_device | |
199 { | |
200 /* The name of the device or null meaning use a default device name. */ | |
201 char *file; | |
202 | |
203 /* File descriptor of the device. */ | |
204 int fd; | |
205 | |
206 /* Device-dependent format. */ | |
207 int format; | |
208 | |
209 /* Volume (0..100). Zero means unspecified. */ | |
210 int volume; | |
211 | |
212 /* Sample size. */ | |
213 int sample_size; | |
214 | |
215 /* Sample rate. */ | |
216 int sample_rate; | |
217 | |
218 /* Bytes per second. */ | |
219 int bps; | |
220 | |
221 /* 1 = mono, 2 = stereo, 0 = don't set. */ | |
222 int channels; | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
223 |
25003 | 224 /* Open device SD. */ |
225 void (* open) P_ ((struct sound_device *sd)); | |
226 | |
227 /* Close device SD. */ | |
228 void (* close) P_ ((struct sound_device *sd)); | |
229 | |
230 /* Configure SD accoring to device-dependent parameters. */ | |
231 void (* configure) P_ ((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
|
232 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
233 /* Choose a device-dependent format for outputting sound S. */ |
25003 | 234 void (* choose_format) P_ ((struct sound_device *sd, |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
235 struct sound *s)); |
25003 | 236 |
70718
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
237 /* 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
|
238 each time. 2048 is used if this is NULL. */ |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
239 int (* period_size) P_ ((struct sound_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
|
240 |
25003 | 241 /* Write NYBTES bytes from BUFFER to device SD. */ |
46554
fb13fafbd279
(struct sound_device): Function pointer field "write"
Ken Raeburn <raeburn@raeburn.org>
parents:
46370
diff
changeset
|
242 void (* write) P_ ((struct sound_device *sd, const char *buffer, |
fb13fafbd279
(struct sound_device): Function pointer field "write"
Ken Raeburn <raeburn@raeburn.org>
parents:
46370
diff
changeset
|
243 int nbytes)); |
25003 | 244 |
245 /* A place for devices to store additional data. */ | |
246 void *data; | |
247 }; | |
248 | |
249 /* An enumerator for each supported sound file type. */ | |
250 | |
251 enum sound_type | |
252 { | |
253 RIFF, | |
254 SUN_AUDIO | |
255 }; | |
256 | |
257 /* Interface structure for sound files. */ | |
258 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
259 struct sound |
25003 | 260 { |
261 /* The type of the file. */ | |
262 enum sound_type type; | |
263 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
264 /* File descriptor of a sound file. */ |
25003 | 265 int fd; |
266 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
267 /* 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
|
268 read from the start of a sound file. */ |
25003 | 269 char *header; |
270 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
271 /* 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
|
272 MAX_SOUND_HEADER_BYTES. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
273 int header_size; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
274 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
275 /* Sound data, if a string. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
276 Lisp_Object data; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
277 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
278 /* Play sound file S on device SD. */ |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
279 void (* play) P_ ((struct sound *s, struct sound_device *sd)); |
25003 | 280 }; |
281 | |
44399
a399428859ff
(Fplay_sound_internal): Renamed from Fplay_sound.
Pavel Janík <Pavel@Janik.cz>
parents:
42754
diff
changeset
|
282 /* These are set during `play-sound-internal' so that sound_cleanup has |
25003 | 283 access to them. */ |
284 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
285 struct sound_device *current_sound_device; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
286 struct sound *current_sound; |
25003 | 287 |
288 /* Function prototypes. */ | |
289 | |
290 static void vox_open P_ ((struct sound_device *)); | |
291 static void vox_configure P_ ((struct sound_device *)); | |
292 static void vox_close P_ ((struct sound_device *sd)); | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
293 static void vox_choose_format P_ ((struct sound_device *, struct sound *)); |
70718
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
294 static int vox_init P_ ((struct sound_device *)); |
46554
fb13fafbd279
(struct sound_device): Function pointer field "write"
Ken Raeburn <raeburn@raeburn.org>
parents:
46370
diff
changeset
|
295 static void vox_write P_ ((struct sound_device *, const char *, int)); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
296 static void find_sound_type P_ ((struct sound *)); |
25003 | 297 static u_int32_t le2hl P_ ((u_int32_t)); |
298 static u_int16_t le2hs P_ ((u_int16_t)); | |
299 static u_int32_t be2hl P_ ((u_int32_t)); | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
300 static int wav_init P_ ((struct sound *)); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
301 static void wav_play P_ ((struct sound *, struct sound_device *)); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
302 static int au_init P_ ((struct sound *)); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
303 static void au_play P_ ((struct sound *, struct sound_device *)); |
25003 | 304 |
25722
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
305 #if 0 /* Currently not used. */ |
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
306 static u_int16_t be2hs P_ ((u_int16_t)); |
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
307 #endif |
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
308 |
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
|
309 /* 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
|
310 #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
|
311 |
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 /* BEGIN: 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
|
313 static int do_play_sound P_ ((const char *, unsigned long)); |
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 /* |
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
|
315 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
|
316 #endif /* WINDOWSNT */ |
25003 | 317 |
318 | |
319 /*********************************************************************** | |
320 General | |
321 ***********************************************************************/ | |
322 | |
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
|
323 /* 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
|
324 |
25003 | 325 /* Like perror, but signals an error. */ |
326 | |
327 static void | |
328 sound_perror (msg) | |
329 char *msg; | |
330 { | |
40745
1622bfdfe454
(sound_perror): Save errno from being clobbered.
Andreas Schwab <schwab@suse.de>
parents:
40364
diff
changeset
|
331 int saved_errno = errno; |
1622bfdfe454
(sound_perror): Save errno from being clobbered.
Andreas Schwab <schwab@suse.de>
parents:
40364
diff
changeset
|
332 |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
333 turn_on_atimers (1); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
334 #ifdef SIGIO |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
335 sigunblock (sigmask (SIGIO)); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
336 #endif |
40745
1622bfdfe454
(sound_perror): Save errno from being clobbered.
Andreas Schwab <schwab@suse.de>
parents:
40364
diff
changeset
|
337 if (saved_errno != 0) |
1622bfdfe454
(sound_perror): Save errno from being clobbered.
Andreas Schwab <schwab@suse.de>
parents:
40364
diff
changeset
|
338 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
|
339 else |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
340 error ("%s", msg); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
341 } |
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 /* Display a warning message. */ |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
345 |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
346 static void |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
347 sound_warning (msg) |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
348 char *msg; |
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 | 351 } |
352 | |
353 | |
354 /* Parse sound specification SOUND, and fill ATTRS with what is | |
355 found. Value is non-zero if SOUND Is a valid sound specification. | |
356 A valid sound specification is a list starting with the symbol | |
357 `sound'. The rest of the list is a property list which may | |
358 contain the following key/value pairs: | |
359 | |
360 - `:file FILE' | |
361 | |
362 FILE is the sound file to play. If it isn't an absolute name, | |
363 it's searched under `data-directory'. | |
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 | 370 - `:device DEVICE' |
371 | |
372 DEVICE is the name of the device to play on, e.g. "/dev/dsp2". | |
373 If not specified, a default device is used. | |
374 | |
375 - `:volume VOL' | |
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 | 379 |
380 static int | |
381 parse_sound (sound, attrs) | |
382 Lisp_Object sound; | |
383 Lisp_Object *attrs; | |
384 { | |
385 /* SOUND must be a list starting with the symbol `sound'. */ | |
386 if (!CONSP (sound) || !EQ (XCAR (sound), Qsound)) | |
387 return 0; | |
388 | |
389 sound = XCDR (sound); | |
390 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
|
391 attrs[SOUND_DATA] = Fplist_get (sound, QCdata); |
25003 | 392 attrs[SOUND_DEVICE] = Fplist_get (sound, QCdevice); |
393 attrs[SOUND_VOLUME] = Fplist_get (sound, QCvolume); | |
394 | |
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
|
395 #ifndef WINDOWSNT |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
396 /* File name or data must be specified. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
397 if (!STRINGP (attrs[SOUND_FILE]) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
398 && !STRINGP (attrs[SOUND_DATA])) |
25003 | 399 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
|
400 #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
|
401 /* |
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 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
|
403 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
|
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 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
|
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 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
|
408 } |
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
|
409 #endif /* WINDOWSNT */ |
25003 | 410 |
411 /* Volume must be in the range 0..100 or unspecified. */ | |
412 if (!NILP (attrs[SOUND_VOLUME])) | |
413 { | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
414 if (INTEGERP (attrs[SOUND_VOLUME])) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
415 { |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
416 if (XINT (attrs[SOUND_VOLUME]) < 0 |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
417 || XINT (attrs[SOUND_VOLUME]) > 100) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
418 return 0; |
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 else if (FLOATP (attrs[SOUND_VOLUME])) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
421 { |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
422 if (XFLOAT_DATA (attrs[SOUND_VOLUME]) < 0 |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
423 || XFLOAT_DATA (attrs[SOUND_VOLUME]) > 1) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
424 return 0; |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
425 } |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
426 else |
25003 | 427 return 0; |
428 } | |
429 | |
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
|
430 #ifndef WINDOWSNT |
25003 | 431 /* Device must be a string or unspecified. */ |
432 if (!NILP (attrs[SOUND_DEVICE]) | |
433 && !STRINGP (attrs[SOUND_DEVICE])) | |
434 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
|
435 #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
|
436 /* |
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 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
|
438 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
|
439 */ |
25003 | 440 return 1; |
441 } | |
442 | |
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
|
443 /* 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
|
444 |
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
|
445 /* 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
|
446 #ifndef WINDOWSNT |
25003 | 447 |
448 /* 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
|
449 S is the sound file structure to fill in. */ |
25003 | 450 |
451 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
452 find_sound_type (s) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
453 struct sound *s; |
25003 | 454 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
455 if (!wav_init (s) && !au_init (s)) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
456 error ("Unknown sound format"); |
25003 | 457 } |
458 | |
459 | |
44399
a399428859ff
(Fplay_sound_internal): Renamed from Fplay_sound.
Pavel Janík <Pavel@Janik.cz>
parents:
42754
diff
changeset
|
460 /* Function installed by play-sound-internal with record_unwind_protect. */ |
25003 | 461 |
462 static Lisp_Object | |
463 sound_cleanup (arg) | |
464 Lisp_Object arg; | |
465 { | |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
466 if (current_sound_device->close) |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
467 current_sound_device->close (current_sound_device); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
468 if (current_sound->fd > 0) |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
469 emacs_close (current_sound->fd); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
470 free (current_sound_device); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
471 free (current_sound); |
34255
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
472 |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
473 return Qnil; |
25003 | 474 } |
475 | |
476 /*********************************************************************** | |
477 Byte-order Conversion | |
478 ***********************************************************************/ | |
479 | |
480 /* Convert 32-bit value VALUE which is in little-endian byte-order | |
481 to host byte-order. */ | |
482 | |
483 static u_int32_t | |
484 le2hl (value) | |
485 u_int32_t value; | |
486 { | |
487 #ifdef WORDS_BIG_ENDIAN | |
488 unsigned char *p = (unsigned char *) &value; | |
489 value = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24); | |
490 #endif | |
491 return value; | |
492 } | |
493 | |
494 | |
495 /* Convert 16-bit value VALUE which is in little-endian byte-order | |
496 to host byte-order. */ | |
497 | |
498 static u_int16_t | |
499 le2hs (value) | |
500 u_int16_t value; | |
501 { | |
502 #ifdef WORDS_BIG_ENDIAN | |
503 unsigned char *p = (unsigned char *) &value; | |
504 value = p[0] + (p[1] << 8); | |
505 #endif | |
506 return value; | |
507 } | |
508 | |
509 | |
510 /* Convert 32-bit value VALUE which is in big-endian byte-order | |
511 to host byte-order. */ | |
512 | |
513 static u_int32_t | |
514 be2hl (value) | |
515 u_int32_t value; | |
516 { | |
517 #ifndef WORDS_BIG_ENDIAN | |
518 unsigned char *p = (unsigned char *) &value; | |
519 value = p[3] + (p[2] << 8) + (p[1] << 16) + (p[0] << 24); | |
520 #endif | |
521 return value; | |
522 } | |
523 | |
524 | |
25722
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
525 #if 0 /* Currently not used. */ |
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
526 |
25003 | 527 /* Convert 16-bit value VALUE which is in big-endian byte-order |
528 to host byte-order. */ | |
529 | |
530 static u_int16_t | |
531 be2hs (value) | |
532 u_int16_t value; | |
533 { | |
534 #ifndef WORDS_BIG_ENDIAN | |
535 unsigned char *p = (unsigned char *) &value; | |
536 value = p[1] + (p[0] << 8); | |
537 #endif | |
538 return value; | |
539 } | |
540 | |
25722
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
541 #endif /* 0 */ |
25003 | 542 |
543 /*********************************************************************** | |
544 RIFF-WAVE (*.wav) | |
545 ***********************************************************************/ | |
546 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
547 /* Try to initialize sound file S from S->header. S->header |
25003 | 548 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the |
549 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
|
550 functions in S and convert header fields to host byte-order. |
25003 | 551 Value is non-zero if the file is a WAV file. */ |
552 | |
553 static int | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
554 wav_init (s) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
555 struct sound *s; |
25003 | 556 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
557 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
|
558 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
559 if (s->header_size < sizeof *header |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
560 || bcmp (s->header, "RIFF", 4) != 0) |
25003 | 561 return 0; |
562 | |
563 /* WAV files are in little-endian order. Convert the header | |
564 if on a big-endian machine. */ | |
565 header->magic = le2hl (header->magic); | |
566 header->length = le2hl (header->length); | |
567 header->chunk_type = le2hl (header->chunk_type); | |
568 header->chunk_format = le2hl (header->chunk_format); | |
569 header->chunk_length = le2hl (header->chunk_length); | |
570 header->format = le2hs (header->format); | |
571 header->channels = le2hs (header->channels); | |
572 header->sample_rate = le2hl (header->sample_rate); | |
573 header->bytes_per_second = le2hl (header->bytes_per_second); | |
574 header->sample_size = le2hs (header->sample_size); | |
575 header->precision = le2hs (header->precision); | |
576 header->chunk_data = le2hl (header->chunk_data); | |
577 header->data_length = le2hl (header->data_length); | |
578 | |
579 /* 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
|
580 s->type = RIFF; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
581 s->play = wav_play; |
25003 | 582 |
583 return 1; | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
584 } |
25003 | 585 |
586 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
587 /* Play RIFF-WAVE audio file S on sound device SD. */ |
25003 | 588 |
589 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
590 wav_play (s, sd) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
591 struct sound *s; |
25003 | 592 struct sound_device *sd; |
593 { | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
594 struct wav_header *header = (struct wav_header *) s->header; |
25003 | 595 |
596 /* Let the device choose a suitable device-dependent format | |
597 for the file. */ | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
598 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
|
599 |
25003 | 600 /* Configure the device. */ |
601 sd->sample_size = header->sample_size; | |
602 sd->sample_rate = header->sample_rate; | |
603 sd->bps = header->bytes_per_second; | |
604 sd->channels = header->channels; | |
605 sd->configure (sd); | |
606 | |
607 /* Copy sound data to the device. The WAV file specification is | |
608 actually more complex. This simple scheme worked with all WAV | |
609 files I found so far. If someone feels inclined to implement the | |
610 whole RIFF-WAVE spec, please do. */ | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
611 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
|
612 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
|
613 SBYTES (s->data) - sizeof *header); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
614 else |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
615 { |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
616 char *buffer; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
617 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
|
618 int blksize = sd->period_size ? sd->period_size (sd) : 2048; |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
619 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
620 buffer = (char *) alloca (blksize); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
621 lseek (s->fd, sizeof *header, SEEK_SET); |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
622 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
623 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
|
624 sd->write (sd, buffer, nbytes); |
25003 | 625 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
626 if (nbytes < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
627 sound_perror ("Error reading sound file"); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
628 } |
25003 | 629 } |
630 | |
631 | |
632 /*********************************************************************** | |
633 Sun Audio (*.au) | |
634 ***********************************************************************/ | |
635 | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
636 /* Sun audio file encodings. */ |
25003 | 637 |
638 enum au_encoding | |
639 { | |
640 AU_ENCODING_ULAW_8 = 1, | |
641 AU_ENCODING_8, | |
642 AU_ENCODING_16, | |
643 AU_ENCODING_24, | |
644 AU_ENCODING_32, | |
645 AU_ENCODING_IEEE32, | |
646 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
|
647 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
|
648 AU_ENCODING_ALAW_8 = 27 |
25003 | 649 }; |
650 | |
651 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
652 /* Try to initialize sound file S from S->header. S->header |
25003 | 653 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the |
654 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
|
655 functions in S and convert header fields to host byte-order. |
25003 | 656 Value is non-zero if the file is an AU file. */ |
657 | |
658 static int | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
659 au_init (s) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
660 struct sound *s; |
25003 | 661 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
662 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
|
663 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
664 if (s->header_size < sizeof *header |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
665 || bcmp (s->header, ".snd", 4) != 0) |
25003 | 666 return 0; |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
667 |
25003 | 668 header->magic_number = be2hl (header->magic_number); |
669 header->data_offset = be2hl (header->data_offset); | |
670 header->data_size = be2hl (header->data_size); | |
671 header->encoding = be2hl (header->encoding); | |
672 header->sample_rate = be2hl (header->sample_rate); | |
673 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
|
674 |
25003 | 675 /* 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
|
676 s->type = SUN_AUDIO; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
677 s->play = au_play; |
25003 | 678 |
679 return 1; | |
680 } | |
681 | |
682 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
683 /* Play Sun audio file S on sound device SD. */ |
25003 | 684 |
685 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
686 au_play (s, sd) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
687 struct sound *s; |
25003 | 688 struct sound_device *sd; |
689 { | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
690 struct au_header *header = (struct au_header *) s->header; |
25003 | 691 |
692 sd->sample_size = 0; | |
693 sd->sample_rate = header->sample_rate; | |
694 sd->bps = 0; | |
695 sd->channels = header->channels; | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
696 sd->choose_format (sd, s); |
25003 | 697 sd->configure (sd); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
698 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
699 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
|
700 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
|
701 SBYTES (s->data) - header->data_offset); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
702 else |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
703 { |
70718
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
704 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
|
705 char *buffer; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
706 int 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 /* Seek */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
709 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
|
710 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
711 /* Copy sound data to the device. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
712 buffer = (char *) alloca (blksize); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
713 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
|
714 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
|
715 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
716 if (nbytes < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
717 sound_perror ("Error reading sound file"); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
718 } |
25003 | 719 } |
720 | |
721 | |
722 /*********************************************************************** | |
723 Voxware Driver Interface | |
724 ***********************************************************************/ | |
725 | |
726 /* This driver is available on GNU/Linux, and the free BSDs. FreeBSD | |
727 has a compatible own driver aka Luigi's driver. */ | |
728 | |
729 | |
730 /* Open device SD. If SD->file is non-null, open that device, | |
731 otherwise use a default device name. */ | |
732 | |
733 static void | |
734 vox_open (sd) | |
735 struct sound_device *sd; | |
736 { | |
737 char *file; | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
738 |
25003 | 739 /* Open the sound device. Default is /dev/dsp. */ |
740 if (sd->file) | |
741 file = sd->file; | |
742 else | |
30079
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
743 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
|
744 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
25722
diff
changeset
|
745 sd->fd = emacs_open (file, O_WRONLY, 0); |
25003 | 746 if (sd->fd < 0) |
747 sound_perror (file); | |
748 } | |
749 | |
750 | |
751 /* Configure device SD from parameters in it. */ | |
752 | |
753 static void | |
754 vox_configure (sd) | |
755 struct sound_device *sd; | |
756 { | |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
757 int val; |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
758 |
25003 | 759 xassert (sd->fd >= 0); |
760 | |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
761 /* 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
|
762 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
|
763 troubles. */ |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
764 turn_on_atimers (0); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
765 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
766 sigblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
767 #endif |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
768 |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
769 val = sd->format; |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
770 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
|
771 || val != sd->format) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
772 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
|
773 |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
774 val = sd->channels != 1; |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
775 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
|
776 || val != (sd->channels != 1)) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
777 sound_perror ("Could not set stereo/mono"); |
25003 | 778 |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
779 /* 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
|
780 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
|
781 if (sd->sample_rate > 0) |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
782 { |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
783 val = sd->sample_rate; |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
784 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
|
785 sound_perror ("Could not set sound speed"); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
786 else if (val != sd->sample_rate) |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
787 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
|
788 } |
25003 | 789 |
34255
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
790 if (sd->volume > 0) |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
791 { |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
792 int volume = sd->volume & 0xff; |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
793 volume |= volume << 8; |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
794 /* 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
|
795 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
|
796 } |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
797 |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
798 turn_on_atimers (1); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
799 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
800 sigunblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
801 #endif |
25003 | 802 } |
803 | |
804 | |
805 /* Close device SD if it is open. */ | |
806 | |
807 static void | |
808 vox_close (sd) | |
809 struct sound_device *sd; | |
810 { | |
811 if (sd->fd >= 0) | |
812 { | |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
813 /* 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
|
814 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
|
815 troubles. */ |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
816 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
817 sigblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
818 #endif |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
819 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
|
820 |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
821 /* Flush sound data, and reset the device. */ |
25003 | 822 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
|
823 |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
824 turn_on_atimers (1); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
825 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
826 sigunblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
827 #endif |
25003 | 828 |
829 /* 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
|
830 emacs_close (sd->fd); |
25003 | 831 sd->fd = -1; |
832 } | |
833 } | |
834 | |
835 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
836 /* Choose device-dependent format for device SD from sound file S. */ |
25003 | 837 |
838 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
839 vox_choose_format (sd, s) |
25003 | 840 struct sound_device *sd; |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
841 struct sound *s; |
25003 | 842 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
843 if (s->type == RIFF) |
25003 | 844 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
845 struct wav_header *h = (struct wav_header *) s->header; |
25003 | 846 if (h->precision == 8) |
847 sd->format = AFMT_U8; | |
848 else if (h->precision == 16) | |
849 sd->format = AFMT_S16_LE; | |
850 else | |
851 error ("Unsupported WAV file format"); | |
852 } | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
853 else if (s->type == SUN_AUDIO) |
25003 | 854 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
855 struct au_header *header = (struct au_header *) s->header; |
25003 | 856 switch (header->encoding) |
857 { | |
858 case AU_ENCODING_ULAW_8: | |
859 case AU_ENCODING_IEEE32: | |
860 case AU_ENCODING_IEEE64: | |
861 sd->format = AFMT_MU_LAW; | |
862 break; | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
863 |
25003 | 864 case AU_ENCODING_8: |
865 case AU_ENCODING_16: | |
866 case AU_ENCODING_24: | |
867 case AU_ENCODING_32: | |
868 sd->format = AFMT_S16_LE; | |
869 break; | |
870 | |
871 default: | |
872 error ("Unsupported AU file format"); | |
873 } | |
874 } | |
875 else | |
876 abort (); | |
877 } | |
878 | |
879 | |
880 /* Initialize device SD. Set up the interface functions in the device | |
881 structure. */ | |
882 | |
70718
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
883 static int |
25003 | 884 vox_init (sd) |
885 struct sound_device *sd; | |
886 { | |
70718
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
887 char *file; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
888 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
|
889 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
890 /* 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
|
891 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
|
892 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
|
893 else |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
894 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
|
895 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
|
896 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
|
897 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
|
898 else |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
899 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
|
900 |
25003 | 901 sd->fd = -1; |
902 sd->open = vox_open; | |
903 sd->close = vox_close; | |
904 sd->configure = vox_configure; | |
905 sd->choose_format = vox_choose_format; | |
906 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
|
907 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
|
908 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
909 return 1; |
25003 | 910 } |
911 | |
912 /* Write NBYTES bytes from BUFFER to device SD. */ | |
913 | |
914 static void | |
915 vox_write (sd, buffer, nbytes) | |
916 struct sound_device *sd; | |
46554
fb13fafbd279
(struct sound_device): Function pointer field "write"
Ken Raeburn <raeburn@raeburn.org>
parents:
46370
diff
changeset
|
917 const char *buffer; |
25003 | 918 int nbytes; |
919 { | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
25722
diff
changeset
|
920 int nwritten = emacs_write (sd->fd, buffer, nbytes); |
25003 | 921 if (nwritten < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
922 sound_perror ("Error writing to sound device"); |
25003 | 923 } |
924 | |
70718
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
925 #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
|
926 /*********************************************************************** |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
927 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
|
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 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
930 /* 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
|
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 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
933 alsa_sound_perror (msg, err) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
934 char *msg; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
935 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
|
936 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
937 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
|
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 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
940 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
|
941 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
942 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
|
943 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
|
944 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
|
945 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
|
946 }; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
947 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
948 /* 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
|
949 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
|
950 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
951 static void |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
952 alsa_open (sd) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
953 struct sound_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
|
954 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
955 char *file; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
956 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
|
957 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
|
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 /* 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
|
960 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
|
961 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
|
962 else |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
963 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
|
964 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
965 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
|
966 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
|
967 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
|
968 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
|
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 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
|
971 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
|
972 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
973 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
974 if ((err = snd_pcm_open (&p->handle, file, SND_PCM_STREAM_PLAYBACK, 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
|
975 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
|
976 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
977 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
978 static int |
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_period_size (sd) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
980 struct sound_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
|
981 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
982 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
|
983 return 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
|
984 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
985 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
986 static void |
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_configure (sd) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
988 struct sound_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
|
989 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
990 int val, err, dir; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
991 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
|
992 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
|
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 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
|
995 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
996 if ((err = snd_pcm_hw_params_malloc (&p->hwparams)) < 0) |
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 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
|
998 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
999 if ((err = snd_pcm_sw_params_malloc (&p->swparams)) < 0) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1000 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
|
1001 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1002 if ((err = snd_pcm_hw_params_any (p->handle, p->hwparams)) < 0) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1003 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
|
1004 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1005 if ((err = snd_pcm_hw_params_set_access (p->handle, 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
|
1006 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) |
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 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
|
1008 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1009 val = sd->format; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1010 if ((err = snd_pcm_hw_params_set_format (p->handle, p->hwparams, val)) < 0) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1011 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
|
1012 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1013 val = sd->sample_rate; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1014 if ((err = snd_pcm_hw_params_set_rate_near (p->handle, p->hwparams, &val, 0)) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1015 < 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 ("Could not set sample rate", 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 val = 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
|
1019 if ((err = snd_pcm_hw_params_set_channels (p->handle, p->hwparams, val)) < 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 ("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
|
1021 |
70955
d42f132da9a8
* sound.c (alsa_configure): Move get period/buffer_size after
Jan Djärv <jan.h.d@swipnet.se>
parents:
70718
diff
changeset
|
1022 if ((err = snd_pcm_hw_params (p->handle, p->hwparams)) < 0) |
d42f132da9a8
* sound.c (alsa_configure): Move get period/buffer_size after
Jan Djärv <jan.h.d@swipnet.se>
parents:
70718
diff
changeset
|
1023 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
|
1024 |
70718
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1025 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1026 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
|
1027 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
|
1028 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
|
1029 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1030 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
|
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 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
|
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 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
|
1035 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
|
1036 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
|
1037 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 /* 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
|
1040 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
|
1041 (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
|
1042 * 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
|
1043 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
|
1044 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
|
1045 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1046 /* 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
|
1047 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
|
1048 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
|
1049 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
|
1050 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1051 /* Align all transfers to 1 period */ |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1052 err = snd_pcm_sw_params_set_xfer_align (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
|
1053 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
|
1054 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
|
1055 alsa_sound_perror ("Unable to set transfer align 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
|
1056 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1057 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
|
1058 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
|
1059 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
|
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 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
|
1062 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
|
1063 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
|
1064 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
|
1065 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1066 if ((err = snd_pcm_prepare (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
|
1067 alsa_sound_perror ("Could not prepare audio interface for use", err); |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1068 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1069 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
|
1070 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1071 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
|
1072 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
|
1073 snd_mixer_elem_t *e; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1074 char *file = sd->file ? sd->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
|
1075 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1076 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
|
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 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
|
1079 && 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
|
1080 && 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
|
1081 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
|
1082 e; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1083 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
|
1084 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1085 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
|
1086 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1087 long pmin, pmax; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1088 snd_mixer_selem_get_playback_volume_range (e, &pmin, &pmax); |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1089 long vol = pmin + (sd->volume * (pmax - pmin)) / 100; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1090 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1091 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
|
1092 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
|
1093 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1094 } |
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_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
|
1096 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1097 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1098 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1099 |
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 /* 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
|
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 static void |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1104 alsa_close (sd) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1105 struct sound_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
|
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 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
|
1108 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
|
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 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
|
1111 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
|
1112 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
|
1113 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
|
1114 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
|
1115 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1116 snd_pcm_drain(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
|
1117 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
|
1118 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1119 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
|
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 } |
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 /* 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
|
1124 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1125 static void |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1126 alsa_choose_format (sd, s) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1127 struct sound_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
|
1128 struct sound *s; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1129 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1130 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
|
1131 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
|
1132 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1133 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
|
1134 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
|
1135 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
|
1136 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
|
1137 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
|
1138 else |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1139 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
|
1140 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1141 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
|
1142 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1143 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
|
1144 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
|
1145 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1146 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
|
1147 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
|
1148 break; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1149 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
|
1150 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
|
1151 break; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1152 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
|
1153 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
|
1154 break; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1155 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
|
1156 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
|
1157 break; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1158 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
|
1159 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
|
1160 break; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1161 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
|
1162 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
|
1163 break; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1164 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
|
1165 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
|
1166 break; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1167 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
|
1168 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
|
1169 break; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1170 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1171 default: |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1172 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
|
1173 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1174 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1175 else |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1176 abort (); |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1177 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1178 |
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 /* 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
|
1181 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1182 static void |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1183 alsa_write (sd, buffer, nbytes) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1184 struct sound_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
|
1185 const char *buffer; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1186 int nbytes; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1187 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1188 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
|
1189 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1190 /* 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
|
1191 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
|
1192 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
|
1193 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
|
1194 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1195 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
|
1196 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1197 if ((err = snd_pcm_writei (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
|
1198 buffer + nwritten, |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1199 (nbytes - nwritten)/fact)) < 0) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1200 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1201 fprintf(stderr, "Err %d/%s\n", err, 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
|
1202 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
|
1203 { /* 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
|
1204 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
|
1205 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
|
1206 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
|
1207 err); |
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 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
|
1210 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1211 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
|
1212 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
|
1213 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
|
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 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
|
1216 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
|
1217 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
|
1218 "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
|
1219 err); |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1220 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1221 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1222 else |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1223 alsa_sound_perror ("Error writing to sound device", 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 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1226 else |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1227 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
|
1228 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1229 } |
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 static void |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1232 snd_error_quiet (file, line, function, err, fmt) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1233 const char *file; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1234 int line; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1235 const char *function; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1236 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
|
1237 const char *fmt; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1238 { |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1239 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1240 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1241 /* 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
|
1242 structure. */ |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1243 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1244 static int |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1245 alsa_init (sd) |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1246 struct sound_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
|
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 char *file; |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1249 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
|
1250 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
|
1251 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1252 /* 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
|
1253 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
|
1254 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
|
1255 else |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1256 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
|
1257 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1258 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
|
1259 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
|
1260 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
|
1261 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
|
1262 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
|
1263 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1264 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
|
1265 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
|
1266 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
|
1267 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
|
1268 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
|
1269 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
|
1270 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
|
1271 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1272 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
|
1273 } |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1274 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1275 #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
|
1276 |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1277 |
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
|
1278 /* 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
|
1279 #else /* WINDOWSNT */ |
25003 | 1280 |
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
|
1281 /* 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
|
1282 |
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
|
1283 static int |
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 do_play_sound (psz_file, ui_volume) |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1285 const char *psz_file; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1286 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
|
1287 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1288 int i_result = 0; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1289 MCIERROR mci_error = 0; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1290 char sz_cmd_buf[520] = {0}; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1291 char sz_ret_buf[520] = {0}; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1292 MMRESULT mm_result = MMSYSERR_NOERROR; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1293 unsigned long ui_volume_org = 0; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1294 BOOL b_reset_volume = FALSE; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1295 |
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
|
1296 memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf)); |
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
|
1297 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
|
1298 sprintf (sz_cmd_buf, |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1299 "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
|
1300 psz_file); |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1301 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, 520, 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
|
1302 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
|
1303 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1304 sound_warning ("The open mciSendString command failed to open\n" |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1305 "the specified sound file"); |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1306 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
|
1307 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
|
1308 } |
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 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
|
1310 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1311 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
|
1312 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
|
1313 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1314 b_reset_volume = TRUE; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1315 mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, 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
|
1316 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
|
1317 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1318 sound_warning ("waveOutSetVolume failed to set the volume level\n" |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1319 "of the WAVE_MAPPER device.\n" |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1320 "As a result, the user selected volume level will\n" |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1321 "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
|
1322 } |
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
|
1323 } |
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
|
1324 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
|
1325 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1326 sound_warning ("waveOutGetVolume failed to obtain the original\n" |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1327 "volume level of the WAVE_MAPPER device.\n" |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1328 "As a result, the user selected volume level will\n" |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1329 "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
|
1330 } |
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
|
1331 } |
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 memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf)); |
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 memset (sz_ret_buf, 0, sizeof(sz_ret_buf)); |
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
|
1334 strcpy (sz_cmd_buf, "play GNUEmacs_PlaySound_Device wait"); |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1335 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, 520, 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
|
1336 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
|
1337 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1338 sound_warning ("The play mciSendString command failed to play the\n" |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1339 "opened sound file."); |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1340 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
|
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 memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf)); |
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 memset (sz_ret_buf, 0, sizeof(sz_ret_buf)); |
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 strcpy (sz_cmd_buf, "close GNUEmacs_PlaySound_Device wait"); |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1345 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, 520, 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
|
1346 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
|
1347 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1348 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
|
1349 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
|
1350 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1351 sound_warning ("waveOutSetVolume failed to reset the original volume\n" |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1352 "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
|
1353 } |
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 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
|
1356 } |
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 /* 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
|
1359 |
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 #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
|
1361 |
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 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
|
1363 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
|
1364 |
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
|
1365 Internal use only, use `play-sound' instead.\n */) |
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
|
1366 (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
|
1367 Lisp_Object 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
|
1368 { |
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 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
|
1370 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
|
1371 |
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 #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
|
1373 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
|
1374 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
|
1375 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
|
1376 #else /* WINDOWSNT */ |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1377 int len = 0; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1378 Lisp_Object lo_file = {0}; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1379 char * psz_file = NULL; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1380 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
|
1381 unsigned long ui_volume = UINT_MAX; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1382 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
|
1383 #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
|
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 /* 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
|
1386 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
|
1387 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
|
1388 |
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
|
1389 #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
|
1390 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
|
1391 GCPRO2 (sound, file); |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1392 current_sound_device = (struct sound_device *) xmalloc (sizeof (struct sound_device)); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1393 bzero (current_sound_device, sizeof (struct sound_device)); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1394 current_sound = (struct sound *) xmalloc (sizeof (struct sound)); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1395 bzero (current_sound, 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
|
1396 record_unwind_protect (sound_cleanup, Qnil); |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1397 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
|
1398 |
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 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
|
1400 { |
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 /* Open the sound file. */ |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1402 current_sound->fd = openp (Fcons (Vdata_directory, Qnil), |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1403 attrs[SOUND_FILE], Qnil, &file, Qnil); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1404 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
|
1405 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
|
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 /* Read the first bytes from the file. */ |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1408 current_sound->header_size |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1409 = emacs_read (current_sound->fd, current_sound->header, |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1410 MAX_SOUND_HEADER_BYTES); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1411 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
|
1412 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
|
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 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
|
1415 { |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1416 current_sound->data = attrs[SOUND_DATA]; |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1417 current_sound->header_size = min (MAX_SOUND_HEADER_BYTES, SBYTES (current_sound->data)); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1418 bcopy (SDATA (current_sound->data), current_sound->header, 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
|
1419 } |
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
|
1420 |
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 /* 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
|
1422 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
|
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 /* 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
|
1425 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
|
1426 { |
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 int len = SCHARS (attrs[SOUND_DEVICE]); |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1428 current_sound_device->file = (char *) alloca (len + 1); |
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1429 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
|
1430 } |
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
|
1431 |
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
|
1432 if (INTEGERP (attrs[SOUND_VOLUME])) |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1433 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
|
1434 else if (FLOATP (attrs[SOUND_VOLUME])) |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1435 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
|
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 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
|
1438 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
|
1439 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
|
1440 |
70718
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1441 #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
|
1442 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
|
1443 #endif |
f8a3f870d0c4
* sound.c (alsa_sound_perror, alsa_open, alsa_period_size)
Jan Djärv <jan.h.d@swipnet.se>
parents:
70363
diff
changeset
|
1444 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
|
1445 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
|
1446 |
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
|
1447 /* Open the device. */ |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1448 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
|
1449 |
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 /* Play the sound. */ |
70363
54e4c6ece57f
(Fplay_sound_internal): Dynamically allocate
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
1451 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
|
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 /* 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
|
1454 UNGCPRO; |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1455 |
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 #else /* WINDOWSNT */ |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1457 |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1458 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
|
1459 len = XSTRING (lo_file)->size; |
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1460 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
|
1461 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
|
1462 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
|
1463 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1464 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
|
1465 } |
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 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
|
1467 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1468 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
|
1469 } |
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
|
1470 /* |
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
|
1471 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
|
1472 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
|
1473 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
|
1474 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
|
1475 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
|
1476 (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
|
1477 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
|
1478 */ |
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
|
1479 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
|
1480 { |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1481 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
|
1482 } |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1483 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
|
1484 |
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
|
1485 #endif /* WINDOWSNT */ |
48456
8f7ad3143e4b
Fix spacing and adapt to GNU coding conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
48375
diff
changeset
|
1486 |
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
|
1487 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
|
1488 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
|
1489 } |
25003 | 1490 |
1491 /*********************************************************************** | |
1492 Initialization | |
1493 ***********************************************************************/ | |
1494 | |
1495 void | |
1496 syms_of_sound () | |
1497 { | |
1498 QCdevice = intern (":device"); | |
1499 staticpro (&QCdevice); | |
1500 QCvolume = intern (":volume"); | |
1501 staticpro (&QCvolume); | |
1502 Qsound = intern ("sound"); | |
1503 staticpro (&Qsound); | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
1504 Qplay_sound_functions = intern ("play-sound-functions"); |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
1505 staticpro (&Qplay_sound_functions); |
25003 | 1506 |
44399
a399428859ff
(Fplay_sound_internal): Renamed from Fplay_sound.
Pavel Janík <Pavel@Janik.cz>
parents:
42754
diff
changeset
|
1507 defsubr (&Splay_sound_internal); |
25003 | 1508 } |
1509 | |
1510 | |
1511 void | |
1512 init_sound () | |
1513 { | |
1514 } | |
1515 | |
1516 #endif /* HAVE_SOUND */ | |
52401 | 1517 |
1518 /* arch-tag: dd850ad8-0433-4e2c-9cba-b7aeeccc0dbd | |
1519 (do not change this comment) */ |