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