# HG changeset patch # User michael # Date 1091443341 0 # Node ID 4478e603a8e3c719a6f1a3a3ef7f4457ee345c23 # Parent f06fb6fc0ff993a9a82bbbd635df67f802feb4bd simpler delta decreasing algorithm patch by (Jeff Muizelaar ) diff -r f06fb6fc0ff9 -r 4478e603a8e3 ac3enc.c --- a/ac3enc.c Mon Aug 02 01:06:55 2004 +0000 +++ b/ac3enc.c Mon Aug 02 10:42:21 2004 +0000 @@ -515,7 +515,7 @@ int nb_exps, int exp_strategy) { - int group_size, nb_groups, i, j, k, recurse, exp_min, delta; + int group_size, nb_groups, i, j, k, exp_min; uint8_t exp1[N/2]; switch(exp_strategy) { @@ -550,25 +550,13 @@ if (exp1[0] > 15) exp1[0] = 15; - /* Iterate until the delta constraints between each groups are - satisfyed. I'm sure it is possible to find a better algorithm, - but I am lazy */ - do { - recurse = 0; - for(i=1;i<=nb_groups;i++) { - delta = exp1[i] - exp1[i-1]; - if (delta > 2) { - /* if delta too big, we encode a smaller exponent */ - exp1[i] = exp1[i-1] + 2; - } else if (delta < -2) { - /* if delta is too small, we must decrease the previous - exponent, which means we must recurse */ - recurse = 1; - exp1[i-1] = exp1[i] + 2; - } - } - } while (recurse); - + /* Decrease the delta between each groups to within 2 + * so that they can be differentially encoded */ + for (i=1;i<=nb_groups;i++) + exp1[i] = FFMIN(exp1[i], exp1[i-1] + 2); + for (i=nb_groups-1;i>=0;i--) + exp1[i] = FFMIN(exp1[i], exp1[i+1] + 2); + /* now we have the exponent values the decoder will see */ encoded_exp[0] = exp1[0]; k = 1;