| 1 | /******************************************************************** |
| 2 | * * |
| 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * |
| 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
| 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
| 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
| 7 | * * |
| 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015 * |
| 9 | * by the Xiph.Org Foundation https://xiph.org/ * |
| 10 | * * |
| 11 | ******************************************************************** |
| 12 | |
| 13 | function: basic codebook pack/unpack/code/decode operations |
| 14 | |
| 15 | ********************************************************************/ |
| 16 | |
| 17 | #include "ogg.h"cxx . . $ `<file>/external/vorbis/ogg.h`/ |
| 18 | #include "vorbis_codec.h"cxx . . $ `<file>/external/vorbis/vorbis_codec.h`/ |
| 19 | #include "vorbis_codebook.h"cxx . . $ `<file>/external/vorbis/vorbis_codebook.h`/ |
| 20 | #include "vorbis_scales.h"cxx . . $ `<file>/external/vorbis/vorbis_scales.h`/ |
| 21 | #include "vorbis_misc.h"cxx . . $ `<file>/external/vorbis/vorbis_misc.h`/ |
| 22 | #include "vorbis_os.h"cxx . . $ `<file>/external/vorbis/vorbis_os.h`/ |
| 23 | |
| 24 | /* packs the given codebook into the bitstream **************************/ |
| 25 | |
| 26 | int vorbis_staticbook_packcxx . . $ vorbis_staticbook_pack(c45c9a04add34572).(const static_codebookcxx . . $ static_codebook# *c,oggpack_buffercxx . . $ oggpack_buffer# *opb){ |
| 27 | long i,j; |
| 28 | int ordered=0; |
| 29 | |
| 30 | /* first the basic parameters */ |
| 31 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,0x564342,24); |
| 32 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->dimcxx . . $ static_codebook#dim.,16); |
| 33 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->entriescxx . . $ static_codebook#entries.,24); |
| 34 | |
| 35 | /* pack the codewords. There are two packings; length ordered and |
| 36 | length random. Decide between the two now. */ |
| 37 | |
| 38 | for(i=1;i<c->entriescxx . . $ static_codebook#entries.;i++) |
| 39 | if(c->lengthlistcxx . . $ static_codebook#lengthlist.[i-1]==0 || c->lengthlistcxx . . $ static_codebook#lengthlist.[i]<c->lengthlistcxx . . $ static_codebook#lengthlist.[i-1])break; |
| 40 | if(i==c->entriescxx . . $ static_codebook#entries.)ordered=1; |
| 41 | |
| 42 | if(ordered){ |
| 43 | /* length ordered. We only need to say how many codewords of |
| 44 | each length. The actual codewords are generated |
| 45 | deterministically */ |
| 46 | |
| 47 | long count=0; |
| 48 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,1,1); /* ordered */ |
| 49 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->lengthlistcxx . . $ static_codebook#lengthlist.[0]-1,5); /* 1 to 32 */ |
| 50 | |
| 51 | for(i=1;i<c->entriescxx . . $ static_codebook#entries.;i++){ |
| 52 | char thiss=c->lengthlistcxx . . $ static_codebook#lengthlist.[i]; |
| 53 | char last=c->lengthlistcxx . . $ static_codebook#lengthlist.[i-1]; |
| 54 | if(thiss>last){ |
| 55 | for(j=last;j<thiss;j++){ |
| 56 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,i-count,ov_ilogcxx . . $ ov_ilog(4c679297bf94b9eb).(c->entriescxx . . $ static_codebook#entries.-count)); |
| 57 | count=i; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,i-count,ov_ilogcxx . . $ ov_ilog(4c679297bf94b9eb).(c->entriescxx . . $ static_codebook#entries.-count)); |
| 62 | |
| 63 | }else{ |
| 64 | /* length random. Again, we don't code the codeword itself, just |
| 65 | the length. This time, though, we have to encode each length */ |
| 66 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,0,1); /* unordered */ |
| 67 | |
| 68 | /* algortihmic mapping has use for 'unused entries', which we tag |
| 69 | here. The algorithmic mapping happens as usual, but the unused |
| 70 | entry has no codeword. */ |
| 71 | for(i=0;i<c->entriescxx . . $ static_codebook#entries.;i++) |
| 72 | if(c->lengthlistcxx . . $ static_codebook#lengthlist.[i]==0)break; |
| 73 | |
| 74 | if(i==c->entriescxx . . $ static_codebook#entries.){ |
| 75 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,0,1); /* no unused entries */ |
| 76 | for(i=0;i<c->entriescxx . . $ static_codebook#entries.;i++) |
| 77 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->lengthlistcxx . . $ static_codebook#lengthlist.[i]-1,5); |
| 78 | }else{ |
| 79 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,1,1); /* we have unused entries; thus we tag */ |
| 80 | for(i=0;i<c->entriescxx . . $ static_codebook#entries.;i++){ |
| 81 | if(c->lengthlistcxx . . $ static_codebook#lengthlist.[i]==0){ |
| 82 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,0,1); |
| 83 | }else{ |
| 84 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,1,1); |
| 85 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->lengthlistcxx . . $ static_codebook#lengthlist.[i]-1,5); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /* is the entry number the desired return value, or do we have a |
| 92 | mapping? If we have a mapping, what type? */ |
| 93 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->maptypecxx . . $ static_codebook#maptype.,4); |
| 94 | switch(c->maptypecxx . . $ static_codebook#maptype.){ |
| 95 | case 0: |
| 96 | /* no mapping */ |
| 97 | break; |
| 98 | case 1:case 2: |
| 99 | /* implicitly populated value mapping */ |
| 100 | /* explicitly populated value mapping */ |
| 101 | |
| 102 | if(!c->quantlistcxx . . $ static_codebook#quantlist.){ |
| 103 | /* no quantlist? error */ |
| 104 | return(-1); |
| 105 | } |
| 106 | |
| 107 | /* values that define the dequantization */ |
| 108 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->q_mincxx . . $ static_codebook#q_min.,32); |
| 109 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->q_deltacxx . . $ static_codebook#q_delta.,32); |
| 110 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->q_quantcxx . . $ static_codebook#q_quant.-1,4); |
| 111 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,c->q_sequencepcxx . . $ static_codebook#q_sequencep.,1); |
| 112 | |
| 113 | { |
| 114 | int quantvals; |
| 115 | switch(c->maptypecxx . . $ static_codebook#maptype.){ |
| 116 | case 1: |
| 117 | /* a single column of (c->entries/c->dim) quantized values for |
| 118 | building a full value list algorithmically (square lattice) */ |
| 119 | quantvals=_book_maptype1_quantvalscxx . . $ _book_maptype1_quantvals(daa85381bb179800).(c); |
| 120 | break; |
| 121 | case 2: |
| 122 | /* every value (c->entries*c->dim total) specified explicitly */ |
| 123 | quantvals=c->entriescxx . . $ static_codebook#entries.*c->dimcxx . . $ static_codebook#dim.; |
| 124 | break; |
| 125 | default: /* NOT_REACHABLE */ |
| 126 | quantvals=-1; |
| 127 | } |
| 128 | |
| 129 | /* quantized values */ |
| 130 | for(i=0;i<quantvals;i++) |
| 131 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,labscxx . . $ labs(27d244100e426cb3).(c->quantlistcxx . . $ static_codebook#quantlist.[i]),c->q_quantcxx . . $ static_codebook#q_quant.); |
| 132 | |
| 133 | } |
| 134 | break; |
| 135 | default: |
| 136 | /* error case; we don't have any other map types now */ |
| 137 | return(-1); |
| 138 | } |
| 139 | |
| 140 | return(0); |
| 141 | } |
| 142 | |
| 143 | /* unpacks a codebook from the packet buffer into the codebook struct, |
| 144 | readies the codebook auxiliary structures for decode *************/ |
| 145 | static_codebookcxx . . $ static_codebook# *vorbis_staticbook_unpackcxx . . $ vorbis_staticbook_unpack(5de40fe896400830).(oggpack_buffercxx . . $ oggpack_buffer# *opb){ |
| 146 | long i,j; |
| 147 | static_codebookcxx . . $ static_codebook# *s = (static_codebookcxx . . $ static_codebook# *) _Melder_calloccxx . . $ _Melder_calloc(d58a73cf1dc24cbb).(1,sizeof(*s)); |
| 148 | s->allocedpcxx . . $ static_codebook#allocedp.=1; |
| 149 | |
| 150 | /* make sure alignment is correct */ |
| 151 | if(oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,24)!=0x564342)goto _eofout; |
| 152 | |
| 153 | /* first the basic parameters */ |
| 154 | s->dimcxx . . $ static_codebook#dim.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,16); |
| 155 | s->entriescxx . . $ static_codebook#entries.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,24); |
| 156 | if(s->entriescxx . . $ static_codebook#entries.==-1)goto _eofout; |
| 157 | |
| 158 | if(ov_ilogcxx . . $ ov_ilog(4c679297bf94b9eb).(s->dimcxx . . $ static_codebook#dim.)+ov_ilogcxx . . $ ov_ilog(4c679297bf94b9eb).(s->entriescxx . . $ static_codebook#entries.)>24)goto _eofout; |
| 159 | |
| 160 | /* codeword ordering.... length ordered or unordered? */ |
| 161 | switch((int)oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,1)){ |
| 162 | case 0:{ |
| 163 | long unused; |
| 164 | /* allocated but unused entries? */ |
| 165 | unused=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,1); |
| 166 | if((s->entriescxx . . $ static_codebook#entries.*(unused?1:5)+7)>>3>opb->storagecxx . . $ $anonymous_type_d401cdaf801be98c_1#storage.-oggpack_bytescxx . . $ oggpack_bytes(ced507c9175a1bd4).(opb)) |
| 167 | goto _eofout; |
| 168 | /* unordered */ |
| 169 | s->lengthlistcxx . . $ static_codebook#lengthlist. = (char *) _Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(sizeof(*s->lengthlistcxx . . $ static_codebook#lengthlist.)*s->entriescxx . . $ static_codebook#entries.); |
| 170 | |
| 171 | /* allocated but unused entries? */ |
| 172 | if(unused){ |
| 173 | /* yes, unused entries */ |
| 174 | |
| 175 | for(i=0;i<s->entriescxx . . $ static_codebook#entries.;i++){ |
| 176 | if(oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,1)){ |
| 177 | long num=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,5); |
| 178 | if(num==-1)goto _eofout; |
| 179 | s->lengthlistcxx . . $ static_codebook#lengthlist.[i]=num+1; |
| 180 | }else |
| 181 | s->lengthlistcxx . . $ static_codebook#lengthlist.[i]=0; |
| 182 | } |
| 183 | }else{ |
| 184 | /* all entries used; no tagging */ |
| 185 | for(i=0;i<s->entriescxx . . $ static_codebook#entries.;i++){ |
| 186 | long num=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,5); |
| 187 | if(num==-1)goto _eofout; |
| 188 | s->lengthlistcxx . . $ static_codebook#lengthlist.[i]=num+1; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | break; |
| 193 | } |
| 194 | case 1: |
| 195 | /* ordered */ |
| 196 | { |
| 197 | long length=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,5)+1; |
| 198 | if(length==0)goto _eofout; |
| 199 | s->lengthlistcxx . . $ static_codebook#lengthlist. = (char *) _Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(sizeof(*s->lengthlistcxx . . $ static_codebook#lengthlist.)*s->entriescxx . . $ static_codebook#entries.); |
| 200 | |
| 201 | for(i=0;i<s->entriescxx . . $ static_codebook#entries.;){ |
| 202 | long num=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,ov_ilogcxx . . $ ov_ilog(4c679297bf94b9eb).(s->entriescxx . . $ static_codebook#entries.-i)); |
| 203 | if(num==-1)goto _eofout; |
| 204 | if(length>32 || num>s->entriescxx . . $ static_codebook#entries.-i || |
| 205 | (num>0 && (num-1)>>(length-1)>1)){ |
| 206 | goto _errout; |
| 207 | } |
| 208 | if(length>32)goto _errout; |
| 209 | for(j=0;j<num;j++,i++) |
| 210 | s->lengthlistcxx . . $ static_codebook#lengthlist.[i]=length; |
| 211 | length++; |
| 212 | } |
| 213 | } |
| 214 | break; |
| 215 | default: |
| 216 | /* EOF */ |
| 217 | goto _eofout; |
| 218 | } |
| 219 | |
| 220 | /* Do we have a mapping to unpack? */ |
| 221 | switch((s->maptypecxx . . $ static_codebook#maptype.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,4))){ |
| 222 | case 0: |
| 223 | /* no mapping */ |
| 224 | break; |
| 225 | case 1: case 2: |
| 226 | /* implicitly populated value mapping */ |
| 227 | /* explicitly populated value mapping */ |
| 228 | |
| 229 | s->q_mincxx . . $ static_codebook#q_min.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,32); |
| 230 | s->q_deltacxx . . $ static_codebook#q_delta.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,32); |
| 231 | s->q_quantcxx . . $ static_codebook#q_quant.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,4)+1; |
| 232 | s->q_sequencepcxx . . $ static_codebook#q_sequencep.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,1); |
| 233 | if(s->q_sequencepcxx . . $ static_codebook#q_sequencep.==-1)goto _eofout; |
| 234 | |
| 235 | { |
| 236 | int quantvals=0; |
| 237 | switch(s->maptypecxx . . $ static_codebook#maptype.){ |
| 238 | case 1: |
| 239 | quantvals=(s->dimcxx . . $ static_codebook#dim.==0?0:_book_maptype1_quantvalscxx . . $ _book_maptype1_quantvals(daa85381bb179800).(s)); |
| 240 | break; |
| 241 | case 2: |
| 242 | quantvals=s->entriescxx . . $ static_codebook#entries.*s->dimcxx . . $ static_codebook#dim.; |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | /* quantized values */ |
| 247 | if(((quantvals*s->q_quantcxx . . $ static_codebook#q_quant.+7)>>3)>opb->storagecxx . . $ $anonymous_type_d401cdaf801be98c_1#storage.-oggpack_bytescxx . . $ oggpack_bytes(ced507c9175a1bd4).(opb)) |
| 248 | goto _eofout; |
| 249 | s->quantlistcxx . . $ static_codebook#quantlist.= (long *) _Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(sizeof(*s->quantlistcxx . . $ static_codebook#quantlist.)*quantvals); |
| 250 | for(i=0;i<quantvals;i++) |
| 251 | s->quantlistcxx . . $ static_codebook#quantlist.[i]=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,s->q_quantcxx . . $ static_codebook#q_quant.); |
| 252 | |
| 253 | if(quantvals&&s->quantlistcxx . . $ static_codebook#quantlist.[quantvals-1]==-1)goto _eofout; |
| 254 | } |
| 255 | break; |
| 256 | default: |
| 257 | goto _errout; |
| 258 | } |
| 259 | |
| 260 | /* all set */ |
| 261 | return(s); |
| 262 | |
| 263 | _errout: |
| 264 | _eofout: |
| 265 | vorbis_staticbook_destroycxx . . $ vorbis_staticbook_destroy(50dc96045c2ba69d).(s); |
| 266 | return(nullptr); |
| 267 | } |
| 268 | |
| 269 | /* returns the number of bits ************************************************/ |
| 270 | int vorbis_book_encodecxx . . $ vorbis_book_encode(270409cc35b9118c).(codebookcxx . . $ codebook# *book, int a, oggpack_buffercxx . . $ oggpack_buffer# *b){ |
| 271 | if(a<0 || a>=book->ccxx . . $ codebook#c.->entriescxx . . $ static_codebook#entries.)return(0); |
| 272 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(b,book->codelistcxx . . $ codebook#codelist.[a],book->ccxx . . $ codebook#c.->lengthlistcxx . . $ static_codebook#lengthlist.[a]); |
| 273 | return(book->ccxx . . $ codebook#c.->lengthlistcxx . . $ static_codebook#lengthlist.[a]); |
| 274 | } |
| 275 | |
| 276 | /* the 'eliminate the decode tree' optimization actually requires the |
| 277 | codewords to be MSb first, not LSb. This is an annoying inelegancy |
| 278 | (and one of the first places where carefully thought out design |
| 279 | turned out to be wrong; Vorbis II and future Ogg codecs should go |
| 280 | to an MSb bitpacker), but not actually the huge hit it appears to |
| 281 | be. The first-stage decode table catches most words so that |
| 282 | bitreverse is not in the main execution path. */ |
| 283 | |
| 284 | static ogg_uint32_tcxx . . $ ogg_uint32_t# bitreversecxx . . $ bitreverse(2141b656ce2cc063).(ogg_uint32_tcxx . . $ ogg_uint32_t# x){ |
| 285 | x= ((x>>16)&0x0000ffff) | ((x<<16)&0xffff0000); |
| 286 | x= ((x>> 8)&0x00ff00ff) | ((x<< 8)&0xff00ff00); |
| 287 | x= ((x>> 4)&0x0f0f0f0f) | ((x<< 4)&0xf0f0f0f0); |
| 288 | x= ((x>> 2)&0x33333333) | ((x<< 2)&0xcccccccc); |
| 289 | return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa); |
| 290 | } |
| 291 | |
| 292 | inline long decode_packed_entry_numbercxx . . $ decode_packed_entry_number(c6017aa1fb295037).(codebookcxx . . $ codebook# *book, oggpack_buffercxx . . $ oggpack_buffer# *b){ |
| 293 | int read=book->dec_maxlengthcxx . . $ codebook#dec_maxlength.; |
| 294 | long lo,hi; |
| 295 | long lok = oggpack_lookcxx . . $ oggpack_look(e96bf1ebf62076a2).(b,book->dec_firsttablencxx . . $ codebook#dec_firsttablen.); |
| 296 | |
| 297 | if (lok >= 0) { |
| 298 | long entry = book->dec_firsttablecxx . . $ codebook#dec_firsttable.[lok]; |
| 299 | if(entry&0x80000000UL){ |
| 300 | lo=(entry>>15)&0x7fff; |
| 301 | hi=book->used_entriescxx . . $ codebook#used_entries.-(entry&0x7fff); |
| 302 | }else{ |
| 303 | oggpack_advcxx . . $ oggpack_adv(25543af10c6676a5).(b, book->dec_codelengthscxx . . $ codebook#dec_codelengths.[entry-1]); |
| 304 | return(entry-1); |
| 305 | } |
| 306 | }else{ |
| 307 | lo=0; |
| 308 | hi=book->used_entriescxx . . $ codebook#used_entries.; |
| 309 | } |
| 310 | |
| 311 | /* Single entry codebooks use a firsttablen of 1 and a |
| 312 | dec_maxlength of 1. If a single-entry codebook gets here (due to |
| 313 | failure to read one bit above), the next look attempt will also |
| 314 | fail and we'll correctly kick out instead of trying to walk the |
| 315 | underformed tree */ |
| 316 | |
| 317 | lok = oggpack_lookcxx . . $ oggpack_look(e96bf1ebf62076a2).(b, read); |
| 318 | |
| 319 | while(lok<0 && read>1) |
| 320 | lok = oggpack_lookcxx . . $ oggpack_look(e96bf1ebf62076a2).(b, --read); |
| 321 | if(lok<0)return -1; |
| 322 | |
| 323 | /* bisect search for the codeword in the ordered list */ |
| 324 | { |
| 325 | ogg_uint32_tcxx . . $ ogg_uint32_t# testword=bitreversecxx . . $ bitreverse(2141b656ce2cc063).((ogg_uint32_tcxx . . $ ogg_uint32_t#)lok); |
| 326 | |
| 327 | while(hi-lo>1){ |
| 328 | long p=(hi-lo)>>1; |
| 329 | long test=book->codelistcxx . . $ codebook#codelist.[lo+p]>testword; |
| 330 | lo+=p&(test-1); |
| 331 | hi-=p&(-test); |
| 332 | } |
| 333 | |
| 334 | if(book->dec_codelengthscxx . . $ codebook#dec_codelengths.[lo]<=read){ |
| 335 | oggpack_advcxx . . $ oggpack_adv(25543af10c6676a5).(b, book->dec_codelengthscxx . . $ codebook#dec_codelengths.[lo]); |
| 336 | return(lo); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | oggpack_advcxx . . $ oggpack_adv(25543af10c6676a5).(b, read); |
| 341 | |
| 342 | return(-1); |
| 343 | } |
| 344 | |
| 345 | /* Decode side is specced and easier, because we don't need to find |
| 346 | matches using different criteria; we simply read and map. There are |
| 347 | two things we need to do 'depending': |
| 348 | |
| 349 | We may need to support interleave. We don't really, but it's |
| 350 | convenient to do it here rather than rebuild the vector later. |
| 351 | |
| 352 | Cascades may be additive or multiplicitive; this is not inherent in |
| 353 | the codebook, but set in the code using the codebook. Like |
| 354 | interleaving, it's easiest to do it here. |
| 355 | addmul==0 -> declarative (set the value) |
| 356 | addmul==1 -> additive |
| 357 | addmul==2 -> multiplicitive */ |
| 358 | |
| 359 | /* returns the [original, not compacted] entry number or -1 on eof *********/ |
| 360 | long vorbis_book_decodecxx . . $ vorbis_book_decode(c6017aa1fb295037).(codebookcxx . . $ codebook# *book, oggpack_buffercxx . . $ oggpack_buffer# *b){ |
| 361 | if(book->used_entriescxx . . $ codebook#used_entries.>0){ |
| 362 | long packed_entry=decode_packed_entry_numbercxx . . $ decode_packed_entry_number(c6017aa1fb295037).(book,b); |
| 363 | if(packed_entry>=0) |
| 364 | return(book->dec_indexcxx . . $ codebook#dec_index.[packed_entry]); |
| 365 | } |
| 366 | |
| 367 | /* if there's no dec_index, the codebook unpacking isn't collapsed */ |
| 368 | return(-1); |
| 369 | } |
| 370 | |
| 371 | /* returns 0 on OK or -1 on eof *************************************/ |
| 372 | /* decode vector / dim granularity gaurding is done in the upper layer */ |
| 373 | long vorbis_book_decodevs_addcxx . . $ vorbis_book_decodevs_add(809189a4d39ab48a).(codebookcxx . . $ codebook# *book,float *a,oggpack_buffercxx . . $ oggpack_buffer# *b,int n){ |
| 374 | if(book->used_entriescxx . . $ codebook#used_entries.>0){ |
| 375 | int step=n/book->dimcxx . . $ codebook#dim.; |
| 376 | long *entry = (long *) allocacxx . . $ `<external>/11612401604547820122/alloca.h:35:10`!(sizeof(*entry)*step); |
| 377 | float **t = (float **) allocacxx . . $ `<external>/11612401604547820122/alloca.h:35:10`!(sizeof(*t)*step); |
| 378 | int i,j,o; |
| 379 | |
| 380 | for (i = 0; i < step; i++) { |
| 381 | entry[i]=decode_packed_entry_numbercxx . . $ decode_packed_entry_number(c6017aa1fb295037).(book,b); |
| 382 | if(entry[i]==-1)return(-1); |
| 383 | t[i] = book->valuelistcxx . . $ codebook#valuelist.+entry[i]*book->dimcxx . . $ codebook#dim.; |
| 384 | } |
| 385 | for(i=0,o=0;i<book->dimcxx . . $ codebook#dim.;i++,o+=step) |
| 386 | for (j=0;o+j<n && j<step;j++) |
| 387 | a[o+j]+=t[j][i]; |
| 388 | } |
| 389 | return(0); |
| 390 | } |
| 391 | |
| 392 | /* decode vector / dim granularity gaurding is done in the upper layer */ |
| 393 | long vorbis_book_decodev_addcxx . . $ vorbis_book_decodev_add(809189a4d39ab48a).(codebookcxx . . $ codebook# *book,float *a,oggpack_buffercxx . . $ oggpack_buffer# *b,int n){ |
| 394 | if(book->used_entriescxx . . $ codebook#used_entries.>0){ |
| 395 | int i,j,entry; |
| 396 | float *t; |
| 397 | |
| 398 | for(i=0;i<n;){ |
| 399 | entry = decode_packed_entry_numbercxx . . $ decode_packed_entry_number(c6017aa1fb295037).(book,b); |
| 400 | if(entry==-1)return(-1); |
| 401 | t = book->valuelistcxx . . $ codebook#valuelist.+entry*book->dimcxx . . $ codebook#dim.; |
| 402 | for(j=0;i<n && j<book->dimcxx . . $ codebook#dim.;) |
| 403 | a[i++]+=t[j++]; |
| 404 | } |
| 405 | } |
| 406 | return(0); |
| 407 | } |
| 408 | |
| 409 | /* unlike the others, we guard against n not being an integer number |
| 410 | of <dim> internally rather than in the upper layer (called only by |
| 411 | floor0) */ |
| 412 | long vorbis_book_decodev_setcxx . . $ vorbis_book_decodev_set(809189a4d39ab48a).(codebookcxx . . $ codebook# *book,float *a,oggpack_buffercxx . . $ oggpack_buffer# *b,int n){ |
| 413 | if(book->used_entriescxx . . $ codebook#used_entries.>0){ |
| 414 | int i,j,entry; |
| 415 | float *t; |
| 416 | |
| 417 | for(i=0;i<n;){ |
| 418 | entry = decode_packed_entry_numbercxx . . $ decode_packed_entry_number(c6017aa1fb295037).(book,b); |
| 419 | if(entry==-1)return(-1); |
| 420 | t = book->valuelistcxx . . $ codebook#valuelist.+entry*book->dimcxx . . $ codebook#dim.; |
| 421 | for (j=0;i<n && j<book->dimcxx . . $ codebook#dim.;){ |
| 422 | a[i++]=t[j++]; |
| 423 | } |
| 424 | } |
| 425 | }else{ |
| 426 | int i; |
| 427 | |
| 428 | for(i=0;i<n;){ |
| 429 | a[i++]=0.f; |
| 430 | } |
| 431 | } |
| 432 | return(0); |
| 433 | } |
| 434 | |
| 435 | long vorbis_book_decodevv_addcxx . . $ vorbis_book_decodevv_add(d0d93024db625415).(codebookcxx . . $ codebook# *book,float **a,long offset,int ch, |
| 436 | oggpack_buffercxx . . $ oggpack_buffer# *b,int n){ |
| 437 | |
| 438 | long i,j,entry; |
| 439 | int chptr=0; |
| 440 | if(book->used_entriescxx . . $ codebook#used_entries.>0){ |
| 441 | int m=(offset+n)/ch; |
| 442 | for(i=offset/ch;i<m;){ |
| 443 | entry = decode_packed_entry_numbercxx . . $ decode_packed_entry_number(c6017aa1fb295037).(book,b); |
| 444 | if(entry==-1)return(-1); |
| 445 | { |
| 446 | const float *t = book->valuelistcxx . . $ codebook#valuelist.+entry*book->dimcxx . . $ codebook#dim.; |
| 447 | for (j=0;i<m && j<book->dimcxx . . $ codebook#dim.;j++){ |
| 448 | a[chptr++][i]+=t[j]; |
| 449 | if(chptr==ch){ |
| 450 | chptr=0; |
| 451 | i++; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | return(0); |
| 458 | } |