final version of symmetric-rice/escape-code experiment before reverting

This commit is contained in:
Josh Coalson 2001-03-21 22:34:44 +00:00
parent 57a6a343bd
commit 9ec2a52011
4 changed files with 37 additions and 35 deletions

View File

@ -3,7 +3,7 @@
#
LIB_NAME = libFLAC
INCLUDES = -I./include -I../../include
INCLUDES = -I./include -I../../include -DSYMMETRIC_RICE
DEBUG_CFLAGS = -DFLAC_OVERFLOW_DETECT
OBJS = \

View File

@ -42,6 +42,29 @@ static unsigned ilog2_(unsigned v)
return l;
}
static unsigned silog2_(int v)
{
doit_:
if(v == 0) {
return 0;
}
else if(v > 0) {
unsigned l = 0;
while(v) {
l++;
v >>= 1;
}
return l+1;
}
else if(v == -1) {
return 2;
}
else {
v = -(++v);
goto doit_;
}
}
static bool bitbuffer_resize_(FLAC__BitBuffer *bb, unsigned new_capacity)
{
byte *new_buffer;
@ -567,43 +590,18 @@ bool FLAC__bitbuffer_write_symmetric_rice_signed_guarded(FLAC__BitBuffer *bb, in
return true;
}
static unsigned silog21_(int v)
{
doit_:
if(v == 0) {
return 0;
}
else if(v > 0) {
unsigned l = 0;
while(v) {
l++;
v >>= 1;
}
return l+1;
}
else if(v == -1) {
return 2;
}
else {
v = -(++v);
goto doit_;
}
}
bool FLAC__bitbuffer_write_symmetric_rice_signed_escape(FLAC__BitBuffer *bb, int val, unsigned parameter)
{
unsigned total_bits, val_bits;
uint32 pattern;
unsigned x;
assert(bb != 0);
assert(bb->buffer != 0);
assert(parameter <= 31);
val_bits = silog21_(val);
val_bits = silog2_(val);
total_bits = 2 + parameter + 5 + val_bits;
x=bb->total_bits;
if(total_bits <= 32) {
pattern = 3;
pattern <<= (parameter + 5);
@ -624,7 +622,6 @@ x=bb->total_bits;
if(!FLAC__bitbuffer_write_raw_int32(bb, val, val_bits))
return false;
}
fprintf(stderr,"wrote %u bits\n",bb->total_bits-x);
return true;
}

View File

@ -44,6 +44,9 @@
#define M_LN2 0.69314718055994530942
#endif
double smult;
unsigned rpdec;
typedef struct FLAC__EncoderPrivate {
unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
@ -320,6 +323,11 @@ FLAC__EncoderState FLAC__encoder_init(FLAC__Encoder *encoder, FLAC__EncoderWrite
return encoder->state = FLAC__ENCODER_NOT_STREAMABLE;
}
{unsigned r = encoder->rice_optimization_level;
smult=(double)(r / 10);
rpdec=r % 10;
encoder->rice_optimization_level=0;
}
if(encoder->rice_optimization_level >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
encoder->rice_optimization_level = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
@ -1087,9 +1095,6 @@ static unsigned uilog21_(unsigned v)
return l;
}
const double smult = 3.0;
const unsigned rpdec = 0;
static uint32 get_thresh_(const int32 residual[], const unsigned residual_samples)
{
double sum, sos, r, stddev, mean;
@ -1106,7 +1111,7 @@ static uint32 get_thresh_(const int32 residual[], const unsigned residual_sample
stddev = sqrt((sos - (sum * sum / residual_samples)) / (residual_samples-1));
thresh = mean+smult*stddev;
thresh = (1u << uilog21_(thresh)) - 1;
return thresh;
return smult>0.0? thresh : 0;
}
#ifdef VARIABLE_RICE_BITS
@ -1151,9 +1156,9 @@ bool encoder_set_partitioned_rice_(const int32 residual[], const uint32 abs_resi
#ifdef SYMMETRIC_RICE
if(cross) {
unsigned escbits, normbits;
escbits = /* VARIABLE_RICE_BITS(0, rice_parameter) == 0 */ 5 + silog21_(residual[i]);
escbits = /* VARIABLE_RICE_BITS(-0, rice_parameter) == 0 */ 5 + silog21_(residual[i]);
normbits = VARIABLE_RICE_BITS(abs_residual[i], rice_parameter);
bits += min(escbits, normbits);
bits_ += min(escbits, normbits);
}
else {
/*@@@ old way */

View File

@ -401,7 +401,7 @@ bool subframe_add_residual_partitioned_rice_(FLAC__BitBuffer *bb, const int32 re
escbits = 5 + silog21_(residual[i]);
normbits = a >> rice_parameters[0];
if(escbits < normbits) {
fprintf(stderr,"ESCAPE, k=%u, r=%d, saved %u bits\n", rice_parameters[0], residual[i], normbits-escbits);
fprintf(stderr,"ESCAPE, k=%u, r=%d, escbits=%u, normbits=%u, saved %u bits\n", rice_parameters[0], residual[i], escbits, normbits, normbits-escbits);
if(!FLAC__bitbuffer_write_symmetric_rice_signed_escape(bb, residual[i], rice_parameters[0]))
return false;
}