Mercurial > emacs
annotate src/sound.c @ 40409:216728b10960
(eval-defun): Doc fix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 28 Oct 2001 14:15:14 +0000 |
parents | f7b039994118 |
children | 1622bfdfe454 |
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; | |
93 | |
94 /* Offset of data part from start of file. Minimum value is 24. */ | |
95 u_int32_t data_offset; | |
96 | |
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; | |
151 | |
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)); | |
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. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
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 |
223 /* These are set during `play-sound' so that sound_cleanup has | |
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 { | |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
265 turn_on_atimers (1); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
266 #ifdef SIGIO |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
267 sigunblock (sigmask (SIGIO)); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
268 #endif |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
269 if (errno != 0) |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
270 error ("%s: %s", msg, strerror (errno)); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
271 else |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
272 error ("%s", msg); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
273 } |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
274 |
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 /* Display a warning message. */ |
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 static void |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
279 sound_warning (msg) |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
280 char *msg; |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
281 { |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
282 message (msg); |
25003 | 283 } |
284 | |
285 | |
286 /* Parse sound specification SOUND, and fill ATTRS with what is | |
287 found. Value is non-zero if SOUND Is a valid sound specification. | |
288 A valid sound specification is a list starting with the symbol | |
289 `sound'. The rest of the list is a property list which may | |
290 contain the following key/value pairs: | |
291 | |
292 - `:file FILE' | |
293 | |
294 FILE is the sound file to play. If it isn't an absolute name, | |
295 it's searched under `data-directory'. | |
296 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
297 - `:data DATA' |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
298 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
299 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
|
300 may be present, but not both. |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
301 |
25003 | 302 - `:device DEVICE' |
303 | |
304 DEVICE is the name of the device to play on, e.g. "/dev/dsp2". | |
305 If not specified, a default device is used. | |
306 | |
307 - `:volume VOL' | |
308 | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
309 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
|
310 range [0, 1]. */ |
25003 | 311 |
312 static int | |
313 parse_sound (sound, attrs) | |
314 Lisp_Object sound; | |
315 Lisp_Object *attrs; | |
316 { | |
317 /* SOUND must be a list starting with the symbol `sound'. */ | |
318 if (!CONSP (sound) || !EQ (XCAR (sound), Qsound)) | |
319 return 0; | |
320 | |
321 sound = XCDR (sound); | |
322 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
|
323 attrs[SOUND_DATA] = Fplist_get (sound, QCdata); |
25003 | 324 attrs[SOUND_DEVICE] = Fplist_get (sound, QCdevice); |
325 attrs[SOUND_VOLUME] = Fplist_get (sound, QCvolume); | |
326 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
327 /* File name or data must be specified. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
328 if (!STRINGP (attrs[SOUND_FILE]) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
329 && !STRINGP (attrs[SOUND_DATA])) |
25003 | 330 return 0; |
331 | |
332 /* Volume must be in the range 0..100 or unspecified. */ | |
333 if (!NILP (attrs[SOUND_VOLUME])) | |
334 { | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
335 if (INTEGERP (attrs[SOUND_VOLUME])) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
336 { |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
337 if (XINT (attrs[SOUND_VOLUME]) < 0 |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
338 || XINT (attrs[SOUND_VOLUME]) > 100) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
339 return 0; |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
340 } |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
341 else if (FLOATP (attrs[SOUND_VOLUME])) |
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 if (XFLOAT_DATA (attrs[SOUND_VOLUME]) < 0 |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
344 || XFLOAT_DATA (attrs[SOUND_VOLUME]) > 1) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
345 return 0; |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
346 } |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
347 else |
25003 | 348 return 0; |
349 } | |
350 | |
351 /* Device must be a string or unspecified. */ | |
352 if (!NILP (attrs[SOUND_DEVICE]) | |
353 && !STRINGP (attrs[SOUND_DEVICE])) | |
354 return 0; | |
355 | |
356 return 1; | |
357 } | |
358 | |
359 | |
360 /* 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
|
361 S is the sound file structure to fill in. */ |
25003 | 362 |
363 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
364 find_sound_type (s) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
365 struct sound *s; |
25003 | 366 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
367 if (!wav_init (s) && !au_init (s)) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
368 error ("Unknown sound format"); |
25003 | 369 } |
370 | |
371 | |
372 /* Function installed by play-sound with record_unwind_protect. */ | |
373 | |
374 static Lisp_Object | |
375 sound_cleanup (arg) | |
376 Lisp_Object arg; | |
377 { | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
378 if (current_sound_device) |
25003 | 379 { |
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
|
380 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
|
381 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
|
382 if (current_sound->fd > 0) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
383 emacs_close (current_sound->fd); |
25003 | 384 } |
34255
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
385 |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
386 return Qnil; |
25003 | 387 } |
388 | |
389 | |
390 DEFUN ("play-sound", Fplay_sound, Splay_sound, 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
|
391 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
|
392 SOUND is a list of the form `(sound KEYWORD VALUE...)'. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
393 The following keywords are recognized: |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
394 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
395 :file FILE.- read sound data from FILE. If FILE isn't an |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
396 absolute file name, it is searched in `data-directory'. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
397 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
398 :data DATA - read sound data from string DATA. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
399 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
400 Exactly one of :file or :data must be present. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
401 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
402 :volume VOL - set volume to VOL. VOL must an integer in the |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
403 range 0..100 or a float in the range 0..1.0. If not specified, |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
404 don't change the volume setting of the sound device. |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
405 |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
406 :device DEVICE - play sound on DEVICE. If not specified, |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
407 a system-dependent default device name is used. */) |
e528f2adeed4
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
39969
diff
changeset
|
408 (sound) |
25003 | 409 Lisp_Object sound; |
410 { | |
411 Lisp_Object attrs[SOUND_ATTR_SENTINEL]; | |
412 Lisp_Object file; | |
413 struct gcpro gcpro1, gcpro2; | |
414 struct sound_device sd; | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
415 struct sound s; |
25003 | 416 Lisp_Object args[2]; |
417 int count = specpdl_ptr - specpdl; | |
418 | |
419 file = Qnil; | |
420 GCPRO2 (sound, file); | |
421 bzero (&sd, sizeof sd); | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
422 bzero (&s, sizeof s); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
423 current_sound_device = &sd; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
424 current_sound = &s; |
25003 | 425 record_unwind_protect (sound_cleanup, Qnil); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
426 s.header = (char *) alloca (MAX_SOUND_HEADER_BYTES); |
25003 | 427 |
428 /* Parse the sound specification. Give up if it is invalid. */ | |
429 if (!parse_sound (sound, attrs)) | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
430 error ("Invalid sound specification"); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
431 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
432 if (STRINGP (attrs[SOUND_FILE])) |
25003 | 433 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
434 /* Open the sound file. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
435 s.fd = openp (Fcons (Vdata_directory, Qnil), |
39812
66e0816837a8
Update calls to openp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39682
diff
changeset
|
436 attrs[SOUND_FILE], Qnil, &file, 0); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
437 if (s.fd < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
438 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
|
439 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
440 /* Read the first bytes from the file. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
441 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
|
442 if (s.header_size < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
443 sound_perror ("Invalid sound file header"); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
444 } |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
445 else |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
446 { |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
447 s.data = attrs[SOUND_DATA]; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
448 bcopy (XSTRING (s.data)->data, s.header, |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
449 min (MAX_SOUND_HEADER_BYTES, STRING_BYTES (XSTRING (s.data)))); |
25003 | 450 } |
451 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
452 /* 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
|
453 find_sound_type (&s); |
25003 | 454 |
455 /* Set up a device. */ | |
456 if (STRINGP (attrs[SOUND_DEVICE])) | |
457 { | |
458 int len = XSTRING (attrs[SOUND_DEVICE])->size; | |
459 sd.file = (char *) alloca (len + 1); | |
460 strcpy (sd.file, XSTRING (attrs[SOUND_DEVICE])->data); | |
461 } | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
462 |
25003 | 463 if (INTEGERP (attrs[SOUND_VOLUME])) |
464 sd.volume = XFASTINT (attrs[SOUND_VOLUME]); | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
465 else if (FLOATP (attrs[SOUND_VOLUME])) |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
466 sd.volume = XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100; |
25003 | 467 |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
468 args[0] = Qplay_sound_functions; |
25003 | 469 args[1] = sound; |
29717
acaa36b47f50
fix up more Lisp_Object/int conversion issues
Ken Raeburn <raeburn@raeburn.org>
parents:
27635
diff
changeset
|
470 Frun_hook_with_args (2, args); |
25003 | 471 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
472 /* 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
|
473 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
|
474 device. */ |
25003 | 475 vox_init (&sd); |
27146
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 /* Open the device. */ |
25003 | 478 sd.open (&sd); |
479 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
480 /* Play the sound. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
481 s.play (&s, &sd); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
482 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
483 /* Close the input file, if any. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
484 if (!STRINGP (s.data)) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
485 { |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
486 emacs_close (s.fd); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
487 s.fd = -1; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
488 } |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
489 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
490 /* Close the device. */ |
25003 | 491 sd.close (&sd); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
492 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
493 /* Clean up. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
494 current_sound_device = NULL; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
495 current_sound = NULL; |
25003 | 496 UNGCPRO; |
497 unbind_to (count, Qnil); | |
498 return Qnil; | |
499 } | |
500 | |
501 | |
502 /*********************************************************************** | |
503 Byte-order Conversion | |
504 ***********************************************************************/ | |
505 | |
506 /* Convert 32-bit value VALUE which is in little-endian byte-order | |
507 to host byte-order. */ | |
508 | |
509 static u_int32_t | |
510 le2hl (value) | |
511 u_int32_t value; | |
512 { | |
513 #ifdef WORDS_BIG_ENDIAN | |
514 unsigned char *p = (unsigned char *) &value; | |
515 value = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24); | |
516 #endif | |
517 return value; | |
518 } | |
519 | |
520 | |
521 /* Convert 16-bit value VALUE which is in little-endian byte-order | |
522 to host byte-order. */ | |
523 | |
524 static u_int16_t | |
525 le2hs (value) | |
526 u_int16_t value; | |
527 { | |
528 #ifdef WORDS_BIG_ENDIAN | |
529 unsigned char *p = (unsigned char *) &value; | |
530 value = p[0] + (p[1] << 8); | |
531 #endif | |
532 return value; | |
533 } | |
534 | |
535 | |
536 /* Convert 32-bit value VALUE which is in big-endian byte-order | |
537 to host byte-order. */ | |
538 | |
539 static u_int32_t | |
540 be2hl (value) | |
541 u_int32_t value; | |
542 { | |
543 #ifndef WORDS_BIG_ENDIAN | |
544 unsigned char *p = (unsigned char *) &value; | |
545 value = p[3] + (p[2] << 8) + (p[1] << 16) + (p[0] << 24); | |
546 #endif | |
547 return value; | |
548 } | |
549 | |
550 | |
25722
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
551 #if 0 /* Currently not used. */ |
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
552 |
25003 | 553 /* Convert 16-bit value VALUE which is in big-endian byte-order |
554 to host byte-order. */ | |
555 | |
556 static u_int16_t | |
557 be2hs (value) | |
558 u_int16_t value; | |
559 { | |
560 #ifndef WORDS_BIG_ENDIAN | |
561 unsigned char *p = (unsigned char *) &value; | |
562 value = p[1] + (p[0] << 8); | |
563 #endif | |
564 return value; | |
565 } | |
566 | |
25722
2be6ced279d3
(Fplay_sound): Remove usused variables.
Gerd Moellmann <gerd@gnu.org>
parents:
25548
diff
changeset
|
567 #endif /* 0 */ |
25003 | 568 |
569 | |
570 /*********************************************************************** | |
571 RIFF-WAVE (*.wav) | |
572 ***********************************************************************/ | |
573 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
574 /* Try to initialize sound file S from S->header. S->header |
25003 | 575 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the |
576 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
|
577 functions in S and convert header fields to host byte-order. |
25003 | 578 Value is non-zero if the file is a WAV file. */ |
579 | |
580 static int | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
581 wav_init (s) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
582 struct sound *s; |
25003 | 583 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
584 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
|
585 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
586 if (s->header_size < sizeof *header |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
587 || bcmp (s->header, "RIFF", 4) != 0) |
25003 | 588 return 0; |
589 | |
590 /* WAV files are in little-endian order. Convert the header | |
591 if on a big-endian machine. */ | |
592 header->magic = le2hl (header->magic); | |
593 header->length = le2hl (header->length); | |
594 header->chunk_type = le2hl (header->chunk_type); | |
595 header->chunk_format = le2hl (header->chunk_format); | |
596 header->chunk_length = le2hl (header->chunk_length); | |
597 header->format = le2hs (header->format); | |
598 header->channels = le2hs (header->channels); | |
599 header->sample_rate = le2hl (header->sample_rate); | |
600 header->bytes_per_second = le2hl (header->bytes_per_second); | |
601 header->sample_size = le2hs (header->sample_size); | |
602 header->precision = le2hs (header->precision); | |
603 header->chunk_data = le2hl (header->chunk_data); | |
604 header->data_length = le2hl (header->data_length); | |
605 | |
606 /* 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
|
607 s->type = RIFF; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
608 s->play = wav_play; |
25003 | 609 |
610 return 1; | |
611 } | |
612 | |
613 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
614 /* Play RIFF-WAVE audio file S on sound device SD. */ |
25003 | 615 |
616 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
617 wav_play (s, sd) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
618 struct sound *s; |
25003 | 619 struct sound_device *sd; |
620 { | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
621 struct wav_header *header = (struct wav_header *) s->header; |
25003 | 622 |
623 /* Let the device choose a suitable device-dependent format | |
624 for the file. */ | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
625 sd->choose_format (sd, s); |
25003 | 626 |
627 /* Configure the device. */ | |
628 sd->sample_size = header->sample_size; | |
629 sd->sample_rate = header->sample_rate; | |
630 sd->bps = header->bytes_per_second; | |
631 sd->channels = header->channels; | |
632 sd->configure (sd); | |
633 | |
634 /* Copy sound data to the device. The WAV file specification is | |
635 actually more complex. This simple scheme worked with all WAV | |
636 files I found so far. If someone feels inclined to implement the | |
637 whole RIFF-WAVE spec, please do. */ | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
638 if (STRINGP (s->data)) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
639 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
|
640 STRING_BYTES (XSTRING (s->data)) - sizeof *header); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
641 else |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
642 { |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
643 char *buffer; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
644 int nbytes; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
645 int blksize = 2048; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
646 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
647 buffer = (char *) alloca (blksize); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
648 lseek (s->fd, sizeof *header, SEEK_SET); |
25003 | 649 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
650 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
|
651 sd->write (sd, buffer, nbytes); |
25003 | 652 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
653 if (nbytes < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
654 sound_perror ("Error reading sound file"); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
655 } |
25003 | 656 } |
657 | |
658 | |
659 | |
660 /*********************************************************************** | |
661 Sun Audio (*.au) | |
662 ***********************************************************************/ | |
663 | |
664 /* Sun audio file encodings. */ | |
665 | |
666 enum au_encoding | |
667 { | |
668 AU_ENCODING_ULAW_8 = 1, | |
669 AU_ENCODING_8, | |
670 AU_ENCODING_16, | |
671 AU_ENCODING_24, | |
672 AU_ENCODING_32, | |
673 AU_ENCODING_IEEE32, | |
674 AU_ENCODING_IEEE64, | |
675 AU_COMPRESSED = 23 | |
676 }; | |
677 | |
678 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
679 /* Try to initialize sound file S from S->header. S->header |
25003 | 680 contains the first MAX_SOUND_HEADER_BYTES number of bytes from the |
681 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
|
682 functions in S and convert header fields to host byte-order. |
25003 | 683 Value is non-zero if the file is an AU file. */ |
684 | |
685 static int | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
686 au_init (s) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
687 struct sound *s; |
25003 | 688 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
689 struct au_header *header = (struct au_header *) s->header; |
25003 | 690 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
691 if (s->header_size < sizeof *header |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
692 || bcmp (s->header, ".snd", 4) != 0) |
25003 | 693 return 0; |
694 | |
695 header->magic_number = be2hl (header->magic_number); | |
696 header->data_offset = be2hl (header->data_offset); | |
697 header->data_size = be2hl (header->data_size); | |
698 header->encoding = be2hl (header->encoding); | |
699 header->sample_rate = be2hl (header->sample_rate); | |
700 header->channels = be2hl (header->channels); | |
701 | |
702 /* 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
|
703 s->type = SUN_AUDIO; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
704 s->play = au_play; |
25003 | 705 |
706 return 1; | |
707 } | |
708 | |
709 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
710 /* Play Sun audio file S on sound device SD. */ |
25003 | 711 |
712 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
713 au_play (s, sd) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
714 struct sound *s; |
25003 | 715 struct sound_device *sd; |
716 { | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
717 struct au_header *header = (struct au_header *) s->header; |
25003 | 718 |
719 sd->sample_size = 0; | |
720 sd->sample_rate = header->sample_rate; | |
721 sd->bps = 0; | |
722 sd->channels = header->channels; | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
723 sd->choose_format (sd, s); |
25003 | 724 sd->configure (sd); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
725 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
726 if (STRINGP (s->data)) |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
727 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
|
728 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
|
729 else |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
730 { |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
731 int blksize = 2048; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
732 char *buffer; |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
733 int nbytes; |
25003 | 734 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
735 /* Seek */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
736 lseek (s->fd, header->data_offset, SEEK_SET); |
25003 | 737 |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
738 /* Copy sound data to the device. */ |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
739 buffer = (char *) alloca (blksize); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
740 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
|
741 sd->write (sd, buffer, nbytes); |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
742 |
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
743 if (nbytes < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
744 sound_perror ("Error reading sound file"); |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
745 } |
25003 | 746 } |
747 | |
748 | |
749 | |
750 /*********************************************************************** | |
751 Voxware Driver Interface | |
752 ***********************************************************************/ | |
753 | |
754 /* This driver is available on GNU/Linux, and the free BSDs. FreeBSD | |
755 has a compatible own driver aka Luigi's driver. */ | |
756 | |
757 | |
758 /* Open device SD. If SD->file is non-null, open that device, | |
759 otherwise use a default device name. */ | |
760 | |
761 static void | |
762 vox_open (sd) | |
763 struct sound_device *sd; | |
764 { | |
765 char *file; | |
766 | |
767 /* Open the sound device. Default is /dev/dsp. */ | |
768 if (sd->file) | |
769 file = sd->file; | |
770 else | |
30079
1572612184fc
Sound support for NetBSD through "Linux emulation" support:
Ken Raeburn <raeburn@raeburn.org>
parents:
29717
diff
changeset
|
771 file = DEFAULT_SOUND_DEVICE; |
25003 | 772 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
25722
diff
changeset
|
773 sd->fd = emacs_open (file, O_WRONLY, 0); |
25003 | 774 if (sd->fd < 0) |
775 sound_perror (file); | |
776 } | |
777 | |
778 | |
779 /* Configure device SD from parameters in it. */ | |
780 | |
781 static void | |
782 vox_configure (sd) | |
783 struct sound_device *sd; | |
784 { | |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
785 int val; |
25003 | 786 |
787 xassert (sd->fd >= 0); | |
788 | |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
789 /* 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
|
790 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
|
791 troubles. */ |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
792 turn_on_atimers (0); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
793 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
794 sigblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
795 #endif |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
796 |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
797 val = sd->format; |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
798 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
|
799 || val != sd->format) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
800 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
|
801 |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
802 val = sd->channels != 1; |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
803 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
|
804 || val != (sd->channels != 1)) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
805 sound_perror ("Could not set stereo/mono"); |
25003 | 806 |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
807 /* 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
|
808 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
|
809 if (sd->sample_rate > 0) |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
810 { |
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
811 val = sd->sample_rate; |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
812 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
|
813 sound_perror ("Could not set sound speed"); |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
814 else if (val != sd->sample_rate) |
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
815 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
|
816 } |
25003 | 817 |
34255
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
818 if (sd->volume > 0) |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
819 { |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
820 int volume = sd->volume & 0xff; |
cb2b0d1799db
(vox_configure): Set volume for left and right channel.
Gerd Moellmann <gerd@gnu.org>
parents:
31587
diff
changeset
|
821 volume |= volume << 8; |
34354
db2901e01b72
(vox_configure): Change order of ioctls. Don't
Gerd Moellmann <gerd@gnu.org>
parents:
34255
diff
changeset
|
822 /* 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
|
823 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
|
824 } |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
825 |
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
826 turn_on_atimers (1); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
827 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
828 sigunblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
829 #endif |
25003 | 830 } |
831 | |
832 | |
833 /* Close device SD if it is open. */ | |
834 | |
835 static void | |
836 vox_close (sd) | |
837 struct sound_device *sd; | |
838 { | |
839 if (sd->fd >= 0) | |
840 { | |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
841 /* 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
|
842 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
|
843 troubles. */ |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
844 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
845 sigblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
846 #endif |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
847 turn_on_atimers (0); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
848 |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
849 /* Flush sound data, and reset the device. */ |
25003 | 850 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
|
851 |
38215
b9fdde642b13
(vox_configure, vox_close): Turn off atimers
Gerd Moellmann <gerd@gnu.org>
parents:
34354
diff
changeset
|
852 turn_on_atimers (1); |
38338
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
853 #ifdef SIGIO |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
854 sigunblock (sigmask (SIGIO)); |
c6ff61f9af43
(toplevel): Include <signal.h> and "syssignal.h".
Gerd Moellmann <gerd@gnu.org>
parents:
38297
diff
changeset
|
855 #endif |
25003 | 856 |
857 /* 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
|
858 emacs_close (sd->fd); |
25003 | 859 sd->fd = -1; |
860 } | |
861 } | |
862 | |
863 | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
864 /* Choose device-dependent format for device SD from sound file S. */ |
25003 | 865 |
866 static void | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
867 vox_choose_format (sd, s) |
25003 | 868 struct sound_device *sd; |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
869 struct sound *s; |
25003 | 870 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
871 if (s->type == RIFF) |
25003 | 872 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
873 struct wav_header *h = (struct wav_header *) s->header; |
25003 | 874 if (h->precision == 8) |
875 sd->format = AFMT_U8; | |
876 else if (h->precision == 16) | |
877 sd->format = AFMT_S16_LE; | |
878 else | |
879 error ("Unsupported WAV file format"); | |
880 } | |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
881 else if (s->type == SUN_AUDIO) |
25003 | 882 { |
27146
68290f44807a
(struct sound): Renamed from struct sound_file.
Gerd Moellmann <gerd@gnu.org>
parents:
26088
diff
changeset
|
883 struct au_header *header = (struct au_header *) s->header; |
25003 | 884 switch (header->encoding) |
885 { | |
886 case AU_ENCODING_ULAW_8: | |
887 case AU_ENCODING_IEEE32: | |
888 case AU_ENCODING_IEEE64: | |
889 sd->format = AFMT_MU_LAW; | |
890 break; | |
891 | |
892 case AU_ENCODING_8: | |
893 case AU_ENCODING_16: | |
894 case AU_ENCODING_24: | |
895 case AU_ENCODING_32: | |
896 sd->format = AFMT_S16_LE; | |
897 break; | |
898 | |
899 default: | |
900 error ("Unsupported AU file format"); | |
901 } | |
902 } | |
903 else | |
904 abort (); | |
905 } | |
906 | |
907 | |
908 /* Initialize device SD. Set up the interface functions in the device | |
909 structure. */ | |
910 | |
911 static void | |
912 vox_init (sd) | |
913 struct sound_device *sd; | |
914 { | |
915 sd->fd = -1; | |
916 sd->open = vox_open; | |
917 sd->close = vox_close; | |
918 sd->configure = vox_configure; | |
919 sd->choose_format = vox_choose_format; | |
920 sd->write = vox_write; | |
921 } | |
922 | |
923 | |
924 /* Write NBYTES bytes from BUFFER to device SD. */ | |
925 | |
926 static void | |
927 vox_write (sd, buffer, nbytes) | |
928 struct sound_device *sd; | |
929 char *buffer; | |
930 int nbytes; | |
931 { | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
25722
diff
changeset
|
932 int nwritten = emacs_write (sd->fd, buffer, nbytes); |
25003 | 933 if (nwritten < 0) |
40364
f7b039994118
(sound_perror): Unblock SIGIO, turn on atimers.
Gerd Moellmann <gerd@gnu.org>
parents:
40123
diff
changeset
|
934 sound_perror ("Error writing to sound device"); |
25003 | 935 } |
936 | |
937 | |
938 | |
939 /*********************************************************************** | |
940 Initialization | |
941 ***********************************************************************/ | |
942 | |
943 void | |
944 syms_of_sound () | |
945 { | |
946 QCdevice = intern (":device"); | |
947 staticpro (&QCdevice); | |
948 QCvolume = intern (":volume"); | |
949 staticpro (&QCvolume); | |
950 Qsound = intern ("sound"); | |
951 staticpro (&Qsound); | |
25548
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
952 Qplay_sound_functions = intern ("play-sound-functions"); |
df6548ca33fd
(Qplay_sound_functions): Replaces Qplay_sound_hook.
Gerd Moellmann <gerd@gnu.org>
parents:
25003
diff
changeset
|
953 staticpro (&Qplay_sound_functions); |
25003 | 954 |
955 defsubr (&Splay_sound); | |
956 } | |
957 | |
958 | |
959 void | |
960 init_sound () | |
961 { | |
962 } | |
963 | |
964 #endif /* HAVE_SOUND */ |