diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index b8abd297a16b82c8e93107aeb7ca820f033d0c4d..9d4c87d66b3e37827620f15c174290b4f71cc586 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -239,10 +239,11 @@ static int16_t g726_decode(G726Context* c, int I)
     c->dml += ((c->tbls.F[I]<<11) - c->dml) >> 7;
     if (tr)
         c->ap = 256;
-    else if (c->y > 1535 && !c->td && abs((c->dms << 2) - c->dml) < (c->dml >> 3))
+    else {
         c->ap += (-c->ap) >> 4;
-    else
-        c->ap += (0x200 - c->ap) >> 4;
+        if (c->y <= 1535 || c->td || abs((c->dms << 2) - c->dml) >= (c->dml >> 3))
+            c->ap += 0x20;
+    }
 
     /* Update Yu and Yl */
     c->yu = av_clip(c->y + c->tbls.W[I] + ((-c->y)>>5), 544, 5120);