23 static std::vector<SoundEntry> _sounds;
33 size_t pos = _sounds.size();
34 _sounds.insert(_sounds.end(), num,
SoundEntry());
39 void InitializeSoundPool()
50 if (index >= _sounds.size())
return nullptr;
51 return &_sounds[index];
57 return (uint)_sounds.size();
68 if (sound->file_offset == SIZE_MAX || sound->file ==
nullptr)
return false;
71 file.
SeekTo(sound->file_offset, SEEK_SET);
80 if (file.
ReadByte() != 0xFF)
return false;
81 if (file.
ReadByte() != 0xFF)
return false;
84 std::string name(name_len + 1,
'\0');
85 file.
ReadBlock(name.data(), name_len + 1);
88 if (name[name_len] != 0) {
101 uint header_size = 11;
103 if (total_size + name_len + header_size > num) {
113 while (total_size >= 8) {
117 if (total_size < size) {
126 if (size < 16 || file.
ReadWord() != 1) {
134 sound->bits_per_sample = file.
ReadWord();
141 sound->file_size = size;
142 sound->file_offset = file.
GetPos();
144 Debug(grf, 2,
"LoadNewGRFSound [{}]: channels {}, sample rate {}, bits per sample {}, length {}", file.
GetSimplifiedFilename(), sound->channels, sound->rate, sound->bits_per_sample, size);
175 if (file ==
nullptr || sound_id >= file->num_sounds)
return INVALID_SOUND;
177 return file->sound_offset + sound_id;
195 if (file ==
nullptr)
return false;
207 if (callback == INVALID_SOUND)
return true;
209 assert(callback < GetNumSounds());
210 SndPlayVehicleFx(callback, v);
223 if (sound_id == INVALID_SOUND)
return;
225 assert(sound_id < GetNumSounds());
226 SndPlayTileFx(sound_id, tile);
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
A file from which bytes, words and double words are read in (potentially) a random order.
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.
uint32_t ReadDword()
Read a double word (32 bits) from the file (in low endian format).
void SkipBytes(size_t n)
Skip n bytes ahead in the file.
uint16_t ReadWord()
Read a word (16 bits) from the file (in low endian format).
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
void MemSetT(T *ptr, uint8_t value, size_t num=1)
Type-safe version of memset().
Base for the NewGRF implementation.
@ CBID_VEHICLE_SOUND_EFFECT
Called to play a special sound effect.
@ CBM_VEHICLE_SOUND_EFFECT
Vehicle uses custom sound effects.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Functions for NewGRF engines.
void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
Play a NewGRF sound effect at the location of a specific tile.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force)
Checks whether a NewGRF wants to play a different vehicle sound effect.
bool LoadNewGRFSound(SoundEntry *sound)
Extract meta data from a NewGRF sound.
SoundID GetNewGRFSoundID(const GRFFile *file, SoundID sound_id)
Resolve NewGRF sound ID.
SoundEntry * AllocateSound(uint num)
Allocate sound slots.
Functions related to NewGRF provided sounds.
VehicleSoundEvent
Events at which a sound might be played.
Class related to random access to files.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
Functions related to sound.
static const uint ORIGINAL_SAMPLE_COUNT
The number of sounds in the original sample.cat.
Definition of base types and functions in a cross-platform compatible way.
SoundSettings sound
sound effect settings
uint16_t callback_mask
Bitmask of vehicle callbacks that have to be called.
Dynamic data of a loaded NewGRF.
uint8_t grf_container_ver
NewGRF container version if the sound is from a NewGRF.
bool vehicle
Play vehicle sound effects.
EngineID engine_type
The type of engine used for this vehicle.
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
Base class for all vehicles.