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.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/apps/codecs/libtremor/sharedbook.c b/apps/codecs/libtremor/sharedbook.c
index edabf3ccb3..853d1f5d61 100644
--- a/apps/codecs/libtremor/sharedbook.c
+++ b/apps/codecs/libtremor/sharedbook.c
@@ -71,7 +71,7 @@ static ogg_int32_t _float32_unpack(long val,int *point){
71static ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ 71static ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
72 long i,j,count=0; 72 long i,j,count=0;
73 ogg_uint32_t marker[33]; 73 ogg_uint32_t marker[33];
74 ogg_uint32_t *r=(ogg_uint32_t *)ogg_tmpmalloc((sparsecount?sparsecount:n)*sizeof(*r)); 74 ogg_uint32_t *r=(ogg_uint32_t *)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
75 memset(marker,0,sizeof(marker)); 75 memset(marker,0,sizeof(marker));
76 76
77 for(i=0;i<n;i++){ 77 for(i=0;i<n;i++){
@@ -87,7 +87,7 @@ static ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
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;
@@ -188,9 +188,8 @@ static ogg_int32_t *_book_unquantize(const static_codebook *b,int n,
188 ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint); 188 ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint);
189 ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint); 189 ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint);
190 ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r)); 190 ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r));
191 int *rp=(int *)ogg_tmpcalloc(n*b->dim,sizeof(*rp)); 191 int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp));
192 192
193 memset(rp, 0, n*b->dim*sizeof(*rp));
194 *maxpoint=minpoint; 193 *maxpoint=minpoint;
195 194
196 /* maptype 1 and 2 both use a quantized value vector, but 195 /* maptype 1 and 2 both use a quantized value vector, but
@@ -277,7 +276,7 @@ static ogg_int32_t *_book_unquantize(const static_codebook *b,int n,
277 if(rp[j]<*maxpoint) 276 if(rp[j]<*maxpoint)
278 r[j]>>=*maxpoint-rp[j]; 277 r[j]>>=*maxpoint-rp[j];
279 278
280 /* _ogg_free(rp); */ 279 _ogg_free(rp);
281 return(r); 280 return(r);
282 } 281 }
283 return(NULL); 282 return(NULL);
@@ -325,7 +324,6 @@ static int sort32a(const void *a,const void *b){
325int vorbis_book_init_decode(codebook *c,const static_codebook *s){ 324int vorbis_book_init_decode(codebook *c,const static_codebook *s){
326 int i,j,n=0,tabn; 325 int i,j,n=0,tabn;
327 int *sortindex; 326 int *sortindex;
328 long pos = ogg_tmpmalloc_pos();
329 memset(c,0,sizeof(*c)); 327 memset(c,0,sizeof(*c));
330 328
331 /* count actually used entries */ 329 /* count actually used entries */
@@ -350,9 +348,13 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
350 348
351 /* perform sort */ 349 /* perform sort */
352 ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); 350 ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
353 ogg_uint32_t **codep=(ogg_uint32_t **)ogg_tmpmalloc(sizeof(*codep)*n); 351 ogg_uint32_t **codep=(ogg_uint32_t **)_ogg_malloc(sizeof(*codep)*n);
354 352
355 if(codes==NULL||codep==NULL)goto err_out; 353 if(codes==NULL||codep==NULL){
354 _ogg_free(codep);
355 _ogg_free(codes);
356 goto err_out;
357 }
356 358
357 for(i=0;i<n;i++){ 359 for(i=0;i<n;i++){
358 codes[i]=bitreverse(codes[i]); 360 codes[i]=bitreverse(codes[i]);
@@ -361,7 +363,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
361 363
362 qsort(codep,n,sizeof(*codep),sort32a); 364 qsort(codep,n,sizeof(*codep),sort32a);
363 365
364 sortindex=(int *)ogg_tmpmalloc(n*sizeof(*sortindex)); 366 sortindex=(int *)_ogg_malloc(n*sizeof(*sortindex));
365 c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); 367 c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist));
366 /* the index is a reverse index */ 368 /* the index is a reverse index */
367 for(i=0;i<n;i++){ 369 for(i=0;i<n;i++){
@@ -371,7 +373,8 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
371 373
372 for(i=0;i<n;i++) 374 for(i=0;i<n;i++)
373 c->codelist[sortindex[i]]=codes[i]; 375 c->codelist[sortindex[i]]=codes[i];
374 /* _ogg_free(codes); */ 376 _ogg_free(codep);
377 _ogg_free(codes);
375 378
376 379
377 380
@@ -387,6 +390,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
387 if(s->lengthlist[i]>0) 390 if(s->lengthlist[i]>0)
388 c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; 391 c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
389 392
393 _ogg_free(sortindex);
390 c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */ 394 c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
391 if(c->dec_firsttablen<5)c->dec_firsttablen=5; 395 if(c->dec_firsttablen<5)c->dec_firsttablen=5;
392 if(c->dec_firsttablen>8)c->dec_firsttablen=8; 396 if(c->dec_firsttablen>8)c->dec_firsttablen=8;
@@ -434,10 +438,8 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
434 } 438 }
435 } 439 }
436 440
437 ogg_tmpmalloc_free(pos);
438 return(0); 441 return(0);
439 err_out: 442 err_out:
440 ogg_tmpmalloc_free(pos);
441 vorbis_book_clear(c); 443 vorbis_book_clear(c);
442 return(-1); 444 return(-1);
443} 445}