30 static constexpr size_t MIN_OPUS_FILE_SIZE = 57U;
34 static constexpr size_t DECODE_BUFFER_SAMPLES = 5760 * 2;
35 static constexpr size_t DECODE_BUFFER_BYTES = DECODE_BUFFER_SAMPLES *
sizeof(opus_int16);
37 bool Load(
SoundEntry &sound,
bool new_format, std::vector<std::byte> &data)
override
39 if (!new_format)
return false;
42 if (sound.file_size < MIN_OPUS_FILE_SIZE)
return false;
45 auto filepos = sound.file->
GetPos();
46 std::vector<uint8_t> tmp(MIN_OPUS_FILE_SIZE);
47 sound.file->
ReadBlock(tmp.data(), tmp.size());
48 if (op_test(
nullptr, tmp.data(), tmp.size()) != 0)
return false;
51 tmp.resize(sound.file_size);
52 sound.file->
SeekTo(filepos, SEEK_SET);
53 sound.file->
ReadBlock(tmp.data(), tmp.size());
57 if (error != 0)
return false;
61 data.resize(datapos + DECODE_BUFFER_BYTES);
64 int read = op_read(of.get(),
reinterpret_cast<opus_int16 *
>(&data[datapos]), DECODE_BUFFER_BYTES, &link_index);
67 if (read < 0 || op_channel_count(of.get(), link_index) != 1) {
73 datapos += read *
sizeof(opus_int16);
82 data.resize(data.size() - DECODE_BUFFER_BYTES);