Fixed the approx_vbr assignment bug in vorbisenc
svn path=/trunk/vorbis/; revision=2973
********************************************************************
function: basic codebook pack/unpack/code/decode operations
********************************************************************
function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.37 2002/01/21 20:51:28 xiphmont Exp $
+ last mod: $Id: codebook.c,v 1.38 2002/01/22 02:16:40 xiphmont Exp $
********************************************************************/
********************************************************************/
return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa);
}
return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa);
}
-
-static long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
+STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
int read=book->dec_maxlength;
long lo,hi;
int read=book->dec_maxlength;
long lo,hi;
- long lok = oggpack_look(b, book->dec_firsttablen);
-
+ long lok = oggpack_look(b,book->dec_firsttablen);
+
if (lok >= 0) {
long entry = book->dec_firsttable[lok];
if(entry&0x80000000UL){
if (lok >= 0) {
long entry = book->dec_firsttable[lok];
if(entry&0x80000000UL){
}
lok = oggpack_look(b, read);
}
lok = oggpack_look(b, read);
while(lok<0 && read>1)
lok = oggpack_look(b, --read);
if(lok<0)return -1;
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);
/* bisect search for the codeword in the ordered list */
{
ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok);
- long test=(book->codelist[p]<=testword)-1;
- lo+=(p-lo)&(~test);
- hi-=(hi-p)&test;
- p=(lo+hi)>>1;
+ long p=(hi-lo)>>1;
+ long test=book->codelist[lo+p]>testword;
+ lo+=p&(test-1);
+ hi-=p&(-test);
- if(book->dec_codelengths[p]<=read){
- oggpack_adv(b, book->dec_codelengths[p]);
- return(p);
+ if(book->dec_codelengths[lo]<=read){
+ oggpack_adv(b, book->dec_codelengths[lo]);
+ return(lo);
********************************************************************
function: basic shared codebook operations
********************************************************************
function: basic shared codebook operations
- last mod: $Id: sharedbook.c,v 1.25 2002/01/21 20:51:28 xiphmont Exp $
+ last mod: $Id: sharedbook.c,v 1.26 2002/01/22 02:16:40 xiphmont Exp $
********************************************************************/
********************************************************************/
hints for the non-direct-hits */
{
ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
hints for the non-direct-hits */
{
ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
- if(c->dec_firsttable[i]==0){
- ogg_uint32_t testword=bitreverse(i);
- long lo=0,hi=0;
- while((lo+1)<n && c->codelist[lo+1]<=testword)lo++;
- while( hi<n && testword>=(c->codelist[hi]&mask))hi++;
-
+ ogg_uint32_t word=i<<(32-c->dec_firsttablen);
+ if(c->dec_firsttable[bitreverse(word)]==0){
+ while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
+ while( hi<n && word>=(c->codelist[hi]&mask))hi++;
+
/* we only actually have 15 bits per hint to play with here.
In order to overflow gracefully (nothing breaks, efficiency
just drops), encode as the difference from the extremes. */
/* we only actually have 15 bits per hint to play with here.
In order to overflow gracefully (nothing breaks, efficiency
just drops), encode as the difference from the extremes. */
if(loval>0x7fff)loval=0x7fff;
if(hival>0x7fff)hival=0x7fff;
if(loval>0x7fff)loval=0x7fff;
if(hival>0x7fff)hival=0x7fff;
- c->dec_firsttable[i]=0x80000000UL | (loval<<15) | hival;
+ c->dec_firsttable[bitreverse(word)]=
+ 0x80000000UL | (loval<<15) | hival;
********************************************************************
function: simple programmatic interface for encoder mode setup
********************************************************************
function: simple programmatic interface for encoder mode setup
- last mod: $Id: vorbisenc.c,v 1.33 2001/12/23 11:53:53 xiphmont Exp $
+ last mod: $Id: vorbisenc.c,v 1.34 2002/01/22 02:16:40 xiphmont Exp $
********************************************************************/
********************************************************************/
long min_bitrate){
double tnominal=nominal_bitrate;
long min_bitrate){
double tnominal=nominal_bitrate;
- double approx_vbr=approx_bitrate_to_vbr(channels,(channels==2),
- (float)nominal_bitrate,rate);
- if(approx_vbr<0)return(OV_EIMPL);
if(nominal_bitrate<=0.){
if(max_bitrate>0.){
if(nominal_bitrate<=0.){
if(max_bitrate>0.){
+ approx_vbr=approx_bitrate_to_vbr(channels,(channels==2),
+ (float)nominal_bitrate,rate);
+ if(approx_vbr<0)return(OV_EIMPL);
+
+
ret=vorbis_encode_setup_vbr(vi,channels,rate,approx_vbr);
if(ret){
vorbis_info_clear(vi);
ret=vorbis_encode_setup_vbr(vi,channels,rate,approx_vbr);
if(ret){
vorbis_info_clear(vi);