Reduce code duplication by using a loop in the bit allocation search.
---
 libavcodec/ac3enc.c |   30 +++++++-----------------------
 1 files changed, 7 insertions(+), 23 deletions(-)

diff --git libavcodec/ac3enc.c libavcodec/ac3enc.c
index fc50fb5..e98e3de 100644
--- libavcodec/ac3enc.c
+++ libavcodec/ac3enc.c
@@ -635,7 +635,7 @@ static int compute_bit_allocation(AC3EncodeContext *s,
                                   int frame_bits)
 {
     int blk, ch;
-    int snr_offset;
+    int snr_offset, snr_incr;
     uint8_t bap1[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
     int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
     int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50];
@@ -707,29 +707,13 @@ static int compute_bit_allocation(AC3EncodeContext *s,
     if (snr_offset < 0) {
         return -1;
     }
-    while ((snr_offset + 64) <= 1023 &&
-           bit_alloc(s, mask, psd, bap1, frame_bits,
-                     snr_offset + 64) >= 0) {
-        snr_offset += 64;
-        memcpy(bap, bap1, sizeof(bap1));
-    }
-    while ((snr_offset + 16) <= 1023 &&
-           bit_alloc(s, mask, psd, bap1, frame_bits, snr_offset + 16) >= 0) {
-        snr_offset += 16;
-        memcpy(bap, bap1, sizeof(bap1));
-    }
 
-    while ((snr_offset + 4) <= 1023 &&
-           bit_alloc(s, mask, psd, bap1, frame_bits,
-                     snr_offset + 4) >= 0) {
-        snr_offset += 4;
-        memcpy(bap, bap1, sizeof(bap1));
-    }
-    while ((snr_offset + 1) <= 1023 &&
-           bit_alloc(s, mask, psd, bap1, frame_bits,
-                     snr_offset + 1) >= 0) {
-        snr_offset++;
-        memcpy(bap, bap1, sizeof(bap1));
+    for (snr_incr = 64; snr_incr > 0; snr_incr >>= 2) {
+        while (snr_offset + snr_incr <= 1023 &&
+               bit_alloc(s, mask, psd, bap1, frame_bits, snr_offset + snr_incr) >= 0) {
+            snr_offset += snr_incr;
+            memcpy(bap, bap1, sizeof(bap1));
+        }
     }
 
     s->coarse_snr_offset = snr_offset >> 4;
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to