annotate src/sound.c @ 38226:7ee172ed0239

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