OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
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_slot == 0)
return false;
83 char *name =
AllocaM(
char, name_len + 1);
87 if (name[name_len] != 0) {
88 DEBUG(grf, 2,
"LoadNewGRFSound [%s]: Name not properly terminated",
FioGetFilename(sound->file_slot));
92 DEBUG(grf, 2,
"LoadNewGRFSound [%s]: Sound name '%s'...",
FioGetFilename(sound->file_slot), name);
95 DEBUG(grf, 1,
"LoadNewGRFSound [%s]: Missing RIFF header",
FioGetFilename(sound->file_slot));
100 uint header_size = 11;
102 if (total_size + name_len + header_size > num) {
103 DEBUG(grf, 1,
"LoadNewGRFSound [%s]: RIFF was truncated",
FioGetFilename(sound->file_slot));
108 DEBUG(grf, 1,
"LoadNewGRFSound [%s]: Invalid RIFF type",
FioGetFilename(sound->file_slot));
112 while (total_size >= 8) {
116 if (total_size < size) {
126 DEBUG(grf, 1,
"LoadGRFSound [%s]: Invalid audio format",
FioGetFilename(sound->file_slot));
140 sound->file_size = size;
143 DEBUG(grf, 2,
"LoadNewGRFSound [%s]: channels %u, sample rate %u, bits per sample %u, length %u",
FioGetFilename(sound->file_slot), sound->channels, sound->rate, sound->bits_per_sample, size);
155 DEBUG(grf, 1,
"LoadNewGRFSound [%s]: RIFF does not contain any sound data",
FioGetFilename(sound->file_slot));
174 if (file ==
nullptr || sound_id >= file->num_sounds)
return INVALID_SOUND;
176 return file->sound_offset + sound_id;
193 if (file ==
nullptr)
return false;
205 if (callback == INVALID_SOUND)
return true;
207 assert(callback < GetNumSounds());
208 SndPlayVehicleFx(callback, v);
221 if (sound_id == INVALID_SOUND)
return;
223 assert(sound_id < GetNumSounds());
224 SndPlayTileFx(sound_id, tile);
SoundEntry * AllocateSound(uint num)
Allocate sound slots.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
Checks whether a NewGRF wants to play a different vehicle sound effect.
uint32 TileIndex
The index/ID of a Tile.
void FioReadBlock(void *ptr, size_t size)
Read a block.
uint16 FioReadWord()
Read a word (16 bits) from the file (in low endian format).
@ CBM_VEHICLE_SOUND_EFFECT
Vehicle uses custom sound effects.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
ClientSettings _settings_client
The current settings for this game.
SoundID GetNewGRFSoundID(const GRFFile *file, SoundID sound_id)
Resolve NewGRF sound ID.
byte grf_container_ver
NewGRF container version if the sound is from a NewGRF.
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
uint32 FioReadDword()
Read a double word (32 bits) from the file (in low endian format).
void FioSkipBytes(int n)
Skip n bytes ahead in the file.
bool LoadNewGRFSound(SoundEntry *sound)
Extract meta data from a NewGRF sound.
void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
Play a NewGRF sound effect at the location of a specific tile.
SoundSettings sound
sound effect settings
@ CBID_VEHICLE_SOUND_EFFECT
Called to play a special sound effect.
#define DEBUG(name, level,...)
Output a line of debugging information.
EngineID engine_type
The type of engine used for this vehicle.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
size_t FioGetPos()
Get position in the current file.
byte FioReadByte()
Read a byte from the file.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
bool vehicle
Play vehicle sound effects.
static const uint ORIGINAL_SAMPLE_COUNT
The number of sounds in the original sample.cat.
VehicleSoundEvent
Events at which a sound might be played.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
void FioSeekToFile(uint8 slot, size_t pos)
Switch to a different file and seek to a position.
Dynamic data of a loaded NewGRF.
const char * FioGetFilename(uint8 slot)
Get the filename associated with a slot.
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro