24 static constexpr uint16_t DEFAULT_SAMPLE_RATE = 11025;
26 bool Load(
SoundEntry &sound,
bool new_format, std::vector<uint8_t> &data)
override
42 if (format != 1)
return false;
45 if (sound.channels != 1)
return false;
48 if (!new_format) sound.rate = DEFAULT_SAMPLE_RATE;
53 sound.bits_per_sample = file.
ReadWord();
54 if (sound.bits_per_sample != 8 && sound.bits_per_sample != 16)
return false;
58 }
else if (tag ==
BSWAP32(
'data')) {
59 uint align = sound.channels * sound.bits_per_sample / 8;
60 if (
Align(size, align) != size)
return false;
62 if (size == 0)
return true;
65 data.reserve(size + align);
70 switch (sound.bits_per_sample) {
73 for (
auto &sample : data) {
74 sample = sample - 128;
80 if constexpr (std::endian::native != std::endian::little) {
81 for (
auto it = std::begin(data); it != std::end(data); ) {
82 std::swap(*it++, *it++);
87 default: NOT_REACHED();
Functions related to bit mathematics.
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.
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).
Wav file (RIFF/WAVE) sound loader.
Base interface for a SoundLoader implementation.
constexpr T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Class related to random access to files.
A number of safeguards to prevent using unsafe methods.
Types related to sound loaders.
Definition of base types and functions in a cross-platform compatible way.