| 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-2010 * |
| 9 | * by the Xiph.Org Foundation https://xiph.org/ * |
| 10 | * * |
| 11 | ******************************************************************** |
| 12 | |
| 13 | function: residue backend 0, 1 and 2 implementation |
| 14 | |
| 15 | ********************************************************************/ |
| 16 | |
| 17 | /* Slow, slow, slow, simpleminded and did I mention it was slow? The |
| 18 | encode/decode loops are coded for clarity and performance is not |
| 19 | yet even a nagging little idea lurking in the shadows. Oh and BTW, |
| 20 | it's slow. */ |
| 21 | |
| 22 | #include "ogg.h"cxx . . $ `<file>/external/vorbis/ogg.h`/ |
| 23 | #include "vorbis_codec.h"cxx . . $ `<file>/external/vorbis/vorbis_codec.h`/ |
| 24 | #include "vorbis_codec_internal.h"cxx . . $ `<file>/external/vorbis/vorbis_codec_internal.h`/ |
| 25 | #include "vorbis_registry.h"cxx . . $ `<file>/external/vorbis/vorbis_registry.h`/ |
| 26 | #include "vorbis_codebook.h"cxx . . $ `<file>/external/vorbis/vorbis_codebook.h`/ |
| 27 | #include "vorbis_misc.h"cxx . . $ `<file>/external/vorbis/vorbis_misc.h`/ |
| 28 | #include "vorbis_os.h"cxx . . $ `<file>/external/vorbis/vorbis_os.h`/ |
| 29 | |
| 30 | #if defined(TRAIN_RES) || defined (TRAIN_RESAUX) |
| 31 | #include <stdio.h> |
| 32 | #endif |
| 33 | |
| 34 | typedef structcxx . . $ $anonymous_type_fbc217f811b06792_0# { |
| 35 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *infocxx . . $ $anonymous_type_fbc217f811b06792_0#info.; |
| 36 | |
| 37 | int partscxx . . $ $anonymous_type_fbc217f811b06792_0#parts.; |
| 38 | int stagescxx . . $ $anonymous_type_fbc217f811b06792_0#stages.; |
| 39 | codebookcxx . . $ codebook# *fullbookscxx . . $ $anonymous_type_fbc217f811b06792_0#fullbooks.; |
| 40 | codebookcxx . . $ codebook# *phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.; |
| 41 | codebookcxx . . $ codebook# ***partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.; |
| 42 | |
| 43 | int partvalscxx . . $ $anonymous_type_fbc217f811b06792_0#partvals.; |
| 44 | int **decodemapcxx . . $ $anonymous_type_fbc217f811b06792_0#decodemap.; |
| 45 | |
| 46 | long postbitscxx . . $ $anonymous_type_fbc217f811b06792_0#postbits.; |
| 47 | long phrasebitscxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebits.; |
| 48 | long framescxx . . $ $anonymous_type_fbc217f811b06792_0#frames.; |
| 49 | |
| 50 | #if defined(TRAIN_RES) || defined(TRAIN_RESAUX) |
| 51 | int train_seq; |
| 52 | long *training_data[8][64]; |
| 53 | float training_max[8][64]; |
| 54 | float training_min[8][64]; |
| 55 | float tmin; |
| 56 | float tmax; |
| 57 | int submap; |
| 58 | #endif |
| 59 | |
| 60 | } vorbis_look_residue0cxx . . $ vorbis_look_residue0#; |
| 61 | |
| 62 | void res0_free_infocxx . . $ res0_free_info(5d22bdacc48458e8).(vorbis_info_residuecxx . . $ vorbis_info_residue# *i){ |
| 63 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *info=(vorbis_info_residue0cxx . . $ vorbis_info_residue0# *)i; |
| 64 | if(info){ |
| 65 | memset(info,0,sizeof(*info)); |
| 66 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(info); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void res0_free_lookcxx . . $ res0_free_look(5d22bdacc48458e8).(vorbis_look_residuecxx . . $ vorbis_look_residue# *i){ |
| 71 | int j; |
| 72 | if(i){ |
| 73 | |
| 74 | vorbis_look_residue0cxx . . $ vorbis_look_residue0# *look=(vorbis_look_residue0cxx . . $ vorbis_look_residue0# *)i; |
| 75 | |
| 76 | #ifdef TRAIN_RES |
| 77 | { |
| 78 | int j,k,l; |
| 79 | for(j=0;j<look->parts;j++){ |
| 80 | /*fprintf(stderr,"partition %d: ",j);*/ |
| 81 | for(k=0;k<8;k++) |
| 82 | if(look->training_data[k][j]){ |
| 83 | char buffer[80]; |
| 84 | FILE *of; |
| 85 | codebook *statebook=look->partbooks[j][k]; |
| 86 | |
| 87 | /* long and short into the same bucket by current convention */ |
| 88 | sprintf(buffer,"res_sub%d_part%d_pass%d.vqd",look->submap,j,k); |
| 89 | of=fopen(buffer,"a"); |
| 90 | |
| 91 | for(l=0;l<statebook->entries;l++) |
| 92 | fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]); |
| 93 | |
| 94 | fclose(of); |
| 95 | |
| 96 | /*fprintf(stderr,"%d(%.2f|%.2f) ",k, |
| 97 | look->training_min[k][j],look->training_max[k][j]);*/ |
| 98 | |
| 99 | _ogg_free(look->training_data[k][j]); |
| 100 | look->training_data[k][j]=nullptr; |
| 101 | } |
| 102 | /*fprintf(stderr,"\n");*/ |
| 103 | } |
| 104 | } |
| 105 | fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax); |
| 106 | |
| 107 | /*fprintf(stderr,"residue bit usage %f:%f (%f total)\n", |
| 108 | (float)look->phrasebits/look->frames, |
| 109 | (float)look->postbits/look->frames, |
| 110 | (float)(look->postbits+look->phrasebits)/look->frames);*/ |
| 111 | #endif |
| 112 | |
| 113 | |
| 114 | /*vorbis_info_residue0 *info=look->info; |
| 115 | |
| 116 | fprintf(stderr, |
| 117 | "%ld frames encoded in %ld phrasebits and %ld residue bits " |
| 118 | "(%g/frame) \n",look->frames,look->phrasebits, |
| 119 | look->resbitsflat, |
| 120 | (look->phrasebits+look->resbitsflat)/(float)look->frames); |
| 121 | |
| 122 | for(j=0;j<look->parts;j++){ |
| 123 | long acc=0; |
| 124 | fprintf(stderr,"\t[%d] == ",j); |
| 125 | for(k=0;k<look->stages;k++) |
| 126 | if((info->secondstages[j]>>k)&1){ |
| 127 | fprintf(stderr,"%ld,",look->resbits[j][k]); |
| 128 | acc+=look->resbits[j][k]; |
| 129 | } |
| 130 | |
| 131 | fprintf(stderr,":: (%ld vals) %1.2fbits/sample\n",look->resvals[j], |
| 132 | acc?(float)acc/(look->resvals[j]*info->grouping):0); |
| 133 | } |
| 134 | fprintf(stderr,"\n");*/ |
| 135 | |
| 136 | for(j=0;j<look->partscxx . . $ $anonymous_type_fbc217f811b06792_0#parts.;j++) |
| 137 | if(look->partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.[j])Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(look->partbooks[j]); |
| 138 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(look->partbooks); |
| 139 | for(j=0;j<look->partvalscxx . . $ $anonymous_type_fbc217f811b06792_0#partvals.;j++) |
| 140 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(look->decodemap[j]); |
| 141 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(look->decodemap); |
| 142 | |
| 143 | memset(look,0,sizeof(*look)); |
| 144 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(look); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | static int icountcxx . . $ icount(4c679297bf94b9eb).(unsigned int v){ |
| 149 | int ret=0; |
| 150 | while(v){ |
| 151 | ret+=v&1; |
| 152 | v>>=1; |
| 153 | } |
| 154 | return(ret); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | void res0_packcxx . . $ res0_pack(14051757f6862fa4).(vorbis_info_residuecxx . . $ vorbis_info_residue# *vr,oggpack_buffercxx . . $ oggpack_buffer# *opb){ |
| 159 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *info=(vorbis_info_residue0cxx . . $ vorbis_info_residue0# *)vr; |
| 160 | int j,acc=0; |
| 161 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,info->begincxx . . $ vorbis_info_residue0#begin.,24); |
| 162 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,info->endcxx . . $ vorbis_info_residue0#end.,24); |
| 163 | |
| 164 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,info->groupingcxx . . $ vorbis_info_residue0#grouping.-1,24); /* residue vectors to group and |
| 165 | code with a partitioned book */ |
| 166 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,info->partitionscxx . . $ vorbis_info_residue0#partitions.-1,6); /* possible partition choices */ |
| 167 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,info->groupbookcxx . . $ vorbis_info_residue0#groupbook.,8); /* group huffman book */ |
| 168 | |
| 169 | /* secondstages is a bitmask; as encoding progresses pass by pass, a |
| 170 | bitmask of one indicates this partition class has bits to write |
| 171 | this pass */ |
| 172 | for(j=0;j<info->partitionscxx . . $ vorbis_info_residue0#partitions.;j++){ |
| 173 | if(ov_ilogcxx . . $ ov_ilog(4c679297bf94b9eb).(info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[j])>3){ |
| 174 | /* yes, this is a minor hack due to not thinking ahead */ |
| 175 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[j],3); |
| 176 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,1,1); |
| 177 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[j]>>3,5); |
| 178 | }else |
| 179 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[j],4); /* trailing zero */ |
| 180 | acc+=icountcxx . . $ icount(4c679297bf94b9eb).(info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[j]); |
| 181 | } |
| 182 | for(j=0;j<acc;j++) |
| 183 | oggpack_writecxx . . $ oggpack_write(287f339ee0a6f63e).(opb,info->booklistcxx . . $ vorbis_info_residue0#booklist.[j],8); |
| 184 | |
| 185 | } |
| 186 | |
| 187 | /* vorbis_info is for range checking */ |
| 188 | vorbis_info_residuecxx . . $ vorbis_info_residue# *res0_unpackcxx . . $ res0_unpack(eeac8d4f838aca31).(vorbis_infocxx . . $ vorbis_info# *vi,oggpack_buffercxx . . $ oggpack_buffer# *opb){ |
| 189 | int j,acc=0; |
| 190 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *info = (vorbis_info_residue0cxx . . $ vorbis_info_residue0# *) _Melder_calloccxx . . $ _Melder_calloc(d58a73cf1dc24cbb).(1,sizeof(*info)); |
| 191 | codec_setup_infocxx . . $ codec_setup_info# *ci = (codec_setup_infocxx . . $ codec_setup_info# *) vi->codec_setupcxx . . $ vorbis_info#codec_setup.; |
| 192 | |
| 193 | info->begincxx . . $ vorbis_info_residue0#begin.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,24); |
| 194 | info->endcxx . . $ vorbis_info_residue0#end.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,24); |
| 195 | info->groupingcxx . . $ vorbis_info_residue0#grouping.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,24)+1; |
| 196 | info->partitionscxx . . $ vorbis_info_residue0#partitions.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,6)+1; |
| 197 | info->groupbookcxx . . $ vorbis_info_residue0#groupbook.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,8); |
| 198 | |
| 199 | /* check for premature EOP */ |
| 200 | if(info->groupbookcxx . . $ vorbis_info_residue0#groupbook.<0)goto errout; |
| 201 | |
| 202 | for(j=0;j<info->partitionscxx . . $ vorbis_info_residue0#partitions.;j++){ |
| 203 | int cascade=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,3); |
| 204 | int cflag=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,1); |
| 205 | if(cflag<0) goto errout; |
| 206 | if(cflag){ |
| 207 | int c=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,5); |
| 208 | if(c<0) goto errout; |
| 209 | cascade|=(c<<3); |
| 210 | } |
| 211 | info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[j]=cascade; |
| 212 | |
| 213 | acc+=icountcxx . . $ icount(4c679297bf94b9eb).(cascade); |
| 214 | } |
| 215 | for(j=0;j<acc;j++){ |
| 216 | int book=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,8); |
| 217 | if(book<0) goto errout; |
| 218 | info->booklistcxx . . $ vorbis_info_residue0#booklist.[j]=book; |
| 219 | } |
| 220 | |
| 221 | if(info->groupbookcxx . . $ vorbis_info_residue0#groupbook.>=ci->bookscxx . . $ codec_setup_info#books.)goto errout; |
| 222 | for(j=0;j<acc;j++){ |
| 223 | if(info->booklistcxx . . $ vorbis_info_residue0#booklist.[j]>=ci->bookscxx . . $ codec_setup_info#books.)goto errout; |
| 224 | if(ci->book_paramcxx . . $ codec_setup_info#book_param.[info->booklistcxx . . $ vorbis_info_residue0#booklist.[j]]->maptypecxx . . $ static_codebook#maptype.==0)goto errout; |
| 225 | } |
| 226 | |
| 227 | /* verify the phrasebook is not specifying an impossible or |
| 228 | inconsistent partitioning scheme. */ |
| 229 | /* modify the phrasebook ranging check from r16327; an early beta |
| 230 | encoder had a bug where it used an oversized phrasebook by |
| 231 | accident. These files should continue to be playable, but don't |
| 232 | allow an exploit */ |
| 233 | { |
| 234 | int entries = ci->book_paramcxx . . $ codec_setup_info#book_param.[info->groupbookcxx . . $ vorbis_info_residue0#groupbook.]->entriescxx . . $ static_codebook#entries.; |
| 235 | int dim = ci->book_paramcxx . . $ codec_setup_info#book_param.[info->groupbookcxx . . $ vorbis_info_residue0#groupbook.]->dimcxx . . $ static_codebook#dim.; |
| 236 | int partvals = 1; |
| 237 | if (dim<1) goto errout; |
| 238 | while(dim>0){ |
| 239 | partvals *= info->partitionscxx . . $ vorbis_info_residue0#partitions.; |
| 240 | if(partvals > entries) goto errout; |
| 241 | dim--; |
| 242 | } |
| 243 | info->partvalscxx . . $ vorbis_info_residue0#partvals. = partvals; |
| 244 | } |
| 245 | |
| 246 | return(info); |
| 247 | errout: |
| 248 | res0_free_infocxx . . $ res0_free_info(5d22bdacc48458e8).(info); |
| 249 | return(nullptr); |
| 250 | } |
| 251 | |
| 252 | vorbis_look_residuecxx . . $ vorbis_look_residue# *res0_lookcxx . . $ res0_look(f22d77a7569cfb00).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *vd, |
| 253 | vorbis_info_residuecxx . . $ vorbis_info_residue# *vr){ |
| 254 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *info=(vorbis_info_residue0cxx . . $ vorbis_info_residue0# *)vr; |
| 255 | vorbis_look_residue0cxx . . $ vorbis_look_residue0# *look= (vorbis_look_residue0cxx . . $ vorbis_look_residue0# *) _Melder_calloccxx . . $ _Melder_calloc(d58a73cf1dc24cbb).(1,sizeof(*look)); |
| 256 | codec_setup_infocxx . . $ codec_setup_info# *ci = (codec_setup_infocxx . . $ codec_setup_info# *) vd->vicxx . . $ vorbis_dsp_state#vi.->codec_setupcxx . . $ vorbis_info#codec_setup.; |
| 257 | |
| 258 | int j,k,acc=0; |
| 259 | int dim; |
| 260 | int maxstage=0; |
| 261 | look->infocxx . . $ $anonymous_type_fbc217f811b06792_0#info.=info; |
| 262 | |
| 263 | look->partscxx . . $ $anonymous_type_fbc217f811b06792_0#parts.=info->partitionscxx . . $ vorbis_info_residue0#partitions.; |
| 264 | look->fullbookscxx . . $ $anonymous_type_fbc217f811b06792_0#fullbooks.=ci->fullbookscxx . . $ codec_setup_info#fullbooks.; |
| 265 | look->phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.=ci->fullbookscxx . . $ codec_setup_info#fullbooks.+info->groupbookcxx . . $ vorbis_info_residue0#groupbook.; |
| 266 | dim=look->phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.->dimcxx . . $ codebook#dim.; |
| 267 | |
| 268 | look->partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.= (codebookcxx . . $ codebook# ***) _Melder_calloccxx . . $ _Melder_calloc(d58a73cf1dc24cbb).(look->partscxx . . $ $anonymous_type_fbc217f811b06792_0#parts.,sizeof(*look->partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.)); |
| 269 | |
| 270 | for(j=0;j<look->partscxx . . $ $anonymous_type_fbc217f811b06792_0#parts.;j++){ |
| 271 | int stages=ov_ilogcxx . . $ ov_ilog(4c679297bf94b9eb).(info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[j]); |
| 272 | if(stages){ |
| 273 | if(stages>maxstage)maxstage=stages; |
| 274 | look->partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.[j] = (codebookcxx . . $ codebook# **) _Melder_calloccxx . . $ _Melder_calloc(d58a73cf1dc24cbb).(stages,sizeof(*look->partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.[j])); |
| 275 | for(k=0;k<stages;k++) |
| 276 | if(info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[j]&(1<<k)){ |
| 277 | look->partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.[j][k]=ci->fullbookscxx . . $ codec_setup_info#fullbooks.+info->booklistcxx . . $ vorbis_info_residue0#booklist.[acc++]; |
| 278 | #ifdef TRAIN_RES |
| 279 | look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries, |
| 280 | sizeof(***look->training_data)); |
| 281 | #endif |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | look->partvalscxx . . $ $anonymous_type_fbc217f811b06792_0#partvals.=1; |
| 287 | for(j=0;j<dim;j++) |
| 288 | look->partvalscxx . . $ $anonymous_type_fbc217f811b06792_0#partvals.*=look->partscxx . . $ $anonymous_type_fbc217f811b06792_0#parts.; |
| 289 | |
| 290 | look->stagescxx . . $ $anonymous_type_fbc217f811b06792_0#stages.=maxstage; |
| 291 | look->decodemapcxx . . $ $anonymous_type_fbc217f811b06792_0#decodemap. = (int **) _Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(look->partvalscxx . . $ $anonymous_type_fbc217f811b06792_0#partvals.*sizeof(*look->decodemapcxx . . $ $anonymous_type_fbc217f811b06792_0#decodemap.)); |
| 292 | for(j=0;j<look->partvalscxx . . $ $anonymous_type_fbc217f811b06792_0#partvals.;j++){ |
| 293 | long val=j; |
| 294 | long mult=look->partvalscxx . . $ $anonymous_type_fbc217f811b06792_0#partvals./look->partscxx . . $ $anonymous_type_fbc217f811b06792_0#parts.; |
| 295 | look->decodemapcxx . . $ $anonymous_type_fbc217f811b06792_0#decodemap.[j] = (int *) _Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(dim*sizeof(*look->decodemapcxx . . $ $anonymous_type_fbc217f811b06792_0#decodemap.[j])); |
| 296 | for(k=0;k<dim;k++){ |
| 297 | long deco=val/mult; |
| 298 | val-=deco*mult; |
| 299 | mult/=look->partscxx . . $ $anonymous_type_fbc217f811b06792_0#parts.; |
| 300 | look->decodemapcxx . . $ $anonymous_type_fbc217f811b06792_0#decodemap.[j][k]=deco; |
| 301 | } |
| 302 | } |
| 303 | #if defined(TRAIN_RES) || defined (TRAIN_RESAUX) |
| 304 | { |
| 305 | static int train_seq=0; |
| 306 | look->train_seq=train_seq++; |
| 307 | } |
| 308 | #endif |
| 309 | return(look); |
| 310 | } |
| 311 | |
| 312 | /* break an abstraction and copy some code for performance purposes */ |
| 313 | static int local_book_besterrorcxx . . $ local_book_besterror(5f783d6d23a67b8e).(codebookcxx . . $ codebook# *book,int *a){ |
| 314 | int dim=book->dimcxx . . $ codebook#dim.; |
| 315 | int i,j,o; |
| 316 | int minval=book->minvalcxx . . $ codebook#minval.; |
| 317 | int del=book->deltacxx . . $ codebook#delta.; |
| 318 | int qv=book->quantvalscxx . . $ codebook#quantvals.; |
| 319 | int ze=(qv>>1); |
| 320 | int index=0; |
| 321 | /* assumes integer/centered encoder codebook maptype 1 no more than dim 8 */ |
| 322 | int p[8]={0,0,0,0,0,0,0,0}; |
| 323 | |
| 324 | if(del!=1){ |
| 325 | for(i=0,o=dim;i<dim;i++){ |
| 326 | int v = (a[--o]-minval+(del>>1))/del; |
| 327 | int m = (v<ze ? ((ze-v)<<1)-1 : ((v-ze)<<1)); |
| 328 | index = index*qv+ (m<0?0:(m>=qv?qv-1:m)); |
| 329 | p[o]=v*del+minval; |
| 330 | } |
| 331 | }else{ |
| 332 | for(i=0,o=dim;i<dim;i++){ |
| 333 | int v = a[--o]-minval; |
| 334 | int m = (v<ze ? ((ze-v)<<1)-1 : ((v-ze)<<1)); |
| 335 | index = index*qv+ (m<0?0:(m>=qv?qv-1:m)); |
| 336 | p[o]=v*del+minval; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | if(book->ccxx . . $ codebook#c.->lengthlistcxx . . $ static_codebook#lengthlist.[index]<=0){ |
| 341 | const static_codebookcxx . . $ static_codebook# *c=book->ccxx . . $ codebook#c.; |
| 342 | int best=-1; |
| 343 | /* assumes integer/centered encoder codebook maptype 1 no more than dim 8 */ |
| 344 | int e[8]={0,0,0,0,0,0,0,0}; |
| 345 | int maxval = book->minvalcxx . . $ codebook#minval. + book->deltacxx . . $ codebook#delta.*(book->quantvalscxx . . $ codebook#quantvals.-1); |
| 346 | for(i=0;i<book->entriescxx . . $ codebook#entries.;i++){ |
| 347 | if(c->lengthlistcxx . . $ static_codebook#lengthlist.[i]>0){ |
| 348 | int thiss=0; |
| 349 | for(j=0;j<dim;j++){ |
| 350 | int val=(e[j]-a[j]); |
| 351 | thiss+=val*val; |
| 352 | } |
| 353 | if(best==-1 || thiss<best){ |
| 354 | memcpy(p,e,sizeof(p)); |
| 355 | best=thiss; |
| 356 | index=i; |
| 357 | } |
| 358 | } |
| 359 | /* assumes the value patterning created by the tools in vq/ */ |
| 360 | j=0; |
| 361 | while(e[j]>=maxval) |
| 362 | e[j++]=0; |
| 363 | if(e[j]>=0) |
| 364 | e[j]+=book->deltacxx . . $ codebook#delta.; |
| 365 | e[j]= -e[j]; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | if(index>-1){ |
| 370 | for(i=0;i<dim;i++) |
| 371 | *a++ -= p[i]; |
| 372 | } |
| 373 | |
| 374 | return(index); |
| 375 | } |
| 376 | |
| 377 | #ifdef TRAIN_RES |
| 378 | static int _encodepart(oggpack_buffer *opb,int *vec, int n, |
| 379 | codebook *book,long *acc){ |
| 380 | #else |
| 381 | static int _encodepartcxx . . $ _encodepart(56c546e6904769fb).(oggpack_buffercxx . . $ oggpack_buffer# *opb,int *vec, int n, |
| 382 | codebookcxx . . $ codebook# *book){ |
| 383 | #endif |
| 384 | int i,bits=0; |
| 385 | int dim=book->dimcxx . . $ codebook#dim.; |
| 386 | int step=n/dim; |
| 387 | |
| 388 | for(i=0;i<step;i++){ |
| 389 | int entry=local_book_besterrorcxx . . $ local_book_besterror(5f783d6d23a67b8e).(book,vec+i*dim); |
| 390 | |
| 391 | #ifdef TRAIN_RES |
| 392 | if(entry>=0) |
| 393 | acc[entry]++; |
| 394 | #endif |
| 395 | |
| 396 | bits+=vorbis_book_encodecxx . . $ vorbis_book_encode(270409cc35b9118c).(book,entry,opb); |
| 397 | |
| 398 | } |
| 399 | |
| 400 | return(bits); |
| 401 | } |
| 402 | |
| 403 | static long **_01classcxx . . $ _01class(1608c07fa6da16f9).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 404 | int **in,int ch){ |
| 405 | long i,j,k; |
| 406 | vorbis_look_residue0cxx . . $ vorbis_look_residue0# *look=(vorbis_look_residue0cxx . . $ vorbis_look_residue0# *)vl; |
| 407 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *info=look->infocxx . . $ $anonymous_type_fbc217f811b06792_0#info.; |
| 408 | |
| 409 | /* move all this setup out later */ |
| 410 | int samples_per_partition=info->groupingcxx . . $ vorbis_info_residue0#grouping.; |
| 411 | int possible_partitions=info->partitionscxx . . $ vorbis_info_residue0#partitions.; |
| 412 | int n=info->endcxx . . $ vorbis_info_residue0#end.-info->begincxx . . $ vorbis_info_residue0#begin.; |
| 413 | |
| 414 | int partvals=n/samples_per_partition; |
| 415 | long **partword = (long **)_vorbis_block_alloccxx . . $ _vorbis_block_alloc(339031f86f86193e).(vb,ch*sizeof(*partword)); |
| 416 | float scale=100./samples_per_partition; |
| 417 | |
| 418 | /* we find the partition type for each partition of each |
| 419 | channel. We'll go back and do the interleaved encoding in a |
| 420 | bit. For now, clarity */ |
| 421 | |
| 422 | for(i=0;i<ch;i++){ |
| 423 | partword[i] = (long *) _vorbis_block_alloccxx . . $ _vorbis_block_alloc(339031f86f86193e).(vb,n/samples_per_partition*sizeof(*partword[i])); |
| 424 | memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i])); |
| 425 | } |
| 426 | |
| 427 | for(i=0;i<partvals;i++){ |
| 428 | int offset=i*samples_per_partition+info->begincxx . . $ vorbis_info_residue0#begin.; |
| 429 | for(j=0;j<ch;j++){ |
| 430 | int max=0; |
| 431 | int ent=0; |
| 432 | for(k=0;k<samples_per_partition;k++){ |
| 433 | if(abscxx . . $ abs(a1851578aea3f541).(in[j][offset+k])>max)max=abscxx . . $ abs(a1851578aea3f541).(in[j][offset+k]); |
| 434 | ent+=abscxx . . $ abs(a1851578aea3f541).(in[j][offset+k]); |
| 435 | } |
| 436 | ent*=scale; |
| 437 | |
| 438 | for(k=0;k<possible_partitions-1;k++) |
| 439 | if(max<=info->classmetric1cxx . . $ vorbis_info_residue0#classmetric1.[k] && |
| 440 | (info->classmetric2cxx . . $ vorbis_info_residue0#classmetric2.[k]<0 || ent<info->classmetric2cxx . . $ vorbis_info_residue0#classmetric2.[k])) |
| 441 | break; |
| 442 | |
| 443 | partword[j][i]=k; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | #ifdef TRAIN_RESAUX |
| 448 | { |
| 449 | FILE *of; |
| 450 | char buffer[80]; |
| 451 | |
| 452 | for(i=0;i<ch;i++){ |
| 453 | sprintf(buffer,"resaux_%d.vqd",look->train_seq); |
| 454 | of=fopen(buffer,"a"); |
| 455 | for(j=0;j<partvals;j++) |
| 456 | fprintf(of,"%ld, ",partword[i][j]); |
| 457 | fprintf(of,"\n"); |
| 458 | fclose(of); |
| 459 | } |
| 460 | } |
| 461 | #endif |
| 462 | look->framescxx . . $ $anonymous_type_fbc217f811b06792_0#frames.++; |
| 463 | |
| 464 | return(partword); |
| 465 | } |
| 466 | |
| 467 | /* designed for stereo or other modes where the partition size is an |
| 468 | integer multiple of the number of channels encoded in the current |
| 469 | submap */ |
| 470 | static long **_2classcxx . . $ _2class(1608c07fa6da16f9).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl,int **in, |
| 471 | int ch){ |
| 472 | long i,j,k,l; |
| 473 | vorbis_look_residue0cxx . . $ vorbis_look_residue0# *look=(vorbis_look_residue0cxx . . $ vorbis_look_residue0# *)vl; |
| 474 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *info=look->infocxx . . $ $anonymous_type_fbc217f811b06792_0#info.; |
| 475 | |
| 476 | /* move all this setup out later */ |
| 477 | int samples_per_partition=info->groupingcxx . . $ vorbis_info_residue0#grouping.; |
| 478 | int possible_partitions=info->partitionscxx . . $ vorbis_info_residue0#partitions.; |
| 479 | int n=info->endcxx . . $ vorbis_info_residue0#end.-info->begincxx . . $ vorbis_info_residue0#begin.; |
| 480 | |
| 481 | int partvals=n/samples_per_partition; |
| 482 | long **partword = (long **) _vorbis_block_alloccxx . . $ _vorbis_block_alloc(339031f86f86193e).(vb,sizeof(*partword)); |
| 483 | |
| 484 | #if defined(TRAIN_RES) || defined (TRAIN_RESAUX) |
| 485 | FILE *of; |
| 486 | char buffer[80]; |
| 487 | #endif |
| 488 | |
| 489 | partword[0] = (long *) _vorbis_block_alloccxx . . $ _vorbis_block_alloc(339031f86f86193e).(vb,partvals*sizeof(*partword[0])); |
| 490 | memset(partword[0],0,partvals*sizeof(*partword[0])); |
| 491 | |
| 492 | for(i=0,l=info->begincxx . . $ vorbis_info_residue0#begin./ch;i<partvals;i++){ |
| 493 | int magmax=0; |
| 494 | int angmax=0; |
| 495 | for(j=0;j<samples_per_partition;j+=ch){ |
| 496 | if(abscxx . . $ abs(a1851578aea3f541).(in[0][l])>magmax)magmax=abscxx . . $ abs(a1851578aea3f541).(in[0][l]); |
| 497 | for(k=1;k<ch;k++) |
| 498 | if(abscxx . . $ abs(a1851578aea3f541).(in[k][l])>angmax)angmax=abscxx . . $ abs(a1851578aea3f541).(in[k][l]); |
| 499 | l++; |
| 500 | } |
| 501 | |
| 502 | for(j=0;j<possible_partitions-1;j++) |
| 503 | if(magmax<=info->classmetric1cxx . . $ vorbis_info_residue0#classmetric1.[j] && |
| 504 | angmax<=info->classmetric2cxx . . $ vorbis_info_residue0#classmetric2.[j]) |
| 505 | break; |
| 506 | |
| 507 | partword[0][i]=j; |
| 508 | |
| 509 | } |
| 510 | |
| 511 | #ifdef TRAIN_RESAUX |
| 512 | sprintf(buffer,"resaux_%d.vqd",look->train_seq); |
| 513 | of=fopen(buffer,"a"); |
| 514 | for(i=0;i<partvals;i++) |
| 515 | fprintf(of,"%ld, ",partword[0][i]); |
| 516 | fprintf(of,"\n"); |
| 517 | fclose(of); |
| 518 | #endif |
| 519 | |
| 520 | look->framescxx . . $ $anonymous_type_fbc217f811b06792_0#frames.++; |
| 521 | |
| 522 | return(partword); |
| 523 | } |
| 524 | |
| 525 | static int _01forwardcxx . . $ _01forward(b6fd5806b4ab9298).(oggpack_buffercxx . . $ oggpack_buffer# *opb, |
| 526 | vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 527 | int **in,int ch, |
| 528 | long **partword, |
| 529 | #ifdef TRAIN_RES |
| 530 | int (*encode)(oggpack_buffer *,int *,int, |
| 531 | codebook *,long *), |
| 532 | int submap |
| 533 | #else |
| 534 | int (*encode)(oggpack_buffercxx . . $ oggpack_buffer# *,int *,int, |
| 535 | codebookcxx . . $ codebook# *) |
| 536 | #endif |
| 537 | ){ |
| 538 | long i,j,k,s; |
| 539 | vorbis_look_residue0cxx . . $ vorbis_look_residue0# *look=(vorbis_look_residue0cxx . . $ vorbis_look_residue0# *)vl; |
| 540 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *info=look->infocxx . . $ $anonymous_type_fbc217f811b06792_0#info.; |
| 541 | |
| 542 | #ifdef TRAIN_RES |
| 543 | look->submap=submap; |
| 544 | #endif |
| 545 | |
| 546 | /* move all this setup out later */ |
| 547 | int samples_per_partition=info->groupingcxx . . $ vorbis_info_residue0#grouping.; |
| 548 | int possible_partitions=info->partitionscxx . . $ vorbis_info_residue0#partitions.; |
| 549 | int partitions_per_word=look->phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.->dimcxx . . $ codebook#dim.; |
| 550 | int n=info->endcxx . . $ vorbis_info_residue0#end.-info->begincxx . . $ vorbis_info_residue0#begin.; |
| 551 | |
| 552 | int partvals=n/samples_per_partition; |
| 553 | long resbits[128]; |
| 554 | long resvals[128]; |
| 555 | |
| 556 | #ifdef TRAIN_RES |
| 557 | for(i=0;i<ch;i++) |
| 558 | for(j=info->begin;j<info->end;j++){ |
| 559 | if(in[i][j]>look->tmax)look->tmax=in[i][j]; |
| 560 | if(in[i][j]<look->tmin)look->tmin=in[i][j]; |
| 561 | } |
| 562 | #endif |
| 563 | |
| 564 | memset(resbits,0,sizeof(resbits)); |
| 565 | memset(resvals,0,sizeof(resvals)); |
| 566 | |
| 567 | /* we code the partition words for each channel, then the residual |
| 568 | words for a partition per channel until we've written all the |
| 569 | residual words for that partition word. Then write the next |
| 570 | partition channel words... */ |
| 571 | |
| 572 | for(s=0;s<look->stagescxx . . $ $anonymous_type_fbc217f811b06792_0#stages.;s++){ |
| 573 | |
| 574 | for(i=0;i<partvals;){ |
| 575 | |
| 576 | /* first we encode a partition codeword for each channel */ |
| 577 | if(s==0){ |
| 578 | for(j=0;j<ch;j++){ |
| 579 | long val=partword[j][i]; |
| 580 | for(k=1;k<partitions_per_word;k++){ |
| 581 | val*=possible_partitions; |
| 582 | if(i+k<partvals) |
| 583 | val+=partword[j][i+k]; |
| 584 | } |
| 585 | |
| 586 | /* training hack */ |
| 587 | if(val<look->phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.->entriescxx . . $ codebook#entries.) |
| 588 | look->phrasebitscxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebits.+=vorbis_book_encodecxx . . $ vorbis_book_encode(270409cc35b9118c).(look->phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.,val,opb); |
| 589 | #if 0 /*def TRAIN_RES*/ |
| 590 | else |
| 591 | fprintf(stderr,"!"); |
| 592 | #endif |
| 593 | |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | /* now we encode interleaved residual values for the partitions */ |
| 598 | for(k=0;k<partitions_per_word && i<partvals;k++,i++){ |
| 599 | long offset=i*samples_per_partition+info->begincxx . . $ vorbis_info_residue0#begin.; |
| 600 | |
| 601 | for(j=0;j<ch;j++){ |
| 602 | if(s==0)resvals[partword[j][i]]+=samples_per_partition; |
| 603 | if(info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[partword[j][i]]&(1<<s)){ |
| 604 | codebookcxx . . $ codebook# *statebook=look->partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.[partword[j][i]][s]; |
| 605 | if(statebook){ |
| 606 | int ret; |
| 607 | #ifdef TRAIN_RES |
| 608 | long *accumulator=nullptr; |
| 609 | accumulator=look->training_data[s][partword[j][i]]; |
| 610 | { |
| 611 | int l; |
| 612 | int *samples=in[j]+offset; |
| 613 | for(l=0;l<samples_per_partition;l++){ |
| 614 | if(samples[l]<look->training_min[s][partword[j][i]]) |
| 615 | look->training_min[s][partword[j][i]]=samples[l]; |
| 616 | if(samples[l]>look->training_max[s][partword[j][i]]) |
| 617 | look->training_max[s][partword[j][i]]=samples[l]; |
| 618 | } |
| 619 | } |
| 620 | ret=encode(opb,in[j]+offset,samples_per_partition, |
| 621 | statebook,accumulator); |
| 622 | #else |
| 623 | ret=encode(opb,in[j]+offset,samples_per_partition, |
| 624 | statebook); |
| 625 | #endif |
| 626 | |
| 627 | look->postbitscxx . . $ $anonymous_type_fbc217f811b06792_0#postbits.+=ret; |
| 628 | resbits[partword[j][i]]+=ret; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | return(0); |
| 637 | } |
| 638 | |
| 639 | /* a truncated packet here just means 'stop working'; it's not an error */ |
| 640 | static int _01inversecxx . . $ _01inverse(12bed5d7d7dbd5fa).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 641 | float **in,int ch, |
| 642 | long (*decodepart)(codebookcxx . . $ codebook# *, float *, |
| 643 | oggpack_buffercxx . . $ oggpack_buffer# *,int)){ |
| 644 | |
| 645 | long i,j,k,l,s; |
| 646 | vorbis_look_residue0cxx . . $ vorbis_look_residue0# *look=(vorbis_look_residue0cxx . . $ vorbis_look_residue0# *)vl; |
| 647 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *info=look->infocxx . . $ $anonymous_type_fbc217f811b06792_0#info.; |
| 648 | |
| 649 | /* move all this setup out later */ |
| 650 | int samples_per_partition=info->groupingcxx . . $ vorbis_info_residue0#grouping.; |
| 651 | int partitions_per_word=look->phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.->dimcxx . . $ codebook#dim.; |
| 652 | int max=vb->pcmendcxx . . $ vorbis_block#pcmend.>>1; |
| 653 | int end=(info->endcxx . . $ vorbis_info_residue0#end.<max?info->endcxx . . $ vorbis_info_residue0#end.:max); |
| 654 | int n=end-info->begincxx . . $ vorbis_info_residue0#begin.; |
| 655 | |
| 656 | if(n>0){ |
| 657 | int partvals=n/samples_per_partition; |
| 658 | int partwords=(partvals+partitions_per_word-1)/partitions_per_word; |
| 659 | int ***partword= (int ***) allocacxx . . $ `<external>/11612401604547820122/alloca.h:35:10`!(ch*sizeof(*partword)); |
| 660 | |
| 661 | for(j=0;j<ch;j++) |
| 662 | partword[j]= (int **)_vorbis_block_alloccxx . . $ _vorbis_block_alloc(339031f86f86193e).(vb,partwords*sizeof(*partword[j])); |
| 663 | |
| 664 | for(s=0;s<look->stagescxx . . $ $anonymous_type_fbc217f811b06792_0#stages.;s++){ |
| 665 | |
| 666 | /* each loop decodes on partition codeword containing |
| 667 | partitions_per_word partitions */ |
| 668 | for(i=0,l=0;i<partvals;l++){ |
| 669 | if(s==0){ |
| 670 | /* fetch the partition word for each channel */ |
| 671 | for(j=0;j<ch;j++){ |
| 672 | int temp=vorbis_book_decodecxx . . $ vorbis_book_decode(c6017aa1fb295037).(look->phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.,&vb->opbcxx . . $ vorbis_block#opb.); |
| 673 | |
| 674 | if(temp==-1 || temp>=info->partvalscxx . . $ vorbis_info_residue0#partvals.)goto eopbreak; |
| 675 | partword[j][l]=look->decodemapcxx . . $ $anonymous_type_fbc217f811b06792_0#decodemap.[temp]; |
| 676 | if(partword[j][l]==nullptr)goto errout; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | /* now we decode residual values for the partitions */ |
| 681 | for(k=0;k<partitions_per_word && i<partvals;k++,i++) |
| 682 | for(j=0;j<ch;j++){ |
| 683 | long offset=info->begincxx . . $ vorbis_info_residue0#begin.+i*samples_per_partition; |
| 684 | if(info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[partword[j][l][k]]&(1<<s)){ |
| 685 | codebookcxx . . $ codebook# *stagebook=look->partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.[partword[j][l][k]][s]; |
| 686 | if(stagebook){ |
| 687 | if(decodepart(stagebook,in[j]+offset,&vb->opbcxx . . $ vorbis_block#opb., |
| 688 | samples_per_partition)==-1)goto eopbreak; |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | errout: |
| 696 | eopbreak: |
| 697 | return(0); |
| 698 | } |
| 699 | |
| 700 | int res0_inversecxx . . $ res0_inverse(171bf5b78738c462).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 701 | float **in,int *nonzero,int ch){ |
| 702 | int i,used=0; |
| 703 | for(i=0;i<ch;i++) |
| 704 | if(nonzero[i]) |
| 705 | in[used++]=in[i]; |
| 706 | if(used) |
| 707 | return(_01inversecxx . . $ _01inverse(12bed5d7d7dbd5fa).(vb,vl,in,used,vorbis_book_decodevs_addcxx . . $ vorbis_book_decodevs_add(809189a4d39ab48a).)); |
| 708 | else |
| 709 | return(0); |
| 710 | } |
| 711 | |
| 712 | int res1_forwardcxx . . $ res1_forward(43fdd37ccacf33b5).(oggpack_buffercxx . . $ oggpack_buffer# *opb,vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 713 | int **in,int *nonzero,int ch, long **partword, int submap){ |
| 714 | int i,used=0; |
| 715 | (void)vb; |
| 716 | for(i=0;i<ch;i++) |
| 717 | if(nonzero[i]) |
| 718 | in[used++]=in[i]; |
| 719 | |
| 720 | if(used){ |
| 721 | #ifdef TRAIN_RES |
| 722 | return _01forward(opb,vl,in,used,partword,_encodepart,submap); |
| 723 | #else |
| 724 | (void)submap; |
| 725 | return _01forwardcxx . . $ _01forward(b6fd5806b4ab9298).(opb,vl,in,used,partword,_encodepartcxx . . $ _encodepart(56c546e6904769fb).); |
| 726 | #endif |
| 727 | }else{ |
| 728 | return(0); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | long **res1_classcxx . . $ res1_class(15134ec91ac7067).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 733 | int **in,int *nonzero,int ch){ |
| 734 | int i,used=0; |
| 735 | for(i=0;i<ch;i++) |
| 736 | if(nonzero[i]) |
| 737 | in[used++]=in[i]; |
| 738 | if(used) |
| 739 | return(_01classcxx . . $ _01class(1608c07fa6da16f9).(vb,vl,in,used)); |
| 740 | else |
| 741 | return(0); |
| 742 | } |
| 743 | |
| 744 | int res1_inversecxx . . $ res1_inverse(171bf5b78738c462).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 745 | float **in,int *nonzero,int ch){ |
| 746 | int i,used=0; |
| 747 | for(i=0;i<ch;i++) |
| 748 | if(nonzero[i]) |
| 749 | in[used++]=in[i]; |
| 750 | if(used) |
| 751 | return(_01inversecxx . . $ _01inverse(12bed5d7d7dbd5fa).(vb,vl,in,used,vorbis_book_decodev_addcxx . . $ vorbis_book_decodev_add(809189a4d39ab48a).)); |
| 752 | else |
| 753 | return(0); |
| 754 | } |
| 755 | |
| 756 | long **res2_classcxx . . $ res2_class(15134ec91ac7067).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 757 | int **in,int *nonzero,int ch){ |
| 758 | int i,used=0; |
| 759 | for(i=0;i<ch;i++) |
| 760 | if(nonzero[i])used++; |
| 761 | if(used) |
| 762 | return(_2classcxx . . $ _2class(1608c07fa6da16f9).(vb,vl,in,ch)); |
| 763 | else |
| 764 | return(0); |
| 765 | } |
| 766 | |
| 767 | /* res2 is slightly more different; all the channels are interleaved |
| 768 | into a single vector and encoded. */ |
| 769 | |
| 770 | int res2_forwardcxx . . $ res2_forward(43fdd37ccacf33b5).(oggpack_buffercxx . . $ oggpack_buffer# *opb, |
| 771 | vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 772 | int **in,int *nonzero,int ch, long **partword,int submap){ |
| 773 | long i,j,k,n=vb->pcmendcxx . . $ vorbis_block#pcmend./2,used=0; |
| 774 | |
| 775 | /* don't duplicate the code; use a working vector hack for now and |
| 776 | reshape ourselves into a single channel res1 */ |
| 777 | /* ugly; reallocs for each coupling pass :-( */ |
| 778 | int *work = (int *) _vorbis_block_alloccxx . . $ _vorbis_block_alloc(339031f86f86193e).(vb,ch*n*sizeof(*work)); |
| 779 | for(i=0;i<ch;i++){ |
| 780 | int *pcm=in[i]; |
| 781 | if(nonzero[i])used++; |
| 782 | for(j=0,k=i;j<n;j++,k+=ch) |
| 783 | work[k]=pcm[j]; |
| 784 | } |
| 785 | |
| 786 | if(used){ |
| 787 | #ifdef TRAIN_RES |
| 788 | return _01forward(opb,vl,&work,1,partword,_encodepart,submap); |
| 789 | #else |
| 790 | (void)submap; |
| 791 | return _01forwardcxx . . $ _01forward(b6fd5806b4ab9298).(opb,vl,&work,1,partword,_encodepartcxx . . $ _encodepart(56c546e6904769fb).); |
| 792 | #endif |
| 793 | }else{ |
| 794 | return(0); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | /* duplicate code here as speed is somewhat more important */ |
| 799 | int res2_inversecxx . . $ res2_inverse(171bf5b78738c462).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_residuecxx . . $ vorbis_look_residue# *vl, |
| 800 | float **in,int *nonzero,int ch){ |
| 801 | long i,k,l,s; |
| 802 | vorbis_look_residue0cxx . . $ vorbis_look_residue0# *look=(vorbis_look_residue0cxx . . $ vorbis_look_residue0# *)vl; |
| 803 | vorbis_info_residue0cxx . . $ vorbis_info_residue0# *info=look->infocxx . . $ $anonymous_type_fbc217f811b06792_0#info.; |
| 804 | |
| 805 | /* move all this setup out later */ |
| 806 | int samples_per_partition=info->groupingcxx . . $ vorbis_info_residue0#grouping.; |
| 807 | int partitions_per_word=look->phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.->dimcxx . . $ codebook#dim.; |
| 808 | int max=(vb->pcmendcxx . . $ vorbis_block#pcmend.*ch)>>1; |
| 809 | int end=(info->endcxx . . $ vorbis_info_residue0#end.<max?info->endcxx . . $ vorbis_info_residue0#end.:max); |
| 810 | int n=end-info->begincxx . . $ vorbis_info_residue0#begin.; |
| 811 | |
| 812 | if(n>0){ |
| 813 | int partvals=n/samples_per_partition; |
| 814 | int partwords=(partvals+partitions_per_word-1)/partitions_per_word; |
| 815 | int **partword= (int **) _vorbis_block_alloccxx . . $ _vorbis_block_alloc(339031f86f86193e).(vb,partwords*sizeof(*partword)); |
| 816 | |
| 817 | for(i=0;i<ch;i++)if(nonzero[i])break; |
| 818 | if(i==ch)return(0); /* no nonzero vectors */ |
| 819 | |
| 820 | for(s=0;s<look->stagescxx . . $ $anonymous_type_fbc217f811b06792_0#stages.;s++){ |
| 821 | for(i=0,l=0;i<partvals;l++){ |
| 822 | |
| 823 | if(s==0){ |
| 824 | /* fetch the partition word */ |
| 825 | int temp=vorbis_book_decodecxx . . $ vorbis_book_decode(c6017aa1fb295037).(look->phrasebookcxx . . $ $anonymous_type_fbc217f811b06792_0#phrasebook.,&vb->opbcxx . . $ vorbis_block#opb.); |
| 826 | if(temp==-1 || temp>=info->partvalscxx . . $ vorbis_info_residue0#partvals.)goto eopbreak; |
| 827 | partword[l]=look->decodemapcxx . . $ $anonymous_type_fbc217f811b06792_0#decodemap.[temp]; |
| 828 | if(partword[l]==nullptr)goto errout; |
| 829 | } |
| 830 | |
| 831 | /* now we decode residual values for the partitions */ |
| 832 | for(k=0;k<partitions_per_word && i<partvals;k++,i++) |
| 833 | if(info->secondstagescxx . . $ vorbis_info_residue0#secondstages.[partword[l][k]]&(1<<s)){ |
| 834 | codebookcxx . . $ codebook# *stagebook=look->partbookscxx . . $ $anonymous_type_fbc217f811b06792_0#partbooks.[partword[l][k]][s]; |
| 835 | |
| 836 | if(stagebook){ |
| 837 | if(vorbis_book_decodevv_addcxx . . $ vorbis_book_decodevv_add(d0d93024db625415).(stagebook,in, |
| 838 | i*samples_per_partition+info->begincxx . . $ vorbis_info_residue0#begin.,ch, |
| 839 | &vb->opbcxx . . $ vorbis_block#opb.,samples_per_partition)==-1) |
| 840 | goto eopbreak; |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | } |
| 846 | errout: |
| 847 | eopbreak: |
| 848 | return(0); |
| 849 | } |
| 850 | |
| 851 | |
| 852 | const vorbis_func_residuecxx . . $ vorbis_func_residue# residue0_exportbundlecxx . . $ residue0_exportbundle.={ |
| 853 | nullptr, |
| 854 | &res0_unpackcxx . . $ res0_unpack(eeac8d4f838aca31)., |
| 855 | &res0_lookcxx . . $ res0_look(f22d77a7569cfb00)., |
| 856 | &res0_free_infocxx . . $ res0_free_info(5d22bdacc48458e8)., |
| 857 | &res0_free_lookcxx . . $ res0_free_look(5d22bdacc48458e8)., |
| 858 | nullptr, |
| 859 | nullptr, |
| 860 | &res0_inversecxx . . $ res0_inverse(171bf5b78738c462). |
| 861 | }; |
| 862 | |
| 863 | const vorbis_func_residuecxx . . $ vorbis_func_residue# residue1_exportbundlecxx . . $ residue1_exportbundle.={ |
| 864 | &res0_packcxx . . $ res0_pack(14051757f6862fa4)., |
| 865 | &res0_unpackcxx . . $ res0_unpack(eeac8d4f838aca31)., |
| 866 | &res0_lookcxx . . $ res0_look(f22d77a7569cfb00)., |
| 867 | &res0_free_infocxx . . $ res0_free_info(5d22bdacc48458e8)., |
| 868 | &res0_free_lookcxx . . $ res0_free_look(5d22bdacc48458e8)., |
| 869 | &res1_classcxx . . $ res1_class(15134ec91ac7067)., |
| 870 | &res1_forwardcxx . . $ res1_forward(43fdd37ccacf33b5)., |
| 871 | &res1_inversecxx . . $ res1_inverse(171bf5b78738c462). |
| 872 | }; |
| 873 | |
| 874 | const vorbis_func_residuecxx . . $ vorbis_func_residue# residue2_exportbundlecxx . . $ residue2_exportbundle.={ |
| 875 | &res0_packcxx . . $ res0_pack(14051757f6862fa4)., |
| 876 | &res0_unpackcxx . . $ res0_unpack(eeac8d4f838aca31)., |
| 877 | &res0_lookcxx . . $ res0_look(f22d77a7569cfb00)., |
| 878 | &res0_free_infocxx . . $ res0_free_info(5d22bdacc48458e8)., |
| 879 | &res0_free_lookcxx . . $ res0_free_look(5d22bdacc48458e8)., |
| 880 | &res2_classcxx . . $ res2_class(15134ec91ac7067)., |
| 881 | &res2_forwardcxx . . $ res2_forward(43fdd37ccacf33b5)., |
| 882 | &res2_inversecxx . . $ res2_inverse(171bf5b78738c462). |
| 883 | }; |