---
 libavcodec/ac3enc.c |   48 ++++++++++++++++++++++--------------------------
 1 files changed, 22 insertions(+), 26 deletions(-)

diff --git libavcodec/ac3enc.c libavcodec/ac3enc.c
index b264991..fa6dbe2 100644
--- libavcodec/ac3enc.c
+++ libavcodec/ac3enc.c
@@ -573,12 +573,11 @@ static int bit_alloc(AC3EncodeContext *s,
                      int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50],
                      int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
                      uint8_t bap[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
-                     int frame_bits, int coarse_snr_offset, int fine_snr_offset)
+                     int frame_bits, int snr_offset)
 {
     int blk, ch;
-    int snr_offset;
 
-    snr_offset = (((coarse_snr_offset - 15) << 4) + fine_snr_offset) << 2;
+    snr_offset = (snr_offset - 240) << 2;
 
     /* compute size */
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
@@ -601,8 +600,6 @@ static int bit_alloc(AC3EncodeContext *s,
     return 16 * s->frame_size - frame_bits;
 }
 
-#define SNR_INC1 4
-
 static int compute_bit_allocation(AC3EncodeContext *s,
                                   uint8_t bap[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
                                   uint8_t encoded_exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
@@ -610,7 +607,7 @@ static int compute_bit_allocation(AC3EncodeContext *s,
                                   int frame_bits)
 {
     int blk, ch;
-    int coarse_snr_offset, fine_snr_offset;
+    int snr_offset;
     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];
@@ -675,43 +672,42 @@ static int compute_bit_allocation(AC3EncodeContext *s,
     /* now the big work begins : do the bit allocation. Modify the snr
        offset until we can pack everything in the requested frame size */
 
-    coarse_snr_offset = s->coarse_snr_offset;
-    while (coarse_snr_offset >= 0 &&
-           bit_alloc(s, mask, psd, bap, frame_bits, coarse_snr_offset, 0) < 0)
-        coarse_snr_offset -= SNR_INC1;
-    if (coarse_snr_offset < 0) {
+    snr_offset = s->coarse_snr_offset << 4;
+    while (snr_offset >= 0 &&
+           bit_alloc(s, mask, psd, bap, frame_bits, snr_offset) < 0)
+        snr_offset -= 64;
+    if (snr_offset < 0) {
         av_log(NULL, AV_LOG_ERROR, "Bit allocation failed. Try increasing the bitrate.\n");
         return -1;
     }
-    while ((coarse_snr_offset + SNR_INC1) <= 63 &&
+    while ((snr_offset + 64) <= 1023 &&
            bit_alloc(s, mask, psd, bap1, frame_bits,
-                     coarse_snr_offset + SNR_INC1, 0) >= 0) {
-        coarse_snr_offset += SNR_INC1;
+                     snr_offset + 64) >= 0) {
+        snr_offset += 64;
         memcpy(bap, bap1, sizeof(bap1));
     }
-    while ((coarse_snr_offset + 1) <= 63 &&
-           bit_alloc(s, mask, psd, bap1, frame_bits, coarse_snr_offset + 1, 0) >= 0) {
-        coarse_snr_offset++;
+    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));
     }
 
-    fine_snr_offset = 0;
-    while ((fine_snr_offset + SNR_INC1) <= 15 &&
+    while ((snr_offset + 4) <= 1023 &&
            bit_alloc(s, mask, psd, bap1, frame_bits,
-                     coarse_snr_offset, fine_snr_offset + SNR_INC1) >= 0) {
-        fine_snr_offset += SNR_INC1;
+                     snr_offset + 4) >= 0) {
+        snr_offset += 4;
         memcpy(bap, bap1, sizeof(bap1));
     }
-    while ((fine_snr_offset + 1) <= 15 &&
+    while ((snr_offset + 1) <= 1023 &&
            bit_alloc(s, mask, psd, bap1, frame_bits,
-                     coarse_snr_offset, fine_snr_offset + 1) >= 0) {
-        fine_snr_offset++;
+                     snr_offset + 1) >= 0) {
+        snr_offset++;
         memcpy(bap, bap1, sizeof(bap1));
     }
 
-    s->coarse_snr_offset = coarse_snr_offset;
+    s->coarse_snr_offset = snr_offset >> 4;
     for(ch=0;ch<s->channels;ch++)
-        s->fine_snr_offset[ch] = fine_snr_offset;
+        s->fine_snr_offset[ch] = snr_offset & 0xF;
 #ifdef DEBUG_BITALLOC
     {
         int i;
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to