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

◆ compute_sorted_huffman()

static void fl::third_party::vorbis::compute_sorted_huffman ( Codebook * c,
uint8 * lengths,
uint32 * values )
static

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

904{
905 int32_t i, len;
906 // build a list of all the entries
907 // OPTIMIZATION: don't include the short ones, since they'll be caught by FAST_HUFFMAN.
908 // this is kind of a frivolous optimization--I don't see any performance improvement,
909 // but it's like 4 extra lines of code, so.
910 if (!c->sparse) {
911 int32_t k = 0;
912 for (i=0; i < c->entries; ++i)
913 if (include_in_sort(c, lengths[i]))
914 c->sorted_codewords[k++] = bit_reverse(c->codewords[i]);
915 FL_ASSERT(k == c->sorted_entries, "k must equal sorted_entries");
916 } else {
917 for (i=0; i < c->sorted_entries; ++i)
919 }
920
922 c->sorted_codewords[c->sorted_entries] = 0xffffffff;
923
924 len = c->sparse ? c->sorted_entries : c->entries;
925 // now we need to indicate how they correspond; we could either
926 // #1: sort a different data structure that says who they correspond to
927 // #2: for each sorted entry, search the original list to find who corresponds
928 // #3: for each original entry, find the sorted entry
929 // #1 requires extra storage, #2 is slow, #3 can use binary search!
930 for (i=0; i < len; ++i) {
931 int32_t huff_len = c->sparse ? lengths[values[i]] : lengths[i];
932 if (include_in_sort(c,huff_len)) {
933 uint32 code = bit_reverse(c->codewords[i]);
934 int32_t x=0, n=c->sorted_entries;
935 while (n > 1) {
936 // invariant: sc[x] <= code < sc[x+n]
937 int32_t m = x + (n >> 1);
938 if (c->sorted_codewords[m] <= code) {
939 x = m;
940 n -= (n>>1);
941 } else {
942 n >>= 1;
943 }
944 }
945 FL_ASSERT(c->sorted_codewords[x] == code, "sorted_codewords must match code");
946 if (c->sparse) {
947 c->sorted_values[x] = values[i];
948 c->codeword_lengths[x] = huff_len;
949 } else {
950 c->sorted_values[x] = i;
951 }
952 }
953 }
954}
constexpr int lengths[]
#define FL_ASSERT(x, MSG)
Definition assert.h:6
static int uint32_compare(const void *p, const void *q) FL_NOEXCEPT
static uint32_t bit_reverse(uint32_t n) FL_NOEXCEPT
static int32_t include_in_sort(Codebook *c, uint8 len) FL_NOEXCEPT
fl::i32 int32_t
Definition coder.h:220
void qsort(void *base, size_t nmemb, size_t size, qsort_compare_fn compar)
fl::i32 int32_t
Definition s16x16x4.h:220

References bit_reverse(), FL_ASSERT, FL_NOEXCEPT, include_in_sort(), lengths, fl::qsort(), uint32_compare(), and fl::x.

Referenced by start_decoder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: