| 490 | |
| 491 | #define SOUND_FILE_SAMPLE_ALIGNMENT 4 |
| 492 | char taunt_LoadWaveFile(char *filename, tWaveFile *wave) { |
| 493 | // File pointer to sound file |
| 494 | CFILE *cfptr; |
| 495 | |
| 496 | wave->sample_16bit = NULL; |
| 497 | wave->sample_8bit = NULL; |
| 498 | wave->np_sample_length = 0; |
| 499 | wave->sample_length = 0; |
| 500 | |
| 501 | cfptr = NULL; |
| 502 | char format_type[80]; // ASCII name of format type |
| 503 | uint16_t fmttag = 0; // Numerical format type |
| 504 | uint32_t ckid; // Current chunk's ID |
| 505 | uint32_t cksize; // Current chunk's size in bytes |
| 506 | uint32_t filesize; // Size of the sound file |
| 507 | uint32_t nextseek = 0; // Location of the next seek |
| 508 | uint32_t aligned_size; // Sound files are aligned to SOUND_FILE_SAMPLE_ALIGNMENT samples |
| 509 | |
| 510 | // Sound format information |
| 511 | int samples_per_second; |
| 512 | int16_t bits_per_sample; |
| 513 | int16_t number_channels; |
| 514 | char error_code = 0; |
| 515 | |
| 516 | // Used to read temporary long values |
| 517 | uint32_t temp_long; |
| 518 | |
| 519 | // Flags for if we previously read data or a format |
| 520 | char f_data, f_fmt = 0; |
| 521 | |
| 522 | // Loop counter |
| 523 | int count; |
| 524 | |
| 525 | // Open the wave file |
| 526 | if ((cfptr = cfopen(filename, "rb")) == NULL) { |
| 527 | error_code = 1; |
| 528 | mprintf(0, "TAUNT: Wav %s not found\n", filename); |
| 529 | goto error_state; |
| 530 | } |
| 531 | |
| 532 | // Make sure that it is a RIFF format |
| 533 | temp_long = (uint32_t)cf_ReadInt(cfptr); |
| 534 | if (temp_long != 0x46464952) { |
| 535 | error_code = 2; |
| 536 | mprintf(0, "TAUNT: Wav Load: %s is not a RIFF format file\n", filename); |
| 537 | goto error_state; |
| 538 | } |
| 539 | |
| 540 | // The first item is the filesize minus the RIFF type specifier and filesize (add current location for total filesize) |
| 541 | filesize = cf_ReadInt(cfptr); |
| 542 | filesize += cftell(cfptr); |
| 543 | |
| 544 | // Make sure it is a wave file |
| 545 | temp_long = (uint32_t)cf_ReadInt(cfptr); |
| 546 | if (temp_long != 0x45564157) { |
| 547 | error_code = 3; |
| 548 | mprintf(0, "TAUNT: Wav Load: %s is not a WAVE file\n", filename); |
| 549 | goto error_state; |
no test coverage detected