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