annotate src/sgiplay.c @ 235:85a06df23a9a r20-5b16

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