The actual C code for residual decoding looks something like:
msb = read_unary(bitstream, 1); /*count 0 bits until the next 1 bit*/
lsb = read(bitstream, rice_parameter); /*read "Rice parameter" number of additional bits, or 0 if "parameter" is 0*/
value = (msb << rice_parameter) | lsb; /*combine the high and low bits - note that value = msb if "parameter" is 0*/
if (value & 1) { /*chop off the bottom bit as a sign value*/
residuals_data[sample++] = -(value >> 1) - 1; /*negative residual if 1*/
} else {
residuals_data[sample++] = value >> 1; /*positive residual if 0*/
}
So if the Rice parameter is 0, the sign bit gets pulled out of the unary value. But when in doubt, it's often easier to check your results against the output of
flac -a --residual-text file.flac
which is a good way to separate problems parsing the input stream from problems doing the decoding calculations.
Anyway, I'll try to make my document more clear in the next version.