| 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 | |
| 51 | private: |
| 52 | static SoundLoader_Raw instance; |