}else{ /* length random. Again, we don't code the codeword itself, just
the length. This time, though, we have to encode each length */
oggpack_write(opb,0,1); /* unordered */
/* algortihmic mapping has use for 'unused entries', which we tag here.Thealgorithmicmappinghappensasusual,buttheunused
entry has no codeword. */ for(i=0;i<c->entries;i++) if(c->lengthlist[i]==0)break;
if(i==c->entries){
oggpack_write(opb,0,1); /* no unused entries */ for(i=0;i<c->entries;i++)
oggpack_write(opb,c->lengthlist[i]-1,5);
}else{
oggpack_write(opb,1,1); /* we have unused entries; thus we tag */ for(i=0;i<c->entries;i++){ if(c->lengthlist[i]==0){
oggpack_write(opb,0,1);
}else{
oggpack_write(opb,1,1);
oggpack_write(opb,c->lengthlist[i]-1,5);
}
}
}
}
/* is the entry number the desired return value, or do we have a
mapping? If we have a mapping, what type? */
oggpack_write(opb,c->maptype,4); switch(c->maptype){ case0: /* no mapping */ break; case1:case2: /* implicitly populated value mapping */ /* explicitly populated value mapping */
if(!c->quantlist){ /* no quantlist? error */ return(-1);
}
/* values that define the dequantization */
oggpack_write(opb,c->q_min,32);
oggpack_write(opb,c->q_delta,32);
oggpack_write(opb,c->q_quant-1,4);
oggpack_write(opb,c->q_sequencep,1);
{ int quantvals; switch(c->maptype){ case1: /* a single column of (c->entries/c->dim) quantized values for
building a full value list algorithmically (square lattice) */
quantvals=_book_maptype1_quantvals(c); break; case2: /* every value (c->entries*c->dim total) specified explicitly */
quantvals=c->entries*c->dim; break; default: /* NOT_REACHABLE */
quantvals=-1;
}
} break; default: /* error case; we don't have any other map types now */ return(-1);
}
return(0);
}
/* unpacks a codebook from the packet buffer into the codebook struct,
readies the codebook auxiliary structures for decode *************/
static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){ long i,j;
static_codebook *s=_ogg_calloc(1,sizeof(*s));
s->allocedp=1;
/* make sure alignment is correct */ if(oggpack_read(opb,24)!=0x564342)goto _eofout;
/* first the basic parameters */
s->dim=oggpack_read(opb,16);
s->entries=oggpack_read(opb,24); if(s->entries==-1)goto _eofout;
/* Do we have a mapping to unpack? */ switch((s->maptype=oggpack_read(opb,4))){ case0: /* no mapping */ break; case1: case2: /* implicitly populated value mapping */ /* explicitly populated value mapping */
/* returns the number of bits ************************************************/ int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){ if(a<0 || a>=book->c->entries)return(0);
oggpack_write(b,book->codelist[a],book->c->lengthlist[a]); return(book->c->lengthlist[a]);
}
/* the 'eliminate the decode tree' optimization actually requires the codewordstobeMSbfirst,notLSb.Thisisanannoyinginelegancy (andoneofthefirstplaceswherecarefullythoughtoutdesign turnedouttobewrong;VorbisIIandfutureOggcodecsshouldgo toanMSbbitpacker),butnotactuallythehugehititappearsto be.Thefirst-stagedecodetablecatchesmostwordssothat
bitreverse is not in the main execution path. */
STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){ int read=book->dec_maxlength; long lo,hi; long lok = oggpack_look(b,book->dec_firsttablen);
/* Single entry codebooks use a firsttablen of 1 and a dec_maxlengthof1.Ifasingle-entrycodebookgetshere(dueto failuretoreadonebitabove),thenextlookattemptwillalso failandwe'llcorrectlykickoutinsteadoftryingtowalkthe
underformed tree */
lok = oggpack_look(b, read);
while(lok<0 && read>1)
lok = oggpack_look(b, --read); if(lok<0)return -1;
/* bisect search for the codeword in the ordered list */
{
ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok);
while(hi-lo>1){ long p=(hi-lo)>>1; long test=book->codelist[lo+p]>testword;
lo+=p&(test-1);
hi-=p&(-test);
}
/* Decode side is specced and easier, because we don't need to find matchesusingdifferentcriteria;wesimplyreadandmap.Thereare twothingsweneedtodo'depending':
/* 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(-1);
}
/* returns 0 on OK or -1 on eof *************************************/ /* decode vector / dim granularity gaurding is done in the upper layer */ long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){ if(book->used_entries>0){ int step=n/book->dim; long *entry = alloca(sizeof(*entry)*step); float **t = alloca(sizeof(*t)*step); int i,j,o;
for (i = 0; i < step; i++) {
entry[i]=decode_packed_entry_number(book,b); if(entry[i]==-1)return(-1);
t[i] = book->valuelist+entry[i]*book->dim;
} for(i=0,o=0;i<book->dim;i++,o+=step) for (j=0;o+j<n && j<step;j++)
a[o+j]+=t[j][i];
} return(0);
}
/* decode vector / dim granularity gaurding is done in the upper layer */ long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){ if(book->used_entries>0){ int i,j,entry; float *t;
/* unlike the others, we guard against n not being an integer number of<dim>internallyratherthanintheupperlayer(calledonlyby
floor0) */ long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){ if(book->used_entries>0){ int i,j,entry; float *t;
for(i=0;i<n;){
entry = decode_packed_entry_number(book,b); if(entry==-1)return(-1);
t = book->valuelist+entry*book->dim; for (j=0;i<n && j<book->dim;){
a[i++]=t[j++];
}
}
}else{ int i;
for(i=0;i<n;){
a[i++]=0.f;
}
} return(0);
}
long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
oggpack_buffer *b,int n){
long i,j,entry; int chptr=0; if(book->used_entries>0){ int m=(offset+n)/ch; for(i=offset/ch;i<m;){
entry = decode_packed_entry_number(book,b); if(entry==-1)return(-1);
{ constfloat *t = book->valuelist+entry*book->dim; for (j=0;i<m && j<book->dim;j++){
a[chptr++][i]+=t[j]; if(chptr==ch){
chptr=0;
i++;
}
}
}
}
} return(0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.