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

Method Load

src/soundloader_raw.cpp:25–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 static constexpr uint8_t RAW_SAMPLE_BITS = 8; ///< Bit depths of raw pcm samples.
24
25 bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) const override
26 {
27 /* Raw sounds are apecial case for the jackhammer sound (name in Windows sample.cat is "Corrupt sound")
28 * It's not a RIFF file, but raw PCM data.
29 * We no longer compare by name as the same file in the DOS sample.cat does not have a unique name. */
30
31 /* Raw sounds are not permitted in a new format file. */
32 if (new_format) return false;
33
34 sound.channels = 1;
35 sound.rate = RAW_SAMPLE_RATE;
36 sound.bits_per_sample = RAW_SAMPLE_BITS;
37
38 /* Allocate an extra sample to ensure the runtime resampler doesn't go out of bounds.*/
39 data.reserve(sound.file_size + 1);
40 data.resize(sound.file_size);
41 sound.file->ReadBlock(std::data(data), std::size(data));
42
43 /* Convert 8-bit samples from unsigned to signed. */
44 for (auto &sample : data) {
45 sample ^= std::byte{0x80};
46 }
47
48 return true;
49 }
50
51private:
52 static SoundLoader_Raw instance;

Callers

nothing calls this directly

Calls 5

reserveMethod · 0.80
resizeMethod · 0.80
ReadBlockMethod · 0.80
dataFunction · 0.50
sizeFunction · 0.50

Tested by

no test coverage detected