Mercurial > SDL_sound_CoreAudio
comparison decoders/voc.c @ 387:fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 05 Jul 2002 23:11:51 +0000 |
parents | 9efb760c4a6b |
children | c42ac9ee2ce4 |
comparison
equal
deleted
inserted
replaced
386:8c8ecd1008c9 | 387:fb519e6028e3 |
---|---|
144 | 144 |
145 static inline int voc_readbytes(SDL_RWops *src, vs_t *v, void *p, int size) | 145 static inline int voc_readbytes(SDL_RWops *src, vs_t *v, void *p, int size) |
146 { | 146 { |
147 if (SDL_RWread(src, p, size, 1) != 1) | 147 if (SDL_RWread(src, p, size, 1) != 1) |
148 { | 148 { |
149 Sound_SetError("VOC: i/o error"); | |
150 v->error = 1; | 149 v->error = 1; |
151 return 0; | 150 BAIL_MACRO("VOC: i/o error", 0); |
152 } /* if */ | 151 } /* if */ |
153 | 152 |
154 return(1); | 153 return(1); |
155 } /* voc_readbytes */ | 154 } /* voc_readbytes */ |
156 | 155 |
165 if (!voc_readbytes(src, &v, signature, sizeof (signature))) | 164 if (!voc_readbytes(src, &v, signature, sizeof (signature))) |
166 return(0); | 165 return(0); |
167 | 166 |
168 if (memcmp(signature, "Creative Voice File\032", sizeof (signature)) != 0) | 167 if (memcmp(signature, "Creative Voice File\032", sizeof (signature)) != 0) |
169 { | 168 { |
170 Sound_SetError("VOC: Wrong signature; not a VOC file."); | 169 BAIL_MACRO("VOC: Wrong signature; not a VOC file.", 0); |
171 return(0); | |
172 } /* if */ | 170 } /* if */ |
173 | 171 |
174 /* get the offset where the first datablock is located */ | 172 /* get the offset where the first datablock is located */ |
175 if (!voc_readbytes(src, &v, &datablockofs, sizeof (Uint16))) | 173 if (!voc_readbytes(src, &v, &datablockofs, sizeof (Uint16))) |
176 return(0); | 174 return(0); |
177 | 175 |
178 datablockofs = SDL_SwapLE16(datablockofs); | 176 datablockofs = SDL_SwapLE16(datablockofs); |
179 | 177 |
180 if (SDL_RWseek(src, datablockofs, SEEK_SET) != datablockofs) | 178 if (SDL_RWseek(src, datablockofs, SEEK_SET) != datablockofs) |
181 { | 179 { |
182 Sound_SetError("VOC: Failed to seek to data block."); | 180 BAIL_MACRO("VOC: Failed to seek to data block.", 0); |
183 return(0); | |
184 } /* if */ | 181 } /* if */ |
185 | 182 |
186 return(1); /* success! */ | 183 return(1); /* success! */ |
187 } /* voc_check_header */ | 184 } /* voc_check_header */ |
188 | 185 |
225 | 222 |
226 /* When DATA block preceeded by an EXTENDED */ | 223 /* When DATA block preceeded by an EXTENDED */ |
227 /* block, the DATA blocks rate value is invalid */ | 224 /* block, the DATA blocks rate value is invalid */ |
228 if (!v->extended) | 225 if (!v->extended) |
229 { | 226 { |
230 if (uc == 0) | 227 BAIL_IF_MACRO(uc == 0, "VOC: Sample rate is zero?", 0); |
231 { | |
232 Sound_SetError("VOC Sample rate is zero?"); | |
233 return 0; | |
234 } /* if */ | |
235 | 228 |
236 if ((v->rate != -1) && (uc != v->rate)) | 229 if ((v->rate != -1) && (uc != v->rate)) |
237 { | 230 BAIL_MACRO("VOC sample rate codes differ", 0); |
238 Sound_SetError("VOC sample rate codes differ"); | |
239 return 0; | |
240 } /* if */ | |
241 | 231 |
242 v->rate = uc; | 232 v->rate = uc; |
243 sample->actual.rate = 1000000.0/(256 - v->rate); | 233 sample->actual.rate = 1000000.0/(256 - v->rate); |
244 v->channels = 1; | 234 v->channels = 1; |
245 } /* if */ | 235 } /* if */ |
246 | 236 |
247 if (!voc_readbytes(src, v, &uc, sizeof (uc))) | 237 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
248 return 0; | 238 return(0); |
249 | 239 |
250 if (uc != 0) | 240 BAIL_IF_MACRO(uc != 0, "VOC: only supports 8-bit data", 0); |
251 { | |
252 Sound_SetError("VOC decoder only interprets 8-bit data"); | |
253 return 0; | |
254 } /* if */ | |
255 | 241 |
256 v->extended = 0; | 242 v->extended = 0; |
257 v->rest = sblen - 2; | 243 v->rest = sblen - 2; |
258 v->size = ST_SIZE_BYTE; | 244 v->size = ST_SIZE_BYTE; |
259 return 1; | 245 return 1; |
261 case VOC_DATA_16: | 247 case VOC_DATA_16: |
262 if (!voc_readbytes(src, v, &new_rate_long, sizeof (Uint32))) | 248 if (!voc_readbytes(src, v, &new_rate_long, sizeof (Uint32))) |
263 return 0; | 249 return 0; |
264 | 250 |
265 new_rate_long = SDL_SwapLE32(new_rate_long); | 251 new_rate_long = SDL_SwapLE32(new_rate_long); |
266 if (new_rate_long == 0) | 252 BAIL_IF_MACRO(!new_rate_long, "VOC: Sample rate is zero?", 0); |
267 { | 253 |
268 Sound_SetError("VOC Sample rate is zero?"); | |
269 return 0; | |
270 } /* if */ | |
271 if ((v->rate != -1) && (new_rate_long != v->rate)) | 254 if ((v->rate != -1) && (new_rate_long != v->rate)) |
272 { | 255 BAIL_MACRO("VOC: sample rate codes differ", 0); |
273 Sound_SetError("VOC sample rate codes differ"); | 256 |
274 return 0; | |
275 } /* if */ | |
276 v->rate = new_rate_long; | 257 v->rate = new_rate_long; |
277 sample->actual.rate = new_rate_long; | 258 sample->actual.rate = new_rate_long; |
278 | 259 |
279 if (!voc_readbytes(src, v, &uc, sizeof (uc))) | 260 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
280 return 0; | 261 return 0; |
282 switch (uc) | 263 switch (uc) |
283 { | 264 { |
284 case 8: v->size = ST_SIZE_BYTE; break; | 265 case 8: v->size = ST_SIZE_BYTE; break; |
285 case 16: v->size = ST_SIZE_WORD; break; | 266 case 16: v->size = ST_SIZE_WORD; break; |
286 default: | 267 default: |
287 Sound_SetError("VOC with unknown data size"); | 268 BAIL_MACRO("VOC: unknown data size", 0); |
288 return 0; | |
289 } /* switch */ | 269 } /* switch */ |
290 | 270 |
291 if (!voc_readbytes(src, v, &v->channels, sizeof (Uint8))) | 271 if (!voc_readbytes(src, v, &v->channels, sizeof (Uint8))) |
292 return 0; | 272 return 0; |
293 | 273 |
308 period = SDL_SwapLE16(period); | 288 period = SDL_SwapLE16(period); |
309 | 289 |
310 if (!voc_readbytes(src, v, &uc, sizeof (uc))) | 290 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
311 return 0; | 291 return 0; |
312 | 292 |
313 if (uc == 0) | 293 BAIL_IF_MACRO(uc == 0, "VOC: silence sample rate is zero", 0); |
314 { | |
315 Sound_SetError("VOC silence sample rate is zero"); | |
316 return 0; | |
317 } /* if */ | |
318 | 294 |
319 /* | 295 /* |
320 * Some silence-packed files have gratuitously | 296 * Some silence-packed files have gratuitously |
321 * different sample rate codes in silence. | 297 * different sample rate codes in silence. |
322 * Adjust period. | 298 * Adjust period. |
331 | 307 |
332 case VOC_LOOP: | 308 case VOC_LOOP: |
333 case VOC_LOOPEND: | 309 case VOC_LOOPEND: |
334 for(i = 0; i < sblen; i++) /* skip repeat loops. */ | 310 for(i = 0; i < sblen; i++) /* skip repeat loops. */ |
335 { | 311 { |
336 if (!voc_readbytes(src, v, trash, sizeof (Uint8))) | 312 if (!voc_readbytes(src, v, trash, sizeof (Uint8))) |
337 return 0; | 313 return 0; |
338 } /* for */ | 314 } /* for */ |
339 break; | 315 break; |
340 | 316 |
341 case VOC_EXTENDED: | 317 case VOC_EXTENDED: |
346 v->extended = 1; | 322 v->extended = 1; |
347 if (!voc_readbytes(src, v, &new_rate_short, sizeof (Uint16))) | 323 if (!voc_readbytes(src, v, &new_rate_short, sizeof (Uint16))) |
348 return 0; | 324 return 0; |
349 | 325 |
350 new_rate_short = SDL_SwapLE16(new_rate_short); | 326 new_rate_short = SDL_SwapLE16(new_rate_short); |
351 if (new_rate_short == 0) | 327 BAIL_IF_MACRO(!new_rate_short, "VOC: sample rate is zero", 0); |
352 { | 328 |
353 Sound_SetError("VOC sample rate is zero"); | |
354 return 0; | |
355 } /* if */ | |
356 if ((v->rate != -1) && (new_rate_short != v->rate)) | 329 if ((v->rate != -1) && (new_rate_short != v->rate)) |
357 { | 330 BAIL_MACRO("VOC: sample rate codes differ", 0); |
358 Sound_SetError("VOC sample rate codes differ"); | 331 |
359 return 0; | |
360 } /* if */ | |
361 v->rate = new_rate_short; | 332 v->rate = new_rate_short; |
362 | 333 |
363 if (!voc_readbytes(src, v, &uc, sizeof (uc))) | 334 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
364 return 0; | 335 return 0; |
365 | 336 |
366 if (uc != 0) | 337 BAIL_IF_MACRO(uc != 0, "VOC: only supports 8-bit data", 0); |
367 { | |
368 Sound_SetError("VOC decoder only interprets 8-bit data"); | |
369 return 0; | |
370 } /* if */ | |
371 | 338 |
372 if (!voc_readbytes(src, v, &uc, sizeof (uc))) | 339 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
373 return 0; | 340 return 0; |
374 | 341 |
375 if (uc) | 342 if (uc) |
389 return 0; | 356 return 0; |
390 | 357 |
391 /* Falling! Falling! */ | 358 /* Falling! Falling! */ |
392 | 359 |
393 default: /* text block or other krapola. */ | 360 default: /* text block or other krapola. */ |
394 if (!voc_readbytes(src, v, &trash, sizeof (Uint8) * sblen)) | 361 for(i = 0; i < sblen; i++) /* skip repeat loops. */ |
395 return 0; | 362 { |
363 if (!voc_readbytes(src, v, trash, sizeof (Uint8))) | |
364 return 0; | |
365 } /* for */ | |
396 | 366 |
397 if (block == VOC_TEXT) | 367 if (block == VOC_TEXT) |
398 continue; /* get next block */ | 368 continue; /* get next block */ |
399 } /* switch */ | 369 } /* switch */ |
400 } /* while */ | 370 } /* while */ |
441 if (fill_buf) | 411 if (fill_buf) |
442 { | 412 { |
443 done = SDL_RWread(src, buf + v->bufpos, 1, max); | 413 done = SDL_RWread(src, buf + v->bufpos, 1, max); |
444 if (done < max) | 414 if (done < max) |
445 { | 415 { |
446 Sound_SetError("VOC: i/o error"); | 416 __Sound_SetError("VOC: i/o error"); |
447 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | 417 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
448 } /* if */ | 418 } /* if */ |
449 } /* if */ | 419 } /* if */ |
450 | 420 |
451 else | 421 else |
457 rc = SDL_RWseek(src, max, SEEK_CUR); | 427 rc = SDL_RWseek(src, max, SEEK_CUR); |
458 if (rc >= 0) | 428 if (rc >= 0) |
459 done = rc - cur; | 429 done = rc - cur; |
460 else | 430 else |
461 { | 431 { |
462 Sound_SetError("VOC: seek error"); | 432 __Sound_SetError("VOC: seek error"); |
463 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | 433 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
464 } /* else */ | 434 } /* else */ |
465 } /* if */ | 435 } /* if */ |
466 } /* else */ | 436 } /* else */ |
467 | 437 |
494 return(0); | 464 return(0); |
495 } /* if */ | 465 } /* if */ |
496 | 466 |
497 if (v->rate == -1) | 467 if (v->rate == -1) |
498 { | 468 { |
499 Sound_SetError("VOC data had no sound!"); | |
500 free(v); | 469 free(v); |
501 return(0); | 470 BAIL_MACRO("VOC: data had no sound!", 0); |
502 } /* if */ | 471 } /* if */ |
503 | 472 |
504 SNDDBG(("VOC: Accepting data stream.\n")); | 473 SNDDBG(("VOC: Accepting data stream.\n")); |
505 sample->actual.format = (v->size == ST_SIZE_WORD) ? AUDIO_S16LSB:AUDIO_U8; | 474 sample->actual.format = (v->size == ST_SIZE_WORD) ? AUDIO_S16LSB:AUDIO_U8; |
506 sample->actual.channels = v->channels; | 475 sample->actual.channels = v->channels; |