1
0
Fork 0
forked from len0rd/rockbox

Vorbis: Apply various bugfixes from upstream Tremor.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13756 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Magnus Holmgren 2007-07-01 17:58:49 +00:00
parent 9af4289770
commit 932b20ec62
6 changed files with 290 additions and 260 deletions

View file

@ -148,7 +148,7 @@ static inline ogg_uint32_t bitreverse(register ogg_uint32_t x){
return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa);
}
static inline long decode_packed_entry_number(codebook *book,
STIN long decode_packed_entry_number(codebook *book,
oggpack_buffer *b){
int read=book->dec_maxlength;
long lo,hi;
@ -172,7 +172,11 @@ static inline long decode_packed_entry_number(codebook *book,
while(lok<0 && read>1)
lok = oggpack_look(b, --read);
if(lok<0)return -1;
if(lok<0){
oggpack_adv(b,1); /* force eop */
return -1;
}
/* bisect search for the codeword in the ordered list */
{
@ -191,7 +195,7 @@ static inline long decode_packed_entry_number(codebook *book,
}
}
oggpack_adv(b, read);
oggpack_adv(b, read+1);
return(-1);
}
@ -283,17 +287,20 @@ static inline long decode_packed_block(codebook *book, oggpack_buffer *b,
/* returns the [original, not compacted] entry number or -1 on eof *********/
long vorbis_book_decode(codebook *book, oggpack_buffer *b){
if(book->used_entries>0){
long packed_entry=decode_packed_entry_number(book,b);
if(packed_entry>=0)
return(book->dec_index[packed_entry]);
}
/* if there's no dec_index, the codebook unpacking isn't collapsed */
return(packed_entry);
return(-1);
}
/* returns 0 on OK or -1 on eof *************************************/
long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a,
oggpack_buffer *b,int n,int point){
if(book->used_entries>0){
int step=n/book->dim;
long *entry = (long *)alloca(sizeof(*entry)*step);
ogg_int32_t **t = (ogg_int32_t **)alloca(sizeof(*t)*step);
@ -319,11 +326,13 @@ long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a,
for (j=0;j<step;j++)
a[o+j]+=t[j][i]<<-shift;
}
}
return(0);
}
long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a,
oggpack_buffer *b,int n,int point){
if(book->used_entries>0){
int i,j,entry;
ogg_int32_t *t;
int shift=point-book->binarypoint;
@ -346,11 +355,13 @@ long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a,
a[i++]+=t[j++]<<shift;
}
}
}
return(0);
}
long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a,
oggpack_buffer *b,int n,int point){
if(book->used_entries>0){
int i,j,entry;
ogg_int32_t *t;
int shift=point-book->binarypoint;
@ -376,12 +387,22 @@ long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a,
}
}
}
}else{
int i,j;
for(i=0;i<n;){
for (j=0;j<book->dim;){
a[i++]=0;
}
}
}
return(0);
}
long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,
long offset,int ch,
oggpack_buffer *b,int n,int point){
if(book->used_entries>0){
long i,j,k,chunk,read;
int chptr=0;
int shift=point-book->binarypoint;
@ -426,5 +447,6 @@ long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,
if (read<chunk)return-1;
}
}
}
return(0);
}

View file

