| 21 | template class ProviderManager<SoundLoader>; |
| 22 | |
| 23 | bool LoadSoundData(SoundEntry &sound, bool new_format, SoundID sound_id, const std::string &name) |
| 24 | { |
| 25 | /* Check for valid sound size. */ |
| 26 | if (sound.file_size == 0 || sound.file_size > SIZE_MAX - 2) return false; |
| 27 | |
| 28 | size_t pos = sound.file->GetPos(); |
| 29 | sound.data = std::make_shared<std::vector<std::byte>>(); |
| 30 | for (auto &loader : ProviderManager<SoundLoader>::GetProviders()) { |
| 31 | sound.file->SeekTo(pos, SEEK_SET); |
| 32 | if (loader->Load(sound, new_format, *sound.data)) break; |
| 33 | } |
| 34 | |
| 35 | if (sound.data->empty()) { |
| 36 | Debug(grf, 0, "LoadSound [{}]: Failed to load sound '{}' for slot {}", sound.file->GetSimplifiedFilename(), name, sound_id); |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | assert(sound.bits_per_sample == 8 || sound.bits_per_sample == 16); |
| 41 | assert(sound.channels == 1); |
| 42 | assert(sound.rate != 0); |
| 43 | |
| 44 | Debug(grf, 2, "LoadSound [{}]: channels {}, sample rate {}, bits per sample {}, length {}", sound.file->GetSimplifiedFilename(), sound.channels, sound.rate, sound.bits_per_sample, sound.file_size); |
| 45 | |
| 46 | /* Mixer always requires an extra sample at the end for the built-in linear resampler. */ |
| 47 | sound.data->resize(sound.data->size() + sound.channels * sound.bits_per_sample / 8); |
| 48 | sound.data->shrink_to_fit(); |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | static bool LoadBasesetSound(SoundEntry &sound, bool new_format, SoundID sound_id) |
| 54 | { |