[Flac-dev] Rice coding parameter

Miroslav Lichvar lichvarm at phoenix.inf.upol.cz
Wed Oct 22 15:21:31 PDT 2003


On Tue, Oct 21, 2003 at 06:25:31PM +0000, Dan Stowell wrote:
> Date: Sun, 19 Oct 2003 00:59:22 +0200
> > On Sat, Oct 18, 2003 at 07:21:08PM +0000, Dan Stowell wrote:
> > > I asked a few questions about the flac format a couple of weeks 
> ago.
> > > One more (if you don't mind) about the Rice coding. The Rice
> > > parameter "k" can't be zero (unless I'm mistaken), yet the FLAC spec
> > > says the Rice parameter can range from 0 to 15.
> > > 
> > > I guessed, and tried adding one before using the parameter (i.e.
> > > assuming the range was really 1 to 16), and that didn't fix it.
> > > 
> > > How should I interpret those four little bits?
> > 
> > The spec is ok, Rice parameter can be 0 to 14, 15 is escape code. And
> > Rice parameter 0 means that only the unary part is used. For example
> > 000001000010001001011 is -3 2 -2 1 -1 0.
> 
> Thanks again Miroslav. So if I understand your example correctly, I can 
> interpret a single number in this unary code using
> 
>       return ( (q&1)==1 ? -((q>>1)+1) : (q>>1) );
> 
> if 'q' is the number of zeroes found before bumping into a 1.

Yes, and you can use this for all Rice codes, not just for codes with
k = 0. (A faster version would be (q >> 1) ^ -(q & 1)).

In file src/libFLAC/bitbuffer.c from FLAC sources there is
FLAC__bitbuffer_read_rice_signed function, it is short and readable.

> Is this a standard component of Rice coding, or is it developed for
> FLAC? I didn't read about it when I read up on Rice coding.

I think it is a normal Rice code with parameter k = 0, and that is
identical to the Golomb code with parameter m = 1.

-- 
Miroslav Lichvar




More information about the Flac-dev mailing list