summaryrefslogtreecommitdiff
path: root/apps/codecs/libtremor/sharedbook.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libtremor/sharedbook.c')
-rw-r--r--apps/codecs/libtremor/sharedbook.c240
1 files changed, 120 insertions, 120 deletions
diff --git a/apps/codecs/libtremor/sharedbook.c b/apps/codecs/libtremor/sharedbook.c
index 853d1f5d61..10fae80c84 100644
--- a/apps/codecs/libtremor/sharedbook.c
+++ b/apps/codecs/libtremor/sharedbook.c
@@ -80,45 +80,45 @@ static ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
80 ogg_uint32_t entry=marker[length]; 80 ogg_uint32_t entry=marker[length];
81 81
82 /* when we claim a node for an entry, we also claim the nodes 82 /* when we claim a node for an entry, we also claim the nodes
83 below it (pruning off the imagined tree that may have dangled 83 below it (pruning off the imagined tree that may have dangled
84 from it) as well as blocking the use of any nodes directly 84 from it) as well as blocking the use of any nodes directly
85 above for leaves */ 85 above for leaves */
86 86
87 /* update ourself */ 87 /* update ourself */
88 if(length<32 && (entry>>length)){ 88 if(length<32 && (entry>>length)){
89 /* error condition; the lengths must specify an overpopulated tree */ 89 /* error condition; the lengths must specify an overpopulated tree */
90 _ogg_free(r); 90 _ogg_free(r);
91 return(NULL); 91 return(NULL);
92 } 92 }
93 r[count++]=entry; 93 r[count++]=entry;
94 94
95 /* Look to see if the next shorter marker points to the node 95 /* Look to see if the next shorter marker points to the node
96 above. if so, update it and repeat. */ 96 above. if so, update it and repeat. */
97 { 97 {
98 for(j=length;j>0;j--){ 98 for(j=length;j>0;j--){
99 99
100 if(marker[j]&1){ 100 if(marker[j]&1){
101 /* have to jump branches */ 101 /* have to jump branches */
102 if(j==1) 102 if(j==1)
103 marker[1]++; 103 marker[1]++;
104 else 104 else
105 marker[j]=marker[j-1]<<1; 105 marker[j]=marker[j-1]<<1;
106 break; /* invariant says next upper marker would already 106 break; /* invariant says next upper marker would already
107 have been moved if it was on the same path */ 107 have been moved if it was on the same path */
108 } 108 }
109 marker[j]++; 109 marker[j]++;
110 } 110 }
111 } 111 }
112 112
113 /* prune the tree; the implicit invariant says all the longer 113 /* prune the tree; the implicit invariant says all the longer
114 markers were dangling from our just-taken node. Dangle them 114 markers were dangling from our just-taken node. Dangle them
115 from our *new* node. */ 115 from our *new* node. */
116 for(j=length+1;j<33;j++) 116 for(j=length+1;j<33;j++)
117 if((marker[j]>>1) == entry){ 117 if((marker[j]>>1) == entry){
118 entry=marker[j]; 118 entry=marker[j];
119 marker[j]=marker[j-1]<<1; 119 marker[j]=marker[j-1]<<1;
120 }else 120 }else
121 break; 121 break;
122 }else 122 }else
123 if(sparsecount==0)count++; 123 if(sparsecount==0)count++;
124 } 124 }
@@ -134,7 +134,7 @@ static ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
134 134
135 if(sparsecount){ 135 if(sparsecount){
136 if(l[i]) 136 if(l[i])
137 r[count++]=temp; 137 r[count++]=temp;
138 }else 138 }else
139 r[count++]=temp; 139 r[count++]=temp;
140 } 140 }
@@ -162,9 +162,9 @@ long _book_maptype1_quantvals(const static_codebook *b){
162 return(vals); 162 return(vals);
163 }else{ 163 }else{
164 if(acc>b->entries){ 164 if(acc>b->entries){
165 vals--; 165 vals--;
166 }else{ 166 }else{
167 vals++; 167 vals++;
168 } 168 }
169 } 169 }
170 } 170 }
@@ -197,85 +197,85 @@ static ogg_int32_t *_book_unquantize(const static_codebook *b,int n,
197 switch(b->maptype){ 197 switch(b->maptype){
198 case 1: 198 case 1:
199 /* most of the time, entries%dimensions == 0, but we need to be 199 /* most of the time, entries%dimensions == 0, but we need to be
200 well defined. We define that the possible vales at each 200 well defined. We define that the possible vales at each
201 scalar is values == entries/dim. If entries%dim != 0, we'll 201 scalar is values == entries/dim. If entries%dim != 0, we'll
202 have 'too few' values (values*dim<entries), which means that 202 have 'too few' values (values*dim<entries), which means that
203 we'll have 'left over' entries; left over entries use zeroed 203 we'll have 'left over' entries; left over entries use zeroed
204 values (and are wasted). So don't generate codebooks like 204 values (and are wasted). So don't generate codebooks like
205 that */ 205 that */
206 quantvals=_book_maptype1_quantvals(b); 206 quantvals=_book_maptype1_quantvals(b);
207 for(j=0;j<b->entries;j++){ 207 for(j=0;j<b->entries;j++){
208 if((sparsemap && b->lengthlist[j]) || !sparsemap){ 208 if((sparsemap && b->lengthlist[j]) || !sparsemap){
209 ogg_int32_t last=0; 209 ogg_int32_t last=0;
210 int lastpoint=0; 210 int lastpoint=0;
211 int indexdiv=1; 211 int indexdiv=1;
212 for(k=0;k<b->dim;k++){ 212 for(k=0;k<b->dim;k++){
213 int index= (j/indexdiv)%quantvals; 213 int index= (j/indexdiv)%quantvals;
214 int point=0; 214 int point=0;
215 int val=VFLOAT_MULTI(delta,delpoint, 215 int val=VFLOAT_MULTI(delta,delpoint,
216 abs(b->quantlist[index]),&point); 216 abs(b->quantlist[index]),&point);
217 217
218 val=VFLOAT_ADD(mindel,minpoint,val,point,&point); 218 val=VFLOAT_ADD(mindel,minpoint,val,point,&point);
219 val=VFLOAT_ADD(last,lastpoint,val,point,&point); 219 val=VFLOAT_ADD(last,lastpoint,val,point,&point);
220 220
221 if(b->q_sequencep){ 221 if(b->q_sequencep){
222 last=val; 222 last=val;
223 lastpoint=point; 223 lastpoint=point;
224 } 224 }
225 225
226 if(sparsemap){ 226 if(sparsemap){
227 r[sparsemap[count]*b->dim+k]=val; 227 r[sparsemap[count]*b->dim+k]=val;
228 rp[sparsemap[count]*b->dim+k]=point; 228 rp[sparsemap[count]*b->dim+k]=point;
229 }else{ 229 }else{
230 r[count*b->dim+k]=val; 230 r[count*b->dim+k]=val;
231 rp[count*b->dim+k]=point; 231 rp[count*b->dim+k]=point;
232 } 232 }
233 if(*maxpoint<point)*maxpoint=point; 233 if(*maxpoint<point)*maxpoint=point;
234 indexdiv*=quantvals; 234 indexdiv*=quantvals;
235 } 235 }
236 count++; 236 count++;
237 } 237 }
238 238
239 } 239 }
240 break; 240 break;
241 case 2: 241 case 2:
242 for(j=0;j<b->entries;j++){ 242 for(j=0;j<b->entries;j++){
243 if((sparsemap && b->lengthlist[j]) || !sparsemap){ 243 if((sparsemap && b->lengthlist[j]) || !sparsemap){
244 ogg_int32_t last=0; 244 ogg_int32_t last=0;
245 int lastpoint=0; 245 int lastpoint=0;
246 246
247 for(k=0;k<b->dim;k++){ 247 for(k=0;k<b->dim;k++){
248 int point=0; 248 int point=0;
249 int val=VFLOAT_MULTI(delta,delpoint, 249 int val=VFLOAT_MULTI(delta,delpoint,
250 abs(b->quantlist[j*b->dim+k]),&point); 250 abs(b->quantlist[j*b->dim+k]),&point);
251 251
252 val=VFLOAT_ADD(mindel,minpoint,val,point,&point); 252 val=VFLOAT_ADD(mindel,minpoint,val,point,&point);
253 val=VFLOAT_ADD(last,lastpoint,val,point,&point); 253 val=VFLOAT_ADD(last,lastpoint,val,point,&point);
254 254
255 if(b->q_sequencep){ 255 if(b->q_sequencep){
256 last=val; 256 last=val;
257 lastpoint=point; 257 lastpoint=point;
258 } 258 }
259 259
260 if(sparsemap){ 260 if(sparsemap){
261 r[sparsemap[count]*b->dim+k]=val; 261 r[sparsemap[count]*b->dim+k]=val;
262 rp[sparsemap[count]*b->dim+k]=point; 262 rp[sparsemap[count]*b->dim+k]=point;
263 }else{ 263 }else{
264 r[count*b->dim+k]=val; 264 r[count*b->dim+k]=val;
265 rp[count*b->dim+k]=point; 265 rp[count*b->dim+k]=point;
266 } 266 }
267 if(*maxpoint<point)*maxpoint=point; 267 if(*maxpoint<point)*maxpoint=point;
268 } 268 }
269 count++; 269 count++;
270 } 270 }
271 } 271 }
272 break; 272 break;
273 } 273 }
274 274
275 for(j=0;j<n*b->dim;j++) 275 for(j=0;j<n*b->dim;j++)
276 if(rp[j]<*maxpoint) 276 if(rp[j]<*maxpoint)
277 r[j]>>=*maxpoint-rp[j]; 277 r[j]>>=*maxpoint-rp[j];
278 278
279 _ogg_free(rp); 279 _ogg_free(rp);
280 return(r); 280 return(r);
281 } 281 }
@@ -383,12 +383,12 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
383 383
384 for(n=0,i=0;i<s->entries;i++) 384 for(n=0,i=0;i<s->entries;i++)
385 if(s->lengthlist[i]>0) 385 if(s->lengthlist[i]>0)
386 c->dec_index[sortindex[n++]]=i; 386 c->dec_index[sortindex[n++]]=i;
387 387
388 c->dec_codelengths=(char *)_ogg_malloc(n*sizeof(*c->dec_codelengths)); 388 c->dec_codelengths=(char *)_ogg_malloc(n*sizeof(*c->dec_codelengths));
389 for(n=0,i=0;i<s->entries;i++) 389 for(n=0,i=0;i<s->entries;i++)
390 if(s->lengthlist[i]>0) 390 if(s->lengthlist[i]>0)
391 c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; 391 c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
392 392
393 _ogg_free(sortindex); 393 _ogg_free(sortindex);
394 c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */ 394 c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
@@ -401,11 +401,11 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
401 401
402 for(i=0;i<n;i++){ 402 for(i=0;i<n;i++){
403 if(c->dec_maxlength<c->dec_codelengths[i]) 403 if(c->dec_maxlength<c->dec_codelengths[i])
404 c->dec_maxlength=c->dec_codelengths[i]; 404 c->dec_maxlength=c->dec_codelengths[i];
405 if(c->dec_codelengths[i]<=c->dec_firsttablen){ 405 if(c->dec_codelengths[i]<=c->dec_firsttablen){
406 ogg_uint32_t orig=bitreverse(c->codelist[i]); 406 ogg_uint32_t orig=bitreverse(c->codelist[i]);
407 for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++) 407 for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
408 c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1; 408 c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
409 } 409 }
410 } 410 }
411 411
@@ -416,24 +416,24 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
416 long lo=0,hi=0; 416 long lo=0,hi=0;
417 417
418 for(i=0;i<tabn;i++){ 418 for(i=0;i<tabn;i++){
419 ogg_uint32_t word=i<<(32-c->dec_firsttablen); 419 ogg_uint32_t word=i<<(32-c->dec_firsttablen);
420 if(c->dec_firsttable[bitreverse(word)]==0){ 420 if(c->dec_firsttable[bitreverse(word)]==0){
421 while((lo+1)<n && c->codelist[lo+1]<=word)lo++; 421 while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
422 while( hi<n && word>=(c->codelist[hi]&mask))hi++; 422 while( hi<n && word>=(c->codelist[hi]&mask))hi++;
423 423
424 /* we only actually have 15 bits per hint to play with here. 424 /* we only actually have 15 bits per hint to play with here.
425 In order to overflow gracefully (nothing breaks, efficiency 425 In order to overflow gracefully (nothing breaks, efficiency
426 just drops), encode as the difference from the extremes. */ 426 just drops), encode as the difference from the extremes. */
427 { 427 {
428 unsigned long loval=lo; 428 unsigned long loval=lo;
429 unsigned long hival=n-hi; 429 unsigned long hival=n-hi;
430 430
431 if(loval>0x7fff)loval=0x7fff; 431 if(loval>0x7fff)loval=0x7fff;
432 if(hival>0x7fff)hival=0x7fff; 432 if(hival>0x7fff)hival=0x7fff;
433 c->dec_firsttable[bitreverse(word)]= 433 c->dec_firsttable[bitreverse(word)]=
434 0x80000000UL | (loval<<15) | hival; 434 0x80000000UL | (loval<<15) | hival;
435 } 435 }
436 } 436 }
437 } 437 }
438 } 438 }
439 } 439 }