annotate src/nas.c @ 611:38db05db9cb5

[xemacs-hg @ 2001-06-08 12:21:09 by ben] ------ gc-in-window-procedure fixes ------ alloc.c: Create "post-gc actions", to avoid those dreaded "GC during window procedure" problems. event-msw.c: Abort, clean and simple, when GC in window procedure. We want to flush these puppies out. glyphs-msw.c: Use a post-gc action when destroying subwindows. lisp.h: Declare register_post_gc_action(). scrollbar-msw.c: Use a post-gc action when unshowing scrollbar windows, if in gc. redisplay.c: Add comment about the utter evilness of what's going down here. ------ cygwin setitimer fixes ------ Makefile.in.in: Compile profile.c only when HAVE_SETITIMER. nt.c: Style fixes. nt.c: Move setitimer() emulation to win32.c, because Cygwin needs it too. profile.c: Make sure we don't compile if no setitimer(). Use qxe_setitimer() instead of just plain setitimer(). signal.c: Define qxe_setitimer() as an encapsulation around setitimer() -- call setitimer() directly unless Cygwin or MS Win, in which case we use our simulated version in win32.c. systime.h: Prototype mswindows_setitimer() and qxe_setitimer(). Long comment about "qxe" and the policy regarding encapsulation. win32.c: Move setitimer() emulation here, so Cygwin can use it. Rename a couple of functions and variables to be longer and more descriptive. In setitimer_helper_proc(), send the signal using either mswindows_raise() or (on Cygwin) kill(). If for some reason we are still getting lockups, we'll change the kill() to directly invoke the signal handlers. ------ windows shell fixes ------ callproc.c, ntproc.c: Comments about how these two files must die. callproc.c: On MS Windows, init shell-file-name from SHELL, then COMSPEC, not just COMSPEC. (more correct and closer to FSF.) Don't force a value for SHELL into the environment. (Comments added to explain why not.) nt.c: Don't shove a fabricated SHELL into the environment. See above. ------ misc fixes ------ glyphs-shared.c: Style correction. xemacs-faq.texi: Merge in the rest of Hrvoje's Windows FAQ. Redo section 7 to update current reality and add condensed versions of new changes for 21.1 and 21.4. (Not quite done for 21.4.) Lots more Windows updates. process.el: Need to quote a null argument, too. From Dan Holmsand. startup.el: startup.el: Call MS Windows init function. win32-native.el: Correct comments at top. Correctly handle passing arguments to Cygwin programs and to bash. Fix quoting of zero-length arguments (from Dan Holmsand). Set shell-command-switch based on shell-file-name, which in turn comes from env var SHELL.
author ben
date Fri, 08 Jun 2001 12:21:27 +0000
parents 183866b06e0b
children 023b83f4e54b
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
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
29 /* This file Mule-ized by Ben Wing, 5-15-01. */
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
30
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 /* There are four compile-time options.
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 * XTOOLKIT This will be part of an Xt program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 * XTEVENTS The playing will be supervised asynchronously by the Xt event
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 * loop. If not set, playing will be completed within the call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 * to play_file etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 * 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
40 * program will attempt not to die if the nas server does.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 * 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
43 * server. They are named by their comment field, or if that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 * 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
45 * from the sample itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 /* CHANGES:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 * 10/8/94, rjc Changed names from netaudio to nas
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 * Added back asynchronous play if nas library has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 * correct error facilities.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 * 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
53 * be sure all play has finished.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 * 1998-10-01 rlt Added support for WAVE files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 #include "lisp.h"
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
59
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
60 #include "sound.h"
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
61
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 #include "sysdep.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
65 /* NAS <= 1.2p5 defines {BIG,LITTLE}_ENDIAN in <audio/fileutil.h>,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
66 conflicting with GNU libc (at least); newer versions avoid this
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
67 name space pollution.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
69 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
70
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
71 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
72 seems unnecessarily complex.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
73 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 #undef LITTLE_ENDIAN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #undef BIG_ENDIAN
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
76
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 #include <audio/audiolib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 #include <audio/soundlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #include <audio/snd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 #include <audio/wave.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #include <audio/fileutil.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
83 /* 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
84 #ifndef NAS_LITTLE_ENDIAN
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
85 #define NAS_LITTLE_ENDIAN LITTLE_ENDIAN
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
86 #define NAS_BIG_ENDIAN BIG_ENDIAN
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
87 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
88
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 # define XTOOLKIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 # define XTEVENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 # define ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 # define CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 * For old NAS libraries, force playing to be synchronous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 * and declare the long jump point locally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 # if defined (NAS_NO_ERROR_JUMP)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 # undef XTEVENTS
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 # include <setjmp.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 jmp_buf AuXtErrorJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 # endif
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 # define play_sound_file nas_play_sound_file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 # define play_sound_data nas_play_sound_data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 # define wait_for_sounds nas_wait_for_sounds
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 # define init_play nas_init_play
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 # define close_down_play nas_close_down_play
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 #ifdef XTOOLKIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 # include <X11/Intrinsic.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 # include <audio/Xtutil.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 #endif
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 #if defined (ROBUST_PLAY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 static AuBool CatchIoErrorAndJump (AuServer *aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 static AuBool CatchErrorAndJump (AuServer *aud, AuErrorEvent *event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 SIGTYPE sigpipe_handle (int signo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 #endif
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 extern Lisp_Object Vsynchronous_sounds;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
126 static Sound SoundOpenDataForReading (UChar_Binary *data, int length);
428
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 static AuServer *aud;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 /* count of sounds currently being played. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 static int sounds_in_play;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #ifdef XTOOLKIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 static Display *aud_server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 static XtInputId input_id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
138 static Extbyte *aud_server;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 #endif /* XTOOLKIT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
141 Extbyte *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 init_play (
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 #ifdef XTOOLKIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 Display *display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
146 Extbyte *server
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 #endif
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
148 );
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
149 Extbyte *
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
150 init_play (
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
151 #ifdef XTOOLKIT
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
152 Display *display
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
153 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
154 Extbyte *server
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
155 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
158 Extbyte *err_message;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
159 SIGTYPE (*old_sigpipe) (int);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 #ifdef XTOOLKIT
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
162 Extbyte * server = DisplayString (display);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 XtAppContext app_context = XtDisplayToApplicationContext (display);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 aud_server = display;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 aud_server = server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 old_sigpipe = signal (SIGPIPE, sigpipe_handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 if (setjmp (AuXtErrorJump))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 start_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 return "error in NAS";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 #endif
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 #if defined (ROBUST_PLAY) && !defined (NAS_NO_ERROR_JUMP)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 AuDefaultIOErrorHandler = CatchIoErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 AuDefaultErrorHandler = CatchErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 stop_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 aud = AuOpenServer (server, 0, NULL, 0, NULL, &err_message);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 start_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 if (!aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 if (err_message == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 return "Can't connect to audio server";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 return err_message;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 #if defined (ROBUST_PLAY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 # if defined (NAS_NO_ERROR_JUMP)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 aud->funcs.ioerror_handler = CatchIoErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 aud->funcs.error_handler = CatchErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 # else /* !NAS_NO_ERROR_JUMP */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 AuDefaultIOErrorHandler = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 AuDefaultErrorHandler = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 # endif
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 #ifdef XTEVENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 input_id = AuXtAppAddAudioHandler (app_context, aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 #endif
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 #ifdef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 AuSetCloseDownMode (aud, AuCloseDownRetainPermanent, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 sounds_in_play = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
233 static void
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 close_down_play (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 AuCloseServer (aud);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
238 sound_warn ("disconnected from audio server");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 /********************************************************************\
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 * Callback which is run when the sound finishes playing. *
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 \********************************************************************/
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 static void
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
248 doneCB (AuServer *auserver,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 AuEventHandlerRec *handler,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 AuEvent *ev,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 AuPointer data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 int *in_play_p = (int *) data;
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 (*in_play_p) --;
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 #ifdef CACHE_SOUNDS
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 * Play a sound by playing the relevant bucket, if any or *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 * downloading it if not. *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 \********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 do_caching_play (Sound s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 int volume,
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
270 UChar_Binary *buf)
428
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 AuBucketAttributes *list, b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 AuBucketID id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 int n;
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 AuSetString (AuBucketDescription (&b),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 AuStringLatin1, strlen (SoundComment (s)), SoundComment (s));
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 list = AuListBuckets (aud, AuCompCommonDescriptionMask, &b, &n, NULL);
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 if (list == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
284 AuPointer my_buf;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 if (buf==NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
288 if ((my_buf= (AuPointer) malloc (SoundNumBytes (s)))==NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 return;
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
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
293 if (SoundReadFile ((Extbyte *) my_buf, SoundNumBytes (s), s) != SoundNumBytes (s))
428
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 free (my_buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 else
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
300 my_buf = (AuPointer) buf;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 id = AuSoundCreateBucketFromData (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 my_buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 AuAccessAllMasks,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 if (buf == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 free (my_buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 else /* found cached sound */
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 id = AuBucketIdentifier (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 AuFreeBucketAttributes (aud, n, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 }
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 sounds_in_play++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 AuSoundPlayFromBucket (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 id,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 AuNone,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 AuFixedPointFromFraction (volume, 100),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 doneCB, (AuPointer) &sounds_in_play,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 NULL, NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 NULL, NULL);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 #endif /* CACHE_SOUNDS */
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
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
332 void wait_for_sounds (void);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 wait_for_sounds (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 AuEvent ev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 while (sounds_in_play>0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 AuNextEvent (aud, AuTrue, &ev);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 AuDispatchEvent (aud, &ev);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
346 int play_sound_file (Extbyte *sound_file, int volume);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 int
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
348 play_sound_file (Extbyte *sound_file,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 int volume)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
351 SIGTYPE (*old_sigpipe) (int);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 old_sigpipe=signal (SIGPIPE, sigpipe_handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 if (setjmp (AuXtErrorJump))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 return 0;
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 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 if (aud==NULL) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 if (aud_server != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
365 Extbyte *m;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 /* attempt to reconect */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 if ((m=init_play (aud_server))!= NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 #endif
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
378 sound_warn ("Attempt to play with no audio init\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 return 0;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 #ifndef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 sounds_in_play++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 AuSoundPlayFromFile (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 sound_file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 AuNone,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 AuFixedPointFromFraction (volume,100),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 doneCB, (AuPointer) &sounds_in_play,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 /* Cache the sounds in buckets on the server */
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 Sound s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 if ((s = SoundOpenFileForReading (sound_file))==NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 if (SoundComment (s) == NULL || SoundComment (s)[0] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 SoundComment (s) = FileCommentFromFilename (sound_file);
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 do_caching_play (s, volume, NULL);
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 SoundCloseFile (s);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 #endif /* CACHE_SOUNDS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 #ifndef XTEVENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 wait_for_sounds ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 if (!NILP (Vsynchronous_sounds))
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 wait_for_sounds ();
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 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 #endif
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 return 1;
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
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
439 int play_sound_data (UChar_Binary *data, int length, int volume);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 int
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
441 play_sound_data (UChar_Binary *data,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 int length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 int volume)
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 Sound s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 int offset;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
447 SIGTYPE (*old_sigpipe) (int);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 #if !defined (XTEVENTS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 AuEvent ev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 #endif
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 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 old_sigpipe = signal (SIGPIPE, sigpipe_handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 if (setjmp (AuXtErrorJump) !=0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 return 0;
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 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 if (aud == NULL) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 if (aud_server != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
466 Extbyte *m;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 /* attempt to reconect */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 if ((m = init_play (aud_server)) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 #endif
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
478 sound_warn ("Attempt to play with no audio init\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 if ((s=SoundOpenDataForReading (data, length))==NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
488 sound_warn ("unknown sound type");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 if (SoundFileFormat (s) == SoundFileFormatSnd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 /* hack, hack */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 offset = ((SndInfo *) (s->formatInfo))->h.dataOffset;
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 else if (SoundFileFormat (s) == SoundFileFormatWave)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 offset = ((WaveInfo *) (s->formatInfo))->dataOffset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
506 sound_warn ("only understand snd and wave files at the moment");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 SoundCloseFile (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 #ifndef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 sounds_in_play++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 AuSoundPlayFromData (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 data+offset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 AuNone,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 AuFixedPointFromFraction (volume,100),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 doneCB, (AuPointer) &sounds_in_play,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 /* Cache the sounds in buckets on the server */
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 do_caching_play (s, volume, data+offset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 #endif /* CACHE_SOUNDS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 #ifndef XTEVENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 wait_for_sounds ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 if (!NILP (Vsynchronous_sounds))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 wait_for_sounds ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 #endif
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 SoundCloseFile (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 #ifdef ROBUST_PLAY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 signal (SIGPIPE, old_sigpipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 #endif
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 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 #if defined (ROBUST_PLAY)
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 /********************************************************************\
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 * Code to protect the client from server shutdowns. *
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 * This is unbelievably horrible. *
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 \********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 static AuBool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 CatchIoErrorAndJump (AuServer *old_aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 if (old_aud)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
567 sound_warn ("Audio Server connection broken");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
569 sound_warn ("Audio Server connection broken because of signal");
428
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 #ifdef XTEVENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 #ifdef XTOOLKIT
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 AuXtAppRemoveAudioHandler (aud, input_id);
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 #endif
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 if (aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 AuCloseServer (aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 aud = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 sounds_in_play = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 longjmp (AuXtErrorJump, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 #else /* not XTEVENTS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 if (aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 AuCloseServer (aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 aud = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 sounds_in_play = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 longjmp (AuXtErrorJump, 1);
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 #endif /* XTEVENTS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 sigpipe_handle (int signo)
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 CatchIoErrorAndJump (NULL);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 static AuBool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 CatchErrorAndJump (AuServer *old_aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 AuErrorEvent *event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 return CatchIoErrorAndJump (old_aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 #endif /* ROBUST_PLAY */
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 /********************************************************************\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 * This code is here because the nas Sound library doesn't *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 * support playing from a file buffered in memory. It's a fairly *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 * direct translation of the file-based equivalent. *
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 * Since we don't have a filename, samples with no comment field *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 * are named by a section of their content. *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 * *
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 /* Create a name from the sound. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
625 static Extbyte *
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
626 NameFromData (const Char_Binary *buf,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 int len)
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 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
630 Extbyte name[9];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 int i;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
632 Extbyte *s;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 buf+=len/2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 len -= len/2;
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 i=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 while (i<8 && len >0)
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 while (*buf < 32 && len>0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 buf++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 len--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 name[i]= *buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 buf++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 len--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 name[i]='\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 if (i==8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
655 strcpy (s = (Extbyte *) malloc (10), name);
428
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
659 strcpy (s = (Extbyte *) malloc (15), "short sound");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 return s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 }
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 /* 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
666 moment.
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 static SndInfo *
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
670 SndOpenDataForReading (const Char_Binary *data,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 int length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 SndInfo *si;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 int size;
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 if (!(si = (SndInfo *) malloc (sizeof (SndInfo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 return NULL;
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 si->comment = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 si->writing = 0;
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 memcpy (&si->h, data, sizeof (SndHeader));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
685 if (NAS_LITTLE_ENDIAN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
687 Char_Binary n;
428
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 swapl (&si->h.magic, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 swapl (&si->h.dataOffset, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 swapl (&si->h.dataSize, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 swapl (&si->h.format, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 swapl (&si->h.sampleRate, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 swapl (&si->h.tracks, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 if (si->h.magic != SND_MAGIC_NUM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 free (si);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 return NULL;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 size = si->h.dataOffset - sizeof (SndHeader);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 if (size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
707 if (!(si->comment = (Extbyte *) malloc (size + 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 free (si);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 return NULL;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 memcpy (si->comment, data+sizeof (SndHeader), size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 *(si->comment + size) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 if (*si->comment == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 si->comment =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 si->comment = NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 si->h.dataSize = length-si->h.dataOffset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 si->fp=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 return si;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 }
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 /* 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
731 read wave data from memory, so these functions do that for us. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 #define Err() { return NULL; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 #define readFourcc(_f) dread(_f, sizeof(RIFF_FOURCC), 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 #define cmpID(_x, _y) \
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
736 strncmp((Char_Binary *) (_x), (Char_Binary *) (_y), sizeof(RIFF_FOURCC))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 #define PAD2(_x) (((_x) + 1) & ~1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 /* These functions here are for faking file I/O from buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 /* The "file" position */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
742 static size_t file_posn;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 /* The length of the "file" */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
744 static size_t file_len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 /* The actual "file" data. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
746 static const void* file_data;
428
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 /* Like fopen, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
750 dopen (const void* data, size_t length)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 file_data = data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 file_len = length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 file_posn = 0;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 /* Like fread, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 static int
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
759 dread (void* buf, size_t size, size_t nitems)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
761 size_t nread = size * nitems;
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 if (file_posn + nread <= file_len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
765 memcpy(buf, (Char_Binary *) file_data + file_posn, size * nitems);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 file_posn += nread;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 return nitems;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 else
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 return EOF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 /* Like fgetc, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 static int
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
777 dgetc (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 if (file_posn < file_len)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
780 return ((Char_Binary *)file_data)[file_posn++];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 return -1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 /* Like fseek, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 static int
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
787 dseek (long offset, int from)
428
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 if (from == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 file_posn = offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 else if (from == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 file_posn += offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 else if (from == 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 file_posn = file_len + offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 }
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 /* Like ftell, but for a buffer in memory */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
800 static long
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
801 dtell (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 return file_posn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 /* Data buffer analogs for FileReadS and FileReadL in NAS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 static unsigned short
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
809 DataReadS (int swapit)
428
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 unsigned short us;
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 dread(&us, 2, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 if (swapit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 us = FileSwapS(us);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 return us;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 static AuUint32
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
820 DataReadL (int swapit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 AuUint32 ul;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 dread(&ul, 4, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 if (swapit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 ul = FileSwapL(ul);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 return ul;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 static int
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
831 readChunk (RiffChunk *c)
428
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 int status;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
834 Char_Binary n;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 if ((status = dread(c, sizeof(RiffChunk), 1)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
837 if (NAS_BIG_ENDIAN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 swapl(&c->ckSize, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 return status;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 /* A very straight-forward translation of WaveOpenFileForReading to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 read the wave data from a buffer in memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 static WaveInfo *
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
847 WaveOpenDataForReading (const Char_Binary *data,
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
848 int length)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 RiffChunk ck;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 RIFF_FOURCC fourcc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 AuInt32 fileSize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 WaveInfo *wi;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 if (!(wi = (WaveInfo *) malloc(sizeof(WaveInfo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 wi->comment = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 wi->dataOffset = wi->format = wi->writing = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 dopen(data, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 if (!readChunk(&ck) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 cmpID(&ck.ckID, RIFF_RiffID) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 !readFourcc(&fourcc) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 cmpID(&fourcc, RIFF_WaveID))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 Err();
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 fileSize = PAD2(ck.ckSize) - sizeof(RIFF_FOURCC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 while (fileSize >= sizeof(RiffChunk))
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 if (!readChunk(&ck))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 Err();
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 fileSize -= sizeof(RiffChunk) + PAD2(ck.ckSize);
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 /* LIST chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 if (!cmpID(&ck.ckID, RIFF_ListID))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 if (!readFourcc(&fourcc))
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 /* INFO chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 if (!cmpID(&fourcc, RIFF_ListInfoID))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 ck.ckSize -= sizeof(RIFF_FOURCC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 while (ck.ckSize)
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 RiffChunk c;
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 if (!readChunk(&c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 Err();
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 /* ICMT chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 if (!cmpID(&c.ckID, RIFF_InfoIcmtID))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
900 if (!(wi->comment = (Extbyte *) malloc(c.ckSize)) ||
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 !dread(wi->comment, c.ckSize, 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 Err();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 if (c.ckSize & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 dgetc(); /* eat the pad byte */
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 /* skip unknown chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 dseek(PAD2(c.ckSize), 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 ck.ckSize -= sizeof(RiffChunk) + PAD2(c.ckSize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 /* skip unknown chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 dseek(PAD2(ck.ckSize) - sizeof(RIFF_FOURCC), 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 /* wave format chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 else if (!cmpID(&ck.ckID, RIFF_WaveFmtID) && !wi->format)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 AuInt32 dummy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
923 wi->format = DataReadS(NAS_BIG_ENDIAN);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
924 wi->channels = DataReadS(NAS_BIG_ENDIAN);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
925 wi->sampleRate = DataReadL(NAS_BIG_ENDIAN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 /* we don't care about the next two fields */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
928 dummy = DataReadL(NAS_BIG_ENDIAN);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
929 dummy = DataReadS(NAS_BIG_ENDIAN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 if (wi->format != RIFF_WAVE_FORMAT_PCM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 Err();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
934 wi->bitsPerSample = DataReadS(NAS_BIG_ENDIAN);
428
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 /* skip any other format specific fields */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 dseek(PAD2(ck.ckSize - 16), 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 /* wave data chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 else if (!cmpID(&ck.ckID, RIFF_WaveDataID) && !wi->dataOffset)
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 long endOfFile;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 wi->dataOffset = dtell();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 wi->dataSize = ck.ckSize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 dseek(0, 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 endOfFile = dtell();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 /* seek past the data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 if (dseek(wi->dataOffset + PAD2(ck.ckSize), 0) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 dtell() > endOfFile)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 /* the seek failed, assume the size is bogus */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 dseek(0, 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 wi->dataSize = dtell() - 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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 wi->dataOffset -= sizeof(long);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 /* skip unknown chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 dseek(PAD2(ck.ckSize), 1);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 if (!wi->dataOffset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 Err();
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 wi->numSamples = wi->dataSize / wi->channels / (wi->bitsPerSample >> 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 if (!wi->comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 wi->comment = NameFromData (data + wi->dataOffset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 length - wi->dataOffset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 wi->fp = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 return wi;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 }
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 static Sound
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
981 SoundOpenDataForReading (UChar_Binary *data,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 int length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983
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 Sound s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 if (!(s = (Sound) malloc (sizeof (SoundRec))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
990 if ((s->formatInfo = SndOpenDataForReading ((Char_Binary *) data, length)) != NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
992 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatSnd].toSound)) (s))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
994 SndCloseFile ((SndInfo *) (s->formatInfo));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 free (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 }
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
999 else if ((s->formatInfo = WaveOpenDataForReading ((Char_Binary *) data, length)) != NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
1001 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatWave].toSound)) (s))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
1003 WaveCloseFile ((WaveInfo *) (s->formatInfo));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 free (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 return s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 }