hi all,
a bit of a change to the quantize() and count_bits() function. combining
them into one. Saves a bunch of seconds. Plus there is a check to make sure the
quantize() is going to succeed *before* we start calc'ing. Exact same output.
(ignore the makefile changes in the patch)
later
mike
------
patched against 3.12pre4
-------
Common subdirectories: lame3.12/Dll and lame3.12p4-q/Dll
diff -c lame3.12/Makefile lame3.12p4-q/Makefile
*** lame3.12/Makefile Wed Jun 9 12:10:11 1999
--- lame3.12p4-q/Makefile Wed Jun 9 17:23:03 1999
***************
*** 5,17 ****
#
#
UNAME = $(shell uname)
- ARCH = $(shell uname -m)
-
-
- #define these to use Erik de Castro Lopo's libsndfile
- # http://www.zip.com.au/~erikd/libsndfile/
- #SNDLIB = -DLIBSNDFILE
- #LIBSNDFILE=-lsndfile
# defaults:
--- 5,10 ----
***************
*** 20,26 ****
CC_OPTS = -O
GTK =
GTKLIBS =
! LIBS = -lm
MAKEDEP = -M
NINT_SWITCH =
--- 13,19 ----
CC_OPTS = -O
GTK =
GTKLIBS =
! LIBS = -lm
MAKEDEP = -M
NINT_SWITCH =
***************
*** 35,65 ****
# remove these if you do not have GTK, or dont want the GTK frame analyzer
GTK = -DHAVEGTK `gtk-config --cflags`
GTKLIBS = `gtk-config --libs`
! # for debugging:
! # CC_OPTS = -O -Wall -g -DABORTFP
# these options reportedly work well with egcs-990524
# CC = egcs
# CC_OPTS = -O9 -fomit-frame-pointer -march=pentium \
# -mcpu=pentium -ffast-math -funroll-loops \
# -fprofile-arcs -fbranch-probabilities
- #
- # For Linux on Digital/Compaq Alpha CPUs
- #
- ifeq ($(ARCH),alpha)
- # double is faster than float on Alpha
- CC_OPTS = -O4 -Wall -fomit-frame-pointer -ffast-math -funroll-loops \
- -mfp-regs -fschedule-insns -fschedule-insns2 \
- -finline-functions \
- -DFLOAT=double
- # standard Linux libm
- LIBS = -lm
- # optimized libffm (free fast math library)
- #LIBS = -lffm
- # Compaq's fast math library
- #LIBS = -lcpml
- endif
-
endif
ifeq ($(UNAME),FreeBSD)
--- 28,43 ----
# remove these if you do not have GTK, or dont want the GTK frame analyzer
GTK = -DHAVEGTK `gtk-config --cflags`
GTKLIBS = `gtk-config --libs`
! PG = -pg
! # PG = -fomit-frame-pointer
! CC_OPTS = -O9 -Wall -march=pentium \
! -mcpu=pentium -ffast-math -funroll-loops $(PG)
# these options reportedly work well with egcs-990524
# CC = egcs
# CC_OPTS = -O9 -fomit-frame-pointer -march=pentium \
# -mcpu=pentium -ffast-math -funroll-loops \
# -fprofile-arcs -fbranch-probabilities
endif
ifeq ($(UNAME),FreeBSD)
***************
*** 83,107 ****
! CC_SWITCHES = $(CC_OPTS) $(DISTRIB) $(SNDLIB) $(GTK) -DBS_FORMAT=BINARY
$(NINT_SWITCH) -DNDEBUG
c_sources = \
common.c \
encode.c \
formatBitstream.c \
- get_audio.c \
gtkanal.c \
gpkplotting.c \
huffman.c \
- l3bitstream.c \
ieeefloat.c \
l3psy.c \
loop.c \
mdct.c \
musicin.c \
- psy.c \
portableio.c \
reservoir.c \
subs.c \
tables.c \
--- 61,84 ----
! CC_SWITCHES = $(CC_OPTS) $(DISTRIB) $(GTK) -DBS_FORMAT=BINARY
$(NINT_SWITCH) -DNDEBUG
c_sources = \
common.c \
encode.c \
formatBitstream.c \
gtkanal.c \
gpkplotting.c \
huffman.c \
ieeefloat.c \
+ l3bitstream.c \
l3psy.c \
loop.c \
mdct.c \
musicin.c \
portableio.c \
+ psy.c \
reservoir.c \
subs.c \
tables.c \
***************
*** 127,133 ****
$(PGM): $(OBJ) Makefile
! $(CC) -o $(PGM) $(OBJ) $(LIBS) $(LIBSNDFILE) $(GTKLIBS)
clean:
-rm $(OBJ) $(DEP) $(PGM)
--- 104,110 ----
$(PGM): $(OBJ) Makefile
! $(CC) $(PG) -o $(PGM) $(OBJ) $(LIBS) $(GTKLIBS)
clean:
-rm $(OBJ) $(DEP) $(PGM)
Only in lame3.12p4-q: Makefile.orig
Only in lame3.12: Makefile~
Common subdirectories: lame3.12/doc and lame3.12p4-q/doc
Only in lame3.12p4-q: gmon.out
diff -c lame3.12/loop-pvt.h lame3.12p4-q/loop-pvt.h
*** lame3.12/loop-pvt.h Mon Jun 7 12:15:12 1999
--- lame3.12p4-q/loop-pvt.h Thu Jun 10 17:30:13 1999
***************
*** 153,159 ****
int ch,
int iteration,
int distort[4][CBLIMIT]);
! void quantize( double xr[576],
int ix[576],
gr_info *cod_info );
void quantize_xrpow( double xr[576],
--- 153,159 ----
int ch,
int iteration,
int distort[4][CBLIMIT]);
! int quantize( double xr[576],
int ix[576],
gr_info *cod_info );
void quantize_xrpow( double xr[576],
diff -c lame3.12/loop.c lame3.12p4-q/loop.c
*** lame3.12/loop.c Wed Jun 9 11:57:51 1999
--- lame3.12p4-q/loop.c Thu Jun 10 17:57:23 1999
***************
*** 28,34 ****
#include "loop-pvt.h"
#include "gtkanal.h"
!
int VBR_on_pe(frame_params *fr_ps, layer *info, III_side_info_t *l3_side,
int VBRbits[2][2],
--- 28,37 ----
#include "loop-pvt.h"
#include "gtkanal.h"
! struct quant_info_struct {
! int channel;
! double max_xr[2];
! } quant_info;
int VBR_on_pe(frame_params *fr_ps, layer *info, III_side_info_t *l3_side,
int VBRbits[2][2],
***************
*** 633,641 ****
}
for (ch=0 ; ch < stereo ; ch ++) {
count[ch]=0;
! for (i=0; i<576; i++)
if ( fabs(xr[gr][ch][i]) > 0 ) count[ch]++;
notdone[ch]=count[ch];
if (count[ch]==0) best_over[ch]=0;
}
--- 636,649 ----
}
for (ch=0 ; ch < stereo ; ch ++) {
+ quant_info.max_xr[ch]=0;
count[ch]=0;
! for (i=0; i<576; i++) {
if ( fabs(xr[gr][ch][i]) > 0 ) count[ch]++;
+ /* hijack this loop to calculate an xr_max value */
+ if ( fabs(xr[gr][ch][i]) > quant_info.max_xr[ch])
+ quant_info.max_xr[ch]=fabs(xr[gr][ch][i]);
+ }
notdone[ch]=count[ch];
if (count[ch]==0) best_over[ch]=0;
}
***************
*** 758,763 ****
--- 766,772 ----
xrpow[gr][ch][i]=sqrt(sqrt(temp)*temp);
}
}
+ quant_info.channel=ch;
bits_found[ch]=bin_search_StepSize(targ_bits[ch],-211.0,46,
l3_enc[gr][ch],xr[gr][ch],xrpow[gr][ch],cod_info[ch]);
}
***************
*** 1181,1196 ****
{
int bits;
assert( max_bits >= 0 );
cod_info->quantizerStepSize -= 1.0;;
do
{
cod_info->quantizerStepSize += 1.0;
! if (xrpow_flag)
quantize_xrpow( xrpow[gr][ch], l3_enc[gr][ch], cod_info );
else
! quantize( xr[gr][ch], l3_enc[gr][ch], cod_info );
! bits= count_bits(l3_enc[gr][ch],cod_info);
}
while ( bits > max_bits );
return bits;
--- 1190,1207 ----
{
int bits;
+ quant_info.channel=ch;
assert( max_bits >= 0 );
cod_info->quantizerStepSize -= 1.0;;
do
{
cod_info->quantizerStepSize += 1.0;
! if (xrpow_flag) {
quantize_xrpow( xrpow[gr][ch], l3_enc[gr][ch], cod_info );
+ bits= count_bits(l3_enc[gr][ch],cod_info);
+ }
else
! bits=quantize( xr[gr][ch], l3_enc[gr][ch], cod_info );
}
while ( bits > max_bits );
return bits;
***************
*** 2186,2192 ****
! void quantize( double xr[576], int ix[576], gr_info *cod_info )
{
register int b;
int j;
--- 2197,2203 ----
! int quantize( double xr[576], int ix[576], gr_info *cod_info )
{
register int b;
int j;
***************
*** 2194,2199 ****
--- 2205,2212 ----
int *ixp;
double *xrp;
+
+ int bits=0;
double quantizerStepSize; /* double step */
double istep_l,istep[3],temp;
***************
*** 2220,2225 ****
--- 2233,2241 ----
istep[b] = istep_l * pow(2.0,2* (double) cod_info->subblock_gain[b]);
else istep[b] = istep_l;
}
+ if (cod_info->block_type!=2)
+ if (istep_l*quant_info.max_xr[quant_info.channel]>165489.8823)
+ return 1000000;
ixp = ix;
xrp = xr;
***************
*** 2258,2356 ****
else
ixp++;
}
! else
! *ixp++ = (int)( sqrt(sqrt(temp)*temp) + 0.4054);
}
}
}
}
}
}
}
- #if 0
- /*************************************************************************/
- /* quantize */
- /*************************************************************************/
-
- /*
- Function: Quantization of the vector xr ( -> ix)
- */
-
- void quantize( double xr[576], int ix[576], gr_info *cod_info )
- {
- register int i,b;
- int j;
- double quantizerStepSize; /* double step */
- double istep_l,istep[3],temp;
- static int init=0;
- #define LUTABSIZE 10000
- static int lutab[LUTABSIZE];
-
- if (init==0) {
- init++;
- for (i=0;i<LUTABSIZE;i++) {
- lutab[i]=nint(pow((double)i/10.0,0.75)-0.0946);
- }
- for (i=1;i<LUTABSIZE;i++)
- if ((lutab[i]-lutab[i-1])==1) { /* we have a change over this interval
*/
- lutab[i-1]=-1;
- }
- }
-
- quantizerStepSize = cod_info->quantizerStepSize;
- /* if subblock gain is used (short blocks), this should be: */
- /* step = pow( 2.0, (quantizerStepSize - 8.0 * (double)
cod_info->subblock_gain[b]) * -0.25 ); */
- /* step = pow( 2.0, quantizerStepSize * -0.25) *
- pow( 2.0, 2*(double) cod_info->subblock_gain[b]) */
-
- if ( quantizerStepSize == 0.0 )
- istep_l = 1.0;
- else
- istep_l = pow ( 2.0, quantizerStepSize * -0.25 );
-
- for (b=0;b<3;b++) {
- if ((cod_info->block_type==2))
- istep[b] = istep_l * pow(2.0,2* (double) cod_info->subblock_gain[b]);
- else istep[b] = istep_l;
- }
-
-
- i=0;
- for (j=0;j<192;j++)
- for (b=0;b<3;b++) {
- temp=istep[b]*fabs(xr[i]); /* step always positive -> temp always
postive */
- if (temp<0.499996)
- ix[i]=0;
- else
- if (temp<1.862955)
- ix[i]=1;
- else
- if (temp<3.565282)
- ix[i]=2;
- else
- if (temp<5.506396)
- ix[i]=3;
- else
- if (temp<7.638304)
- ix[i]=4;
- else
- if (temp<9.931741)
- ix[i]=5;
- else
- if (temp<1000.0) {
- ix[i]=lutab[(int)(temp*10.0)];
- if (ix[i]==-1) /* too close to an interface, calculate exact value */
- ix[i] = (int)( sqrt(sqrt(temp)*temp) + 0.4054);
- }
- else
- ix[i] = (int)( sqrt(sqrt(temp)*temp) + 0.4054);
- i++;
- }
-
- }
- #endif
-
void quantize_xrpow( double xr[576], int ix[576], gr_info *cod_info )
{
/* quantize on xr^(3/4) instead of xr */
--- 2274,2300 ----
else
ixp++;
}
! else {
! *ixp = (int)( sqrt(sqrt(temp)*temp) + 0.4054);
! if (*ixp > 8191 + 14)
! return 1000000;
! else
! ixp++;
! }
}
}
}
}
}
}
+ /* now do count_bits */
+ calc_runlen(ix,cod_info); /*count1,big_values*/
+ bits = count1_bitcount(ix, cod_info); /*count1_table selection*/
+ subdivide(cod_info); /* bigvalues sfb division */
+ bits += bigv_bitcount(ix,cod_info); /* bit count */
+ return bits;
}
void quantize_xrpow( double xr[576], int ix[576], gr_info *cod_info )
{
/* quantize on xr^(3/4) instead of xr */
***************
*** 3205,3214 ****
cod_info->quantizerStepSize = next;
if (xrpow_flag) {
quantize_xrpow(xrspow,ix,cod_info);
} else {
! quantize(xrs,ix,cod_info);
}
- bit = count_bits(ix,cod_info);
if (bit>desired_rate) top = next;
else bot = next;
// printf("\n%f %f %f %f %d %d",start,next, top,bot,bit,desired_rate);
--- 3149,3158 ----
cod_info->quantizerStepSize = next;
if (xrpow_flag) {
quantize_xrpow(xrspow,ix,cod_info);
+ bit = count_bits(ix,cod_info);
} else {
! bit=quantize(xrs,ix,cod_info);
}
if (bit>desired_rate) top = next;
else bot = next;
// printf("\n%f %f %f %f %d %d",start,next, top,bot,bit,desired_rate);
Common subdirectories: lame3.12/mpglib and lame3.12p4-q/mpglib
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )