<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<font face="Courier New, Courier, monospace">Marcus,<br>
<br>
The code used in flac is a Golomb-Rice code. As flac codes
residuals (errors) after estimating the signal with a suitable
model obtained during coding, the code is chosen because it
requires less bits for smaller residuals and more bits for larger
residuals. <br>
<br>
This works because smaller residuals are far more frequent, so
even if large residuals require many bits, they are so infrequent
that this is not a problem.<br>
<br>
How does Golomb-rice work?<br>
<br>
The residuals are divided by a suitable power of two (generally
small, like 8 or so). The integer quotient is represented in unary
code, this is, a number of zeros equal to the number to be
represented followed bya a 1 as separator, and the remainder in
ordinary binary code. <br>
<br>
For instance, if you have to represent decimal 7 you would do
this:<br>
<br>
integer quotient 7/8 = 0<br>
remainder = 7<br>
<br>
So the GR code would be 1111. The first 1 is the separator (in
this case there are zero 0's) and the remaining bits are 111
(decimal 7)<br>
<br>
If you have to represent 45, a much more infrequent residual, <br>
<br>
integer quotient 45/7 = 6<br>
remaider = 3<br>
<br>
So the GR code would be 0000001011. The first six 0's represent 6,
the following 1 is the separator and 011 represents decimal 3<br>
<br>
The idea is that most residuals will be very small if the model is
accurate, so they will bhe representable with only 4 bits (in this
example). Of course, now and then you may have a residual as large
as 32767 (full scale for 16 bit), wich would require 8191 zeros (</font><font
face="Courier New, Courier, monospace"><font face="Courier New,
Courier, monospace">integer quotient of 32767/4</font>), one 1
(separator) and three additional bits. This is very inefficient,
but the odds that this happens are extremely low (the statistical
distribution is Laplatian or absolute value exponential, so large
values are very unlñikely.<br>
<br>
Regards,<br>
<br>
Federico Miyara <br>
<br>
</font><br>
<div class="moz-cite-prefix">On 23/05/2017 10:40, Marcus Johnson
wrote:<br>
</div>
<blockquote
cite="mid:CAFWGNQXxUXvjB+8vsqZKtE1N4toYZUtZXku-QRxw5G1tN92Kqg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_default" style="font-size:large">Can you
guys clarify that by Rice you don't mean unary coding, but
exponential golomb coding?</div>
<div class="gmail_default" style="font-size:large"><br>
</div>
<div class="gmail_default" style="font-size:large">that issue
has confused me before, and probably others.</div>
<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
flac-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:flac-dev@xiph.org">flac-dev@xiph.org</a>
<a class="moz-txt-link-freetext" href="http://lists.xiph.org/mailman/listinfo/flac-dev">http://lists.xiph.org/mailman/listinfo/flac-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>