comparison decoders/au.c @ 535:45ee760a6f5a stable-1.0

Converted all text encoding from ISO-8859-1 to UTF-8.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 17 Apr 2008 18:06:53 +0000
parents fb519e6028e3
children
comparison
equal deleted inserted replaced
533:cad2940e992f 535:45ee760a6f5a
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20 /* 20 /*
21 * Sun/NeXT .au decoder for SDL_sound. 21 * Sun/NeXT .au decoder for SDL_sound.
22 * Formats supported: 8 and 16 bit linear PCM, 8 bit µ-law. 22 * Formats supported: 8 and 16 bit linear PCM, 8 bit µ-law.
23 * Files without valid header are assumed to be 8 bit µ-law, 8kHz, mono. 23 * Files without valid header are assumed to be 8 bit µ-law, 8kHz, mono.
24 * 24 *
25 * Please see the file COPYING in the source's root directory. 25 * Please see the file COPYING in the source's root directory.
26 * 26 *
27 * This file written by Mattias Engdegård. (f91-men@nada.kth.se) 27 * This file written by Mattias EngdegÃ¥rd. (f91-men@nada.kth.se)
28 */ 28 */
29 29
30 #if HAVE_CONFIG_H 30 #if HAVE_CONFIG_H
31 # include <config.h> 31 # include <config.h>
32 #endif 32 #endif
59 const Sound_DecoderFunctions __Sound_DecoderFunctions_AU = 59 const Sound_DecoderFunctions __Sound_DecoderFunctions_AU =
60 { 60 {
61 { 61 {
62 extensions_au, 62 extensions_au,
63 "Sun/NeXT audio file format", 63 "Sun/NeXT audio file format",
64 "Mattias Engdegård <f91-men@nada.kth.se>", 64 "Mattias EngdegÃ¥rd <f91-men@nada.kth.se>",
65 "http://www.icculus.org/SDL_sound/" 65 "http://www.icculus.org/SDL_sound/"
66 }, 66 },
67 67
68 AU_init, /* init() method */ 68 AU_init, /* init() method */
69 AU_quit, /* quit() method */ 69 AU_quit, /* quit() method */
97 97
98 #define HDR_SIZE 24 98 #define HDR_SIZE 24
99 99
100 enum 100 enum
101 { 101 {
102 AU_ENC_ULAW_8 = 1, /* 8-bit ISDN µ-law */ 102 AU_ENC_ULAW_8 = 1, /* 8-bit ISDN µ-law */
103 AU_ENC_LINEAR_8 = 2, /* 8-bit linear PCM */ 103 AU_ENC_LINEAR_8 = 2, /* 8-bit linear PCM */
104 AU_ENC_LINEAR_16 = 3, /* 16-bit linear PCM */ 104 AU_ENC_LINEAR_16 = 3, /* 16-bit linear PCM */
105 105
106 /* the rest are unsupported (I have never seen them in the wild) */ 106 /* the rest are unsupported (I have never seen them in the wild) */
107 AU_ENC_LINEAR_24 = 4, /* 24-bit linear PCM */ 107 AU_ENC_LINEAR_24 = 4, /* 24-bit linear PCM */
183 /* valid magic */ 183 /* valid magic */
184 dec->encoding = hdr.encoding; 184 dec->encoding = hdr.encoding;
185 switch(dec->encoding) 185 switch(dec->encoding)
186 { 186 {
187 case AU_ENC_ULAW_8: 187 case AU_ENC_ULAW_8:
188 /* Convert 8-bit µ-law to 16-bit linear on the fly. This is 188 /* Convert 8-bit µ-law to 16-bit linear on the fly. This is
189 slightly wasteful if the audio driver must convert them 189 slightly wasteful if the audio driver must convert them
190 back, but µ-law only devices are rare (mostly _old_ Suns) */ 190 back, but µ-law only devices are rare (mostly _old_ Suns) */
191 sample->actual.format = AUDIO_S16SYS; 191 sample->actual.format = AUDIO_S16SYS;
192 break; 192 break;
193 193
194 case AU_ENC_LINEAR_8: 194 case AU_ENC_LINEAR_8:
195 sample->actual.format = AUDIO_S8; 195 sample->actual.format = AUDIO_S8;
222 222
223 else if (__Sound_strcasecmp(ext, "au") == 0) 223 else if (__Sound_strcasecmp(ext, "au") == 0)
224 { 224 {
225 /* 225 /*
226 * A number of files in the wild have the .au extension but no valid 226 * A number of files in the wild have the .au extension but no valid
227 * header; these are traditionally assumed to be 8kHz µ-law. Handle 227 * header; these are traditionally assumed to be 8kHz µ-law. Handle
228 * them here only if the extension is recognized. 228 * them here only if the extension is recognized.
229 */ 229 */
230 230
231 SNDDBG(("AU: Invalid header, assuming raw 8kHz µ-law.\n")); 231 SNDDBG(("AU: Invalid header, assuming raw 8kHz µ-law.\n"));
232 /* if seeking fails, we lose 24 samples. big deal */ 232 /* if seeking fails, we lose 24 samples. big deal */
233 SDL_RWseek(rw, -HDR_SIZE, SEEK_CUR); 233 SDL_RWseek(rw, -HDR_SIZE, SEEK_CUR);
234 dec->encoding = AU_ENC_ULAW_8; 234 dec->encoding = AU_ENC_ULAW_8;
235 dec->remaining = (Uint32)-1; /* no limit */ 235 dec->remaining = (Uint32)-1; /* no limit */
236 sample->actual.format = AUDIO_S16SYS; 236 sample->actual.format = AUDIO_S16SYS;
258 Sound_SampleInternal *internal = sample->opaque; 258 Sound_SampleInternal *internal = sample->opaque;
259 free(internal->decoder_private); 259 free(internal->decoder_private);
260 } /* AU_close */ 260 } /* AU_close */
261 261
262 262
263 /* table to convert from µ-law encoding to signed 16-bit samples, 263 /* table to convert from µ-law encoding to signed 16-bit samples,
264 generated by a throwaway perl script */ 264 generated by a throwaway perl script */
265 static Sint16 ulaw_to_linear[256] = { 265 static Sint16 ulaw_to_linear[256] = {
266 -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956, 266 -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
267 -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764, 267 -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
268 -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412, 268 -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
308 308
309 maxlen = internal->buffer_size; 309 maxlen = internal->buffer_size;
310 buf = internal->buffer; 310 buf = internal->buffer;
311 if (dec->encoding == AU_ENC_ULAW_8) 311 if (dec->encoding == AU_ENC_ULAW_8)
312 { 312 {
313 /* We read µ-law samples into the second half of the buffer, so 313 /* We read µ-law samples into the second half of the buffer, so
314 we can expand them to 16-bit samples afterwards */ 314 we can expand them to 16-bit samples afterwards */
315 maxlen >>= 1; 315 maxlen >>= 1;
316 buf += maxlen; 316 buf += maxlen;
317 } /* if */ 317 } /* if */
318 318