annotate src/nas.c @ 1346:01c57eb70ae9

[xemacs-hg @ 2003-03-09 02:27:27 by ben] To: xemacs-patches@xemacs.org i.c: Sleep between calls to check for I/O, since these calls are non-blocking. behavior.el: Allow other keywords for forward compatibility. cl-macs.el: Rewrite to eliminate byte-compiler warning when `return' is used without `finally'. cmdloop.el: Avoid truncated error messages for `end-of-file' and the like. cmdloop.el: Avoid char-int error after syncing. files.el: Eliminate byte-compile warnings. printer.el: Fix line-width calculations. #### This used to work. Someone's changes (perhaps by Michael Sperber?) seem to have messed something up. simple.el: Use new clear-left-side functions to avoid messages ending up on the same line as other output. xemacs.mak: Add override for info/ as well when separate source/build dirs. xemacs.mak: Order sections in main build process and add comments. Add additional dependencies to try and prevent later steps from happening when failures in earlier steps have occurred. Makefile.in.in: Order sections in main build process and add comments. Add additional dependencies to try and prevent later steps from happening when failures in earlier steps have occurred. alloc.c: Don't arbitrarily clear Vconfigure_info_directory since it messes up separate build/source dirs. console.c, console.h, device-msw.c, device.c: Add accidentally omitted msprinter console and data descriptions. print.c, console-msw.c: Add clear-left-side functionality to help keep stdio/stderr output from separate sources on separate lines. Generalize the different kinds of debugging output. Add dpa(). profile.c: Add better docs on Unix/Windows differences. regex.c: Fix problems with rel-alloc compilation caused by previous patch. emacs.c: Seg fault rather than abort on Cygwin, since gdb doesn't trap aborts properly. console-gtk-impl.h, console-gtk.h, console-msw.h, console-x-impl.h, console-x.h, dialog-gtk.c, dialog-x.c, event-msw.c, frame-gtk.c, frame-x.c, frameslots.h, glyphs-gtk.c, glyphs-x.c, gui-gtk.c, gui-x.c, inline.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, scrollbar-gtk.c, scrollbar-x.c, ui-gtk.c: Delete popup-data object. Delete menubar_data field from frames, since its usage is frame-specific. Delete menubar-msw.h, gui-x.h, gui-gtk.h. Clean up handling of lwlib callback data GCPRO'ing and add missing GCPRO recomputation in widget code.
author ben
date Sun, 09 Mar 2003 02:27:46 +0000
parents 26274e0d7794
children 18d2b8dabcf7
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.
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
55 * 2002-10-16 Jon Trulson modifed this to work with NAS releases
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
56 * 1.5f and higher. We were using the private variable
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
57 * SoundFileInfo that doesn't exist anymore. But preserve
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
58 * backward compatibility. This will not work for some
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
59 * versions of NAS around 1.5b to 1.5f or so. Known to
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
60 * work on 1.2p5 and 1.6.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #include "lisp.h"
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
65
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
66 #include "sound.h"
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
67
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #include "sysdep.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
71 /* NAS <= 1.2p5 defines {BIG,LITTLE}_ENDIAN in <audio/fileutil.h>,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
72 conflicting with GNU libc (at least); newer versions avoid this
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
73 name space pollution.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
75 DO NOT USE THOSE MACROS in this file. Use NAS_{BIG,LITTLE}_ENDIAN.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
76
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
77 It would be slightly more reliable to do this via configure, but that
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
78 seems unnecessarily complex.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
79 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 #undef LITTLE_ENDIAN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #undef BIG_ENDIAN
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
82
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #include <audio/audiolib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 #include <audio/soundlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 #include <audio/snd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #include <audio/wave.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #include <audio/fileutil.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
89 /* NAS <= 1.2p5 <audio/fileutil.h> doesn't define the NAS_ versions */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
90 #ifndef NAS_LITTLE_ENDIAN
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
91 # define NAS_LITTLE_ENDIAN LITTLE_ENDIAN
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
92 # define NAS_BIG_ENDIAN BIG_ENDIAN
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
93 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
94
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
95 #define XTOOLKIT
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
96 #define XTEVENTS
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
97 #define ROBUST_PLAY
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
98 #define CACHE_SOUNDS
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
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 * For old NAS libraries, force playing to be synchronous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 * and declare the long jump point locally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
105 #if defined (NAS_NO_ERROR_JUMP)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
106 # undef XTEVENTS
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
107 # include <setjmp.h>
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
108 jmp_buf AuXtErrorJump;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
109 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 #ifdef XTOOLKIT
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
112 # include <X11/Intrinsic.h>
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
113 # include <audio/Xtutil.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 #if defined (ROBUST_PLAY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 static AuBool CatchIoErrorAndJump (AuServer *aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 static AuBool CatchErrorAndJump (AuServer *aud, AuErrorEvent *event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 SIGTYPE sigpipe_handle (int signo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 extern Lisp_Object Vsynchronous_sounds;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
124 static Sound SoundOpenDataForReading (UChar_Binary *data, int length);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 static AuServer *aud;
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 /* count of sounds currently being played. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 static int sounds_in_play;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 #ifdef XTOOLKIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 static Display *aud_server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 static XtInputId input_id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
136 static Extbyte *aud_server;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 #endif /* XTOOLKIT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
139 Extbyte *
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
140 nas_init_play (
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 #ifdef XTOOLKIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 Display *display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
144 Extbyte *server
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 #endif
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
146 );
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
147 Extbyte *
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
148 nas_init_play (
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
149 #ifdef XTOOLKIT
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
150 Display *display
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
151 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
152 Extbyte *server
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
153 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
156 Extbyte *err_message;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
157 SIGTYPE (*old_sigpipe) (int);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 #ifdef XTOOLKIT
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
160 Extbyte * server = DisplayString (display);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 XtAppContext app_context = XtDisplayToApplicationContext (display);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 aud_server = display;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 aud_server = server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
170 old_sigpipe = EMACS_SIGNAL (SIGPIPE, sigpipe_handle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 if (setjmp (AuXtErrorJump))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
173 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 start_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 return "error in NAS";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 #if defined (ROBUST_PLAY) && !defined (NAS_NO_ERROR_JUMP)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 AuDefaultIOErrorHandler = CatchIoErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 AuDefaultErrorHandler = CatchErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 stop_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 aud = AuOpenServer (server, 0, NULL, 0, NULL, &err_message);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 start_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 if (!aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
190 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 if (err_message == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 return "Can't connect to audio server";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 return err_message;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 #if defined (ROBUST_PLAY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 # if defined (NAS_NO_ERROR_JUMP)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 aud->funcs.ioerror_handler = CatchIoErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 aud->funcs.error_handler = CatchErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 # else /* !NAS_NO_ERROR_JUMP */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 AuDefaultIOErrorHandler = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 AuDefaultErrorHandler = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 # endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 #ifdef XTEVENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 input_id = AuXtAppAddAudioHandler (app_context, aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 #ifdef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 AuSetCloseDownMode (aud, AuCloseDownRetainPermanent, NULL);
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 ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
217 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
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 sounds_in_play = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 return NULL;
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
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
225 static void
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
226 nas_close_down_play (void)
428
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 AuCloseServer (aud);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
230 sound_warn ("disconnected from audio server");
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 /********************************************************************\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 * Callback which is run when the sound finishes playing. *
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 \********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 static void
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
240 doneCB (AuServer *auserver,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 AuEventHandlerRec *handler,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 AuEvent *ev,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 AuPointer data)
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 int *in_play_p = (int *) data;
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 (*in_play_p) --;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 #ifdef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 /********************************************************************\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 * Play a sound by playing the relevant bucket, if any or *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 * downloading it if not. *
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 do_caching_play (Sound s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 int volume,
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
262 UChar_Binary *buf)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
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 AuBucketAttributes *list, b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 AuBucketID id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 int n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 AuSetString (AuBucketDescription (&b),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 AuStringLatin1, strlen (SoundComment (s)), SoundComment (s));
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 list = AuListBuckets (aud, AuCompCommonDescriptionMask, &b, &n, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 if (list == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
276 AuPointer my_buf;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 if (buf==NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
280 if ((my_buf= (AuPointer) malloc (SoundNumBytes (s)))==NULL)
428
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 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
285 if (SoundReadFile ((Extbyte *) my_buf, SoundNumBytes (s), s) != SoundNumBytes (s))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 free (my_buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 return;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 else
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
292 my_buf = (AuPointer) buf;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 id = AuSoundCreateBucketFromData (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 my_buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 AuAccessAllMasks,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 if (buf == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 free (my_buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 else /* found cached sound */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 id = AuBucketIdentifier (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 AuFreeBucketAttributes (aud, n, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 sounds_in_play++;
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 AuSoundPlayFromBucket (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 id,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 AuNone,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 AuFixedPointFromFraction (volume, 100),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 doneCB, (AuPointer) &sounds_in_play,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 NULL, NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 NULL, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 #endif /* CACHE_SOUNDS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
324 void nas_wait_for_sounds (void);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 void
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
326 nas_wait_for_sounds (void)
428
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 AuEvent ev;
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 while (sounds_in_play>0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 AuNextEvent (aud, AuTrue, &ev);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 AuDispatchEvent (aud, &ev);
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
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
338 int nas_play_sound_file (Extbyte *sound_file, int volume);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 int
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
340 nas_play_sound_file (Extbyte *sound_file,
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
341 int volume)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
343 SIGTYPE (*old_sigpipe) (int);
428
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 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
346 old_sigpipe = EMACS_SIGNAL (SIGPIPE, sigpipe_handle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 if (setjmp (AuXtErrorJump))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
349 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
354 if (aud==NULL)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
355 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
356 if (aud_server != NULL)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
357 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
358 Extbyte *m;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
359 /* attempt to reconect */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
360 if ((m = nas_init_play (aud_server)) != NULL)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
361 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
362
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
364 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 #endif
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
366 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
367 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
368 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
369 else
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
370 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
371 sound_warn ("Attempt to play with no audio init\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
373 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 #endif
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
375 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
376 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
377 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 #ifndef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 sounds_in_play++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 AuSoundPlayFromFile (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 sound_file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 AuNone,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 AuFixedPointFromFraction (volume,100),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 doneCB, (AuPointer) &sounds_in_play,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 /* Cache the sounds in buckets on the server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 Sound s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 if ((s = SoundOpenFileForReading (sound_file))==NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
399 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 return 0;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 if (SoundComment (s) == NULL || SoundComment (s)[0] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 SoundComment (s) = FileCommentFromFilename (sound_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 do_caching_play (s, volume, NULL);
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 SoundCloseFile (s);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 #endif /* CACHE_SOUNDS */
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 #ifndef XTEVENTS
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
417 nas_wait_for_sounds ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 if (!NILP (Vsynchronous_sounds))
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
420 nas_wait_for_sounds ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 #endif
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 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
424 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
430 int nas_play_sound_data (UChar_Binary *data, int length, int volume);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 int
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
432 nas_play_sound_data (UChar_Binary *data, int length, int volume)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 Sound s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 int offset;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
436 SIGTYPE (*old_sigpipe) (int);
428
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 #if !defined (XTEVENTS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 AuEvent ev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
443 old_sigpipe = EMACS_SIGNAL (SIGPIPE, sigpipe_handle);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
444 if (setjmp (AuXtErrorJump) != 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
446 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 return 0;
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 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 if (aud == NULL) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 if (aud_server != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
455 Extbyte *m;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 /* attempt to reconect */
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
457 if ((m = nas_init_play (aud_server)) != NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
460 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
467 sound_warn ("Attempt to play with no audio init\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
469 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 }
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 if ((s=SoundOpenDataForReading (data, length))==NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
477 sound_warn ("unknown sound type");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
479 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 }
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 if (SoundFileFormat (s) == SoundFileFormatSnd)
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 /* hack, hack */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 offset = ((SndInfo *) (s->formatInfo))->h.dataOffset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 else if (SoundFileFormat (s) == SoundFileFormatWave)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 offset = ((WaveInfo *) (s->formatInfo))->dataOffset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
495 sound_warn ("only understand snd and wave files at the moment");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 SoundCloseFile (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
498 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 return 0;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 #ifndef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 sounds_in_play++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 AuSoundPlayFromData (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 data+offset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 AuNone,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 AuFixedPointFromFraction (volume,100),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 doneCB, (AuPointer) &sounds_in_play,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 /* Cache the sounds in buckets on the server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
518 do_caching_play (s, volume, data+offset);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 #endif /* CACHE_SOUNDS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 #ifndef XTEVENTS
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
523 nas_wait_for_sounds ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 if (!NILP (Vsynchronous_sounds))
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
526 nas_wait_for_sounds ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 #endif
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 SoundCloseFile (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
532 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 #endif
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 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 #if defined (ROBUST_PLAY)
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 /********************************************************************\
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 * Code to protect the client from server shutdowns. *
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 * This is unbelievably horrible. *
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 \********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 static AuBool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 CatchIoErrorAndJump (AuServer *old_aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 if (old_aud)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
552 sound_warn ("Audio Server connection broken");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
554 sound_warn ("Audio Server connection broken because of signal");
428
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 #ifdef XTEVENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 #ifdef XTOOLKIT
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
558 AuXtAppRemoveAudioHandler (aud, input_id);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 #endif
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 if (aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 AuCloseServer (aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 aud = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 sounds_in_play = 0;
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 longjmp (AuXtErrorJump, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 #else /* not XTEVENTS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 if (aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 AuCloseServer (aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 aud = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 sounds_in_play = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 longjmp (AuXtErrorJump, 1);
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 /* XTEVENTS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 sigpipe_handle (int signo)
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 CatchIoErrorAndJump (NULL);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 static AuBool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 CatchErrorAndJump (AuServer *old_aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 AuErrorEvent *event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 return CatchIoErrorAndJump (old_aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 }
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 /* ROBUST_PLAY */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
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 * This code is here because the nas Sound library doesn't *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 * support playing from a file buffered in memory. It's a fairly *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 * direct translation of the file-based equivalent. *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 * Since we don't have a filename, samples with no comment field *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 * are named by a section of their content. *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 \********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 /* Create a name from the sound. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
608 static Extbyte *
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
609 NameFromData (const Char_Binary *buf,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 int len)
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 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
613 Extbyte name[9];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 int i;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
615 Extbyte *s;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 buf+=len/2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 len -= len/2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 i=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 while (i<8 && len >0)
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 while (*buf < 32 && len>0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 buf++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 len--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 name[i]= *buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 buf++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 len--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 name[i]='\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 if (i==8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
638 strcpy (s = (Extbyte *) malloc (10), name);
428
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
642 strcpy (s = (Extbyte *) malloc (15), "short sound");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 return s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 /* 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
649 moment.
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 static SndInfo *
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
653 SndOpenDataForReading (const Char_Binary *data,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 int length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
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 SndInfo *si;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 if (!(si = (SndInfo *) malloc (sizeof (SndInfo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 si->comment = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 si->writing = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 memcpy (&si->h, data, sizeof (SndHeader));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
668 if (NAS_LITTLE_ENDIAN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
670 Char_Binary n;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 swapl (&si->h.magic, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 swapl (&si->h.dataOffset, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 swapl (&si->h.dataSize, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 swapl (&si->h.format, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 swapl (&si->h.sampleRate, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 swapl (&si->h.tracks, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 if (si->h.magic != SND_MAGIC_NUM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 free (si);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 size = si->h.dataOffset - sizeof (SndHeader);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 if (size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
690 if (!(si->comment = (Extbyte *) malloc (size + 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 free (si);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 memcpy (si->comment, data+sizeof (SndHeader), size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 *(si->comment + size) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 if (*si->comment == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 si->comment =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 si->comment = NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 si->h.dataSize = length-si->h.dataOffset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 si->fp=NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 return si;
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 /* 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
714 read wave data from memory, so these functions do that for us. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 #define Err() { return NULL; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 #define readFourcc(_f) dread(_f, sizeof(RIFF_FOURCC), 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 #define cmpID(_x, _y) \
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
719 strncmp((Char_Binary *) (_x), (Char_Binary *) (_y), sizeof(RIFF_FOURCC))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 #define PAD2(_x) (((_x) + 1) & ~1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 /* These functions here are for faking file I/O from buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 /* The "file" position */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
725 static size_t file_posn;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 /* The length of the "file" */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
727 static size_t file_len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 /* The actual "file" data. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
729 static const void* file_data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 /* Like fopen, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
733 dopen (const void* data, size_t length)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 file_data = data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 file_len = length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 file_posn = 0;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 /* Like fread, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 static int
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
742 dread (void* buf, size_t size, size_t nitems)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
744 size_t nread = size * nitems;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 if (file_posn + nread <= file_len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
748 memcpy(buf, (Char_Binary *) file_data + file_posn, size * nitems);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 file_posn += nread;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 return nitems;
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 return EOF;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 /* Like fgetc, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 static int
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
760 dgetc (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 if (file_posn < file_len)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
763 return ((Char_Binary *)file_data)[file_posn++];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 /* Like fseek, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 static int
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
770 dseek (long offset, int from)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 if (from == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 file_posn = offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 else if (from == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 file_posn += offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 else if (from == 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 file_posn = file_len + offset;
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 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 /* Like ftell, but for a buffer in memory */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
783 static long
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
784 dtell (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 return file_posn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 /* Data buffer analogs for FileReadS and FileReadL in NAS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 static unsigned short
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
792 DataReadS (int swapit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
794 unsigned short us;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
796 dread(&us, 2, 1);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
797 if (swapit)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
798 us = FileSwapS(us);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
799 return us;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 static AuUint32
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
803 DataReadL (int swapit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
805 AuUint32 ul;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
807 dread(&ul, 4, 1);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
808 if (swapit)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
809 ul = FileSwapL(ul);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
810 return ul;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 }
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 static int
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
814 readChunk (RiffChunk *c)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
816 int status;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
817 Char_Binary n;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
819 if ((status = dread(c, sizeof(RiffChunk), 1)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
820 if (NAS_BIG_ENDIAN)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
821 swapl(&c->ckSize, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
823 return status;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 /* A very straight-forward translation of WaveOpenFileForReading to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 read the wave data from a buffer in memory. */
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 static WaveInfo *
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
830 WaveOpenDataForReading (const Char_Binary *data,
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
831 int length)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
833 RiffChunk ck;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
834 RIFF_FOURCC fourcc;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
835 AuInt32 fileSize;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
836 WaveInfo *wi;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
839 if (!(wi = (WaveInfo *) malloc(sizeof(WaveInfo))))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
840 return NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
842 wi->comment = NULL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
843 wi->dataOffset = wi->format = wi->writing = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
845 dopen(data, length);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
847 if (!readChunk(&ck) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
848 cmpID(&ck.ckID, RIFF_RiffID) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
849 !readFourcc(&fourcc) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
850 cmpID(&fourcc, RIFF_WaveID))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
851 Err();
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
852
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
853 fileSize = PAD2(ck.ckSize) - sizeof(RIFF_FOURCC);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
854
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1097
diff changeset
855 while (fileSize >= (AuInt32) sizeof(RiffChunk))
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
856 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
857 if (!readChunk(&ck))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 Err();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
860 fileSize -= sizeof(RiffChunk) + PAD2(ck.ckSize);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
862 /* LIST chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
863 if (!cmpID(&ck.ckID, RIFF_ListID))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
864 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
865 if (!readFourcc(&fourcc))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 Err();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
868 /* INFO chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
869 if (!cmpID(&fourcc, RIFF_ListInfoID))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
870 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
871 ck.ckSize -= sizeof(RIFF_FOURCC);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
873 while (ck.ckSize)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
874 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
875 RiffChunk c;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
877 if (!readChunk(&c))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
878 Err();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
880 /* ICMT chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
881 if (!cmpID(&c.ckID, RIFF_InfoIcmtID))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
882 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
883 if (!(wi->comment = (Extbyte *) malloc(c.ckSize)) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
884 !dread(wi->comment, c.ckSize, 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 Err();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
887 if (c.ckSize & 1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
888 dgetc(); /* eat the pad byte */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
889 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
890 else
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
891 /* skip unknown chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
892 dseek(PAD2(c.ckSize), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
894 ck.ckSize -= sizeof(RiffChunk) + PAD2(c.ckSize);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
897 else
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
898 /* skip unknown chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
899 dseek(PAD2(ck.ckSize) - sizeof(RIFF_FOURCC), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
901 /* wave format chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
902 else if (!cmpID(&ck.ckID, RIFF_WaveFmtID) && !wi->format)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
904 AuInt32 dummy;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
906 wi->format = DataReadS(NAS_BIG_ENDIAN);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
907 wi->channels = DataReadS(NAS_BIG_ENDIAN);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
908 wi->sampleRate = DataReadL(NAS_BIG_ENDIAN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
910 /* we don't care about the next two fields */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
911 dummy = DataReadL(NAS_BIG_ENDIAN);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
912 dummy = DataReadS(NAS_BIG_ENDIAN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
914 if (wi->format != RIFF_WAVE_FORMAT_PCM)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
915 Err();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
917 wi->bitsPerSample = DataReadS(NAS_BIG_ENDIAN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
919 /* skip any other format specific fields */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
920 dseek(PAD2(ck.ckSize - 16), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
922 /* wave data chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
923 else if (!cmpID(&ck.ckID, RIFF_WaveDataID) && !wi->dataOffset)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
925 long endOfFile;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
927 wi->dataOffset = dtell();
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
928 wi->dataSize = ck.ckSize;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
929 dseek(0, 2);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
930 endOfFile = dtell();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
932 /* seek past the data */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
933 if (dseek(wi->dataOffset + PAD2(ck.ckSize), 0) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
934 dtell() > endOfFile)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
936 /* the seek failed, assume the size is bogus */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
937 dseek(0, 2);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
938 wi->dataSize = dtell() - wi->dataOffset;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
941 wi->dataOffset -= sizeof(long);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
943 else
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
944 /* skip unknown chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
945 dseek(PAD2(ck.ckSize), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
948 if (!wi->dataOffset)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
949 Err();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
951 wi->numSamples = wi->dataSize / wi->channels / (wi->bitsPerSample >> 3);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
953 if (!wi->comment)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
954 wi->comment = NameFromData (data + wi->dataOffset,
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
955 length - wi->dataOffset);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
957 wi->fp = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
959 return wi;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 static Sound
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
964 SoundOpenDataForReading (UChar_Binary *data,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 int length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
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 Sound s;
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
969 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
970 SoundFileInfoProc toProc;
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
971 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 if (!(s = (Sound) malloc (sizeof (SoundRec))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
976 if ((s->formatInfo = SndOpenDataForReading ((Char_Binary *) data, length)) != NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 {
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
978 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
979 if ((toProc = SoundFileGetProc(SoundFileFormatSnd,
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
980 SoundFileInfoProcTo)) == NULL)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
981 {
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
982 SndCloseFile ((SndInfo *) (s->formatInfo));
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
983 free (s);
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
984
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
985 return NULL;
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
986 }
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
987 if (!((*toProc)(s)))
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
988 #else
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
989 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatSnd].toSound)) (s))
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
990 #endif
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 SndCloseFile ((SndInfo *) (s->formatInfo));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 free (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 }
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
997 else if ((s->formatInfo = WaveOpenDataForReading ((Char_Binary *) data, length)) != NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 {
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
999 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1000 if ((toProc = SoundFileGetProc(SoundFileFormatWave,
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1001 SoundFileInfoProcTo)) == NULL)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1002 {
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1003 WaveCloseFile ((WaveInfo *) (s->formatInfo));
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1004 free (s);
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1005
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1006 return NULL;
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1007 }
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1008 if (!((*toProc)(s)))
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1009 #else
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
1010 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatWave].toSound)) (s))
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1011 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
1013 WaveCloseFile ((WaveInfo *) (s->formatInfo));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 free (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 return s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 }