comparison decoders/au.c @ 536:8a814bbbedfa

Merged r544:545 from branches/stable-1.0: converted to UTF-8 encoding.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 17 Apr 2008 18:08:02 +0000
parents 3e705c9180e5
children 2e8907ff98e9
comparison
equal deleted inserted replaced
534:a116d8f628a0 536:8a814bbbedfa
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;
265 Sound_SampleInternal *internal = sample->opaque; 265 Sound_SampleInternal *internal = sample->opaque;
266 free(internal->decoder_private); 266 free(internal->decoder_private);
267 } /* AU_close */ 267 } /* AU_close */
268 268
269 269
270 /* table to convert from µ-law encoding to signed 16-bit samples, 270 /* table to convert from µ-law encoding to signed 16-bit samples,
271 generated by a throwaway perl script */ 271 generated by a throwaway perl script */
272 static Sint16 ulaw_to_linear[256] = { 272 static Sint16 ulaw_to_linear[256] = {
273 -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956, 273 -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
274 -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764, 274 -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
275 -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412, 275 -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
315 315
316 maxlen = internal->buffer_size; 316 maxlen = internal->buffer_size;
317 buf = internal->buffer; 317 buf = internal->buffer;
318 if (dec->encoding == AU_ENC_ULAW_8) 318 if (dec->encoding == AU_ENC_ULAW_8)
319 { 319 {
320 /* We read µ-law samples into the second half of the buffer, so 320 /* We read µ-law samples into the second half of the buffer, so
321 we can expand them to 16-bit samples afterwards */ 321 we can expand them to 16-bit samples afterwards */
322 maxlen >>= 1; 322 maxlen >>= 1;
323 buf += maxlen; 323 buf += maxlen;
324 } /* if */ 324 } /* if */
325 325