annotate src/miscplay.c @ 733:b1f74adcc1ff

[xemacs-hg @ 2002-01-22 20:40:00 by janv] Fix disabled-command-hook
author janv
date Tue, 22 Jan 2002 20:40:03 +0000
parents 13e3d7ae7155
children 943eaba38521
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 /* miscplay.c - general routines related to playing sounds
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 ** Copyright (C) 1995,96 by Markus Gutschke (gutschk@math.uni-muenster.de)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ** This was sawed out from version 1.3 of linuxplay.c by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ** Robert Bihlmeyer <robbe@orcus.priv.at>.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ** Parts of this code were inspired by sunplay.c, which is copyright 1989 by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ** Jef Poskanzer and 1991,92 by Jamie Zawinski; c.f. sunplay.c for further
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ** information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ** Permission to use, copy, modify, and distribute this software and its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ** documentation for any purpose and without fee is hereby granted, provided
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ** 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
14 ** copyright notice and this permission notice appear in supporting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ** documentation. This software is provided "as is" without express or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ** implied warranty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
19 /* Synched up with: Not in FSF. */
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
20
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
21 /* This file Mule-ized by Ben Wing, 5-15-01. */
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
22
609
13e3d7ae7155 [xemacs-hg @ 2001-06-06 12:34:42 by ben]
ben
parents: 593
diff changeset
23 #define DONT_ENCAPSULATE
13e3d7ae7155 [xemacs-hg @ 2001-06-06 12:34:42 by ben]
ben
parents: 593
diff changeset
24
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #include <config.h>
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
26 #include "lisp.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "miscplay.h"
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
29 #include "sound.h"
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
30
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "sysfile.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #ifdef __GNUC__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #define UNUSED(x) ((void)(x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #define UNUSED(x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 /* Maintain global variable for keeping parser state information; this struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 is set to zero before the first invocation of the parser. The use of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 global variable prevents multiple concurrent executions of this code, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 this does not happen anyways... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 enum wvState
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 { wvMain,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 wvSubchunk,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 wvOutOfBlock,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 wvSkipChunk,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 wvSoundChunk,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 wvFatal,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 wvFatalNotify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 static union {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 struct {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 int align;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 enum wvState state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 size_t left;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
59 UChar_Binary leftover[HEADERSZ];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 signed long chunklength;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 } wave;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 struct {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 int align;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 int isdata;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 int skipping;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 size_t left;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
67 UChar_Binary leftover[HEADERSZ];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 } audio;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 } parsestate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 /* Use a global buffer as scratch-pad for possible conversions of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 sampling format */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
73 UChar_Binary miscplay_sndbuf[SNDBUFSZ];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 /* Initialize global parser state information to zero */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 void reset_parsestate()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 memset(&parsestate,0,sizeof(parsestate));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 /* Verify that we could fully parse the entire soundfile; this is needed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 only for files in WAVE format */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 int parse_wave_complete()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 if (parsestate.wave.state != wvOutOfBlock &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 parsestate.wave.state != wvFatal) {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
87 sound_warn("Unexpected end of WAVE file");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 } else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 /* There is no special treatment required for parsing raw data files; we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 assume that these files contain data in 8bit unsigned format that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 has been sampled at 8kHz; there is no extra header */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 static size_t parseraw(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 int rc = *sz;
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 *outbuf = *data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 return(rc);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 /* Currently we cannot cope with files in VOC format; if you really need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 to play these files, they should be converted by using SOX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 static size_t parsevoc(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 UNUSED(data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 UNUSED(sz);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 UNUSED(outbuf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 return(0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 /* We need to perform some look-ahead in order to parse files in WAVE format;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 this might require re-partioning of the data segments if headers cross the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 boundaries between two read operations. This is done in a two-step way:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 first we request a certain amount of bytes... */
570
db376c5066a7 [xemacs-hg @ 2001-05-25 02:45:57 by martinb]
martinb
parents: 564
diff changeset
119 static int waverequire(void **data,size_t *sz,size_t rq)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 int rc = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 if (rq > HEADERSZ) {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
124 sound_warn("Header size exceeded while parsing WAVE file");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 parsestate.wave.state = wvFatal;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 return(0); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 if ((rq -= parsestate.wave.left) <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 if (rq > *sz) {rq = *sz; rc = 0;}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 memcpy(parsestate.wave.leftover+parsestate.wave.left,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 *data,rq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 parsestate.wave.left += rq;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
134 (*(UChar_Binary **)data) += rq;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 *sz -= rq;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 return(rc);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 /* ...and next we remove this many bytes from the buffer */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
140 static inline void waveremove(size_t rq)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 if (parsestate.wave.left <= rq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 parsestate.wave.left = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 else {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 parsestate.wave.left -= rq;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 memmove(parsestate.wave.leftover,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 parsestate.wave.leftover+rq,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 parsestate.wave.left); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 /* Sound files in WAVE format can contain an arbitrary amount of tagged
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 chunks; this requires quite some effort for parsing the data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 static size_t parsewave(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 switch (parsestate.wave.state) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 case wvMain:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 if (!waverequire(data,sz,20))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 return(0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 /* Keep compatibility with Linux 68k, etc. by not relying on byte-sex */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 parsestate.wave.chunklength = parsestate.wave.leftover[16] +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 256*(parsestate.wave.leftover[17] +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 256*(parsestate.wave.leftover[18] +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 256*parsestate.wave.leftover[19]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 waveremove(20);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 parsestate.wave.state = wvSubchunk;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 case wvSubchunk:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 if (!waverequire(data,sz,parsestate.wave.chunklength))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 return(0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 parsestate.wave.align = parsestate.wave.chunklength < 14 ? 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 : parsestate.wave.leftover[12];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 if (parsestate.wave.align != 1 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 parsestate.wave.align != 2 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 parsestate.wave.align != 4) {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
177 sound_warn("Illegal datawidth detected while parsing WAVE file");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 parsestate.wave.state = wvFatal; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 parsestate.wave.state = wvOutOfBlock;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 waveremove(parsestate.wave.chunklength);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 case wvOutOfBlock:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 if (!waverequire(data,sz,8))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 return(0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 /* Keep compatibility with Linux 68k, etc. by not relying on byte-sex */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 parsestate.wave.chunklength = parsestate.wave.leftover[4] +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 256*(parsestate.wave.leftover[5] +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 256*(parsestate.wave.leftover[6] +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 256*(parsestate.wave.leftover[7] & 0x7F)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 if (memcmp(parsestate.wave.leftover,"data",4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 parsestate.wave.state = wvSkipChunk;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 parsestate.wave.state = wvSoundChunk;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 waveremove(8);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 case wvSkipChunk:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 if (parsestate.wave.chunklength > 0 && *sz > 0 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (signed long)*sz < (signed long)parsestate.wave.chunklength) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 parsestate.wave.chunklength -= *sz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 *sz = 0; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 else {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 if (parsestate.wave.chunklength > 0 && *sz > 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 *sz -= parsestate.wave.chunklength;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
205 (*(UChar_Binary **)data) += parsestate.wave.chunklength; }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 parsestate.wave.state = wvOutOfBlock; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 case wvSoundChunk: {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 size_t count,rq;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 if (parsestate.wave.left) { /* handle leftover bytes from last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 alignment operation */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 count = parsestate.wave.left;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 rq = HEADERSZ-count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 if (rq > (size_t) parsestate.wave.chunklength)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 rq = parsestate.wave.chunklength;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 if (!waverequire(data,sz,rq)) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 parsestate.wave.chunklength -= parsestate.wave.left - count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 return(0); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 parsestate.wave.chunklength -= rq;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 *outbuf = parsestate.wave.leftover;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 parsestate.wave.left = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 return(rq); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 if (*sz >= (size_t) parsestate.wave.chunklength) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 count = parsestate.wave.chunklength;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 rq = 0; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 else {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 count = *sz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 count -= rq = count % parsestate.wave.align; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 *outbuf = *data;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
230 (*(UChar_Binary **)data) += count;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 *sz -= count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 if ((parsestate.wave.chunklength -= count) < parsestate.wave.align) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 parsestate.wave.state = wvOutOfBlock;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 /* Some broken software (e.g. SOX) attaches junk to the end of a sound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 chunk; so, let's ignore this... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 if (parsestate.wave.chunklength)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 parsestate.wave.state = wvSkipChunk; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 else if (rq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 /* align data length to a multiple of datasize; keep additional data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 in "leftover" buffer --- this is necessary to ensure proper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 functioning of the sndcnv... routines */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 waverequire(data,sz,rq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 return(count); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 case wvFatalNotify:
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
245 sound_warn("Irrecoverable error while parsing WAVE file");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 parsestate.wave.state = wvFatal;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 case wvFatal:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 return(0); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 /* Strip the header from files in Sun/DEC audio format; this requires some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 extra processing as the header can be an arbitrary size and it might
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 result in alignment errors for subsequent conversions --- thus we do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 some buffering, where needed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 static size_t parsesundecaudio(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 /* There is data left over from the last invocation of this function; join
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 it with the new data and return a sound chunk that is as big as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 single entry */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 if (parsestate.audio.left) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 if (parsestate.audio.left + *sz > (size_t) parsestate.audio.align) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 int count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 memmove(parsestate.audio.leftover + parsestate.audio.left,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 *data,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 count = parsestate.audio.align - parsestate.audio.left);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 *outbuf = parsestate.audio.leftover;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 *sz -= count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
271 *data = (*(Char_Binary **)data) + count;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 parsestate.audio.left = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 return(parsestate.audio.align); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 else {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 /* We need even more data in order to get one complete single entry! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 memmove(parsestate.audio.leftover + parsestate.audio.left,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 *data,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 *sz);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
279 *data = (*(Char_Binary **)data) + *sz;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 parsestate.audio.left += *sz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 return(0); } }
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 /* This is the main sound chunk, strip of any extra data that does not fit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 the alignment requirements and move these bytes into the leftover buffer*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 if (parsestate.audio.isdata) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 int rc = *sz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 *outbuf = *data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 if ((parsestate.audio.left = rc % parsestate.audio.align) != 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 memmove(parsestate.audio.leftover,
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
291 (Char_Binary *)*outbuf + rc - parsestate.audio.left,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 parsestate.audio.left);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 rc -= parsestate.audio.left; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 return(rc); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 /* This is the first invocation of this function; we need to parse the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 header information and determine how many bytes we need to skip until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 the start of the sound chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 if (!parsestate.audio.skipping) {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
301 UChar_Binary *header = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 if (*sz < 8) {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
303 sound_warn("Irrecoverable error while parsing Sun/DEC audio file");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 return(0); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 /* Keep compatibility with Linux 68k, etc. by not relying on byte-sex */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 if (header[3]) { /* Sun audio (big endian) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 parsestate.audio.align = ((header[15] > 2)+1)*header[23];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 parsestate.audio.skipping = header[7]+256*(header[6]+256*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (header[5]+256*header[4])); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 else { /* DEC audio (little endian) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 parsestate.audio.align = ((header[12] > 2)+1)*header[20];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 parsestate.audio.skipping = header[4]+256*(header[5]+256*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (header[6]+256*header[7])); }}
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 /* We are skipping extra data that has been attached to header; most usually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 this will be just a comment, such as the original filename and/or the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 creation date. Make sure that we do not return less than one single sound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 sample entry to the caller; if this happens, rather decide to move those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 few bytes into the leftover buffer and deal with it later */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 if (*sz >= (size_t) parsestate.audio.skipping) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 /* Skip just the header information and return the sound chunk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 int rc = *sz - parsestate.audio.skipping;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
323 *outbuf = (Char_Binary *)*data + parsestate.audio.skipping;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 if ((parsestate.audio.left = rc % parsestate.audio.align) != 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 memmove(parsestate.audio.leftover,
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
326 (Char_Binary *)*outbuf + rc - parsestate.audio.left,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 parsestate.audio.left);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 rc -= parsestate.audio.left; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 parsestate.audio.skipping = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 parsestate.audio.isdata++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 return(rc); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 else {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 /* Skip everything */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 parsestate.audio.skipping -= *sz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 return(0); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 /* If the soundcard could not be set to natively support the data format, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 try to do some limited on-the-fly conversion to a different format; if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 no conversion is needed, though, we can output directly */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 size_t sndcnvnop(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 int rc = *sz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 *outbuf = *data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 /* Convert 8 bit unsigned stereo data to 8 bit unsigned mono data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 size_t sndcnv8U_2mono(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
354 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
355 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 int rc,count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 count = *sz / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 if (count > SNDBUFSZ) { *sz -= 2*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
362 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 while (count--)
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 444
diff changeset
366 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
367 *dest++ = (UChar_Binary)(((int)*(src) +
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 444
diff changeset
368 (int)*(src+1)) / 2);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 444
diff changeset
369 src += 2;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 444
diff changeset
370 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 /* Convert 8 bit signed stereo data to 8 bit signed mono data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 size_t sndcnv8S_2mono(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
378 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
379 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 int rc, count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 count = *sz / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 if (count > SNDBUFSZ) { *sz -= 2*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
386 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 while (count--)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
390 {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
391 *dest++ = (UChar_Binary)(((int)*((SChar_Binary *)(src)) +
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
392 (int)*((SChar_Binary *)(src+1))) / 2);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
393 src += 2;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
394 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 /* Convert 8 bit signed stereo data to 8 bit unsigned mono data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 size_t sndcnv2monounsigned(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
402 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
403 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 int rc,count;
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 count = *sz / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 if (count > SNDBUFSZ) { *sz -= 2*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
410 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 while (count--)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
414 {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
415 *dest++ = (UChar_Binary)(((int)*((SChar_Binary *)(src)) +
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
416 (int)*((SChar_Binary *)(src+1))) / 2) ^ 0x80;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
417 src += 2;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
418 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 }
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 /* Convert 8 bit signed mono data to 8 bit unsigned mono data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 size_t sndcnv2unsigned(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
426 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
427 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 int rc,count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 count = *sz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 if (count > SNDBUFSZ) { *sz -= SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
434 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 while (count--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 *dest++ = *(src)++ ^ 0x80;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 /* Convert a number in the range -32768..32767 to an 8 bit ulaw encoded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 number --- I hope, I got this conversion right :-) */
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
445 static inline SChar_Binary int2ulaw(int i)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 /* Lookup table for fast calculation of number of bits that need shifting*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 static short int t_bits[128] = {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 REGISTER int bits,logi;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 /* unrolling this condition (hopefully) improves execution speed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 if (i < 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 if ((i = (132-i)) > 0x7FFF) i = 0x7FFF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 logi = (i >> ((bits = t_bits[i/256])+4));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 return((bits << 4 | logi) ^ 0x7F); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 else {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 if ((i = 132+i) > 0x7FFF) i = 0x7FFF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 logi = (i >> ((bits = t_bits[i/256])+4));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 return(~(bits << 4 | logi)); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 /* Convert from 8 bit ulaw mono to 8 bit linear mono */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 size_t sndcnvULaw_2linear(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 /* conversion table stolen from Linux's ulaw.h */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
470 static UChar_Binary ulaw_dsp[] = {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 3, 7, 11, 15, 19, 23, 27, 31,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 35, 39, 43, 47, 51, 55, 59, 63,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 66, 68, 70, 72, 74, 76, 78, 80,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 82, 84, 86, 88, 90, 92, 94, 96,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 98, 99, 100, 101, 102, 103, 104, 105,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 106, 107, 108, 109, 110, 111, 112, 113,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 113, 114, 114, 115, 115, 116, 116, 117,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 117, 118, 118, 119, 119, 120, 120, 121,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 121, 121, 122, 122, 122, 122, 123, 123,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 123, 123, 124, 124, 124, 124, 125, 125,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 125, 125, 125, 125, 126, 126, 126, 126,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 126, 126, 126, 126, 127, 127, 127, 127,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 127, 127, 127, 127, 127, 127, 127, 127,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 128, 128, 128, 128, 128, 128, 128, 128,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 128, 128, 128, 128, 128, 128, 128, 128,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 128, 128, 128, 128, 128, 128, 128, 128,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 253, 249, 245, 241, 237, 233, 229, 225,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 221, 217, 213, 209, 205, 201, 197, 193,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 190, 188, 186, 184, 182, 180, 178, 176,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 174, 172, 170, 168, 166, 164, 162, 160,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 158, 157, 156, 155, 154, 153, 152, 151,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 150, 149, 148, 147, 146, 145, 144, 143,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 143, 142, 142, 141, 141, 140, 140, 139,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 139, 138, 138, 137, 137, 136, 136, 135,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 135, 135, 134, 134, 134, 134, 133, 133,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 133, 133, 132, 132, 132, 132, 131, 131,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 131, 131, 131, 131, 130, 130, 130, 130,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 130, 130, 130, 130, 129, 129, 129, 129,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 129, 129, 129, 129, 129, 129, 129, 129,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 128, 128, 128, 128, 128, 128, 128, 128,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 128, 128, 128, 128, 128, 128, 128, 128,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 128, 128, 128, 128, 128, 128, 128, 128,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 };
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
504 UChar_Binary *p=(UChar_Binary *)*data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 *outbuf = *data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 while ((*sz)--)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
508 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
509 *p = ulaw_dsp[*p];
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
510 p++;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
511 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 *data = p;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
514 return p - (UChar_Binary *)*outbuf;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 /* Convert 8 bit ulaw stereo data to 8 bit ulaw mono data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 size_t sndcnvULaw_2mono(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 static short int ulaw2int[256] = {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 /* Precomputed lookup table for conversion from ulaw to 15 bit signed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 -16062,-15550,-15038,-14526,-14014,-13502,-12990,-12478,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 -11966,-11454,-10942,-10430, -9918, -9406, -8894, -8382,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 -7998, -7742, -7486, -7230, -6974, -6718, -6462, -6206,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 -5950, -5694, -5438, -5182, -4926, -4670, -4414, -4158,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 -3966, -3838, -3710, -3582, -3454, -3326, -3198, -3070,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 -2942, -2814, -2686, -2558, -2430, -2302, -2174, -2046,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 -1950, -1886, -1822, -1758, -1694, -1630, -1566, -1502,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 -1438, -1374, -1310, -1246, -1182, -1118, -1054, -990,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 -942, -910, -878, -846, -814, -782, -750, -718,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 -686, -654, -622, -590, -558, -526, -494, -462,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 -438, -422, -406, -390, -374, -358, -342, -326,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 -310, -294, -278, -262, -246, -230, -214, -198,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 -186, -178, -170, -162, -154, -146, -138, -130,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 -122, -114, -106, -98, -90, -82, -74, -66,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 -60, -56, -52, -48, -44, -40, -36, -32,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 -28, -24, -20, -16, -12, -8, -4, +0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 +16062,+15550,+15038,+14526,+14014,+13502,+12990,+12478,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 +11966,+11454,+10942,+10430, +9918, +9406, +8894, +8382,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 +7998, +7742, +7486, +7230, +6974, +6718, +6462, +6206,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 +5950, +5694, +5438, +5182, +4926, +4670, +4414, +4158,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 +3966, +3838, +3710, +3582, +3454, +3326, +3198, +3070,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 +2942, +2814, +2686, +2558, +2430, +2302, +2174, +2046,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 +1950, +1886, +1822, +1758, +1694, +1630, +1566, +1502,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 +1438, +1374, +1310, +1246, +1182, +1118, +1054, +990,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 +942, +910, +878, +846, +814, +782, +750, +718,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 +686, +654, +622, +590, +558, +526, +494, +462,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 +438, +422, +406, +390, +374, +358, +342, +326,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 +310, +294, +278, +262, +246, +230, +214, +198,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 +186, +178, +170, +162, +154, +146, +138, +130,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 +122, +114, +106, +98, +90, +82, +74, +66,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 +60, +56, +52, +48, +44, +40, +36, +32,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 +28, +24, +20, +16, +12, +8, +4, +0};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
556 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
557 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 int rc,count;
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 count = *sz / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 if (count > SNDBUFSZ) { *sz -= 2*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
564 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 while (count--)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
568 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
569 /* it is not possible to directly interpolate between two ulaw encoded
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
570 data bytes, thus we need to convert to linear format first and later
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
571 we convert back to ulaw format */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
572 *dest++ = int2ulaw(ulaw2int[*src] +
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
573 ulaw2int[*(src+1)]);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
574 src += 2;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
575 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 size_t sndcnv16swap(void **data,size_t *sz,void **outbuf)
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 size_t cnt = *sz / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 unsigned short *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 *outbuf = *data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 p = (unsigned short *) *outbuf;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
587 while (cnt--)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
588 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
589 *p = ((*p & 0x00ff) << 8) | (*p >> 8);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
590 p++;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
591 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 *data = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 cnt = *sz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 return cnt;
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 /* Convert 16 bit little endian signed stereo data to 16 bit little endian
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 signed mono data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 size_t sndcnv16_2monoLE(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
602 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
603 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 int rc,count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 signed short i;
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 count = *sz / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 if (count > SNDBUFSZ) { *sz -= 2*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
611 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 for (count /= 2; count--; ) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 i = ((int)(src[0]) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 256*(int)(src[1]) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (int)(src[2]) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 256*(int)(src[3])) / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 src += 4;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
620 *dest++ = (UChar_Binary)(i & 0xFF);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
621 *dest++ = (UChar_Binary)((i / 256) & 0xFF); }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 /* Convert 16 bit big endian signed stereo data to 16 bit big endian
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 signed mono data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 size_t sndcnv16_2monoBE(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
630 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
631 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 int rc,count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 signed short i;
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 count = *sz / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 if (count > SNDBUFSZ) { *sz -= 2*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
639 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 for (count /= 2; count--; ) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 i = ((int)(src[1]) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 256*(int)(src[0]) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 (int)(src[3]) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 256*(int)(src[2])) / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 src += 4;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
648 *dest++ = (UChar_Binary)((i / 256) & 0xFF);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
649 *dest++ = (UChar_Binary)(i & 0xFF); }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 /* Convert 16 bit little endian signed data to 8 bit unsigned data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 size_t sndcnv2byteLE(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
657 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
658 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 int rc,count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 count = *sz / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 if (count > SNDBUFSZ) { *sz -= 2*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
665 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 while (count--) {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
669 *dest++ = (UChar_Binary)(((SChar_Binary *)src)[1] ^ (SChar_Binary)0x80);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 src += 2;
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 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 return(rc);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 /* Convert 16 bit big endian signed data to 8 bit unsigned data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 size_t sndcnv2byteBE(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
679 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
680 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 int rc,count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 count = *sz / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 if (count > SNDBUFSZ) { *sz -= 2*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
687 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 while (count--) {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
691 *dest++ = (UChar_Binary)(((SChar_Binary *)src)[0] ^ (SChar_Binary)0x80);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 src += 2;
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 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 return(rc);
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 /* Convert 16 bit little endian signed stereo data to 8 bit unsigned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 mono data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 size_t sndcnv2monobyteLE(void **data,size_t *sz,void **outbuf)
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: 452
diff changeset
702 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
703 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 int rc,count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 count = *sz / 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 if (count > SNDBUFSZ) { *sz -= 4*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
710 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 while (count--) {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
714 *dest++ = (UChar_Binary)(((int)((SChar_Binary *)src)[1] +
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
715 (int)((SChar_Binary *)src)[3]) / 2 ^ 0x80);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 src += 4;
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 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 }
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 /* Convert 16 bit big endian signed stereo data to 8 bit unsigned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 mono data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 size_t sndcnv2monobyteBE(void **data,size_t *sz,void **outbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
726 REGISTER UChar_Binary *src;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
727 REGISTER UChar_Binary *dest;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 int rc,count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 count = *sz / 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 if (count > SNDBUFSZ) { *sz -= 4*SNDBUFSZ; count = SNDBUFSZ; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 else *sz = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 rc = count;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
734 src = (UChar_Binary *) *data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 *outbuf =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 dest = miscplay_sndbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 while (count--) {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
738 *dest++ = (UChar_Binary)(((int)((SChar_Binary *)src)[0] +
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 570
diff changeset
739 (int)((SChar_Binary *)src)[2]) / 2 ^ 0x80);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 src += 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 *data = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 return(rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 /* Look at the header of the sound file and try to determine the format;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 we can recognize files in VOC, WAVE, and, Sun/DEC-audio format--- everything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 else is assumed to be raw 8 bit unsigned data sampled at 8kHz */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 452
diff changeset
749 fmtType analyze_format(UChar_Binary *format,int *fmt,int *speed,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 int *tracks,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 size_t (**parsesndfile)(void **,size_t *sz,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 void **))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 /* Keep compatibility with Linux 68k, etc. by not relying on byte-sex */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 if (!memcmp(format,"Creative Voice File\x1A\x1A\x00",22) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 (format[22]+256*format[23]) ==
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 ((0x1233-format[24]-256*format[25])&0xFFFF)) { /* VOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 *fmt = AFMT_U8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 *speed = 8000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 *tracks = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 *parsesndfile = parsevoc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 return(fmtVoc); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 else if (!memcmp(format,"RIFF",4) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 !memcmp(format+8,"WAVEfmt ",8)) { /* WAVE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 if (memcmp(format+20,"\001\000\001"/* PCM mono */,4) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 memcmp(format+20,"\001\000\002"/* PCM stereo */,4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 return(fmtIllegal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 *fmt = (format[32]/(*tracks = format[22])) == 1 ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 AFMT_U8 : AFMT_S16_LE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 /* Keep compatibility with Linux 68k, etc. by not relying on byte-sex */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 *speed = format[24]+256*(format[25]+256*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 (format[26]+256*format[27]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 *parsesndfile = parsewave;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 return(fmtWave); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 else if (!memcmp(format,".snd",4)) { /* Sun Audio (big endian) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 if (format[7]+256*(format[6]+256*(format[5]+256*format[4])) < 24) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 *fmt = AFMT_MU_LAW;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 *speed = 8000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 *tracks = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 *parsesndfile = parsesundecaudio;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 return(fmtSunAudio); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 if (!memcmp(format+12,"\000\000\000\001",4)) *fmt = AFMT_MU_LAW;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 else if (!memcmp(format+12,"\000\000\000\002",4)) *fmt = AFMT_S8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 else if (!memcmp(format+12,"\000\000\000\003",4)) *fmt = AFMT_S16_BE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 else return(fmtIllegal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 /* Keep compatibility with Linux 68k, etc. by not relying on byte-sex */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 *speed = format[19]+256*(format[18]+256*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 (format[17]+256*format[16]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 *tracks = format[23];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 *parsesndfile = parsesundecaudio;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 return(fmtSunAudio); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 else if (!memcmp(format,".sd",4)) { /* DEC Audio (little endian) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 if (format[4]+256*(format[5]+256*(format[6]+256*format[7])) < 24) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 *fmt = AFMT_MU_LAW;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 *speed = 8000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 *tracks = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 *parsesndfile = parsesundecaudio;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 return(fmtSunAudio); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 if (!memcmp(format+12,"\001\000\000",4)) *fmt = AFMT_MU_LAW;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 else if (!memcmp(format+12,"\002\000\000",4)) *fmt = AFMT_S8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 else if (!memcmp(format+12,"\003\000\000",4)) *fmt = AFMT_S16_LE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 else return(fmtIllegal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 /* Keep compatibility with Linux 68k, etc. by not relying on byte-sex */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 *speed = format[16]+256*(format[17]+256*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 (format[18]+256*format[19]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 *tracks = format[20];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 *parsesndfile = parsesundecaudio;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 return(fmtSunAudio); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 else {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 *fmt = AFMT_U8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 *speed = 8000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 *tracks = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 *parsesndfile = parseraw;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 return(fmtRaw); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 }