annotate src/nas.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 8626e4521993
children 697ef44129c6
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 /* nas.c --- XEmacs support for the Network Audio System server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 * Author: Richard Caley <R.Caley@ed.ac.uk>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 * Copyright 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 * Copyright 1993 Network Computing Devices, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 * Permission to use, copy, modify, distribute, and sell this software and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 * its documentation for any purpose is hereby granted without fee, provided
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 * that the above copyright notice appear in all copies and that both that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 * copyright notice and this permission notice appear in supporting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 * documentation, and that the name Network Computing Devices, Inc. not be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 * used in advertising or publicity pertaining to distribution of this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 * software without specific, written prior permission.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED 'AS-IS'. NETWORK COMPUTING DEVICES, INC.,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 /* There are four compile-time options.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 * XTOOLKIT This will be part of an Xt program.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 * XTEVENTS The playing will be supervised asynchronously by the Xt event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 * loop. If not set, playing will be completed within the call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 * to play_file etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 * ROBUST_PLAY Causes errors in nas to be caught. This means that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 * program will attempt not to die if the nas server does.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 * CACHE_SOUNDS Causes the sounds to be played in buckets in the NAS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 * server. They are named by their comment field, or if that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 * empty by the filename, or for play_sound_data by a name made up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 * from the sample itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 /* CHANGES:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 * 10/8/94, rjc Changed names from netaudio to nas
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 * Added back asynchronous play if nas library has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 * correct error facilities.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 * 4/11/94, rjc Added wait_for_sounds to be called when user wants to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 * be sure all play has finished.
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
52 * 1998-10-01 rlt Added support for WAVE files.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
55 #ifdef emacs
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
56 #include <config.h>
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
57 #include "lisp.h"
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
58 #include "sysdep.h"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
59 #include "syssignal.h"
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
60 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
61
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
62 #include <stdlib.h>
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
63 #include <stdarg.h>
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
64 #include <string.h>
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
65 #include <stdio.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
67 #ifdef HAVE_UNISTD_H
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
68 #include <unistd.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
72 #undef LITTLE_ENDIAN
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
73 #undef BIG_ENDIAN
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 #include <audio/audiolib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 #include <audio/soundlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 #include <audio/snd.h>
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
77 #include <audio/wave.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #include <audio/fileutil.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 # define XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 # define XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 # define ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 # define CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 * For old NAS libraries, force playing to be synchronous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 * and declare the long jump point locally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 # if defined (NAS_NO_ERROR_JUMP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 # undef XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 # include <setjmp.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 jmp_buf AuXtErrorJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 /* The GETTEXT is correct. --ben */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 # define warn(str) warn_when_safe (Qnas, Qwarning, "nas: %s ", GETTEXT (str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 # define play_sound_file nas_play_sound_file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 # define play_sound_data nas_play_sound_data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 # define wait_for_sounds nas_wait_for_sounds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 # define init_play nas_init_play
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 # define close_down_play nas_close_down_play
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #else /* !emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 # define warn(str) fprintf (stderr, "%s\n", (str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 #endif /* emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 # include <X11/Intrinsic.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 # include <audio/Xtutil.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 #if defined (ROBUST_PLAY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 static AuBool CatchIoErrorAndJump (AuServer *aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 static AuBool CatchErrorAndJump (AuServer *aud, AuErrorEvent *event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 SIGTYPE sigpipe_handle (int signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 extern Lisp_Object Vsynchronous_sounds;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 static Sound SoundOpenDataForReading (unsigned char *data, int length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 static AuServer *aud;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 /* count of sounds currently being played. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 static int sounds_in_play;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 static Display *aud_server;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 static XtInputId input_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 static char *aud_server;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 #endif /* XTOOLKIT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 init_play (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 Display *display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 char *server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 #endif
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
148 );
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
149 char *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
150 init_play (
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
151 #ifdef XTOOLKIT
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
152 Display *display
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
153 #else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
154 char *server
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
155 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 char *err_message;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
159 SIGTYPE (*old_sigpipe) (int);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 char * server = DisplayString (display);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 XtAppContext app_context = XtDisplayToApplicationContext (display);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 aud_server = display;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 aud_server = server;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 old_sigpipe = signal (SIGPIPE, sigpipe_handle);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 if (setjmp (AuXtErrorJump))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 return "error in NAS";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 #if defined (ROBUST_PLAY) && !defined (NAS_NO_ERROR_JUMP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 AuDefaultIOErrorHandler = CatchIoErrorAndJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 AuDefaultErrorHandler = CatchErrorAndJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 stop_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 aud = AuOpenServer (server, 0, NULL, 0, NULL, &err_message);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 if (!aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 if (err_message == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 return "Can't connect to audio server";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 return err_message;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 #if defined (ROBUST_PLAY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 # if defined (NAS_NO_ERROR_JUMP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 aud->funcs.ioerror_handler = CatchIoErrorAndJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 aud->funcs.error_handler = CatchErrorAndJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 # else /* !NAS_NO_ERROR_JUMP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 AuDefaultIOErrorHandler = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 AuDefaultErrorHandler = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 #ifdef XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 input_id = AuXtAppAddAudioHandler (app_context, aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 #ifdef CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 AuSetCloseDownMode (aud, AuCloseDownRetainPermanent, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 sounds_in_play = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
233 static void
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 close_down_play (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 AuCloseServer (aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 warn ("disconnected from audio server");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 /********************************************************************\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 * Callback which is run when the sound finishes playing. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 \********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
248 doneCB (AuServer *auserver,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 AuEventHandlerRec *handler,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 AuEvent *ev,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 AuPointer data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 int *in_play_p = (int *) data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (*in_play_p) --;
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 #ifdef CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 /********************************************************************\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 * Play a sound by playing the relevant bucket, if any or *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 * downloading it if not. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 \********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 do_caching_play (Sound s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 int volume,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 unsigned char *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 AuBucketAttributes *list, b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 AuBucketID id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 int n;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 AuSetString (AuBucketDescription (&b),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 AuStringLatin1, strlen (SoundComment (s)), SoundComment (s));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 list = AuListBuckets (aud, AuCompCommonDescriptionMask, &b, &n, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 if (list == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
284 AuPointer my_buf;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (buf==NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
288 if ((my_buf= (AuPointer) malloc (SoundNumBytes (s)))==NULL)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
293 if (SoundReadFile ((char *) my_buf, SoundNumBytes (s), s) != SoundNumBytes (s))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 free (my_buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 else
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
300 my_buf = (AuPointer) buf;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 id = AuSoundCreateBucketFromData (aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 my_buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 AuAccessAllMasks,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 if (buf == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 free (my_buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 else /* found cached sound */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 id = AuBucketIdentifier (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 AuFreeBucketAttributes (aud, n, list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 sounds_in_play++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 AuSoundPlayFromBucket (aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 id,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 AuNone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 AuFixedPointFromFraction (volume, 100),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 doneCB, (AuPointer) &sounds_in_play,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 NULL, NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 NULL, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 #endif /* CACHE_SOUNDS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
332 void wait_for_sounds (void);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 wait_for_sounds (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 AuEvent ev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 while (sounds_in_play>0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 AuNextEvent (aud, AuTrue, &ev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 AuDispatchEvent (aud, &ev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
346 int play_sound_file (char *sound_file, int volume);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 play_sound_file (char *sound_file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 int volume)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
351 SIGTYPE (*old_sigpipe) (int);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 old_sigpipe=signal (SIGPIPE, sigpipe_handle);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 if (setjmp (AuXtErrorJump))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 82
diff changeset
362 if (aud==NULL) {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 if (aud_server != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 char *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 /* attempt to reconect */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 if ((m=init_play (aud_server))!= NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 warn ("Attempt to play with no audio init\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 82
diff changeset
384 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 #ifndef CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 sounds_in_play++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 AuSoundPlayFromFile (aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 sound_file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 AuNone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 AuFixedPointFromFraction (volume,100),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 doneCB, (AuPointer) &sounds_in_play,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 /* Cache the sounds in buckets on the server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 Sound s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 if ((s = SoundOpenFileForReading (sound_file))==NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 if (SoundComment (s) == NULL || SoundComment (s)[0] == '\0')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 SoundComment (s) = FileCommentFromFilename (sound_file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 do_caching_play (s, volume, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 SoundCloseFile (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 #endif /* CACHE_SOUNDS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 #ifndef XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 wait_for_sounds ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 if (!NILP (Vsynchronous_sounds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 wait_for_sounds ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
439 int play_sound_data (unsigned char *data, int length, int volume);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 play_sound_data (unsigned char *data,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 int length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 int volume)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 Sound s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 int offset;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
447 SIGTYPE (*old_sigpipe) (int);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 #if !defined (XTEVENTS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 AuEvent ev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 old_sigpipe = signal (SIGPIPE, sigpipe_handle);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 if (setjmp (AuXtErrorJump) !=0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 82
diff changeset
463 if (aud == NULL) {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 if (aud_server != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 char *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 /* attempt to reconect */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 if ((m = init_play (aud_server)) != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 warn ("Attempt to play with no audio init\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 82
diff changeset
484 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 if ((s=SoundOpenDataForReading (data, length))==NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 warn ("unknown sound type");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 if (SoundFileFormat (s) == SoundFileFormatSnd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 /* hack, hack */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 offset = ((SndInfo *) (s->formatInfo))->h.dataOffset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 }
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
500 else if (SoundFileFormat (s) == SoundFileFormatWave)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
501 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
502 offset = ((WaveInfo *) (s->formatInfo))->dataOffset;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
503 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 {
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
506 warn ("only understand snd and wave files at the moment");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 SoundCloseFile (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 #ifndef CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 sounds_in_play++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 AuSoundPlayFromData (aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 data+offset,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 AuNone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 AuFixedPointFromFraction (volume,100),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 doneCB, (AuPointer) &sounds_in_play,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 /* Cache the sounds in buckets on the server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 do_caching_play (s, volume, data+offset);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 #endif /* CACHE_SOUNDS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 #ifndef XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 wait_for_sounds ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 if (!NILP (Vsynchronous_sounds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 wait_for_sounds ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 SoundCloseFile (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 #if defined (ROBUST_PLAY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 /********************************************************************\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 * Code to protect the client from server shutdowns. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 * This is unbelievably horrible. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 \********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 static AuBool
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 CatchIoErrorAndJump (AuServer *old_aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 if (old_aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 warn ("Audio Server connection broken");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 warn ("Audio Server connection broken because of signal");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 #ifdef XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 AuXtAppRemoveAudioHandler (aud, input_id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 #endif
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 (aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 AuCloseServer (aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 aud = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 sounds_in_play = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 longjmp (AuXtErrorJump, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 #else /* not XTEVENTS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 if (aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 AuCloseServer (aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 aud = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 sounds_in_play = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 longjmp (AuXtErrorJump, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 #endif /* XTEVENTS */
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
594 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 sigpipe_handle (int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 CatchIoErrorAndJump (NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 static AuBool
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 CatchErrorAndJump (AuServer *old_aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 AuErrorEvent *event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 return CatchIoErrorAndJump (old_aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 #endif /* ROBUST_PLAY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 /********************************************************************\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 * This code is here because the nas Sound library doesn't *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 * support playing from a file buffered in memory. It's a fairly *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 * direct translation of the file-based equivalent. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 * Since we don't have a filename, samples with no comment field *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 * are named by a section of their content. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 * *
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 /* Create a name from the sound. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 static char *
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
626 NameFromData (const char *buf,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 int len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
630 char name[9];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 char *s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 buf+=len/2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 len -= len/2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 i=0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 while (i<8 && len >0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 while (*buf < 32 && len>0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 buf++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 len--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 name[i]= *buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 i++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 buf++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 len--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 name[i]='\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 if (i==8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
655 strcpy (s = (char *) malloc (10), name);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
659 strcpy (s = (char *) malloc (15), "short sound");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 return s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 /* Code to do a pseudo-open on a data buffer. Only for snd files at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 moment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 static SndInfo *
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
670 SndOpenDataForReading (const char *data,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 int length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 SndInfo *si;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 int size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 if (!(si = (SndInfo *) malloc (sizeof (SndInfo))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 si->comment = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 si->writing = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 memcpy (&si->h, data, sizeof (SndHeader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 365
diff changeset
685 if (LITTLE_ENDIAN)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 char n;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 swapl (&si->h.magic, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 swapl (&si->h.dataOffset, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 swapl (&si->h.dataSize, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 swapl (&si->h.format, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 swapl (&si->h.sampleRate, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 swapl (&si->h.tracks, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 if (si->h.magic != SND_MAGIC_NUM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 free (si);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 size = si->h.dataOffset - sizeof (SndHeader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 if (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 if (!(si->comment = (char *) malloc (size + 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 free (si);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 memcpy (si->comment, data+sizeof (SndHeader), size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 *(si->comment + size) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 if (*si->comment == '\0')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 si->comment =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 si->comment = NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 si->h.dataSize = length-si->h.dataOffset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 si->fp=NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 return si;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
730 /* Stuff taken from wave.c from NAS. Just like snd files, NAS can't
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
731 read wave data from memory, so these functions do that for us. */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
732
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
733 #define Err() { return NULL; }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
734 #define readFourcc(_f) dread(_f, sizeof(RIFF_FOURCC), 1)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
735 #define cmpID(_x, _y) \
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
736 strncmp((char *) (_x), (char *) (_y), sizeof(RIFF_FOURCC))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
737 #define PAD2(_x) (((_x) + 1) & ~1)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
738
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
739 /* These functions here are for faking file I/O from buffer. */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
740
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
741 /* The "file" position */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
742 static size_t file_posn;
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
743 /* The length of the "file" */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
744 static size_t file_len;
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
745 /* The actual "file" data. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
746 static const void* file_data;
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
747
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
748 /* Like fopen, but for a buffer in memory */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
749 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
750 dopen (const void* data, size_t length)
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
751 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
752 file_data = data;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
753 file_len = length;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
754 file_posn = 0;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
755 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
756
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
757 /* Like fread, but for a buffer in memory */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
758 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
759 dread (void* buf, size_t size, size_t nitems)
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
760 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
761 size_t nread = size * nitems;
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
762
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
763 if (file_posn + nread <= file_len)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
764 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
765 memcpy(buf, (char *) file_data + file_posn, size * nitems);
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
766 file_posn += nread;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
767 return nitems;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
768 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
769 else
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
770 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
771 return EOF;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
772 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
773 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
774
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
775 /* Like fgetc, but for a buffer in memory */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
776 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
777 dgetc (void)
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
778 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
779 if (file_posn < file_len)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
780 return ((char *)file_data)[file_posn++];
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
781 else
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
782 return -1;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
783 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
784
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
785 /* Like fseek, but for a buffer in memory */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
786 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
787 dseek (long offset, int from)
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
788 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
789 if (from == 0)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
790 file_posn = offset;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
791 else if (from == 1)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
792 file_posn += offset;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
793 else if (from == 2)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
794 file_posn = file_len + offset;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
795
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
796 return 0;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
797 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
798
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
799 /* Like ftell, but for a buffer in memory */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
800 static long
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
801 dtell (void)
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
802 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
803 return file_posn;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
804 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
805
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
806 /* Data buffer analogs for FileReadS and FileReadL in NAS. */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
807
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
808 static unsigned short
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
809 DataReadS (int swapit)
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
810 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
811 unsigned short us;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
812
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
813 dread(&us, 2, 1);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
814 if (swapit)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
815 us = FileSwapS(us);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
816 return us;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
817 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
818
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
819 static AuUint32
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
820 DataReadL (int swapit)
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
821 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
822 AuUint32 ul;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
823
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
824 dread(&ul, 4, 1);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
825 if (swapit)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
826 ul = FileSwapL(ul);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
827 return ul;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
828 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
829
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
830 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
831 readChunk (RiffChunk *c)
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
832 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
833 int status;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
834 char n;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
835
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
836 if ((status = dread(c, sizeof(RiffChunk), 1)))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
837 if (BIG_ENDIAN)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
838 swapl(&c->ckSize, n);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
839
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
840 return status;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
841 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
842
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
843 /* A very straight-forward translation of WaveOpenFileForReading to
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
844 read the wave data from a buffer in memory. */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
845
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
846 static WaveInfo *
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
847 WaveOpenDataForReading (const char *data,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
848 int length)
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
849 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
850 RiffChunk ck;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
851 RIFF_FOURCC fourcc;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
852 AuInt32 fileSize;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
853 WaveInfo *wi;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
854
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
855
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
856 if (!(wi = (WaveInfo *) malloc(sizeof(WaveInfo))))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
857 return NULL;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
858
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
859 wi->comment = NULL;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
860 wi->dataOffset = wi->format = wi->writing = 0;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
861
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
862 dopen(data, length);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
863
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
864 if (!readChunk(&ck) ||
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
865 cmpID(&ck.ckID, RIFF_RiffID) ||
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
866 !readFourcc(&fourcc) ||
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
867 cmpID(&fourcc, RIFF_WaveID))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
868 Err();
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
869
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
870 fileSize = PAD2(ck.ckSize) - sizeof(RIFF_FOURCC);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
871
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
872 while (fileSize >= sizeof(RiffChunk))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
873 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
874 if (!readChunk(&ck))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
875 Err();
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
876
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
877 fileSize -= sizeof(RiffChunk) + PAD2(ck.ckSize);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
878
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
879 /* LIST chunk */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
880 if (!cmpID(&ck.ckID, RIFF_ListID))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
881 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
882 if (!readFourcc(&fourcc))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
883 Err();
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
884
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
885 /* INFO chunk */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
886 if (!cmpID(&fourcc, RIFF_ListInfoID))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
887 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
888 ck.ckSize -= sizeof(RIFF_FOURCC);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
889
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
890 while (ck.ckSize)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
891 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
892 RiffChunk c;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
893
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
894 if (!readChunk(&c))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
895 Err();
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
896
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
897 /* ICMT chunk */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
898 if (!cmpID(&c.ckID, RIFF_InfoIcmtID))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
899 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
900 if (!(wi->comment = (char *) malloc(c.ckSize)) ||
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
901 !dread(wi->comment, c.ckSize, 1))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
902 Err();
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
903
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
904 if (c.ckSize & 1)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
905 dgetc(); /* eat the pad byte */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
906 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
907 else
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
908 /* skip unknown chunk */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
909 dseek(PAD2(c.ckSize), 1);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
910
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
911 ck.ckSize -= sizeof(RiffChunk) + PAD2(c.ckSize);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
912 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
913 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
914 else
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
915 /* skip unknown chunk */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
916 dseek(PAD2(ck.ckSize) - sizeof(RIFF_FOURCC), 1);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
917 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
918 /* wave format chunk */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
919 else if (!cmpID(&ck.ckID, RIFF_WaveFmtID) && !wi->format)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
920 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
921 AuInt32 dummy;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
922
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
923 wi->format = DataReadS(BIG_ENDIAN);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
924 wi->channels = DataReadS(BIG_ENDIAN);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
925 wi->sampleRate = DataReadL(BIG_ENDIAN);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
926
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
927 /* we don't care about the next two fields */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
928 dummy = DataReadL(BIG_ENDIAN);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
929 dummy = DataReadS(BIG_ENDIAN);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
930
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
931 if (wi->format != RIFF_WAVE_FORMAT_PCM)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
932 Err();
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
933
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
934 wi->bitsPerSample = DataReadS(BIG_ENDIAN);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
935
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
936 /* skip any other format specific fields */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
937 dseek(PAD2(ck.ckSize - 16), 1);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
938 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
939 /* wave data chunk */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
940 else if (!cmpID(&ck.ckID, RIFF_WaveDataID) && !wi->dataOffset)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
941 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
942 long endOfFile;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
943
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
944 wi->dataOffset = dtell();
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
945 wi->dataSize = ck.ckSize;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
946 dseek(0, 2);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
947 endOfFile = dtell();
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
948
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
949 /* seek past the data */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
950 if (dseek(wi->dataOffset + PAD2(ck.ckSize), 0) ||
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
951 dtell() > endOfFile)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
952 {
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
953 /* the seek failed, assume the size is bogus */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
954 dseek(0, 2);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
955 wi->dataSize = dtell() - wi->dataOffset;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
956 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
957
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
958 wi->dataOffset -= sizeof(long);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
959 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
960 else
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
961 /* skip unknown chunk */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
962 dseek(PAD2(ck.ckSize), 1);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
963 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
964
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
965 if (!wi->dataOffset)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
966 Err();
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
967
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
968 wi->numSamples = wi->dataSize / wi->channels / (wi->bitsPerSample >> 3);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
969
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
970 if (!wi->comment)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
971 wi->comment = NameFromData (data + wi->dataOffset,
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
972 length - wi->dataOffset);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
973
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
974 wi->fp = NULL;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
975
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
976 return wi;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
977 }
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
978
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
979
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 static Sound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 SoundOpenDataForReading (unsigned char *data,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 int length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 Sound s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 if (!(s = (Sound) malloc (sizeof (SoundRec))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
990 if ((s->formatInfo = SndOpenDataForReading ((char *) data, length)) != NULL)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
992 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatSnd].toSound)) (s))
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
993 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
994 SndCloseFile ((SndInfo *) (s->formatInfo));
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
995 free (s);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
996 return NULL;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
997 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
999 else if ((s->formatInfo = WaveOpenDataForReading ((char *) data, length)) != NULL)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1001 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatWave].toSound)) (s))
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
1002 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1003 WaveCloseFile ((WaveInfo *) (s->formatInfo));
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
1004 free (s);
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
1005 return NULL;
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
1006 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 return s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 }