FastLED 3.9.15
Loading...
Searching...
No Matches

◆ codebook_decode_scalar_raw()

static int32_t fl::third_party::vorbis::codebook_decode_scalar_raw ( vorb * f,
Codebook * c )
static

Definition at line 1384 of file stb_vorbis.cpp.hpp.

1385{
1386 int32_t i;
1387 prep_huffman(f);
1388
1389 if (c->codewords == nullptr && c->sorted_codewords == nullptr)
1390 return -1;
1391
1392 // cases to use binary search: sorted_codewords && !c->codewords
1393 // sorted_codewords && c->entries > 8
1394 if (c->entries > 8 ? c->sorted_codewords!=nullptr : !c->codewords) {
1395 // binary search
1396 uint32 code = bit_reverse(f->acc);
1397 int32_t x=0, n=c->sorted_entries, len;
1398
1399 while (n > 1) {
1400 // invariant: sc[x] <= code < sc[x+n]
1401 int32_t m = x + (n >> 1);
1402 if (c->sorted_codewords[m] <= code) {
1403 x = m;
1404 n -= (n>>1);
1405 } else {
1406 n >>= 1;
1407 }
1408 }
1409 // x is now the sorted index
1410 if (!c->sparse) x = c->sorted_values[x];
1411 // x is now sorted index if sparse, or symbol otherwise
1412 len = c->codeword_lengths[x];
1413 if (f->valid_bits >= len) {
1414 f->acc >>= len;
1415 f->valid_bits -= len;
1416 return x;
1417 }
1418
1419 f->valid_bits = 0;
1420 return -1;
1421 }
1422
1423 // if small, linear search
1424 FL_ASSERT(!c->sparse, "codebook must not be sparse");
1425 for (i=0; i < c->entries; ++i) {
1426 if (c->codeword_lengths[i] == NO_CODE) continue;
1427 if (c->codewords[i] == (f->acc & ((1 << c->codeword_lengths[i])-1))) {
1428 if (f->valid_bits >= c->codeword_lengths[i]) {
1429 f->acc >>= c->codeword_lengths[i];
1430 f->valid_bits -= c->codeword_lengths[i];
1431 return i;
1432 }
1433 f->valid_bits = 0;
1434 return -1;
1435 }
1436 }
1437
1439 f->valid_bits = 0;
1440 return -1;
1441}
int x
Definition simple.h:92
#define FL_ASSERT(x, MSG)
Definition assert.h:6
static int32_t error(vorb *f, enum STBVorbisError e) FL_NOEXCEPT
static constexpr uint8_t NO_CODE
static uint32_t bit_reverse(uint32_t n) FL_NOEXCEPT
FL_ALWAYS_INLINE void prep_huffman(vorb *f) FL_NOEXCEPT
fl::i32 int32_t
Definition coder.h:220

References bit_reverse(), error(), FL_ASSERT, FL_NOEXCEPT, NO_CODE, prep_huffman(), VORBIS_invalid_stream, and fl::x.

+ Here is the call graph for this function: