Given a filename, loads the sound file.
| 407 | |
| 408 | // Given a filename, loads the sound file. |
| 409 | int LoadSoundFile(const char *filename, float import_volume, bool f_get_data) { |
| 410 | int sound_file_index; |
| 411 | char extension[10]; |
| 412 | char name[90]; |
| 413 | int len; |
| 414 | |
| 415 | ChangeSoundFileName(filename, name); |
| 416 | |
| 417 | // See if the file was already loaded |
| 418 | sound_file_index = FindSoundFileName(name); |
| 419 | if (sound_file_index != -1) |
| 420 | return sound_file_index; |
| 421 | |
| 422 | // Make room for the new sound |
| 423 | sound_file_index = AllocSoundFile(); |
| 424 | if (sound_file_index == -1) { |
| 425 | mprintf(0, "SOUND LOADER: No free sound file slots are available.\n", filename); |
| 426 | Int3(); |
| 427 | return -1; |
| 428 | } |
| 429 | |
| 430 | // Validate the extension length |
| 431 | |
| 432 | len = strlen(filename); |
| 433 | if (len < 4) { |
| 434 | mprintf(0, "SOUND LOADER: %s does not have a 3 charactor extension.\n", filename); |
| 435 | Int3(); // Get chris |
| 436 | goto error_state; |
| 437 | } |
| 438 | |
| 439 | strcpy(SoundFiles[sound_file_index].name, name); |
| 440 | |
| 441 | // Load the file by its type (as defined by the extension) |
| 442 | strncpy(extension, &filename[len - 3], 5); |
| 443 | if (strnicmp("wav", extension, 3) == 0) { |
| 444 | if (!SoundLoadWaveFile(filename, import_volume, sound_file_index, false, f_get_data)) { |
| 445 | mprintf(0, "SOUND LOADER: Error loading %s.\n", filename); |
| 446 | goto error_state; |
| 447 | } |
| 448 | } else { |
| 449 | mprintf(0, "SOUND LOADER: %s in not a supported file type.\n", extension); |
| 450 | goto error_state; |
| 451 | } |
| 452 | |
| 453 | return sound_file_index; |
| 454 | |
| 455 | error_state: |
| 456 | if (SoundFiles[sound_file_index].used) |
| 457 | FreeSoundFile(sound_file_index); |
| 458 | return -1; |
| 459 | } |
| 460 | |
| 461 | // Sets all sounds to unused |
| 462 | void InitSounds() { |
no test coverage detected