annotate src/nas.c @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
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.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #if __STDC__ || defined (STDC_HEADERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 # include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 # include <unistd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 # include <stdarg.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 #include <config.h> /* for CONST in syssignal.h (neal@ctd.comsat.com) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 #include "syssignal.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 #include <audio/audiolib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 #include <audio/soundlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 #include <audio/snd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #include <audio/fileutil.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 # include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 # include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 # define XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 # define XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 # define ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 # define CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 * For old NAS libraries, force playing to be synchronous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 * and declare the long jump point locally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 # if defined (NAS_NO_ERROR_JUMP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 # undef XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 # include <setjmp.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 jmp_buf AuXtErrorJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 /* The GETTEXT is correct. --ben */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 # define warn(str) warn_when_safe (Qnas, Qwarning, "nas: %s ", GETTEXT (str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 # define play_sound_file nas_play_sound_file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 # define play_sound_data nas_play_sound_data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 # define wait_for_sounds nas_wait_for_sounds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 # define init_play nas_init_play
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 # define close_down_play nas_close_down_play
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 #else /* !emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 # define warn(str) fprintf (stderr, "%s\n", (str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 # define CONST const
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #endif /* emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 # include <X11/Intrinsic.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 # include <audio/Xtutil.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 #if defined (ROBUST_PLAY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 static AuBool CatchIoErrorAndJump (AuServer *aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 static AuBool CatchErrorAndJump (AuServer *aud, AuErrorEvent *event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 SIGTYPE sigpipe_handle (int signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 extern Lisp_Object Vsynchronous_sounds;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 static Sound SoundOpenDataForReading (unsigned char *data, int length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 static AuServer *aud;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 /* count of sounds currently being played. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 static int sounds_in_play;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 static Display *aud_server;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 static XtInputId input_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 static char *aud_server;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 #endif /* XTOOLKIT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 init_play (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 Display *display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 char *server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 char *err_message;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 SIGTYPE (*old_sigpipe) ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 char * server = DisplayString (display);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 XtAppContext app_context = XtDisplayToApplicationContext (display);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 aud_server = display;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 aud_server = server;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 old_sigpipe = signal (SIGPIPE, sigpipe_handle);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 if (setjmp (AuXtErrorJump))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 return "error in NAS";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 }
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 #if defined (ROBUST_PLAY) && !defined (NAS_NO_ERROR_JUMP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 AuDefaultIOErrorHandler = CatchIoErrorAndJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 AuDefaultErrorHandler = CatchErrorAndJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
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 stop_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 aud = AuOpenServer (server, 0, NULL, 0, NULL, &err_message);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 if (!aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 if (err_message == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 return "Can't connect to audio server";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 return err_message;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 #if defined (ROBUST_PLAY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 # if defined (NAS_NO_ERROR_JUMP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 aud->funcs.ioerror_handler = CatchIoErrorAndJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 aud->funcs.error_handler = CatchErrorAndJump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 # else /* !NAS_NO_ERROR_JUMP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 AuDefaultIOErrorHandler = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 AuDefaultErrorHandler = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 #ifdef XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 input_id = AuXtAppAddAudioHandler (app_context, aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 #ifdef CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 AuSetCloseDownMode (aud, AuCloseDownRetainPermanent, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 signal (SIGPIPE, old_sigpipe);
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 sounds_in_play = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 close_down_play (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 AuCloseServer (aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 warn ("disconnected from audio server");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 /********************************************************************\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 * Callback which is run when the sound finishes playing. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 \********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 doneCB (AuServer *aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 AuEventHandlerRec *handler,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 AuEvent *ev,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 AuPointer data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 int *in_play_p = (int *) data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (*in_play_p) --;
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 #ifdef CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 /********************************************************************\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 * Play a sound by playing the relevant bucket, if any or *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 * downloading it if not. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 \********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 do_caching_play (Sound s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 int volume,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 unsigned char *buf)
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 AuBucketAttributes *list, b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 AuBucketID id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 int n;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 AuSetString (AuBucketDescription (&b),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 AuStringLatin1, strlen (SoundComment (s)), SoundComment (s));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 list = AuListBuckets (aud, AuCompCommonDescriptionMask, &b, &n, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 if (list == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 unsigned char *my_buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 if (buf==NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 if ((my_buf=malloc (SoundNumBytes (s)))==NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 if (SoundReadFile (my_buf, SoundNumBytes (s), s) != SoundNumBytes (s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 free (my_buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 my_buf=buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 id = AuSoundCreateBucketFromData (aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 my_buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 AuAccessAllMasks,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 if (buf == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 free (my_buf);
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 /* found cached sound */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 id = AuBucketIdentifier (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 AuFreeBucketAttributes (aud, n, list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 sounds_in_play++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 AuSoundPlayFromBucket (aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 id,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 AuNone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 AuFixedPointFromFraction (volume, 100),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 doneCB, (AuPointer) &sounds_in_play,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 NULL, NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 NULL, NULL);
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 #endif /* CACHE_SOUNDS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 wait_for_sounds (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 AuEvent ev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 while (sounds_in_play>0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 AuNextEvent (aud, AuTrue, &ev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 AuDispatchEvent (aud, &ev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 play_sound_file (char *sound_file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 int volume)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 SIGTYPE (*old_sigpipe) ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 old_sigpipe=signal (SIGPIPE, sigpipe_handle);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 if (setjmp (AuXtErrorJump))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 if (aud==NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 if (aud_server != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 char *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 /* attempt to reconect */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 if ((m=init_play (aud_server))!= NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 #ifdef ROBUST_PLAY
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 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 warn ("Attempt to play with no audio init\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 #ifndef CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 sounds_in_play++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 AuSoundPlayFromFile (aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 sound_file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 AuNone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 AuFixedPointFromFraction (volume,100),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 doneCB, (AuPointer) &sounds_in_play,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 /* Cache the sounds in buckets on the server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 Sound s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 if ((s = SoundOpenFileForReading (sound_file))==NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 if (SoundComment (s) == NULL || SoundComment (s)[0] == '\0')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 SoundComment (s) = FileCommentFromFilename (sound_file);
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 do_caching_play (s, volume, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 SoundCloseFile (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 #endif /* CACHE_SOUNDS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 #ifndef XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 wait_for_sounds ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 if (!NILP (Vsynchronous_sounds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 wait_for_sounds ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 play_sound_data (unsigned char *data,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 int length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 int volume)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 Sound s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 int offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 SIGTYPE (*old_sigpipe) ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 #if !defined (XTEVENTS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 AuEvent ev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 old_sigpipe = signal (SIGPIPE, sigpipe_handle);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 if (setjmp (AuXtErrorJump) !=0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 if (aud == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 if (aud_server != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 char *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 /* attempt to reconect */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 if ((m = init_play (aud_server)) != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 warn ("Attempt to play with no audio init\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 if ((s=SoundOpenDataForReading (data, length))==NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 warn ("unknown sound type");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 if (SoundFileFormat (s) == SoundFileFormatSnd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 /* hack, hack */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 offset = ((SndInfo *) (s->formatInfo))->h.dataOffset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 warn ("only understand snd files at the moment");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 SoundCloseFile (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 #ifndef CACHE_SOUNDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 sounds_in_play++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 AuSoundPlayFromData (aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 data+offset,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 AuNone,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 AuFixedPointFromFraction (volume,100),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 doneCB, (AuPointer) &sounds_in_play,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 NULL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 /* Cache the sounds in buckets on the server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 do_caching_play (s, volume, data+offset);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 #endif /* CACHE_SOUNDS */
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 XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 wait_for_sounds ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 if (!NILP (Vsynchronous_sounds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 wait_for_sounds ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 SoundCloseFile (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 #ifdef ROBUST_PLAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 #if defined (ROBUST_PLAY)
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 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 * Code to protect the client from server shutdowns. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 * This is unbelievably horrible. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 \********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 static AuBool
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 CatchIoErrorAndJump (AuServer *old_aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 if (old_aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 warn ("Audio Server connection broken");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 warn ("Audio Server connection broken because of signal");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 #ifdef XTEVENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 #ifdef XTOOLKIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 AuXtAppRemoveAudioHandler (aud, input_id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 if (aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 AuCloseServer (aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 aud = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 sounds_in_play = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 longjmp (AuXtErrorJump, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 #else /* not XTEVENTS */
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 (aud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 AuCloseServer (aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 aud = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 sounds_in_play = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 longjmp (AuXtErrorJump, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 #endif /* XTEVENTS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 sigpipe_handle (int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 CatchIoErrorAndJump (NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 static AuBool
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 CatchErrorAndJump (AuServer *old_aud,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 AuErrorEvent *event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 return CatchIoErrorAndJump (old_aud);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 #endif /* ROBUST_PLAY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 /********************************************************************\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 * This code is here because the nas Sound library doesn't *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 * support playing from a file buffered in memory. It's a fairly *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 * direct translation of the file-based equivalent. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 * Since we don't have a filename, samples with no comment field *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 * are named by a section of their content. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 \********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 /* Create a name from the sound. */
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 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 NameFromData (CONST unsigned char *buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 int len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 unsigned char name[9];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 char *s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 buf+=len/2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 len -= len/2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 i=0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 while (i<8 && len >0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 while (*buf < 32 && len>0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 buf++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 len--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 name[i]= *buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 i++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 buf++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 len--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 name[i]='\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 if (i==8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 strcpy (s=malloc (10), name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 strcpy (s=malloc (15), "short sound");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 return s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 /* 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
644 moment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 static SndInfo *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 SndOpenDataForReading (CONST char *data,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 int length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 SndInfo *si;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 int size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 if (!(si = (SndInfo *) malloc (sizeof (SndInfo))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 si->comment = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 si->writing = 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 memcpy (&si->h, data, sizeof (SndHeader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 if (LITTLE_ENDIAN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 char n;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 swapl (&si->h.magic, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 swapl (&si->h.dataOffset, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 swapl (&si->h.dataSize, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 swapl (&si->h.format, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 swapl (&si->h.sampleRate, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 swapl (&si->h.tracks, n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 if (si->h.magic != SND_MAGIC_NUM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 free (si);
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 size = si->h.dataOffset - sizeof (SndHeader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 if (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 if (!(si->comment = (char *) malloc (size + 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 free (si);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 memcpy (si->comment, data+sizeof (SndHeader), size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 *(si->comment + size) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 if (*si->comment == '\0')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 si->comment =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 si->comment = NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 si->h.dataSize = length-si->h.dataOffset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 si->fp=NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 return si;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 static Sound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 SoundOpenDataForReading (unsigned char *data,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 int length)
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 Sound s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 if (!(s = (Sound) malloc (sizeof (SoundRec))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 if ((s->formatInfo = SndOpenDataForReading (data, length))==NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 free (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 if (!(SoundFileInfo[SoundFileFormatSnd].toSound) (s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 SndCloseFile (s->formatInfo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 free (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 return s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734