summaryrefslogtreecommitdiff
path: root/libavcodec/ac3enc.c
diff options
context:
space:
mode:
authorJeff Muizelaar <jrmuizel@gmail.com>2004-08-02 10:42:21 +0000
committerMichael Niedermayer <michaelni@gmx.at>2004-08-02 10:42:21 +0000
commite44cad52914532d5e87f528b823f0f0ead21b1e0 (patch)
tree92bb53d614dba30c01faeae288b02a9fe886c8f9 /libavcodec/ac3enc.c
parentd8665b12740d09f5ecbc06c8dba47afb480ea2c7 (diff)
simpler delta decreasing algorithm patch by (Jeff Muizelaar <jrmuizel at student dot cs dot uwaterloo dot ca>)
Originally committed as revision 3369 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r--libavcodec/ac3enc.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 1ce534a8ed..78af63b9c9 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -515,7 +515,7 @@ static int encode_exp(uint8_t encoded_exp[N/2],
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 @@ static int encode_exp(uint8_t encoded_exp[N/2],
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;