annotate src/nas.c @ 140:585fb297b004 r20-2b4

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