@ -286,7 +286,7 @@ static const ogg_int32_t FLOOR_fromdB_LOOKUP[256] ICONST_ATTR = {
XdB(0x69f80e9a), XdB(0x70dafda8), XdB(0x78307d76), XdB(0x7fffffff),
};
static void render_line(int x0,register int x1,int y0,int y1,ogg_int32_t *d){
static void render_line(int n, int x0,register int x1,int y0,int y1,ogg_int32_t *d){
int dy=y1-y0;
register int x=x0;
register int y=y0;
@ -296,11 +296,13 @@ static void render_line(int x0,register int x1,int y0,int y1,ogg_int32_t *d){
register int sy=(dy<0?base-1:base+1);
int err=0;
if(n>x1)n=x1;
ady-=abs(base*adx);
if(x<n)
d[x]= MULT31_SHIFT15(d[x],FLOOR_fromdB_LOOKUP[y]);
while(++x<x1){
while(++x<n){
err=err+ady;
if(err>=adx){
err-=adx;
@ -424,7 +426,7 @@ static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
hy*=info->mult;
hx=info->postlist[current];
render_line(lx,hx,ly,hy,out);
render_line(n,lx,hx,ly,hy,out);
lx=hx;
ly=hy;

View file

@ -53,11 +53,6 @@ static void _ogg_buffer_destroy(ogg_buffer_state *bs){
bt=bs->unused_buffers;
rt=bs->unused_references;
if(!bs->outstanding){
_ogg_free(bs);
return;
}
while(bt){
ogg_buffer *b=bt;
bt=b->ptr.next;
@ -71,6 +66,10 @@ static void _ogg_buffer_destroy(ogg_buffer_state *bs){
_ogg_free(r);
}
bs->unused_references=0;
if(!bs->outstanding)
_ogg_free(bs);
}
}
@ -836,6 +835,7 @@ int ogg_stream_destroy(ogg_stream_state *os){
ogg_buffer_release(os->header_tail);
ogg_buffer_release(os->body_tail);
memset(os,0,sizeof(*os));
_ogg_free(os);
}
return OGG_SUCCESS;
}

View file

@ -97,9 +97,9 @@ void vorbis_comment_clear(vorbis_comment *vc){
if(vc->user_comments)_ogg_free(vc->user_comments);
if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
if(vc->vendor)_ogg_free(vc->vendor);
}
memset(vc,0,sizeof(*vc));
}
}
/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long.
They may be equal, but short will never ge greater than long */
@ -124,12 +124,15 @@ void vorbis_info_clear(vorbis_info *vi){
if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
for(i=0;i<ci->maps;i++) /* unpack does the range checking */
if(ci->map_param[i])
_mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
for(i=0;i<ci->floors;i++) /* unpack does the range checking */
if(ci->floor_param[i])
_floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
for(i=0;i<ci->residues;i++) /* unpack does the range checking */
if(ci->residue_param[i])
_residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
for(i=0;i<ci->books;i++){

View file

@ -187,8 +187,11 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
/* move all this setup out later */
int samples_per_partition=info->grouping;
int partitions_per_word=look->phrasebook->dim;
int n=info->end-info->begin;
int max=vb->pcmend>>1;
int end=(info->end<max?info->end:max);
int n=end-info->begin;
if(n>0){
int partvals=n/samples_per_partition;
int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
int ***partword=(int ***)alloca(ch*sizeof(*partword));
@ -225,7 +228,7 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
}
}
}
}
errout:
eopbreak:
return(0);
@ -255,8 +258,6 @@ int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
return(0);
}
/* duplicate code here as speed is somewhat more important */
int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
ogg_int32_t **in,int *nonzero,int ch)
@ -270,7 +271,11 @@ int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
/* move all this setup out later */
int samples_per_partition=info->grouping;
int partitions_per_word=look->phrasebook->dim;
int n=info->end-info->begin;
int max=(vb->pcmend*ch)>>1;
int end=(info->end<max?info->end:max);
int n=end-info->begin;
if(n>0){
int partvals=n/samples_per_partition;
int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
@ -307,7 +312,7 @@ int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
}
}
}
}
errout:
eopbreak:
return(0);

View file

@ -337,9 +337,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
c->used_entries=n;
c->dim=s->dim;
c->q_min=s->q_min;
c->q_delta=s->q_delta;
if(n>0){
/* two different remappings go on here.
First, we collapse the likely sparse codebook down only to
@ -350,7 +348,6 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
Second, we reorder all vectors, including the entry index above,
by sorted bitreversed codeword to allow treeless decode. */
{
/* perform sort */
ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
ogg_uint32_t **codep=(ogg_uint32_t **)ogg_tmpmalloc(sizeof(*codep)*n);
@ -375,7 +372,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
for(i=0;i<n;i++)
c->codelist[sortindex[i]]=codes[i];
/* _ogg_free(codes); */
}
c->valuelist=_book_unquantize(s,n,sortindex,&c->binarypoint);
@ -435,6 +432,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
}
}
}
}
ogg_tmpmalloc_free(pos);
return(0);