comparison decoders/wav.c @ 364:4bcbc442d145

Fix to handle strange WAV fmt chunks.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 13 Jun 2002 23:15:37 +0000
parents 069ce624d6cf
children cbb15ecf423a
comparison
equal deleted inserted replaced
363:0b0457462ccc 364:4bcbc442d145
140 Uint32 dwSamplesPerSec; 140 Uint32 dwSamplesPerSec;
141 Uint32 dwAvgBytesPerSec; 141 Uint32 dwAvgBytesPerSec;
142 Uint16 wBlockAlign; 142 Uint16 wBlockAlign;
143 Uint16 wBitsPerSample; 143 Uint16 wBitsPerSample;
144 144
145 Uint32 next_chunk_offset;
146
145 Uint32 sample_frame_size; 147 Uint32 sample_frame_size;
146 Uint32 data_starting_offset; 148 Uint32 data_starting_offset;
147 Uint32 total_bytes; 149 Uint32 total_bytes;
148 150
149 void (*free)(struct S_WAV_FMT_T *fmt); 151 void (*free)(struct S_WAV_FMT_T *fmt);
180 { 182 {
181 /* skip reading the chunk ID, since it was already read at this point... */ 183 /* skip reading the chunk ID, since it was already read at this point... */
182 fmt->chunkID = fmtID; 184 fmt->chunkID = fmtID;
183 185
184 BAIL_IF_MACRO(!read_le32(rw, &fmt->chunkSize), NULL, 0); 186 BAIL_IF_MACRO(!read_le32(rw, &fmt->chunkSize), NULL, 0);
187 BAIL_IF_MACRO(fmt->chunkSize < 16, "WAV: Invalid chunk size", 0);
188 fmt->next_chunk_offset = SDL_RWtell(rw) + fmt->chunkSize;
189
185 BAIL_IF_MACRO(!read_le16(rw, &fmt->wFormatTag), NULL, 0); 190 BAIL_IF_MACRO(!read_le16(rw, &fmt->wFormatTag), NULL, 0);
186 BAIL_IF_MACRO(!read_le16(rw, &fmt->wChannels), NULL, 0); 191 BAIL_IF_MACRO(!read_le16(rw, &fmt->wChannels), NULL, 0);
187 BAIL_IF_MACRO(!read_le32(rw, &fmt->dwSamplesPerSec), NULL, 0); 192 BAIL_IF_MACRO(!read_le32(rw, &fmt->dwSamplesPerSec), NULL, 0);
188 BAIL_IF_MACRO(!read_le32(rw, &fmt->dwAvgBytesPerSec), NULL, 0); 193 BAIL_IF_MACRO(!read_le32(rw, &fmt->dwAvgBytesPerSec), NULL, 0);
189 BAIL_IF_MACRO(!read_le16(rw, &fmt->wBlockAlign), NULL, 0); 194 BAIL_IF_MACRO(!read_le16(rw, &fmt->wBlockAlign), NULL, 0);
706 SNDDBG(("WAV: %d bits per sample!?\n", (int) fmt->wBitsPerSample)); 711 SNDDBG(("WAV: %d bits per sample!?\n", (int) fmt->wBitsPerSample));
707 BAIL_MACRO("WAV: Unsupported sample size.", 0); 712 BAIL_MACRO("WAV: Unsupported sample size.", 0);
708 } /* else */ 713 } /* else */
709 714
710 BAIL_IF_MACRO(!read_fmt(rw, fmt), NULL, 0); 715 BAIL_IF_MACRO(!read_fmt(rw, fmt), NULL, 0);
716 SDL_RWseek(rw, fmt->next_chunk_offset, SEEK_SET);
711 BAIL_IF_MACRO(!find_chunk(rw, dataID), "WAV: No data chunk.", 0); 717 BAIL_IF_MACRO(!find_chunk(rw, dataID), "WAV: No data chunk.", 0);
712 BAIL_IF_MACRO(!read_data_chunk(rw, &d), "WAV: Can't read data chunk.", 0); 718 BAIL_IF_MACRO(!read_data_chunk(rw, &d), "WAV: Can't read data chunk.", 0);
713 719
714 w = (wav_t *) malloc(sizeof(wav_t)); 720 w = (wav_t *) malloc(sizeof(wav_t));
715 BAIL_IF_MACRO(w == NULL, ERR_OUT_OF_MEMORY, 0); 721 BAIL_IF_MACRO(w == NULL, ERR_OUT_OF_MEMORY, 0);