| 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: floor backend 0 implementation |
| 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_codec_internal.h"cxx . . $ `<file>/external/vorbis/vorbis_codec_internal.h`/ |
| 20 | #include "vorbis_registry.h"cxx . . $ `<file>/external/vorbis/vorbis_registry.h`/ |
| 21 | #include "vorbis_lpc.h"cxx . . $ `<file>/external/vorbis/vorbis_lpc.h`/ |
| 22 | #include "vorbis_lsp.h"cxx . . $ `<file>/external/vorbis/vorbis_lsp.h`/ |
| 23 | #include "vorbis_codebook.h"cxx . . $ `<file>/external/vorbis/vorbis_codebook.h`/ |
| 24 | #include "vorbis_scales.h"cxx . . $ `<file>/external/vorbis/vorbis_scales.h`/ |
| 25 | #include "vorbis_misc.h"cxx . . $ `<file>/external/vorbis/vorbis_misc.h`/ |
| 26 | #include "vorbis_os.h"cxx . . $ `<file>/external/vorbis/vorbis_os.h`/ |
| 27 | |
| 28 | #include "vorbis_misc.h"cxx . . $ `<file>/external/vorbis/vorbis_misc.h`/ |
| 29 | |
| 30 | typedef structcxx . . $ $anonymous_type_64a11263da209325_0# { |
| 31 | int lncxx . . $ $anonymous_type_64a11263da209325_0#ln.; |
| 32 | int mcxx . . $ $anonymous_type_64a11263da209325_0#m.; |
| 33 | int **linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.; |
| 34 | int ncxx . . $ $anonymous_type_64a11263da209325_0#n.[2]; |
| 35 | |
| 36 | vorbis_info_floor0cxx . . $ vorbis_info_floor0# *vicxx . . $ $anonymous_type_64a11263da209325_0#vi.; |
| 37 | |
| 38 | long bitscxx . . $ $anonymous_type_64a11263da209325_0#bits.; |
| 39 | long framescxx . . $ $anonymous_type_64a11263da209325_0#frames.; |
| 40 | } vorbis_look_floor0cxx . . $ vorbis_look_floor0#; |
| 41 | |
| 42 | |
| 43 | /***********************************************/ |
| 44 | |
| 45 | static void floor0_free_infocxx . . $ floor0_free_info(5d22bdacc48458e8).(vorbis_info_floorcxx . . $ vorbis_info_floor# *i){ |
| 46 | vorbis_info_floor0cxx . . $ vorbis_info_floor0# *info=(vorbis_info_floor0cxx . . $ vorbis_info_floor0# *)i; |
| 47 | if(info){ |
| 48 | memset(info,0,sizeof(*info)); |
| 49 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(info); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | static void floor0_free_lookcxx . . $ floor0_free_look(5d22bdacc48458e8).(vorbis_look_floorcxx . . $ vorbis_look_floor# *i){ |
| 54 | vorbis_look_floor0cxx . . $ vorbis_look_floor0# *look=(vorbis_look_floor0cxx . . $ vorbis_look_floor0# *)i; |
| 55 | if(look){ |
| 56 | |
| 57 | if(look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.){ |
| 58 | |
| 59 | if(look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.[0])Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(look->linearmap[0]); |
| 60 | if(look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.[1])Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(look->linearmap[1]); |
| 61 | |
| 62 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(look->linearmap); |
| 63 | } |
| 64 | memset(look,0,sizeof(*look)); |
| 65 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(look); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | static vorbis_info_floorcxx . . $ vorbis_info_floor# *floor0_unpackcxx . . $ floor0_unpack(eeac8d4f838aca31). (vorbis_infocxx . . $ vorbis_info# *vi,oggpack_buffercxx . . $ oggpack_buffer# *opb){ |
| 70 | codec_setup_infocxx . . $ codec_setup_info# *ci= (codec_setup_infocxx . . $ codec_setup_info# *) vi->codec_setupcxx . . $ vorbis_info#codec_setup.; |
| 71 | int j; |
| 72 | |
| 73 | vorbis_info_floor0cxx . . $ vorbis_info_floor0# *info = ( vorbis_info_floor0cxx . . $ vorbis_info_floor0# *) _Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(sizeof(*info)); |
| 74 | info->ordercxx . . $ $anonymous_type_f527c519943fbe69_1#order.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,8); |
| 75 | info->ratecxx . . $ $anonymous_type_f527c519943fbe69_1#rate.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,16); |
| 76 | info->barkmapcxx . . $ $anonymous_type_f527c519943fbe69_1#barkmap.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,16); |
| 77 | info->ampbitscxx . . $ $anonymous_type_f527c519943fbe69_1#ampbits.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,6); |
| 78 | info->ampdBcxx . . $ $anonymous_type_f527c519943fbe69_1#ampdB.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,8); |
| 79 | info->numbookscxx . . $ $anonymous_type_f527c519943fbe69_1#numbooks.=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,4)+1; |
| 80 | |
| 81 | if(info->ordercxx . . $ $anonymous_type_f527c519943fbe69_1#order.<1)goto err_out; |
| 82 | if(info->ratecxx . . $ $anonymous_type_f527c519943fbe69_1#rate.<1)goto err_out; |
| 83 | if(info->barkmapcxx . . $ $anonymous_type_f527c519943fbe69_1#barkmap.<1)goto err_out; |
| 84 | if(info->numbookscxx . . $ $anonymous_type_f527c519943fbe69_1#numbooks.<1)goto err_out; |
| 85 | |
| 86 | for(j=0;j<info->numbookscxx . . $ $anonymous_type_f527c519943fbe69_1#numbooks.;j++){ |
| 87 | info->bookscxx . . $ $anonymous_type_f527c519943fbe69_1#books.[j]=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(opb,8); |
| 88 | if(info->bookscxx . . $ $anonymous_type_f527c519943fbe69_1#books.[j]<0 || info->bookscxx . . $ $anonymous_type_f527c519943fbe69_1#books.[j]>=ci->bookscxx . . $ codec_setup_info#books.)goto err_out; |
| 89 | if(ci->book_paramcxx . . $ codec_setup_info#book_param.[info->bookscxx . . $ $anonymous_type_f527c519943fbe69_1#books.[j]]->maptypecxx . . $ static_codebook#maptype.==0)goto err_out; |
| 90 | if(ci->book_paramcxx . . $ codec_setup_info#book_param.[info->bookscxx . . $ $anonymous_type_f527c519943fbe69_1#books.[j]]->dimcxx . . $ static_codebook#dim.<1)goto err_out; |
| 91 | } |
| 92 | return(info); |
| 93 | |
| 94 | err_out: |
| 95 | floor0_free_infocxx . . $ floor0_free_info(5d22bdacc48458e8).(info); |
| 96 | return(nullptr); |
| 97 | } |
| 98 | |
| 99 | /* initialize Bark scale and normalization lookups. We could do this |
| 100 | with static tables, but Vorbis allows a number of possible |
| 101 | combinations, so it's best to do it computationally. |
| 102 | |
| 103 | The below is authoritative in terms of defining scale mapping. |
| 104 | Note that the scale depends on the sampling rate as well as the |
| 105 | linear block and mapping sizes */ |
| 106 | |
| 107 | static void floor0_map_lazy_initcxx . . $ floor0_map_lazy_init(351f3d434046d415).(vorbis_blockcxx . . $ vorbis_block# *vb, |
| 108 | vorbis_info_floorcxx . . $ vorbis_info_floor# *infoX, |
| 109 | vorbis_look_floor0cxx . . $ vorbis_look_floor0# *look){ |
| 110 | if(!look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.[vb->Wcxx . . $ vorbis_block#W.]){ |
| 111 | vorbis_dsp_statecxx . . $ vorbis_dsp_state# *vd=vb->vdcxx . . $ vorbis_block#vd.; |
| 112 | vorbis_infocxx . . $ vorbis_info# *vi=vd->vicxx . . $ vorbis_dsp_state#vi.; |
| 113 | codec_setup_infocxx . . $ codec_setup_info# *ci= (codec_setup_infocxx . . $ codec_setup_info# *) vi->codec_setupcxx . . $ vorbis_info#codec_setup.; |
| 114 | vorbis_info_floor0cxx . . $ vorbis_info_floor0# *info=(vorbis_info_floor0cxx . . $ vorbis_info_floor0# *)infoX; |
| 115 | int W=vb->Wcxx . . $ vorbis_block#W.; |
| 116 | int n=ci->blocksizescxx . . $ codec_setup_info#blocksizes.[W]/2,j; |
| 117 | |
| 118 | /* we choose a scaling constant so that: |
| 119 | floor(bark(rate/2-1)*C)=mapped-1 |
| 120 | floor(bark(rate/2)*C)=mapped */ |
| 121 | float scale=look->lncxx . . $ $anonymous_type_64a11263da209325_0#ln./toBARKcxx . . $ `external/vorbis/vorbis_scales.h:73:9`!(info->rate/2.f); |
| 122 | |
| 123 | /* the mapping from a linear scale to a smaller bark scale is |
| 124 | straightforward. We do *not* make sure that the linear mapping |
| 125 | does not skip bark-scale bins; the decoder simply skips them and |
| 126 | the encoder may do what it wishes in filling them. They're |
| 127 | necessary in some mapping combinations to keep the scale spacing |
| 128 | accurate */ |
| 129 | look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.[W] = (int *) _Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).((n+1)*sizeof(**look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.)); |
| 130 | for(j=0;j<n;j++){ |
| 131 | int val=floorcxx . . $ floor(fbcf3211dfe1bfd1).( toBARKcxx . . $ `external/vorbis/vorbis_scales.h:73:9`!((info->rate/2.f)/n*j) |
| 132 | *scale); /* bark numbers represent band edges */ |
| 133 | if(val>=look->lncxx . . $ $anonymous_type_64a11263da209325_0#ln.)val=look->lncxx . . $ $anonymous_type_64a11263da209325_0#ln.-1; /* guard against the approximation */ |
| 134 | look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.[W][j]=val; |
| 135 | } |
| 136 | look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.[W][j]=-1; |
| 137 | look->ncxx . . $ $anonymous_type_64a11263da209325_0#n.[W]=n; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | static vorbis_look_floorcxx . . $ vorbis_look_floor# *floor0_lookcxx . . $ floor0_look(f22d77a7569cfb00).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *vd, |
| 142 | vorbis_info_floorcxx . . $ vorbis_info_floor# *i){ |
| 143 | vorbis_info_floor0cxx . . $ vorbis_info_floor0# *info=(vorbis_info_floor0cxx . . $ vorbis_info_floor0# *)i; |
| 144 | vorbis_look_floor0cxx . . $ vorbis_look_floor0# *look = (vorbis_look_floor0cxx . . $ vorbis_look_floor0# *) _Melder_calloccxx . . $ _Melder_calloc(d58a73cf1dc24cbb).(1,sizeof(*look)); |
| 145 | |
| 146 | (void)vd; |
| 147 | |
| 148 | look->mcxx . . $ $anonymous_type_64a11263da209325_0#m.=info->ordercxx . . $ $anonymous_type_f527c519943fbe69_1#order.; |
| 149 | look->lncxx . . $ $anonymous_type_64a11263da209325_0#ln.=info->barkmapcxx . . $ $anonymous_type_f527c519943fbe69_1#barkmap.; |
| 150 | look->vicxx . . $ $anonymous_type_64a11263da209325_0#vi.=info; |
| 151 | |
| 152 | look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap. = (int ** )_Melder_calloccxx . . $ _Melder_calloc(d58a73cf1dc24cbb).(2,sizeof(*look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.)); |
| 153 | |
| 154 | return look; |
| 155 | } |
| 156 | |
| 157 | static void *floor0_inverse1cxx . . $ floor0_inverse1(73e60fc02c6cc8c7).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_floorcxx . . $ vorbis_look_floor# *i){ |
| 158 | vorbis_look_floor0cxx . . $ vorbis_look_floor0# *look=(vorbis_look_floor0cxx . . $ vorbis_look_floor0# *)i; |
| 159 | vorbis_info_floor0cxx . . $ vorbis_info_floor0# *info=look->vicxx . . $ $anonymous_type_64a11263da209325_0#vi.; |
| 160 | int j,k; |
| 161 | |
| 162 | int ampraw=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(&vb->opbcxx . . $ vorbis_block#opb.,info->ampbitscxx . . $ $anonymous_type_f527c519943fbe69_1#ampbits.); |
| 163 | if(ampraw>0){ /* also handles the -1 out of data case */ |
| 164 | long maxval=(1<<info->ampbitscxx . . $ $anonymous_type_f527c519943fbe69_1#ampbits.)-1; |
| 165 | float amp=(float)ampraw/maxval*info->ampdBcxx . . $ $anonymous_type_f527c519943fbe69_1#ampdB.; |
| 166 | int booknum=oggpack_readcxx . . $ oggpack_read(e96bf1ebf62076a2).(&vb->opbcxx . . $ vorbis_block#opb.,ov_ilogcxx . . $ ov_ilog(4c679297bf94b9eb).(info->numbookscxx . . $ $anonymous_type_f527c519943fbe69_1#numbooks.)); |
| 167 | |
| 168 | if(booknum!=-1 && booknum<info->numbookscxx . . $ $anonymous_type_f527c519943fbe69_1#numbooks.){ /* be paranoid */ |
| 169 | codec_setup_infocxx . . $ codec_setup_info# *ci = (codec_setup_infocxx . . $ codec_setup_info# *) vb->vdcxx . . $ vorbis_block#vd.->vicxx . . $ vorbis_dsp_state#vi.->codec_setupcxx . . $ vorbis_info#codec_setup.; |
| 170 | codebookcxx . . $ codebook# *b=ci->fullbookscxx . . $ codec_setup_info#fullbooks.+info->bookscxx . . $ $anonymous_type_f527c519943fbe69_1#books.[booknum]; |
| 171 | float last=0.f; |
| 172 | |
| 173 | /* the additional b->dim is a guard against any possible stack |
| 174 | smash; b->dim is provably more than we can overflow the |
| 175 | vector */ |
| 176 | float *lsp = (float *) _vorbis_block_alloccxx . . $ _vorbis_block_alloc(339031f86f86193e).(vb,sizeof(*lsp)*(look->mcxx . . $ $anonymous_type_64a11263da209325_0#m.+b->dimcxx . . $ codebook#dim.+1)); |
| 177 | |
| 178 | if(vorbis_book_decodev_setcxx . . $ vorbis_book_decodev_set(809189a4d39ab48a).(b,lsp,&vb->opbcxx . . $ vorbis_block#opb.,look->mcxx . . $ $anonymous_type_64a11263da209325_0#m.)==-1)goto eop; |
| 179 | for(j=0;j<look->mcxx . . $ $anonymous_type_64a11263da209325_0#m.;){ |
| 180 | for(k=0;j<look->mcxx . . $ $anonymous_type_64a11263da209325_0#m. && k<b->dimcxx . . $ codebook#dim.;k++,j++)lsp[j]+=last; |
| 181 | last=lsp[j-1]; |
| 182 | } |
| 183 | |
| 184 | lsp[look->mcxx . . $ $anonymous_type_64a11263da209325_0#m.]=amp; |
| 185 | return(lsp); |
| 186 | } |
| 187 | } |
| 188 | eop: |
| 189 | return(nullptr); |
| 190 | } |
| 191 | |
| 192 | static int floor0_inverse2cxx . . $ floor0_inverse2(dae53d83734571e5).(vorbis_blockcxx . . $ vorbis_block# *vb,vorbis_look_floorcxx . . $ vorbis_look_floor# *i, |
| 193 | void *memo,float *out){ |
| 194 | vorbis_look_floor0cxx . . $ vorbis_look_floor0# *look=(vorbis_look_floor0cxx . . $ vorbis_look_floor0# *)i; |
| 195 | vorbis_info_floor0cxx . . $ vorbis_info_floor0# *info=look->vicxx . . $ $anonymous_type_64a11263da209325_0#vi.; |
| 196 | |
| 197 | floor0_map_lazy_initcxx . . $ floor0_map_lazy_init(351f3d434046d415).(vb,info,look); |
| 198 | |
| 199 | if(memo){ |
| 200 | float *lsp=(float *)memo; |
| 201 | float amp=lsp[look->mcxx . . $ $anonymous_type_64a11263da209325_0#m.]; |
| 202 | |
| 203 | /* take the coefficients back to a spectral envelope curve */ |
| 204 | vorbis_lsp_to_curvecxx . . $ vorbis_lsp_to_curve(3eee639f4942a09b).(out, |
| 205 | look->linearmapcxx . . $ $anonymous_type_64a11263da209325_0#linearmap.[vb->Wcxx . . $ vorbis_block#W.], |
| 206 | look->ncxx . . $ $anonymous_type_64a11263da209325_0#n.[vb->Wcxx . . $ vorbis_block#W.], |
| 207 | look->lncxx . . $ $anonymous_type_64a11263da209325_0#ln., |
| 208 | lsp,look->mcxx . . $ $anonymous_type_64a11263da209325_0#m.,amp,(float)info->ampdBcxx . . $ $anonymous_type_f527c519943fbe69_1#ampdB.); |
| 209 | return(1); |
| 210 | } |
| 211 | memset(out,0,sizeof(*out)*look->ncxx . . $ $anonymous_type_64a11263da209325_0#n.[vb->Wcxx . . $ vorbis_block#W.]); |
| 212 | return(0); |
| 213 | } |
| 214 | |
| 215 | /* export hooks */ |
| 216 | const vorbis_func_floorcxx . . $ vorbis_func_floor# floor0_exportbundlecxx . . $ floor0_exportbundle.={ |
| 217 | nullptr,&floor0_unpackcxx . . $ floor0_unpack(eeac8d4f838aca31).,&floor0_lookcxx . . $ floor0_look(f22d77a7569cfb00).,&floor0_free_infocxx . . $ floor0_free_info(5d22bdacc48458e8)., |
| 218 | &floor0_free_lookcxx . . $ floor0_free_look(5d22bdacc48458e8).,&floor0_inverse1cxx . . $ floor0_inverse1(73e60fc02c6cc8c7).,&floor0_inverse2cxx . . $ floor0_inverse2(dae53d83734571e5). |
| 219 | }; |