annotate src/sgiplay.c @ 370:bd866891f083

Added tag r21-1-14 for changeset 1d62742628b6
author cvs
date Mon, 13 Aug 2007 11:01:58 +0200
parents a4f53d9b3154
children cc15677e0335
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Play sound using the SGI audio library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 written by Simon Leinen <simon@lia.di.epfl.ch>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1992 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include <audio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include <sys/file.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include <fcntl.h>
367
a4f53d9b3154 Import from CVS: tag r21-1-13
cvs
parents: 185
diff changeset
32 #include <unistd.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include <netinet/in.h> /* for ntohl() etc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 /* Configuration options */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 /* ability to parse Sun/NeXT (.au or .snd) audio file headers. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 .snd format supports all sampling rates and sample widths that are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 commonly used, as well as stereo. It is also easy to parse. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #ifndef HAVE_SND_FILES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #define HAVE_SND_FILES 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 /* support for eight-but mu-law encoding. This is a useful compaction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 technique, and most sounds from the Sun universe are in this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 format. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #ifndef HAVE_MULAW_8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #define HAVE_MULAW_8 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 /* if your machine is very slow, you have to use a table lookup to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 convert mulaw samples to linear. This makes Emacs bigger so try to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 avoid it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #ifndef USE_MULAW_DECODE_TABLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #define USE_MULAW_DECODE_TABLE 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 /* support for linear encoding -- useful if you want better quality.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 This enables 8, 16 and 24 bit wide samples. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #ifndef HAVE_LINEAR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 #define HAVE_LINEAR 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 /* support for 32 bit wide samples. If you notice the difference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 between 32 and 24 bit samples, you must have very good ears. Since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 the SGI audio library only supports 24 bit samples, each sample has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 to be shifted right by 8 bits anyway. So you should probably just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 convert all your 32 bit audio files to 24 bit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #ifndef HAVE_LINEAR_32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 #define HAVE_LINEAR_32 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 /* support for stereo sound. Imagine the cool applications of this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 finally you don't just hear a beep -- you also know immediately
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 *where* something went wrong! Unfortunately the programming
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 interface only takes a single volume argument so far. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #ifndef HAVE_STEREO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 #define HAVE_STEREO 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 /* the play routine can be interrupted between chunks, so we choose a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 small chunksize to keep the system responsive (2000 samples
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 correspond to a quarter of a second for .au files. If you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 HAVE_STEREO, the chunksize should probably be even. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 #define CHUNKSIZE 8000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 /* the format assumed for header-less audio data. The following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 assumes ".au" format (8000 samples/sec mono 8-bit mulaw). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 #define DEFAULT_SAMPLING_RATE 8000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 #define DEFAULT_CHANNEL_COUNT 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 #define DEFAULT_FORMAT AFmulaw8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 /* Exports */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 /* all compilers on machines that have the SGI audio library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 understand prototypes, right? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 extern void play_sound_file (char *, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 extern void play_sound_data (unsigned char *, int, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 /* Data structures */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 /* an AudioContext describes everything we want to know about how a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 particular sound snippet should be played. It is split into three
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 parts (device, port and buffer) for implementation reasons. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 device part corresponds to the state of the output device and must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 be reverted after playing the samples. The port part corresponds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 to an ALport; we want to allocate a minimal number of these since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 there are only four of them system-wide, but on the other hand we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 can't use the same port for mono and stereo. The buffer part
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 corresponds to the sound data itself. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 typedef struct _AudioContextRec * AudioContext;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 long device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 int left_speaker_gain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 int right_speaker_gain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 long output_rate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 AudioDeviceRec, * AudioDevice;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 /* supported sound data formats */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 typedef enum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 AFunknown,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 #if HAVE_MULAW_8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 AFmulaw8,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 #if HAVE_LINEAR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 AFlinear8,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 AFlinear16,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 AFlinear24,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 #if HAVE_LINEAR_32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 AFlinear32,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 AFillegal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 AudioFormat;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ALport port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 AudioFormat format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 unsigned nchan;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 unsigned queue_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 AudioPortRec, * AudioPort;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 void * data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 unsigned long size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 void (* write_chunk_function) (void *, void *, AudioContext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 AudioBufferRec, * AudioBuffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 typedef struct _AudioContextRec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 AudioDeviceRec device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 AudioPortRec port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 AudioBufferRec buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 AudioContextRec;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 #define ac_device device.device
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 #define ac_left_speaker_gain device.left_speaker_gain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 #define ac_right_speaker_gain device.right_speaker_gain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 #define ac_output_rate device.output_rate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 #define ac_port port.port
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 #define ac_format port.format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 #define ac_nchan port.nchan
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 #define ac_queue_size port.queue_size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 #define ac_data buffer.data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 #define ac_size buffer.size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 #define ac_write_chunk_function buffer.write_chunk_function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 /* Forward declarations */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 static Lisp_Object close_sound_file (Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 static AudioContext audio_initialize (unsigned char *, int, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 static void play_internal (unsigned char *, int, AudioContext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 static void drain_audio_port (AudioContext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 static void write_mulaw_8_chunk (void *, void *, AudioContext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 static void write_linear_chunk (void *, void *, AudioContext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 static void write_linear_32_chunk (void *, void *, AudioContext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 static Lisp_Object restore_audio_port (Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 static AudioContext initialize_audio_port (AudioContext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 static int open_audio_port (AudioContext, AudioContext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 static void adjust_audio_volume (AudioDevice);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 static void get_current_volumes (AudioDevice);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 static int set_channels (ALconfig, unsigned);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 static int set_output_format (ALconfig, AudioFormat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 static int parse_snd_header (void*, long, AudioContext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 /* are we looking at an NeXT/Sun audio header? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 #define LOOKING_AT_SND_HEADER_P(address) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (!strncmp(".snd", (char *)(address), 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 close_sound_file (closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 Lisp_Object closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 close (XINT (closure));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 play_sound_file (sound_file, volume)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 char * sound_file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 int volume;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 int count = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 int input_fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 unsigned char buffer[CHUNKSIZE];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 int bytes_read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 AudioContext ac = (AudioContext) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 input_fd = open (sound_file, O_RDONLY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 if (input_fd == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 /* no error message -- this can't happen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 because Fplay_sound_file has checked the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 file for us. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 record_unwind_protect (close_sound_file, make_int (input_fd));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 while ((bytes_read = read (input_fd, buffer, CHUNKSIZE)) > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 if (ac == (AudioContext) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ac = audio_initialize (buffer, bytes_read, volume);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 if (ac == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ac->ac_data = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ac->ac_size = bytes_read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 play_internal (buffer, bytes_read, ac);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 drain_audio_port (ac);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 unbind_to (count, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 static long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 saved_device_state[] = {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 AL_OUTPUT_RATE, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 AL_LEFT_SPEAKER_GAIN, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 AL_RIGHT_SPEAKER_GAIN, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 restore_audio_port (closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 Lisp_Object closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
262 Lisp_Object * contents = XVECTOR_DATA (closure);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 saved_device_state[1] = XINT (contents[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 saved_device_state[3] = XINT (contents[1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 saved_device_state[5] = XINT (contents[2]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ALsetparams (AL_DEFAULT_DEVICE, saved_device_state, 6);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 play_sound_data (data, length, volume)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 unsigned char * data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 int length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 int volume;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 int count = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 AudioContext ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ac = audio_initialize (data, length, volume);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 if (ac == (AudioContext) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 play_internal (data, length, ac);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 drain_audio_port (ac);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 unbind_to (count, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 static AudioContext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 audio_initialize (data, length, volume)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 unsigned char * data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 int length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 int volume;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 Lisp_Object audio_port_state[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 static AudioContextRec desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 AudioContext ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 desc.ac_right_speaker_gain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 = desc.ac_left_speaker_gain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 = volume * 256 / 100;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 desc.ac_device = AL_DEFAULT_DEVICE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 #if HAVE_SND_FILES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 if (LOOKING_AT_SND_HEADER_P (data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 if (parse_snd_header (data, length, & desc)==-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 report_file_error ("decoding .snd header", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 desc.ac_data = data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 desc.ac_size = length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 desc.ac_output_rate = DEFAULT_SAMPLING_RATE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 desc.ac_nchan = DEFAULT_CHANNEL_COUNT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 desc.ac_format = DEFAULT_FORMAT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 desc.ac_write_chunk_function = write_mulaw_8_chunk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 /* Make sure that the audio port is reset to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 its initial characteristics after exit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ALgetparams (desc.ac_device, saved_device_state,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 sizeof (saved_device_state) / sizeof (long));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 audio_port_state[0] = make_int (saved_device_state[1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 audio_port_state[1] = make_int (saved_device_state[3]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 audio_port_state[2] = make_int (saved_device_state[5]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 record_unwind_protect (restore_audio_port,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 Fvector (3, &audio_port_state[0]));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
328
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ac = initialize_audio_port (& desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 desc = * ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 return ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 play_internal (data, length, ac)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 unsigned char * data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 int length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 AudioContext ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 unsigned char * limit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 if (ac == (AudioContext) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 data = ac->ac_data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 limit = data + ac->ac_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 while (data < limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 unsigned char * chunklimit = data + CHUNKSIZE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 if (chunklimit > limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 chunklimit = limit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (* ac->ac_write_chunk_function) (data, chunklimit, ac);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 data = chunklimit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 drain_audio_port (ac)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 AudioContext ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 while (ALgetfilled (ac->ac_port) > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 sginap(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 /* Methods to write a "chunk" from a buffer containing audio data to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 an audio port. This may involve some conversion if the output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 device doesn't directly support the format the audio data is in. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 #if HAVE_MULAW_8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 #if USE_MULAW_DECODE_TABLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 #include "libst.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 #else /* not USE_MULAW_DECODE_TABLE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 st_ulaw_to_linear (u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 int u;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 static CONST short table[] = {0,132,396,924,1980,4092,8316,16764};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 int u1 = ~u;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 short exponent = (u1 >> 4) & 0x07;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 int mantissa = u1 & 0x0f;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 int unsigned_result = table[exponent]+(mantissa << (exponent+3));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 return u1 & 0x80 ? -unsigned_result : unsigned_result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 #endif /* not USE_MULAW_DECODE_TABLE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 write_mulaw_8_chunk (buffer, chunklimit, ac)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 void * buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 void * chunklimit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 AudioContext ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 unsigned char * data = (unsigned char *) buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 unsigned char * limit = (unsigned char *) chunklimit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 short * obuf, * bufp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 long n_samples = limit - data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
401 obuf = alloca_array (short, n_samples);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 bufp = &obuf[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 while (data < limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 *bufp++ = st_ulaw_to_linear (*data++);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 ALwritesamps (ac->ac_port, obuf, n_samples);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 #endif /* HAVE_MULAW_8 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 #if HAVE_LINEAR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 write_linear_chunk (data, limit, ac)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 void * data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 void * limit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 AudioContext ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 unsigned n_samples;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 switch (ac->ac_format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 case AFlinear16: n_samples = (short *) limit - (short *) data; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 case AFlinear8: n_samples = (char *) limit - (char *) data; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 default: n_samples = (long *) limit - (long *) data; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ALwritesamps (ac->ac_port, data, (long) n_samples);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 #if HAVE_LINEAR_32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 write_linear_32_chunk (buffer, chunklimit, ac)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 void * buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 void * chunklimit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 AudioContext ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 long * data = (long *) buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 long * limit = (long *) chunklimit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 long * obuf, * bufp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 long n_samples = limit-data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
440 obuf = alloca_array (long, n_samples);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 bufp = &obuf[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 while (data < limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 *bufp++ = *data++ >> 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ALwritesamps (ac->ac_port, obuf, n_samples);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 #endif /* HAVE_LINEAR_32 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 #endif /* HAVE_LINEAR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 static AudioContext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 initialize_audio_port (desc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 AudioContext desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 /* we can't use the same port for mono and stereo */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 static AudioContextRec mono_port_state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 = { { 0, 0, 0, 0 },
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 { (ALport) 0, AFunknown, 1, 0 },
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 { (void *) 0, (unsigned long) 0 } };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 #if HAVE_STEREO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 static AudioContextRec stereo_port_state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 = { { 0, 0, 0, 0 },
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 { (ALport) 0, AFunknown, 2, 0 },
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 { (void *) 0, (unsigned long) 0 } };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 static AudioContext return_ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 switch (desc->ac_nchan)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 case 1: return_ac = & mono_port_state; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 case 2: return_ac = & stereo_port_state; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 default: return (AudioContext) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 #else /* not HAVE_STEREO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 static AudioContext return_ac = & mono_port_state;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 #endif /* not HAVE_STEREO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 return_ac->device = desc->device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 return_ac->buffer = desc->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 return_ac->ac_format = desc->ac_format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 return_ac->ac_queue_size = desc->ac_queue_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 if (return_ac->ac_port==(ALport) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 if ((open_audio_port (return_ac, desc))==-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 report_file_error ("Open audio port", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 return (AudioContext) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ALconfig config = ALgetconfig (return_ac->ac_port);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 int changed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 long params[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 params[0] = AL_OUTPUT_RATE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ALgetparams (return_ac->ac_device, params, 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 return_ac->ac_output_rate = params[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 if (return_ac->ac_output_rate != desc->ac_output_rate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 return_ac->ac_output_rate = params[1] = desc->ac_output_rate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ALsetparams (return_ac->ac_device, params, 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 if ((changed = set_output_format (config, return_ac->ac_format))==-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 return (AudioContext) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 return_ac->ac_format = desc->ac_format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 if (changed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ALsetconfig (return_ac->ac_port, config);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 return_ac->ac_write_chunk_function = desc->ac_write_chunk_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 get_current_volumes (& return_ac->device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 if (return_ac->ac_left_speaker_gain != desc->ac_left_speaker_gain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 || return_ac->ac_right_speaker_gain != desc->ac_right_speaker_gain)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 adjust_audio_volume (& desc->device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 return return_ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 open_audio_port (return_ac, desc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 AudioContext return_ac;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 AudioContext desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 ALconfig config = ALnewconfig();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 long params[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 adjust_audio_volume (& desc->device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 return_ac->ac_left_speaker_gain = desc->ac_left_speaker_gain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 return_ac->ac_right_speaker_gain = desc->ac_right_speaker_gain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 params[0] = AL_OUTPUT_RATE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 params[1] = desc->ac_output_rate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ALsetparams (desc->ac_device, params, 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 return_ac->ac_output_rate = desc->ac_output_rate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 if (set_channels (config, desc->ac_nchan)==-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 return_ac->ac_nchan = desc->ac_nchan;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 if (set_output_format (config, desc->ac_format)==-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 return_ac->ac_format = desc->ac_format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ALsetqueuesize (config, (long) CHUNKSIZE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 return_ac->ac_port = ALopenport("XEmacs audio output", "w", config);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ALfreeconfig (config);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 if (return_ac->ac_port==0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 report_file_error ("Opening audio output port", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 set_channels (config, nchan)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ALconfig config;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 unsigned nchan;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 switch (nchan)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 case 1: ALsetchannels (config, AL_MONO); break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 #if HAVE_STEREO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 case 2: ALsetchannels (config, AL_STEREO); break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 #endif /* HAVE_STEREO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 report_file_error ("Unsupported channel count",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 Fcons (make_int (nchan), Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 set_output_format (config, format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ALconfig config;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 AudioFormat format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 long samplesize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 long old_samplesize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 switch (format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 #if HAVE_MULAW_8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 case AFmulaw8:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 #if HAVE_LINEAR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 case AFlinear16:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 #if HAVE_MULAW_8 || HAVE_LINEAR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 samplesize = AL_SAMPLE_16;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 #if HAVE_LINEAR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 case AFlinear8:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 samplesize = AL_SAMPLE_8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 case AFlinear24:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 #if HAVE_LINEAR_32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 case AFlinear32:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 samplesize = AL_SAMPLE_24;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 report_file_error ("Unsupported audio format",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 Fcons (make_int (format), Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 old_samplesize = ALgetwidth (config);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 if (old_samplesize==samplesize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 ALsetwidth (config, samplesize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 adjust_audio_volume (device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 AudioDevice device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 long params[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 params[0] = AL_LEFT_SPEAKER_GAIN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 params[1] = device->left_speaker_gain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 params[2] = AL_RIGHT_SPEAKER_GAIN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 params[3] = device->right_speaker_gain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ALsetparams (device->device, params, 4);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 get_current_volumes (device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 AudioDevice device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 long params[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 params[0] = AL_LEFT_SPEAKER_GAIN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 params[2] = AL_RIGHT_SPEAKER_GAIN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ALgetparams (device->device, params, 4);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 device->left_speaker_gain = params[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 device->right_speaker_gain = params[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 #if HAVE_SND_FILES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 /* Parsing .snd (NeXT/Sun) headers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 int magic;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 int dataLocation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 int dataSize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 int dataFormat;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 int samplingRate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 int channelCount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 char info[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 SNDSoundStruct;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 #define SOUND_TO_HOST_INT(x) ntohl(x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 typedef enum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 SND_FORMAT_FORMAT_UNSPECIFIED,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 SND_FORMAT_MULAW_8,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 SND_FORMAT_LINEAR_8,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 SND_FORMAT_LINEAR_16,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 SND_FORMAT_LINEAR_24,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 SND_FORMAT_LINEAR_32,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 SND_FORMAT_FLOAT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 SND_FORMAT_DOUBLE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 SND_FORMAT_INDIRECT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 SND_FORMAT_NESTED,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 SND_FORMAT_DSP_CODE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 SND_FORMAT_DSP_DATA_8,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 SND_FORMAT_DSP_DATA_16,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 SND_FORMAT_DSP_DATA_24,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 SND_FORMAT_DSP_DATA_32,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 SND_FORMAT_DSP_unknown_15,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 SND_FORMAT_DISPLAY,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 SND_FORMAT_MULAW_SQUELCH,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 SND_FORMAT_EMPHASIZED,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 SND_FORMAT_COMPRESSED,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 SND_FORMAT_COMPRESSED_EMPHASIZED,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 SND_FORMAT_DSP_COMMANDS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 SND_FORMAT_DSP_COMMANDS_SAMPLES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 SNDFormatCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 parse_snd_header (header, length, desc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 void * header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 long length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 AudioContext desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 #define hp ((SNDSoundStruct *) (header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 long limit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 #if HAVE_LINEAR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 desc->ac_write_chunk_function = write_linear_chunk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 switch ((SNDFormatCode) SOUND_TO_HOST_INT (hp->dataFormat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 #if HAVE_MULAW_8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 case SND_FORMAT_MULAW_8:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 desc->ac_format = AFmulaw8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 desc->ac_write_chunk_function = write_mulaw_8_chunk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 #if HAVE_LINEAR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 case SND_FORMAT_LINEAR_8:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 desc->ac_format = AFlinear8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 case SND_FORMAT_LINEAR_16:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 desc->ac_format = AFlinear16;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 case SND_FORMAT_LINEAR_24:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 desc->ac_format = AFlinear24;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 #if HAVE_LINEAR_32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 case SND_FORMAT_LINEAR_32:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 desc->ac_format = AFlinear32;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 desc->ac_write_chunk_function = write_linear_32_chunk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 desc->ac_format = AFunknown;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 desc->ac_output_rate = SOUND_TO_HOST_INT (hp->samplingRate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 desc->ac_nchan = SOUND_TO_HOST_INT (hp->channelCount);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 desc->ac_data = (char *) header + SOUND_TO_HOST_INT (hp->dataLocation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 limit = (char *) header + length - (char *) desc->ac_data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 desc->ac_size = SOUND_TO_HOST_INT (hp->dataSize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 if (desc->ac_size > limit) desc->ac_size = limit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 #undef hp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 #endif /* HAVE_SND_FILES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731