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

◆ compute_codewords()

static int32_t fl::third_party::vorbis::compute_codewords ( Codebook * c,
uint8 * len,
int32_t n,
uint32 * values )
static

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

817{
818 int32_t i,k,m=0;
819 uint32 available[32];
820
821 memset(available, 0, sizeof(available));
822 // find the first entry
823 for (k=0; k < n; ++k) if (len[k] < NO_CODE) break;
824 if (k == n) { FL_ASSERT(c->sorted_entries == 0, "sorted_entries must be 0"); return true; }
825 FL_ASSERT(len[k] < 32, "len must be < 32"); // no error return required, code reading lens checks this
826 // add to the list
827 add_entry(c, 0, k, m++, len[k], values);
828 // add all available leaves
829 for (i=1; i <= len[k]; ++i)
830 available[i] = 1U << (32-i);
831 // note that the above code treats the first case specially,
832 // but it's really the same as the following code, so they
833 // could probably be combined (except the initial code is 0,
834 // and I use 0 in available[] to mean 'empty')
835 for (i=k+1; i < n; ++i) {
836 uint32 res;
837 int32_t z = len[i], y;
838 if (z == NO_CODE) continue;
839 FL_ASSERT(z < 32, "z must be < 32"); // no error return required, code reading lens checks this
840 // find lowest available leaf (should always be earliest,
841 // which is what the specification calls for)
842 // note that this property, and the fact we can never have
843 // more than one free leaf at a given level, isn't totally
844 // trivial to prove, but it seems true and the assert never
845 // fires, so!
846 while (z > 0 && !available[z]) --z;
847 if (z == 0) { return false; }
848 res = available[z];
849 available[z] = 0;
850 add_entry(c, bit_reverse(res), i, m++, len[i], values);
851 // propagate availability up the tree
852 if (z != len[i]) {
853 for (y=len[i]; y > z; --y) {
854 FL_ASSERT(available[y] == 0, "available must be 0");
855 available[y] = res + (1 << (32-y));
856 }
857 }
858 }
859 return true;
860}
uint32_t z[NUM_LAYERS]
Definition Fire2023.h:93
#define FL_ASSERT(x, MSG)
Definition assert.h:6
static constexpr uint8_t NO_CODE
static void add_entry(Codebook *c, uint32 huff_code, int32_t symbol, int32_t count, int32_t len, uint32 *values) FL_NOEXCEPT
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
static uint32_t bit_reverse(uint32_t n) FL_NOEXCEPT
fl::i32 int32_t
Definition coder.h:220
int available()

References add_entry(), fl::available(), bit_reverse(), FL_ASSERT, FL_NOEXCEPT, memset(), NO_CODE, fl::y, and z.

Referenced by start_decoder().

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