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

@@ -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;
}