annotate src/nas.c @ 2092:f557693c61de

[xemacs-hg @ 2004-05-21 20:56:26 by james] Batch of fixes and new functions for bignums, ratios, and bigfloats.
author james
date Fri, 21 May 2004 20:56:32 +0000
parents 18d2b8dabcf7
children 8de911beca70
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
1746
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
116 /* audiolib <= some version doesn't define major and minor versions */
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
117 /* Do NOT use AudioLibraryVersion in this file. */
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
118 #ifndef AudioLibraryVersion
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
119 #define AudioLibraryVersion 1
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
120 #endif
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
121 #ifndef AudioLibraryVersionMajor
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
122 #define AudioLibraryVersionMajor AudioLibraryVersion
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
123 #endif
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
124 #ifndef AudioLibraryVersionMinor
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
125 #define AudioLibraryVersionMinor 0
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
126 #endif
18d2b8dabcf7 [xemacs-hg @ 2003-10-14 16:34:54 by stephent]
stephent
parents: 1346
diff changeset
127
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 #if defined (ROBUST_PLAY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 static AuBool CatchIoErrorAndJump (AuServer *aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 static AuBool CatchErrorAndJump (AuServer *aud, AuErrorEvent *event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 SIGTYPE sigpipe_handle (int signo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 extern Lisp_Object Vsynchronous_sounds;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
136 static Sound SoundOpenDataForReading (UChar_Binary *data, int length);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 static AuServer *aud;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 /* count of sounds currently being played. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 static int sounds_in_play;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 #ifdef XTOOLKIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 static Display *aud_server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 static XtInputId input_id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
148 static Extbyte *aud_server;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 #endif /* XTOOLKIT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
151 Extbyte *
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
152 nas_init_play (
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 #ifdef XTOOLKIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 Display *display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
156 Extbyte *server
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 #endif
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
158 );
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
159 Extbyte *
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
160 nas_init_play (
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
161 #ifdef XTOOLKIT
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
162 Display *display
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
163 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
164 Extbyte *server
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
165 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
168 Extbyte *err_message;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
169 SIGTYPE (*old_sigpipe) (int);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 #ifdef XTOOLKIT
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
172 Extbyte * server = DisplayString (display);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 XtAppContext app_context = XtDisplayToApplicationContext (display);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 aud_server = display;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 aud_server = server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
182 old_sigpipe = EMACS_SIGNAL (SIGPIPE, sigpipe_handle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 if (setjmp (AuXtErrorJump))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
185 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
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 return "error in NAS";
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 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 #if defined (ROBUST_PLAY) && !defined (NAS_NO_ERROR_JUMP)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 AuDefaultIOErrorHandler = CatchIoErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 AuDefaultErrorHandler = CatchErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 stop_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 aud = AuOpenServer (server, 0, NULL, 0, NULL, &err_message);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 start_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 if (!aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
202 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 if (err_message == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 return "Can't connect to audio server";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 return err_message;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 #if defined (ROBUST_PLAY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 # if defined (NAS_NO_ERROR_JUMP)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 aud->funcs.ioerror_handler = CatchIoErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 aud->funcs.error_handler = CatchErrorAndJump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 # else /* !NAS_NO_ERROR_JUMP */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 AuDefaultIOErrorHandler = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 AuDefaultErrorHandler = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 # endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 #ifdef XTEVENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 input_id = AuXtAppAddAudioHandler (app_context, aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 #ifdef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 AuSetCloseDownMode (aud, AuCloseDownRetainPermanent, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
229 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 #endif
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 sounds_in_play = 0;
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 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
237 static void
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
238 nas_close_down_play (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 AuCloseServer (aud);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
242 sound_warn ("disconnected from audio server");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 /********************************************************************\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 * Callback which is run when the sound finishes playing. *
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 static void
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
252 doneCB (AuServer *auserver,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 AuEventHandlerRec *handler,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 AuEvent *ev,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 AuPointer data)
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 int *in_play_p = (int *) data;
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 (*in_play_p) --;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 #ifdef CACHE_SOUNDS
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 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 * Play a sound by playing the relevant bucket, if any or *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 * downloading it if not. *
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 \********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 do_caching_play (Sound s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 int volume,
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
274 UChar_Binary *buf)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 AuBucketAttributes *list, b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 AuBucketID id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 int n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 AuSetString (AuBucketDescription (&b),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 AuStringLatin1, strlen (SoundComment (s)), SoundComment (s));
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 list = AuListBuckets (aud, AuCompCommonDescriptionMask, &b, &n, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 if (list == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
288 AuPointer my_buf;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 if (buf==NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
292 if ((my_buf= (AuPointer) malloc (SoundNumBytes (s)))==NULL)
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 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
297 if (SoundReadFile ((Extbyte *) my_buf, SoundNumBytes (s), s) != SoundNumBytes (s))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 free (my_buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 else
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
304 my_buf = (AuPointer) buf;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 id = AuSoundCreateBucketFromData (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 my_buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 AuAccessAllMasks,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 if (buf == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 free (my_buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 else /* found cached sound */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 id = AuBucketIdentifier (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 AuFreeBucketAttributes (aud, n, list);
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 sounds_in_play++;
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 AuSoundPlayFromBucket (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 id,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 AuNone,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 AuFixedPointFromFraction (volume, 100),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 doneCB, (AuPointer) &sounds_in_play,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 NULL, NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 NULL, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 #endif /* CACHE_SOUNDS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
336 void nas_wait_for_sounds (void);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 void
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
338 nas_wait_for_sounds (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 AuEvent ev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 while (sounds_in_play>0)
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 AuNextEvent (aud, AuTrue, &ev);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 AuDispatchEvent (aud, &ev);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
350 int nas_play_sound_file (Extbyte *sound_file, int volume);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 int
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
352 nas_play_sound_file (Extbyte *sound_file,
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
353 int volume)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
355 SIGTYPE (*old_sigpipe) (int);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
358 old_sigpipe = EMACS_SIGNAL (SIGPIPE, sigpipe_handle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 if (setjmp (AuXtErrorJump))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
361 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
366 if (aud==NULL)
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 if (aud_server != NULL)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
369 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
370 Extbyte *m;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
371 /* attempt to reconect */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
372 if ((m = nas_init_play (aud_server)) != NULL)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
373 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
374
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
376 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 #endif
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
378 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
379 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
380 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
381 else
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
382 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
383 sound_warn ("Attempt to play with no audio init\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
385 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 #endif
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
387 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
388 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
389 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 #ifndef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 sounds_in_play++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 AuSoundPlayFromFile (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 sound_file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 AuNone,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 AuFixedPointFromFraction (volume,100),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 doneCB, (AuPointer) &sounds_in_play,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 /* Cache the sounds in buckets on the server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 Sound s;
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 if ((s = SoundOpenFileForReading (sound_file))==NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
411 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 if (SoundComment (s) == NULL || SoundComment (s)[0] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 SoundComment (s) = FileCommentFromFilename (sound_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 do_caching_play (s, volume, NULL);
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 SoundCloseFile (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 #endif /* CACHE_SOUNDS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 #ifndef XTEVENTS
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
429 nas_wait_for_sounds ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 if (!NILP (Vsynchronous_sounds))
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
432 nas_wait_for_sounds ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
436 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
442 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
443 int
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
444 nas_play_sound_data (UChar_Binary *data, int length, int volume)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 Sound s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 int offset;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
448 SIGTYPE (*old_sigpipe) (int);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 #if !defined (XTEVENTS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 AuEvent ev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
455 old_sigpipe = EMACS_SIGNAL (SIGPIPE, sigpipe_handle);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
456 if (setjmp (AuXtErrorJump) != 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
458 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 if (aud == NULL) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 if (aud_server != NULL)
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 Extbyte *m;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 /* attempt to reconect */
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
469 if ((m = nas_init_play (aud_server)) != NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
472 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
479 sound_warn ("Attempt to play with no audio init\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
481 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 if ((s=SoundOpenDataForReading (data, length))==NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
489 sound_warn ("unknown sound type");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
491 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 if (SoundFileFormat (s) == SoundFileFormatSnd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 /* hack, hack */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 offset = ((SndInfo *) (s->formatInfo))->h.dataOffset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 else if (SoundFileFormat (s) == SoundFileFormatWave)
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 offset = ((WaveInfo *) (s->formatInfo))->dataOffset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
507 sound_warn ("only understand snd and wave files at the moment");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 SoundCloseFile (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
510 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 #ifndef CACHE_SOUNDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 sounds_in_play++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 AuSoundPlayFromData (aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 data+offset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 AuNone,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 AuFixedPointFromFraction (volume,100),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 doneCB, (AuPointer) &sounds_in_play,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 /* Cache the sounds in buckets on the server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
530 do_caching_play (s, volume, data+offset);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 #endif /* CACHE_SOUNDS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 #ifndef XTEVENTS
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
535 nas_wait_for_sounds ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 if (!NILP (Vsynchronous_sounds))
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
538 nas_wait_for_sounds ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 #endif
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 SoundCloseFile (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 #ifdef ROBUST_PLAY
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
544 EMACS_SIGNAL (SIGPIPE, old_sigpipe);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 #endif
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 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 #if defined (ROBUST_PLAY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 /********************************************************************\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 * Code to protect the client from server shutdowns. *
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 * This is unbelievably horrible. *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 \********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 static AuBool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 CatchIoErrorAndJump (AuServer *old_aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 if (old_aud)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
564 sound_warn ("Audio Server connection broken");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
566 sound_warn ("Audio Server connection broken because of signal");
428
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 #ifdef XTEVENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 #ifdef XTOOLKIT
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
570 AuXtAppRemoveAudioHandler (aud, input_id);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 if (aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 AuCloseServer (aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 aud = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 sounds_in_play = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 longjmp (AuXtErrorJump, 1);
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 #else /* not XTEVENTS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 if (aud)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 AuCloseServer (aud);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 aud = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 sounds_in_play = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 longjmp (AuXtErrorJump, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 #endif /* XTEVENTS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 sigpipe_handle (int signo)
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 CatchIoErrorAndJump (NULL);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 static AuBool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 CatchErrorAndJump (AuServer *old_aud,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 AuErrorEvent *event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 return CatchIoErrorAndJump (old_aud);
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 #endif /* ROBUST_PLAY */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 /********************************************************************\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 * This code is here because the nas Sound library doesn't *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 * support playing from a file buffered in memory. It's a fairly *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 * direct translation of the file-based equivalent. *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 * Since we don't have a filename, samples with no comment field *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 * are named by a section of their content. *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 * *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 \********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 /* Create a name from the sound. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
620 static Extbyte *
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
621 NameFromData (const Char_Binary *buf,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 int len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
625 Extbyte name[9];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 int i;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
627 Extbyte *s;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 buf+=len/2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 len -= len/2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 i=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 while (i<8 && len >0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 while (*buf < 32 && len>0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 buf++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 len--;
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 name[i]= *buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 buf++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 len--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 name[i]='\0';
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 if (i==8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
650 strcpy (s = (Extbyte *) malloc (10), name);
428
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
654 strcpy (s = (Extbyte *) malloc (15), "short sound");
428
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 return s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 }
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 /* 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
661 moment.
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 static SndInfo *
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
665 SndOpenDataForReading (const Char_Binary *data,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 int length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 SndInfo *si;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 int size;
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 if (!(si = (SndInfo *) malloc (sizeof (SndInfo))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 si->comment = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 si->writing = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 memcpy (&si->h, data, sizeof (SndHeader));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
680 if (NAS_LITTLE_ENDIAN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
682 Char_Binary n;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 swapl (&si->h.magic, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 swapl (&si->h.dataOffset, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 swapl (&si->h.dataSize, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 swapl (&si->h.format, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 swapl (&si->h.sampleRate, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 swapl (&si->h.tracks, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 if (si->h.magic != SND_MAGIC_NUM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 free (si);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 size = si->h.dataOffset - sizeof (SndHeader);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 if (size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
702 if (!(si->comment = (Extbyte *) malloc (size + 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 free (si);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 }
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 memcpy (si->comment, data+sizeof (SndHeader), size);
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 *(si->comment + size) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 if (*si->comment == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 si->comment =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 si->comment = NameFromData (data+si->h.dataOffset, length-si->h.dataOffset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 si->h.dataSize = length-si->h.dataOffset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 si->fp=NULL;
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 return si;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 /* 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
726 read wave data from memory, so these functions do that for us. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 #define Err() { return NULL; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 #define readFourcc(_f) dread(_f, sizeof(RIFF_FOURCC), 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 #define cmpID(_x, _y) \
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
731 strncmp((Char_Binary *) (_x), (Char_Binary *) (_y), sizeof(RIFF_FOURCC))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 #define PAD2(_x) (((_x) + 1) & ~1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 /* These functions here are for faking file I/O from buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 /* The "file" position */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
737 static size_t file_posn;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 /* The length of the "file" */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
739 static size_t file_len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 /* The actual "file" data. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
741 static const void* file_data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 /* Like fopen, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
745 dopen (const void* data, size_t length)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 file_data = data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 file_len = length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 file_posn = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 }
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 /* Like fread, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 static int
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
754 dread (void* buf, size_t size, size_t nitems)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
756 size_t nread = size * nitems;
428
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 if (file_posn + nread <= file_len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
760 memcpy(buf, (Char_Binary *) file_data + file_posn, size * nitems);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 file_posn += nread;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 return nitems;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 }
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 return EOF;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 /* Like fgetc, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 static int
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
772 dgetc (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 if (file_posn < file_len)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
775 return ((Char_Binary *)file_data)[file_posn++];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 return -1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 /* Like fseek, but for a buffer in memory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 static int
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
782 dseek (long offset, int from)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 if (from == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 file_posn = offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 else if (from == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 file_posn += offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 else if (from == 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 file_posn = file_len + offset;
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 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 /* Like ftell, but for a buffer in memory */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
795 static long
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
796 dtell (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 return file_posn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 /* Data buffer analogs for FileReadS and FileReadL in NAS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 static unsigned short
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
804 DataReadS (int swapit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
806 unsigned short us;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
808 dread(&us, 2, 1);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
809 if (swapit)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
810 us = FileSwapS(us);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
811 return us;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 static AuUint32
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
815 DataReadL (int swapit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
817 AuUint32 ul;
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 dread(&ul, 4, 1);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
820 if (swapit)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
821 ul = FileSwapL(ul);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
822 return ul;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 static int
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
826 readChunk (RiffChunk *c)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
828 int status;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
829 Char_Binary n;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
831 if ((status = dread(c, sizeof(RiffChunk), 1)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
832 if (NAS_BIG_ENDIAN)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
833 swapl(&c->ckSize, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
835 return status;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 /* A very straight-forward translation of WaveOpenFileForReading to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 read the wave data from a buffer in memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 static WaveInfo *
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
842 WaveOpenDataForReading (const Char_Binary *data,
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
843 int length)
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 RiffChunk ck;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
846 RIFF_FOURCC fourcc;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
847 AuInt32 fileSize;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
848 WaveInfo *wi;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
851 if (!(wi = (WaveInfo *) malloc(sizeof(WaveInfo))))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
852 return NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
854 wi->comment = NULL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
855 wi->dataOffset = wi->format = wi->writing = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
857 dopen(data, length);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
859 if (!readChunk(&ck) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
860 cmpID(&ck.ckID, RIFF_RiffID) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
861 !readFourcc(&fourcc) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
862 cmpID(&fourcc, RIFF_WaveID))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
863 Err();
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 fileSize = PAD2(ck.ckSize) - sizeof(RIFF_FOURCC);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
866
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1097
diff changeset
867 while (fileSize >= (AuInt32) sizeof(RiffChunk))
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
868 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
869 if (!readChunk(&ck))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 Err();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
872 fileSize -= sizeof(RiffChunk) + PAD2(ck.ckSize);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
874 /* LIST chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
875 if (!cmpID(&ck.ckID, RIFF_ListID))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
876 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
877 if (!readFourcc(&fourcc))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 Err();
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 /* INFO chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
881 if (!cmpID(&fourcc, RIFF_ListInfoID))
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 ck.ckSize -= sizeof(RIFF_FOURCC);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
885 while (ck.ckSize)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
886 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
887 RiffChunk c;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
889 if (!readChunk(&c))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
890 Err();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
892 /* ICMT chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
893 if (!cmpID(&c.ckID, RIFF_InfoIcmtID))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
894 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
895 if (!(wi->comment = (Extbyte *) malloc(c.ckSize)) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
896 !dread(wi->comment, c.ckSize, 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 Err();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
899 if (c.ckSize & 1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
900 dgetc(); /* eat the pad byte */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
901 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
902 else
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
903 /* skip unknown chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
904 dseek(PAD2(c.ckSize), 1);
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 ck.ckSize -= sizeof(RiffChunk) + PAD2(c.ckSize);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
909 else
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
910 /* skip unknown chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
911 dseek(PAD2(ck.ckSize) - sizeof(RIFF_FOURCC), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
913 /* wave format chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
914 else if (!cmpID(&ck.ckID, RIFF_WaveFmtID) && !wi->format)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
916 AuInt32 dummy;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
918 wi->format = DataReadS(NAS_BIG_ENDIAN);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
919 wi->channels = DataReadS(NAS_BIG_ENDIAN);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
920 wi->sampleRate = DataReadL(NAS_BIG_ENDIAN);
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 /* 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
923 dummy = DataReadL(NAS_BIG_ENDIAN);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
924 dummy = DataReadS(NAS_BIG_ENDIAN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
926 if (wi->format != RIFF_WAVE_FORMAT_PCM)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
927 Err();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
929 wi->bitsPerSample = DataReadS(NAS_BIG_ENDIAN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
931 /* skip any other format specific fields */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
932 dseek(PAD2(ck.ckSize - 16), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
934 /* wave data chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
935 else if (!cmpID(&ck.ckID, RIFF_WaveDataID) && !wi->dataOffset)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
937 long endOfFile;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
939 wi->dataOffset = dtell();
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
940 wi->dataSize = ck.ckSize;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
941 dseek(0, 2);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
942 endOfFile = dtell();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
944 /* seek past the data */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
945 if (dseek(wi->dataOffset + PAD2(ck.ckSize), 0) ||
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
946 dtell() > endOfFile)
428
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 /* the seek failed, assume the size is bogus */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
949 dseek(0, 2);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
950 wi->dataSize = dtell() - wi->dataOffset;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 }
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 wi->dataOffset -= sizeof(long);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
955 else
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
956 /* skip unknown chunk */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
957 dseek(PAD2(ck.ckSize), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
960 if (!wi->dataOffset)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
961 Err();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
963 wi->numSamples = wi->dataSize / wi->channels / (wi->bitsPerSample >> 3);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
965 if (!wi->comment)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
966 wi->comment = NameFromData (data + wi->dataOffset,
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
967 length - wi->dataOffset);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
969 wi->fp = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
971 return wi;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 static Sound
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
976 SoundOpenDataForReading (UChar_Binary *data,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 int length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 Sound s;
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
981 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
982 SoundFileInfoProc toProc;
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
983 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 if (!(s = (Sound) malloc (sizeof (SoundRec))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
988 if ((s->formatInfo = SndOpenDataForReading ((Char_Binary *) data, length)) != NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 {
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
990 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
991 if ((toProc = SoundFileGetProc(SoundFileFormatSnd,
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
992 SoundFileInfoProcTo)) == NULL)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
993 {
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
994 SndCloseFile ((SndInfo *) (s->formatInfo));
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
995 free (s);
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
996
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
997 return NULL;
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
998 }
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
999 if (!((*toProc)(s)))
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1000 #else
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
1001 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatSnd].toSound)) (s))
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1002 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
1004 SndCloseFile ((SndInfo *) (s->formatInfo));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 free (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 }
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
1009 else if ((s->formatInfo = WaveOpenDataForReading ((Char_Binary *) data, length)) != NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 {
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1011 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1012 if ((toProc = SoundFileGetProc(SoundFileFormatWave,
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1013 SoundFileInfoProcTo)) == NULL)
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1014 {
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1015 WaveCloseFile ((WaveInfo *) (s->formatInfo));
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1016 free (s);
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1017
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1018 return NULL;
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1019 }
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1020 if (!((*toProc)(s)))
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1021 #else
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
1022 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatWave].toSound)) (s))
1097
26274e0d7794 [xemacs-hg @ 2002-11-11 16:03:12 by stephent]
stephent
parents: 826
diff changeset
1023 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 {
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
1025 WaveCloseFile ((WaveInfo *) (s->formatInfo));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 free (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 return s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 }