Mercurial > emacs
annotate src/sound.c @ 45483:81cb13e7ce4f
*** empty log message ***
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Thu, 23 May 2002 10:20:12 +0000 |
parents | 6e2fa2a3081b |
children | 1fb8f75062c6 |
rev | line source |
---|---|
25003 | 1 /* sound.c -- sound support. |
38297
17465a81d1dd
Include Emacs' header files with #include "...".
Gerd Moellmann <gerd@gnu.org>
parents:
38215
diff
changeset
|
2 Copyright (C) 1998, 1999, 2001 Free Software Foundation. |
25003 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 Boston, MA 02111-1307, USA. */ | |
20 | |
21 /* Written by Gerd Moellmann <gerd@gnu.org>. Tested with Luigi's | |
22 driver on FreeBSD 2.2.7 with a SoundBlaster 16. */ | |
23 | |
24 #include <config.h> | |
25 | |
26 #if defined HAVE_SOUND | |
27 | |
28 #include <fcntl.h> | |
29 #include <unistd.h> | |
30 #include <sys/types.h> | |
31 #include <errno.h> | |
38297
17465a81d1dd
Include Emacs' header files with #include "...".
Gerd Moellmann <gerd@gnu.org>
parents:
38215
diff
changeset
|
32 #include "lisp.h" |
17465a81d1dd
Include Emacs' header files with #include "...".
Gerd Moellmann <gerd@gnu.org>
parents:
38215
diff
changeset
|
33 #include "dispextern.h" |
17465a81d1dd
Include Emacs' header files with #include "...".
Gerd Moellmann <gerd@gnu.org>
parents:
38215
diff
changeset
|
34 #include "atimer.h" |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
35 #include <signal.h> |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
36 #include "syssignal.h" |
25003 | 37 |
39969
21d7408e0d86
Include <sys/ioctl.h> also on systems without <soundcard.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39812
diff
changeset
|
38 #ifndef MSDOS |
21d7408e0d86
Include <sys/ioctl.h> also on systems without <soundcard.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39812
diff
changeset
|
39 #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
|
40 #endif |
21d7408e0d86
Include <sys/ioctl.h> also on systems without <soundcard.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39812
diff
changeset
|
41 |
25003 | 42 /* FreeBSD has machine/soundcard.h. Voxware sound driver docs mention |
43 sys/soundcard.h. So, let's try whatever's there. */ | |
44 | |
45 #ifdef HAVE_MACHINE_SOUNDCARD_H | |
46 #include <machine/soundcard.h> | |
47 #endif | |
48 #ifdef HAVE_SYS_SOUNDCARD_H | |
49 #include <sys/soundcard.h> | |
50 #endif | |
30079
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
51 #ifdef HAVE_SOUNDCARD_H |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
52 #include <soundcard.h> |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
53 #endif |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
54 |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
55 #ifndef DEFAULT_SOUND_DEVICE |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
56 #define DEFAULT_SOUND_DEVICE "/dev/dsp" |
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
57 #endif |
25003 | 58 |
59 #define abs(X) ((X) < 0 ? -(X) : (X)) | |
60 | |
61 /* Structure forward declarations. */ | |
62 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
63 struct sound; |
25003 | 64 struct sound_device; |
65 | |
66 /* The file header of RIFF-WAVE files (*.wav). Files are always in | |
67 little-endian byte-order. */ | |
68 | |
69 struct wav_header | |
70 { | |
71 u_int32_t magic; | |
72 u_int32_t length; | |
73 u_int32_t chunk_type; | |
74 u_int32_t chunk_format; | |
75 u_int32_t chunk_length; | |
76 u_int16_t format; | |
77 u_int16_t channels; | |
78 u_int32_t sample_rate; | |
79 u_int32_t bytes_per_second; | |
80 u_int16_t sample_size; | |
81 u_int16_t precision; | |
82 u_int32_t chunk_data; | |
83 u_int32_t data_length; | |
84 }; | |
85 | |
86 /* The file header of Sun adio files (*.au). Files are always in | |
87 big-endian byte-order. */ | |
88 | |
89 struct au_header | |
90 { | |
91 /* ASCII ".snd" */ | |
92 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
|
93 |
25003 | 94 /* Offset of data part from start of file. Minimum value is 24. */ |
95 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
|
96 |
25003 | 97 /* Size of data part, 0xffffffff if unknown. */ |
98 u_int32_t data_size; | |
99 | |
100 /* Data encoding format. | |
101 1 8-bit ISDN u-law | |
102 2 8-bit linear PCM (REF-PCM) | |
103 3 16-bit linear PCM | |
104 4 24-bit linear PCM | |
105 5 32-bit linear PCM | |
106 6 32-bit IEEE floating-point | |
107 7 64-bit IEEE floating-point | |
108 23 8-bit u-law compressed using CCITT 0.721 ADPCM voice data | |
109 encoding scheme. */ | |
110 u_int32_t encoding; | |
111 | |
112 /* Number of samples per second. */ | |
113 u_int32_t sample_rate; | |
114 | |
115 /* Number of interleaved channels. */ | |
116 u_int32_t channels; | |
117 }; | |
118 | |
119 /* Maximum of all sound file headers sizes. */ | |
120 | |
121 #define MAX_SOUND_HEADER_BYTES \ | |
122 max (sizeof (struct wav_header), sizeof (struct au_header)) | |
123 | |
124 /* Interface structure for sound devices. */ | |
125 | |
126 struct sound_device | |
127 { | |
128 /* The name of the device or null meaning use a default device name. */ | |
129 char *file; | |
130 | |
131 /* File descriptor of the device. */ | |
132 int fd; | |
133 | |
134 /* Device-dependent format. */ | |
135 int format; | |
136 | |
137 /* Volume (0..100). Zero means unspecified. */ | |
138 int volume; | |
139 | |
140 /* Sample size. */ | |
141 int sample_size; | |
142 | |
143 /* Sample rate. */ | |
144 int sample_rate; | |
145 | |
146 /* Bytes per second. */ | |
147 int bps; | |
148 | |
149 /* 1 = mono, 2 = stereo, 0 = don't set. */ | |
150 int channels; | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
151 |
25003 | 152 /* Open device SD. */ |
153 void (* open) P_ ((struct sound_device *sd)); | |
154 | |
155 /* Close device SD. */ | |
156 void (* close) P_ ((struct sound_device *sd)); | |
157 | |
158 /* Configure SD accoring to device-dependent parameters. */ | |
159 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
|
160 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
161 /* Choose a device-dependent format for outputting sound S. */ |
25003 | 162 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
|
163 struct sound *s)); |
25003 | 164 |
165 /* Write NYBTES bytes from BUFFER to device SD. */ | |
166 void (* write) P_ ((struct sound_device *sd, char *buffer, int nbytes)); | |
167 | |
168 /* A place for devices to store additional data. */ | |
169 void *data; | |
170 }; | |
171 | |
172 /* An enumerator for each supported sound file type. */ | |
173 | |
174 enum sound_type | |
175 { | |
176 RIFF, | |
177 SUN_AUDIO | |
178 }; | |
179 | |
180 /* Interface structure for sound files. */ | |
181 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
182 struct sound |
25003 | 183 { |
184 /* The type of the file. */ | |
185 enum sound_type type; | |
186 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
187 /* File descriptor of a sound file. */ |
25003 | 188 int fd; |
189 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
190 /* 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
|
191 read from the start of a sound file. */ |
25003 | 192 char *header; |
193 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
194 /* 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
|
195 MAX_SOUND_HEADER_BYTES. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
196 int header_size; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
197 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
198 /* Sound data, if a string. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
199 Lisp_Object data; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
200 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
201 /* 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
|
202 void (* play) P_ ((struct sound *s, struct sound_device *sd)); |
25003 | 203 }; |
204 | |
205 /* Indices of attributes in a sound attributes vector. */ | |
206 | |
207 enum sound_attr | |
208 { | |
209 SOUND_FILE, | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
210 SOUND_DATA, |
25003 | 211 SOUND_DEVICE, |
212 SOUND_VOLUME, | |
213 SOUND_ATTR_SENTINEL | |
214 }; | |
215 | |
216 /* Symbols. */ | |
217 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
218 extern Lisp_Object QCfile, QCdata; |
25003 | 219 Lisp_Object QCvolume, QCdevice; |
220 Lisp_Object Qsound; | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
221 Lisp_Object Qplay_sound_functions; |
25003 | 222 |
44399
a399428859ff
(Fplay_sound_internal): Renamed from Fplay_sound.
Pavel Janík <Pavel@Janik.cz>
parents:
42754
diff
changeset
|
223 /* These are set during `play-sound-internal' so that sound_cleanup has |
25003 | 224 access to them. */ |
225 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
226 struct sound_device *current_sound_device; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
227 struct sound *current_sound; |
25003 | 228 |
229 /* Function prototypes. */ | |
230 | |
231 static void vox_open P_ ((struct sound_device *)); | |
232 static void vox_configure P_ ((struct sound_device *)); | |
233 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
|
234 static void vox_choose_format P_ ((struct sound_device *, struct sound *)); |
25003 | 235 static void vox_init P_ ((struct sound_device *)); |
236 static void vox_write P_ ((struct sound_device *, char *, int)); | |
237 static void sound_perror P_ ((char *)); | |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
238 static void sound_warning P_ ((char *)); |
25003 | 239 static int parse_sound P_ ((Lisp_Object, Lisp_Object *)); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
240 static void find_sound_type P_ ((struct sound *)); |
25003 | 241 static u_int32_t le2hl P_ ((u_int32_t)); |
242 static u_int16_t le2hs P_ ((u_int16_t)); | |
243 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
|
244 static int wav_init P_ ((struct sound *)); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
245 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
|
246 static int au_init P_ ((struct sound *)); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
247 static void au_play P_ ((struct sound *, struct sound_device *)); |
25003 | 248 |
25722
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
249 #if 0 /* Currently not used. */ |
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
250 static u_int16_t be2hs P_ ((u_int16_t)); |
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
251 #endif |
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
252 |
25003 | 253 |
254 | |
255 /*********************************************************************** | |
256 General | |
257 ***********************************************************************/ | |
258 | |
259 /* Like perror, but signals an error. */ | |
260 | |
261 static void | |
262 sound_perror (msg) | |
263 char *msg; | |
264 { | |
40745
1622bfdfe454
(sound_perror): Save errno from being clobbered.
Andreas Schwab <schwab@suse.de>
parents:
40364
diff
changeset
|
265 int saved_errno = errno; |
1622bfdfe454
(sound_perror): Save errno from being clobbered.
Andreas Schwab <schwab@suse.de>
parents:
40364
diff
changeset
|
266 |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
267 turn_on_atimers (1); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
268 #ifdef SIGIO |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
269 sigunblock (sigmask (SIGIO)); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
270 #endif |
40745
1622bfdfe454
(sound_perror): Save errno from being clobbered.
Andreas Schwab <schwab@suse.de>
parents:
40364
diff
changeset
|
271 if (saved_errno != 0) |
1622bfdfe454
(sound_perror): Save errno from being clobbered.
Andreas Schwab <schwab@suse.de>
parents:
40364
diff
changeset
|
272 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
|
273 else |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
274 error ("%s", msg); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
275 } |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
276 |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
277 |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
278 /* Display a warning message. */ |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
279 |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
280 static void |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
281 sound_warning (msg) |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
282 char *msg; |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
283 { |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
284 message (msg); |
25003 | 285 } |
286 | |
287 | |
288 /* Parse sound specification SOUND, and fill ATTRS with what is | |
289 found. Value is non-zero if SOUND Is a valid sound specification. | |
290 A valid sound specification is a list starting with the symbol | |
291 `sound'. The rest of the list is a property list which may | |
292 contain the following key/value pairs: | |
293 | |
294 - `:file FILE' | |
295 | |
296 FILE is the sound file to play. If it isn't an absolute name, | |
297 it's searched under `data-directory'. | |
298 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
299 - `:data DATA' |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
300 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
301 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
|
302 may be present, but not both. |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
303 |
25003 | 304 - `:device DEVICE' |
305 | |
306 DEVICE is the name of the device to play on, e.g. "/dev/dsp2". | |
307 If not specified, a default device is used. | |
308 | |
309 - `:volume VOL' | |
310 | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
311 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
|
312 range [0, 1]. */ |
25003 | 313 |
314 static int | |
315 parse_sound (sound, attrs) | |
316 Lisp_Object sound; | |
317 Lisp_Object *attrs; | |
318 { | |
319 /* SOUND must be a list starting with the symbol `sound'. */ | |
320 if (!CONSP (sound) || !EQ (XCAR (sound), Qsound)) | |
321 return 0; | |
322 | |
323 sound = XCDR (sound); | |
324 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
|
325 attrs[SOUND_DATA] = Fplist_get (sound, QCdata); |
25003 | 326 attrs[SOUND_DEVICE] = Fplist_get (sound, QCdevice); |
327 attrs[SOUND_VOLUME] = Fplist_get (sound, QCvolume); | |
328 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
329 /* File name or data must be specified. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
330 if (!STRINGP (attrs[SOUND_FILE]) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
331 && !STRINGP (attrs[SOUND_DATA])) |
25003 | 332 return 0; |
333 | |
334 /* Volume must be in the range 0..100 or unspecified. */ | |
335 if (!NILP (attrs[SOUND_VOLUME])) | |
336 { | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
337 if (INTEGERP (attrs[SOUND_VOLUME])) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
338 { |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
339 if (XINT (attrs[SOUND_VOLUME]) < 0 |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
340 || XINT (attrs[SOUND_VOLUME]) > 100) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
341 return 0; |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
342 } |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
343 else if (FLOATP (attrs[SOUND_VOLUME])) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
344 { |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
345 if (XFLOAT_DATA (attrs[SOUND_VOLUME]) < 0 |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
346 || XFLOAT_DATA (attrs[SOUND_VOLUME]) > 1) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
347 return 0; |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
348 } |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
349 else |
25003 | 350 return 0; |
351 } | |
352 | |
353 /* Device must be a string or unspecified. */ | |
354 if (!NILP (attrs[SOUND_DEVICE]) | |
355 && !STRINGP (attrs[SOUND_DEVICE])) | |
356 return 0; | |
357 | |
358 return 1; | |
359 } | |
360 | |
361 | |
362 /* 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
|
363 S is the sound file structure to fill in. */ |
25003 | 364 |
365 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
366 find_sound_type (s) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
367 struct sound *s; |
25003 | 368 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
369 if (!wav_init (s) && !au_init (s)) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
370 error ("Unknown sound format"); |
25003 | 371 } |
372 | |
373 | |
44399
a399428859ff
(Fplay_sound_internal): Renamed from Fplay_sound.
Pavel Janík <Pavel@Janik.cz>
parents:
42754
diff
changeset
|
374 /* Function installed by play-sound-internal with record_unwind_protect. */ |
25003 | 375 |
376 static Lisp_Object | |
377 sound_cleanup (arg) | |
378 Lisp_Object arg; | |
379 { | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
380 if (current_sound_device) |
25003 | 381 { |
27635
8344762c0da2
* sound.c (sound_cleanup): Don't call device close routine if pointer is null.
Ken Raeburn <raeburn@raeburn.org>
parents:
27315
diff
changeset
|
382 if (current_sound_device->close) |
8344762c0da2
* sound.c (sound_cleanup): Don't call device close routine if pointer is null.
Ken Raeburn <raeburn@raeburn.org>
parents:
27315
diff
changeset
|
383 current_sound_device->close (current_sound_device); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
384 if (current_sound->fd > 0) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
385 emacs_close (current_sound->fd); |
25003 | 386 } |
34255
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
387 |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
388 return Qnil; |
25003 | 389 } |
390 | |
391 | |
44399
a399428859ff
(Fplay_sound_internal): Renamed from Fplay_sound.
Pavel Janík <Pavel@Janik.cz>
parents:
42754
diff
changeset
|
392 DEFUN ("play-sound-internal", Fplay_sound_internal, Splay_sound_internal, 1, 1, 0, |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
393 doc: /* Play sound SOUND. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
394 |
44399
a399428859ff
(Fplay_sound_internal): Renamed from Fplay_sound.
Pavel Janík <Pavel@Janik.cz>
parents:
42754
diff
changeset
|
395 Internal use only, use `play-sound' instead. */) |
40123
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
396 (sound) |
25003 | 397 Lisp_Object sound; |
398 { | |
399 Lisp_Object attrs[SOUND_ATTR_SENTINEL]; | |
400 Lisp_Object file; | |
401 struct gcpro gcpro1, gcpro2; | |
402 struct sound_device sd; | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
403 struct sound s; |
25003 | 404 Lisp_Object args[2]; |
405 int count = specpdl_ptr - specpdl; | |
406 | |
407 file = Qnil; | |
408 GCPRO2 (sound, file); | |
409 bzero (&sd, sizeof sd); | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
410 bzero (&s, sizeof s); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
411 current_sound_device = &sd; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
412 current_sound = &s; |
25003 | 413 record_unwind_protect (sound_cleanup, Qnil); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
414 s.header = (char *) alloca (MAX_SOUND_HEADER_BYTES); |
25003 | 415 |
416 /* Parse the sound specification. Give up if it is invalid. */ | |
417 if (!parse_sound (sound, attrs)) | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
418 error ("Invalid sound specification"); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
419 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
420 if (STRINGP (attrs[SOUND_FILE])) |
25003 | 421 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
422 /* Open the sound file. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
423 s.fd = openp (Fcons (Vdata_directory, Qnil), |
45006
6e2fa2a3081b
(Fplay_sound_internal): Update call to openp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44399
diff
changeset
|
424 attrs[SOUND_FILE], Qnil, &file, Qnil); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
425 if (s.fd < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
426 sound_perror ("Could not open sound file"); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
427 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
428 /* Read the first bytes from the file. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
429 s.header_size = emacs_read (s.fd, s.header, MAX_SOUND_HEADER_BYTES); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
430 if (s.header_size < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
431 sound_perror ("Invalid sound file header"); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
432 } |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
433 else |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
434 { |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
435 s.data = attrs[SOUND_DATA]; |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
436 s.header_size = min (MAX_SOUND_HEADER_BYTES, STRING_BYTES (XSTRING (s.data))); |
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
437 bcopy (XSTRING (s.data)->data, s.header, s.header_size); |
25003 | 438 } |
439 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
440 /* Find out the type of sound. Give up if we can't tell. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
441 find_sound_type (&s); |
25003 | 442 |
443 /* Set up a device. */ | |
444 if (STRINGP (attrs[SOUND_DEVICE])) | |
445 { | |
446 int len = XSTRING (attrs[SOUND_DEVICE])->size; | |
447 sd.file = (char *) alloca (len + 1); | |
448 strcpy (sd.file, XSTRING (attrs[SOUND_DEVICE])->data); | |
449 } | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
450 |
25003 | 451 if (INTEGERP (attrs[SOUND_VOLUME])) |
452 sd.volume = XFASTINT (attrs[SOUND_VOLUME]); | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
453 else if (FLOATP (attrs[SOUND_VOLUME])) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
454 sd.volume = XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100; |
25003 | 455 |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
456 args[0] = Qplay_sound_functions; |
25003 | 457 args[1] = sound; |
29717
acaa36b47f50
fix up more Lisp_Object/int conversion issues
Ken Raeburn <raeburn@raeburn.org>
parents:
27635
diff
changeset
|
458 Frun_hook_with_args (2, args); |
25003 | 459 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
460 /* There is only one type of device we currently support, the VOX |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
461 sound driver. Set up the device interface functions for that |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
462 device. */ |
25003 | 463 vox_init (&sd); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
464 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
465 /* Open the device. */ |
25003 | 466 sd.open (&sd); |
467 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
468 /* Play the sound. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
469 s.play (&s, &sd); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
470 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
471 /* Close the input file, if any. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
472 if (!STRINGP (s.data)) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
473 { |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
474 emacs_close (s.fd); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
475 s.fd = -1; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
476 } |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
477 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
478 /* Close the device. */ |
25003 | 479 sd.close (&sd); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
480 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
481 /* Clean up. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
482 current_sound_device = NULL; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
483 current_sound = NULL; |
25003 | 484 UNGCPRO; |
485 unbind_to (count, Qnil); | |
486 return Qnil; | |
487 } | |
488 | |
489 | |
490 /*********************************************************************** | |
491 Byte-order Conversion | |
492 ***********************************************************************/ | |
493 | |
494 /* Convert 32-bit value VALUE which is in little-endian byte-order | |
495 to host byte-order. */ | |
496 | |
497 static u_int32_t | |
498 le2hl (value) | |
499 u_int32_t value; | |
500 { | |
501 #ifdef WORDS_BIG_ENDIAN | |
502 unsigned char *p = (unsigned char *) &value; | |
503 value = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24); | |
504 #endif | |
505 return value; | |
506 } | |
507 | |
508 | |
509 /* Convert 16-bit value VALUE which is in little-endian byte-order | |
510 to host byte-order. */ | |
511 | |
512 static u_int16_t | |
513 le2hs (value) | |
514 u_int16_t value; | |
515 { | |
516 #ifdef WORDS_BIG_ENDIAN | |
517 unsigned char *p = (unsigned char *) &value; | |
518 value = p[0] + (p[1] << 8); | |
519 #endif | |
520 return value; | |
521 } | |
522 | |
523 | |
524 /* Convert 32-bit value VALUE which is in big-endian byte-order | |
525 to host byte-order. */ | |
526 | |
527 static u_int32_t | |
528 be2hl (value) | |
529 u_int32_t value; | |
530 { | |
531 #ifndef WORDS_BIG_ENDIAN | |
532 unsigned char *p = (unsigned char *) &value; | |
533 value = p[3] + (p[2] << 8) + (p[1] << 16) + (p[0] << 24); | |
534 #endif | |
535 return value; | |
536 } | |
537 | |
538 | |
25722
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
539 #if 0 /* Currently not used. */ |
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
540 |
25003 | 541 /* Convert 16-bit value VALUE which is in big-endian byte-order |
542 to host byte-order. */ | |
543 | |
544 static u_int16_t | |
545 be2hs (value) | |
546 u_int16_t value; | |
547 { | |
548 #ifndef WORDS_BIG_ENDIAN | |
549 unsigned char *p = (unsigned char *) &value; | |
550 value = p[1] + (p[0] << 8); | |
551 #endif | |
552 return value; | |
553 } | |
554 | |
25722
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
555 #endif /* 0 */ |
25003 | 556 |
557 | |
558 /*********************************************************************** | |
559 RIFF-WAVE (*.wav) | |
560 ***********************************************************************/ | |
561 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
562 /* Try to initialize sound file S from S->header. S->header |
25003 | 563 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the |
564 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
|
565 functions in S and convert header fields to host byte-order. |
25003 | 566 Value is non-zero if the file is a WAV file. */ |
567 | |
568 static int | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
569 wav_init (s) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
570 struct sound *s; |
25003 | 571 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
572 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
|
573 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
574 if (s->header_size < sizeof *header |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
575 || bcmp (s->header, "RIFF", 4) != 0) |
25003 | 576 return 0; |
577 | |
578 /* WAV files are in little-endian order. Convert the header | |
579 if on a big-endian machine. */ | |
580 header->magic = le2hl (header->magic); | |
581 header->length = le2hl (header->length); | |
582 header->chunk_type = le2hl (header->chunk_type); | |
583 header->chunk_format = le2hl (header->chunk_format); | |
584 header->chunk_length = le2hl (header->chunk_length); | |
585 header->format = le2hs (header->format); | |
586 header->channels = le2hs (header->channels); | |
587 header->sample_rate = le2hl (header->sample_rate); | |
588 header->bytes_per_second = le2hl (header->bytes_per_second); | |
589 header->sample_size = le2hs (header->sample_size); | |
590 header->precision = le2hs (header->precision); | |
591 header->chunk_data = le2hl (header->chunk_data); | |
592 header->data_length = le2hl (header->data_length); | |
593 | |
594 /* 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
|
595 s->type = RIFF; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
596 s->play = wav_play; |
25003 | 597 |
598 return 1; | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
599 } |
25003 | 600 |
601 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
602 /* Play RIFF-WAVE audio file S on sound device SD. */ |
25003 | 603 |
604 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
605 wav_play (s, sd) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
606 struct sound *s; |
25003 | 607 struct sound_device *sd; |
608 { | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
609 struct wav_header *header = (struct wav_header *) s->header; |
25003 | 610 |
611 /* Let the device choose a suitable device-dependent format | |
612 for the file. */ | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
613 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
|
614 |
25003 | 615 /* Configure the device. */ |
616 sd->sample_size = header->sample_size; | |
617 sd->sample_rate = header->sample_rate; | |
618 sd->bps = header->bytes_per_second; | |
619 sd->channels = header->channels; | |
620 sd->configure (sd); | |
621 | |
622 /* Copy sound data to the device. The WAV file specification is | |
623 actually more complex. This simple scheme worked with all WAV | |
624 files I found so far. If someone feels inclined to implement the | |
625 whole RIFF-WAVE spec, please do. */ | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
626 if (STRINGP (s->data)) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
627 sd->write (sd, XSTRING (s->data)->data + sizeof *header, |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
628 STRING_BYTES (XSTRING (s->data)) - sizeof *header); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
629 else |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
630 { |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
631 char *buffer; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
632 int nbytes; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
633 int blksize = 2048; |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
634 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
635 buffer = (char *) alloca (blksize); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
636 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
|
637 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
638 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
|
639 sd->write (sd, buffer, nbytes); |
25003 | 640 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
641 if (nbytes < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
642 sound_perror ("Error reading sound file"); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
643 } |
25003 | 644 } |
645 | |
646 | |
647 | |
648 /*********************************************************************** | |
649 Sun Audio (*.au) | |
650 ***********************************************************************/ | |
651 | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
652 /* Sun audio file encodings. */ |
25003 | 653 |
654 enum au_encoding | |
655 { | |
656 AU_ENCODING_ULAW_8 = 1, | |
657 AU_ENCODING_8, | |
658 AU_ENCODING_16, | |
659 AU_ENCODING_24, | |
660 AU_ENCODING_32, | |
661 AU_ENCODING_IEEE32, | |
662 AU_ENCODING_IEEE64, | |
663 AU_COMPRESSED = 23 | |
664 }; | |
665 | |
666 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
667 /* Try to initialize sound file S from S->header. S->header |
25003 | 668 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the |
669 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
|
670 functions in S and convert header fields to host byte-order. |
25003 | 671 Value is non-zero if the file is an AU file. */ |
672 | |
673 static int | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
674 au_init (s) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
675 struct sound *s; |
25003 | 676 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
677 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
|
678 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
679 if (s->header_size < sizeof *header |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
680 || bcmp (s->header, ".snd", 4) != 0) |
25003 | 681 return 0; |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
682 |
25003 | 683 header->magic_number = be2hl (header->magic_number); |
684 header->data_offset = be2hl (header->data_offset); | |
685 header->data_size = be2hl (header->data_size); | |
686 header->encoding = be2hl (header->encoding); | |
687 header->sample_rate = be2hl (header->sample_rate); | |
688 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
|
689 |
25003 | 690 /* 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
|
691 s->type = SUN_AUDIO; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
692 s->play = au_play; |
25003 | 693 |
694 return 1; | |
695 } | |
696 | |
697 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
698 /* Play Sun audio file S on sound device SD. */ |
25003 | 699 |
700 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
701 au_play (s, sd) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
702 struct sound *s; |
25003 | 703 struct sound_device *sd; |
704 { | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
705 struct au_header *header = (struct au_header *) s->header; |
25003 | 706 |
707 sd->sample_size = 0; | |
708 sd->sample_rate = header->sample_rate; | |
709 sd->bps = 0; | |
710 sd->channels = header->channels; | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
711 sd->choose_format (sd, s); |
25003 | 712 sd->configure (sd); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
713 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
714 if (STRINGP (s->data)) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
715 sd->write (sd, XSTRING (s->data)->data + header->data_offset, |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
716 STRING_BYTES (XSTRING (s->data)) - header->data_offset); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
717 else |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
718 { |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
719 int blksize = 2048; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
720 char *buffer; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
721 int nbytes; |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
722 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
723 /* Seek */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
724 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
|
725 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
726 /* Copy sound data to the device. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
727 buffer = (char *) alloca (blksize); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
728 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
|
729 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
|
730 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
731 if (nbytes < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
732 sound_perror ("Error reading sound file"); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
733 } |
25003 | 734 } |
735 | |
736 | |
737 | |
738 /*********************************************************************** | |
739 Voxware Driver Interface | |
740 ***********************************************************************/ | |
741 | |
742 /* This driver is available on GNU/Linux, and the free BSDs. FreeBSD | |
743 has a compatible own driver aka Luigi's driver. */ | |
744 | |
745 | |
746 /* Open device SD. If SD->file is non-null, open that device, | |
747 otherwise use a default device name. */ | |
748 | |
749 static void | |
750 vox_open (sd) | |
751 struct sound_device *sd; | |
752 { | |
753 char *file; | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
754 |
25003 | 755 /* Open the sound device. Default is /dev/dsp. */ |
756 if (sd->file) | |
757 file = sd->file; | |
758 else | |
30079
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
759 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
|
760 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
25722
diff
changeset
|
761 sd->fd = emacs_open (file, O_WRONLY, 0); |
25003 | 762 if (sd->fd < 0) |
763 sound_perror (file); | |
764 } | |
765 | |
766 | |
767 /* Configure device SD from parameters in it. */ | |
768 | |
769 static void | |
770 vox_configure (sd) | |
771 struct sound_device *sd; | |
772 { | |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
773 int val; |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
774 |
25003 | 775 xassert (sd->fd >= 0); |
776 | |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
777 /* 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
|
778 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
|
779 troubles. */ |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
780 turn_on_atimers (0); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
781 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
782 sigblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
783 #endif |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
784 |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
785 val = sd->format; |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
786 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
|
787 || val != sd->format) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
788 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
|
789 |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
790 val = sd->channels != 1; |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
791 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
|
792 || val != (sd->channels != 1)) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
793 sound_perror ("Could not set stereo/mono"); |
25003 | 794 |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
795 /* 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
|
796 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
|
797 if (sd->sample_rate > 0) |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
798 { |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
799 val = sd->sample_rate; |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
800 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
|
801 sound_perror ("Could not set sound speed"); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
802 else if (val != sd->sample_rate) |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
803 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
|
804 } |
25003 | 805 |
34255
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
806 if (sd->volume > 0) |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
807 { |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
808 int volume = sd->volume & 0xff; |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
809 volume |= volume << 8; |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
810 /* 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
|
811 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
|
812 } |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
813 |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
814 turn_on_atimers (1); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
815 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
816 sigunblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
817 #endif |
25003 | 818 } |
819 | |
820 | |
821 /* Close device SD if it is open. */ | |
822 | |
823 static void | |
824 vox_close (sd) | |
825 struct sound_device *sd; | |
826 { | |
827 if (sd->fd >= 0) | |
828 { | |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
829 /* 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
|
830 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
|
831 troubles. */ |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
832 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
833 sigblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
834 #endif |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
835 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
|
836 |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
837 /* Flush sound data, and reset the device. */ |
25003 | 838 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
|
839 |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
840 turn_on_atimers (1); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
841 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
842 sigunblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
843 #endif |
25003 | 844 |
845 /* 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
|
846 emacs_close (sd->fd); |
25003 | 847 sd->fd = -1; |
848 } | |
849 } | |
850 | |
851 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
852 /* Choose device-dependent format for device SD from sound file S. */ |
25003 | 853 |
854 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
855 vox_choose_format (sd, s) |
25003 | 856 struct sound_device *sd; |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
857 struct sound *s; |
25003 | 858 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
859 if (s->type == RIFF) |
25003 | 860 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
861 struct wav_header *h = (struct wav_header *) s->header; |
25003 | 862 if (h->precision == 8) |
863 sd->format = AFMT_U8; | |
864 else if (h->precision == 16) | |
865 sd->format = AFMT_S16_LE; | |
866 else | |
867 error ("Unsupported WAV file format"); | |
868 } | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
869 else if (s->type == SUN_AUDIO) |
25003 | 870 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
871 struct au_header *header = (struct au_header *) s->header; |
25003 | 872 switch (header->encoding) |
873 { | |
874 case AU_ENCODING_ULAW_8: | |
875 case AU_ENCODING_IEEE32: | |
876 case AU_ENCODING_IEEE64: | |
877 sd->format = AFMT_MU_LAW; | |
878 break; | |
42754
158482d8af9d
(Fplay_sound): Initialize header_size also for :data case.
Pavel Janík <Pavel@Janik.cz>
parents:
42534
diff
changeset
|
879 |
25003 | 880 case AU_ENCODING_8: |
881 case AU_ENCODING_16: | |
882 case AU_ENCODING_24: | |
883 case AU_ENCODING_32: | |
884 sd->format = AFMT_S16_LE; | |
885 break; | |
886 | |
887 default: | |
888 error ("Unsupported AU file format"); | |
889 } | |
890 } | |
891 else | |
892 abort (); | |
893 } | |
894 | |
895 | |
896 /* Initialize device SD. Set up the interface functions in the device | |
897 structure. */ | |
898 | |
899 static void | |
900 vox_init (sd) | |
901 struct sound_device *sd; | |
902 { | |
903 sd->fd = -1; | |
904 sd->open = vox_open; | |
905 sd->close = vox_close; | |
906 sd->configure = vox_configure; | |
907 sd->choose_format = vox_choose_format; | |
908 sd->write = vox_write; | |
909 } | |
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; | |
917 char *buffer; | |
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 | |
925 | |
926 | |
927 /*********************************************************************** | |
928 Initialization | |
929 ***********************************************************************/ | |
930 | |
931 void | |
932 syms_of_sound () | |
933 { | |
934 QCdevice = intern (":device"); | |
935 staticpro (&QCdevice); | |
936 QCvolume = intern (":volume"); | |
937 staticpro (&QCvolume); | |
938 Qsound = intern ("sound"); | |
939 staticpro (&Qsound); | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
940 Qplay_sound_functions = intern ("play-sound-functions"); |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
941 staticpro (&Qplay_sound_functions); |
25003 | 942 |
44399
a399428859ff
(Fplay_sound_internal): Renamed from Fplay_sound.
Pavel Janík <Pavel@Janik.cz>
parents:
42754
diff
changeset
|
943 defsubr (&Splay_sound_internal); |
25003 | 944 } |
945 | |
946 | |
947 void | |
948 init_sound () | |
949 { | |
950 } | |
951 | |
952 #endif /* HAVE_SOUND */ |