[Flac-dev] rice format

Josh Coalson xflac at yahoo.com
Sun Apr 17 19:55:26 PDT 2005


--- CHI Hongliang <hongliang.chi at enst-bretagne.fr> wrote:
> hello,
> 
> I am now develloping an embeded decoding system for flac.I have a
> problem about the format of the rice coding:
> 
> the residual begins with : 01 01 08 0C
> 
> the first two bytes are the warmups, the prediction order is 2. and
> the 080C is the following:
> 00 0010 0000 001100
> 
> the first two bits mean: residual coding method is partitioned rice
> the following four bits mean: the partition order is 2 ;
> the following four bits mean: the rice parametre is 0;
> 
> then,  accdoring the ["k" zeroes][1][low-order bits][sign-bit]
> format, I found the first decoded residual is : -2,
> 
>  and with the Fixed predictor, I got the decoded sample: 2*1-1 +(-2)
> = -1,  but the real number is 3.I can not figure out what is the
> problem. Is it the problem of the rice format? or the predictor? 
> 
> thanks
> 
> 
> this is what i got by: flac -a 
> frame=0 blocksize=16 sample_rate=22050 channels=1
> channel_assignment=INDEPENDENT
> subframe=0 wasted_bits=0 type=FIXED order=2 partition_order=2
> warmup[0]=1
> warmup[1]=1

is it 8 bits-per-sample?  if so, then the problem is this:

> then,  accdoring the ["k" zeroes][1][low-order bits][sign-bit]
> format, I found the first decoded residual is : -2,

that's not quite the correct format for the rice code.  first,
it's not 'k' zeroes, it's value>>k zeroes.  second, FLAC does
not transmit the sign bit (because it wastes one of the two
shortest codes on a value that cannot exist: minus zero).

instead, it 'folds' signed values into unsigned like so:

 0 -> 0
-1 -> 1
 1 -> 2
-2 -> 3
 2 -> 4
-3 -> 5
 3 -> 6
...and so on.  the resulting unsigned value is then encoded
similar to how you described:

 [val>>k zeroes]1[k low-order bits]

example:

start with value=-11, k=3
-11 folded becomes  21 == 10101
for k=3, split into 10|101, i.e. 2 and 5
transmit 2 zeros, 1 stop bit, 101 in binary

00 1 101 == 001101

one day I'll get to updating the format page to make that clearer.

Josh



		
__________________________________ 
Do you Yahoo!? 
Plan great trips with Yahoo! Travel: Now over 17,000 guides!
http://travel.yahoo.com/p-travelguide


More information about the Flac-dev mailing list