| 1 | /******************************************************************** |
| 2 | * * |
| 3 | * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * |
| 4 | * * |
| 5 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
| 6 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
| 7 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
| 8 | * * |
| 9 | * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * |
| 10 | * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * |
| 11 | * * |
| 12 | ******************************************************************** |
| 13 | |
| 14 | function: basic shared codebook operations |
| 15 | |
| 16 | ********************************************************************/ |
| 17 | |
| 18 | #include <stdlib.h> |
| 19 | #include <math.h> |
| 20 | #include <string.h> |
| 21 | #include "ogg.h"cxx . . $ `<file>/mednafen/tremor/ogg.h`/ |
| 22 | #include "misc.h"cxx . . $ `<file>/mednafen/tremor/misc.h`/ |
| 23 | #include "ivorbiscodec.h"cxx . . $ `<file>/mednafen/tremor/ivorbiscodec.h`/ |
| 24 | #include "codebook.h"cxx . . $ `<file>/mednafen/tremor/codebook.h`/ |
| 25 | |
| 26 | /**** pack/unpack helpers ******************************************/ |
| 27 | int _ilogcxx . . $ _ilog(4c679297bf94b9eb).(unsigned int v){ |
| 28 | int ret=0; |
| 29 | while(v){ |
| 30 | ret++; |
| 31 | v>>=1; |
| 32 | } |
| 33 | return(ret); |
| 34 | } |
| 35 | |
| 36 | /* 32 bit float (not IEEE; nonnormalized mantissa + |
| 37 | biased exponent) : neeeeeee eeemmmmm mmmmmmmm mmmmmmmm |
| 38 | Why not IEEE? It's just not that important here. */ |
| 39 | |
| 40 | #define VQ_FEXPcxx . . $ `mednafen/tremor/sharedbook.c:40:9`! 10 |
| 41 | #define VQ_FMANcxx . . $ `mednafen/tremor/sharedbook.c:41:9`! 21 |
| 42 | #define VQ_FEXP_BIAScxx . . $ `mednafen/tremor/sharedbook.c:42:9`! 768 /* bias toward values smaller than 1. */ |
| 43 | |
| 44 | static ogg_int32_tcxx . . $ ogg_int32_t# _float32_unpackcxx . . $ _float32_unpack(a4d7d21d93db71ec).(long val,int *point){ |
| 45 | long mant=val&0x1fffff; |
| 46 | int sign=val&0x80000000; |
| 47 | long exp =(val&0x7fe00000L)>>VQ_FMANcxx . . $ `mednafen/tremor/sharedbook.c:41:9`!; |
| 48 | |
| 49 | exp-=(VQ_FMANcxx . . $ `mednafen/tremor/sharedbook.c:41:9`!-1)+VQ_FEXP_BIAScxx . . $ `mednafen/tremor/sharedbook.c:42:9`!; |
| 50 | |
| 51 | if(mant){ |
| 52 | while(!(mant&0x40000000)){ |
| 53 | mant<<=1; |
| 54 | exp-=1; |
| 55 | } |
| 56 | |
| 57 | if(sign)mant= -mant; |
| 58 | }else{ |
| 59 | sign=0; |
| 60 | exp=-9999; |
| 61 | } |
| 62 | |
| 63 | *point=exp; |
| 64 | return mant; |
| 65 | } |
| 66 | |
| 67 | /* given a list of word lengths, generate a list of codewords. Works |
| 68 | for length ordered or unordered, always assigns the lowest valued |
| 69 | codewords first. Extended to handle unused entries (length 0) */ |
| 70 | ogg_uint32_tcxx . . $ ogg_uint32_t# *_make_wordscxx . . $ _make_words(31954b37aecd0963).(long *l,long n,long sparsecount){ |
| 71 | long i,j,count=0; |
| 72 | ogg_uint32_tcxx . . $ ogg_uint32_t# marker[33]; |
| 73 | ogg_uint32_tcxx . . $ ogg_uint32_t# *r=(ogg_uint32_tcxx . . $ ogg_uint32_t# *)_ogg_malloccxx . . $ `mednafen/tremor/os_types.h:22:9`!((sparsecount?sparsecount:n)*sizeof(*r)); |
| 74 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(marker,0,sizeof(marker)); |
| 75 | |
| 76 | for(i=0;i<n;i++){ |
| 77 | long length=l[i]; |
| 78 | if(length>0){ |
| 79 | ogg_uint32_tcxx . . $ ogg_uint32_t# entry=marker[length]; |
| 80 | |
| 81 | /* when we claim a node for an entry, we also claim the nodes |
| 82 | below it (pruning off the imagined tree that may have dangled |
| 83 | from it) as well as blocking the use of any nodes directly |
| 84 | above for leaves */ |
| 85 | |
| 86 | /* update ourself */ |
| 87 | if(length<32 && (entry>>length)){ |
| 88 | /* error condition; the lengths must specify an overpopulated tree */ |
| 89 | _ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(r); |
| 90 | return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 91 | } |
| 92 | r[count++]=entry; |
| 93 | |
| 94 | /* Look to see if the next shorter marker points to the node |
| 95 | above. if so, update it and repeat. */ |
| 96 | { |
| 97 | for(j=length;j>0;j--){ |
| 98 | |
| 99 | if(marker[j]&1){ |
| 100 | /* have to jump branches */ |
| 101 | if(j==1) |
| 102 | marker[1]++; |
| 103 | else |
| 104 | marker[j]=marker[j-1]<<1; |
| 105 | break; /* invariant says next upper marker would already |
| 106 | have been moved if it was on the same path */ |
| 107 | } |
| 108 | marker[j]++; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /* prune the tree; the implicit invariant says all the longer |
| 113 | markers were dangling from our just-taken node. Dangle them |
| 114 | from our *new* node. */ |
| 115 | for(j=length+1;j<33;j++) |
| 116 | if((marker[j]>>1) == entry){ |
| 117 | entry=marker[j]; |
| 118 | marker[j]=marker[j-1]<<1; |
| 119 | }else |
| 120 | break; |
| 121 | }else |
| 122 | if(sparsecount==0)count++; |
| 123 | } |
| 124 | |
| 125 | /* sanity check the huffman tree; an underpopulated tree must be |
| 126 | rejected. The only exception is the one-node pseudo-nil tree, |
| 127 | which appears to be underpopulated because the tree doesn't |
| 128 | really exist; there's only one possible 'codeword' or zero bits, |
| 129 | but the above tree-gen code doesn't mark that. */ |
| 130 | if(sparsecount != 1){ |
| 131 | for(i=1;i<33;i++) |
| 132 | if(marker[i] & (0xffffffffUL>>(32-i))){ |
| 133 | _ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(r); |
| 134 | return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /* bitreverse the words because our bitwise packer/unpacker is LSb |
| 139 | endian */ |
| 140 | for(i=0,count=0;i<n;i++){ |
| 141 | ogg_uint32_tcxx . . $ ogg_uint32_t# temp=0; |
| 142 | for(j=0;j<l[i];j++){ |
| 143 | temp<<=1; |
| 144 | temp|=(r[count]>>j)&1; |
| 145 | } |
| 146 | |
| 147 | if(sparsecount){ |
| 148 | if(l[i]) |
| 149 | r[count++]=temp; |
| 150 | }else |
| 151 | r[count++]=temp; |
| 152 | } |
| 153 | |
| 154 | return(r); |
| 155 | } |
| 156 | |
| 157 | /* there might be a straightforward one-line way to do the below |
| 158 | that's portable and totally safe against roundoff, but I haven't |
| 159 | thought of it. Therefore, we opt on the side of caution */ |
| 160 | long _book_maptype1_quantvalscxx . . $ _book_maptype1_quantvals(daa85381bb179800).(const static_codebookcxx . . $ static_codebook# *b){ |
| 161 | /* get us a starting hint, we'll polish it below */ |
| 162 | int bits=_ilogcxx . . $ _ilog(4c679297bf94b9eb).(b->entriescxx . . $ static_codebook#entries.); |
| 163 | int vals=b->entriescxx . . $ static_codebook#entries.>>((bits-1)*(b->dimcxx . . $ static_codebook#dim.-1)/b->dimcxx . . $ static_codebook#dim.); |
| 164 | |
| 165 | while(1){ |
| 166 | long acc=1; |
| 167 | long acc1=1; |
| 168 | int i; |
| 169 | for(i=0;i<b->dimcxx . . $ static_codebook#dim.;i++){ |
| 170 | acc*=vals; |
| 171 | acc1*=vals+1; |
| 172 | } |
| 173 | if(acc<=b->entriescxx . . $ static_codebook#entries. && acc1>b->entriescxx . . $ static_codebook#entries.){ |
| 174 | return(vals); |
| 175 | }else{ |
| 176 | if(acc>b->entriescxx . . $ static_codebook#entries.){ |
| 177 | vals--; |
| 178 | }else{ |
| 179 | vals++; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* different than what _book_unquantize does for mainline: |
| 186 | we repack the book in a fixed point format that shares the same |
| 187 | binary point. Upon first use, we can shift point if needed */ |
| 188 | |
| 189 | /* we need to deal with two map types: in map type 1, the values are |
| 190 | generated algorithmically (each column of the vector counts through |
| 191 | the values in the quant vector). in map type 2, all the values came |
| 192 | in in an explicit list. Both value lists must be unpacked */ |
| 193 | |
| 194 | ogg_int32_tcxx . . $ ogg_int32_t# *_book_unquantizecxx . . $ _book_unquantize(3b3309500f4045eb).(const static_codebookcxx . . $ static_codebook# *b,int n,int *sparsemap, |
| 195 | int *maxpoint){ |
| 196 | long j,k,count=0; |
| 197 | if(b->maptypecxx . . $ static_codebook#maptype.==1 || b->maptypecxx . . $ static_codebook#maptype.==2){ |
| 198 | int quantvals; |
| 199 | int minpoint,delpoint; |
| 200 | ogg_int32_tcxx . . $ ogg_int32_t# mindel=_float32_unpackcxx . . $ _float32_unpack(a4d7d21d93db71ec).(b->q_mincxx . . $ static_codebook#q_min.,&minpoint); |
| 201 | ogg_int32_tcxx . . $ ogg_int32_t# delta=_float32_unpackcxx . . $ _float32_unpack(a4d7d21d93db71ec).(b->q_deltacxx . . $ static_codebook#q_delta.,&delpoint); |
| 202 | ogg_int32_tcxx . . $ ogg_int32_t# *r=(ogg_int32_tcxx . . $ ogg_int32_t# *)_ogg_calloccxx . . $ `mednafen/tremor/os_types.h:23:9`!(n*b->dimcxx . . $ static_codebook#dim.,sizeof(*r)); |
| 203 | int *rp=(int *)_ogg_calloccxx . . $ `mednafen/tremor/os_types.h:23:9`!(n*b->dimcxx . . $ static_codebook#dim.,sizeof(*rp)); |
| 204 | |
| 205 | *maxpoint=minpoint; |
| 206 | |
| 207 | /* maptype 1 and 2 both use a quantized value vector, but |
| 208 | different sizes */ |
| 209 | switch(b->maptypecxx . . $ static_codebook#maptype.){ |
| 210 | case 1: |
| 211 | /* most of the time, entries%dimensions == 0, but we need to be |
| 212 | well defined. We define that the possible vales at each |
| 213 | scalar is values == entries/dim. If entries%dim != 0, we'll |
| 214 | have 'too few' values (values*dim<entries), which means that |
| 215 | we'll have 'left over' entries; left over entries use zeroed |
| 216 | values (and are wasted). So don't generate codebooks like |
| 217 | that */ |
| 218 | quantvals=_book_maptype1_quantvalscxx . . $ _book_maptype1_quantvals(daa85381bb179800).(b); |
| 219 | for(j=0;j<b->entriescxx . . $ static_codebook#entries.;j++){ |
| 220 | if((sparsemap && b->lengthlistcxx . . $ static_codebook#lengthlist.[j]) || !sparsemap){ |
| 221 | ogg_int32_tcxx . . $ ogg_int32_t# last=0; |
| 222 | int lastpoint=0; |
| 223 | int indexdiv=1; |
| 224 | for(k=0;k<b->dimcxx . . $ static_codebook#dim.;k++){ |
| 225 | int index= (j/indexdiv)%quantvals; |
| 226 | int point=0; |
| 227 | int val=VFLOAT_MULTIcxx . . $ VFLOAT_MULTI(669e4832ed6c1c49).(delta,delpoint, |
| 228 | abscxx . . $ abs(7864480464b09eea).(b->quantlistcxx . . $ static_codebook#quantlist.[index]),&point); |
| 229 | |
| 230 | val=VFLOAT_ADDcxx . . $ VFLOAT_ADD(241650a5e574c3b0).(mindel,minpoint,val,point,&point); |
| 231 | val=VFLOAT_ADDcxx . . $ VFLOAT_ADD(241650a5e574c3b0).(last,lastpoint,val,point,&point); |
| 232 | |
| 233 | if(b->q_sequencepcxx . . $ static_codebook#q_sequencep.){ |
| 234 | last=val; |
| 235 | lastpoint=point; |
| 236 | } |
| 237 | |
| 238 | if(sparsemap){ |
| 239 | r[sparsemap[count]*b->dimcxx . . $ static_codebook#dim.+k]=val; |
| 240 | rp[sparsemap[count]*b->dimcxx . . $ static_codebook#dim.+k]=point; |
| 241 | }else{ |
| 242 | r[count*b->dimcxx . . $ static_codebook#dim.+k]=val; |
| 243 | rp[count*b->dimcxx . . $ static_codebook#dim.+k]=point; |
| 244 | } |
| 245 | if(*maxpoint<point)*maxpoint=point; |
| 246 | indexdiv*=quantvals; |
| 247 | } |
| 248 | count++; |
| 249 | } |
| 250 | |
| 251 | } |
| 252 | break; |
| 253 | case 2: |
| 254 | for(j=0;j<b->entriescxx . . $ static_codebook#entries.;j++){ |
| 255 | if((sparsemap && b->lengthlistcxx . . $ static_codebook#lengthlist.[j]) || !sparsemap){ |
| 256 | ogg_int32_tcxx . . $ ogg_int32_t# last=0; |
| 257 | int lastpoint=0; |
| 258 | |
| 259 | for(k=0;k<b->dimcxx . . $ static_codebook#dim.;k++){ |
| 260 | int point=0; |
| 261 | int val=VFLOAT_MULTIcxx . . $ VFLOAT_MULTI(669e4832ed6c1c49).(delta,delpoint, |
| 262 | abscxx . . $ abs(7864480464b09eea).(b->quantlistcxx . . $ static_codebook#quantlist.[j*b->dimcxx . . $ static_codebook#dim.+k]),&point); |
| 263 | |
| 264 | val=VFLOAT_ADDcxx . . $ VFLOAT_ADD(241650a5e574c3b0).(mindel,minpoint,val,point,&point); |
| 265 | val=VFLOAT_ADDcxx . . $ VFLOAT_ADD(241650a5e574c3b0).(last,lastpoint,val,point,&point); |
| 266 | |
| 267 | if(b->q_sequencepcxx . . $ static_codebook#q_sequencep.){ |
| 268 | last=val; |
| 269 | lastpoint=point; |
| 270 | } |
| 271 | |
| 272 | if(sparsemap){ |
| 273 | r[sparsemap[count]*b->dimcxx . . $ static_codebook#dim.+k]=val; |
| 274 | rp[sparsemap[count]*b->dimcxx . . $ static_codebook#dim.+k]=point; |
| 275 | }else{ |
| 276 | r[count*b->dimcxx . . $ static_codebook#dim.+k]=val; |
| 277 | rp[count*b->dimcxx . . $ static_codebook#dim.+k]=point; |
| 278 | } |
| 279 | if(*maxpoint<point)*maxpoint=point; |
| 280 | } |
| 281 | count++; |
| 282 | } |
| 283 | } |
| 284 | break; |
| 285 | } |
| 286 | |
| 287 | for(j=0;j<n*b->dimcxx . . $ static_codebook#dim.;j++) |
| 288 | if(rp[j]<*maxpoint) |
| 289 | r[j]>>=*maxpoint-rp[j]; |
| 290 | |
| 291 | _ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(rp); |
| 292 | return(r); |
| 293 | } |
| 294 | return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 295 | } |
| 296 | |
| 297 | void vorbis_staticbook_destroycxx . . $ vorbis_staticbook_destroy(50dc96045c2ba69d).(static_codebookcxx . . $ static_codebook# *b){ |
| 298 | if(b->quantlistcxx . . $ static_codebook#quantlist.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b->quantlistcxx . . $ static_codebook#quantlist.); |
| 299 | if(b->lengthlistcxx . . $ static_codebook#lengthlist.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b->lengthlistcxx . . $ static_codebook#lengthlist.); |
| 300 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(b,0,sizeof(*b)); |
| 301 | _ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b); |
| 302 | } |
| 303 | |
| 304 | void vorbis_book_clearcxx . . $ vorbis_book_clear(947fb228bbaa529d).(codebookcxx . . $ codebook# *b){ |
| 305 | /* static book is not cleared; we're likely called on the lookup and |
| 306 | the static codebook belongs to the info struct */ |
| 307 | if(b->valuelistcxx . . $ codebook#valuelist.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b->valuelistcxx . . $ codebook#valuelist.); |
| 308 | if(b->codelistcxx . . $ codebook#codelist.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b->codelistcxx . . $ codebook#codelist.); |
| 309 | |
| 310 | if(b->dec_indexcxx . . $ codebook#dec_index.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b->dec_indexcxx . . $ codebook#dec_index.); |
| 311 | if(b->dec_codelengthscxx . . $ codebook#dec_codelengths.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b->dec_codelengthscxx . . $ codebook#dec_codelengths.); |
| 312 | if(b->dec_firsttablecxx . . $ codebook#dec_firsttable.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b->dec_firsttablecxx . . $ codebook#dec_firsttable.); |
| 313 | |
| 314 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(b,0,sizeof(*b)); |
| 315 | } |
| 316 | |
| 317 | static ogg_uint32_tcxx . . $ ogg_uint32_t# bitreversecxx . . $ bitreverse(2141b656ce2cc063).(ogg_uint32_tcxx . . $ ogg_uint32_t# x){ |
| 318 | x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL); |
| 319 | x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL); |
| 320 | x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL); |
| 321 | x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL); |
| 322 | return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL); |
| 323 | } |
| 324 | |
| 325 | static int sort32acxx . . $ sort32a(9148c8c3ff42c9d8).(const void *a,const void *b){ |
| 326 | return (**(ogg_uint32_tcxx . . $ ogg_uint32_t# **)a>**(ogg_uint32_tcxx . . $ ogg_uint32_t# **)b)- |
| 327 | (**(ogg_uint32_tcxx . . $ ogg_uint32_t# **)a<**(ogg_uint32_tcxx . . $ ogg_uint32_t# **)b); |
| 328 | } |
| 329 | |
| 330 | /* decode codebook arrangement is more heavily optimized than encode */ |
| 331 | int vorbis_book_init_decodecxx . . $ vorbis_book_init_decode(cdfb7b438ddf71a0).(codebookcxx . . $ codebook# *c,const static_codebookcxx . . $ static_codebook# *s){ |
| 332 | int i,j,n=0,tabn; |
| 333 | int *sortindex; |
| 334 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(c,0,sizeof(*c)); |
| 335 | |
| 336 | /* count actually used entries */ |
| 337 | for(i=0;i<s->entriescxx . . $ static_codebook#entries.;i++) |
| 338 | if(s->lengthlistcxx . . $ static_codebook#lengthlist.[i]>0) |
| 339 | n++; |
| 340 | |
| 341 | c->entriescxx . . $ codebook#entries.=s->entriescxx . . $ static_codebook#entries.; |
| 342 | c->used_entriescxx . . $ codebook#used_entries.=n; |
| 343 | c->dimcxx . . $ codebook#dim.=s->dimcxx . . $ static_codebook#dim.; |
| 344 | |
| 345 | if(n>0){ |
| 346 | /* two different remappings go on here. |
| 347 | |
| 348 | First, we collapse the likely sparse codebook down only to |
| 349 | actually represented values/words. This collapsing needs to be |
| 350 | indexed as map-valueless books are used to encode original entry |
| 351 | positions as integers. |
| 352 | |
| 353 | Second, we reorder all vectors, including the entry index above, |
| 354 | by sorted bitreversed codeword to allow treeless decode. */ |
| 355 | |
| 356 | /* perform sort */ |
| 357 | ogg_uint32_tcxx . . $ ogg_uint32_t# *codes=_make_wordscxx . . $ _make_words(31954b37aecd0963).(s->lengthlistcxx . . $ static_codebook#lengthlist.,s->entriescxx . . $ static_codebook#entries.,c->used_entriescxx . . $ codebook#used_entries.); |
| 358 | ogg_uint32_tcxx . . $ ogg_uint32_t# **codep=(ogg_uint32_tcxx . . $ ogg_uint32_t# **)allocacxx . . $ `<external>/11612401604547820122/alloca.h:35:10`!(sizeof(*codep)*n); |
| 359 | |
| 360 | if(codes==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)goto err_out; |
| 361 | |
| 362 | for(i=0;i<n;i++){ |
| 363 | codes[i]=bitreversecxx . . $ bitreverse(2141b656ce2cc063).(codes[i]); |
| 364 | codep[i]=codes+i; |
| 365 | } |
| 366 | |
| 367 | qsortcxx . . $ qsort(ebb60b13a65e77d7).(codep,n,sizeof(*codep),sort32acxx . . $ sort32a(9148c8c3ff42c9d8).); |
| 368 | |
| 369 | sortindex=(int *)allocacxx . . $ `<external>/11612401604547820122/alloca.h:35:10`!(n*sizeof(*sortindex)); |
| 370 | c->codelistcxx . . $ codebook#codelist.=(ogg_uint32_tcxx . . $ ogg_uint32_t# *)_ogg_malloccxx . . $ `mednafen/tremor/os_types.h:22:9`!(n*sizeof(*c->codelistcxx . . $ codebook#codelist.)); |
| 371 | /* the index is a reverse index */ |
| 372 | for(i=0;i<n;i++){ |
| 373 | int position=codep[i]-codes; |
| 374 | sortindex[position]=i; |
| 375 | } |
| 376 | |
| 377 | for(i=0;i<n;i++) |
| 378 | c->codelistcxx . . $ codebook#codelist.[sortindex[i]]=codes[i]; |
| 379 | _ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(codes); |
| 380 | |
| 381 | |
| 382 | |
| 383 | c->valuelistcxx . . $ codebook#valuelist.=_book_unquantizecxx . . $ _book_unquantize(3b3309500f4045eb).(s,n,sortindex,&c->binarypointcxx . . $ codebook#binarypoint.); |
| 384 | c->dec_indexcxx . . $ codebook#dec_index.=(int *)_ogg_malloccxx . . $ `mednafen/tremor/os_types.h:22:9`!(n*sizeof(*c->dec_indexcxx . . $ codebook#dec_index.)); |
| 385 | |
| 386 | for(n=0,i=0;i<s->entriescxx . . $ static_codebook#entries.;i++) |
| 387 | if(s->lengthlistcxx . . $ static_codebook#lengthlist.[i]>0) |
| 388 | c->dec_indexcxx . . $ codebook#dec_index.[sortindex[n++]]=i; |
| 389 | |
| 390 | c->dec_codelengthscxx . . $ codebook#dec_codelengths.=(char *)_ogg_malloccxx . . $ `mednafen/tremor/os_types.h:22:9`!(n*sizeof(*c->dec_codelengthscxx . . $ codebook#dec_codelengths.)); |
| 391 | for(n=0,i=0;i<s->entriescxx . . $ static_codebook#entries.;i++) |
| 392 | if(s->lengthlistcxx . . $ static_codebook#lengthlist.[i]>0) |
| 393 | c->dec_codelengthscxx . . $ codebook#dec_codelengths.[sortindex[n++]]=s->lengthlistcxx . . $ static_codebook#lengthlist.[i]; |
| 394 | |
| 395 | c->dec_firsttablencxx . . $ codebook#dec_firsttablen.=_ilogcxx . . $ _ilog(4c679297bf94b9eb).(c->used_entriescxx . . $ codebook#used_entries.)-4; /* this is magic */ |
| 396 | if(c->dec_firsttablencxx . . $ codebook#dec_firsttablen.<5)c->dec_firsttablencxx . . $ codebook#dec_firsttablen.=5; |
| 397 | if(c->dec_firsttablencxx . . $ codebook#dec_firsttablen.>8)c->dec_firsttablencxx . . $ codebook#dec_firsttablen.=8; |
| 398 | |
| 399 | tabn=1<<c->dec_firsttablencxx . . $ codebook#dec_firsttablen.; |
| 400 | c->dec_firsttablecxx . . $ codebook#dec_firsttable.=(ogg_uint32_tcxx . . $ ogg_uint32_t# *)_ogg_calloccxx . . $ `mednafen/tremor/os_types.h:23:9`!(tabn,sizeof(*c->dec_firsttablecxx . . $ codebook#dec_firsttable.)); |
| 401 | c->dec_maxlengthcxx . . $ codebook#dec_maxlength.=0; |
| 402 | |
| 403 | for(i=0;i<n;i++){ |
| 404 | if(c->dec_maxlengthcxx . . $ codebook#dec_maxlength.<c->dec_codelengthscxx . . $ codebook#dec_codelengths.[i]) |
| 405 | c->dec_maxlengthcxx . . $ codebook#dec_maxlength.=c->dec_codelengthscxx . . $ codebook#dec_codelengths.[i]; |
| 406 | if(c->dec_codelengthscxx . . $ codebook#dec_codelengths.[i]<=c->dec_firsttablencxx . . $ codebook#dec_firsttablen.){ |
| 407 | ogg_uint32_tcxx . . $ ogg_uint32_t# orig=bitreversecxx . . $ bitreverse(2141b656ce2cc063).(c->codelistcxx . . $ codebook#codelist.[i]); |
| 408 | for(j=0;j<(1<<(c->dec_firsttablencxx . . $ codebook#dec_firsttablen.-c->dec_codelengthscxx . . $ codebook#dec_codelengths.[i]));j++) |
| 409 | c->dec_firsttablecxx . . $ codebook#dec_firsttable.[orig|(j<<c->dec_codelengthscxx . . $ codebook#dec_codelengths.[i])]=i+1; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /* now fill in 'unused' entries in the firsttable with hi/lo search |
| 414 | hints for the non-direct-hits */ |
| 415 | { |
| 416 | ogg_uint32_tcxx . . $ ogg_uint32_t# mask=0xfffffffeUL<<(31-c->dec_firsttablencxx . . $ codebook#dec_firsttablen.); |
| 417 | long lo=0,hi=0; |
| 418 | |
| 419 | for(i=0;i<tabn;i++){ |
| 420 | ogg_uint32_tcxx . . $ ogg_uint32_t# word=i<<(32-c->dec_firsttablencxx . . $ codebook#dec_firsttablen.); |
| 421 | if(c->dec_firsttablecxx . . $ codebook#dec_firsttable.[bitreversecxx . . $ bitreverse(2141b656ce2cc063).(word)]==0){ |
| 422 | while((lo+1)<n && c->codelistcxx . . $ codebook#codelist.[lo+1]<=word)lo++; |
| 423 | while( hi<n && word>=(c->codelistcxx . . $ codebook#codelist.[hi]&mask))hi++; |
| 424 | |
| 425 | /* we only actually have 15 bits per hint to play with here. |
| 426 | In order to overflow gracefully (nothing breaks, efficiency |
| 427 | just drops), encode as the difference from the extremes. */ |
| 428 | { |
| 429 | unsigned long loval=lo; |
| 430 | unsigned long hival=n-hi; |
| 431 | |
| 432 | if(loval>0x7fff)loval=0x7fff; |
| 433 | if(hival>0x7fff)hival=0x7fff; |
| 434 | c->dec_firsttablecxx . . $ codebook#dec_firsttable.[bitreversecxx . . $ bitreverse(2141b656ce2cc063).(word)]= |
| 435 | 0x80000000UL | (loval<<15) | hival; |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | return(0); |
| 443 | err_out: |
| 444 | vorbis_book_clearcxx . . $ vorbis_book_clear(947fb228bbaa529d).(c); |
| 445 | return(-1); |
| 446 | } |
| 447 |