diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/codecs/Tremor/sharedbook.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/apps/codecs/Tremor/sharedbook.c b/apps/codecs/Tremor/sharedbook.c index e163f3dc12..b61b6d0997 100644 --- a/apps/codecs/Tremor/sharedbook.c +++ b/apps/codecs/Tremor/sharedbook.c | |||
@@ -30,6 +30,12 @@ | |||
30 | */ | 30 | */ |
31 | #define BOOK_INIT_MAXSIZE 3072 | 31 | #define BOOK_INIT_MAXSIZE 3072 |
32 | 32 | ||
33 | /* Max value in static_codebook.dim we expect to find in _book_unquantize. | ||
34 | * Used to avoid some temporary allocations. Again, enough for some test | ||
35 | * files... | ||
36 | */ | ||
37 | #define BOOK_DIM_MAX 4 | ||
38 | |||
33 | /**** pack/unpack helpers ******************************************/ | 39 | /**** pack/unpack helpers ******************************************/ |
34 | int _ilog(unsigned int v){ | 40 | int _ilog(unsigned int v){ |
35 | int ret=0; | 41 | int ret=0; |
@@ -189,13 +195,19 @@ ogg_int32_t *_book_unquantize(const static_codebook *b,int n,int *sparsemap, | |||
189 | int *maxpoint){ | 195 | int *maxpoint){ |
190 | long j,k,count=0; | 196 | long j,k,count=0; |
191 | if(b->maptype==1 || b->maptype==2){ | 197 | if(b->maptype==1 || b->maptype==2){ |
198 | /* Static buffer to avoid temporary calloc, which Rockbox (currently) | ||
199 | * doesn't handle well | ||
200 | */ | ||
201 | static int rp_buffer[BOOK_INIT_MAXSIZE*BOOK_DIM_MAX]; | ||
192 | int quantvals; | 202 | int quantvals; |
193 | int minpoint,delpoint; | 203 | int minpoint,delpoint; |
194 | ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint); | 204 | ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint); |
195 | ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint); | 205 | ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint); |
196 | ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r)); | 206 | ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r)); |
197 | int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp)); | 207 | /* int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp)); */ |
208 | int* rp=rp_buffer; | ||
198 | 209 | ||
210 | memset(rp, 0, n*b->dim*sizeof(*rp)); | ||
199 | *maxpoint=minpoint; | 211 | *maxpoint=minpoint; |
200 | 212 | ||
201 | /* maptype 1 and 2 both use a quantized value vector, but | 213 | /* maptype 1 and 2 both use a quantized value vector, but |
@@ -282,7 +294,7 @@ ogg_int32_t *_book_unquantize(const static_codebook *b,int n,int *sparsemap, | |||
282 | if(rp[j]<*maxpoint) | 294 | if(rp[j]<*maxpoint) |
283 | r[j]>>=*maxpoint-rp[j]; | 295 | r[j]>>=*maxpoint-rp[j]; |
284 | 296 | ||
285 | _ogg_free(rp); | 297 | /* _ogg_free(rp); */ |
286 | return(r); | 298 | return(r); |
287 | } | 299 | } |
288 | return(NULL); | 300 | return(NULL); |
@@ -364,7 +376,9 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ | |||
364 | /* ogg_uint32_t **codep=(ogg_uint32_t **)alloca(sizeof(*codep)*n); */ | 376 | /* ogg_uint32_t **codep=(ogg_uint32_t **)alloca(sizeof(*codep)*n); */ |
365 | ogg_uint32_t **codep=codep_buffer; | 377 | ogg_uint32_t **codep=codep_buffer; |
366 | 378 | ||
367 | if (n > BOOK_INIT_MAXSIZE) | 379 | /* We have buffers for these sizes */ |
380 | if ((n>BOOK_INIT_MAXSIZE) | ||
381 | || (n*s->dim>BOOK_INIT_MAXSIZE*BOOK_DIM_MAX)) | ||
368 | goto err_out; | 382 | goto err_out; |
369 | 383 | ||
370 | if(codes==NULL)goto err_out; | 384 | if(codes==NULL)goto err_out; |
@@ -376,7 +390,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ | |||
376 | 390 | ||
377 | qsort(codep,n,sizeof(*codep),sort32a); | 391 | qsort(codep,n,sizeof(*codep),sort32a); |
378 | 392 | ||
379 | /*sortindex=(int *)alloca(n*sizeof(*sortindex));*/ | 393 | /* sortindex=(int *)alloca(n*sizeof(*sortindex)); */ |
380 | sortindex=sortindex_buffer; | 394 | sortindex=sortindex_buffer; |
381 | c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); | 395 | c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); |
382 | /* the index is a reverse index */ | 396 | /* the index is a reverse index */ |