26bool LoadSoundData(
SoundEntry &sound,
bool new_format, SoundID sound_id,
const std::string &name)
29 if (sound.file_size == 0 || sound.file_size > SIZE_MAX - 2)
return false;
31 size_t pos = sound.file->
GetPos();
32 sound.data = std::make_shared<std::vector<std::byte>>();
34 sound.file->
SeekTo(pos, SEEK_SET);
35 if (loader->Load(sound, new_format, *sound.data))
break;
38 if (sound.data->empty()) {
43 assert(sound.bits_per_sample == 8 || sound.bits_per_sample == 16);
44 assert(sound.channels == 1);
45 assert(sound.rate != 0);
47 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);
51 if (play_rate != sound.rate) {
53 if (resampler->Resample(sound, play_rate))
break;
58 sound.data->resize(sound.data->size() + sound.channels * sound.bits_per_sample / 8);
59 sound.data->shrink_to_fit();
64static bool LoadBasesetSound(
SoundEntry &sound,
bool new_format, SoundID sound_id)
66 sound.file->
SeekTo(sound.file_offset, SEEK_SET);
69 size_t name_len = sound.file->
ReadByte();
70 std::string name(name_len,
'\0');
71 sound.file->
ReadBlock(name.data(), name_len);
73 return LoadSoundData(sound, new_format, sound_id,
StrMakeValid(name));
76bool LoadSound(
SoundEntry &sound, SoundID sound_id)
78 switch (sound.source) {
82 default: NOT_REACHED();
The ProviderManager manages a single Provider-type.
static std::vector< const TProviderType * > & GetProviders()
Get the currently known providers.
void ReadBlock(void *ptr, size_t size)
Read a block.
size_t GetPos() const
Get position in the file.
void SeekTo(size_t pos, int mode)
Seek in the current file.
uint8_t ReadByte()
Read a byte from the file.
const std::string & GetSimplifiedFilename() const
Get the simplified filename of the opened file.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
uint32_t MxGetRate()
Get the current mixer sampling rate.
Functions to mix sound samples.
bool LoadNewGRFSound(SoundEntry &sound, SoundID sound_id)
Extract meta data from a NewGRF sound.
Functions related to NewGRF provided sounds.
Class related to random access to files.
A number of safeguards to prevent using unsafe methods.
@ NewGRF
Contained within a NewGRF.
@ BasesetNewFormat
New format with Opus and WAV files.
@ BasesetOldFormat
The TTD format with certain internal bugs (incorrect frequency, WAV without headers,...
Functions related to sound loaders.
Types related to sound loaders.
Types related to sound resamplers.
Definition of base types and functions in a cross-platform compatible way.
static void StrMakeValid(Builder &builder, StringConsumer &consumer, StringValidationSettings settings)
Copies the valid (UTF-8) characters from consumer to the builder.
Functions related to low-level strings.