14 std::span<const std::byte>
bytes,
15 std::size_t
offset)
noexcept
18 static_cast<std::uint16_t
>(
20 static_cast<std::uint16_t
>(
21 std::to_integer<std::uint8_t>(
bytes[
offset + 1]) << 8U);
26 std::span<const std::byte>
bytes,
27 std::size_t
offset)
noexcept
30 static_cast<std::uint32_t
>(
32 (
static_cast<std::uint32_t
>(
33 std::to_integer<std::uint8_t>(
bytes[
offset + 1])) << 8U) |
34 (
static_cast<std::uint32_t
>(
35 std::to_integer<std::uint8_t>(
bytes[
offset + 2])) << 16U) |
36 (
static_cast<std::uint32_t
>(
37 std::to_integer<std::uint8_t>(
bytes[
offset + 3])) << 24U);
42 std::span<const std::byte>
bytes,
44 char a,
char b,
char c,
char d)
noexcept
65 if (
bytes.size() < 12 ||
70 const std::uint64_t
end64 =
74 const auto end =
static_cast<std::size_t
>(
end64);
81 const auto payload =
cursor + 8;
83 static_cast<std::uint64_t
>(payload) + size;
89 result.formatOffset = payload;
90 result.formatSize =
size;
94 result.dataOffset = payload;
95 result.dataSize =
size;
114 if (
cursor != end || result.formatSize == 0 || result.dataSize == 0)
120 [[
nodiscard]] std::expected<DecodedWave, std::string>
122 std::span<const std::byte>
bytes,
125 if (
chunks.formatSize < 20)
126 return std::unexpected(
127 "GSM 6.10 WAVE fmt chunk is shorter than WAVEFORMATEX");
131 return std::unexpected(
"WAVE is not Microsoft GSM 6.10");
142 sampleRate >
static_cast<std::uint32_t
>(
143 std::numeric_limits<int>::max()) ||
145 bitsPerSample != 0 ||
149 return std::unexpected(
150 "unsupported Microsoft GSM 6.10 WAVE format");
153 return std::unexpected(
154 "GSM 6.10 WAVE data is not block aligned");
157 reinterpret_cast<const std::uint8_t*
>(
159 const std::span<const std::uint8_t>
encoded{
163 voicechat::gsm610::Decoder decoder;
164 auto pcm = decoder.decodeToU8(
encoded);
166 return std::unexpected(pcm.error());
172 static_cast<int>(sampleRate)};
173 result.pcm.assign(pcm->begin(), pcm->end());
178 [[
nodiscard]] std::expected<DecodedWave, std::string>
184 return std::unexpected(
192 return std::unexpected(
199 if (result.pcm.empty())
200 return std::unexpected(
201 "decoded WAVE contains no PCM samples");
207 std::expected<DecodedWave, std::string>
212 chunks->formatSize >= 2 &&
std::vector< std::byte > bytes
std::expected< DecodedWave, std::string > decodeWave(std::span< const std::byte > bytes)
constexpr std::uint16_t SamplesPerBlock
constexpr std::uint16_t FormatTag
constexpr std::uint16_t BlockAlign
constexpr std::uint32_t fourCC(char a, char b, char c, char d) noexcept