comparison decoders/au.c @ 221:c9772a9f5271

Initial implementation or stubs for rewind method. Other cleanups.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 17 Jan 2002 20:53:53 +0000
parents 9bab949e2318
children 7c4f6ee02cd0
comparison
equal deleted inserted replaced
220:ef72f3c490e7 221:c9772a9f5271
46 static int AU_init(void); 46 static int AU_init(void);
47 static void AU_quit(void); 47 static void AU_quit(void);
48 static int AU_open(Sound_Sample *sample, const char *ext); 48 static int AU_open(Sound_Sample *sample, const char *ext);
49 static void AU_close(Sound_Sample *sample); 49 static void AU_close(Sound_Sample *sample);
50 static Uint32 AU_read(Sound_Sample *sample); 50 static Uint32 AU_read(Sound_Sample *sample);
51 static int AU_rewind(Sound_Sample *sample);
51 52
52 /* 53 /*
53 * Sometimes the extension ".snd" is used for these files (mostly on the NeXT), 54 * Sometimes the extension ".snd" is used for these files (mostly on the NeXT),
54 * and the magic number comes from this. However it may clash with other 55 * and the magic number comes from this. However it may clash with other
55 * formats and is somewhat of an anachronism, so only .au is used here. 56 * formats and is somewhat of an anachronism, so only .au is used here.
62 "Sun/NeXT audio file format", 63 "Sun/NeXT audio file format",
63 "Mattias Engdegård <f91-men@nada.kth.se>", 64 "Mattias Engdegård <f91-men@nada.kth.se>",
64 "http://www.icculus.org/SDL_sound/" 65 "http://www.icculus.org/SDL_sound/"
65 }, 66 },
66 67
67 AU_init, 68 AU_init, /* init() method */
68 AU_quit, 69 AU_quit, /* quit() method */
69 AU_open, 70 AU_open, /* open() method */
70 AU_close, 71 AU_close, /* close() method */
71 AU_read 72 AU_read, /* read() method */
73 AU_rewind /* rewind() method */
72 }; 74 };
73 75
74 /* no init/deinit needed */ 76 /* no init/deinit needed */
75 static int AU_init(void) 77 static int AU_init(void)
76 { 78 {
113 AU_ENC_ALAW_8 = 27 115 AU_ENC_ALAW_8 = 27
114 }; 116 };
115 117
116 struct audec 118 struct audec
117 { 119 {
118 unsigned remaining; 120 Uint32 total;
121 Uint32 remaining;
122 Uint32 start_offset;
119 int encoding; 123 int encoding;
120 }; 124 };
121 125
122 126
123 #define AU_MAGIC 0x646E732E /* ".snd", in ASCII */ 127 #define AU_MAGIC 0x646E732E /* ".snd", in ASCII */
139 Sound_SetError("No .au file (bad header)"); 143 Sound_SetError("No .au file (bad header)");
140 free(dec); 144 free(dec);
141 return(0); 145 return(0);
142 } /* if */ 146 } /* if */
143 147
148 /*
149 * !!! FIXME: For correctness, we should calculate this as a bigendian
150 * !!! FIXME: number, which means swapping AU_MAGIC around.
151 */
144 if (SDL_SwapLE32(hdr.magic) == AU_MAGIC) 152 if (SDL_SwapLE32(hdr.magic) == AU_MAGIC)
145 { 153 {
146 /* valid magic */ 154 /* valid magic */
147 dec->encoding = SDL_SwapBE32(hdr.encoding); 155 dec->encoding = SDL_SwapBE32(hdr.encoding);
148 switch(dec->encoding) 156 switch(dec->encoding)
202 free(dec); 210 free(dec);
203 return(0); 211 return(0);
204 } /* else */ 212 } /* else */
205 213
206 sample->flags = SOUND_SAMPLEFLAG_NONE; 214 sample->flags = SOUND_SAMPLEFLAG_NONE;
215 dec->total = dec->remaining;
216 dec->start_offset = SDL_RWtell(rw);
207 217
208 SNDDBG(("AU: Accepting data stream.\n")); 218 SNDDBG(("AU: Accepting data stream.\n"));
209 return(1); 219 return(1);
210 } /* AU_open */ 220 } /* AU_open */
211 221
271 we can expand them to 16-bit samples afterwards */ 281 we can expand them to 16-bit samples afterwards */
272 maxlen >>= 1; 282 maxlen >>= 1;
273 buf += maxlen; 283 buf += maxlen;
274 } /* if */ 284 } /* if */
275 285
276 if(maxlen > dec->remaining) 286 if (maxlen > dec->remaining)
277 maxlen = dec->remaining; 287 maxlen = dec->remaining;
278 ret = SDL_RWread(internal->rw, buf, 1, maxlen); 288 ret = SDL_RWread(internal->rw, buf, 1, maxlen);
279 if (ret == 0) 289 if (ret == 0)
280 sample->flags |= SOUND_SAMPLEFLAG_EOF; 290 sample->flags |= SOUND_SAMPLEFLAG_EOF;
281 else if (ret == -1) 291 else if (ret == -1)
297 } /* else */ 307 } /* else */
298 308
299 return(ret); 309 return(ret);
300 } /* AU_read */ 310 } /* AU_read */
301 311
312
313 static int AU_rewind(Sound_Sample *sample)
314 {
315 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
316 struct audec *dec = (struct audec *) internal->decoder_private;
317 int rc = SDL_RWseek(internal->rw, dec->start_offset, SEEK_SET);
318 BAIL_IF_MACRO(rc != dec->start_offset, ERR_IO_ERROR, 0);
319 dec->remaining = dec->total;
320 return(1);
321 } /* AU_rewind */
322
302 #endif /* SOUND_SUPPORTS_AU */ 323 #endif /* SOUND_SUPPORTS_AU */
303 324