Files
JustOneCacophony/src/foundation/bit_reader.cpp
T
TheM14 6f6b5db6c2
ci / ubuntu-latest (push) Failing after 15s
ci / macos-latest (push) Has been cancelled
ci / windows-latest (push) Has been cancelled
Add JOC downmix configurations 0..4, cross-layer notes, and the analysis-side clipgain
2026-10-16 19:52:04 +08:00

31 lines
889 B
C++

#include "foundation/bit_reader.h"
namespace joc::bits {
bool variable_bits(BitReader& reader, unsigned width, unsigned max_groups, std::uint32_t* out_value) {
std::uint32_t value = 0;
for (unsigned group = 0; group < max_groups; ++group) {
value += reader.read(width);
if (reader.failed()) {
return false;
}
const std::uint32_t more = reader.read(1);
if (reader.failed()) {
return false;
}
if (more == 0u) {
if (out_value != nullptr) {
*out_value = value;
}
return true;
}
value = (value + 1u) << width;
}
// An extension chain that never terminates is a syntax error, not a
// truncation.
reader.fail(JOC_ERR_EMDF_SYNTAX, "variable_bits extension groups exceeded");
return false;
}
} // namespace joc::bits