| 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: PCM data vector blocking, windowing and dis/reassembly |
| 15 | |
| 16 | ********************************************************************/ |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | #include "ogg.h"cxx . . $ `<file>/mednafen/tremor/ogg.h`/ |
| 22 | #include "ivorbiscodec.h"cxx . . $ `<file>/mednafen/tremor/ivorbiscodec.h`/ |
| 23 | #include "codec_internal.h"cxx . . $ `<file>/mednafen/tremor/codec_internal.h`/ |
| 24 | |
| 25 | #include "window.h"cxx . . $ `<file>/mednafen/tremor/window.h`/ |
| 26 | #include "registry.h"cxx . . $ `<file>/mednafen/tremor/registry.h`/ |
| 27 | #include "misc.h"cxx . . $ `<file>/mednafen/tremor/misc.h`/ |
| 28 | |
| 29 | static int ilogcxx . . $ ilog(4c679297bf94b9eb).(unsigned int v){ |
| 30 | int ret=0; |
| 31 | if(v)--v; |
| 32 | while(v){ |
| 33 | ret++; |
| 34 | v>>=1; |
| 35 | } |
| 36 | return(ret); |
| 37 | } |
| 38 | |
| 39 | /* pcm accumulator examples (not exhaustive): |
| 40 | |
| 41 | <-------------- lW ----------------> |
| 42 | <--------------- W ----------------> |
| 43 | : .....|..... _______________ | |
| 44 | : .''' | '''_--- | |\ | |
| 45 | :.....''' |_____--- '''......| | \_______| |
| 46 | :.................|__________________|_______|__|______| |
| 47 | |<------ Sl ------>| > Sr < |endW |
| 48 | |beginSl |endSl | |endSr |
| 49 | |beginW |endlW |beginSr |
| 50 | |
| 51 | |
| 52 | |< lW >| |
| 53 | <--------------- W ----------------> |
| 54 | | | .. ______________ | |
| 55 | | | ' `/ | ---_ | |
| 56 | |___.'___/`. | ---_____| |
| 57 | |_______|__|_______|_________________| |
| 58 | | >|Sl|< |<------ Sr ----->|endW |
| 59 | | | |endSl |beginSr |endSr |
| 60 | |beginW | |endlW |
| 61 | mult[0] |beginSl mult[n] |
| 62 | |
| 63 | <-------------- lW -----------------> |
| 64 | |<--W-->| |
| 65 | : .............. ___ | | |
| 66 | : .''' |`/ \ | | |
| 67 | :.....''' |/`....\|...| |
| 68 | :.........................|___|___|___| |
| 69 | |Sl |Sr |endW |
| 70 | | | |endSr |
| 71 | | |beginSr |
| 72 | | |endSl |
| 73 | |beginSl |
| 74 | |beginW |
| 75 | */ |
| 76 | |
| 77 | /* block abstraction setup *********************************************/ |
| 78 | |
| 79 | #ifndef WORD_ALIGN |
| 80 | #define WORD_ALIGNcxx . . $ `mednafen/tremor/block.c:80:9`! 8 |
| 81 | #endif |
| 82 | |
| 83 | int vorbis_block_initcxx . . $ vorbis_block_init(c8f1c0cf9c31dd14).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *v, vorbis_blockcxx . . $ vorbis_block# *vb){ |
| 84 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(vb,0,sizeof(*vb)); |
| 85 | vb->vdcxx . . $ vorbis_block#vd.=v; |
| 86 | vb->localalloccxx . . $ vorbis_block#localalloc.=0; |
| 87 | vb->localstorecxx . . $ vorbis_block#localstore.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 88 | |
| 89 | return(0); |
| 90 | } |
| 91 | |
| 92 | void *_vorbis_block_alloccxx . . $ _vorbis_block_alloc(339031f86f86193e).(vorbis_blockcxx . . $ vorbis_block# *vb,long bytes){ |
| 93 | bytes=(bytes+(WORD_ALIGNcxx . . $ `mednafen/tremor/block.c:80:9`!-1)) & ~(WORD_ALIGNcxx . . $ `mednafen/tremor/block.c:80:9`!-1); |
| 94 | if(bytes+vb->localtopcxx . . $ vorbis_block#localtop.>vb->localalloccxx . . $ vorbis_block#localalloc.){ |
| 95 | /* can't just _ogg_realloc... there are outstanding pointers */ |
| 96 | if(vb->localstorecxx . . $ vorbis_block#localstore.){ |
| 97 | struct alloc_chaincxx . . $ alloc_chain# *link=(struct alloc_chaincxx . . $ alloc_chain# *)_ogg_malloccxx . . $ `mednafen/tremor/os_types.h:22:9`!(sizeof(*link)); |
| 98 | vb->totalusecxx . . $ vorbis_block#totaluse.+=vb->localtopcxx . . $ vorbis_block#localtop.; |
| 99 | link->nextcxx . . $ alloc_chain#next.=vb->reapcxx . . $ vorbis_block#reap.; |
| 100 | link->ptrcxx . . $ alloc_chain#ptr.=vb->localstorecxx . . $ vorbis_block#localstore.; |
| 101 | vb->reapcxx . . $ vorbis_block#reap.=link; |
| 102 | } |
| 103 | /* highly conservative */ |
| 104 | vb->localalloccxx . . $ vorbis_block#localalloc.=bytes; |
| 105 | vb->localstorecxx . . $ vorbis_block#localstore.=_ogg_malloccxx . . $ `mednafen/tremor/os_types.h:22:9`!(vb->localalloccxx . . $ vorbis_block#localalloc.); |
| 106 | vb->localtopcxx . . $ vorbis_block#localtop.=0; |
| 107 | } |
| 108 | { |
| 109 | void *ret=(void *)(((char *)vb->localstorecxx . . $ vorbis_block#localstore.)+vb->localtopcxx . . $ vorbis_block#localtop.); |
| 110 | vb->localtopcxx . . $ vorbis_block#localtop.+=bytes; |
| 111 | return ret; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /* reap the chain, pull the ripcord */ |
| 116 | void _vorbis_block_ripcordcxx . . $ _vorbis_block_ripcord(b02413cf866c4e1f).(vorbis_blockcxx . . $ vorbis_block# *vb){ |
| 117 | /* reap the chain */ |
| 118 | struct alloc_chaincxx . . $ alloc_chain# *reap=vb->reapcxx . . $ vorbis_block#reap.; |
| 119 | while(reap){ |
| 120 | struct alloc_chaincxx . . $ alloc_chain# *next=reap->nextcxx . . $ alloc_chain#next.; |
| 121 | _ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(reap->ptrcxx . . $ alloc_chain#ptr.); |
| 122 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(reap,0,sizeof(*reap)); |
| 123 | _ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(reap); |
| 124 | reap=next; |
| 125 | } |
| 126 | /* consolidate storage */ |
| 127 | if(vb->totalusecxx . . $ vorbis_block#totaluse.){ |
| 128 | vb->localstorecxx . . $ vorbis_block#localstore.=_ogg_realloccxx . . $ `mednafen/tremor/os_types.h:24:9`!(vb->localstorecxx . . $ vorbis_block#localstore.,vb->totalusecxx . . $ vorbis_block#totaluse.+vb->localalloccxx . . $ vorbis_block#localalloc.); |
| 129 | vb->localalloccxx . . $ vorbis_block#localalloc.+=vb->totalusecxx . . $ vorbis_block#totaluse.; |
| 130 | vb->totalusecxx . . $ vorbis_block#totaluse.=0; |
| 131 | } |
| 132 | |
| 133 | /* pull the ripcord */ |
| 134 | vb->localtopcxx . . $ vorbis_block#localtop.=0; |
| 135 | vb->reapcxx . . $ vorbis_block#reap.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 136 | } |
| 137 | |
| 138 | int vorbis_block_clearcxx . . $ vorbis_block_clear(e7ca6336a14cf342).(vorbis_blockcxx . . $ vorbis_block# *vb){ |
| 139 | _vorbis_block_ripcordcxx . . $ _vorbis_block_ripcord(b02413cf866c4e1f).(vb); |
| 140 | if(vb->localstorecxx . . $ vorbis_block#localstore.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(vb->localstorecxx . . $ vorbis_block#localstore.); |
| 141 | |
| 142 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(vb,0,sizeof(*vb)); |
| 143 | return(0); |
| 144 | } |
| 145 | |
| 146 | static int _vds_initcxx . . $ _vds_init(eac5c897194134f0).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *v,vorbis_infocxx . . $ vorbis_info# *vi){ |
| 147 | int i; |
| 148 | codec_setup_infocxx . . $ codec_setup_info# *ci=(codec_setup_infocxx . . $ codec_setup_info# *)vi->codec_setupcxx . . $ vorbis_info#codec_setup.; |
| 149 | private_statecxx . . $ private_state# *b=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 150 | |
| 151 | if(ci==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return 1; |
| 152 | |
| 153 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(v,0,sizeof(*v)); |
| 154 | b=(private_statecxx . . $ private_state# *)(v->backend_statecxx . . $ vorbis_dsp_state#backend_state.=_ogg_calloccxx . . $ `mednafen/tremor/os_types.h:23:9`!(1,sizeof(*b))); |
| 155 | |
| 156 | v->vicxx . . $ vorbis_dsp_state#vi.=vi; |
| 157 | b->modebitscxx . . $ private_state#modebits.=ilogcxx . . $ ilog(4c679297bf94b9eb).(ci->modescxx . . $ codec_setup_info#modes.); |
| 158 | |
| 159 | /* Vorbis I uses only window type 0 */ |
| 160 | b->windowcxx . . $ private_state#window.[0]=_vorbis_windowcxx . . $ _vorbis_window(67b6191fc2d12f59).(0,ci->blocksizescxx . . $ codec_setup_info#blocksizes.[0]/2); |
| 161 | b->windowcxx . . $ private_state#window.[1]=_vorbis_windowcxx . . $ _vorbis_window(67b6191fc2d12f59).(0,ci->blocksizescxx . . $ codec_setup_info#blocksizes.[1]/2); |
| 162 | |
| 163 | /* finish the codebooks */ |
| 164 | if(!ci->fullbookscxx . . $ codec_setup_info#fullbooks.){ |
| 165 | ci->fullbookscxx . . $ codec_setup_info#fullbooks.=(codebookcxx . . $ codebook# *)_ogg_calloccxx . . $ `mednafen/tremor/os_types.h:23:9`!(ci->bookscxx . . $ codec_setup_info#books.,sizeof(*ci->fullbookscxx . . $ codec_setup_info#fullbooks.)); |
| 166 | for(i=0;i<ci->bookscxx . . $ codec_setup_info#books.;i++){ |
| 167 | if(ci->book_paramcxx . . $ codec_setup_info#book_param.[i]==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 168 | goto abort_books; |
| 169 | if(vorbis_book_init_decodecxx . . $ vorbis_book_init_decode(cdfb7b438ddf71a0).(ci->fullbookscxx . . $ codec_setup_info#fullbooks.+i,ci->book_paramcxx . . $ codec_setup_info#book_param.[i])) |
| 170 | goto abort_books; |
| 171 | /* decode codebooks are now standalone after init */ |
| 172 | vorbis_staticbook_destroycxx . . $ vorbis_staticbook_destroy(50dc96045c2ba69d).(ci->book_paramcxx . . $ codec_setup_info#book_param.[i]); |
| 173 | ci->book_paramcxx . . $ codec_setup_info#book_param.[i]=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | v->pcm_storagecxx . . $ vorbis_dsp_state#pcm_storage.=ci->blocksizescxx . . $ codec_setup_info#blocksizes.[1]; |
| 178 | v->pcmcxx . . $ vorbis_dsp_state#pcm.=(ogg_int32_tcxx . . $ ogg_int32_t# **)_ogg_malloccxx . . $ `mednafen/tremor/os_types.h:22:9`!(vi->channelscxx . . $ vorbis_info#channels.*sizeof(*v->pcmcxx . . $ vorbis_dsp_state#pcm.)); |
| 179 | v->pcmretcxx . . $ vorbis_dsp_state#pcmret.=(ogg_int32_tcxx . . $ ogg_int32_t# **)_ogg_malloccxx . . $ `mednafen/tremor/os_types.h:22:9`!(vi->channelscxx . . $ vorbis_info#channels.*sizeof(*v->pcmretcxx . . $ vorbis_dsp_state#pcmret.)); |
| 180 | for(i=0;i<vi->channelscxx . . $ vorbis_info#channels.;i++) |
| 181 | v->pcmcxx . . $ vorbis_dsp_state#pcm.[i]=(ogg_int32_tcxx . . $ ogg_int32_t# *)_ogg_calloccxx . . $ `mednafen/tremor/os_types.h:23:9`!(v->pcm_storagecxx . . $ vorbis_dsp_state#pcm_storage.,sizeof(*v->pcmcxx . . $ vorbis_dsp_state#pcm.[i])); |
| 182 | |
| 183 | /* all 1 (large block) or 0 (small block) */ |
| 184 | /* explicitly set for the sake of clarity */ |
| 185 | v->lWcxx . . $ vorbis_dsp_state#lW.=0; /* previous window size */ |
| 186 | v->Wcxx . . $ vorbis_dsp_state#W.=0; /* current window size */ |
| 187 | |
| 188 | /* initialize all the mapping/backend lookups */ |
| 189 | b->modecxx . . $ private_state#mode.=(vorbis_look_mappingcxx . . $ vorbis_look_mapping# **)_ogg_calloccxx . . $ `mednafen/tremor/os_types.h:23:9`!(ci->modescxx . . $ codec_setup_info#modes.,sizeof(*b->modecxx . . $ private_state#mode.)); |
| 190 | for(i=0;i<ci->modescxx . . $ codec_setup_info#modes.;i++){ |
| 191 | int mapnum=ci->mode_paramcxx . . $ codec_setup_info#mode_param.[i]->mappingcxx . . $ $anonymous_type_310d37d35ac071a0_0#mapping.; |
| 192 | int maptype=ci->map_typecxx . . $ codec_setup_info#map_type.[mapnum]; |
| 193 | b->modecxx . . $ private_state#mode.[i]=_mapping_Pcxx . . $ _mapping_P.[maptype]->lookcxx . . $ $anonymous_type_c7374eb872c22577_4#look.(v,ci->mode_paramcxx . . $ codec_setup_info#mode_param.[i], |
| 194 | ci->map_paramcxx . . $ codec_setup_info#map_param.[mapnum]); |
| 195 | } |
| 196 | return 0; |
| 197 | abort_books: |
| 198 | for(i=0;i<ci->bookscxx . . $ codec_setup_info#books.;i++){ |
| 199 | if(ci->book_paramcxx . . $ codec_setup_info#book_param.[i]!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){ |
| 200 | vorbis_staticbook_destroycxx . . $ vorbis_staticbook_destroy(50dc96045c2ba69d).(ci->book_paramcxx . . $ codec_setup_info#book_param.[i]); |
| 201 | ci->book_paramcxx . . $ codec_setup_info#book_param.[i]=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 202 | } |
| 203 | } |
| 204 | vorbis_dsp_clearcxx . . $ vorbis_dsp_clear(1841c7801a59e076).(v); |
| 205 | return -1; |
| 206 | } |
| 207 | |
| 208 | int vorbis_synthesis_restartcxx . . $ vorbis_synthesis_restart(6cb399ae167b2de8).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *v){ |
| 209 | vorbis_infocxx . . $ vorbis_info# *vi=v->vicxx . . $ vorbis_dsp_state#vi.; |
| 210 | codec_setup_infocxx . . $ codec_setup_info# *ci; |
| 211 | |
| 212 | if(!v->backend_statecxx . . $ vorbis_dsp_state#backend_state.)return -1; |
| 213 | if(!vi)return -1; |
| 214 | ci=vi->codec_setupcxx . . $ vorbis_info#codec_setup.; |
| 215 | if(!ci)return -1; |
| 216 | |
| 217 | v->centerWcxx . . $ vorbis_dsp_state#centerW.=ci->blocksizescxx . . $ codec_setup_info#blocksizes.[1]/2; |
| 218 | v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.=v->centerWcxx . . $ vorbis_dsp_state#centerW.; |
| 219 | |
| 220 | v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.=-1; |
| 221 | v->granuleposcxx . . $ vorbis_dsp_state#granulepos.=-1; |
| 222 | v->sequencecxx . . $ vorbis_dsp_state#sequence.=-1; |
| 223 | ((private_statecxx . . $ private_state# *)(v->backend_statecxx . . $ vorbis_dsp_state#backend_state.))->sample_countcxx . . $ private_state#sample_count.=-1; |
| 224 | |
| 225 | return(0); |
| 226 | } |
| 227 | |
| 228 | int vorbis_synthesis_initcxx . . $ vorbis_synthesis_init(eac5c897194134f0).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *v,vorbis_infocxx . . $ vorbis_info# *vi){ |
| 229 | if(_vds_initcxx . . $ _vds_init(eac5c897194134f0).(v,vi))return 1; |
| 230 | vorbis_synthesis_restartcxx . . $ vorbis_synthesis_restart(6cb399ae167b2de8).(v); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | void vorbis_dsp_clearcxx . . $ vorbis_dsp_clear(1841c7801a59e076).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *v){ |
| 236 | int i; |
| 237 | if(v){ |
| 238 | vorbis_infocxx . . $ vorbis_info# *vi=v->vicxx . . $ vorbis_dsp_state#vi.; |
| 239 | codec_setup_infocxx . . $ codec_setup_info# *ci=(codec_setup_infocxx . . $ codec_setup_info# *)(vi?vi->codec_setupcxx . . $ vorbis_info#codec_setup.:NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 240 | private_statecxx . . $ private_state# *b=(private_statecxx . . $ private_state# *)v->backend_statecxx . . $ vorbis_dsp_state#backend_state.; |
| 241 | |
| 242 | if(v->pcmcxx . . $ vorbis_dsp_state#pcm.){ |
| 243 | for(i=0;i<vi->channelscxx . . $ vorbis_info#channels.;i++) |
| 244 | if(v->pcmcxx . . $ vorbis_dsp_state#pcm.[i])_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(v->pcmcxx . . $ vorbis_dsp_state#pcm.[i]); |
| 245 | _ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(v->pcmcxx . . $ vorbis_dsp_state#pcm.); |
| 246 | if(v->pcmretcxx . . $ vorbis_dsp_state#pcmret.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(v->pcmretcxx . . $ vorbis_dsp_state#pcmret.); |
| 247 | } |
| 248 | |
| 249 | /* free mode lookups; these are actually vorbis_look_mapping structs */ |
| 250 | if(ci){ |
| 251 | for(i=0;i<ci->modescxx . . $ codec_setup_info#modes.;i++){ |
| 252 | int mapnum=ci->mode_paramcxx . . $ codec_setup_info#mode_param.[i]->mappingcxx . . $ $anonymous_type_310d37d35ac071a0_0#mapping.; |
| 253 | int maptype=ci->map_typecxx . . $ codec_setup_info#map_type.[mapnum]; |
| 254 | if(b && b->modecxx . . $ private_state#mode.)_mapping_Pcxx . . $ _mapping_P.[maptype]->free_lookcxx . . $ $anonymous_type_c7374eb872c22577_4#free_look.(b->modecxx . . $ private_state#mode.[i]); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | if(b){ |
| 259 | if(b->modecxx . . $ private_state#mode.)_ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b->modecxx . . $ private_state#mode.); |
| 260 | _ogg_freecxx . . $ `mednafen/tremor/os_types.h:25:9`!(b); |
| 261 | } |
| 262 | |
| 263 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(v,0,sizeof(*v)); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | /* Unlike in analysis, the window is only partially applied for each |
| 268 | block. The time domain envelope is not yet handled at the point of |
| 269 | calling (as it relies on the previous block). */ |
| 270 | |
| 271 | int vorbis_synthesis_blockincxx . . $ vorbis_synthesis_blockin(c8f1c0cf9c31dd14).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *v,vorbis_blockcxx . . $ vorbis_block# *vb){ |
| 272 | vorbis_infocxx . . $ vorbis_info# *vi=v->vicxx . . $ vorbis_dsp_state#vi.; |
| 273 | codec_setup_infocxx . . $ codec_setup_info# *ci=(codec_setup_infocxx . . $ codec_setup_info# *)vi->codec_setupcxx . . $ vorbis_info#codec_setup.; |
| 274 | private_statecxx . . $ private_state# *b=v->backend_statecxx . . $ vorbis_dsp_state#backend_state.; |
| 275 | int i,j; |
| 276 | |
| 277 | if(v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.>v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned. && v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.!=-1)return(OV_EINVALcxx . . $ `mednafen/tremor/ivorbiscodec.h:190:9`!); |
| 278 | |
| 279 | v->lWcxx . . $ vorbis_dsp_state#lW.=v->Wcxx . . $ vorbis_dsp_state#W.; |
| 280 | v->Wcxx . . $ vorbis_dsp_state#W.=vb->Wcxx . . $ vorbis_block#W.; |
| 281 | v->nWcxx . . $ vorbis_dsp_state#nW.=-1; |
| 282 | |
| 283 | if((v->sequencecxx . . $ vorbis_dsp_state#sequence.==-1)|| |
| 284 | (v->sequencecxx . . $ vorbis_dsp_state#sequence.+1 != vb->sequencecxx . . $ vorbis_block#sequence.)){ |
| 285 | v->granuleposcxx . . $ vorbis_dsp_state#granulepos.=-1; /* out of sequence; lose count */ |
| 286 | b->sample_countcxx . . $ private_state#sample_count.=-1; |
| 287 | } |
| 288 | |
| 289 | v->sequencecxx . . $ vorbis_dsp_state#sequence.=vb->sequencecxx . . $ vorbis_block#sequence.; |
| 290 | |
| 291 | if(vb->pcmcxx . . $ vorbis_block#pcm.){ /* no pcm to process if vorbis_synthesis_trackonly |
| 292 | was called on block */ |
| 293 | int n=ci->blocksizescxx . . $ codec_setup_info#blocksizes.[v->Wcxx . . $ vorbis_dsp_state#W.]/2; |
| 294 | int n0=ci->blocksizescxx . . $ codec_setup_info#blocksizes.[0]/2; |
| 295 | int n1=ci->blocksizescxx . . $ codec_setup_info#blocksizes.[1]/2; |
| 296 | |
| 297 | int thisCenter; |
| 298 | int prevCenter; |
| 299 | |
| 300 | if(v->centerWcxx . . $ vorbis_dsp_state#centerW.){ |
| 301 | thisCenter=n1; |
| 302 | prevCenter=0; |
| 303 | }else{ |
| 304 | thisCenter=0; |
| 305 | prevCenter=n1; |
| 306 | } |
| 307 | |
| 308 | /* v->pcm is now used like a two-stage double buffer. We don't want |
| 309 | to have to constantly shift *or* adjust memory usage. Don't |
| 310 | accept a new block until the old is shifted out */ |
| 311 | |
| 312 | /* overlap/add PCM */ |
| 313 | |
| 314 | for(j=0;j<vi->channelscxx . . $ vorbis_info#channels.;j++){ |
| 315 | /* the overlap/add section */ |
| 316 | if(v->lWcxx . . $ vorbis_dsp_state#lW.){ |
| 317 | if(v->Wcxx . . $ vorbis_dsp_state#W.){ |
| 318 | /* large/large */ |
| 319 | ogg_int32_tcxx . . $ ogg_int32_t# *pcm=v->pcmcxx . . $ vorbis_dsp_state#pcm.[j]+prevCenter; |
| 320 | ogg_int32_tcxx . . $ ogg_int32_t# *p=vb->pcmcxx . . $ vorbis_block#pcm.[j]; |
| 321 | for(i=0;i<n1;i++) |
| 322 | pcm[i]+=p[i]; |
| 323 | }else{ |
| 324 | /* large/small */ |
| 325 | ogg_int32_tcxx . . $ ogg_int32_t# *pcm=v->pcmcxx . . $ vorbis_dsp_state#pcm.[j]+prevCenter+n1/2-n0/2; |
| 326 | ogg_int32_tcxx . . $ ogg_int32_t# *p=vb->pcmcxx . . $ vorbis_block#pcm.[j]; |
| 327 | for(i=0;i<n0;i++) |
| 328 | pcm[i]+=p[i]; |
| 329 | } |
| 330 | }else{ |
| 331 | if(v->Wcxx . . $ vorbis_dsp_state#W.){ |
| 332 | /* small/large */ |
| 333 | ogg_int32_tcxx . . $ ogg_int32_t# *pcm=v->pcmcxx . . $ vorbis_dsp_state#pcm.[j]+prevCenter; |
| 334 | ogg_int32_tcxx . . $ ogg_int32_t# *p=vb->pcmcxx . . $ vorbis_block#pcm.[j]+n1/2-n0/2; |
| 335 | for(i=0;i<n0;i++) |
| 336 | pcm[i]+=p[i]; |
| 337 | for(;i<n1/2+n0/2;i++) |
| 338 | pcm[i]=p[i]; |
| 339 | }else{ |
| 340 | /* small/small */ |
| 341 | ogg_int32_tcxx . . $ ogg_int32_t# *pcm=v->pcmcxx . . $ vorbis_dsp_state#pcm.[j]+prevCenter; |
| 342 | ogg_int32_tcxx . . $ ogg_int32_t# *p=vb->pcmcxx . . $ vorbis_block#pcm.[j]; |
| 343 | for(i=0;i<n0;i++) |
| 344 | pcm[i]+=p[i]; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /* the copy section */ |
| 349 | { |
| 350 | ogg_int32_tcxx . . $ ogg_int32_t# *pcm=v->pcmcxx . . $ vorbis_dsp_state#pcm.[j]+thisCenter; |
| 351 | ogg_int32_tcxx . . $ ogg_int32_t# *p=vb->pcmcxx . . $ vorbis_block#pcm.[j]+n; |
| 352 | for(i=0;i<n;i++) |
| 353 | pcm[i]=p[i]; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | if(v->centerWcxx . . $ vorbis_dsp_state#centerW.) |
| 358 | v->centerWcxx . . $ vorbis_dsp_state#centerW.=0; |
| 359 | else |
| 360 | v->centerWcxx . . $ vorbis_dsp_state#centerW.=n1; |
| 361 | |
| 362 | /* deal with initial packet state; we do this using the explicit |
| 363 | pcm_returned==-1 flag otherwise we're sensitive to first block |
| 364 | being short or long */ |
| 365 | |
| 366 | if(v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.==-1){ |
| 367 | v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.=thisCenter; |
| 368 | v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.=thisCenter; |
| 369 | }else{ |
| 370 | v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.=prevCenter; |
| 371 | v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.=prevCenter+ |
| 372 | ci->blocksizescxx . . $ codec_setup_info#blocksizes.[v->lWcxx . . $ vorbis_dsp_state#lW.]/4+ |
| 373 | ci->blocksizescxx . . $ codec_setup_info#blocksizes.[v->Wcxx . . $ vorbis_dsp_state#W.]/4; |
| 374 | } |
| 375 | |
| 376 | } |
| 377 | |
| 378 | /* track the frame number... This is for convenience, but also |
| 379 | making sure our last packet doesn't end with added padding. If |
| 380 | the last packet is partial, the number of samples we'll have to |
| 381 | return will be past the vb->granulepos. |
| 382 | |
| 383 | This is not foolproof! It will be confused if we begin |
| 384 | decoding at the last page after a seek or hole. In that case, |
| 385 | we don't have a starting point to judge where the last frame |
| 386 | is. For this reason, vorbisfile will always try to make sure |
| 387 | it reads the last two marked pages in proper sequence */ |
| 388 | |
| 389 | if(b->sample_countcxx . . $ private_state#sample_count.==-1){ |
| 390 | b->sample_countcxx . . $ private_state#sample_count.=0; |
| 391 | }else{ |
| 392 | b->sample_countcxx . . $ private_state#sample_count.+=ci->blocksizescxx . . $ codec_setup_info#blocksizes.[v->lWcxx . . $ vorbis_dsp_state#lW.]/4+ci->blocksizescxx . . $ codec_setup_info#blocksizes.[v->Wcxx . . $ vorbis_dsp_state#W.]/4; |
| 393 | } |
| 394 | |
| 395 | if(v->granuleposcxx . . $ vorbis_dsp_state#granulepos.==-1){ |
| 396 | if(vb->granuleposcxx . . $ vorbis_block#granulepos.!=-1){ /* only set if we have a position to set to */ |
| 397 | |
| 398 | v->granuleposcxx . . $ vorbis_dsp_state#granulepos.=vb->granuleposcxx . . $ vorbis_block#granulepos.; |
| 399 | |
| 400 | /* is this a short page? */ |
| 401 | if(b->sample_countcxx . . $ private_state#sample_count.>v->granuleposcxx . . $ vorbis_dsp_state#granulepos.){ |
| 402 | /* corner case; if this is both the first and last audio page, |
| 403 | then spec says the end is cut, not beginning */ |
| 404 | long extra=b->sample_countcxx . . $ private_state#sample_count.-vb->granuleposcxx . . $ vorbis_block#granulepos.; |
| 405 | |
| 406 | /* we use ogg_int64_t for granule positions because a |
| 407 | uint64 isn't universally available. Unfortunately, |
| 408 | that means granposes can be 'negative' and result in |
| 409 | extra being negative */ |
| 410 | if(extra<0) |
| 411 | extra=0; |
| 412 | |
| 413 | if(vb->eofflagcxx . . $ vorbis_block#eofflag.){ |
| 414 | /* trim the end */ |
| 415 | /* no preceeding granulepos; assume we started at zero (we'd |
| 416 | have to in a short single-page stream) */ |
| 417 | /* granulepos could be -1 due to a seek, but that would result |
| 418 | in a long coun`t, not short count */ |
| 419 | |
| 420 | /* Guard against corrupt/malicious frames that set EOP and |
| 421 | a backdated granpos; don't rewind more samples than we |
| 422 | actually have */ |
| 423 | if(extra > v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current. - v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.) |
| 424 | extra = v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current. - v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.; |
| 425 | |
| 426 | v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.-=extra; |
| 427 | }else{ |
| 428 | /* trim the beginning */ |
| 429 | v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.+=extra; |
| 430 | if(v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.>v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.) |
| 431 | v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.=v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.; |
| 432 | } |
| 433 | |
| 434 | } |
| 435 | |
| 436 | } |
| 437 | }else{ |
| 438 | v->granuleposcxx . . $ vorbis_dsp_state#granulepos.+=ci->blocksizescxx . . $ codec_setup_info#blocksizes.[v->lWcxx . . $ vorbis_dsp_state#lW.]/4+ci->blocksizescxx . . $ codec_setup_info#blocksizes.[v->Wcxx . . $ vorbis_dsp_state#W.]/4; |
| 439 | if(vb->granuleposcxx . . $ vorbis_block#granulepos.!=-1 && v->granuleposcxx . . $ vorbis_dsp_state#granulepos.!=vb->granuleposcxx . . $ vorbis_block#granulepos.){ |
| 440 | |
| 441 | if(v->granuleposcxx . . $ vorbis_dsp_state#granulepos.>vb->granuleposcxx . . $ vorbis_block#granulepos.){ |
| 442 | long extra=v->granuleposcxx . . $ vorbis_dsp_state#granulepos.-vb->granuleposcxx . . $ vorbis_block#granulepos.; |
| 443 | |
| 444 | if(extra) |
| 445 | if(vb->eofflagcxx . . $ vorbis_block#eofflag.){ |
| 446 | /* partial last frame. Strip the extra samples off */ |
| 447 | |
| 448 | /* Guard against corrupt/malicious frames that set EOP and |
| 449 | a backdated granpos; don't rewind more samples than we |
| 450 | actually have */ |
| 451 | if(extra > v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current. - v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.) |
| 452 | extra = v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current. - v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.; |
| 453 | |
| 454 | /* we use ogg_int64_t for granule positions because a |
| 455 | uint64 isn't universally available. Unfortunately, |
| 456 | that means granposes can be 'negative' and result in |
| 457 | extra being negative */ |
| 458 | if(extra<0) |
| 459 | extra=0; |
| 460 | |
| 461 | v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.-=extra; |
| 462 | |
| 463 | } /* else {Shouldn't happen *unless* the bitstream is out of |
| 464 | spec. Either way, believe the bitstream } */ |
| 465 | } /* else {Shouldn't happen *unless* the bitstream is out of |
| 466 | spec. Either way, believe the bitstream } */ |
| 467 | v->granuleposcxx . . $ vorbis_dsp_state#granulepos.=vb->granuleposcxx . . $ vorbis_block#granulepos.; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /* Update, cleanup */ |
| 472 | |
| 473 | if(vb->eofflagcxx . . $ vorbis_block#eofflag.)v->eofflagcxx . . $ vorbis_dsp_state#eofflag.=1; |
| 474 | return(0); |
| 475 | } |
| 476 | |
| 477 | /* pcm==NULL indicates we just want the pending samples, no more */ |
| 478 | int vorbis_synthesis_pcmoutcxx . . $ vorbis_synthesis_pcmout(a5862dcc143b250).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *v,ogg_int32_tcxx . . $ ogg_int32_t# ***pcm){ |
| 479 | vorbis_infocxx . . $ vorbis_info# *vi=v->vicxx . . $ vorbis_dsp_state#vi.; |
| 480 | if(v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.>-1 && v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.<v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.){ |
| 481 | if(pcm){ |
| 482 | int i; |
| 483 | for(i=0;i<vi->channelscxx . . $ vorbis_info#channels.;i++) |
| 484 | v->pcmretcxx . . $ vorbis_dsp_state#pcmret.[i]=v->pcmcxx . . $ vorbis_dsp_state#pcm.[i]+v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.; |
| 485 | *pcm=v->pcmretcxx . . $ vorbis_dsp_state#pcmret.; |
| 486 | } |
| 487 | return(v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.-v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.); |
| 488 | } |
| 489 | return(0); |
| 490 | } |
| 491 | |
| 492 | int vorbis_synthesis_readcxx . . $ vorbis_synthesis_read(462060a1f4fafeae).(vorbis_dsp_statecxx . . $ vorbis_dsp_state# *v,int bytes){ |
| 493 | if(bytes && v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.+bytes>v->pcm_currentcxx . . $ vorbis_dsp_state#pcm_current.)return(OV_EINVALcxx . . $ `mednafen/tremor/ivorbiscodec.h:190:9`!); |
| 494 | v->pcm_returnedcxx . . $ vorbis_dsp_state#pcm_returned.+=bytes; |
| 495 | return(0); |
| 496 | } |
| 497 |