annotate src/nas.c @ 296:5a79be0ef6a8 r21-0b46

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