comparison decoders/aiff.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 47cc2de2ae36
children c97be6e1bd27
comparison
equal deleted inserted replaced
220:ef72f3c490e7 221:c9772a9f5271
63 static int AIFF_init(void); 63 static int AIFF_init(void);
64 static void AIFF_quit(void); 64 static void AIFF_quit(void);
65 static int AIFF_open(Sound_Sample *sample, const char *ext); 65 static int AIFF_open(Sound_Sample *sample, const char *ext);
66 static void AIFF_close(Sound_Sample *sample); 66 static void AIFF_close(Sound_Sample *sample);
67 static Uint32 AIFF_read(Sound_Sample *sample); 67 static Uint32 AIFF_read(Sound_Sample *sample);
68 static int AIFF_rewind(Sound_Sample *sample);
68 69
69 static const char *extensions_aiff[] = { "AIFF", NULL }; 70 static const char *extensions_aiff[] = { "AIFF", NULL };
70 const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF = 71 const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF =
71 { 72 {
72 { 73 {
74 "Audio Interchange File Format", 75 "Audio Interchange File Format",
75 "Torbjörn Andersson <d91tan@Update.UU.SE>", 76 "Torbjörn Andersson <d91tan@Update.UU.SE>",
76 "http://www.icculus.org/SDL_sound/" 77 "http://www.icculus.org/SDL_sound/"
77 }, 78 },
78 79
79 AIFF_init, /* init() method */ 80 AIFF_init, /* init() method */
80 AIFF_quit, /* quit() method */ 81 AIFF_quit, /* quit() method */
81 AIFF_open, /* open() method */ 82 AIFF_open, /* open() method */
82 AIFF_close, /* close() method */ 83 AIFF_close, /* close() method */
83 AIFF_read /* read() method */ 84 AIFF_read, /* read() method */
85 AIFF_rewind /* rewind() method */
84 }; 86 };
85 87
86 88
87 /***************************************************************************** 89 /*****************************************************************************
88 * aiff_t is what we store in our internal->decoder_private field... * 90 * aiff_t is what we store in our internal->decoder_private field... *
89 *****************************************************************************/ 91 *****************************************************************************/
90 typedef struct S_AIFF_FMT_T 92 typedef struct S_AIFF_FMT_T
91 { 93 {
92 Uint32 type; 94 Uint32 type;
95
96 Uint32 total_bytes;
97 Uint32 data_starting_offset;
98
93 void (*free)(struct S_AIFF_FMT_T *fmt); 99 void (*free)(struct S_AIFF_FMT_T *fmt);
94 Uint32(*read_sample)(Sound_Sample *sample); 100 Uint32 (*read_sample)(Sound_Sample *sample);
101 int (*rewind_sample)(Sound_Sample *sample);
102
95 103
96 #if 0 104 #if 0
97 /* 105 /*
98 this is ripped from wav.c as ann example of format-specific data. 106 this is ripped from wav.c as ann example of format-specific data.
99 please replace with something more appropriate when the need arises. 107 please replace with something more appropriate when the need arises.
313 321
314 return(retval); 322 return(retval);
315 } /* read_sample_fmt_normal */ 323 } /* read_sample_fmt_normal */
316 324
317 325
326 static int rewind_sample_fmt_normal(Sound_Sample *sample)
327 {
328 /* no-op. */
329 return(1);
330 } /* rewind_sample_fmt_normal */
331
332
318 static void free_fmt_normal(fmt_t *fmt) 333 static void free_fmt_normal(fmt_t *fmt)
319 { 334 {
320 /* it's a no-op. */ 335 /* it's a no-op. */
321 } /* free_fmt_normal */ 336 } /* free_fmt_normal */
322 337
324 static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt) 339 static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt)
325 { 340 {
326 /* (don't need to read more from the RWops...) */ 341 /* (don't need to read more from the RWops...) */
327 fmt->free = free_fmt_normal; 342 fmt->free = free_fmt_normal;
328 fmt->read_sample = read_sample_fmt_normal; 343 fmt->read_sample = read_sample_fmt_normal;
344 fmt->rewind_sample = rewind_sample_fmt_normal;
329 return(1); 345 return(1);
330 } /* read_fmt_normal */ 346 } /* read_fmt_normal */
331 347
332 348
333 349
485 Sound_SetError("AIFF: Can't read sound data chunk."); 501 Sound_SetError("AIFF: Can't read sound data chunk.");
486 free(a); 502 free(a);
487 return(0); 503 return(0);
488 } /* if */ 504 } /* if */
489 505
490 a->bytesLeft = bytes_per_sample * c.numSampleFrames; 506 a->fmt.total_bytes = a->bytesLeft = bytes_per_sample * c.numSampleFrames;
507 a->fmt.data_starting_offset = SDL_RWtell(rw);
491 internal->decoder_private = (void *) a; 508 internal->decoder_private = (void *) a;
492 509
493 sample->flags = SOUND_SAMPLEFLAG_NONE; 510 sample->flags = SOUND_SAMPLEFLAG_NONE;
494 511
495 SNDDBG(("AIFF: Accepting data stream.\n")); 512 SNDDBG(("AIFF: Accepting data stream.\n"));
511 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; 528 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
512 aiff_t *a = (aiff_t *) internal->decoder_private; 529 aiff_t *a = (aiff_t *) internal->decoder_private;
513 return(a->fmt.read_sample(sample)); 530 return(a->fmt.read_sample(sample));
514 } /* AIFF_read */ 531 } /* AIFF_read */
515 532
533
534 static int AIFF_rewind(Sound_Sample *sample)
535 {
536 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
537 aiff_t *a = (aiff_t *) internal->decoder_private;
538 fmt_t *fmt = &a->fmt;
539 int rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, SEEK_SET);
540 BAIL_IF_MACRO(rc != fmt->data_starting_offset, ERR_IO_ERROR, 0);
541 a->bytesLeft = fmt->total_bytes;
542 return(fmt->rewind_sample(sample));
543 } /* AIFF_rewind */
544
516 #endif /* SOUND_SUPPORTS_AIFF */ 545 #endif /* SOUND_SUPPORTS_AIFF */
517 546
518 /* end of aiff.c ... */ 547 /* end of aiff.c ... */
519 548