annotate src/nas.c @ 70:131b0175ea99 r20-0b30

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