[FFmpeg-devel] [PATCH][RFC] Lagarith Decoder.

Reimar Döffinger Reimar.Doeffinger
Fri Aug 14 23:21:54 CEST 2009


On Fri, Aug 14, 2009 at 02:25:44PM -0600, Nathan Caldwell wrote:
> On Wed, Aug 12, 2009 at 8:34 AM, Reimar
> D?ffinger<Reimar.Doeffinger at gmx.de> wrote:
> > On Mon, Aug 10, 2009 at 11:42:19PM -0600, Nathan Caldwell wrote:
> >> + ? ?/* Scale probabilities so cumulative probability is an even power of 2. */
> >> + ? ?cumulative_target = clp2(cumul_prob);
> >> +
> >> + ? ?scale_factor = cumulative_target / (double) cumul_prob;
> >> +
> >> + ? ?for (i = 1; i < 257; i++) {
> >> + ? ? ? ?rac->prob[i] = (unsigned int) (rac->prob[i] * scale_factor);
> >
> > I think a 32x32 -> 64 bit multiply + right shift is a more reliable way
> > to calculate this. floating-point IMO is usually misplaced in
> > anything that claims to be lossless (yes, you can do it and even have
> > it work cross-platform, but it's a real effort).
> 
> I tried this earlier, but it doesn't retain enough precision. It was
> right most of the time, but not all the time. I'm open to any other
> suggestions.

Please show the code you used.
I admit I confused cumulative_target and cumul_prob in the scale_factor
calculation, so it would be harder than I thought.
Particularly since the code lacks some information on the limits of
the values (and relatedly also lacks some necessary checks, e.g. all-0
probabilities seem to trigger an endless loop, in addition to the
possible crash/endless loop in lag_decode_prob).
So the first question would be: what would be valid values for the
probabilities?



More information about the ffmpeg-devel mailing list