[Flac-dev] Building a Rice Encoder/Decoder from FLAC

Josh Coalson xflac at yahoo.com
Fri Jul 14 17:49:01 PDT 2006


--- Mary Amon <mary.amon at gmail.com> wrote:
> Hi all,
> 
> I am interested in building a stand alone Rice Encoder/Decoder, using
> FLAC
> source code as a starting point.  I've read the theory behind it, and
> I am
> very interested in info theory.  However,  I am struggling with how
> exactly
> I would implement the theory in code.  I'm a newbie to computer
> science
> (only 1 year experience). I have read the format and documentation
> links on
> the FLAC website, as well as the archives of the mailing list...and I
> haven't found anyone doing something similar.  I am new to doxygen
> and have
> never read or written anything as large as FLAC before.   Right now,
> I am
> looking in the src code of libFLAC, (I am looking through
> stream_encoder.c
> in libFLAC src code), but its really confusing to someone who just
> learned
> what ./configure meant today.
> 
> So any help in where I can find where the Rice encoder/decoder is
> implemented in the code (in libFLAC or libFLAC++) would be super
> helpful.

hi Mary,
the actual lowest level routines that write the value are in
.../src/libFLAC/bitbuffer.c, they are

 FLAC__bitbuffer_write_rice_signed()
 FLAC__bitbuffer_read_rice_signed()

there is a little terminology vagueness here, but FLAC's "rice"
codes are probably not exactly "rice".  usually rice codes (like
in shorten) start with a sign bit and then have the magnitude
encoded with the unary/binary part.  since this wastes one of the
shortest code words on minus-zero (which never occurs), FLAC first
folds the signed number into unsigned like so:

 0 -> 0
-1 -> 1
 1 -> 2
-2 -> 3
 2 -> 4

etc. and then codes the value without a sign bit.

Josh


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Flac-dev mailing list