Mercurial > SDL_sound_CoreAudio
comparison decoders/wav.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 | 6cd07211a235 |
children | 12a9c2e0b00f |
comparison
equal
deleted
inserted
replaced
220:ef72f3c490e7 | 221:c9772a9f5271 |
---|---|
47 static int WAV_init(void); | 47 static int WAV_init(void); |
48 static void WAV_quit(void); | 48 static void WAV_quit(void); |
49 static int WAV_open(Sound_Sample *sample, const char *ext); | 49 static int WAV_open(Sound_Sample *sample, const char *ext); |
50 static void WAV_close(Sound_Sample *sample); | 50 static void WAV_close(Sound_Sample *sample); |
51 static Uint32 WAV_read(Sound_Sample *sample); | 51 static Uint32 WAV_read(Sound_Sample *sample); |
52 static int WAV_rewind(Sound_Sample *sample); | |
52 | 53 |
53 static const char *extensions_wav[] = { "WAV", NULL }; | 54 static const char *extensions_wav[] = { "WAV", NULL }; |
54 const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV = | 55 const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV = |
55 { | 56 { |
56 { | 57 { |
58 "Microsoft WAVE audio format", | 59 "Microsoft WAVE audio format", |
59 "Ryan C. Gordon <icculus@clutteredmind.org>", | 60 "Ryan C. Gordon <icculus@clutteredmind.org>", |
60 "http://www.icculus.org/SDL_sound/" | 61 "http://www.icculus.org/SDL_sound/" |
61 }, | 62 }, |
62 | 63 |
63 WAV_init, /* init() method */ | 64 WAV_init, /* init() method */ |
64 WAV_quit, /* quit() method */ | 65 WAV_quit, /* quit() method */ |
65 WAV_open, /* open() method */ | 66 WAV_open, /* open() method */ |
66 WAV_close, /* close() method */ | 67 WAV_close, /* close() method */ |
67 WAV_read /* read() method */ | 68 WAV_read, /* read() method */ |
69 WAV_rewind /* rewind() method */ | |
68 }; | 70 }; |
69 | 71 |
70 | 72 |
71 /* Better than SDL_ReadLE16, since you can detect i/o errors... */ | 73 /* Better than SDL_ReadLE16, since you can detect i/o errors... */ |
72 static inline int read_le16(SDL_RWops *rw, Uint16 *ui16) | 74 static inline int read_le16(SDL_RWops *rw, Uint16 *ui16) |
137 Uint32 dwAvgBytesPerSec; | 139 Uint32 dwAvgBytesPerSec; |
138 Uint16 wBlockAlign; | 140 Uint16 wBlockAlign; |
139 Uint16 wBitsPerSample; | 141 Uint16 wBitsPerSample; |
140 | 142 |
141 Uint32 sample_frame_size; | 143 Uint32 sample_frame_size; |
144 Uint32 data_starting_offset; | |
145 Uint32 total_bytes; | |
142 | 146 |
143 void (*free)(struct S_WAV_FMT_T *fmt); | 147 void (*free)(struct S_WAV_FMT_T *fmt); |
144 Uint32 (*read_sample)(Sound_Sample *sample); | 148 Uint32 (*read_sample)(Sound_Sample *sample); |
149 int (*rewind_sample)(Sound_Sample *sample); | |
145 | 150 |
146 union | 151 union |
147 { | 152 { |
148 struct | 153 struct |
149 { | 154 { |
266 | 271 |
267 return(retval); | 272 return(retval); |
268 } /* read_sample_fmt_normal */ | 273 } /* read_sample_fmt_normal */ |
269 | 274 |
270 | 275 |
276 static int rewind_sample_fmt_normal(Sound_Sample *sample) | |
277 { | |
278 /* no-op. */ | |
279 return(1); | |
280 } /* rewind_sample_fmt_normal */ | |
281 | |
271 | 282 |
272 static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt) | 283 static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt) |
273 { | 284 { |
274 /* (don't need to read more from the RWops...) */ | 285 /* (don't need to read more from the RWops...) */ |
275 fmt->free = NULL; | 286 fmt->free = NULL; |
276 fmt->read_sample = read_sample_fmt_normal; | 287 fmt->read_sample = read_sample_fmt_normal; |
288 fmt->rewind_sample = rewind_sample_fmt_normal; | |
277 return(1); | 289 return(1); |
278 } /* read_fmt_normal */ | 290 } /* read_fmt_normal */ |
279 | 291 |
280 | 292 |
281 | 293 |
484 if (fmt->fmt.adpcm.blockheaders != NULL) | 496 if (fmt->fmt.adpcm.blockheaders != NULL) |
485 free(fmt->fmt.adpcm.blockheaders); | 497 free(fmt->fmt.adpcm.blockheaders); |
486 } /* free_fmt_adpcm */ | 498 } /* free_fmt_adpcm */ |
487 | 499 |
488 | 500 |
501 static int rewind_sample_fmt_adpcm(Sound_Sample *sample) | |
502 { | |
503 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
504 wav_t *w = (wav_t *) internal->decoder_private; | |
505 w->fmt->fmt.adpcm.samples_left_in_block = 0; | |
506 return(1); | |
507 } /* rewind_sample_fmt_adpcm */ | |
508 | |
509 | |
489 /* | 510 /* |
490 * Read in a the adpcm-specific info from disk. This makes this process | 511 * Read in a the adpcm-specific info from disk. This makes this process |
491 * safe regardless of the processor's byte order or how the fmt_t | 512 * safe regardless of the processor's byte order or how the fmt_t |
492 * structure is packed. | 513 * structure is packed. |
493 */ | 514 */ |
496 size_t i; | 517 size_t i; |
497 | 518 |
498 memset(&fmt->fmt.adpcm, '\0', sizeof (fmt->fmt.adpcm)); | 519 memset(&fmt->fmt.adpcm, '\0', sizeof (fmt->fmt.adpcm)); |
499 fmt->free = free_fmt_adpcm; | 520 fmt->free = free_fmt_adpcm; |
500 fmt->read_sample = read_sample_fmt_adpcm; | 521 fmt->read_sample = read_sample_fmt_adpcm; |
522 fmt->rewind_sample = rewind_sample_fmt_adpcm; | |
501 | 523 |
502 BAIL_IF_MACRO(!read_le16(rw, &fmt->fmt.adpcm.cbSize), NULL, 0); | 524 BAIL_IF_MACRO(!read_le16(rw, &fmt->fmt.adpcm.cbSize), NULL, 0); |
503 BAIL_IF_MACRO(!read_le16(rw, &fmt->fmt.adpcm.wSamplesPerBlock), NULL, 0); | 525 BAIL_IF_MACRO(!read_le16(rw, &fmt->fmt.adpcm.wSamplesPerBlock), NULL, 0); |
504 BAIL_IF_MACRO(!read_le16(rw, &fmt->fmt.adpcm.wNumCoef), NULL, 0); | 526 BAIL_IF_MACRO(!read_le16(rw, &fmt->fmt.adpcm.wNumCoef), NULL, 0); |
505 | 527 |
627 BAIL_IF_MACRO(!read_data_chunk(rw, &d), "WAV: Can't read data chunk.", 0); | 649 BAIL_IF_MACRO(!read_data_chunk(rw, &d), "WAV: Can't read data chunk.", 0); |
628 | 650 |
629 w = (wav_t *) malloc(sizeof(wav_t)); | 651 w = (wav_t *) malloc(sizeof(wav_t)); |
630 BAIL_IF_MACRO(w == NULL, ERR_OUT_OF_MEMORY, 0); | 652 BAIL_IF_MACRO(w == NULL, ERR_OUT_OF_MEMORY, 0); |
631 w->fmt = fmt; | 653 w->fmt = fmt; |
632 w->bytesLeft = d.chunkSize; | 654 fmt->total_bytes = w->bytesLeft = d.chunkSize; |
655 fmt->data_starting_offset = SDL_RWtell(rw); | |
633 | 656 |
634 /* !!! FIXME: Move this to Sound_SampleInfo ? */ | 657 /* !!! FIXME: Move this to Sound_SampleInfo ? */ |
635 fmt->sample_frame_size = ( ((sample->actual.format & 0xFF) / 8) * | 658 fmt->sample_frame_size = ( ((sample->actual.format & 0xFF) / 8) * |
636 sample->actual.channels ); | 659 sample->actual.channels ); |
637 | 660 |
682 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | 705 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
683 wav_t *w = (wav_t *) internal->decoder_private; | 706 wav_t *w = (wav_t *) internal->decoder_private; |
684 return(w->fmt->read_sample(sample)); | 707 return(w->fmt->read_sample(sample)); |
685 } /* WAV_read */ | 708 } /* WAV_read */ |
686 | 709 |
710 | |
711 static int WAV_rewind(Sound_Sample *sample) | |
712 { | |
713 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
714 wav_t *w = (wav_t *) internal->decoder_private; | |
715 fmt_t *fmt = w->fmt; | |
716 int rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, SEEK_SET); | |
717 BAIL_IF_MACRO(rc != fmt->data_starting_offset, ERR_IO_ERROR, 0); | |
718 w->bytesLeft = fmt->total_bytes; | |
719 return(fmt->rewind_sample(sample)); | |
720 } /* WAV_rewind */ | |
721 | |
687 #endif /* SOUND_SUPPORTS_WAV */ | 722 #endif /* SOUND_SUPPORTS_WAV */ |
688 | 723 |
689 /* end of wav.c ... */ | 724 /* end of wav.c ... */ |
690 | 725 |