trunk/src/lib/util/chdcd.c
| r20104 | r20105 | |
| 164 | 164 | if (offset < 4) |
| 165 | 165 | { |
| 166 | 166 | osd_close(file); |
| 167 | | printf("ERROR: unexpected RIFF offset %lu (%s)\n", actual, filename); |
| 167 | printf("ERROR: unexpected RIFF offset %lu (%s)\n", offset, filename); |
| 168 | 168 | return 0; |
| 169 | 169 | } |
| 170 | 170 | if (memcmp(&buf[0], "RIFF", 4) != 0) |
| r20104 | r20105 | |
| 180 | 180 | if (offset < 8) |
| 181 | 181 | { |
| 182 | 182 | osd_close(file); |
| 183 | | printf("ERROR: unexpected size offset %lu (%s)\n", actual, filename); |
| 183 | printf("ERROR: unexpected size offset %lu (%s)\n", offset, filename); |
| 184 | 184 | return 0; |
| 185 | 185 | } |
| 186 | 186 | filesize = LITTLE_ENDIANIZE_INT32(filesize); |
| r20104 | r20105 | |
| 191 | 191 | if (offset < 12) |
| 192 | 192 | { |
| 193 | 193 | osd_close(file); |
| 194 | | printf("ERROR: unexpected WAVE offset %lu (%s)\n", actual, filename); |
| 194 | printf("ERROR: unexpected WAVE offset %lu (%s)\n", offset, filename); |
| 195 | 195 | return 0; |
| 196 | 196 | } |
| 197 | 197 | if (memcmp(&buf[0], "WAVE", 4) != 0) |
| 198 | 198 | { |
| 199 | 199 | osd_close(file); |
| 200 | | printf("ERROR:could not find WAVE header (%s)\n", filename); |
| 200 | printf("ERROR: could not find WAVE header (%s)\n", filename); |
| 201 | 201 | return 0; |
| 202 | 202 | } |
| 203 | 203 | |
| r20104 | r20105 | |
| 217 | 217 | if (offset >= filesize) |
| 218 | 218 | { |
| 219 | 219 | osd_close(file); |
| 220 | | printf("ERROR:could not find fmt tag (%s)\n", filename); |
| 220 | printf("ERROR: could not find fmt tag (%s)\n", filename); |
| 221 | 221 | return 0; |
| 222 | 222 | } |
| 223 | 223 | } |
| r20104 | r20105 | |
| 297 | 297 | |
| 298 | 298 | /* if there was a 0 length data block, we're done */ |
| 299 | 299 | if (length == 0) |
| 300 | { |
| 301 | printf("ERROR: empty data block (%s)\n", filename); |
| 300 | 302 | return 0; |
| 303 | } |
| 301 | 304 | |
| 302 | 305 | *dataoffs = offset; |
| 303 | 306 | |
trunk/src/emu/sound/samples.c
| r20104 | r20105 | |
| 462 | 462 | UINT32 filesize; |
| 463 | 463 | offset += file.read(&filesize, 4); |
| 464 | 464 | if (offset < 8) |
| 465 | { |
| 466 | mame_printf_warning("Unexpected size offset %u (%s)\n", offset, file.filename()); |
| 465 | 467 | return false; |
| 468 | } |
| 466 | 469 | filesize = LITTLE_ENDIANIZE_INT32(filesize); |
| 467 | 470 | |
| 468 | 471 | // read the RIFF file type and make sure it's a WAVE file |
| 469 | 472 | char buf[32]; |
| 470 | 473 | offset += file.read(buf, 4); |
| 471 | 474 | if (offset < 12) |
| 475 | { |
| 476 | mame_printf_warning("Unexpected WAVE offset %u (%s)\n", offset, file.filename()); |
| 472 | 477 | return false; |
| 478 | } |
| 473 | 479 | if (memcmp(&buf[0], "WAVE", 4) != 0) |
| 474 | 480 | return false; |
| 475 | 481 | |
| r20104 | r20105 | |
| 487 | 493 | file.seek(length, SEEK_CUR); |
| 488 | 494 | offset += length; |
| 489 | 495 | if (offset >= filesize) |
| 496 | { |
| 497 | mame_printf_warning("Could not find fmt tag (%s)\n", file.filename()); |
| 490 | 498 | return false; |
| 499 | } |
| 491 | 500 | } |
| 492 | 501 | |
| 493 | 502 | // read the format -- make sure it is PCM |
| r20104 | r20105 | |
| 495 | 504 | offset += file.read(&temp16, 2); |
| 496 | 505 | temp16 = LITTLE_ENDIANIZE_INT16(temp16); |
| 497 | 506 | if (temp16 != 1) |
| 507 | { |
| 508 | mame_printf_warning("unsupported format %u - only PCM is supported (%s)\n", temp16, file.filename()); |
| 498 | 509 | return false; |
| 510 | } |
| 499 | 511 | |
| 500 | 512 | // number of channels -- only mono is supported |
| 501 | 513 | offset += file.read(&temp16, 2); |
| 502 | 514 | temp16 = LITTLE_ENDIANIZE_INT16(temp16); |
| 503 | 515 | if (temp16 != 1) |
| 516 | { |
| 517 | mame_printf_warning("unsupported number of channels %u - only mono is supported (%s)\n", temp16, file.filename()); |
| 504 | 518 | return false; |
| 519 | } |
| 505 | 520 | |
| 506 | 521 | // sample rate |
| 507 | 522 | UINT32 rate; |
| r20104 | r20105 | |
| 516 | 531 | offset += file.read(&bits, 2); |
| 517 | 532 | bits = LITTLE_ENDIANIZE_INT16(bits); |
| 518 | 533 | if (bits != 8 && bits != 16) |
| 534 | { |
| 535 | mame_printf_warning("unsupported bits/sample %u - only 8 and 16 are supported (%s)\n", bits, file.filename()); |
| 519 | 536 | return false; |
| 537 | } |
| 520 | 538 | |
| 521 | 539 | // seek past any extra data |
| 522 | 540 | file.seek(length - 16, SEEK_CUR); |
| r20104 | r20105 | |
| 535 | 553 | file.seek(length, SEEK_CUR); |
| 536 | 554 | offset += length; |
| 537 | 555 | if (offset >= filesize) |
| 556 | { |
| 557 | mame_printf_warning("Could not find data tag (%s)\n", file.filename()); |
| 538 | 558 | return false; |
| 559 | } |
| 539 | 560 | } |
| 540 | 561 | |
| 541 | 562 | // if there was a 0 length data block, we're done |
| 542 | 563 | if (length == 0) |
| 564 | { |
| 565 | mame_printf_warning("empty data block (%s)\n", file.filename()); |
| 543 | 566 | return false; |
| 567 | } |
| 544 | 568 | |
| 545 | 569 | // fill in the sample data |
| 546 | 570 | sample.frequency = rate; |