From 46ba3676b854acbc69a4c7845f578d4c2886377b Mon Sep 17 00:00:00 2001
From: Jean-Michel Trivi <jmtrivi@google.com>
Date: Fri, 8 Apr 2016 10:52:42 -0700
Subject: AAC/SBR encoder improvements

* AAC-Encoder

  - AAC-ELD core encoder audio quality tuning. Update tuning tables, configure
    bitreservoir size and adapt afterburner iteration value.
     Modified file(s):
        libAACenc/src/aacenc.h
        libAACenc/src/aacenc_lib.cpp
        libAACenc/src/adj_thr.cpp
        libAACenc/src/adj_thr.h
        libAACenc/src/adj_thr_data.h
        libAACenc/src/bandwidth.cpp
        libAACenc/src/pnsparam.cpp
        libAACenc/src/qc_main.cpp

   - Introduze dead zone quantizer for ELD to improve audio quality at certain
     configurations.
     Modified file(s):
        libAACenc/src/aacenc_lib.cpp
        libAACenc/src/adj_thr.cpp
        libAACenc/src/adj_thr.h
        libAACenc/src/qc_data.h
        libAACenc/src/qc_main.cpp
        libAACenc/src/quantize.cpp
        libAACenc/src/quantize.h
        libAACenc/src/sf_estim.cpp
        libAACenc/src/sf_estim.h

   - Revise TNS module to improve ELD audio quality.
   - Use new window function and separate prediction gain according TNS filters.
   - Add missing memory initilization to TNS configuration.
     Modified file(s):
        libAACenc/src/aacenc_lib.cpp
        libAACenc/src/aacenc_tns.cpp
        libAACenc/src/aacenc_tns.h
        libAACenc/src/psy_main.cpp
        libAACenc/src/tns_func.h

* SBR-Encoder

   - Revise frequency resolution calculation and handle differently depending
     on number of envelopes and split frames decision.
   - Add and adjust ELD SBR tuning tables.
     Modified file(s):
        libSBRenc/include/sbr_encoder.h
        libSBRenc/src/bit_sbr.h
        libSBRenc/src/env_est.cpp
        libSBRenc/src/fram_gen.cpp
        libSBRenc/src/fram_gen.h
        libSBRenc/src/mh_det.cpp
        libSBRenc/src/sbr_def.h
        libSBRenc/src/sbr_encoder.cpp
        libSBRenc/src/sbr_rom.cpp
        libSBRenc/src/tran_det.cpp

   - Replace ELD transient detector with fast implementation.
     Modified file(s):
        libSBRenc/src/env_est.cpp
        libSBRenc/src/env_est.h
        libSBRenc/src/fram_gen.cpp
        libSBRenc/src/sbr_def.h
        libSBRenc/src/sbr_encoder.cpp
        libSBRenc/src/tran_det.cpp
        libSBRenc/src/tran_det.h

* FDK-Library
   - Introduce generic compare function in tools library.
     Modified file(s):
        libFDK/include/fixpoint_math.h
        libFDK/src/FDK_core.cpp

* SBR-Encoder

  -  Revise ELD frame splitter to improve bit distribution.
     Modified file(s):
        libSBRenc/include/sbr_encoder.h
        libSBRenc/src/bit_sbr.h
        libSBRenc/src/env_est.cpp
        libSBRenc/src/fram_gen.cpp
        libSBRenc/src/fram_gen.h
        libSBRenc/src/sbr_encoder.cpp
        libSBRenc/src/tran_det.cpp
        libSBRenc/src/tran_det.h

   - Configure amplitude resolution according the tonality of the audio signal.
     Modified file(s):
        libSBRenc/include/sbr_encoder.h
        libSBRenc/src/bit_sbr.h
        libSBRenc/src/env_est.cpp
        libSBRenc/src/nf_est.cpp
        libSBRenc/src/nf_est.h
        libSBRenc/src/sbr_def.h
        libSBRenc/src/sbr_encoder.cpp
        libSBRenc/src/ton_corr.cpp
        libSBRenc/src/ton_corr.h
        libSBRenc/src/tran_det.cpp
        libSBRenc/src/tran_det.h

Change-Id: Ie0672b989a06ee63b50240616b8d1d4b790b6cb2
---
 libAACenc/src/quantize.cpp | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

(limited to 'libAACenc/src/quantize.cpp')

diff --git a/libAACenc/src/quantize.cpp b/libAACenc/src/quantize.cpp
index 5380e35..a74da0e 100644
--- a/libAACenc/src/quantize.cpp
+++ b/libAACenc/src/quantize.cpp
@@ -2,7 +2,7 @@
 /* -----------------------------------------------------------------------------------------------------------
 Software License for The Fraunhofer FDK AAC Codec Library for Android
 
-� Copyright  1995 - 2013 Fraunhofer-Gesellschaft zur F�rderung der angewandten Forschung e.V.
+� Copyright  1995 - 2015 Fraunhofer-Gesellschaft zur F�rderung der angewandten Forschung e.V.
   All rights reserved.
 
  1.    INTRODUCTION
@@ -104,13 +104,19 @@ amm-info@iis.fraunhofer.de
 static void FDKaacEnc_quantizeLines(INT      gain,
                           INT      noOfLines,
                           FIXP_DBL *mdctSpectrum,
-                          SHORT      *quaSpectrum)
+                          SHORT    *quaSpectrum,
+                          INT      dZoneQuantEnable)
 {
   int   line;
-  FIXP_DBL k = FL2FXCONST_DBL(-0.0946f + 0.5f)>>16;
+  FIXP_DBL k = FL2FXCONST_DBL(0.0f);
   FIXP_QTD quantizer = FDKaacEnc_quantTableQ[(-gain)&3];
   INT      quantizershift = ((-gain)>>2)+1;
+  const INT kShift=16;
 
+  if (dZoneQuantEnable)
+    k = FL2FXCONST_DBL(0.23f)>>kShift;
+  else
+    k = FL2FXCONST_DBL(-0.0946f + 0.5f)>>kShift;
 
   for (line = 0; line < noOfLines; line++)
   {
@@ -263,7 +269,8 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt,
                       FIXP_DBL *mdctSpectrum,
                       INT globalGain,
                       INT *scalefactors,
-                      SHORT *quantizedSpectrum)
+                      SHORT *quantizedSpectrum,
+                      INT dZoneQuantEnable)
 {
   INT sfbOffs,sfb;
 
@@ -280,7 +287,8 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt,
     FDKaacEnc_quantizeLines(globalGain - scalefactor, /* QSS */
                   sfbOffset[sfbOffs+sfb+1] - sfbOffset[sfbOffs+sfb],
                   mdctSpectrum + sfbOffset[sfbOffs+sfb],
-                  quantizedSpectrum + sfbOffset[sfbOffs+sfb]);
+                  quantizedSpectrum + sfbOffset[sfbOffs+sfb],
+                  dZoneQuantEnable);
   }
 }
 
@@ -296,7 +304,8 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt,
 FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum,
                      SHORT *quantSpectrum,
                      INT noOfLines,
-                     INT gain
+                     INT gain,
+                     INT dZoneQuantEnable
                      )
 {
   INT i,scale;
@@ -311,7 +320,8 @@ FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum,
     FDKaacEnc_quantizeLines(gain,
                   1,
                  &mdctSpectrum[i],
-                 &quantSpectrum[i]);
+                 &quantSpectrum[i],
+                  dZoneQuantEnable);
 
     if (fAbs(quantSpectrum[i])>MAX_QUANT) {
       return FL2FXCONST_DBL(0.0f);
-- 
cgit v1.2.3