Mercurial > SDL_sound_CoreAudio
comparison decoders/aiff.c @ 41:0d5ff5679523
Cleanups from Torbj�rn Andersson.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 22 Sep 2001 12:28:58 +0000 |
parents | 938ef560c7bf |
children | ea58bc3b15d7 |
comparison
equal
deleted
inserted
replaced
40:c15396fc0e55 | 41:0d5ff5679523 |
---|---|
177 | 177 |
178 if (SDL_RWread(rw, &comm->numChannels, sizeof (comm->numChannels), 1) != 1) | 178 if (SDL_RWread(rw, &comm->numChannels, sizeof (comm->numChannels), 1) != 1) |
179 return(0); | 179 return(0); |
180 comm->numChannels = SDL_SwapBE16(comm->numChannels); | 180 comm->numChannels = SDL_SwapBE16(comm->numChannels); |
181 | 181 |
182 if (SDL_RWread(rw, &comm->numSampleFrames, sizeof (comm->numSampleFrames), 1) != 1) | 182 if (SDL_RWread(rw, &comm->numSampleFrames, |
183 sizeof (comm->numSampleFrames), 1) != 1) | |
183 return(0); | 184 return(0); |
184 comm->numSampleFrames = SDL_SwapBE32(comm->numSampleFrames); | 185 comm->numSampleFrames = SDL_SwapBE32(comm->numSampleFrames); |
185 | 186 |
186 if (SDL_RWread(rw, &comm->sampleSize, sizeof (comm->sampleSize), 1) != 1) | 187 if (SDL_RWread(rw, &comm->sampleSize, sizeof (comm->sampleSize), 1) != 1) |
187 return(0); | 188 return(0); |
188 comm->sampleSize = SDL_SwapBE16(comm->sampleSize); | 189 comm->sampleSize = SDL_SwapBE16(comm->sampleSize); |
189 | 190 |
190 if (SDL_RWread(rw, sampleRate, sizeof(sampleRate), 1) != 1) | 191 if (SDL_RWread(rw, sampleRate, sizeof (sampleRate), 1) != 1) |
191 return(0); | 192 return(0); |
192 comm->sampleRate = SANE_to_Uint32(sampleRate); | 193 comm->sampleRate = SANE_to_Uint32(sampleRate); |
193 | 194 |
194 if (comm->ckDataSize > sizeof(comm->numChannels) | 195 if (comm->ckDataSize > sizeof(comm->numChannels) |
195 + sizeof(comm->numSampleFrames) | 196 + sizeof(comm->numSampleFrames) |
196 + sizeof(comm->sampleSize) | 197 + sizeof(comm->sampleSize) |
197 + sizeof(sampleRate)) | 198 + sizeof(sampleRate)) |
198 { | 199 { |
199 if (SDL_RWread(rw, &comm->compressionType, sizeof (comm->compressionType), 1) != 1) | 200 if (SDL_RWread(rw, &comm->compressionType, |
201 sizeof (comm->compressionType), 1) != 1) | |
200 return(0); | 202 return(0); |
201 comm->compressionType = SDL_SwapBE32(comm->compressionType); | 203 comm->compressionType = SDL_SwapBE32(comm->compressionType); |
202 } /* if */ | 204 } /* if */ |
203 else | 205 else |
204 comm->compressionType = noneID; | 206 comm->compressionType = noneID; |
226 | 228 |
227 if (SDL_RWread(rw, &ssnd->ckDataSize, sizeof (ssnd->ckDataSize), 1) != 1) | 229 if (SDL_RWread(rw, &ssnd->ckDataSize, sizeof (ssnd->ckDataSize), 1) != 1) |
228 return(0); | 230 return(0); |
229 ssnd->ckDataSize = SDL_SwapBE32(ssnd->ckDataSize); | 231 ssnd->ckDataSize = SDL_SwapBE32(ssnd->ckDataSize); |
230 | 232 |
231 if (SDL_RWread(rw, &ssnd->offset, sizeof(ssnd->offset), 1) != 1) | 233 if (SDL_RWread(rw, &ssnd->offset, sizeof (ssnd->offset), 1) != 1) |
232 return(0); | 234 return(0); |
233 ssnd->offset = SDL_SwapBE32(ssnd->offset); | 235 ssnd->offset = SDL_SwapBE32(ssnd->offset); |
234 | 236 |
235 if (SDL_RWread(rw, &ssnd->blockSize, sizeof(ssnd->blockSize), 1) != 1) | 237 if (SDL_RWread(rw, &ssnd->blockSize, sizeof (ssnd->blockSize), 1) != 1) |
236 return(0); | 238 return(0); |
237 ssnd->blockSize = SDL_SwapBE32(ssnd->blockSize); | 239 ssnd->blockSize = SDL_SwapBE32(ssnd->blockSize); |
238 | 240 |
239 /* Leave the SDL_RWops position indicator at the start of the samples */ | 241 /* Leave the SDL_RWops position indicator at the start of the samples */ |
240 if (SDL_RWseek(rw, (int) ssnd->offset, SEEK_CUR) == -1) /* !!! FIXME: Int? Really? */ | 242 /* !!! FIXME: Int? Really? */ |
243 if (SDL_RWseek(rw, (int) ssnd->offset, SEEK_CUR) == -1) | |
241 return(0); | 244 return(0); |
242 | 245 |
243 return(1); | 246 return(1); |
244 } /* read_ssnd_chunk */ | 247 } /* read_ssnd_chunk */ |
245 | 248 |
285 | 288 |
286 /* Chunks may appear in any order, so we establish base camp here. */ | 289 /* Chunks may appear in any order, so we establish base camp here. */ |
287 pos = SDL_RWtell(rw); | 290 pos = SDL_RWtell(rw); |
288 | 291 |
289 BAIL_IF_MACRO(!find_chunk(rw, commID), "AIFF: No common chunk.", 0); | 292 BAIL_IF_MACRO(!find_chunk(rw, commID), "AIFF: No common chunk.", 0); |
290 BAIL_IF_MACRO(!read_comm_chunk(rw, &c), "AIFF: Can't read common chunk.", 0); | 293 BAIL_IF_MACRO(!read_comm_chunk(rw, &c), |
294 "AIFF: Can't read common chunk.", 0); | |
291 | 295 |
292 /* !!! FIXME: This will have to change for compression types... */ | 296 /* !!! FIXME: This will have to change for compression types... */ |
293 BAIL_IF_MACRO(c.compressionType != noneID, "AIFF: Unsupported encoding.", 0); | 297 BAIL_IF_MACRO(c.compressionType != noneID, |
298 "AIFF: Unsupported encoding.", 0); | |
294 | 299 |
295 BAIL_IF_MACRO(c.sampleRate == 0, "AIFF: Unsupported sample rate.", 0); | 300 BAIL_IF_MACRO(c.sampleRate == 0, "AIFF: Unsupported sample rate.", 0); |
296 | 301 |
297 sample->actual.channels = (Uint8) c.numChannels; | 302 sample->actual.channels = (Uint8) c.numChannels; |
298 sample->actual.rate = c.sampleRate; | 303 sample->actual.rate = c.sampleRate; |
311 BAIL_MACRO("AIFF: Unsupported sample size.", 0); | 316 BAIL_MACRO("AIFF: Unsupported sample size.", 0); |
312 | 317 |
313 SDL_RWseek(rw, pos, SEEK_SET); | 318 SDL_RWseek(rw, pos, SEEK_SET); |
314 | 319 |
315 BAIL_IF_MACRO(!find_chunk(rw, ssndID), "AIFF: No sound data chunk.", 0); | 320 BAIL_IF_MACRO(!find_chunk(rw, ssndID), "AIFF: No sound data chunk.", 0); |
316 BAIL_IF_MACRO(!read_ssnd_chunk(rw, &s), "AIFF: Can't read sound data chunk.", 0); | 321 BAIL_IF_MACRO(!read_ssnd_chunk(rw, &s), |
322 "AIFF: Can't read sound data chunk.", 0); | |
317 | 323 |
318 a = (aiff_t *) malloc(sizeof(aiff_t)); | 324 a = (aiff_t *) malloc(sizeof(aiff_t)); |
319 BAIL_IF_MACRO(a == NULL, ERR_OUT_OF_MEMORY, 0); | 325 BAIL_IF_MACRO(a == NULL, ERR_OUT_OF_MEMORY, 0); |
320 a->bytesLeft = bytes_per_sample * c.numSampleFrames; | 326 a->bytesLeft = bytes_per_sample * c.numSampleFrames; |
321 internal->decoder_private = (void *) a; | 327 internal->decoder_private = (void *) a; |
328 | |
329 sample->flags = SOUND_SAMPLEFLAG_NONE; | |
322 | 330 |
323 _D(("AIFF: Accepting data stream.\n")); | 331 _D(("AIFF: Accepting data stream.\n")); |
324 return(1); /* we'll handle this data. */ | 332 return(1); /* we'll handle this data. */ |
325 } /* AIFF_open */ | 333 } /* AIFF_open */ |
326 | 334 |