MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / LoadSoundData

Function LoadSoundData

src/soundloader.cpp:23–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21template class ProviderManager<SoundLoader>;
22
23bool 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
53static bool LoadBasesetSound(SoundEntry &sound, bool new_format, SoundID sound_id)
54{

Callers 2

LoadNewGRFSoundFunction · 0.85
LoadBasesetSoundFunction · 0.85

Calls 6

GetPosMethod · 0.80
SeekToMethod · 0.80
resizeMethod · 0.80
LoadMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected