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

Function OpenBankFile

src/sound.cpp:27–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25static std::array<SoundEntry, ORIGINAL_SAMPLE_COUNT> _original_sounds;
26
27static void OpenBankFile(const std::string &filename)
28{
29 /**
30 * The sound file for the original sounds, i.e. those not defined/overridden by a NewGRF.
31 * Needs to be kept alive during the game as _original_sounds[n].file refers to this.
32 */
33 static std::unique_ptr<RandomAccessFile> original_sound_file;
34
35 _original_sounds.fill({});
36
37 /* If there is no sound file (nosound set), don't load anything */
38 if (filename.empty()) return;
39
40 original_sound_file = std::make_unique<RandomAccessFile>(filename, BASESET_DIR);
41 size_t pos = original_sound_file->GetPos();
42 uint count = original_sound_file->ReadDword();
43
44 /* The new format has the highest bit always set */
45 auto source = HasBit(count, 31) ? SoundSource::BasesetNewFormat : SoundSource::BasesetOldFormat;
46 ClrBit(count, 31);
47 count /= 8;
48
49 /* Simple check for the correct number of original sounds. */
50 if (count != ORIGINAL_SAMPLE_COUNT) {
51 /* Corrupt sample data? Just leave the allocated memory as those tell
52 * there is no sound to play (size = 0 due to calloc). Not allocating
53 * the memory disables valid NewGRFs that replace sounds. */
54 Debug(misc, 6, "Incorrect number of sounds in '{}', ignoring.", filename);
55 return;
56 }
57
58 original_sound_file->SeekTo(pos, SEEK_SET);
59
60 /* Read sound file positions. */
61 for (auto &sound : _original_sounds) {
62 sound.file = original_sound_file.get();
63 sound.file_offset = GB(original_sound_file->ReadDword(), 0, 31) + pos;
64 sound.file_size = original_sound_file->ReadDword();
65 sound.source = source;
66 }
67}
68
69static bool SetBankSource(MixerChannel *mc, SoundEntry *sound, SoundID sound_id)
70{

Callers 1

InitializeSoundFunction · 0.85

Calls 9

HasBitFunction · 0.85
ClrBitFunction · 0.85
GBFunction · 0.85
fillMethod · 0.80
GetPosMethod · 0.80
ReadDwordMethod · 0.80
SeekToMethod · 0.80
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected