annotate src/nas.c @ 510:5bdbc721d46a

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