merge in nyc-release history after reset to nyc-dev
diff --git a/documentation/aacDecoder.pdf b/documentation/aacDecoder.pdf
index d388576..458fda1 100644
--- a/documentation/aacDecoder.pdf
+++ b/documentation/aacDecoder.pdf
Binary files differ
diff --git a/libAACdec/include/aacdecoder_lib.h b/libAACdec/include/aacdecoder_lib.h
index a0c0854..7ab60f1 100644
--- a/libAACdec/include/aacdecoder_lib.h
+++ b/libAACdec/include/aacdecoder_lib.h
@@ -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
@@ -378,6 +378,7 @@
                                                          not exist. */
   AAC_DEC_NEED_TO_RESTART                = 0x200B,  /*!< The decoder needs to be restarted, since the requiered configuration change cannot be
                                                          performed. */
+  AAC_DEC_OUTPUT_BUFFER_TOO_SMALL        = 0x200C,  /*!< The provided output buffer is too small. */
   aac_dec_init_error_end                 = 0x2FFF,
 
   /* Decode errors. Output buffer is valid but concealed. */
diff --git a/libAACdec/src/aac_rom.cpp b/libAACdec/src/aac_rom.cpp
index 607cb3b..f3c9b5a 100644
--- a/libAACdec/src/aac_rom.cpp
+++ b/libAACdec/src/aac_rom.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
@@ -167,6 +167,36 @@
 } ;
 
 
+/* 41 scfbands */
+static const SHORT sfb_96_1024[42] =
+{
+     0,    4,    8,   12,   16,   20,   24,   28,   32,   36,   40,   44,
+    48,   52,   56,   64,   72,   80,   88,   96,  108,  120,  132,  144,
+   156,  172,  188,  212,  240,  276,  320,  384,  448,  512,  576,  640,
+   704,  768,  832,  896,  960, 1024
+};
+/* 12 scfbands */
+static const SHORT sfb_96_128[13] =
+{
+     0,    4,    8,   12,   16,   20,   24,   32,   40,   48,    64,  92,
+   128
+};
+
+/* 47 scfbands*/
+static const SHORT sfb_64_1024[48] =
+{
+     0,   4,   8,  12,  16,  20,  24,   28,  32,  36,  40,  44,  48,  52,
+    56,  64,  72,  80,  88, 100, 112,  124, 140, 156, 172, 192, 216, 240,
+   268, 304, 344, 384, 424, 464, 504,  544, 584, 624, 664, 704, 744, 784,
+   824, 864, 904, 944, 984,1024
+};
+
+/* 12 scfbands */
+static const SHORT sfb_64_128[13] =
+{
+     0,   4,   8,  12,  16,  20,  24,
+    32,  40,  48,  64,  92, 128
+};
 
 /* 49 scfbands */
 static const SHORT sfb_48_1024[50] = {
@@ -239,6 +269,35 @@
 };
 
 
+static const SHORT sfb_96_960[42] =
+{
+  0,      4,      8,      12,     16,     20,     24,     28,     32,     36,
+  40,     44,     48,     52,     56,     64,     72,     80,     88,     96,
+  108,    120,    132,    144,    156,    172,    188,    212,    240,    276,
+  320,    384,    448,    512,    576,    640,    704,    768,    832,    896,
+  960
+};   /* 40 scfbands */
+
+static const SHORT sfb_96_120[13] =
+{
+  0,      4,      8,      12,     16,     20,     24,     32,     40,     48,
+  64,     92,     120
+};   /* 12 scfbands */
+
+static const SHORT sfb_64_960[47] =
+{
+  0,      4,      8,      12,     16,     20,     24,     28,     32,     36,
+  40,     44,     48,     52,     56,     64,     72,     80,     88,     100,
+  112,    124,    140,    156,    172,    192,    216,    240,    268,    304,
+  344,    384,    424,    464,    504,    544,    584,    624,    664,    704,
+  744,    784,    824,    864,    904,    944,    960
+};   /* 46 scfbands */
+
+static const SHORT sfb_64_120[13] =
+{
+  0,      4,      8,      12,     16,     20,     24,     32,     40,     48,
+  64,     92,     120
+};   /* 12 scfbands */
 
 static const SHORT sfb_48_960[50] =
 {
@@ -358,9 +417,9 @@
 const SFB_INFO sfbOffsetTables[5][16] =
 {
   {
-    { NULL, NULL, 0, 0 },
-    { NULL, NULL, 0, 0 },
-    { NULL, NULL, 0, 0 },
+    { sfb_96_1024, sfb_96_128, 41, 12 },
+    { sfb_96_1024, sfb_96_128, 41, 12 },
+    { sfb_64_1024, sfb_64_128, 47, 12 },
     { sfb_48_1024, sfb_48_128, 49, 14 },
     { sfb_48_1024, sfb_48_128, 49, 14 },
     { sfb_32_1024, sfb_48_128, 51, 14 },
@@ -372,9 +431,9 @@
     { sfb_8_1024, sfb_8_128, 40, 15 },
     { sfb_8_1024, sfb_8_128, 40, 15 },
   }, {
-    { NULL, NULL, 0, 0 },
-    { NULL, NULL, 0, 0 },
-    { NULL, NULL, 0, 0 },
+    { sfb_96_960, sfb_96_120, 40, 12 },
+    { sfb_96_960, sfb_96_120, 40, 12 },
+    { sfb_64_960, sfb_64_120, 46, 12 },
     { sfb_48_960, sfb_48_120, 49, 14 },
     { sfb_48_960, sfb_48_120, 49, 14 },
     { sfb_32_960, sfb_48_120, 49, 14 },
@@ -388,9 +447,9 @@
   }, {
     { NULL, NULL, 0, 0 },
   }, {
-    { NULL, NULL, 0, 0 },
-    { NULL, NULL, 0, 0 },
-    { NULL, NULL, 0, 0 },
+    { sfb_48_512,  NULL, 36, 0 },
+    { sfb_48_512,  NULL, 36, 0 },
+    { sfb_48_512,  NULL, 36, 0 },
     { sfb_48_512,  NULL, 36, 0 },
     { sfb_48_512, NULL, 36, 0},
     { sfb_32_512, NULL, 37, 0 },
@@ -402,9 +461,9 @@
     { sfb_24_512, NULL, 31, 0 },
     { sfb_24_512, NULL, 31, 0 },
   }, {
-    { NULL, NULL, 0, 0 },
-    { NULL, NULL, 0, 0 },
-    { NULL, NULL, 0, 0 },
+    { sfb_48_480, NULL, 35, 0 },
+    { sfb_48_480, NULL, 35, 0 },
+    { sfb_48_480, NULL, 35, 0 },
     { sfb_48_480, NULL, 35, 0 },
     { sfb_48_480, NULL, 35, 0 },
     { sfb_32_480, NULL, 37, 0 },
diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp
index 8270f69..579e470 100644
--- a/libAACdec/src/aacdecoder.cpp
+++ b/libAACdec/src/aacdecoder.cpp
@@ -157,6 +157,7 @@
 
 #include "conceal.h"
 
+  #include "FDK_crc.h"
 
 
 void CAacDecoder_SyncQmfMode(HANDLE_AACDECODER self)
@@ -537,8 +538,9 @@
                 previous_element,
                 elIndex,
                 self->flags & AC_INDEP );
-        /* Enable SBR for implicit SBR signalling. */
-        if (sbrError == SBRDEC_OK) {
+        /* Enable SBR for implicit SBR signalling but only if no severe error happend. */
+        if ( (sbrError == SBRDEC_OK)
+          || (sbrError == SBRDEC_PARSE_ERROR) ) {
           self->sbrEnabled = 1;
         }
       } else {
@@ -553,7 +555,7 @@
         FDKpushBiDirectional(hBs, *count);
         *count = 0;
       } else {
-        /* If this is not a fill element with a known length, we are screwed an no further parsing makes sense. */
+        /* If this is not a fill element with a known length, we are screwed and further parsing makes no sense. */
         if (sbrError != SBRDEC_OK) {
           self->frameOK = 0;
         }
@@ -832,12 +834,18 @@
   switch (asc->m_aot) {
   case AOT_AAC_LC:
     self->streamInfo.profile = 1;
-    break;
+
+  case AOT_ER_AAC_SCAL:
+    if (asc->m_sc.m_gaSpecificConfig.m_layer > 0) {
+      /* aac_scalable_extension_element() currently not supported. */
+      return AAC_DEC_UNSUPPORTED_FORMAT;
+    }
 
   case AOT_SBR:
   case AOT_PS:
   case AOT_ER_AAC_LD:
   case AOT_ER_AAC_ELD:
+  case AOT_DRM_AAC:
     break;
 
   default:
@@ -957,11 +965,20 @@
 
   if (asc->m_aot == AOT_ER_AAC_ELD) {
     self->flags |=  AC_ELD;
+    self->flags |= (asc->m_sbrPresentFlag) ? AC_SBR_PRESENT : 0;  /* Need to set the SBR flag for backward-compatibility
+                                                                     reasons. Even if SBR is not supported. */
     self->flags |= (asc->m_sc.m_eldSpecificConfig.m_sbrCrcFlag) ? AC_SBRCRC : 0;
     self->flags |= (asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign) ? AC_LD_MPS : 0;
   }
   self->flags |= (asc->m_aot == AOT_ER_AAC_LD) ? AC_LD : 0;
   self->flags |= (asc->m_epConfig >= 0) ? AC_ER : 0;
+  if ( asc->m_aot == AOT_DRM_AAC ) {
+    self->flags |= AC_DRM|AC_SBRCRC|AC_SCALABLE;
+  }
+  if ( (asc->m_aot == AOT_AAC_SCAL)
+    || (asc->m_aot == AOT_ER_AAC_SCAL) ) {
+    self->flags |= AC_SCALABLE;
+  }
 
 
   if (asc->m_sbrPresentFlag) {
@@ -1147,6 +1164,9 @@
 
   /* Check sampling frequency  */
   switch ( self->streamInfo.aacSampleRate ) {
+    case 96000:
+    case 88200:
+    case 64000:
     case 16000:
     case 12000:
    case 11025:
@@ -1475,7 +1495,7 @@
           /* get the remaining bits of this frame */
           bitCnt = transportDec_GetAuBitsRemaining(self->hInput, 0);
 
-          if ( (bitCnt > 0) && (self->flags & AC_SBR_PRESENT) && (self->flags & (AC_USAC|AC_RSVD50|AC_ELD)) )
+          if ( (bitCnt > 0) && (self->flags & AC_SBR_PRESENT) && (self->flags & (AC_USAC|AC_RSVD50|AC_ELD|AC_DRM)) )
           {
             SBR_ERROR err = SBRDEC_OK;
             int  elIdx, numChElements = el_cnt[ID_SCE] + el_cnt[ID_CPE];
@@ -1513,6 +1533,13 @@
           }
 
 
+          if (self->flags & AC_DRM)
+          {
+            if ((bitCnt = (INT)FDKgetValidBits(bs)) != 0) {
+              FDKpushBiDirectional(bs, bitCnt);
+            }
+          }
+
           if ( ! (self->flags & (AC_USAC|AC_RSVD50|AC_DRM)) )
           {
             while ( bitCnt > 7 ) {
diff --git a/libAACdec/src/aacdecoder.h b/libAACdec/src/aacdecoder.h
index 3541773..25bc35d 100644
--- a/libAACdec/src/aacdecoder.h
+++ b/libAACdec/src/aacdecoder.h
@@ -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
@@ -226,6 +226,8 @@
   FIXP_DBL     extGain[1];                           /*!< Gain that must be applied to the output signal. */
   UINT         extGainDelay;                         /*!< Delay that must be accounted for extGain. */
 
+  INT_PCM      pcmOutputBuffer[(8)*(2048)];
+
 };
 
 
diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp
index b501eb9..8863da5 100644
--- a/libAACdec/src/aacdecoder_lib.cpp
+++ b/libAACdec/src/aacdecoder_lib.cpp
@@ -110,7 +110,7 @@
 /* Decoder library info */
 #define AACDECODER_LIB_VL0 2
 #define AACDECODER_LIB_VL1 5
-#define AACDECODER_LIB_VL2 11
+#define AACDECODER_LIB_VL2 17
 #define AACDECODER_LIB_TITLE "AAC Decoder Lib"
 #ifdef __ANDROID__
 #define AACDECODER_LIB_BUILD_DATE ""
@@ -181,8 +181,9 @@
           break;
         }
         /* if baselayer is OK we continue decoding */
-        if(layer  >= 1){
+        if(layer >= 1){
           self->nrOfLayers = layer;
+          err = AAC_DEC_OK;
         }
         break;
       }
@@ -785,8 +786,8 @@
 
 LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_DecodeFrame(
         HANDLE_AACDECODER  self,
-        INT_PCM           *pTimeData,
-        const INT          timeDataSize,
+        INT_PCM           *pTimeData_extern,
+        const INT          timeDataSize_extern,
         const UINT         flags)
 {
     AAC_DECODER_ERROR ErrorStatus;
@@ -796,12 +797,17 @@
     HANDLE_FDK_BITSTREAM hBs;
     int fTpInterruption = 0;  /* Transport originated interruption detection. */
     int fTpConceal = 0;       /* Transport originated concealment. */
+    INT_PCM *pTimeData = NULL;
+    INT timeDataSize = 0;
 
 
     if (self == NULL) {
       return AAC_DEC_INVALID_HANDLE;
     }
 
+    pTimeData = self->pcmOutputBuffer;
+    timeDataSize = sizeof(self->pcmOutputBuffer)/sizeof(*self->pcmOutputBuffer);
+
     if (flags & AACDEC_INTR) {
       self->streamInfo.numLostAccessUnits = 0;
     }
@@ -918,7 +924,8 @@
     if (self->sbrEnabled)
     {
       SBR_ERROR sbrError = SBRDEC_OK;
-      int chOutMapIdx = ((self->chMapIndex==0) && (self->streamInfo.numChannels<7)) ? self->streamInfo.numChannels : self->chMapIndex;
+      int chIdx, numCoreChannel = self->streamInfo.numChannels;
+      int chOutMapIdx = ((self->chMapIndex==0) && (numCoreChannel<7)) ? numCoreChannel : self->chMapIndex;
 
       /* set params */
       sbrDecoder_SetParam ( self->hSbrDecoder,
@@ -978,10 +985,10 @@
 
        if (self->psPossible) {
          self->flags |= AC_PS_PRESENT;
-         self->channelType[0] = ACT_FRONT;
-         self->channelType[1] = ACT_FRONT;
-         self->channelIndices[0] = 0;
-         self->channelIndices[1] = 1;
+       }
+       for (chIdx = numCoreChannel; chIdx < self->streamInfo.numChannels; chIdx+=1) {
+         self->channelType[chIdx] = ACT_FRONT;
+         self->channelIndices[chIdx] = chIdx;
        }
      }
    }
@@ -1006,7 +1013,8 @@
             self->channelOutputMapping,
             (self->limiterEnableCurr) ? &pcmLimiterScale : NULL
       );
-    if (dmxErr == PCMDMX_INVALID_MODE) {
+    if ( (ErrorStatus == AAC_DEC_OK)
+      && (dmxErr == PCMDMX_INVALID_MODE) ) {
       /* Announce the framework that the current combination of channel configuration and downmix
        * settings are not know to produce a predictable behavior and thus maybe produce strange output. */
       ErrorStatus = AAC_DEC_DECODE_FRAME_ERROR;
@@ -1051,6 +1059,19 @@
     /* Update Statistics */
     aacDecoder_UpdateBitStreamCounters(&self->streamInfo, hBs, nBits, ErrorStatus);
 
+    /* Check whether external output buffer is large enough. */
+    if (timeDataSize_extern < self->streamInfo.numChannels*self->streamInfo.frameSize) {
+      ErrorStatus = AAC_DEC_OUTPUT_BUFFER_TOO_SMALL;
+    }
+
+    /* Update external output buffer. */
+    if ( IS_OUTPUT_VALID(ErrorStatus) ) {
+      FDKmemcpy(pTimeData_extern, pTimeData, self->streamInfo.numChannels*self->streamInfo.frameSize*sizeof(*pTimeData));
+    }
+    else {
+      FDKmemclear(pTimeData_extern, timeDataSize_extern*sizeof(*pTimeData_extern));
+    }
+
     return ErrorStatus;
 }
 
@@ -1120,6 +1141,7 @@
   /* Set flags */
   info->flags = 0
       | CAPF_AAC_LC
+      | CAPF_ER_AAC_SCAL
       | CAPF_AAC_VCB11
       | CAPF_AAC_HCR
       | CAPF_AAC_RVLC
@@ -1130,6 +1152,7 @@
 
       | CAPF_AAC_MPEG4
 
+      | CAPF_AAC_DRM_BSFORMAT
 
       | CAPF_AAC_1024
       | CAPF_AAC_960
diff --git a/libAACdec/src/block.cpp b/libAACdec/src/block.cpp
index 9d703cc..2965fa6 100644
--- a/libAACdec/src/block.cpp
+++ b/libAACdec/src/block.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
@@ -324,11 +324,11 @@
 
       if (flags & AC_ER_HCR) {
         /* HCR input (long) -- collecting sideinfo (for HCR-_long_ only) */
-        pNumLinesInSec[numLinesInSecIdx] = BandOffsets[top] - BandOffsets[band];
-        numLinesInSecIdx++;
         if (numLinesInSecIdx >= MAX_SFB_HCR) {
           return AAC_DEC_PARSE_ERROR;
         }
+        pNumLinesInSec[numLinesInSecIdx] = BandOffsets[top] - BandOffsets[band];
+        numLinesInSecIdx++;
         if (
              (sect_cb == BOOKSCL) )
         {
diff --git a/libAACenc/src/aacenc.h b/libAACenc/src/aacenc.h
index 61520de..79524b5 100644
--- a/libAACenc/src/aacenc.h
+++ b/libAACenc/src/aacenc.h
@@ -98,6 +98,11 @@
 
 #include "sbr_encoder.h"
 
+#define BITRES_MAX_LD   4000
+#define BITRES_MIN_LD    500
+#define BITRATE_MAX_LD 70000 /* Max assumed bitrate for bitres calculation */
+#define BITRATE_MIN_LD 12000 /* Min assumed bitrate for bitres calculation */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp
index 9a3b214..2845177 100644
--- a/libAACenc/src/aacenc_lib.cpp
+++ b/libAACenc/src/aacenc_lib.cpp
@@ -98,7 +98,7 @@
 /* Encoder library info */
 #define AACENCODER_LIB_VL0 3
 #define AACENCODER_LIB_VL1 4
-#define AACENCODER_LIB_VL2 19
+#define AACENCODER_LIB_VL2 22
 #define AACENCODER_LIB_TITLE "AAC Encoder"
 #ifdef __ANDROID__
 #define AACENCODER_LIB_BUILD_DATE ""
@@ -813,11 +813,16 @@
     switch ( hAacConfig->audioObjectType ) {
       case AOT_ER_AAC_LD:
       case AOT_ER_AAC_ELD:
-        if (config->userBitrateMode==8) {
-          hAacConfig->bitrateMode = 0;
-        }
         if (config->userBitrateMode==0) {
-          hAacConfig->bitreservoir = 100*config->nChannels; /* default, reduced bitreservoir */
+          /* bitreservoir  = (maxBitRes-minBitRes)/(maxBitRate-minBitrate)*(bitRate-minBitrate)+minBitRes; */
+          if ( isLowDelay(hAacConfig->audioObjectType) ) {
+            INT bitreservoir;
+            INT brPerChannel = hAacConfig->bitRate/hAacConfig->nChannels;
+            brPerChannel     = fMin(BITRATE_MAX_LD, fMax(BITRATE_MIN_LD, brPerChannel));
+            FIXP_DBL slope   = fDivNorm((brPerChannel-BITRATE_MIN_LD), BITRATE_MAX_LD-BITRATE_MIN_LD); /* calc slope for interpolation */
+            bitreservoir     = fMultI(slope, (INT)(BITRES_MAX_LD-BITRES_MIN_LD)) + BITRES_MIN_LD; /* interpolate */
+            hAacConfig->bitreservoir = bitreservoir & ~7; /* align to bytes */
+          }
         }
         if (hAacConfig->bitrateMode!=0) {
           return AACENC_INVALID_CONFIG;
diff --git a/libAACenc/src/aacenc_tns.cpp b/libAACenc/src/aacenc_tns.cpp
index 85aea65..9a07e8f 100644
--- a/libAACenc/src/aacenc_tns.cpp
+++ b/libAACenc/src/aacenc_tns.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
@@ -95,13 +95,7 @@
 #include "aacEnc_rom.h"
 #include "aacenc_tns.h"
 
-enum {
-    HIFILT = 0, /* index of higher filter */
-    LOFILT = 1 /* index of lower filter */
-};
-
-
-#define FILTER_DIRECTION 0
+#define FILTER_DIRECTION 0 /* 0 = up, 1 = down */
 
 static const FIXP_DBL acfWindowLong[12+3+1] = {
   0x7fffffff,0x7fb80000,0x7ee00000,0x7d780000,0x7b800000,0x78f80000,0x75e00000,0x72380000,
@@ -112,20 +106,6 @@
   0x7fffffff,0x7e000000,0x78000000,0x6e000000,0x60000000,0x4e000000,0x38000000,0x1e000000
 };
 
-
-typedef struct {
-  INT      filterEnabled[MAX_NUM_OF_FILTERS];
-  INT      threshOn[MAX_NUM_OF_FILTERS];                /* min. prediction gain for using tns TABUL*/
-  INT      filterStartFreq[MAX_NUM_OF_FILTERS];         /* lowest freq for lpc TABUL*/
-  INT      tnsLimitOrder[MAX_NUM_OF_FILTERS];           /* Limit for TNS order TABUL*/
-  INT      tnsFilterDirection[MAX_NUM_OF_FILTERS];      /* Filtering direction, 0=up, 1=down TABUL */
-  INT      acfSplit[MAX_NUM_OF_FILTERS];
-  FIXP_DBL tnsTimeResolution[MAX_NUM_OF_FILTERS];       /* TNS max. time resolution TABUL. Should be fract but MSVC won't compile then */
-  INT      seperateFiltersAllowed;
-
-} TNS_PARAMETER_TABULATED;
-
-
 typedef struct{
   INT                      bitRateFrom[2];  /* noneSbr=0, useSbr=1 */
   INT                      bitRateTo[2];    /* noneSbr=0, useSbr=1 */
@@ -373,6 +353,7 @@
                                                  INT channels,
                                                  INT blockType,
                                                  INT granuleLength,
+                                                 INT isLowDelay,
                                                  INT ldSbrPresent,
                                                  TNS_CONFIG *tC,
                                                  PSY_CONFIGURATION *pC,
@@ -385,6 +366,8 @@
   if (channels <= 0)
     return (AAC_ENCODER_ERROR)1;
 
+  tC->isLowDelay = isLowDelay;
+
   /* initialize TNS filter flag, order, and coefficient resolution (in bits per coeff) */
   tC->tnsActive      = (active) ? TRUE : FALSE;
   tC->maxOrder       = (blockType == SHORT_WINDOW) ? 5 : 12;  /* maximum: 7, 20 */
@@ -450,27 +433,14 @@
         const TNS_PARAMETER_TABULATED* pCfg = FDKaacEnc_GetTnsParam(bitRate, channels, ldSbrPresent);
 
         if ( pCfg != NULL ) {
+
+          FDKmemcpy(&(tC->confTab), pCfg, sizeof(tC->confTab));
+
           tC->lpcStartBand[HIFILT]         = FDKaacEnc_FreqToBandWithRounding(pCfg->filterStartFreq[HIFILT], sampleRate, pC->sfbCnt, pC->sfbOffset);
           tC->lpcStartLine[HIFILT]         = pC->sfbOffset[tC->lpcStartBand[HIFILT]];
           tC->lpcStartBand[LOFILT]         = FDKaacEnc_FreqToBandWithRounding(pCfg->filterStartFreq[LOFILT], sampleRate, pC->sfbCnt, pC->sfbOffset);
           tC->lpcStartLine[LOFILT]         = pC->sfbOffset[tC->lpcStartBand[LOFILT]];
 
-          tC->confTab.threshOn[HIFILT] = pCfg->threshOn[HIFILT];
-          tC->confTab.threshOn[LOFILT] = pCfg->threshOn[LOFILT];
-
-          tC->confTab.tnsLimitOrder[HIFILT] = pCfg->tnsLimitOrder[HIFILT];
-          tC->confTab.tnsLimitOrder[LOFILT] = pCfg->tnsLimitOrder[LOFILT];
-
-          tC->confTab.tnsFilterDirection[HIFILT] = pCfg->tnsFilterDirection[HIFILT];
-          tC->confTab.tnsFilterDirection[LOFILT] = pCfg->tnsFilterDirection[LOFILT];
-
-          tC->confTab.acfSplit[HIFILT] = pCfg->acfSplit[HIFILT];
-          tC->confTab.acfSplit[LOFILT] = pCfg->acfSplit[LOFILT];
-
-          tC->confTab.filterEnabled[HIFILT] = pCfg->filterEnabled[HIFILT];
-          tC->confTab.filterEnabled[LOFILT] = pCfg->filterEnabled[LOFILT];
-          tC->confTab.seperateFiltersAllowed = pCfg->seperateFiltersAllowed;
-
           FDKaacEnc_CalcGaussWindow(tC->acfWindow[HIFILT], tC->maxOrder+1, sampleRate, granuleLength, pCfg->tnsTimeResolution[HIFILT], TNS_TIMERES_SCALE);
           FDKaacEnc_CalcGaussWindow(tC->acfWindow[LOFILT], tC->maxOrder+1, sampleRate, granuleLength, pCfg->tnsTimeResolution[LOFILT], TNS_TIMERES_SCALE);
         }
@@ -614,6 +584,7 @@
 
 static void FDKaacEnc_MergedAutoCorrelation(
         const FIXP_DBL           *spectrum,
+        const INT                 isLowDelay,
         const FIXP_DBL            acfWindow[MAX_NUM_OF_FILTERS][TNS_MAX_ORDER+3+1],
         const INT                 lpcStartLine[MAX_NUM_OF_FILTERS],
         const INT                 lpcStopLine,
@@ -633,6 +604,8 @@
     FDKmemclear(&_rxx1[0], sizeof(FIXP_DBL)*(maxOrder+1));
     FDKmemclear(&_rxx2[0], sizeof(FIXP_DBL)*(maxOrder+1));
 
+    idx0 = idx1 = idx2 = idx3 = idx4 = 0;
+
     /* MDCT line indices separating the 1st, 2nd, 3rd, and 4th analysis quarters */
     if ( (acfSplit[LOFILT]==-1) || (acfSplit[HIFILT]==-1) ) {
       /* autocorrelation function for 1st, 2nd, 3rd, and 4th quarter of the spectrum */
@@ -676,17 +649,27 @@
     /* compute energy normalization factors, i. e. 1/energy (saves some divisions) */
     if (rxx1_0 != FL2FXCONST_DBL(0.f))
     {
-        INT sc_fac1 = -1;
-        FIXP_DBL fac1 = FDKaacEnc_AutoCorrNormFac(rxx1_0, ((-2*sc1)+nsc1), &sc_fac1);
-        _rxx1[0] = scaleValue(fMult(rxx1_0,fac1),sc_fac1);
+      INT sc_fac1 = -1;
+      FIXP_DBL fac1 = FDKaacEnc_AutoCorrNormFac(rxx1_0, ((-2*sc1)+nsc1), &sc_fac1);
+      _rxx1[0] = scaleValue(fMult(rxx1_0,fac1),sc_fac1);
 
+      if (isLowDelay)
+      {
         for (lag = 1; lag <= maxOrder; lag++) {
           /* compute energy-normalized and windowed autocorrelation values at this lag */
+          FIXP_DBL x1 = FDKaacEnc_CalcAutoCorrValue(pSpectrum, idx0, idx1, lag, nsc1);
+          _rxx1[lag] = fMult(scaleValue(fMult(x1,fac1),sc_fac1), acfWindow[LOFILT][lag]);
+        }
+      }
+      else
+      {
+        for (lag = 1; lag <= maxOrder; lag++) {
           if ((3 * lag) <= maxOrder + 3) {
               FIXP_DBL x1 = FDKaacEnc_CalcAutoCorrValue(pSpectrum, idx0, idx1, lag, nsc1);
               _rxx1[lag] = fMult(scaleValue(fMult(x1,fac1),sc_fac1), acfWindow[LOFILT][3*lag]);
           }
         }
+      }
     }
 
     /* auto corr over upper 3/4 of spectrum */
@@ -762,8 +745,12 @@
     : &tnsData->dataRaw.Long.subBlockInfo;
 
   tnsData->filtersMerged  = FALSE;
-  tsbi->tnsActive         = FALSE;
-  tsbi->predictionGain    = 1000;
+
+  tsbi->tnsActive[HIFILT]         = FALSE;
+  tsbi->predictionGain[HIFILT]    = 1000;
+  tsbi->tnsActive[LOFILT]         = FALSE;
+  tsbi->predictionGain[LOFILT]    = 1000;
+
   tnsInfo->numOfFilters[subBlockNumber] = 0;
   tnsInfo->coefRes[subBlockNumber]      = tC->coefRes;
   for (i = 0; i < tC->maxOrder; i++) {
@@ -779,6 +766,7 @@
 
     FDKaacEnc_MergedAutoCorrelation(
           spectrum,
+          tC->isLowDelay,
           tC->acfWindow,
           tC->lpcStartLine,
           tC->lpcStopLine,
@@ -788,7 +776,7 @@
           rxx2);
 
     /* compute higher TNS filter in lattice (ParCor) form with LeRoux-Gueguen algorithm */
-    tsbi->predictionGain = FDKaacEnc_AutoToParcor(rxx2, parcor_tmp, tC->confTab.tnsLimitOrder[HIFILT]);
+    tsbi->predictionGain[HIFILT] = FDKaacEnc_AutoToParcor(rxx2, parcor_tmp, tC->confTab.tnsLimitOrder[HIFILT]);
 
     /* non-linear quantization of TNS lattice coefficients with given resolution */
     FDKaacEnc_Parcor2Index(
@@ -815,9 +803,9 @@
     tnsInfo->length[subBlockNumber][HIFILT] = sfbCnt - tC->lpcStartBand[HIFILT];
 
     /* disable TNS if predictionGain is less than 3dB or sumSqrCoef is too small */
-    if ((tsbi->predictionGain > tC->confTab.threshOn[HIFILT]) || (sumSqrCoef > (tC->confTab.tnsLimitOrder[HIFILT]/2 + 2)))
+    if ((tsbi->predictionGain[HIFILT] > tC->confTab.threshOn[HIFILT]) || (sumSqrCoef > (tC->confTab.tnsLimitOrder[HIFILT]/2 + 2)))
     {
-      tsbi->tnsActive = TRUE;
+      tsbi->tnsActive[HIFILT] = TRUE;
       tnsInfo->numOfFilters[subBlockNumber]++;
 
       /* compute second filter for lower quarter; only allowed for long windows! */
@@ -857,6 +845,7 @@
           || ( (sumSqrCoef > 9)  && (sumSqrCoef < 22 * tC->confTab.tnsLimitOrder[LOFILT]) ) )
         {
           /* compare lower to upper filter; if they are very similar, merge them */
+          tsbi->tnsActive[LOFILT] = TRUE;
           sumSqrCoef = 0;
           for (i = 0; i < tC->confTab.tnsLimitOrder[LOFILT]; i++) {
             sumSqrCoef += FDKabs(tnsInfo->coef[subBlockNumber][HIFILT][i] - tnsInfo->coef[subBlockNumber][LOFILT][i]);
@@ -884,6 +873,8 @@
             tnsInfo->numOfFilters[subBlockNumber]++;
           }
         } /* filter lower part */
+        tsbi->predictionGain[LOFILT]=predGain;
+
       } /* second filter allowed  */
     } /* if predictionGain > 1437 ... */
   } /* maxOrder > 0 && tnsActive */
@@ -944,7 +935,7 @@
       INT doSync = 1, absDiffSum = 0;
 
       /* if TNS is active in at least one channel, check if ParCor coefficients of higher filter are similar */
-      if (pSbInfoDestW->tnsActive || pSbInfoSrcW->tnsActive) {
+      if (pSbInfoDestW->tnsActive[HIFILT] || pSbInfoSrcW->tnsActive[HIFILT]) {
         for (i = 0; i < tC->maxOrder; i++) {
           absDiff = FDKabs(tnsInfoDest->coef[w][HIFILT][i] - tnsInfoSrc->coef[w][HIFILT][i]);
           absDiffSum += absDiff;
@@ -957,12 +948,12 @@
 
         if (doSync) {
             /* if no significant difference was detected, synchronize coefficient sets */
-            if (pSbInfoSrcW->tnsActive) {
+            if (pSbInfoSrcW->tnsActive[HIFILT]) {
               /* no dest filter, or more dest than source filters: use one dest filter */
-              if ((!pSbInfoDestW->tnsActive) ||
-                  ((pSbInfoDestW->tnsActive) && (tnsInfoDest->numOfFilters[w] > tnsInfoSrc->numOfFilters[w])))
+              if ((!pSbInfoDestW->tnsActive[HIFILT]) ||
+                  ((pSbInfoDestW->tnsActive[HIFILT]) && (tnsInfoDest->numOfFilters[w] > tnsInfoSrc->numOfFilters[w])))
               {
-                pSbInfoDestW->tnsActive = tnsInfoDest->numOfFilters[w] = 1;
+                pSbInfoDestW->tnsActive[HIFILT] = tnsInfoDest->numOfFilters[w] = 1;
               }
               tnsDataDest->filtersMerged = tnsDataSrc->filtersMerged;
               tnsInfoDest->order       [w][HIFILT] = tnsInfoSrc->order       [w][HIFILT];
@@ -975,7 +966,7 @@
               }
             }
             else
-              pSbInfoDestW->tnsActive = tnsInfoDest->numOfFilters[w] = 0;
+              pSbInfoDestW->tnsActive[HIFILT] = tnsInfoDest->numOfFilters[w] = 0;
             }
         }
 
@@ -1012,8 +1003,8 @@
 {
     INT i, startLine, stopLine;
 
-    if ( ( (blockType == SHORT_WINDOW) && (!tnsData->dataRaw.Short.subBlockInfo[subBlockNumber].tnsActive) )
-      || ( (blockType != SHORT_WINDOW) && (!tnsData->dataRaw.Long.subBlockInfo.tnsActive) ) )
+    if ( ( (blockType == SHORT_WINDOW) && (!tnsData->dataRaw.Short.subBlockInfo[subBlockNumber].tnsActive[HIFILT]) )
+      || ( (blockType != SHORT_WINDOW) && (!tnsData->dataRaw.Long.subBlockInfo.tnsActive[HIFILT]) ) )
     {
       return 1;
     }
@@ -1129,8 +1120,9 @@
   FIXP_DBL *RESTRICT workBuffer = parcorWorkBuffer;
   const FIXP_DBL  autoCorr_0 = input[0];
 
+  FDKmemclear(reflCoeff,numOfCoeff*sizeof(FIXP_DBL));
+
   if((FIXP_DBL)input[0] == FL2FXCONST_DBL(0.0)) {
-    FDKmemclear(reflCoeff,numOfCoeff*sizeof(FIXP_DBL));
     return(predictionGain);
   }
 
diff --git a/libAACenc/src/aacenc_tns.h b/libAACenc/src/aacenc_tns.h
index f2b731f..2824cbc 100644
--- a/libAACenc/src/aacenc_tns.h
+++ b/libAACenc/src/aacenc_tns.h
@@ -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
@@ -117,21 +117,25 @@
 
 #define MAX_NUM_OF_FILTERS 2
 
+#define HIFILT 0           /* index of higher filter   */
+#define LOFILT 1           /* index of lower filter    */
 
-typedef struct{ /*stuff that is tabulated dependent on bitrate etc. */
-  INT     filterEnabled[MAX_NUM_OF_FILTERS];
-  INT     threshOn[MAX_NUM_OF_FILTERS];                /* min. prediction gain for using tns TABUL*/
-  INT     tnsLimitOrder[MAX_NUM_OF_FILTERS];           /* Limit for TNS order TABUL*/
-  INT     tnsFilterDirection[MAX_NUM_OF_FILTERS];      /* Filtering direction, 0=up, 1=down TABUL */
-  INT     acfSplit[MAX_NUM_OF_FILTERS];
-  INT     seperateFiltersAllowed;
 
-}TNS_CONFIG_TABULATED;
-
+typedef struct{ /* stuff that is tabulated dependent on bitrate etc. */
+  INT      filterEnabled[MAX_NUM_OF_FILTERS];
+  INT      threshOn[MAX_NUM_OF_FILTERS];                /* min. prediction gain for using tns TABUL*/
+  INT      filterStartFreq[MAX_NUM_OF_FILTERS];         /* lowest freq for lpc TABUL*/
+  INT      tnsLimitOrder[MAX_NUM_OF_FILTERS];           /* Limit for TNS order TABUL*/
+  INT      tnsFilterDirection[MAX_NUM_OF_FILTERS];      /* Filtering direction, 0=up, 1=down TABUL */
+  INT      acfSplit[MAX_NUM_OF_FILTERS];
+  FIXP_DBL tnsTimeResolution[MAX_NUM_OF_FILTERS];       /* TNS max. time resolution TABUL. Should be fract but MSVC won't compile then */
+  INT      seperateFiltersAllowed;
+} TNS_PARAMETER_TABULATED;
 
 
 typedef struct {   /*assigned at InitTime*/
-  TNS_CONFIG_TABULATED confTab;
+  TNS_PARAMETER_TABULATED confTab;
+  INT isLowDelay;
   INT tnsActive;
   INT maxOrder;                /* max. order of tns filter */
   INT coefRes;
@@ -148,8 +152,8 @@
 
 
 typedef struct {
-  INT   tnsActive;
-  INT   predictionGain;
+  INT   tnsActive[MAX_NUM_OF_FILTERS];
+  INT   predictionGain[MAX_NUM_OF_FILTERS];
 } TNS_SUBBLOCK_INFO;
 
 typedef struct{   /*changed at runTime*/
diff --git a/libAACenc/src/adj_thr.cpp b/libAACenc/src/adj_thr.cpp
index c318843..a79a9ae 100644
--- a/libAACenc/src/adj_thr.cpp
+++ b/libAACenc/src/adj_thr.cpp
@@ -153,10 +153,10 @@
   { 24000, 0x23D70A3D, 0x029F16B1, 0x2199999A, 0x07DD4413, 0x23D70A3D, 0x029F16B1, 0x2199999A, 0x07DD4413},
   { 32000, 0x247AE148, 0x11B1D92B, 0x23851EB8, 0x01F75105, 0x247AE148, 0x110A137F, 0x23851EB8, 0x01F75105},
   { 48000, 0x2D1EB852, 0x6833C600, 0x247AE148, 0x014F8B59, 0x2CCCCCCD, 0x68DB8BAC, 0x247AE148, 0x01F75105},
-  { 64000, 0x60000000, 0x00000000, 0x251EB852, 0x154C985F, 0x60000000, 0x00000000, 0x2570A3D7, 0x154C985F},
-  { 96000, 0x60000000, 0x00000000, 0x39EB851F, 0x088509C0, 0x60000000, 0x00000000, 0x3A3D70A4, 0x088509C0},
-  {128000, 0x60000000, 0x00000000, 0x423D70A4, 0x18A43BB4, 0x60000000, 0x00000000, 0x428F5C29, 0x181E03F7},
-  {148000, 0x60000000, 0x00000000, 0x5147AE14, 0x00000000, 0x60000000, 0x00000000, 0x5147AE14, 0x00000000}
+  { 64000, 0x25c28f40, 0x00000000, 0x251EB852, 0x01480000, 0x25c28f40, 0x00000000, 0x2570A3D7, 0x01480000},
+  { 96000, 0x25c28f40, 0x00000000, 0x26000000, 0x01000000, 0x25c28f40, 0x00000000, 0x26000000, 0x01000000},
+  {128000, 0x25c28f40, 0x00000000, 0x270a3d80, 0x01000000, 0x25c28f40, 0x00000000, 0x270a3d80, 0x01000000},
+  {148000, 0x25c28f40, 0x00000000, 0x28000000, 0x00000000, 0x25c28f40, 0x00000000, 0x28000000, 0x00000000}
 };
 
 static const BIT_PE_SFAC S_Bits2PeTab22050[] = {
@@ -166,8 +166,8 @@
   { 48000, 0x23d70a3d, 0x014f8b59, 0x2199999a, 0x03eea20a, 0x23d70a3d, 0x14f8b59,  0x2199999a, 0x03eea20a},
   { 64000, 0x247ae148, 0x08d8ec96, 0x23851eb8, 0x00fba882, 0x247ae148, 0x88509c0,  0x23851eb8, 0x00fba882},
   { 96000, 0x2d1eb852, 0x3419e300, 0x247ae148, 0x00a7c5ac, 0x2ccccccd, 0x346dc5d6, 0x247ae148, 0x00fba882},
-  {128000, 0x60000000, 0x00000000, 0x251eb852, 0x029f16b1, 0x60000000, 0x00000000, 0x2570a3d7, 0x009f16b1},
-  {148000, 0x60000000, 0x00000000, 0x26b851ec, 0x00000000, 0x60000000, 0x00000000, 0x270a3d71, 0x00000000}
+  {128000, 0x25c28f40, 0x00000000, 0x251eb852, 0x029f16b1, 0x60000000, 0x25c28f40, 0x2570a3d7, 0x009f16b1},
+  {148000, 0x25c28f40, 0x00000000, 0x26b851ec, 0x00000000, 0x60000000, 0x25c28f40, 0x270a3d71, 0x00000000}
 };
 
 static const BIT_PE_SFAC S_Bits2PeTab24000[] = {
@@ -178,21 +178,21 @@
   { 64000, 0x24cccccd, 0x05e5f30e, 0x22e147ae, 0x01a36e2f, 0x24cccccd, 0x05e5f30e, 0x23333333, 0x014f8b59},
   { 96000, 0x2a8f5c29, 0x24b33db0, 0x247ae148, 0x00fba882, 0x2a8f5c29, 0x26fe718b, 0x247ae148, 0x00fba882},
   {128000, 0x4e666666, 0x1cd5f99c, 0x2570a3d7, 0x010c6f7a, 0x50a3d70a, 0x192a7371, 0x2570a3d7, 0x010c6f7a},
-  {148000, 0x60000000, 0x00000000, 0x26147ae1, 0x00000000, 0x60000000, 0x00000000, 0x26147ae1, 0x00000000}
+  {148000, 0x25c28f40, 0x00000000, 0x26147ae1, 0x00000000, 0x25c28f40, 0x00000000, 0x26147ae1, 0x00000000}
 };
 
 static const BIT_PE_SFAC S_Bits2PeTab32000[] = {
-  { 16000, 0x1199999a, 0x20c49ba6, 0x00000000, 0x4577d955, 0x00000000, 0x60fe4799, 0x00000000, 0x00000000},
-  { 24000, 0x1999999a, 0x0fba8827, 0x10f5c28f, 0x1b866e44, 0x17ae147b, 0x0fba8827, 0x00000000, 0x4d551d69},
+  { 16000, 0x247ae140, 0xFFFFAC1E, 0x270a3d80, 0xFFFE9B7C, 0x14ccccc0, 0x000110A1, 0x15c28f60, 0xFFFEEF5F},
+  { 24000, 0x23333340, 0x0fba8827, 0x21999980, 0x1b866e44, 0x18f5c280, 0x0fba8827, 0x119999a0, 0x4d551d69},
   { 32000, 0x1d70a3d7, 0x07357e67, 0x17ae147b, 0x09d49518, 0x1b851eb8, 0x0a7c5ac4, 0x12e147ae, 0x110a137f},
   { 48000, 0x20f5c28f, 0x049667b6, 0x1c7ae148, 0x053e2d62, 0x20a3d70a, 0x053e2d62, 0x1b333333, 0x05e5f30e},
   { 64000, 0x23333333, 0x029f16b1, 0x1f0a3d71, 0x02f2f987, 0x23333333, 0x029f16b1, 0x1e147ae1, 0x03eea20a},
   { 96000, 0x25c28f5c, 0x2c3c9eed, 0x21eb851f, 0x01f75105, 0x25c28f5c, 0x0a7c5ac4, 0x21eb851f, 0x01a36e2f},
   {128000, 0x50f5c28f, 0x18a43bb4, 0x23d70a3d, 0x010c6f7a, 0x30000000, 0x168b5cc0, 0x23851eb8, 0x0192a737},
-  {148000, 0x60000000, 0x00000000, 0x247ae148, 0x00dfb23b, 0x3dc28f5c, 0x300f4aaf, 0x247ae148, 0x01bf6476},
-  {160000, 0x60000000, 0xb15b5740, 0x24cccccd, 0x053e2d62, 0x4f5c28f6, 0xbefd0072, 0x251eb852, 0x04fb1184},
-  {200000, 0x00000000, 0x00000000, 0x2b333333, 0x0836be91, 0x00000000, 0x00000000, 0x2b333333, 0x0890390f},
-  {320000, 0x00000000, 0x00000000, 0x4947ae14, 0x00000000, 0x00000000, 0x00000000, 0x4a8f5c29, 0x00000000}
+  {148000, 0x25c28f40, 0x00000000, 0x247ae148, 0x00dfb23b, 0x3dc28f5c, 0x300f4aaf, 0x247ae148, 0x01bf6476},
+  {160000, 0x25c28f40, 0xb15b5740, 0x24cccccd, 0x053e2d62, 0x4f5c28f6, 0xbefd0072, 0x251eb852, 0x04fb1184},
+  {200000, 0x25c28f40, 0x00000000, 0x2b333333, 0x0836be91, 0x25c28f40, 0x00000000, 0x2b333333, 0x0890390f},
+  {320000, 0x25c28f40, 0x00000000, 0x4947ae14, 0x00000000, 0x25c28f40, 0x00000000, 0x4a8f5c29, 0x00000000}
 };
 
 static const BIT_PE_SFAC S_Bits2PeTab44100[] = {
@@ -205,8 +205,8 @@
   {128000, 0x2ae147ae, 0x1b435265, 0x223d70a4, 0x0192a737, 0x2a3d70a4, 0x1040bfe4, 0x21eb851f, 0x0192a737},
   {148000, 0x3b851eb8, 0x2832069c, 0x23333333, 0x00dfb23b, 0x3428f5c3, 0x2054c288, 0x22e147ae, 0x00dfb23b},
   {160000, 0x4a3d70a4, 0xc32ebe5a, 0x23851eb8, 0x01d5c316, 0x40000000, 0xcb923a2b, 0x23333333, 0x01d5c316},
-  {200000, 0x00000000, 0x00000000, 0x25c28f5c, 0x0713f078, 0x00000000, 0x00000000, 0x2570a3d7, 0x072a4f17},
-  {320000, 0x00000000, 0x00000000, 0x3fae147b, 0x00000000, 0x00000000, 0x00000000, 0x3fae147b, 0x00000000}
+  {200000, 0x25c28f40, 0x00000000, 0x25c28f5c, 0x0713f078, 0x25c28f40, 0x00000000, 0x2570a3d7, 0x072a4f17},
+  {320000, 0x25c28f40, 0x00000000, 0x3fae147b, 0x00000000, 0x25c28f40, 0x00000000, 0x3fae147b, 0x00000000}
 };
 
 static const BIT_PE_SFAC S_Bits2PeTab48000[] = {
@@ -219,8 +219,8 @@
   {128000, 0x28f5c28f, 0x14727dcc, 0x2147ae14, 0x0218def4, 0x2851eb85, 0x0e27e0f0, 0x20f5c28f, 0x0218def4},
   {148000, 0x3570a3d7, 0x1cd5f99c, 0x228f5c29, 0x01bf6476, 0x30f5c28f, 0x18777e75, 0x223d70a4, 0x01bf6476},
   {160000, 0x40000000, 0xcb923a2b, 0x23333333, 0x0192a737, 0x39eb851f, 0xd08d4bae, 0x22e147ae, 0x0192a737},
-  {200000, 0x00000000, 0x00000000, 0x251eb852, 0x06775a1b, 0x00000000, 0x00000000, 0x24cccccd, 0x06a4175a},
-  {320000, 0x00000000, 0x00000000, 0x3ccccccd, 0x00000000, 0x00000000, 0x00000000, 0x3d1eb852, 0x00000000}
+  {200000, 0x25c28f40, 0x00000000, 0x251eb852, 0x06775a1b, 0x25c28f40, 0x00000000, 0x24cccccd, 0x06a4175a},
+  {320000, 0x25c28f40, 0x00000000, 0x3ccccccd, 0x00000000, 0x25c28f40, 0x00000000, 0x3d1eb852, 0x00000000}
 };
 
 static const BITS2PE_CFG_TAB bits2PeConfigTab[] = {
@@ -258,6 +258,7 @@
         const INT nChannels,
         const INT sampleRate,
         const INT advancedBitsToPe,
+        const INT dZoneQuantEnable,
         const INT invQuant
         )
 {
@@ -329,7 +330,32 @@
   } /* advancedBitsToPe */
 
 
-  /* return bits2pe factor */
+  if (dZoneQuantEnable)
+  {
+    if(bit2PE_m >= (FL2FXCONST_DBL(0.6f))>>bit2PE_e)
+    {
+      /* Additional headroom for addition */
+      bit2PE_m >>= 1;
+      bit2PE_e  += 1;
+    }
+
+    /* the quantTendencyCompensator compensates a lower bit consumption due to increasing the tendency to quantize low spectral values to the lower quantizer border for bitrates below a certain bitrate threshold --> see also function calcSfbDistLD in quantize.c */
+    if ((bitRate/nChannels > 32000) && (bitRate/nChannels <= 40000)) {
+      bit2PE_m += (FL2FXCONST_DBL(0.4f))>>bit2PE_e;
+    }
+    else if (bitRate/nChannels > 20000) {
+      bit2PE_m += (FL2FXCONST_DBL(0.3f))>>bit2PE_e;
+    }
+    else if (bitRate/nChannels >= 16000) {
+      bit2PE_m += (FL2FXCONST_DBL(0.3f))>>bit2PE_e;
+    }
+    else {
+      bit2PE_m += (FL2FXCONST_DBL(0.0f))>>bit2PE_e;
+    }
+  }
+
+
+  /***** 3.) Return bits2pe factor *****/
   *bits2PeFactor_m = bit2PE_m;
   *bits2PeFactor_e = bit2PE_e;
 }
@@ -1649,6 +1675,7 @@
                                 QC_OUT_ELEMENT*   qcElement[(8)],
                                 PSY_OUT_ELEMENT*  psyOutElement[(8)],
                                 const INT         desiredPe,
+                                const INT         maxIter2ndGuess,
                                 const INT         processElements,
                                 const INT         elementOffset)
 {
@@ -1733,7 +1760,7 @@
    /* Part III: Iterate until bit constraints are met */
    /* -------------------------------------------------- */
    iter = 0;
-   while ((fixp_abs(redPeGlobal - desiredPe) > fMultI(FL2FXCONST_DBL(0.05f),desiredPe)) && (iter < 1)) {
+   while ((fixp_abs(redPeGlobal - desiredPe) > fMultI(FL2FXCONST_DBL(0.05f),desiredPe)) && (iter < maxIter2ndGuess)) {
 
      INT desiredPeNoAHGlobal;
      INT redPeNoAHGlobal = 0;
@@ -2225,7 +2252,8 @@
         INT             nChannelsEff,
         INT             sampleRate,
         INT             advancedBitsToPe,
-        FIXP_DBL        vbrQualFactor
+        FIXP_DBL        vbrQualFactor,
+        const INT       dZoneQuantEnable
         )
 {
   INT i;
@@ -2233,6 +2261,10 @@
   FIXP_DBL POINT8 = FL2FXCONST_DBL(0.8f);
   FIXP_DBL POINT6 = FL2FXCONST_DBL(0.6f);
 
+  /* Max number of iterations in second guess is 3 for lowdelay aot and for configurations with
+     multiple audio elements in general, otherwise iteration value is always 1. */
+  hAdjThr->maxIter2ndGuess = (advancedBitsToPe!=0 || nElements>1) ? 3 : 1;
+
   /* common for all elements: */
   /* parameters for bitres control */
   hAdjThr->bresParamLong.clipSaveLow   = (FIXP_DBL)0x1999999a; /* FL2FXCONST_DBL(0.2f); */
@@ -2313,10 +2345,11 @@
     FDKaacEnc_InitBits2PeFactor(
               &atsElem->bits2PeFactor_m,
               &atsElem->bits2PeFactor_e,
-              chBitrate,       /* bitrate/channel*/
+              chBitrate*nChannelsEff, /* overall bitrate */
               nChannelsEff,    /* number of channels */
               sampleRate,
               advancedBitsToPe,
+              dZoneQuantEnable,
               invQuant
               );
 
@@ -2545,6 +2578,7 @@
                                 QC_OUT*             qcOut,
                                 PSY_OUT_ELEMENT*    psyOutElement[(8)],
                                 INT                 CBRbitrateMode,
+                                INT                 maxIter2ndGuess,
                                 CHANNEL_MAPPING*    cm)
 {
     int i;
@@ -2570,6 +2604,7 @@
                                             qcElement,
                                             psyOutElement,
                                             qcElement[i]->grantedPeCorr,
+                                            maxIter2ndGuess,
                                             1,         /* Process only 1 element */
                                             i);        /* Process exactly THIS element */
 
diff --git a/libAACenc/src/adj_thr.h b/libAACenc/src/adj_thr.h
index 69b1dcc..be68c6e 100644
--- a/libAACenc/src/adj_thr.h
+++ b/libAACenc/src/adj_thr.h
@@ -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
@@ -118,7 +118,8 @@
                 INT nChannelsEff,
                 INT sampleRate,
                 INT advancedBitsToPe,
-                FIXP_DBL vbrQualFactor);
+                FIXP_DBL vbrQualFactor,
+                const INT dZoneQuantEnable);
  
 
 void FDKaacEnc_DistributeBits(ADJ_THR_STATE *adjThrState,
@@ -140,6 +141,7 @@
     QC_OUT*           qcOut,
     PSY_OUT_ELEMENT*  psyOutElement[(8)],
     INT               CBRbitrateMode,
+    INT               maxIter2ndGuess,
     CHANNEL_MAPPING*  cm);
 
 void FDKaacEnc_AdjThrClose(ADJ_THR_STATE** hAdjThr);
diff --git a/libAACenc/src/adj_thr_data.h b/libAACenc/src/adj_thr_data.h
index 3eb7678..7c3a191 100644
--- a/libAACenc/src/adj_thr_data.h
+++ b/libAACenc/src/adj_thr_data.h
@@ -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
@@ -145,6 +145,7 @@
 typedef struct {
   BRES_PARAM bresParamLong, bresParamShort;
   ATS_ELEMENT* adjThrStateElem[(8)];
+  INT maxIter2ndGuess;
 } ADJ_THR_STATE;
 
 #endif
diff --git a/libAACenc/src/bandwidth.cpp b/libAACenc/src/bandwidth.cpp
index 6fc7d87..6937362 100644
--- a/libAACenc/src/bandwidth.cpp
+++ b/libAACenc/src/bandwidth.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
@@ -127,7 +127,7 @@
   { 8000,  2000,  2000},
   {12000,  2000,  2300},
   {16000,  2200,  2500},
-  {24000,  5650,  6400},
+  {24000,  5650,  7200},
   {32000,  11600, 12000},
   {40000,  12000, 16000},
   {48000,  16000, 16000},
@@ -138,10 +138,10 @@
 static const BANDWIDTH_TAB bandWidthTable_LD_32000[] = {
   { 8000,  2000,  2000},
   {12000,  2000,  2000},
-  {24000,  4250,  5200},
+  {24000,  4250,  7200},
   {32000,  8400,  9000},
   {40000,  9400,  11300},
-  {48000,  11900, 13700},
+  {48000,  11900, 14700},
   {64000,  14800, 16000},
   {76000,  16000, 16000},
   {360001, 16000, 16000}
diff --git a/libAACenc/src/pnsparam.cpp b/libAACenc/src/pnsparam.cpp
index afc5bdd..9d59ddc 100644
--- a/libAACenc/src/pnsparam.cpp
+++ b/libAACenc/src/pnsparam.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
@@ -107,6 +107,7 @@
 typedef struct {
   ULONG brFrom;
   ULONG brTo;
+  UCHAR S16000;
   UCHAR S22050;
   UCHAR S24000;
   UCHAR S32000;
@@ -115,25 +116,26 @@
 } AUTO_PNS_TAB;
 
 static const AUTO_PNS_TAB levelTable_mono[]= {
-  {0,      11999, 1, 1, 1, 1, 1,},
-  {12000,  19999, 1, 1, 1, 1, 1,},
-  {20000,  28999, 2, 1, 1, 1, 1,},
-  {29000,  40999, 4, 4, 4, 2, 2,},
-  {41000,  55999, 9, 9, 7, 7, 7,},
-  {56000,  79999, 0, 0, 0, 9, 9,},
-  {80000,  99999, 0, 0, 0, 0, 0,},
-  {100000,999999, 0, 0, 0, 0, 0,},
+  {0,      11999, 0, 1, 1, 1, 1, 1,},
+  {12000,  19999, 0, 1, 1, 1, 1, 1,},
+  {20000,  28999, 0, 2, 1, 1, 1, 1,},
+  {29000,  40999, 0, 4, 4, 4, 2, 2,},
+  {41000,  55999, 0, 9, 9, 7, 7, 7,},
+  {56000,  61999, 0, 0, 0, 0, 9, 9,},
+  {62000,  75999, 0, 0, 0, 0, 0, 0,},
+  {76000,  92999, 0, 0, 0, 0, 0, 0,},
+  {93000, 999999, 0, 0, 0, 0, 0, 0,},
 };
 
 static const AUTO_PNS_TAB levelTable_stereo[]= {
-  {0,      11999, 1, 1, 1, 1, 1,},
-  {12000,  19999, 3, 1, 1, 1, 1,},
-  {20000,  28999, 3, 3, 3, 2, 2,},
-  {29000,  40999, 7, 6, 6, 5, 5,},
-  {41000,  55999, 9, 9, 7, 7, 7,},
-  {56000,  79999, 0, 0, 0, 0, 0,},
-  {80000,  99999, 0, 0, 0, 0, 0,},
-  {100000,999999, 0, 0, 0, 0, 0,},
+  {0,      11999, 0, 1, 1, 1, 1, 1,},
+  {12000,  19999, 0, 3, 1, 1, 1, 1,},
+  {20000,  28999, 0, 3, 3, 3, 2, 2,},
+  {29000,  40999, 0, 7, 6, 6, 5, 5,},
+  {41000,  55999, 0, 9, 9, 7, 7, 7,},
+  {56000,  79999, 0, 0, 0, 0, 0, 0,},
+  {80000,  99999, 0, 0, 0, 0, 0, 0,},
+  {100000,999999, 0, 0, 0, 0, 0, 0,},
 };
 
 
@@ -160,11 +162,11 @@
 };
 
 static const AUTO_PNS_TAB levelTable_lowComplexity[]= {
-  {0,      27999, 0, 0, 0, 0, 0,},
-  {28000,  31999, 2, 2, 2, 2, 2,},
-  {32000,  47999, 3, 3, 3, 3, 3,},
-  {48000,  48000, 4, 4, 4, 4, 4,},
-  {48001, 999999, 0, 0, 0, 0, 0,},
+  {0,      27999, 0, 0, 0, 0, 0, 0,},
+  {28000,  31999, 0, 2, 2, 2, 2, 2,},
+  {32000,  47999, 0, 3, 3, 3, 3, 3,},
+  {48000,  48000, 0, 4, 4, 4, 4, 4,},
+  {48001, 999999, 0, 0, 0, 0, 0, 0,},
 };
 
 /* conversion of old LC tuning tables to new (LD enc) structure (only entries which are actually used were converted) */
@@ -211,6 +213,7 @@
   }
 
   switch (sampleRate) {
+  case 16000: hUsePns = levelTable[i].S16000; break;
   case 22050: hUsePns = levelTable[i].S22050; break;
   case 24000: hUsePns = levelTable[i].S24000; break;
   case 32000: hUsePns = levelTable[i].S32000; break;
diff --git a/libAACenc/src/psy_main.cpp b/libAACenc/src/psy_main.cpp
index 3cc9438..446c894 100644
--- a/libAACenc/src/psy_main.cpp
+++ b/libAACenc/src/psy_main.cpp
@@ -342,6 +342,7 @@
         tnsChannels,
         LONG_WINDOW,
         hPsy->granuleLength,
+        isLowDelay(audioObjectType),
         (syntaxFlags&AC_SBR_PRESENT)?1:0,
        &(hPsy->psyConf[0].tnsConf),
        &hPsy->psyConf[0],
@@ -362,6 +363,7 @@
             tnsChannels,
             SHORT_WINDOW,
             hPsy->granuleLength,
+            isLowDelay(audioObjectType),
             (syntaxFlags&AC_SBR_PRESENT)?1:0,
            &hPsy->psyConf[1].tnsConf,
            &hPsy->psyConf[1],
@@ -763,7 +765,8 @@
 
     /* Advance psychoacoustics: Tonality and TNS */
     if (psyStatic[0]->isLFE) {
-        tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive = 0;
+        tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT] = 0;
+        tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[LOFILT] = 0;
     }
     else
     {
@@ -819,11 +822,15 @@
             for(w = 0; w < nWindows[0]; w++)
             {
                 if (isShortWindow[0])
-                    tnsActive[w] = tnsData[0]->dataRaw.Short.subBlockInfo[w].tnsActive ||
-                    ((channels == 2) ? tnsData[1]->dataRaw.Short.subBlockInfo[w].tnsActive : 0);
+                    tnsActive[w] = tnsData[0]->dataRaw.Short.subBlockInfo[w].tnsActive[HIFILT] ||
+                    tnsData[0]->dataRaw.Short.subBlockInfo[w].tnsActive[LOFILT] ||
+                    tnsData[channels-1]->dataRaw.Short.subBlockInfo[w].tnsActive[HIFILT] ||
+                    tnsData[channels-1]->dataRaw.Short.subBlockInfo[w].tnsActive[LOFILT];
                 else
-                    tnsActive[w] = tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive ||
-                    ((channels == 2) ? tnsData[1]->dataRaw.Long.subBlockInfo.tnsActive : 0);
+                    tnsActive[w] = tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT] ||
+                    tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[LOFILT] ||
+                    tnsData[channels-1]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT] ||
+                    tnsData[channels-1]->dataRaw.Long.subBlockInfo.tnsActive[LOFILT];
             }
 
             for(ch = 0; ch < channels; ch++) {
@@ -1150,8 +1157,8 @@
                        psyData[ch]->sfbMaxScaleSpec.Long,
                        sfbTonality[ch],
                        psyOutChannel[ch]->tnsInfo.order[0][0],
-                       tnsData[ch]->dataRaw.Long.subBlockInfo.predictionGain,
-                       tnsData[ch]->dataRaw.Long.subBlockInfo.tnsActive,
+                       tnsData[ch]->dataRaw.Long.subBlockInfo.predictionGain[HIFILT],
+                       tnsData[ch]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT],
                        psyOutChannel[ch]->sfbEnergyLdData,
                        psyOutChannel[ch]->noiseNrg );
         } /* !isLFE */
diff --git a/libAACenc/src/qc_data.h b/libAACenc/src/qc_data.h
index a9309c8..00d6090 100644
--- a/libAACenc/src/qc_data.h
+++ b/libAACenc/src/qc_data.h
@@ -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
@@ -269,6 +269,8 @@
   BITCNTR_STATE *hBitCounter;
   ADJ_THR_STATE *hAdjThr;
 
+  INT dZoneQuantEnable;   /* enable dead zone quantizer */
+
 } QC_STATE;
 
 #endif /* _QC_DATA_H */
diff --git a/libAACenc/src/qc_main.cpp b/libAACenc/src/qc_main.cpp
index 7503309..9cd73f6 100644
--- a/libAACenc/src/qc_main.cpp
+++ b/libAACenc/src/qc_main.cpp
@@ -380,7 +380,7 @@
   if ( isConstantBitrateMode(hQC->bitrateMode) ) {
     INT bitresPerChannel = (hQC->bitResTotMax / init->channelMapping->nChannelsEff);
     /* 0: full bitreservoir, 1: reduced bitreservoir, 2: disabled bitreservoir */
-    hQC->bitDistributionMode = (bitresPerChannel>100) ? 0 : (bitresPerChannel>0) ? 1 : 2;
+    hQC->bitDistributionMode = (bitresPerChannel>BITRES_MIN_LD) ? 0 : (bitresPerChannel>0) ? 1 : 2;
   }
   else {
     hQC->bitDistributionMode = 0; /* full bitreservoir */
@@ -405,6 +405,16 @@
     }
   }
 
+  if (init->channelMapping->nChannelsEff == 1 &&
+     (init->bitrate / init->channelMapping->nChannelsEff) < 32000 &&
+     init->advancedBitsToPe != 0
+     )
+  {
+    hQC->dZoneQuantEnable = 1;
+  } else {
+    hQC->dZoneQuantEnable = 0;
+  }
+
   FDKaacEnc_AdjThrInit(
         hQC->hAdjThr,
         init->meanPe,
@@ -414,7 +424,8 @@
         init->channelMapping->nChannelsEff,
         init->sampleRate,                 /* output sample rate */
         init->advancedBitsToPe,           /* if set, calc bits2PE factor depending on samplerate */
-        hQC->vbrQualFactor
+        hQC->vbrQualFactor,
+        hQC->dZoneQuantEnable
         );
 
   return AAC_ENC_OK;
@@ -877,6 +888,7 @@
                                      qcOut[c],
                                      psyOut[c]->psyOutElement,
                                      isConstantBitrateMode(hQC->bitrateMode),
+                                     hQC->hAdjThr->maxIter2ndGuess,
                                      cm);
 
       } /* -end- sub frame counter */
@@ -904,6 +916,7 @@
                       FDKaacEnc_EstimateScaleFactors(psyOut[c]->psyOutElement[i]->psyOutChannel,
                                             qcElement[c][i]->qcOutChannel,
                                             hQC->invQuant,
+                                            hQC->dZoneQuantEnable,
                                             cm->elInfo[i].nChannelsInEl);
 
 
@@ -998,7 +1011,8 @@
                                                              qcOutCh->mdctSpectrum,
                                                              qcOutCh->globalGain,
                                                              qcOutCh->scf,
-                                                             qcOutCh->quantSpec) ;
+                                                             qcOutCh->quantSpec,
+                                                             hQC->dZoneQuantEnable);
 
                                   /*-------------------------------------------- */
                                   if (FDKaacEnc_calcMaxValueInSfb(psyOutCh->sfbCnt,
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 @@
 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 @@
                       FIXP_DBL *mdctSpectrum,
                       INT globalGain,
                       INT *scalefactors,
-                      SHORT *quantizedSpectrum)
+                      SHORT *quantizedSpectrum,
+                      INT dZoneQuantEnable)
 {
   INT sfbOffs,sfb;
 
@@ -280,7 +287,8 @@
     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 @@
 FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum,
                      SHORT *quantSpectrum,
                      INT noOfLines,
-                     INT gain
+                     INT gain,
+                     INT dZoneQuantEnable
                      )
 {
   INT i,scale;
@@ -311,7 +320,8 @@
     FDKaacEnc_quantizeLines(gain,
                   1,
                  &mdctSpectrum[i],
-                 &quantSpectrum[i]);
+                 &quantSpectrum[i],
+                  dZoneQuantEnable);
 
     if (fAbs(quantSpectrum[i])>MAX_QUANT) {
       return FL2FXCONST_DBL(0.0f);
diff --git a/libAACenc/src/quantize.h b/libAACenc/src/quantize.h
index 975b98e..16d3d4e 100644
--- a/libAACenc/src/quantize.h
+++ b/libAACenc/src/quantize.h
@@ -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
@@ -102,12 +102,14 @@
                       INT sfbPerGroup,
                       INT *sfbOffset, FIXP_DBL *mdctSpectrum,
                       INT globalGain, INT *scalefactors,
-                      SHORT *quantizedSpectrum);
+                      SHORT *quantizedSpectrum,
+                      INT dZoneQuantEnable);
 
 FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum,
                      SHORT *quantSpectrum,
                      INT noOfLines,
-                     INT gain);
+                     INT gain,
+                     INT dZoneQuantEnable);
 
 void FDKaacEnc_calcSfbQuantEnergyAndDist(FIXP_DBL *mdctSpectrum,
                                SHORT   *quantSpectrum,
diff --git a/libAACenc/src/sf_estim.cpp b/libAACenc/src/sf_estim.cpp
index 72b75a6..1cb243b 100644
--- a/libAACenc/src/sf_estim.cpp
+++ b/libAACenc/src/sf_estim.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
@@ -363,7 +363,8 @@
                       INT scf,
                       INT minScf,
                       FIXP_DBL  *distLdData,
-                      INT *minScfCalculated
+                      INT *minScfCalculated,
+                      INT dZoneQuantEnable
                       )
 {
    FIXP_DBL sfbDistLdData;
@@ -375,7 +376,8 @@
    sfbDistLdData = FDKaacEnc_calcSfbDist(spec,
                                          quantSpec,
                                          sfbWidth,
-                                         scf);
+                                         scf,
+                                         dZoneQuantEnable);
    *minScfCalculated = scf;
    /* nmr > 1.25 -> try to improve nmr */
    if (sfbDistLdData > (threshLdData-distFactorLdData)) {
@@ -390,7 +392,8 @@
          sfbDistLdData = FDKaacEnc_calcSfbDist(spec,
                                                quantSpecTmp,
                                                sfbWidth,
-                                               scf);
+                                               scf,
+                                               dZoneQuantEnable);
 
          if (sfbDistLdData < sfbDistBestLdData) {
             scfBest = scf;
@@ -408,7 +411,8 @@
          sfbDistLdData = FDKaacEnc_calcSfbDist(spec,
                                                quantSpecTmp,
                                                sfbWidth,
-                                               scf);
+                                               scf,
+                                               dZoneQuantEnable);
 
          if (sfbDistLdData < sfbDistBestLdData) {
             scfBest = scf;
@@ -429,7 +433,8 @@
          sfbDistLdData = FDKaacEnc_calcSfbDist(spec,
                                                quantSpecTmp,
                                                sfbWidth,
-                                               scf);
+                                               scf,
+                                               dZoneQuantEnable);
 
          if (sfbDistLdData < sfbDistAllowedLdData) {
            *minScfCalculated = scfBest+1;
@@ -454,6 +459,7 @@
                                 QC_OUT_CHANNEL   *qcOutChannel,
                                 SHORT *quantSpec,
                                 SHORT *quantSpecTmp,
+                                INT dZoneQuantEnable,
                                 INT *scf,
                                 INT *minScf,
                                 FIXP_DBL *sfbDist,
@@ -570,7 +576,8 @@
             sfbDistNew = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs,
                                                quantSpecTmp+sfbOffs,
                                                sfbWidth,
-                                               scfAct);
+                                               scfAct,
+                                               dZoneQuantEnable);
 
             if (sfbDistNew < sfbDist[sfbAct]) {
               /* success, replace scf by new one */
@@ -629,6 +636,7 @@
                                   QC_OUT_CHANNEL  *qcOutChannel,
                                   SHORT *quantSpec,
                                   SHORT *quantSpecTmp,
+                                  INT dZoneQuantEnable,
                                   INT *scf,
                                   INT *minScf,
                                   FIXP_DBL *sfbDist,
@@ -724,7 +732,8 @@
                 sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs,
                                               quantSpecTmp+sfbOffs,
                                               sfbWidth,
-                                              scfAct);
+                                              scfAct,
+                                              dZoneQuantEnable);
 
                 if (sfbDistNew[sfb] >qcOutChannel->sfbThresholdLdData[sfb]) {
                   /* no improvement, skip further dist. calculations */
@@ -768,6 +777,7 @@
                                    QC_OUT_CHANNEL  *qcOutChannel,
                                    SHORT *quantSpec,
                                    SHORT *quantSpecTmp,
+                                   INT dZoneQuantEnable,
                                    INT *scf,
                                    INT *minScf,
                                    FIXP_DBL *sfbDist,
@@ -883,7 +893,8 @@
                 sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs[sfb],
                                               quantSpecTmp+sfbOffs[sfb],
                                               sfbOffs[sfb+1]-sfbOffs[sfb],
-                                              scfNew);
+                                              scfNew,
+                                              dZoneQuantEnable);
 
                 if (sfbDistNew[sfb] > sfbDistMax[sfb]) {
                   /* no improvement, skip further dist. calculations */
@@ -963,7 +974,8 @@
               sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs[sfb],
                                                       quantSpecTmp+sfbOffs[sfb],
                                                       sfbOffs[sfb+1]-sfbOffs[sfb],
-                                                      scfNew);
+                                                      scfNew,
+                                                      dZoneQuantEnable);
 
               if (sfbDistNew[sfb] > qcOutChannel->sfbThresholdLdData[sfb]) {
                 /* no improvement, skip further dist. calculations */
@@ -1058,7 +1070,8 @@
                             INT *RESTRICT globalGain,
                             FIXP_DBL *RESTRICT sfbFormFactorLdData
                             ,const INT invQuant,
-                            SHORT *RESTRICT quantSpec
+                            SHORT *RESTRICT quantSpec,
+                            const INT dZoneQuantEnable
                             )
 {
   INT i, j, sfb, sfbOffs;
@@ -1160,7 +1173,8 @@
                               quantSpecTmp+psyOutChannel->sfbOffsets[sfbOffs+sfb],
                               psyOutChannel->sfbOffsets[sfbOffs+sfb+1]-psyOutChannel->sfbOffsets[sfbOffs+sfb],
                               threshLdData, scfInt, minSfMaxQuant[sfbOffs+sfb],
-                              &sfbDistLdData[sfbOffs+sfb], &minScfCalculated[sfbOffs+sfb]
+                              &sfbDistLdData[sfbOffs+sfb], &minScfCalculated[sfbOffs+sfb],
+                              dZoneQuantEnable
                               );
         }
         scf[sfbOffs+sfb] = scfInt;
@@ -1187,20 +1201,32 @@
                           sfbNRelevantLines);
 
 
-    FDKaacEnc_assimilateSingleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, scf,
+    FDKaacEnc_assimilateSingleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp,
+                        dZoneQuantEnable,
+                        scf,
                         minSfMaxQuant, sfbDistLdData, sfbConstPePart,
                         sfbFormFactorLdData, sfbNRelevantLines, minScfCalculated, 1);
 
+    if(invQuant > 1) {
+      FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp,
+                        dZoneQuantEnable,
+                        scf,
+                        minSfMaxQuant, sfbDistLdData, sfbConstPePart,
+                        sfbFormFactorLdData, sfbNRelevantLines);
 
-    FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, scf,
-                          minSfMaxQuant, sfbDistLdData, sfbConstPePart,
-                          sfbFormFactorLdData, sfbNRelevantLines);
+      FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp,
+                        dZoneQuantEnable,
+                        scf,
+                        minSfMaxQuant, sfbDistLdData, sfbConstPePart,
+                        sfbFormFactorLdData, sfbNRelevantLines);
 
 
-    FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, scf,
-                           minSfMaxQuant, sfbDistLdData, sfbConstPePart,
-                           sfbFormFactorLdData, sfbNRelevantLines);
-
+      FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp,
+                        dZoneQuantEnable,
+                        scf,
+                        minSfMaxQuant, sfbDistLdData, sfbConstPePart,
+                        sfbFormFactorLdData, sfbNRelevantLines);
+    }
   }
 
 
@@ -1223,7 +1249,8 @@
                FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+psyOutChannel->sfbOffsets[sfbOffs+sfb],
                                      quantSpec+psyOutChannel->sfbOffsets[sfbOffs+sfb],
                                      psyOutChannel->sfbOffsets[sfbOffs+sfb+1]-psyOutChannel->sfbOffsets[sfbOffs+sfb],
-                                     scf[sfbOffs+sfb]
+                                     scf[sfbOffs+sfb],
+                                     dZoneQuantEnable
                                      );
         }
       }
@@ -1281,6 +1308,7 @@
 FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[],
                      QC_OUT_CHANNEL* qcOutChannel[],
                      const int invQuant,
+                     const INT dZoneQuantEnable,
                      const int nChannels)
 {
   int ch;
@@ -1293,7 +1321,8 @@
                                   &qcOutChannel[ch]->globalGain,
                                   qcOutChannel[ch]->sfbFormFactorLdData
                                   ,invQuant,
-                                  qcOutChannel[ch]->quantSpec
+                                  qcOutChannel[ch]->quantSpec,
+                                  dZoneQuantEnable
                                   );
   }
 
diff --git a/libAACenc/src/sf_estim.h b/libAACenc/src/sf_estim.h
index b5ac000..ef8d366 100644
--- a/libAACenc/src/sf_estim.h
+++ b/libAACenc/src/sf_estim.h
@@ -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
@@ -110,6 +110,7 @@
 FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[],
                      QC_OUT_CHANNEL* qcOutChannel[],
                      const int invQuant,
+                     const INT dZoneQuantEnable,
                      const int nChannels);
 
 
diff --git a/libAACenc/src/tns_func.h b/libAACenc/src/tns_func.h
index 6ee0edb..5e5265d 100644
--- a/libAACenc/src/tns_func.h
+++ b/libAACenc/src/tns_func.h
@@ -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
@@ -100,6 +100,7 @@
                          INT channels,
                          INT blocktype,
                          INT granuleLength,
+                         INT isLowDelay,
                          INT ldSbrPresent,
                          TNS_CONFIG *tnsConfig,
                          PSY_CONFIGURATION *psyConfig,
diff --git a/libFDK/include/fixpoint_math.h b/libFDK/include/fixpoint_math.h
index 88e2f09..0d50f0a 100644
--- a/libFDK/include/fixpoint_math.h
+++ b/libFDK/include/fixpoint_math.h
@@ -94,6 +94,35 @@
 
 #include "common_fix.h"
 
+#if !defined(FUNCTION_fIsLessThan)
+/**
+ * \brief Compares two fixpoint values incl. scaling.
+ * \param a_m mantissa of the first input value.
+ * \param a_e exponent of the first input value.
+ * \param b_m mantissa of the second input value.
+ * \param b_e exponent of the second input value.
+ * \return non-zero if (a_m*2^a_e) < (b_m*2^b_e), 0 otherwise
+ */
+FDK_INLINE INT fIsLessThan(FIXP_DBL a_m, INT a_e, FIXP_DBL b_m, INT b_e)
+{
+  if (a_e > b_e) {
+    return (b_m >> fMin(a_e-b_e, DFRACT_BITS-1) > a_m);
+  } else {
+    return (a_m >> fMin(b_e-a_e, DFRACT_BITS-1) < b_m);
+  }
+}
+
+FDK_INLINE INT fIsLessThan(FIXP_SGL a_m, INT a_e, FIXP_SGL b_m, INT b_e)
+{
+  if (a_e > b_e) {
+    return (b_m >> fMin(a_e-b_e, FRACT_BITS-1) > a_m);
+  } else {
+    return (a_m >> fMin(b_e-a_e, FRACT_BITS-1) < b_m);
+  }
+}
+#endif
+
+
 
 #define LD_DATA_SCALING (64.0f)
 #define LD_DATA_SHIFT   6   /* pow(2, LD_DATA_SHIFT) = LD_DATA_SCALING */
diff --git a/libFDK/src/FDK_core.cpp b/libFDK/src/FDK_core.cpp
index 8fa5596..1d8ac7b 100644
--- a/libFDK/src/FDK_core.cpp
+++ b/libFDK/src/FDK_core.cpp
@@ -93,7 +93,7 @@
 /* FDK tools library info */
 #define FDK_TOOLS_LIB_VL0 2
 #define FDK_TOOLS_LIB_VL1 3
-#define FDK_TOOLS_LIB_VL2 4
+#define FDK_TOOLS_LIB_VL2 6
 #define FDK_TOOLS_LIB_TITLE "FDK Tools"
 #ifdef __ANDROID__
 #define FDK_TOOLS_LIB_BUILD_DATE ""
diff --git a/libFDK/src/FDK_tools_rom.cpp b/libFDK/src/FDK_tools_rom.cpp
index 49f0ee1..29e37f2 100644
--- a/libFDK/src/FDK_tools_rom.cpp
+++ b/libFDK/src/FDK_tools_rom.cpp
@@ -2236,7 +2236,7 @@
   ics_info,
   ms,
   ltp_data_present,
-  ltp_data,
+  /* ltp_data, */
   global_gain,
   section_data,
   scale_factor_data,
@@ -2247,7 +2247,7 @@
   next_channel,
 
   ltp_data_present,
-  ltp_data,
+  /* ltp_data, */
   global_gain,
   section_data,
   scale_factor_data,
@@ -2290,7 +2290,178 @@
   { &node_aac_cpe0_epc1, &node_aac_cpe1_epc1 }
 };
 
+/*
+ * AOT = 20
+ * epConfig = 0
+ */
+static const rbd_id_t el_scal_sce_epc0[] = {
+  ics_info,            /* ESC 1 */
+  tns_data_present,
+  ltp_data_present,
+  /* ltp_data, */
+  global_gain,
+  section_data,
+  scale_factor_data,
+  esc1_hcr,
+  esc2_rvlc,           /* ESC 2 */
+  tns_data,            /* ESC 3 */
+  spectral_data,       /* ESC 4 */
+  end_of_sequence
+};
 
+static const struct element_list node_scal_sce_epc0 = {
+  el_scal_sce_epc0,
+  { NULL, NULL }
+};
+
+static const rbd_id_t el_scal_cpe_epc0[] = {
+  ics_info,            /* ESC 0 */
+  ms,
+  tns_data_present,    /* ESC 1 (ch 0) */
+  ltp_data_present,
+  /* ltp_data, */
+  global_gain,
+  section_data,
+  scale_factor_data,
+  esc1_hcr,
+  esc2_rvlc,           /* ESC 2 (ch 0) */
+  tns_data,            /* ESC 3 (ch 0) */
+  spectral_data,       /* ESC 4 (ch 0) */
+  next_channel,
+  tns_data_present,    /* ESC 1 (ch 1) */
+  ltp_data_present,
+  global_gain,
+  section_data,
+  scale_factor_data,
+  esc1_hcr,
+  esc2_rvlc,           /* ESC 2 (ch 1) */
+  tns_data,            /* ESC 3 (ch 1) */
+  spectral_data,       /* ESC 4 (ch 1) */
+  end_of_sequence
+};
+
+static const struct element_list node_scal_cpe_epc0 = {
+  el_scal_cpe_epc0,
+  { NULL, NULL }
+};
+
+/*
+ * AOT = 20
+ * epConfig = 1
+ */
+static const rbd_id_t el_scal_sce_epc1[] = {
+  ics_info,
+  tns_data_present,
+  ltp_data_present,
+  /* ltp_data, */
+  global_gain,
+  section_data,
+  scale_factor_data,
+  esc1_hcr,
+  tns_data,
+  spectral_data,
+  end_of_sequence
+};
+
+static const struct element_list node_scal_sce_epc1 = {
+  el_scal_sce_epc1,
+  { NULL, NULL }
+};
+
+static const rbd_id_t el_scal_cpe_epc1[] = {
+  ics_info,
+  ms,
+  tns_data_present,
+  ltp_data_present,
+  /* ltp_data, */
+  global_gain,
+  section_data,
+  scale_factor_data,
+  esc1_hcr,
+  next_channel,
+  tns_data_present,
+  ltp_data_present,
+  /* ltp_data, */
+  global_gain,
+  section_data,
+  scale_factor_data,
+  esc1_hcr,
+  next_channel,
+  tns_data,
+  next_channel,
+  tns_data,
+  next_channel,
+  spectral_data,
+  next_channel,
+  spectral_data,
+  end_of_sequence
+};
+
+static const struct element_list node_scal_cpe_epc1 = {
+  el_scal_cpe_epc1,
+  { NULL, NULL }
+};
+
+/*
+ * Pseudo AOT for DRM/DRM+ (similar to AOT 20)
+ * Derived from epConfig = 1
+ */
+static const rbd_id_t el_drm_sce[] = {
+  drmcrc_start_reg,
+  ics_info,
+  tns_data_present,
+  ltp_data_present,
+  /* ltp_data, */
+  global_gain,
+  section_data,
+  scale_factor_data,
+  esc1_hcr,
+  tns_data,
+  drmcrc_end_reg,
+  spectral_data,
+  end_of_sequence
+};
+
+static const struct element_list node_drm_sce = {
+  el_drm_sce,
+  { NULL, NULL }
+};
+
+static const rbd_id_t el_drm_cpe[] = {
+  drmcrc_start_reg,
+  ics_info,
+  ms,
+  tns_data_present,
+  ltp_data_present,
+  /* ltp_data, */
+  global_gain,
+  section_data,
+  scale_factor_data,
+  esc1_hcr,
+  next_channel,
+  tns_data_present,
+  ltp_data_present,
+  /* ltp_data, */
+  global_gain,
+  section_data,
+  scale_factor_data,
+  esc1_hcr,
+  next_channel,
+  tns_data,
+  next_channel,
+  tns_data,
+  drmcrc_end_reg,
+  next_channel,
+  spectral_data,
+  next_channel,
+  spectral_data,
+  end_of_sequence
+};
+
+static const struct element_list node_drm_cpe = {
+  el_drm_cpe,
+  { NULL, NULL }
+};
 
 /*
  * AOT = 39
@@ -2405,6 +2576,19 @@
           return &node_aac_cpe_epc1;
       }
       break;
+    case AOT_ER_AAC_SCAL:
+      if (nChannels == 1) {
+        if (epConfig <= 0)
+          return &node_scal_sce_epc0;
+        else
+          return &node_scal_sce_epc1;
+      } else {
+        if (epConfig <= 0)
+          return &node_scal_cpe_epc0;
+        else
+          return &node_scal_cpe_epc1;
+      }
+      break;
     case AOT_ER_AAC_ELD:
       if (nChannels == 1) {
         if (epConfig <= 0)
@@ -2417,6 +2601,16 @@
         else
           return &node_eld_cpe_epc1;
       }
+    case AOT_DRM_AAC:
+    case AOT_DRM_SBR:
+    case AOT_DRM_MPEG_PS:
+      FDK_ASSERT(epConfig == 1);
+      if (nChannels == 1) {
+        return &node_drm_sce;
+      } else {
+        return &node_drm_cpe;
+      }
+      break;
     default:
       break;
   }
diff --git a/libMpegTPDec/src/tpdec_asc.cpp b/libMpegTPDec/src/tpdec_asc.cpp
index bae271e..96a1b35 100644
--- a/libMpegTPDec/src/tpdec_asc.cpp
+++ b/libMpegTPDec/src/tpdec_asc.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
@@ -1126,6 +1126,8 @@
       if ( 0 != ld_sbr_header(asc, hBs, cb) ) {
         return TRANSPORTDEC_PARSE_ERROR;
       }
+    } else {
+      return TRANSPORTDEC_UNSUPPORTED_FORMAT;
     }
   }
   esc->m_useLdQmfTimeAlign = 0;
@@ -1146,7 +1148,7 @@
 
     switch (eldExtType) {
       default:
-        for(cnt=0; cnt<len; cnt++) {
+        for(cnt=0; cnt<eldExtLen; cnt++) {
           FDKreadBits(hBs, 8 );
         }
         break;
@@ -1372,4 +1374,133 @@
   return (ErrorStatus);
 }
 
+TRANSPORTDEC_ERROR DrmRawSdcAudioConfig_Parse(
+        CSAudioSpecificConfig *self,
+        HANDLE_FDK_BITSTREAM   bs
+        )
+{
+  TRANSPORTDEC_ERROR ErrorStatus = TRANSPORTDEC_OK;
+
+  AudioSpecificConfig_Init(self);
+
+  if ((INT)FDKgetValidBits(bs) < 20) {
+    ErrorStatus = TRANSPORTDEC_PARSE_ERROR;
+    goto bail;
+  }
+  else {
+    /* DRM - Audio information data entity - type 9
+       - Short Id            2 bits
+       - Stream Id           2 bits
+       - audio coding        2 bits
+       - SBR flag            1 bit
+       - audio mode          2 bits
+       - audio sampling rate 3 bits
+       - text flag           1 bit
+       - enhancement flag    1 bit
+       - coder field         5 bits
+       - rfa                 1 bit  */
+
+    int audioCoding, audioMode, cSamplingFreq, coderField, sfIdx, sbrFlag;
+
+    /* Read the SDC field */
+    FDKreadBits(bs,4);   /* Short and Stream Id */
+
+    audioCoding   = FDKreadBits(bs, 2);
+    sbrFlag       = FDKreadBits(bs, 1);
+    audioMode     = FDKreadBits(bs, 2);
+    cSamplingFreq = FDKreadBits(bs, 3);    /* audio sampling rate */
+
+    FDKreadBits(bs, 2);  /* Text and enhancement flag */
+    coderField   = FDKreadBits(bs, 5);
+    FDKreadBits(bs, 1);  /* rfa */
+
+    /* Evaluate configuration and fill the ASC */
+    switch (cSamplingFreq) {
+    case 0: /*  8 kHz */
+      sfIdx = 11;
+      break;
+    case 1: /* 12 kHz */
+      sfIdx = 9;
+      break;
+    case 2: /* 16 kHz */
+      sfIdx = 8;
+      break;
+    case 3: /* 24 kHz */
+      sfIdx = 6;
+      break;
+    case 5: /* 48 kHz */
+      sfIdx = 3;
+      break;
+    case 4: /* reserved */
+    case 6: /* reserved */
+    case 7: /* reserved */
+    default:
+      ErrorStatus = TRANSPORTDEC_PARSE_ERROR;
+      goto bail;
+    }
+
+    self->m_samplingFrequencyIndex = sfIdx;
+    self->m_samplingFrequency = SamplingRateTable[sfIdx];
+
+    if ( sbrFlag ) {
+      UINT i;
+      int tmp = -1;
+      self->m_sbrPresentFlag = 1;
+      self->m_extensionAudioObjectType = AOT_SBR;
+      self->m_extensionSamplingFrequency = self->m_samplingFrequency << 1;
+      for (i=0; i<(sizeof(SamplingRateTable)/sizeof(SamplingRateTable[0])); i++){
+        if (SamplingRateTable[i] == self->m_extensionSamplingFrequency){
+          tmp = i;
+          break;
+        }
+      }
+      self->m_extensionSamplingFrequencyIndex = tmp;
+    }
+
+    switch (audioCoding) {
+      case 0: /* AAC */
+          self->m_aot = AOT_DRM_AAC     ;  /* Set pseudo AOT for Drm AAC */
+
+        switch (audioMode) {
+        case 1: /* parametric stereo */
+          self->m_psPresentFlag = 1;
+        case 0: /* mono */
+          self->m_channelConfiguration = 1;
+          break;
+        case 2: /* stereo */
+          self->m_channelConfiguration = 2;
+          break;
+        default:
+          ErrorStatus = TRANSPORTDEC_PARSE_ERROR;
+          goto bail;
+        }
+        self->m_vcb11Flag = 1;
+        self->m_hcrFlag = 1;
+        self->m_samplesPerFrame = 960;
+        self->m_epConfig = 1;
+        break;
+      case 1: /* CELP */
+        self->m_aot = AOT_ER_CELP;
+        self->m_channelConfiguration = 1;
+        break;
+      case 2: /* HVXC */
+        self->m_aot = AOT_ER_HVXC;
+        self->m_channelConfiguration = 1;
+        break;
+      case 3: /* reserved */
+      default:
+        ErrorStatus = TRANSPORTDEC_PARSE_ERROR;
+        self->m_aot = AOT_NONE;
+        break;
+    }
+
+    if (self->m_psPresentFlag && !self->m_sbrPresentFlag) {
+      ErrorStatus = TRANSPORTDEC_PARSE_ERROR;
+      goto bail;
+    }
+  }
+
+bail:
+  return (ErrorStatus);
+}
 
diff --git a/libMpegTPDec/src/tpdec_drm.cpp b/libMpegTPDec/src/tpdec_drm.cpp
new file mode 100644
index 0000000..df319e5
--- /dev/null
+++ b/libMpegTPDec/src/tpdec_drm.cpp
@@ -0,0 +1,146 @@
+
+/* -----------------------------------------------------------------------------------------------------------
+Software License for The Fraunhofer FDK AAC Codec Library for Android
+
+© Copyright  1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
+  All rights reserved.
+
+ 1.    INTRODUCTION
+The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
+the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
+This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
+
+AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
+audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
+independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
+of the MPEG specifications.
+
+Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
+may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
+individually for the purpose of encoding or decoding bit streams in products that are compliant with
+the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
+these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
+software may already be covered under those patent licenses when it is used for those licensed purposes only.
+
+Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
+are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
+applications information and documentation.
+
+2.    COPYRIGHT LICENSE
+
+Redistribution and use in source and binary forms, with or without modification, are permitted without
+payment of copyright license fees provided that you satisfy the following conditions:
+
+You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
+your modifications thereto in source code form.
+
+You must retain the complete text of this software license in the documentation and/or other materials
+provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
+You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
+modifications thereto to recipients of copies in binary form.
+
+The name of Fraunhofer may not be used to endorse or promote products derived from this library without
+prior written permission.
+
+You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
+software or your modifications thereto.
+
+Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
+and the date of any change. For modified versions of the FDK AAC Codec, the term
+"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
+"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
+
+3.    NO PATENT LICENSE
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
+ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
+respect to this software.
+
+You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
+by appropriate patent licenses.
+
+4.    DISCLAIMER
+
+This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
+"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
+of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
+including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
+or business interruption, however caused and on any theory of liability, whether in contract, strict
+liability, or tort (including negligence), arising in any way out of the use of this software, even if
+advised of the possibility of such damage.
+
+5.    CONTACT INFORMATION
+
+Fraunhofer Institute for Integrated Circuits IIS
+Attention: Audio and Multimedia Departments - FDK AAC LL
+Am Wolfsmantel 33
+91058 Erlangen, Germany
+
+www.iis.fraunhofer.de/amm
+amm-info@iis.fraunhofer.de
+----------------------------------------------------------------------------------------------------------- */
+
+/*****************************  MPEG-4 AAC Decoder  **************************
+
+   Author(s):   Christian Griebel
+   Description: DRM transport stuff
+
+******************************************************************************/
+
+#include "tpdec_drm.h"
+
+
+#include "FDK_bitstream.h"
+
+
+
+void drmRead_CrcInit(HANDLE_DRM pDrm)      /*!< pointer to drm crc info stucture */
+{
+  FDK_ASSERT(pDrm != NULL);
+
+  FDKcrcInit(&pDrm->crcInfo, 0x001d, 0xFFFF, 8);
+}
+
+int drmRead_CrcStartReg(
+                     HANDLE_DRM pDrm,            /*!< pointer to drm stucture */
+                     HANDLE_FDK_BITSTREAM hBs,   /*!< handle to current bit buffer structure */
+                     int mBits                   /*!< number of bits in crc region */
+                   )
+{
+  FDK_ASSERT(pDrm != NULL);
+
+  FDKcrcReset(&pDrm->crcInfo);
+
+  pDrm->crcReadValue = FDKreadBits(hBs, 8);
+
+  return ( FDKcrcStartReg(&pDrm->crcInfo, hBs, mBits) );
+
+}
+
+void drmRead_CrcEndReg(
+                    HANDLE_DRM pDrm,             /*!< pointer to drm crc info stucture */
+                    HANDLE_FDK_BITSTREAM hBs,    /*!< handle to current bit buffer structure */
+                    int reg                      /*!< crc region */
+                  )
+{
+  FDK_ASSERT(pDrm != NULL);
+
+  FDKcrcEndReg(&pDrm->crcInfo, hBs, reg);
+}
+
+TRANSPORTDEC_ERROR drmRead_CrcCheck( HANDLE_DRM pDrm )
+{
+  TRANSPORTDEC_ERROR ErrorStatus = TRANSPORTDEC_OK;
+  USHORT crc;
+
+  crc = FDKcrcGetCRC(&pDrm->crcInfo) ^ 0xFF;
+  if (crc != pDrm->crcReadValue)
+  {
+    return (TRANSPORTDEC_CRC_ERROR);
+  }
+
+  return (ErrorStatus);
+}
+
+
diff --git a/libMpegTPDec/src/tpdec_drm.h b/libMpegTPDec/src/tpdec_drm.h
new file mode 100644
index 0000000..2161b4c
--- /dev/null
+++ b/libMpegTPDec/src/tpdec_drm.h
@@ -0,0 +1,194 @@
+
+/* -----------------------------------------------------------------------------------------------------------
+Software License for The Fraunhofer FDK AAC Codec Library for Android
+
+© Copyright  1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
+  All rights reserved.
+
+ 1.    INTRODUCTION
+The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
+the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
+This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
+
+AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
+audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
+independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
+of the MPEG specifications.
+
+Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
+may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
+individually for the purpose of encoding or decoding bit streams in products that are compliant with
+the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
+these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
+software may already be covered under those patent licenses when it is used for those licensed purposes only.
+
+Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
+are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
+applications information and documentation.
+
+2.    COPYRIGHT LICENSE
+
+Redistribution and use in source and binary forms, with or without modification, are permitted without
+payment of copyright license fees provided that you satisfy the following conditions:
+
+You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
+your modifications thereto in source code form.
+
+You must retain the complete text of this software license in the documentation and/or other materials
+provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
+You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
+modifications thereto to recipients of copies in binary form.
+
+The name of Fraunhofer may not be used to endorse or promote products derived from this library without
+prior written permission.
+
+You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
+software or your modifications thereto.
+
+Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
+and the date of any change. For modified versions of the FDK AAC Codec, the term
+"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
+"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
+
+3.    NO PATENT LICENSE
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
+ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
+respect to this software.
+
+You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
+by appropriate patent licenses.
+
+4.    DISCLAIMER
+
+This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
+"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
+of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
+including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
+or business interruption, however caused and on any theory of liability, whether in contract, strict
+liability, or tort (including negligence), arising in any way out of the use of this software, even if
+advised of the possibility of such damage.
+
+5.    CONTACT INFORMATION
+
+Fraunhofer Institute for Integrated Circuits IIS
+Attention: Audio and Multimedia Departments - FDK AAC LL
+Am Wolfsmantel 33
+91058 Erlangen, Germany
+
+www.iis.fraunhofer.de/amm
+amm-info@iis.fraunhofer.de
+----------------------------------------------------------------------------------------------------------- */
+
+/*****************************  MPEG-4 AAC Decoder  **************************
+
+   Author(s):   Josef Hoepfl
+   Description: DRM interface
+
+******************************************************************************/
+
+#ifndef TPDEC_DRM_H
+#define TPDEC_DRM_H
+
+#include "tpdec_lib.h"
+
+
+#include "FDK_crc.h"
+
+typedef struct {
+
+  FDK_CRCINFO crcInfo;             /* CRC state info */
+  USHORT      crcReadValue;        /* CRC value read from bitstream data */
+
+} STRUCT_DRM;
+
+typedef STRUCT_DRM *HANDLE_DRM;
+
+/*!
+  \brief Initialize DRM CRC
+
+  The function initialzes the crc buffer and the crc lookup table.
+
+  \return  none
+*/
+void drmRead_CrcInit( HANDLE_DRM pDrm );
+
+/**
+ * \brief Starts CRC region with a maximum number of bits
+ *        If mBits is positive zero padding will be used for CRC calculation, if there
+ *        are less than mBits bits available.
+ *        If mBits is negative no zero padding is done.
+ *        If mBits is zero the memory for the buffer is allocated dynamically, the
+ *        number of bits is not limited.
+ *
+ * \param pDrm DRM data handle
+ * \param hBs bitstream handle, on which the CRC region referes to
+ * \param mBits max number of bits in crc region to be considered
+ *
+ * \return  ID for the created region, -1 in case of an error
+ */
+int drmRead_CrcStartReg(
+        HANDLE_DRM pDrm,
+        HANDLE_FDK_BITSTREAM hBs,
+        int mBits
+        );
+
+/**
+ * \brief Ends CRC region identified by reg
+ *
+ * \param pDrm DRM data handle
+ * \param hBs bitstream handle, on which the CRC region referes to
+ * \param reg CRC regions ID returned by drmRead_CrcStartReg()
+ *
+ * \return  none
+ */
+void drmRead_CrcEndReg(
+        HANDLE_DRM pDrm,
+        HANDLE_FDK_BITSTREAM hBs,
+        int reg
+        );
+
+/**
+ * \brief Check CRC
+ *
+ * Checks if the currently calculated CRC matches the CRC field read from the bitstream
+ * Deletes all CRC regions.
+ *
+ * \param pDrm DRM data handle
+ *
+ * \return Returns 0 if they are identical otherwise 1
+ */
+TRANSPORTDEC_ERROR drmRead_CrcCheck( HANDLE_DRM pDrm );
+
+/**
+ * \brief Check if we have a valid DRM frame at the current bitbuffer position
+ *
+ * This function assumes enough bits in buffer for the current frame.
+ * It reads out the header bits to prepare the bitbuffer for the decode loop.
+ * In case the header bits show an invalid bitstream/frame, the whole frame is skipped.
+ *
+ * \param pDrm DRM data handle which is filled with parsed DRM header data
+ * \param bs handle of bitstream from whom the DRM header is read
+ *
+ * \return  error status
+ */
+TRANSPORTDEC_ERROR drmRead_DecodeHeader(
+        HANDLE_DRM            pDrm,
+        HANDLE_FDK_BITSTREAM  bs
+        );
+
+/**
+ * \brief   Parse a Drm specific SDC audio config from a given bitstream handle.
+ *
+ * \param pAsc                         A pointer to an allocated CSAudioSpecificConfig struct.
+ * \param hBs                          Bitstream handle.
+ *
+ * \return  Total element count including all SCE, CPE and LFE.
+ */
+TRANSPORTDEC_ERROR DrmRawSdcAudioConfig_Parse( CSAudioSpecificConfig *pAsc,
+                                               HANDLE_FDK_BITSTREAM hBs );
+
+
+
+#endif /* TPDEC_DRM_H */
diff --git a/libMpegTPDec/src/tpdec_lib.cpp b/libMpegTPDec/src/tpdec_lib.cpp
index 950af64..24f755b 100644
--- a/libMpegTPDec/src/tpdec_lib.cpp
+++ b/libMpegTPDec/src/tpdec_lib.cpp
@@ -102,6 +102,7 @@
 
 #include "tpdec_latm.h"
 
+#include "tpdec_drm.h"
 
 
 #define MODULE_NAME "transportDec"
@@ -113,6 +114,7 @@
 
   CLatmDemux latm;
 
+  STRUCT_DRM drm;
 
 } transportdec_parser_t;
 
@@ -182,6 +184,9 @@
     hInput->numberOfRawDataBlocks = 0;
     break;
 
+  case TT_DRM:
+    drmRead_CrcInit(&hInput->parser.drm);
+    break;
 
   case TT_MP4_LATM_MCP0:
   case TT_MP4_LATM_MCP1:
@@ -253,6 +258,18 @@
         }
       }
       break;
+    case TT_DRM:
+      fConfigFound = 1;
+      err = DrmRawSdcAudioConfig_Parse(&hTp->asc[layer], hBs);
+      if (err == TRANSPORTDEC_OK) {
+        int errC;
+
+        errC = hTp->callbacks.cbUpdateConfig(hTp->callbacks.cbUpdateConfigData, &hTp->asc[layer]);
+        if (errC != 0) {
+          err = TRANSPORTDEC_PARSE_ERROR;
+        }
+      }
+      break;
   }
 
   if (err == TRANSPORTDEC_OK && fConfigFound) {
@@ -1083,6 +1100,7 @@
       break;
 
     case TT_MP4_RAW:
+    case TT_DRM:
       /* One Access Unit was filled into buffer.
          So get the length out of the buffer. */
       hTp->auLength[layer] = FDKgetValidBits(hBs);
@@ -1283,6 +1301,7 @@
     | CAPF_LATM
     | CAPF_LOAS
     | CAPF_RAWPACKETS
+    | CAPF_DRM
     ;
 
   return TRANSPORTDEC_OK; /* FDKERR_NOERROR; */
@@ -1294,6 +1313,8 @@
   switch (pTp->transportFmt) {
   case TT_MP4_ADTS:
     return adtsRead_CrcStartReg(&pTp->parser.adts, &pTp->bitStream[0], mBits);
+  case TT_DRM:
+    return drmRead_CrcStartReg(&pTp->parser.drm, &pTp->bitStream[0], mBits);
   default:
     return 0;
   }
@@ -1305,6 +1326,9 @@
   case TT_MP4_ADTS:
     adtsRead_CrcEndReg(&pTp->parser.adts, &pTp->bitStream[0], reg);
     break;
+  case TT_DRM:
+    drmRead_CrcEndReg(&pTp->parser.drm, &pTp->bitStream[0], reg);
+    break;
   default:
     break;
   }
@@ -1321,6 +1345,9 @@
       transportDec_AdjustEndOfAccessUnit(pTp);
     }
     return adtsRead_CrcCheck(&pTp->parser.adts);
+  case TT_DRM:
+    return drmRead_CrcCheck(&pTp->parser.drm);
+    break;
   default:
     return TRANSPORTDEC_OK;
   }
diff --git a/libMpegTPDec/src/version b/libMpegTPDec/src/version
index 18fc9ba..75e22c9 100644
--- a/libMpegTPDec/src/version
+++ b/libMpegTPDec/src/version
@@ -2,7 +2,7 @@
 /* library info */
 #define TP_LIB_VL0 2
 #define TP_LIB_VL1 3
-#define TP_LIB_VL2 5
+#define TP_LIB_VL2 7
 #define TP_LIB_TITLE "MPEG Transport"
 #ifdef __ANDROID__
 #define TP_LIB_BUILD_DATE ""
diff --git a/libSBRdec/include/sbrdecoder.h b/libSBRdec/include/sbrdecoder.h
index 174fb5c..3bb9ba3 100644
--- a/libSBRdec/include/sbrdecoder.h
+++ b/libSBRdec/include/sbrdecoder.h
@@ -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
@@ -262,6 +262,7 @@
  *         into *count if a payload length is given (byPayLen > 0). If no SBR payload length is
  *         given (bsPayLen < 0) then the bit stream position on return will be random after this
  *         function call in case of errors, and any further decoding will be completely pointless.
+ *         This function accepts either normal ordered SBR data or reverse ordered DRM SBR data.
  *
  * \param self           SBR decoder handle.
  * \param hBs            Bit stream handle as data source.
diff --git a/libSBRdec/src/env_calc.cpp b/libSBRdec/src/env_calc.cpp
index ade57fc..fa5330a 100644
--- a/libSBRdec/src/env_calc.cpp
+++ b/libSBRdec/src/env_calc.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
@@ -151,13 +151,13 @@
 }
 ENV_CALC_NRGS;
 
-/*static*/ void equalizeFiltBufferExp(FIXP_DBL *filtBuffer,
+static void equalizeFiltBufferExp(FIXP_DBL *filtBuffer,
                                   SCHAR   *filtBuffer_e,
                                   FIXP_DBL *NrgGain,
                                   SCHAR   *NrgGain_e,
                                   int    subbands);
 
-/*static*/ void calcNrgPerSubband(FIXP_DBL  **analysBufferReal,
+static void calcNrgPerSubband(FIXP_DBL  **analysBufferReal,
                               FIXP_DBL  **analysBufferImag,
                               int       lowSubband, int highSubband,
                               int       start_pos,  int next_pos,
@@ -165,7 +165,7 @@
                               FIXP_DBL *nrgEst,
                               SCHAR    *nrgEst_e );
 
-/*static*/ void calcNrgPerSfb(FIXP_DBL  **analysBufferReal,
+static void calcNrgPerSfb(FIXP_DBL  **analysBufferReal,
                           FIXP_DBL  **analysBufferImag,
                           int       nSfb,
                           UCHAR    *freqBandTable,
@@ -174,13 +174,13 @@
                           FIXP_DBL *nrg_est,
                           SCHAR    *nrg_est_e );
 
-/*static*/ void calcSubbandGain(FIXP_DBL  nrgRef, SCHAR nrgRef_e, ENV_CALC_NRGS* nrgs, int c,
+static void calcSubbandGain(FIXP_DBL  nrgRef, SCHAR nrgRef_e, ENV_CALC_NRGS* nrgs, int c,
                             FIXP_DBL  tmpNoise, SCHAR tmpNoise_e,
                             UCHAR     sinePresentFlag,
                             UCHAR     sineMapped,
                             int       noNoiseFlag);
 
-/*static*/ void calcAvgGain(ENV_CALC_NRGS* nrgs,
+static void calcAvgGain(ENV_CALC_NRGS* nrgs,
                         int        lowSubband,
                         int        highSubband,
                         FIXP_DBL  *sumRef_m,
@@ -188,7 +188,7 @@
                         FIXP_DBL  *ptrAvgGain_m,
                         SCHAR     *ptrAvgGain_e);
 
-/*static*/ void adjustTimeSlotLC(FIXP_DBL  *ptrReal,
+static void adjustTimeSlot_EldGrid(FIXP_DBL  *ptrReal,
                            ENV_CALC_NRGS* nrgs,
                            UCHAR *ptrHarmIndex,
                            int    lowSubbands,
@@ -196,8 +196,17 @@
                            int    scale_change,
                            int    noNoiseFlag,
                            int   *ptrPhaseIndex,
-                           int    fCldfb);
-/*static*/ void adjustTimeSlotHQ(FIXP_DBL  *ptrReal,
+                           int    scale_diff_low);
+
+static void adjustTimeSlotLC(FIXP_DBL  *ptrReal,
+                           ENV_CALC_NRGS* nrgs,
+                           UCHAR *ptrHarmIndex,
+                           int    lowSubbands,
+                           int    noSubbands,
+                           int    scale_change,
+                           int    noNoiseFlag,
+                           int   *ptrPhaseIndex);
+static void adjustTimeSlotHQ(FIXP_DBL  *ptrReal,
                            FIXP_DBL  *ptrImag,
                            HANDLE_SBR_CALCULATE_ENVELOPE h_sbr_cal_env,
                            ENV_CALC_NRGS* nrgs,
@@ -224,7 +233,7 @@
   Additionally, the flags in harmFlagsPrev are being updated by this function
   for the next frame.
 */
-/*static*/ void mapSineFlags(UCHAR *freqBandTable, /*!< Band borders (there's only 1 flag per band) */
+static void mapSineFlags(UCHAR *freqBandTable,         /*!< Band borders (there's only 1 flag per band) */
                          int nSfb,                     /*!< Number of bands in the table */
                          UCHAR *addHarmonics,           /*!< vector with 1 flag per sfb */
                          int *harmFlagsPrev,           /*!< Packed 'addHarmonics' */
@@ -990,7 +999,6 @@
           /* Prevent the smoothing filter from running on constant levels */
           if (j-start_pos < smooth_length)
             smooth_ratio = FDK_sbrDecoder_sbr_smoothFilter[j-start_pos];
-
           else
             smooth_ratio = FL2FXCONST_SGL(0.0f);
 
@@ -1007,7 +1015,8 @@
         }
         else
         {
-          adjustTimeSlotLC(&analysBufferReal[j][lowSubband],
+          if (flags & SBRDEC_ELD_GRID) {
+            adjustTimeSlot_EldGrid(&analysBufferReal[j][lowSubband],
                            pNrgs,
                           &h_sbr_cal_env->harmIndex,
                            lowSubband,
@@ -1015,7 +1024,18 @@
                            scale_change,
                            noNoiseFlag,
                           &h_sbr_cal_env->phaseIndex,
-                           (flags & SBRDEC_ELD_GRID));
+                           EXP2SCALE(adj_e) - sbrScaleFactor->lb_scale);
+          } else
+          {
+            adjustTimeSlotLC(&analysBufferReal[j][lowSubband],
+                           pNrgs,
+                          &h_sbr_cal_env->harmIndex,
+                           lowSubband,
+                           noSubbands,
+                           scale_change,
+                           noNoiseFlag,
+                          &h_sbr_cal_env->phaseIndex);
+          }
         }
       } // for
 
@@ -1176,7 +1196,7 @@
   can be performed.
   This function is called once for each envelope before adjusting.
 */
-/*static*/ void equalizeFiltBufferExp(FIXP_DBL *filtBuffer,     /*!< bufferd gains */
+static void equalizeFiltBufferExp(FIXP_DBL *filtBuffer,     /*!< bufferd gains */
                                   SCHAR    *filtBuffer_e,   /*!< exponents of bufferd gains */
                                   FIXP_DBL *nrgGain,        /*!< gains for current envelope */
                                   SCHAR    *nrgGain_e,      /*!< exponents of gains for current envelope */
@@ -1331,7 +1351,7 @@
 
   This function is used when interpolFreq is true.
 */
-/*static*/ void calcNrgPerSubband(FIXP_DBL  **analysBufferReal, /*!< Real part of subband samples */
+static void calcNrgPerSubband(FIXP_DBL  **analysBufferReal, /*!< Real part of subband samples */
                               FIXP_DBL  **analysBufferImag, /*!< Imaginary part of subband samples */
                               int       lowSubband,           /*!< Begin of the SBR frequency range */
                               int       highSubband,          /*!< High end of the SBR frequency range */
@@ -1452,7 +1472,7 @@
 
   This function is used when interpolFreq is false.
 */
-/*static*/ void calcNrgPerSfb(FIXP_DBL  **analysBufferReal,  /*!< Real part of subband samples */
+static void calcNrgPerSfb(FIXP_DBL  **analysBufferReal,  /*!< Real part of subband samples */
                           FIXP_DBL  **analysBufferImag,  /*!< Imaginary part of subband samples */
                           int       nSfb,                /*!< Number of scale factor bands */
                           UCHAR    *freqBandTable,       /*!< First Subband for each Sfb */
@@ -1585,7 +1605,7 @@
 
   The resulting energy gain is given by mantissa and exponent.
 */
-/*static*/ void calcSubbandGain(FIXP_DBL  nrgRef,            /*!< Reference Energy according to envelope data */
+static void calcSubbandGain(FIXP_DBL  nrgRef,            /*!< Reference Energy according to envelope data */
                             SCHAR     nrgRef_e,          /*!< Reference Energy according to envelope data (exponent) */
                             ENV_CALC_NRGS* nrgs,
                             int       i,
@@ -1689,7 +1709,7 @@
   The result is used as a relative limit for all gains within the
   current "limiter band" (a certain frequency range).
 */
-/*static*/ void calcAvgGain(ENV_CALC_NRGS* nrgs,
+static void calcAvgGain(ENV_CALC_NRGS* nrgs,
                         int        lowSubband,    /*!< Begin of the limiter band */
                         int        highSubband,   /*!< High end of the limiter band */
                         FIXP_DBL  *ptrSumRef,
@@ -1728,21 +1748,101 @@
   *ptrSumRef_e = sumRef_e;
 }
 
+static void adjustTimeSlot_EldGrid(
+                              FIXP_DBL *ptrReal,        /*!< Subband samples to be adjusted, real part */
+                              ENV_CALC_NRGS* nrgs,
+                              UCHAR    *ptrHarmIndex,   /*!< Harmonic index */
+                              int       lowSubband,     /*!< Lowest QMF-channel in the currently used SBR range. */
+                              int       noSubbands,     /*!< Number of QMF subbands */
+                              int       scale_change,   /*!< Number of bits to shift adjusted samples */
+                              int       noNoiseFlag,    /*!< Flag to suppress noise addition */
+                              int      *ptrPhaseIndex,  /*!< Start index to random number array */
+                              int       scale_diff_low) /*!<  */
+{
+  int k;
+  FIXP_DBL  signalReal, sbNoise;
+  int tone_count = 0;
+
+  FIXP_DBL *pGain       = nrgs->nrgGain;     /*!< Gains of current envelope */
+  FIXP_DBL *pNoiseLevel = nrgs->noiseLevel;  /*!< Noise levels of current envelope */
+  FIXP_DBL *pSineLevel  = nrgs->nrgSine;     /*!< Sine levels */
+
+  int    phaseIndex = *ptrPhaseIndex;
+  UCHAR  harmIndex  = *ptrHarmIndex;
+
+  static const INT harmonicPhase [2][4] = {
+    { 1, 0, -1,  0},
+    { 0, 1,  0, -1}
+  };
+
+  static const FIXP_DBL harmonicPhaseX [2][4] = {
+    { FL2FXCONST_DBL(2.0*1.245183154539139e-001),  FL2FXCONST_DBL(2.0*-1.123767859325028e-001),  FL2FXCONST_DBL(2.0*-1.245183154539139e-001), FL2FXCONST_DBL(2.0* 1.123767859325028e-001) },
+    { FL2FXCONST_DBL(2.0*1.245183154539139e-001),  FL2FXCONST_DBL(2.0* 1.123767859325028e-001),  FL2FXCONST_DBL(2.0*-1.245183154539139e-001), FL2FXCONST_DBL(2.0*-1.123767859325028e-001) }
+  };
+
+  for (k=0; k < noSubbands; k++) {
+
+    phaseIndex = (phaseIndex + 1) & (SBR_NF_NO_RANDOM_VAL - 1);
+
+    if( (pSineLevel[0] != FL2FXCONST_DBL(0.0f)) || (noNoiseFlag == 1) ){
+      sbNoise = FL2FXCONST_DBL(0.0f);
+    } else {
+      sbNoise = pNoiseLevel[0];
+    }
+
+    signalReal = fMultDiv2(*ptrReal,*pGain) << ((int)scale_change);
+
+    signalReal += (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[phaseIndex][0], sbNoise)<<4);
+
+    signalReal += pSineLevel[0] * harmonicPhase[0][harmIndex];
+
+    *ptrReal = signalReal;
+
+    if (k == 0) {
+      *(ptrReal-1) += scaleValue(fMultDiv2(harmonicPhaseX[lowSubband&1][harmIndex], pSineLevel[0]), -scale_diff_low)  ;
+      if (k < noSubbands - 1) {
+        *(ptrReal)   += fMultDiv2(pSineLevel[1], harmonicPhaseX[(lowSubband+1)&1][harmIndex]);
+      }
+    }
+    if (k > 0 && k < noSubbands - 1 && tone_count < 16) {
+      *(ptrReal)   += fMultDiv2(pSineLevel[- 1], harmonicPhaseX [(lowSubband+k)&1]  [harmIndex]);
+      *(ptrReal)   += fMultDiv2(pSineLevel[+ 1], harmonicPhaseX [(lowSubband+k+1)&1][harmIndex]);
+    }
+    if (k == noSubbands - 1 && tone_count < 16) {
+      if (k > 0) {
+        *(ptrReal)   += fMultDiv2(pSineLevel[- 1], harmonicPhaseX [(lowSubband+k)&1][harmIndex]);
+      }
+      if (k + lowSubband + 1< 63) {
+        *(ptrReal+1) += fMultDiv2(pSineLevel[0], harmonicPhaseX[(lowSubband+k+1)&1][harmIndex]);
+      }
+    }
+
+    if(pSineLevel[0] != FL2FXCONST_DBL(0.0f)){
+      tone_count++;
+    }
+    ptrReal++;
+    pNoiseLevel++;
+    pGain++;
+    pSineLevel++;
+  }
+
+  *ptrHarmIndex = (harmIndex + 1) & 3;
+  *ptrPhaseIndex = phaseIndex & (SBR_NF_NO_RANDOM_VAL - 1);
+}
 
 /*!
   \brief   Amplify one timeslot of the signal with the calculated gains
            and add the noisefloor.
 */
 
-/*static*/ void adjustTimeSlotLC(FIXP_DBL *ptrReal,       /*!< Subband samples to be adjusted, real part */
+static void adjustTimeSlotLC(FIXP_DBL *ptrReal,       /*!< Subband samples to be adjusted, real part */
                              ENV_CALC_NRGS* nrgs,
                              UCHAR    *ptrHarmIndex,  /*!< Harmonic index */
                              int       lowSubband,    /*!< Lowest QMF-channel in the currently used SBR range. */
                              int       noSubbands,    /*!< Number of QMF subbands */
                              int       scale_change,  /*!< Number of bits to shift adjusted samples */
                              int       noNoiseFlag,   /*!< Flag to suppress noise addition */
-                             int      *ptrPhaseIndex, /*!< Start index to random number array */
-                             int       fCldfb)        /*!< CLDFB 80 flag */
+                             int      *ptrPhaseIndex) /*!< Start index to random number array */
 {
   FIXP_DBL *pGain       = nrgs->nrgGain;     /*!< Gains of current envelope */
   FIXP_DBL *pNoiseLevel = nrgs->noiseLevel;  /*!< Noise levels of current envelope */
@@ -1775,41 +1875,10 @@
   sineLevelNext = (noSubbands > 1) ? pSineLevel[0] : FL2FXCONST_DBL(0.0f);
 
   if (sineLevel!=FL2FXCONST_DBL(0.0f)) tone_count++;
-
   else if (!noNoiseFlag)
         /* Add noisefloor to the amplified signal */
         signalReal += (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], pNoiseLevel[0])<<4);
 
-  if (fCldfb) {
-
-    if (!(harmIndex&0x1)) {
-      /* harmIndex 0,2 */
-      signalReal += (harmIndex&0x2) ? -sineLevel : sineLevel;
-      *ptrReal++ = signalReal;
-    }
-    else {
-      /* harmIndex 1,3 in combination with freqInvFlag */
-      int shift = (int) (scale_change+1);
-      shift = (shift>=0) ? fixMin(DFRACT_BITS-1,shift) : fixMax(-(DFRACT_BITS-1),shift);
-
-      FIXP_DBL tmp1 = scaleValue( fMultDiv2(C1_CLDFB, sineLevel), -shift );
-
-      FIXP_DBL tmp2 = fMultDiv2(C1_CLDFB, sineLevelNext);
-
-
-      /* save switch and compare operations and reduce to XOR statement */
-      if ( ((harmIndex>>1)&0x1)^freqInvFlag) {
-          *(ptrReal-1) += tmp1;
-          signalReal   -= tmp2;
-      } else {
-          *(ptrReal-1) -= tmp1;
-          signalReal   += tmp2;
-      }
-      *ptrReal++ = signalReal;
-      freqInvFlag = !freqInvFlag;
-    }
-
-  } else
   {
     if (!(harmIndex&0x1)) {
       /* harmIndex 0,2 */
@@ -1933,8 +2002,9 @@
   *ptrHarmIndex = (harmIndex + 1) & 3;
   *ptrPhaseIndex = index & (SBR_NF_NO_RANDOM_VAL - 1);
 }
-void adjustTimeSlotHQ(FIXP_DBL *RESTRICT ptrReal,           /*!< Subband samples to be adjusted, real part */
-                      FIXP_DBL *RESTRICT ptrImag,               /*!< Subband samples to be adjusted, imag part */
+static void adjustTimeSlotHQ(
+                      FIXP_DBL *RESTRICT ptrReal,      /*!< Subband samples to be adjusted, real part */
+                      FIXP_DBL *RESTRICT ptrImag,      /*!< Subband samples to be adjusted, imag part */
                       HANDLE_SBR_CALCULATE_ENVELOPE h_sbr_cal_env,
                       ENV_CALC_NRGS* nrgs,
                       int       lowSubband,            /*!< Lowest QMF-channel in the currently used SBR range. */
@@ -2137,7 +2207,6 @@
   UCHAR workLimiterBandTable[MAX_FREQ_COEFFS / 2 + MAX_NUM_PATCHES + 1];
   int patchBorders[MAX_NUM_PATCHES + 1];
   int kx, k2;
-  FIXP_DBL temp;
 
   int lowSubband = freqBandTable[0];
   int highSubband = freqBandTable[noFreqBands];
@@ -2169,13 +2238,32 @@
 
 
     while (hiLimIndex <= tempNoLim) {
+      FIXP_DBL div_m, oct_m, temp;
+      INT div_e  = 0, oct_e  = 0, temp_e = 0;
+
       k2 = workLimiterBandTable[hiLimIndex] + lowSubband;
       kx = workLimiterBandTable[loLimIndex] + lowSubband;
 
-      temp = FX_SGL2FX_DBL(FDK_getNumOctavesDiv8(kx,k2)); /* Number of octaves */
-      temp = fMult(temp, FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4[limiterBands]);
+      div_m  = fDivNorm(k2, kx, &div_e);
 
-      if (temp < FL2FXCONST_DBL (0.49f)>>5) {
+      /* calculate number of octaves */
+      oct_m  = fLog2(div_m, div_e, &oct_e);
+
+      /* multiply with limiterbands per octave    */
+      /* values 1, 1.2, 2, 3 -> scale factor of 2 */
+      temp = fMultNorm(oct_m, FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4_DBL[limiterBands], &temp_e);
+
+      /* overall scale factor of temp ist addition of scalefactors from log2 calculation,
+         limiter bands scalefactor (2) and limiter bands multiplication */
+      temp_e += oct_e + 2;
+
+      /*    div can be a maximum of 64 (k2 = 64 and kx = 1)
+         -> oct can be a maximum of 6
+         -> temp can be a maximum of 18 (as limiterBandsPerOctoave is a maximum factor of 3)
+         -> we need a scale factor of 5 for comparisson
+      */
+      if (temp >> (5 - temp_e) < FL2FXCONST_DBL (0.49f) >> 5) {
+
         if (workLimiterBandTable[hiLimIndex] == workLimiterBandTable[loLimIndex]) {
           workLimiterBandTable[hiLimIndex] = highSubband;
           nBands--;
diff --git a/libSBRdec/src/env_dec.cpp b/libSBRdec/src/env_dec.cpp
index 24b2d3b..c65c169 100644
--- a/libSBRdec/src/env_dec.cpp
+++ b/libSBRdec/src/env_dec.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
@@ -369,7 +369,7 @@
   FIXP_SGL step;    /* speed of fade */
   int i;
 
-  int currentStartPos = h_prev_data->stopPos - hHeaderData->numberTimeSlots;
+  int currentStartPos = FDKmax(0, h_prev_data->stopPos - hHeaderData->numberTimeSlots);
   int currentStopPos = hHeaderData->numberTimeSlots;
 
 
diff --git a/libSBRdec/src/env_extr.cpp b/libSBRdec/src/env_extr.cpp
index 6cb0b99..dacd951 100644
--- a/libSBRdec/src/env_extr.cpp
+++ b/libSBRdec/src/env_extr.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
@@ -327,7 +327,7 @@
   }
 
   /* Look for new settings. IEC 14496-3, 4.6.18.3.1 */
-  if(hHeaderData->syncState != SBR_ACTIVE ||
+  if(hHeaderData->syncState < SBR_HEADER ||
      lastHeader.startFreq   != pBsData->startFreq   ||
      lastHeader.stopFreq    != pBsData->stopFreq    ||
      lastHeader.freqScale   != pBsData->freqScale   ||
diff --git a/libSBRdec/src/env_extr.h b/libSBRdec/src/env_extr.h
index ab6b704..0518ea9 100644
--- a/libSBRdec/src/env_extr.h
+++ b/libSBRdec/src/env_extr.h
@@ -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
@@ -125,6 +125,7 @@
 typedef enum
 {
   HEADER_NOT_PRESENT,
+  HEADER_ERROR,
   HEADER_OK,
   HEADER_RESET
 }
@@ -132,10 +133,10 @@
 
 typedef enum
 {
-  SBR_NOT_INITIALIZED,
-  UPSAMPLING,
-  SBR_HEADER,
-  SBR_ACTIVE
+  SBR_NOT_INITIALIZED = 0,
+  UPSAMPLING = 1,
+  SBR_HEADER = 2,
+  SBR_ACTIVE = 3
 }
 SBR_SYNC_STATE;
 
@@ -179,6 +180,7 @@
 #define SBRDEC_LOW_POWER      16  /* Flag indicating that Low Power QMF mode shall be used. */
 #define SBRDEC_PS_DECODED     32  /* Flag indicating that PS was decoded and rendered. */
 #define SBRDEC_LD_MPS_QMF    512  /* Flag indicating that the LD-MPS QMF shall be used. */
+#define SBRDEC_SYNTAX_DRM   2048  /* Flag indicating that DRM30/DRM+ reverse syntax is being used. */
 #define SBRDEC_DOWNSAMPLE   8192  /* Flag indicating that the downsampling mode is used. */
 #define SBRDEC_FLUSH       16384  /* Flag is used to flush all elements in use. */
 #define SBRDEC_FORCE_RESET 32768  /* Flag is used to force a reset of all elements in use. */
diff --git a/libSBRdec/src/sbr_dec.cpp b/libSBRdec/src/sbr_dec.cpp
index 1282338..0864348 100644
--- a/libSBRdec/src/sbr_dec.cpp
+++ b/libSBRdec/src/sbr_dec.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
@@ -225,7 +225,14 @@
   }
 
   if (resetAnaQmf) {
-    int qmfErr = qmfInitAnalysisFilterBank (
+    QMF_FILTER_BANK prvAnaQmf;
+    int  qmfErr;
+
+    /* Store current configuration */
+    FDKmemcpy(&prvAnaQmf, &hSbrDec->AnalysiscQMF, sizeof(QMF_FILTER_BANK));
+
+    /* Reset analysis QMF */
+    qmfErr = qmfInitAnalysisFilterBank (
            &hSbrDec->AnalysiscQMF,
             hSbrDec->anaQmfStates,
             hSbrDec->AnalysiscQMF.no_col,
@@ -234,13 +241,22 @@
             hSbrDec->AnalysiscQMF.no_channels,
             anaQmfFlags | QMF_FLAG_KEEP_STATES
             );
+
     if (qmfErr != 0) {
-      FDK_ASSERT(0);
+      /* Restore old configuration of analysis QMF */
+      FDKmemcpy(&hSbrDec->AnalysiscQMF, &prvAnaQmf, sizeof(QMF_FILTER_BANK));
     }
   }
 
   if (resetSynQmf) {
-    int qmfErr = qmfInitSynthesisFilterBank (
+    QMF_FILTER_BANK prvSynQmf;
+    int  qmfErr;
+
+    /* Store current configuration */
+    FDKmemcpy(&prvSynQmf, &hSbrDec->SynthesisQMF, sizeof(QMF_FILTER_BANK));
+
+    /* Reset synthesis QMF */
+    qmfErr = qmfInitSynthesisFilterBank (
            &hSbrDec->SynthesisQMF,
             hSbrDec->pSynQmfStates,
             hSbrDec->SynthesisQMF.no_col,
@@ -251,7 +267,8 @@
             );
 
     if (qmfErr != 0) {
-      FDK_ASSERT(0);
+      /* Restore old configuration of synthesis QMF */
+      FDKmemcpy(&hSbrDec->SynthesisQMF, &prvSynQmf, sizeof(QMF_FILTER_BANK));
     }
   }
 }
@@ -321,7 +338,8 @@
           HANDLE_SBR_PREV_FRAME_DATA hPrevFrameData,  /*!< Some control data of last frame */
           const int applyProcessing,         /*!< Flag for SBR operation */
           HANDLE_PS_DEC h_ps_d,
-          const UINT flags
+          const UINT flags,
+          const int codecFrameSize
          )
 {
   int i, slot, reserve;
@@ -348,6 +366,33 @@
   if (flags & SBRDEC_ELD_GRID) {
     /* Choose the right low delay filter bank */
     changeQmfType( hSbrDec, (flags & SBRDEC_LD_MPS_QMF) ? 1 : 0 );
+
+    /* If the LD-MPS QMF is not available delay the signal by (96-48*ldSbrSamplingRate)
+     * samples according to ISO/IEC 14496-3:2009/FDAM 2:2010(E) chapter 4.5.2.13. */
+    if ( (flags & SBRDEC_LD_MPS_QMF)
+      && (hSbrDec->AnalysiscQMF.flags & QMF_FLAG_CLDFB) )
+    {
+      INT_PCM *pDlyBuf = hSbrDec->coreDelayBuf;  /* DLYBUF */
+      int smpl, delay = 96 >> (!(flags & SBRDEC_DOWNSAMPLE) ? 1 : 0);
+      /* Create TMPBUF */
+      C_AALLOC_SCRATCH_START(pcmTemp, INT_PCM, (96));
+      /* Copy delay samples from INBUF to TMPBUF */
+      for (smpl = 0; smpl < delay; smpl += 1) {
+        pcmTemp[smpl] = timeIn[(codecFrameSize-delay+smpl)*strideIn];
+      }
+      /* Move input signal remainder to the very end of INBUF */
+      for (smpl = (codecFrameSize-delay-1)*strideIn; smpl >= 0; smpl -= strideIn) {
+        timeIn[smpl+delay] = timeIn[smpl];
+      }
+      /* Copy delayed samples from last frame from DLYBUF to the very beginning of INBUF */
+      for (smpl = 0; smpl < delay; smpl += 1) {
+        timeIn[smpl*strideIn] = pDlyBuf[smpl];
+      }
+      /* Copy TMPBUF to DLYBUF */
+      FDKmemcpy(pDlyBuf, pcmTemp, delay*sizeof(INT_PCM));
+      /* Destory TMPBUF */
+      C_AALLOC_SCRATCH_END(pcmTemp, INT_PCM, (96));
+    }
   }
 
   /*
@@ -761,7 +806,7 @@
   {
     int qmfErr;
     /* Adapted QMF analysis post-twiddles for down-sampled HQ SBR */
-    const UINT downSampledFlag = (downsampleFac==2) ? QMF_FLAG_DOWNSAMPLED : 0;
+    const UINT downSampledFlag = (flags & SBRDEC_DOWNSAMPLE) ? QMF_FLAG_DOWNSAMPLED : 0;
 
     qmfErr = qmfInitAnalysisFilterBank (
                     &hs->AnalysiscQMF,
@@ -836,6 +881,9 @@
     }
   }
 
+  /* Clear input delay line */
+  FDKmemclear(hs->coreDelayBuf, (96)*sizeof(INT_PCM));
+
   /* assign qmf time slots */
   assignTimeSlots( &hSbrChannel->SbrDec, hHeaderData->numberTimeSlots * hHeaderData->timeStep, qmfFlags & QMF_FLAG_LP);
 
diff --git a/libSBRdec/src/sbr_dec.h b/libSBRdec/src/sbr_dec.h
index 175e7b2..edde637 100644
--- a/libSBRdec/src/sbr_dec.h
+++ b/libSBRdec/src/sbr_dec.h
@@ -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
@@ -118,6 +118,9 @@
   FIXP_DBL * WorkBuffer1;
   FIXP_DBL * WorkBuffer2;
 
+  /* Delayed time input signal needed to align CLDFD with LD-MPS QMF. */
+  INT_PCM    coreDelayBuf[(96)];
+
   /* QMF filter states */
   FIXP_QAS   anaQmfStates[(320)];
   FIXP_QSS * pSynQmfStates;
@@ -182,7 +185,8 @@
          HANDLE_SBR_PREV_FRAME_DATA hPrevFrameData,  /*!< Some control data of last frame */
          const int applyProcessing,         /*!< Flag for SBR operation */
          HANDLE_PS_DEC h_ps_d,
-         const UINT flags
+         const UINT flags,
+         const int codecFrameSize
         );
 
 
diff --git a/libSBRdec/src/sbr_ram.h b/libSBRdec/src/sbr_ram.h
index f12631d..7ab5044 100644
--- a/libSBRdec/src/sbr_ram.h
+++ b/libSBRdec/src/sbr_ram.h
@@ -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
@@ -135,6 +135,7 @@
   USHORT codecFrameSize;
   UCHAR synDownsampleFac;
   UCHAR numDelayFrames;        /* The current number of additional delay frames used for processing. */
+  UCHAR numFlushedFrames;      /* The variable counts the number of frames which are flushed consecutively. */
 
   UINT flags;
 
diff --git a/libSBRdec/src/sbr_rom.cpp b/libSBRdec/src/sbr_rom.cpp
index e84c3cd..c48ce35 100644
--- a/libSBRdec/src/sbr_rom.cpp
+++ b/libSBRdec/src/sbr_rom.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
@@ -189,6 +189,15 @@
   FL2FXCONST_SGL(3.0f / 4.0f)
 };
 
+/*! Constants for calculating the number of limiter bands */
+const FIXP_DBL FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4_DBL[4] =
+{
+  FL2FXCONST_DBL(1.0f / 4.0f),
+  FL2FXCONST_DBL(1.2f / 4.0f),
+  FL2FXCONST_DBL(2.0f / 4.0f),
+  FL2FXCONST_DBL(3.0f / 4.0f)
+};
+
 /*! Ratio of old gains and noise levels for the first 4 timeslots of an envelope */
 const FIXP_SGL FDK_sbrDecoder_sbr_smoothFilter[4] = {
   FL2FXCONST_SGL(0.66666666666666f),
diff --git a/libSBRdec/src/sbr_rom.h b/libSBRdec/src/sbr_rom.h
index c318870..1f800bc 100644
--- a/libSBRdec/src/sbr_rom.h
+++ b/libSBRdec/src/sbr_rom.h
@@ -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
@@ -124,6 +124,7 @@
 extern const FIXP_SGL FDK_sbrDecoder_sbr_limGains_m[4];
 extern const UCHAR    FDK_sbrDecoder_sbr_limGains_e[4];
 extern const FIXP_SGL FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4[4];
+extern const FIXP_DBL FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4_DBL[4];
 extern const FIXP_SGL FDK_sbrDecoder_sbr_smoothFilter[4];
 extern const FIXP_SGL FDK_sbrDecoder_sbr_randomPhase[SBR_NF_NO_RANDOM_VAL][2];
 extern const FIXP_SGL harmonicPhaseX [2][4];
diff --git a/libSBRdec/src/sbrdecoder.cpp b/libSBRdec/src/sbrdecoder.cpp
index e15145a..f9ded54 100644
--- a/libSBRdec/src/sbrdecoder.cpp
+++ b/libSBRdec/src/sbrdecoder.cpp
@@ -128,6 +128,7 @@
 #include "lpp_tran.h"
 #include "transcendent.h"
 
+#include "FDK_crc.h"
 
 #include "sbrdec_drc.h"
 
@@ -137,7 +138,7 @@
 /* Decoder library info */
 #define SBRDECODER_LIB_VL0 2
 #define SBRDECODER_LIB_VL1 2
-#define SBRDECODER_LIB_VL2 7
+#define SBRDECODER_LIB_VL2 12
 #define SBRDECODER_LIB_TITLE "SBR Decoder"
 #ifdef __ANDROID__
 #define SBRDECODER_LIB_BUILD_DATE ""
@@ -194,6 +195,33 @@
   hDst->freqBandData.freqBandTable[1] = hDst->freqBandData.freqBandTableHi;
 }
 
+static int compareSbrHeader( const HANDLE_SBR_HEADER_DATA hHdr1, const HANDLE_SBR_HEADER_DATA hHdr2 )
+{
+  int result = 0;
+
+  /* compare basic data */
+  result |= (hHdr1->syncState != hHdr2->syncState) ? 1 : 0;
+  result |= (hHdr1->status != hHdr2->status) ? 1 : 0;
+  result |= (hHdr1->frameErrorFlag != hHdr2->frameErrorFlag) ? 1 : 0;
+  result |= (hHdr1->numberTimeSlots != hHdr2->numberTimeSlots) ? 1 : 0;
+  result |= (hHdr1->numberOfAnalysisBands != hHdr2->numberOfAnalysisBands) ? 1 : 0;
+  result |= (hHdr1->timeStep != hHdr2->timeStep) ? 1 : 0;
+  result |= (hHdr1->sbrProcSmplRate != hHdr2->sbrProcSmplRate) ? 1 : 0;
+
+  /* compare bitstream data */
+  result |= FDKmemcmp( &hHdr1->bs_data, &hHdr2->bs_data, sizeof(SBR_HEADER_DATA_BS) );
+  result |= FDKmemcmp( &hHdr1->bs_info, &hHdr2->bs_info, sizeof(SBR_HEADER_DATA_BS_INFO) );
+
+  /* compare frequency band data */
+  result |= FDKmemcmp( &hHdr1->freqBandData, &hHdr2->freqBandData, (8+MAX_NUM_LIMITERS+1)*sizeof(UCHAR) );
+  result |= FDKmemcmp( hHdr1->freqBandData.freqBandTableLo, hHdr2->freqBandData.freqBandTableLo, (MAX_FREQ_COEFFS/2+1)*sizeof(UCHAR) );
+  result |= FDKmemcmp( hHdr1->freqBandData.freqBandTableHi, hHdr2->freqBandData.freqBandTableHi, (MAX_FREQ_COEFFS+1)*sizeof(UCHAR) );
+  result |= FDKmemcmp( hHdr1->freqBandData.freqBandTableNoise, hHdr2->freqBandData.freqBandTableNoise, (MAX_NOISE_COEFFS+1)*sizeof(UCHAR) );
+  result |= FDKmemcmp( hHdr1->freqBandData.v_k_master, hHdr2->freqBandData.v_k_master, (MAX_FREQ_COEFFS+1)*sizeof(UCHAR) );
+
+  return result;
+}
+
 
 /*!
   \brief Reset SBR decoder.
@@ -391,6 +419,7 @@
     case AOT_PS:
     case AOT_ER_AAC_SCAL:
     case AOT_ER_AAC_ELD:
+    case AOT_DRM_AAC:
       return 1;
     default:
       return 0;
@@ -463,6 +492,8 @@
 
   self->flags = 0;
   self->flags |= (coreCodec == AOT_ER_AAC_ELD) ? SBRDEC_ELD_GRID : 0;
+  self->flags |= (coreCodec == AOT_ER_AAC_SCAL) ? SBRDEC_SYNTAX_SCAL : 0;
+  self->flags |= (coreCodec == AOT_DRM_AAC)     ? SBRDEC_SYNTAX_SCAL|SBRDEC_SYNTAX_DRM : 0;
 
   /* Init SBR elements */
   {
@@ -928,24 +959,73 @@
         )
 {
   SBR_DECODER_ELEMENT   *hSbrElement;
-  HANDLE_SBR_HEADER_DATA hSbrHeader;
+  HANDLE_SBR_HEADER_DATA hSbrHeader = NULL;
   HANDLE_SBR_CHANNEL    *pSbrChannel;
 
   SBR_FRAME_DATA *hFrameDataLeft;
   SBR_FRAME_DATA *hFrameDataRight;
 
   SBR_ERROR errorStatus = SBRDEC_OK;
-  SBR_SYNC_STATE initialSyncState;
   SBR_HEADER_STATUS headerStatus = HEADER_NOT_PRESENT;
 
   INT  startPos;
   INT  CRCLen = 0;
+  HANDLE_FDK_BITSTREAM hBsOriginal = hBs;
+  FDK_CRCINFO  crcInfo;         /* shall be used for all other CRCs in the future (TBD) */
+  INT          crcReg = 0;
+  USHORT       drmSbrCrc = 0;
 
   int  stereo;
   int  fDoDecodeSbrData = 1;
 
   int lastSlot, lastHdrSlot = 0, thisHdrSlot;
 
+  /* Reverse bits of DRM SBR payload */
+  if ( (self->flags & SBRDEC_SYNTAX_DRM) && *count > 0 )
+  {
+    UCHAR *bsBufferDrm = (UCHAR*)self->workBuffer1;
+    HANDLE_FDK_BITSTREAM hBsBwd = (HANDLE_FDK_BITSTREAM) (bsBufferDrm + (512));
+    int dataBytes, dataBits;
+
+    dataBits = *count;
+
+    if (dataBits > ((512)*8)) {
+      /* do not flip more data than needed */
+      dataBits = (512)*8;
+    }
+
+    dataBytes = (dataBits+7)>>3;
+
+    int j;
+
+    if ((j = (int)FDKgetValidBits(hBs)) != 8) {
+      FDKpushBiDirectional(hBs, (j-8));
+    }
+
+    j = 0;
+    for ( ; dataBytes > 0; dataBytes--)
+    {
+      int i;
+      UCHAR tmpByte;
+      UCHAR buffer = 0x00;
+
+      tmpByte = (UCHAR) FDKreadBits(hBs, 8);
+      for (i = 0; i < 4; i++) {
+        int shift = 2 * i + 1;
+        buffer |= (tmpByte & (0x08>>i)) << shift;
+        buffer |= (tmpByte & (0x10<<i)) >> shift;
+      }
+      bsBufferDrm[j++] = buffer;
+      FDKpushBack(hBs, 16);
+    }
+
+    FDKinitBitStream(hBsBwd, bsBufferDrm, (512), dataBits, BS_READER);
+
+    /* Use reversed data */
+    hBs = hBsBwd;
+    bsPayLen = *count;
+  }
+
   /* Remember start position of  SBR element */
   startPos = FDKgetValidBits(hBs);
 
@@ -970,7 +1050,6 @@
   hFrameDataLeft  = &self->pSbrElement[elementIndex]->pSbrChannel[0]->frameData[hSbrElement->useFrameSlot];
   hFrameDataRight = &self->pSbrElement[elementIndex]->pSbrChannel[1]->frameData[hSbrElement->useFrameSlot];
 
-  initialSyncState = hSbrHeader->syncState;
 
   /* reset PS flag; will be set after PS was found */
   self->flags &= ~SBRDEC_PS_DECODED;
@@ -1006,12 +1085,19 @@
   */
   if (fDoDecodeSbrData)
   {
-    if (crcFlag == 1) {
+    if (crcFlag) {
       switch (self->coreCodec) {
       case AOT_ER_AAC_ELD:
         FDKpushFor (hBs, 10);
         /* check sbrcrc later: we don't know the payload length now */
         break;
+      case AOT_DRM_AAC:
+        drmSbrCrc = (USHORT)FDKreadBits(hBs, 8);
+        /* Setup CRC decoder */
+        FDKcrcInit(&crcInfo, 0x001d, 0xFFFF, 8);
+        /* Start CRC region */
+        crcReg = FDKcrcStartReg(&crcInfo, hBs, 0);
+        break;
       default:
         CRCLen = bsPayLen - 10;                     /* change: 0 => i */
         if (CRCLen < 0) {
@@ -1056,6 +1142,7 @@
         hSbrHeader->syncState = SBR_HEADER;
       } else {
         hSbrHeader->syncState = SBR_NOT_INITIALIZED;
+        headerStatus = HEADER_ERROR;
       }
     }
 
@@ -1105,7 +1192,7 @@
         valBits = (INT)FDKgetValidBits(hBs);
       }
 
-      if ( crcFlag == 1 ) {
+      if ( crcFlag ) {
         switch (self->coreCodec) {
         case AOT_ER_AAC_ELD:
           {
@@ -1117,6 +1204,14 @@
             FDKpushFor(hBs, crcLen);
           }
           break;
+        case AOT_DRM_AAC:
+          /* End CRC region */
+          FDKcrcEndReg(&crcInfo, hBs, crcReg);
+          /* Check CRC */
+          if ((FDKcrcGetCRC(&crcInfo)^0xFF) != drmSbrCrc) {
+            fDoDecodeSbrData = 0;
+          }
+          break;
         default:
           break;
         }
@@ -1167,8 +1262,25 @@
   }
 
 bail:
-  if (errorStatus == SBRDEC_OK) {
-    if (headerStatus == HEADER_NOT_PRESENT) {
+
+  if ( self->flags & SBRDEC_SYNTAX_DRM )
+  {
+    hBs = hBsOriginal;
+  }
+
+  if ( (errorStatus == SBRDEC_OK)
+    || ( (errorStatus == SBRDEC_PARSE_ERROR)
+      && (headerStatus != HEADER_ERROR) ) )
+  {
+    int useOldHdr = ( (headerStatus == HEADER_NOT_PRESENT)
+                   || (headerStatus == HEADER_ERROR) ) ? 1 : 0;
+
+    if (!useOldHdr && (thisHdrSlot != lastHdrSlot)) {
+      useOldHdr |= ( compareSbrHeader( hSbrHeader,
+                                      &self->sbrHeader[elementIndex][lastHdrSlot] ) == 0 ) ? 1 : 0;
+    }
+
+    if (useOldHdr != 0) {
       /* Use the old header for this frame */
       hSbrElement->useHeaderSlot[hSbrElement->useFrameSlot] = lastHdrSlot;
     } else {
@@ -1229,12 +1341,21 @@
   int  numElementChannels = hSbrElement->nChannels; /* Number of channels of the current SBR element */
 
   if (self->flags & SBRDEC_FLUSH) {
-    /* Move frame pointer to the next slot which is up to be decoded/applied next */
-    hSbrElement->useFrameSlot = (hSbrElement->useFrameSlot+1) % (self->numDelayFrames+1);
-    /* Update header and frame data pointer because they have already been set */
-    hSbrHeader = &self->sbrHeader[elementIndex][hSbrElement->useHeaderSlot[hSbrElement->useFrameSlot]];
-    hFrameDataLeft  = &hSbrElement->pSbrChannel[0]->frameData[hSbrElement->useFrameSlot];
-    hFrameDataRight = &hSbrElement->pSbrChannel[1]->frameData[hSbrElement->useFrameSlot];
+    if ( self->numFlushedFrames > self->numDelayFrames ) {
+      int hdrIdx;
+      /* No valid SBR payload available, hence switch to upsampling (in all headers) */
+      for (hdrIdx = 0; hdrIdx < ((1)+1); hdrIdx += 1) {
+        self->sbrHeader[elementIndex][hdrIdx].syncState = UPSAMPLING;
+      }
+    }
+    else {
+      /* Move frame pointer to the next slot which is up to be decoded/applied next */
+      hSbrElement->useFrameSlot = (hSbrElement->useFrameSlot+1) % (self->numDelayFrames+1);
+      /* Update header and frame data pointer because they have already been set */
+      hSbrHeader = &self->sbrHeader[elementIndex][hSbrElement->useHeaderSlot[hSbrElement->useFrameSlot]];
+      hFrameDataLeft  = &hSbrElement->pSbrChannel[0]->frameData[hSbrElement->useFrameSlot];
+      hFrameDataRight = &hSbrElement->pSbrChannel[1]->frameData[hSbrElement->useFrameSlot];
+    }
   }
 
   /* Update the header error flag */
@@ -1354,7 +1475,8 @@
            &pSbrChannel[0]->prevFrameData,
             (hSbrHeader->syncState == SBR_ACTIVE),
             h_ps_d,
-            self->flags
+            self->flags,
+            codecFrameSize
           );
 
   if (stereo) {
@@ -1371,7 +1493,8 @@
              &pSbrChannel[1]->prevFrameData,
               (hSbrHeader->syncState == SBR_ACTIVE),
               NULL,
-              self->flags
+              self->flags,
+              codecFrameSize
             );
   }
 
@@ -1387,20 +1510,21 @@
     if ( !(self->flags & SBRDEC_PS_DECODED) ) {
       /* A decoder which is able to decode PS has to produce a stereo output even if no PS data is availble. */
       /* So copy left channel to right channel.                                                              */
+      int copyFrameSize = codecFrameSize * 2 / self->synDownsampleFac;
       if (interleaved) {
         INT_PCM *ptr;
         INT i;
         FDK_ASSERT(strideOut == 2);
 
         ptr = timeData;
-        for (i = codecFrameSize; i--; ) 
+        for (i = copyFrameSize>>1; i--; )
         {
           INT_PCM tmp; /* This temporal variable is required because some compilers can't do *ptr++ = *ptr++ correctly. */
           tmp = *ptr++; *ptr++ = tmp;
           tmp = *ptr++; *ptr++ = tmp;
         }
       } else {
-        FDKmemcpy( timeData+2*codecFrameSize, timeData, 2*codecFrameSize*sizeof(INT_PCM) );
+        FDKmemcpy( timeData+copyFrameSize, timeData, copyFrameSize*sizeof(INT_PCM) );
       }
     }
     *numOutChannels = 2;  /* Output minimum two channels when PS is enabled. */
@@ -1464,14 +1588,23 @@
     self->flags &= ~SBRDEC_PS_DECODED;
   }
 
+  if ( self->flags & SBRDEC_FLUSH ) {
+    /* flushing is signalized, hence increment the flush frame counter */
+    self->numFlushedFrames++;
+  }
+  else {
+    /* no flushing is signalized, hence reset the flush frame counter */
+    self->numFlushedFrames = 0;
+  }
+
   /* Loop over SBR elements */
   for (sbrElementNum = 0; sbrElementNum<self->numSbrElements; sbrElementNum++)
   {
     int numElementChan;
 
     if (psPossible && self->pSbrElement[sbrElementNum]->pSbrChannel[1] == NULL) {
-      errorStatus = SBRDEC_UNSUPPORTED_CONFIG;
-      goto bail;
+      /* Disable PS and try decoding SBR mono. */
+      psPossible = 0;
     }
 
     numElementChan = (self->pSbrElement[sbrElementNum]->elementID == ID_CPE) ? 2 : 1;
@@ -1579,6 +1712,7 @@
     | CAPF_SBR_HQ
     | CAPF_SBR_LP
     | CAPF_SBR_PS_MPEG
+    | CAPF_SBR_DRM_BS
     | CAPF_SBR_CONCEALMENT
     | CAPF_SBR_DRC
       ;
@@ -1607,6 +1741,9 @@
         /* Low delay SBR: */
         {
           outputDelay += (flags & SBRDEC_DOWNSAMPLE) ? 32 : 64;   /* QMF synthesis */
+          if (flags & SBRDEC_LD_MPS_QMF) {
+            outputDelay += 32;
+          }
         }
       }
       else if (!IS_USAC(self->coreCodec)) {
diff --git a/libSBRenc/include/sbr_encoder.h b/libSBRenc/include/sbr_encoder.h
index 93dc46d..aec0398 100644
--- a/libSBRenc/include/sbr_encoder.h
+++ b/libSBRenc/include/sbr_encoder.h
@@ -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
@@ -135,6 +135,12 @@
   SBR_SYNTAX_DRM_CRC   = 0x0008
 };
 
+typedef enum
+{
+  FREQ_RES_LOW = 0,
+  FREQ_RES_HIGH
+} FREQ_RES;
+
 typedef struct
 {
   CODEC_TYPE       coreCoder;        /*!< LC or ELD */
@@ -168,8 +174,9 @@
   INT dynBwSupported;         /*!< Flag: support for dynamic bandwidth in this combination. */
   INT parametricCoding;       /*!< Flag: usage of parametric coding tool. */
   INT downSampleFactor;       /*!< Sampling rate relation between the SBR and the core encoder. */
-  int freq_res_fixfix[3];     /*!< Frequency resolution of envelopes in frame class FIXFIX
-                                 0=1 Env; 1=2 Env; 2=4 Env; */
+  FREQ_RES freq_res_fixfix[2];/*!< Frequency resolution of envelopes in frame class FIXFIX, for non-split case and split case */
+  UCHAR fResTransIsLow;       /*!< Frequency resolution of envelopes in transient frames: low (0) or variable (1) */
+
   /*
      core coder dependent tuning parameters
   */
@@ -221,6 +228,8 @@
   INT sbr_interpol_freq;      /*!< Flag: use interpolation in freq. direction. */
   INT sbr_smoothing_length;   /*!< Flag: choose length 4 or 0 (=on, off). */
   UCHAR init_amp_res_FF;
+  FIXP_DBL threshold_AmpRes_FF_m;
+  SCHAR threshold_AmpRes_FF_e;
 } sbrConfiguration, *sbrConfigurationPtr ;
 
 typedef struct SBR_CONFIG_DATA
@@ -237,7 +246,7 @@
   INT noQmfBands;                       /**< Number of QMF frequency bands. */
   INT noQmfSlots;                       /**< Number of QMF slots. */
 
-  UCHAR *freqBandTable[2];              /**< Frequency table for low and hires, only MAX_FREQ_COEFFS/2 +1 coeefs actually needed for lowres. */
+  UCHAR *freqBandTable[2];              /**< Frequency table for low and hires, only MAX_FREQ_COEFFS/2 +1 coeffs actually needed for lowres. */
   UCHAR *v_k_master;                    /**< Master BandTable where freqBandTable is derived from. */
 
 
@@ -249,6 +258,8 @@
   INT xposCtrlSwitch;                   /**< Flag indicates whether to switch xpos ctrl on the fly. */
   INT switchTransposers;                /**< Flag indicates whether to switch xpos on the fly .     */
   UCHAR initAmpResFF;
+  FIXP_DBL thresholdAmpResFF_m;
+  SCHAR thresholdAmpResFF_e;
 } SBR_CONFIG_DATA, *HANDLE_SBR_CONFIG_DATA;
 
 typedef struct {
diff --git a/libSBRenc/src/bit_sbr.h b/libSBRenc/src/bit_sbr.h
index 1ce2c1e..de4ac89 100644
--- a/libSBRenc/src/bit_sbr.h
+++ b/libSBRenc/src/bit_sbr.h
@@ -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
@@ -141,8 +141,8 @@
 {
 
   INT sbr_xpos_ctrl;
-  INT freq_res_fixfix;
-
+  FREQ_RES freq_res_fixfix[2];
+  UCHAR fResTransIsLow;
 
   INVF_MODE sbr_invf_mode;
   INVF_MODE sbr_invf_mode_vec[MAX_NUM_NOISE_VALUES];
@@ -205,6 +205,8 @@
   INT balance;
   AMP_RES init_sbr_amp_res;
   AMP_RES currentAmpResFF;
+  FIXP_DBL ton_HF[SBR_GLOBAL_TONALITY_VALUES]; /* tonality is scaled by 2^19/0.524288f (fract part of RELAXATION) */
+  FIXP_DBL global_tonality;
 
   /* extended data */
   INT extended_data;
diff --git a/libSBRenc/src/env_est.cpp b/libSBRenc/src/env_est.cpp
index 929f229..4fcda51 100644
--- a/libSBRenc/src/env_est.cpp
+++ b/libSBRenc/src/env_est.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
@@ -103,6 +103,114 @@
 static const UCHAR maxIndex[2] = {9, 5};
 
 
+/******************************************************************************
+ Functionname:  FDKsbrEnc_GetTonality
+******************************************************************************/
+/***************************************************************************/
+/*!
+
+  \brief      Calculates complete energy per band from the energy values
+              of the QMF subsamples.
+
+  \brief      quotaMatrix - calculated in FDKsbrEnc_CalculateTonalityQuotas()
+  \brief      noEstPerFrame - number of estimations per frame
+  \brief      startIndex - start index for the quota matrix
+  \brief      Energies - energy matrix
+  \brief      startBand - start band
+  \brief      stopBand - number of QMF bands
+  \brief      numberCols - number of QMF subsamples
+
+  \return     mean tonality of the 5 bands with the highest energy
+              scaled by 2^(RELAXATION_SHIFT+2)*RELAXATION_FRACT
+
+****************************************************************************/
+static FIXP_DBL FDKsbrEnc_GetTonality(
+        const FIXP_DBL *const *quotaMatrix,
+        const INT              noEstPerFrame,
+        const INT              startIndex,
+        const FIXP_DBL *const *Energies,
+        const UCHAR            startBand,
+        const INT              stopBand,
+        const INT              numberCols
+        )
+{
+  UCHAR b, e, k;
+  INT      no_enMaxBand[SBR_MAX_ENERGY_VALUES] = { -1, -1, -1, -1, -1 };
+  FIXP_DBL energyMax[SBR_MAX_ENERGY_VALUES] = { FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f) };
+  FIXP_DBL energyMaxMin = MAXVAL_DBL; /* min. energy in energyMax array */
+  UCHAR    posEnergyMaxMin = 0;       /* min. energy in energyMax array position */
+  FIXP_DBL tonalityBand[SBR_MAX_ENERGY_VALUES] = { FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f) };
+  FIXP_DBL globalTonality = FL2FXCONST_DBL(0.0f);
+  FIXP_DBL energyBand[QMF_CHANNELS];
+  INT      maxNEnergyValues; /* max. number of max. energy values */
+
+  /*** Sum up energies for each band ***/
+  FDK_ASSERT(numberCols==15||numberCols==16);
+  /* numberCols is always 15 or 16 for ELD. In case of 16 bands, the
+      energyBands are initialized with the [15]th column.
+      The rest of the column energies are added in the next step.   */
+  if (numberCols==15) {
+    for (b=startBand; b<stopBand; b++) {
+      energyBand[b]=FL2FXCONST_DBL(0.0f);
+    }
+  } else {
+    for (b=startBand; b<stopBand; b++) {
+      energyBand[b]=Energies[15][b]>>4;
+    }
+  }
+
+  for (k=0; k<15; k++) {
+    for (b=startBand; b<stopBand; b++) {
+      energyBand[b] += Energies[k][b]>>4;
+    }
+  }
+
+  /*** Determine 5 highest band-energies ***/
+  maxNEnergyValues = fMin(SBR_MAX_ENERGY_VALUES, stopBand-startBand);
+
+  /* Get min. value in energyMax array */
+  energyMaxMin = energyMax[0] = energyBand[startBand];
+  no_enMaxBand[0] = startBand;
+  posEnergyMaxMin = 0;
+  for (k=1; k<maxNEnergyValues; k++) {
+    energyMax[k] = energyBand[startBand+k];
+    no_enMaxBand[k] = startBand+k;
+    if (energyMaxMin > energyMax[k]) {
+      energyMaxMin = energyMax[k];
+      posEnergyMaxMin = k;
+    }
+  }
+
+  for (b=startBand+maxNEnergyValues; b<stopBand; b++) {
+    if (energyBand[b] > energyMaxMin) {
+      energyMax[posEnergyMaxMin] = energyBand[b];
+      no_enMaxBand[posEnergyMaxMin] = b;
+
+      /* Again, get min. value in energyMax array */
+      energyMaxMin = energyMax[0];
+      posEnergyMaxMin = 0;
+      for (k=1; k<maxNEnergyValues; k++) {
+        if (energyMaxMin > energyMax[k]) {
+          energyMaxMin = energyMax[k];
+          posEnergyMaxMin = k;
+        }
+      }
+    }
+  }
+  /*** End determine 5 highest band-energies ***/
+
+  /* Get tonality values for 5 highest energies */
+  for (e=0; e<maxNEnergyValues; e++) {
+    tonalityBand[e]=FL2FXCONST_DBL(0.0f);
+    for (k=0; k<noEstPerFrame; k++) {
+      tonalityBand[e] += quotaMatrix[startIndex + k][no_enMaxBand[e]] >> 1;
+    }
+    globalTonality += tonalityBand[e] >> 2; /* headroom of 2+1 (max. 5 additions) */
+  }
+
+  return globalTonality;
+}
+
 /***************************************************************************/
 /*!
 
@@ -919,10 +1027,42 @@
                                      hEnvChan->qmfScale);
 
 
+  if(h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+    FIXP_DBL tonality = FDKsbrEnc_GetTonality (
+          hEnvChan->TonCorr.quotaMatrix,
+          hEnvChan->TonCorr.numberOfEstimatesPerFrame,
+          hEnvChan->TonCorr.startIndexMatrix,
+          sbrExtrEnv->YBuffer + sbrExtrEnv->YBufferWriteOffset,
+          h_con->freqBandTable[HI][0]+1,
+          h_con->noQmfBands,
+          sbrExtrEnv->no_cols
+        );
+
+    hEnvChan->encEnvData.ton_HF[1] = hEnvChan->encEnvData.ton_HF[0];
+    hEnvChan->encEnvData.ton_HF[0] = tonality;
+
+    /* tonality is scaled by 2^19/0.524288f (fract part of RELAXATION) */
+    hEnvChan->encEnvData.global_tonality = (hEnvChan->encEnvData.ton_HF[0]>>1) + (hEnvChan->encEnvData.ton_HF[1]>>1);
+  }
+
+
 
   /*
     Transient detection COEFF Transform OK
   */
+  if(h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY)
+  {
+    FDKsbrEnc_fastTransientDetect(
+            &hEnvChan->sbrFastTransientDetector,
+             sbrExtrEnv->YBuffer,
+             sbrExtrEnv->YBufferScale,
+             sbrExtrEnv->YBufferWriteOffset,
+             eData->transient_info
+             );
+
+  }
+  else
+  {
   FDKsbrEnc_transientDetect(&hEnvChan->sbrTransientDetector,
                              sbrExtrEnv->YBuffer,
                              sbrExtrEnv->YBufferScale,
@@ -931,6 +1071,7 @@
                              sbrExtrEnv->YBufferSzShift,
                              sbrExtrEnv->time_step,
                              hEnvChan->SbrEnvFrame.frameMiddleSlot);
+  }
 
 
 
@@ -951,7 +1092,8 @@
                           sbrExtrEnv->YBufferSzShift,
                           h_con->nSfb[1],
                           sbrExtrEnv->time_step,
-                          sbrExtrEnv->no_cols);
+                          sbrExtrEnv->no_cols,
+                         &hEnvChan->encEnvData.global_tonality);
 
 
 }
@@ -1128,12 +1270,26 @@
         && ( ed->nEnvelopes == 1 ) )
    {
 
-     if (hEnvChan->encEnvData.ldGrid)
-       hEnvChan->encEnvData.currentAmpResFF = (AMP_RES)h_con->initAmpResFF;
-     else
+     if (h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY)
+     {
+       /* Note: global_tonaliy_float_value == ((float)hEnvChan->encEnvData.global_tonality/((INT64)(1)<<(31-(19+2)))/0.524288*(2.0/3.0)));
+                threshold_float_value == ((float)h_con->thresholdAmpResFF_m/((INT64)(1)<<(31-(h_con->thresholdAmpResFF_e)))/0.524288*(2.0/3.0))); */
+       /* decision of SBR_AMP_RES */
+       if (fIsLessThan( /* global_tonality > threshold ? */
+             h_con->thresholdAmpResFF_m, h_con->thresholdAmpResFF_e,
+             hEnvChan->encEnvData.global_tonality, RELAXATION_SHIFT+2 )
+          )
+       {
+         hEnvChan->encEnvData.currentAmpResFF = SBR_AMP_RES_1_5;
+       }
+       else {
+         hEnvChan->encEnvData.currentAmpResFF = SBR_AMP_RES_3_0;
+       }
+     } else {
        hEnvChan->encEnvData.currentAmpResFF = SBR_AMP_RES_1_5;
+     }
 
-     if ( hEnvChan->encEnvData.currentAmpResFF != hEnvChan->encEnvData.init_sbr_amp_res) {
+      if ( hEnvChan->encEnvData.currentAmpResFF != hEnvChan->encEnvData.init_sbr_amp_res) {
 
         FDKsbrEnc_InitSbrHuffmanTables(&hEnvChan->encEnvData,
                                        &hEnvChan->sbrCodeEnvelope,
@@ -1172,7 +1328,12 @@
     }
 
     /* Low energy in low band fix */
-    if ( hEnvChan->sbrTransientDetector.prevLowBandEnergy < hEnvChan->sbrTransientDetector.prevHighBandEnergy && hEnvChan->sbrTransientDetector.prevHighBandEnergy > FL2FX_DBL(0.03))
+    if ( hEnvChan->sbrTransientDetector.prevLowBandEnergy < hEnvChan->sbrTransientDetector.prevHighBandEnergy
+      && hEnvChan->sbrTransientDetector.prevHighBandEnergy > FL2FX_DBL(0.03)
+      /* The fix needs the non-fast transient detector running.
+         It sets prevLowBandEnergy and prevHighBandEnergy.      */
+      && !(h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY)
+      )
     {
       int i;
 
diff --git a/libSBRenc/src/env_est.h b/libSBRenc/src/env_est.h
index 5e632a4..e17a974 100644
--- a/libSBRenc/src/env_est.h
+++ b/libSBRenc/src/env_est.h
@@ -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
@@ -127,6 +127,7 @@
 
 struct ENV_CHANNEL
 {
+  FAST_TRAN_DETECTOR sbrFastTransientDetector;
   SBR_TRANSIENT_DETECTOR sbrTransientDetector;
   SBR_CODE_ENVELOPE sbrCodeEnvelope;
   SBR_CODE_ENVELOPE sbrCodeNoiseFloor;
diff --git a/libSBRenc/src/fram_gen.cpp b/libSBRenc/src/fram_gen.cpp
index 86c3c81..9a35111 100644
--- a/libSBRenc/src/fram_gen.cpp
+++ b/libSBRenc/src/fram_gen.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
@@ -266,7 +266,7 @@
 
 static void ctrlSignal2FrameInfo (HANDLE_SBR_GRID hSbrGrid,
                                   HANDLE_SBR_FRAME_INFO hFrameInfo,
-                                  INT freq_res_fixfix);
+                                  FREQ_RES *freq_res_fixfix);
 
 
 /* table for 8 time slot index */
@@ -341,8 +341,9 @@
 static void generateFixFixOnly ( HANDLE_SBR_FRAME_INFO hSbrFrameInfo,
                                  HANDLE_SBR_GRID hSbrGrid,
                                  int tranPosInternal,
-                                 int numberTimeSlots
-                               );
+                                 int numberTimeSlots,
+                                 UCHAR fResTransIsLow
+                                 );
 
 
 /*!
@@ -402,11 +403,10 @@
   const int *v_tuningFreq = v_tuning + 3;
 
   hSbrEnvFrame->v_tuningSegm = v_tuningSegm;
-  INT freq_res_fixfix = hSbrEnvFrame->freq_res_fixfix;
 
   if (ldGrid) {
     /* in case there was a transient at the very end of the previous frame, start with a transient envelope */
-    if(v_transient_info_pre[1] && (numberTimeSlots - v_transient_info_pre[0] < minFrameTranDistance)){
+    if ( !tranFlag && v_transient_info_pre[1] && (numberTimeSlots - v_transient_info_pre[0] < minFrameTranDistance) ){
       tranFlag = 1;
       tranPos  = 0;
     }
@@ -529,7 +529,8 @@
       generateFixFixOnly ( &(hSbrEnvFrame->SbrFrameInfo),
                            &(hSbrEnvFrame->SbrGrid),
                            tranPosInternal,
-                           numberTimeSlots
+                           numberTimeSlots,
+                           hSbrEnvFrame->fResTransIsLow
                            );
 
       return &(hSbrEnvFrame->SbrFrameInfo);
@@ -677,7 +678,7 @@
   ---------------------------------------------------------------------------*/
   ctrlSignal2FrameInfo (&hSbrEnvFrame->SbrGrid,
                         &hSbrEnvFrame->SbrFrameInfo,
-                        freq_res_fixfix);
+                         hSbrEnvFrame->freq_res_fixfix);
 
   return &hSbrEnvFrame->SbrFrameInfo;
 }
@@ -692,7 +693,8 @@
 static void generateFixFixOnly ( HANDLE_SBR_FRAME_INFO hSbrFrameInfo,
                                  HANDLE_SBR_GRID hSbrGrid,
                                  int tranPosInternal,
-                                 int numberTimeSlots
+                                 int numberTimeSlots,
+                                 UCHAR fResTransIsLow
                                )
 {
   int nEnv, i, k=0, tranIdx;
@@ -727,8 +729,12 @@
   /* adjust segment-frequency-resolution according to the segment-length */
   for (i=0; i<nEnv; i++){
     k = hSbrFrameInfo->borders[i+1] - hSbrFrameInfo->borders[i];
-    hSbrFrameInfo->freqRes[i] = freqResTable[k];
-    hSbrGrid->v_f[i] = freqResTable[k];
+    if (!fResTransIsLow)
+      hSbrFrameInfo->freqRes[i] = freqResTable[k];
+    else
+      hSbrFrameInfo->freqRes[i] = FREQ_RES_LOW;
+
+    hSbrGrid->v_f[i] = hSbrFrameInfo->freqRes[i];
   }
 
   hSbrFrameInfo->nEnvelopes = nEnv;
@@ -765,15 +771,16 @@
 
 *******************************************************************************/
 void
-FDKsbrEnc_initFrameInfoGenerator (HANDLE_SBR_ENVELOPE_FRAME  hSbrEnvFrame,
-                          INT allowSpread,
-                          INT numEnvStatic,
-                          INT staticFraming,
-                          INT timeSlots,
-                          INT freq_res_fixfix
-                          ,int ldGrid
-                          )
-
+FDKsbrEnc_initFrameInfoGenerator (
+              HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame,
+              INT       allowSpread,
+              INT       numEnvStatic,
+              INT       staticFraming,
+              INT       timeSlots,
+        const FREQ_RES* freq_res_fixfix
+             ,UCHAR     fResTransIsLow,
+              INT       ldGrid
+        )
 {                               /* FH 00-06-26 */
 
   FDKmemclear(hSbrEnvFrame,sizeof(SBR_ENVELOPE_FRAME ));
@@ -786,7 +793,9 @@
   hSbrEnvFrame->allowSpread = allowSpread;
   hSbrEnvFrame->numEnvStatic = numEnvStatic;
   hSbrEnvFrame->staticFraming = staticFraming;
-  hSbrEnvFrame->freq_res_fixfix = freq_res_fixfix;
+  hSbrEnvFrame->freq_res_fixfix[0] = freq_res_fixfix[0];
+  hSbrEnvFrame->freq_res_fixfix[1] = freq_res_fixfix[1];
+  hSbrEnvFrame->fResTransIsLow     = fResTransIsLow;
 
   hSbrEnvFrame->length_v_bord = 0;
   hSbrEnvFrame->length_v_bordFollow = 0;
@@ -804,6 +813,7 @@
       hSbrEnvFrame->dmin = 2;
       hSbrEnvFrame->dmax = 16;
       hSbrEnvFrame->frameMiddleSlot = FRAME_MIDDLE_SLOT_512LD;
+      hSbrEnvFrame->SbrGrid.bufferFrameStart = 0;
   } else
   switch(timeSlots){
     case NUMBER_TIME_SLOTS_1920:
@@ -1862,19 +1872,28 @@
  Functionname:  ctrlSignal2FrameInfo
  *******************************************************************************
 
- Description: Calculates frame_info struct from control signal.
+ Description: Convert "clear-text" sbr_grid() to "frame info" used by the
+              envelope and noise floor estimators.
+              This is basically (except for "low level" calculations) the
+              bitstream decoder defined in the MPEG-4 standard, sub clause
+              4.6.18.3.3, Time / Frequency Grid.  See inline comments for
+              explanation of the shorten and noise border algorithms.
 
  Arguments:   hSbrGrid - source
               hSbrFrameInfo - destination
+              freq_res_fixfix - frequency resolution for FIXFIX frames
 
  Return:      void; hSbrFrameInfo contains the updated FRAME_INFO struct
 
 *******************************************************************************/
 static void
-ctrlSignal2FrameInfo (HANDLE_SBR_GRID hSbrGrid,
-                      HANDLE_SBR_FRAME_INFO hSbrFrameInfo,
-                      INT freq_res_fixfix)
+ctrlSignal2FrameInfo (
+        HANDLE_SBR_GRID        hSbrGrid,       /* input : the grid handle       */
+        HANDLE_SBR_FRAME_INFO  hSbrFrameInfo,  /* output: the frame info handle */
+        FREQ_RES              *freq_res_fixfix /* in/out: frequency resolution for FIXFIX frames */
+        )
 {
+  INT frameSplit = 0;
   INT nEnv = 0, border = 0, i, k, p /*?*/;
   INT *v_r = hSbrGrid->bs_rel_bord;
   INT *v_f = hSbrGrid->v_f;
@@ -1887,17 +1906,10 @@
   case FIXFIX:
     createDefFrameInfo(hSbrFrameInfo, hSbrGrid->bs_num_env, numberTimeSlots);
 
-    /* At this point all frequency resolutions are set to FREQ_RES_HIGH, so
-     * only if freq_res_fixfix is set to FREQ_RES_LOW, they all have to be
-     * changed.
-     * snd */
-    if (freq_res_fixfix == FREQ_RES_LOW) {
-      for (i = 0; i < hSbrFrameInfo->nEnvelopes; i++) {
-        hSbrFrameInfo->freqRes[i] = FREQ_RES_LOW;
-      }
+    frameSplit = (hSbrFrameInfo->nEnvelopes > 1);
+    for (i = 0; i < hSbrFrameInfo->nEnvelopes; i++) {
+      hSbrGrid->v_f[i] = hSbrFrameInfo->freqRes[i] = freq_res_fixfix[frameSplit];
     }
-    /* ELD: store current frequency resolution */
-    hSbrGrid->v_f[0] = hSbrFrameInfo->freqRes[0];
     break;
 
   case FIXVAR:
diff --git a/libSBRenc/src/fram_gen.h b/libSBRenc/src/fram_gen.h
index 3769266..00473d4 100644
--- a/libSBRenc/src/fram_gen.h
+++ b/libSBRenc/src/fram_gen.h
@@ -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
@@ -89,6 +89,7 @@
 #define _FRAM_GEN_H
 
 #include "sbr_def.h" /* for MAX_ENVELOPES and MAX_NOISE_ENVELOPES in struct FRAME_INFO and CODEC_TYPE */
+#include "sbr_encoder.h" /* for FREQ_RES */
 
 #define MAX_ENVELOPES_VARVAR MAX_ENVELOPES /*!< worst case number of envelopes in a VARVAR frame */
 #define MAX_ENVELOPES_FIXVAR_VARFIX 4 /*!< worst case number of envelopes in VARFIX and FIXVAR frames */
@@ -114,7 +115,7 @@
 #define NUMBER_TIME_SLOTS_1920  15
 
 #define LD_PRETRAN_OFF           3
-#define FRAME_MIDDLE_SLOT_512LD  0
+#define FRAME_MIDDLE_SLOT_512LD  4
 #define NUMBER_TIME_SLOTS_512LD  8
 #define TRANSIENT_OFFSET_LD      0
 
@@ -248,9 +249,10 @@
   INT frameMiddleSlot;      /*!< transient detector offset in SBR timeslots */
 
   /* basic tuning parameters */
-  INT staticFraming;        /*!< 1: run static framing in time, i.e. exclusive use of bs_frame_class = FIXFIX */
-  INT numEnvStatic;         /*!< number of envelopes per frame for static framing */
-  INT freq_res_fixfix;      /*!< envelope frequency resolution to use for bs_frame_class = FIXFIX */
+  INT staticFraming;           /*!< 1: run static framing in time, i.e. exclusive use of bs_frame_class = FIXFIX */
+  INT numEnvStatic;            /*!< number of envelopes per frame for static framing */
+  FREQ_RES freq_res_fixfix[2]; /*!< envelope frequency resolution to use for bs_frame_class = FIXFIX; single env and split */
+  UCHAR fResTransIsLow;        /*!< frequency resolution for transient frames - always low (0) or according to table (1) */
 
   /* expert tuning parameters */
   const int *v_tuningSegm;  /*!< segment lengths to use around transient */
@@ -286,14 +288,16 @@
 
 
 void
-FDKsbrEnc_initFrameInfoGenerator (HANDLE_SBR_ENVELOPE_FRAME  hSbrEnvFrame,
-                          INT allowSpread,
-                          INT numEnvStatic,
-                          INT staticFraming,
-                          INT timeSlots,
-                          INT freq_res_fixfix
-                          ,int ldGrid
-                          );
+FDKsbrEnc_initFrameInfoGenerator (
+              HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame,
+              INT       allowSpread,
+              INT       numEnvStatic,
+              INT       staticFraming,
+              INT       timeSlots,
+        const FREQ_RES* freq_res_fixfix
+             ,UCHAR     fResTransIsLow,
+              INT       ldGrid
+        );
 
 HANDLE_SBR_FRAME_INFO
 FDKsbrEnc_frameInfoGenerator (HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame,
diff --git a/libSBRenc/src/mh_det.cpp b/libSBRenc/src/mh_det.cpp
index 73d1b8b..bc80a15 100644
--- a/libSBRenc/src/mh_det.cpp
+++ b/libSBRenc/src/mh_det.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
@@ -663,10 +663,27 @@
 }
 
 
-/**************************************************************************/
+/*****************************************************************************/
 /*!
-  \brief     Do detection for one tonality estimate.
+  \brief     Detection for one tonality estimate.
 
+  This is the actual missing harmonics detection, using information from the
+  previous detection.
+
+  If a missing harmonic was detected (in a previous frame) due to too high
+  tonality differences, but there was not enough tonality difference in the
+  current frame, the detection algorithm still continues to trace the strongest
+  tone in the scalefactor band (assuming that this is the tone that is going to
+  be replaced in the decoder). This is done to avoid abrupt endings of sines
+  fading out (e.g. in the glockenspiel).
+
+  The function also tries to estimate where one sine is going to be replaced
+  with multiple sines (due to the patching). This is done by comparing the
+  tonality flatness measure of the original and the SBR signal.
+
+  The function also tries to estimate (for the scalefactor bands only
+  containing one qmf subband) when a strong tone in the original will be
+  replaced by a strong tone in the adjacent QMF subband.
 
   \return    none.
 
@@ -694,10 +711,10 @@
   for(i=0;i<nSfb;i++){
 
     thresTemp = (guideVectors.guideVectorDiff[i] != FL2FXCONST_DBL(0.0f))
-                  ? fixMax(fMult(mhThresh.decayGuideDiff,guideVectors.guideVectorDiff[i]), mhThresh.thresHoldDiffGuide)
+                  ? fMax(fMult(mhThresh.decayGuideDiff,guideVectors.guideVectorDiff[i]), mhThresh.thresHoldDiffGuide)
                   : mhThresh.thresHoldDiff;
 
-    thresTemp = fixMin(thresTemp, mhThresh.thresHoldDiff);
+    thresTemp = fMin(thresTemp, mhThresh.thresHoldDiff);
 
     if(pDiffVecScfb[i] > thresTemp){
       pHarmVec[i] = 1;
@@ -813,8 +830,11 @@
 
   if(newDetectionAllowed){
 
+    /* Since we don't want to use the transient region for detection (since the tonality values
+       tend to be a bit unreliable for this region) the guide-values are copied to the current
+       starting point. */
     if(totNoEst > 1){
-      start = detectionStart;
+      start = detectionStart+1;
 
       if (start != 0) {
         FDKmemcpy(guideVectors[start].guideVectorDiff,guideVectors[0].guideVectorDiff,nSfb*sizeof(FIXP_DBL));
diff --git a/libSBRenc/src/nf_est.cpp b/libSBRenc/src/nf_est.cpp
index 385a043..a4c5574 100644
--- a/libSBRenc/src/nf_est.cpp
+++ b/libSBRenc/src/nf_est.cpp
@@ -298,7 +298,7 @@
                          SCHAR    *indexVector,              /*!< Index vector to obtain the patched data. */
                          INT missingHarmonicsFlag,           /*!< Flag indicating if a strong tonal component will be missing. */
                          INT startIndex,                     /*!< Start index. */
-                         int numberOfEstimatesPerFrame,      /*!< The number of tonality estimates per frame. */
+                         UINT numberOfEstimatesPerFrame,     /*!< The number of tonality estimates per frame. */
                          int transientFrame,                 /*!< A flag indicating if a transient is present. */
                          INVF_MODE* pInvFiltLevels,          /*!< Pointer to the vector holding the inverse filtering levels. */
                          UINT sbrSyntaxFlags
diff --git a/libSBRenc/src/nf_est.h b/libSBRenc/src/nf_est.h
index d407274..f26f74f 100644
--- a/libSBRenc/src/nf_est.h
+++ b/libSBRenc/src/nf_est.h
@@ -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
@@ -119,7 +119,7 @@
                          SCHAR* indexVector,                 /*!< Index vector to obtain the patched data. */
                          INT missingHarmonicsFlag,           /*!< Flag indicating if a strong tonal component will be missing. */
                          INT startIndex,                     /*!< Start index. */
-                         int numberOfEstimatesPerFrame,      /*!< The number of tonality estimates per frame. */
+                         UINT numberOfEstimatesPerFrame,     /*!< The number of tonality estimates per frame. */
                          INT transientFrame,                 /*!< A flag indicating if a transient is present. */
                          INVF_MODE* pInvFiltLevels,          /*!< Pointer to the vector holding the inverse filtering levels. */
                          UINT sbrSyntaxFlags
diff --git a/libSBRenc/src/sbr_def.h b/libSBRenc/src/sbr_def.h
index 8b7cfc6..85ac587 100644
--- a/libSBRenc/src/sbr_def.h
+++ b/libSBRenc/src/sbr_def.h
@@ -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
@@ -122,6 +122,8 @@
 /************  Definitions ***************/
 #define SBR_COMP_MODE_DELTA                     0
 #define SBR_COMP_MODE_CTS                       1
+#define SBR_MAX_ENERGY_VALUES                   5
+#define SBR_GLOBAL_TONALITY_VALUES              2
 
 #define MAX_NUM_CHANNELS                        2
 
@@ -232,6 +234,8 @@
 #define FREQ                      0
 #define TIME                      1
 
+/* qmf data scaling */
+#define QMF_SCALE_OFFSET          7
 
 /* huffman tables */
 #define CODE_BOOK_SCF_LAV00         60
@@ -268,12 +272,4 @@
 }
 INVF_MODE;
 
-typedef enum
-{
-  FREQ_RES_LOW = 0,
-  FREQ_RES_HIGH
-}
-FREQ_RES;
-
-
 #endif
diff --git a/libSBRenc/src/sbr_encoder.cpp b/libSBRenc/src/sbr_encoder.cpp
index 9bb98c8..90b19cf 100644
--- a/libSBRenc/src/sbr_encoder.cpp
+++ b/libSBRenc/src/sbr_encoder.cpp
@@ -103,7 +103,7 @@
 
 #define SBRENCODER_LIB_VL0 3
 #define SBRENCODER_LIB_VL1 3
-#define SBRENCODER_LIB_VL2 8
+#define SBRENCODER_LIB_VL2 12
 
 
 
@@ -412,6 +412,23 @@
   config->codecSettings.transFac        = transFac;
   config->codecSettings.standardBitrate = standardBitrate;
 
+  if (bitRate < 28000) {
+    config->threshold_AmpRes_FF_m = (FIXP_DBL)MAXVAL_DBL;
+    config->threshold_AmpRes_FF_e = 7;
+  }
+  else if (bitRate >= 28000 && bitRate <= 48000) {
+    /* The float threshold is 75
+       0.524288f is fractional part of RELAXATION, the quotaMatrix and therefore tonality are scaled by this
+       2/3 is because the original implementation divides the tonality values by 3, here it's divided by 2
+       128 compensates the necessary shiftfactor of 7 */
+    config->threshold_AmpRes_FF_m = FL2FXCONST_DBL(75.0f*0.524288f/(2.0f/3.0f)/128.0f);
+    config->threshold_AmpRes_FF_e = 7;
+  }
+  else if (bitRate > 48000) {
+    config->threshold_AmpRes_FF_m = FL2FXCONST_DBL(0);
+    config->threshold_AmpRes_FF_e = 0;
+  }
+
   if (bitRate==0) {
     /* map vbr quality to bitrate */
     if (vbrMode < 30)
@@ -467,6 +484,57 @@
     config->stereoMode      = sbrTuningTable[idx].stereoMode ;
     config->freqScale       = sbrTuningTable[idx].freqScale ;
 
+    if (numChannels == 1) {
+      /* stereo case */
+      switch (core) {
+        case AOT_AAC_LC:
+          if (bitRate <= (useSpeechConfig?24000U:20000U)) {
+            config->freq_res_fixfix[0] = FREQ_RES_LOW; /* set low frequency resolution for non-split frames */
+            config->freq_res_fixfix[1] = FREQ_RES_LOW; /* set low frequency resolution for split frames */
+          }
+          break;
+        case AOT_ER_AAC_ELD:
+          if (bitRate < 36000)
+            config->freq_res_fixfix[1] = FREQ_RES_LOW; /* set low frequency resolution for split frames */
+          if (bitRate < 26000) {
+            config->freq_res_fixfix[0] = FREQ_RES_LOW; /* set low frequency resolution for non-split frames */
+            config->fResTransIsLow = 1;                /* for transient frames, set low frequency resolution */
+          }
+          break;
+        default:
+          break;
+      }
+    }
+    else {
+      /* stereo case */
+      switch (core) {
+        case AOT_AAC_LC:
+          if (bitRate <= 28000) {
+            config->freq_res_fixfix[0] = FREQ_RES_LOW; /* set low frequency resolution for non-split frames */
+            config->freq_res_fixfix[1] = FREQ_RES_LOW; /* set low frequency resolution for split frames */
+          }
+          break;
+        case AOT_ER_AAC_ELD:
+          if (bitRate < 72000) {
+            config->freq_res_fixfix[1] = FREQ_RES_LOW; /* set low frequency resolution for split frames */
+          }
+          if (bitRate < 52000) {
+            config->freq_res_fixfix[0] = FREQ_RES_LOW; /* set low frequency resolution for non-split frames */
+            config->fResTransIsLow = 1;                /* for transient frames, set low frequency resolution */
+          }
+          break;
+        default:
+          break;
+      }
+      if (bitRate <= 28000) {
+        /*
+          additionally restrict frequency resolution in FIXFIX frames
+          to further reduce SBR payload size */
+        config->freq_res_fixfix[0] = FREQ_RES_LOW;
+        config->freq_res_fixfix[1] = FREQ_RES_LOW;
+      }
+    }
+
     /* adjust usage of parametric coding dependent on bitrate and speech config flag */
     if (useSpeechConfig)
       config->parametricCoding  = 0;
@@ -515,6 +583,7 @@
 FDKsbrEnc_InitializeSbrDefaults (sbrConfigurationPtr config,
                                  INT                 downSampleFactor,
                                  UINT                codecGranuleLen
+                                ,const INT           isLowDelay
                                  )
 {
     if ( (downSampleFactor < 1 || downSampleFactor > 2) ||
@@ -525,7 +594,11 @@
     config->useWaveCoding          = 0;
     config->crcSbr                 = 0;
     config->dynBwSupported         = 1;
-    config->tran_thr               = 13000;
+    if (isLowDelay)
+      config->tran_thr             = 6000;
+    else
+      config->tran_thr             = 13000;
+
     config->parametricCoding       = 1;
 
     config->sbrFrameSize           = codecGranuleLen * downSampleFactor;
@@ -558,7 +631,9 @@
     config->noiseFloorOffset       = 0;
     config->startFreq              = 5; /*  5.9 respectively  6.0 kHz at fs = 44.1/48 kHz */
     config->stopFreq               = 9; /* 16.2 respectively 16.8 kHz at fs = 44.1/48 kHz */
-
+    config->freq_res_fixfix[0]     = FREQ_RES_HIGH;  /* non-split case */
+    config->freq_res_fixfix[1]     = FREQ_RES_HIGH;  /* split case */
+    config->fResTransIsLow = 0;  /* for transient frames, set variable frequency resolution according to freqResTable */
 
     /* header_extra_1 */
     config->freqScale       = SBR_FREQ_SCALE_DEFAULT;
@@ -1206,7 +1281,10 @@
 
   FDK_ASSERT(params->e >= 0);
 
-  hEnv->encEnvData.freq_res_fixfix = 1;
+  hEnv->encEnvData.freq_res_fixfix[0] = params->freq_res_fixfix[0];
+  hEnv->encEnvData.freq_res_fixfix[1] = params->freq_res_fixfix[1];
+  hEnv->encEnvData.fResTransIsLow     = params->fResTransIsLow;
+
   hEnv->fLevelProtect = 0;
 
   hEnv->encEnvData.ldGrid = (sbrConfigData->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) ? 1 : 0;
@@ -1348,11 +1426,29 @@
                             e,
                             params->stat,
                             timeSlots,
-                            hEnv->encEnvData.freq_res_fixfix
-                            ,hEnv->encEnvData.ldGrid
+                            hEnv->encEnvData.freq_res_fixfix,
+                            hEnv->encEnvData.fResTransIsLow,
+                            hEnv->encEnvData.ldGrid
                             );
 
+  if(sbrConfigData->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY)
+  {
+    INT bandwidth_qmf_slot = (sbrConfigData->sampleFreq>>1) / (sbrConfigData->noQmfBands);
+    if(FDKsbrEnc_InitSbrFastTransientDetector(
+              &hEnv->sbrFastTransientDetector,
+               sbrConfigData->noQmfSlots,
+               bandwidth_qmf_slot,
+               sbrConfigData->noQmfBands,
+               sbrConfigData->freqBandTable[0][0]
+               ))
+      return(1);
+  }
+
+  /* The transient detector has to be initialized also if the fast transient
+     detector was active, because the values from the transient detector
+     structure are used. */
   if(FDKsbrEnc_InitSbrTransientDetector (&hEnv->sbrTransientDetector,
+                                          sbrConfigData->sbrSyntaxFlags,
                                           sbrConfigData->frameSize,
                                           sbrConfigData->sampleFreq,
                                           params,
@@ -1658,6 +1754,8 @@
    /* other switches */
   hSbrElement->sbrConfigData.useWaveCoding             = params->useWaveCoding;
   hSbrElement->sbrConfigData.useParametricCoding       = params->parametricCoding;
+  hSbrElement->sbrConfigData.thresholdAmpResFF_m       = params->threshold_AmpRes_FF_m;
+  hSbrElement->sbrConfigData.thresholdAmpResFF_e       = params->threshold_AmpRes_FF_e;
 
   /* init freq band table */
   if(updateFreqBandTable(&hSbrElement->sbrConfigData,
@@ -1999,7 +2097,8 @@
          */
         if ( ! FDKsbrEnc_InitializeSbrDefaults ( &sbrConfig[el],
                                                  *downSampleFactor,
-                                                  coreFrameLength
+                                                  coreFrameLength,
+                                                  IS_LOWDELAY(aot)
                                                   ) )
         {
           error = 1;
diff --git a/libSBRenc/src/sbr_rom.cpp b/libSBRenc/src/sbr_rom.cpp
index a2b6527..7a51668 100644
--- a/libSBRenc/src/sbr_rom.cpp
+++ b/libSBRenc/src/sbr_rom.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
@@ -684,6 +684,9 @@
 
   /** AAC LOW DELAY SECTION **/
 
+  /* 24 kHz dual rate - 12kHz singlerate is not allowed (deactivated in FDKsbrEnc_IsSbrSettingAvail()) */
+  { CODEC_AACLD,   8000, 32000,  12000, 1,  1, 1, 0, 0,  1, 0, 6, SBR_MONO, 3 }, /* nominal:  8 kbit/s */
+
   /*** mono ***/
   /* 16/32 kHz dual rate not yet tuned ->alb copied from non LD tables*/
   { CODEC_AACLD,  16000, 18000,  16000, 1,  4, 5, 9, 7,  1, 0, 6, SBR_MONO, 3 }, /* nominal: 16 kbit/s wrr: tuned */
@@ -702,10 +705,10 @@
   { CODEC_AACLD,  52000, 64001,  22050, 1, 13,11,11,10,  2, 0, 3, SBR_MONO, 1 }, /* nominal: 56 kbit/s */
 
   /* 24/48 kHz dual rate */
-  { CODEC_AACLD,  20000, 22000,  24000, 1,  4, 1, 8, 4,  2, 3, 6, SBR_MONO, 2 }, /* nominal: 20 kbit/s */
+  { CODEC_AACLD,  20000, 22000,  24000, 1,  3, 4, 8, 8,  2, 0, 6, SBR_MONO, 2 }, /* nominal: 20 kbit/s */
   { CODEC_AACLD,  22000, 28000,  24000, 1,  3, 8, 8, 7,  2, 0, 3, SBR_MONO, 2 }, /* nominal: 24 kbit/s */
   { CODEC_AACLD,  28000, 36000,  24000, 1,  4, 8, 8, 7,  2, 0, 3, SBR_MONO, 2 }, /* nominal: 32 kbit/s */
-  { CODEC_AACLD,  36000, 56000,  24000, 1,  8, 9, 9, 9,  2, 0, 3, SBR_MONO, 1 }, /* nominal: 40 kbit/s */
+  { CODEC_AACLD,  36000, 56000,  24000, 1,  8, 9, 9, 8,  2, 0, 3, SBR_MONO, 1 }, /* nominal: 40 kbit/s */
   { CODEC_AACLD,  56000, 64001,  24000, 1, 13,11,11,10,  2, 0, 3, SBR_MONO, 1 }, /* nominal: 64 kbit/s */
 
   /* 32/64 kHz dual rate */  /* placebo settings */  /*jgr: new, copy from CODEC_AAC */
@@ -722,7 +725,7 @@
   { CODEC_AACLD, 100000,160001,  44100, 1, 13,13,11,11,  2, 0, 3, SBR_MONO, 1 }, /* nominal: 128 */
 
   /* 48/96 kHz dual rate */  /* 32 and 40kbps line tuned for dual-rate SBR */
-  { CODEC_AACLD,  36000, 60000,  48000, 1,  8, 7, 6, 9,  2, 0, 3, SBR_MONO, 2 }, /* nominal: 40 */
+  { CODEC_AACLD,  36000, 60000,  48000, 1,  4, 7, 4, 4,  2, 0, 3, SBR_MONO, 3 }, /* nominal: 40 */
   { CODEC_AACLD,  60000, 72000,  48000, 1,  9, 9,10,10,  2, 0, 3, SBR_MONO, 1 }, /* nominal: 64 */
   { CODEC_AACLD,  72000,100000,  48000, 1, 11,11,11,11,  2, 0, 3, SBR_MONO, 1 }, /* nominal: 80 */
   { CODEC_AACLD, 100000,160001,  48000, 1, 13,13,11,11,  2, 0, 3, SBR_MONO, 1 }, /* nominal: 128 */
diff --git a/libSBRenc/src/ton_corr.cpp b/libSBRenc/src/ton_corr.cpp
index 224da11..af5afba 100644
--- a/libSBRenc/src/ton_corr.cpp
+++ b/libSBRenc/src/ton_corr.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
@@ -682,7 +682,7 @@
 
   /*
   Reset the patching and allocate memory for the quota matrix.
-  Assing parameters for the LPC analysis.
+  Assuming parameters for the LPC analysis.
   */
   if (sbrCfg->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
     switch (timeSlots) {
@@ -690,7 +690,7 @@
       hTonCorr->lpcLength[0]              = 8 - LPC_ORDER;
       hTonCorr->lpcLength[1]              = 7 - LPC_ORDER;
       hTonCorr->numberOfEstimates         = NO_OF_ESTIMATES_LD;
-      hTonCorr->numberOfEstimatesPerFrame = sbrCfg->noQmfSlots / 7;
+      hTonCorr->numberOfEstimatesPerFrame = 2; /* sbrCfg->noQmfSlots / 7 */
       hTonCorr->frameStartIndexInvfEst    = 0;
       hTonCorr->transientPosOffset        = FRAME_MIDDLE_SLOT_512LD;
       break;
@@ -698,7 +698,7 @@
       hTonCorr->lpcLength[0]              = 8 - LPC_ORDER;
       hTonCorr->lpcLength[1]              = 8 - LPC_ORDER;
       hTonCorr->numberOfEstimates         = NO_OF_ESTIMATES_LD;
-      hTonCorr->numberOfEstimatesPerFrame = sbrCfg->noQmfSlots / 8;
+      hTonCorr->numberOfEstimatesPerFrame = 2; /* sbrCfg->noQmfSlots / 8 */
       hTonCorr->frameStartIndexInvfEst    = 0;
       hTonCorr->transientPosOffset        = FRAME_MIDDLE_SLOT_512LD;
       break;
diff --git a/libSBRenc/src/ton_corr.h b/libSBRenc/src/ton_corr.h
index 8c8425c..504ab03 100644
--- a/libSBRenc/src/ton_corr.h
+++ b/libSBRenc/src/ton_corr.h
@@ -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
@@ -118,7 +118,7 @@
   INT bufferLength;               /*!< Length of the r and i buffers. */
   INT stepSize;                   /*!< Stride for the lpc estimate. */
   INT numberOfEstimates;          /*!< The total number of estiamtes, available in the quotaMatrix.*/
-  INT numberOfEstimatesPerFrame;  /*!< The number of estimates per frame available in the quotaMatrix.*/
+  UINT numberOfEstimatesPerFrame; /*!< The number of estimates per frame available in the quotaMatrix.*/
   INT lpcLength[2];               /*!< Segment length used for second order LPC analysis.*/
   INT nextSample;                 /*!< Where to start the LPC analysis of the current frame.*/
   INT move;                       /*!< How many estimates to move in the quotaMatrix, when buffering. */
diff --git a/libSBRenc/src/tran_det.cpp b/libSBRenc/src/tran_det.cpp
index 6c62b4c..33ea60e 100644
--- a/libSBRenc/src/tran_det.cpp
+++ b/libSBRenc/src/tran_det.cpp
@@ -89,7 +89,7 @@
 
 #include "genericStds.h"
 
-#define NORM_QMF_ENERGY 5.684341886080801486968994140625e-14 /* 2^-44 */
+#define NORM_QMF_ENERGY 9.31322574615479E-10 /* 2^-30 */
 
 /* static FIXP_DBL ABS_THRES = fixMax( FL2FXCONST_DBL(1.28e5 *  NORM_QMF_ENERGY), (FIXP_DBL)1)  Minimum threshold for detecting changes */
 #define ABS_THRES ((FIXP_DBL)16)
@@ -106,22 +106,30 @@
 
  \return  calculated value
 *******************************************************************************/
+#define NRG_SHIFT  3 /* for energy summation */
+
 static FIXP_DBL spectralChange(FIXP_DBL Energies[NUMBER_TIME_SLOTS_2304][MAX_FREQ_COEFFS],
                                INT *scaleEnergies,
                                FIXP_DBL EnergyTotal,
                                INT nSfb,
                                INT start,
                                INT border,
-                               INT stop)
+                               INT YBufferWriteOffset,
+                               INT stop,
+                               INT *result_e)
 {
   INT i,j;
   INT len1,len2;
-  FIXP_DBL delta,tmp0,tmp1,tmp2;
-  FIXP_DBL accu1,accu2,delta_sum,result;
+  SCHAR energies_e_diff[NUMBER_TIME_SLOTS_2304], energies_e, energyTotal_e=19, energies_e_add;
+  SCHAR prevEnergies_e_diff, newEnergies_e_diff;
+  FIXP_DBL tmp0,tmp1;
+  FIXP_DBL accu1,accu2,accu1_init,accu2_init;
+  FIXP_DBL delta, delta_sum;
+  INT accu_e, tmp_e;
 
-  FDK_ASSERT(scaleEnergies[0] >= 0);
+  delta_sum = FL2FXCONST_DBL(0.0f);
+  *result_e = 0;
 
-  /* equal for aac (would be not equal for mp3) */
   len1 = border-start;
   len2 = stop-border;
 
@@ -130,43 +138,91 @@
   pos_weight = FL2FXCONST_DBL(0.5f) - (len1*GetInvInt(len1+len2));
   pos_weight = /*FL2FXCONST_DBL(1.0)*/ (FIXP_DBL)MAXVAL_DBL - (fMult(pos_weight, pos_weight)<<2);
 
-  delta_sum = FL2FXCONST_DBL(0.0f);
+  /*** Calc scaling for energies ***/
+  FDK_ASSERT(scaleEnergies[0] >= 0);
+  FDK_ASSERT(scaleEnergies[1] >= 0);
+
+  energies_e = 19 - FDKmin(scaleEnergies[0], scaleEnergies[1]);
+
+  /* limit shift for energy accumulation, energies_e can be -10 min. */
+  if (energies_e < -10) {
+     energies_e_add = -10 - energies_e;
+     energies_e = -10;
+  } else if (energies_e > 17) {
+     energies_e_add = energies_e - 17;
+     energies_e = 17;
+  } else {
+     energies_e_add = 0;
+  }
+
+  /* compensate scaling differences between scaleEnergies[0] and scaleEnergies[1]  */
+  prevEnergies_e_diff = scaleEnergies[0] - FDKmin(scaleEnergies[0], scaleEnergies[1]) + energies_e_add + NRG_SHIFT;
+  newEnergies_e_diff  = scaleEnergies[1] - FDKmin(scaleEnergies[0], scaleEnergies[1]) + energies_e_add + NRG_SHIFT;
+
+  prevEnergies_e_diff = fMin(prevEnergies_e_diff, DFRACT_BITS-1);
+  newEnergies_e_diff  = fMin(newEnergies_e_diff,  DFRACT_BITS-1);
+
+  for (i=start; i<YBufferWriteOffset; i++) {
+    energies_e_diff[i] = prevEnergies_e_diff;
+  }
+  for (i=YBufferWriteOffset; i<stop; i++) {
+    energies_e_diff[i] = newEnergies_e_diff;
+  }
 
   /* Sum up energies of all QMF-timeslots for both halfs */
+  FDK_ASSERT(len1<=8); /* otherwise an overflow is possible */
+  FDK_ASSERT(len2<=8); /* otherwise an overflow is possible */
+  /* init with some energy to prevent division by zero
+      and to prevent splitting for very low levels */
+  accu1_init = scaleValue((FL2FXCONST_DBL((1.0e6*NORM_QMF_ENERGY))),-energies_e);
+  accu2_init = scaleValue((FL2FXCONST_DBL((1.0e6*NORM_QMF_ENERGY))),-energies_e);
+  accu1_init = fMult(accu1_init, (FIXP_DBL)len1<<((DFRACT_BITS-1)-NRG_SHIFT-1))<<1;
+  accu2_init = fMult(accu2_init, (FIXP_DBL)len2<<((DFRACT_BITS-1)-NRG_SHIFT-1))<<1;
+
   for (j=0; j<nSfb; j++) {
-    #define NRG_SCALE  3
-    /* init with some energy to prevent division by zero
-       and to prevent splitting for very low levels */
-    accu1 = ((FL2FXCONST_DBL((1.0e6*NORM_QMF_ENERGY*8.0/32))) << fixMin(scaleEnergies[0],25))>>NRG_SCALE;  /* complex init for compare with original version */
-    accu2 = ((FL2FXCONST_DBL((1.0e6*NORM_QMF_ENERGY*8.0/32))) << fixMin(scaleEnergies[0],25))>>NRG_SCALE;  /* can be simplified in dsp implementation */
+
+    accu1 = accu1_init;
+    accu2 = accu2_init;
+    accu_e = energies_e+3;
 
     /* Sum up energies in first half */
     for (i=start; i<border; i++) {
-      accu1 += (Energies[i][j]>>NRG_SCALE);
+      accu1 += scaleValue(Energies[i][j], -energies_e_diff[i]);
     }
 
     /* Sum up energies in second half */
     for (i=border; i<stop; i++) {
-      accu2 += (Energies[i][j]>>NRG_SCALE);
+      accu2 += scaleValue(Energies[i][j], -energies_e_diff[i]);
     }
 
     /* Energy change in current band */
-    tmp0 = CalcLdData(accu2);
-    tmp1 = CalcLdData(accu1);
-    tmp2 = (tmp0 - tmp1 + CalcLdData(len1)-CalcLdData(len2));
-    delta = fixp_abs(fMult(tmp2, FL2FXCONST_DBL(0.6931471806f)));
+    #define LN2 FL2FXCONST_DBL(0.6931471806f) /* ln(2) */
+    tmp0 = fLog2(accu2, accu_e) - fLog2(accu1, accu_e);
+    tmp1 = fLog2((FIXP_DBL)len1, 31) - fLog2((FIXP_DBL)len2, 31);
+    delta = fMult(LN2, (tmp0 + tmp1));
+    delta = (FIXP_DBL)FDKabs( delta );
 
     /* Weighting with amplitude ratio of this band */
-    result = (EnergyTotal == FL2FXCONST_DBL(0.0f))
-            ? FL2FXCONST_DBL(0.f)
-            : FDKsbrEnc_LSI_divide_scale_fract( (accu1+accu2),
-                                      (EnergyTotal>>NRG_SCALE)+(FIXP_DBL)1,
-                                      (FIXP_DBL)MAXVAL_DBL >> fixMin(scaleEnergies[0],(DFRACT_BITS-1)) );
+    accu_e++;
+    accu1>>=1;
+    accu2>>=1;
+    if (accu_e & 1) {
+      accu_e++;
+      accu1>>=1;
+      accu2>>=1;
+    }
 
-    delta_sum += (FIXP_DBL)(fMult(sqrtFixp(result), delta));
+    delta_sum += fMult(sqrtFixp(accu1+accu2), delta);
+    *result_e = ((accu_e>>1) + LD_DATA_SHIFT);
   }
 
+  energyTotal_e+=1; /* for a defined square result exponent, the exponent has to be even */
+  EnergyTotal<<=1;
+  delta_sum = fMult(delta_sum, invSqrtNorm2(EnergyTotal, &tmp_e));
+  *result_e = *result_e + (tmp_e-(energyTotal_e>>1));
+
   return fMult(delta_sum, pos_weight);
+
 }
 
 
@@ -175,9 +231,12 @@
  *******************************************************************************
  \brief   Calculates total lowband energy
 
- The return value nrgTotal is scaled by the factor (1/32.0)
+ The input values Energies[0] (low-band) are scaled by the factor
+ 2^(14-*scaleEnergies[0])
+ The input values Energies[1] (high-band) are scaled by the factor
+ 2^(14-*scaleEnergies[1])
 
- \return  total energy in the lowband
+ \return  total energy in the lowband, scaled by the factor 2^19
 *******************************************************************************/
 static FIXP_DBL addLowbandEnergies(FIXP_DBL **Energies,
                                    int       *scaleEnergies,
@@ -194,6 +253,7 @@
   int ts,k;
 
   /* Sum up lowband energy from one frame at offset tran_off */
+  /* freqBandTable[LORES] has MAX_FREQ_COEFFS/2 +1 coeefs max. */
   for (ts=tran_offdiv2; ts<YBufferWriteOffset; ts++) {
     for (k = 0; k < freqBandTable[0]; k++) {
       accu1 += Energies[ts][k] >> 6;
@@ -201,12 +261,12 @@
   }
   for (; ts<tran_offdiv2+(slots>>nrgSzShift); ts++) {
     for (k = 0; k < freqBandTable[0]; k++) {
-      accu2 += Energies[ts][k] >> 6;
+      accu2 += Energies[ts][k] >> 9;
     }
   }
 
-  nrgTotal = ( (accu1 >> fixMin(scaleEnergies[0],(DFRACT_BITS-1)))
-           +   (accu2 >> fixMin(scaleEnergies[1],(DFRACT_BITS-1))) ) << (2);
+  nrgTotal = ( scaleValueSaturate(accu1, 1-scaleEnergies[0]) )
+           + ( scaleValueSaturate(accu2, 4-scaleEnergies[1]) );
 
   return(nrgTotal);
 }
@@ -222,21 +282,23 @@
  is 1 SBR-band. Therefore the data to be fed into the spectralChange
  function is reduced.
 
- The values EnergiesM are scaled by the factor (1/32.0) and scaleEnergies[0]
- The return value nrgTotal is scaled by the factor (1/32.0)
+ The values EnergiesM are scaled by the factor (2^19-scaleEnergies[0]) for
+ slots<YBufferWriteOffset and by the factor (2^19-scaleEnergies[1]) for
+ slots>=YBufferWriteOffset.
 
- \return  total energy in the highband
+ \return  total energy in the highband, scaled by factor 2^19
 *******************************************************************************/
 
 static FIXP_DBL addHighbandEnergies(FIXP_DBL **RESTRICT Energies, /*!< input */
                                     INT       *scaleEnergies,
+                                    INT        YBufferWriteOffset,
                                     FIXP_DBL   EnergiesM[NUMBER_TIME_SLOTS_2304][MAX_FREQ_COEFFS], /*!< Combined output */
                                     UCHAR     *RESTRICT freqBandTable,
                                     INT        nSfb,
                                     INT        sbrSlots,
                                     INT        timeStep)
 {
-  INT i,j,k,slotIn,slotOut,scale;
+  INT i,j,k,slotIn,slotOut,scale[2];
   INT li,ui;
   FIXP_DBL nrgTotal;
   FIXP_DBL accu = FL2FXCONST_DBL(0.0f);
@@ -245,7 +307,7 @@
      combine QMF-bands to SBR-bands,
      combine Left and Right channel */
   for (slotOut=0; slotOut<sbrSlots; slotOut++) {
-    slotIn = 2*slotOut;
+    slotIn = timeStep*slotOut;
 
     for (j=0; j<nSfb; j++) {
       accu = FL2FXCONST_DBL(0.0f);
@@ -262,19 +324,29 @@
     }
   }
 
-  scale = fixMin(8,scaleEnergies[0]);      /* scale energies down before add up */
+  /* scale energies down before add up */
+  scale[0] = fixMin(8,scaleEnergies[0]);
+  scale[1] = fixMin(8,scaleEnergies[1]);
 
-  if ((scaleEnergies[0]-1) > (DFRACT_BITS-1) )
+  if ((scaleEnergies[0]-scale[0]) > (DFRACT_BITS-1) || (scaleEnergies[1]-scale[0]) > (DFRACT_BITS-1))
     nrgTotal = FL2FXCONST_DBL(0.0f);
   else {
     /* Now add all energies */
     accu = FL2FXCONST_DBL(0.0f);
-    for (slotOut=0; slotOut<sbrSlots; slotOut++) {
+
+    for (slotOut=0; slotOut<YBufferWriteOffset; slotOut++) {
       for (j=0; j<nSfb; j++) {
-        accu += (EnergiesM[slotOut][j] >> scale);
+        accu += (EnergiesM[slotOut][j] >> scale[0]);
       }
     }
-    nrgTotal = accu >> (scaleEnergies[0]-scale);
+    nrgTotal = accu >> (scaleEnergies[0]-scale[0]);
+
+    for (slotOut=YBufferWriteOffset; slotOut<sbrSlots; slotOut++) {
+      for (j=0; j<nSfb; j++) {
+        accu += (EnergiesM[slotOut][j] >> scale[0]);
+      }
+    }
+    nrgTotal = accu >> (scaleEnergies[1]-scale[1]);
   }
 
   return(nrgTotal);
@@ -299,18 +371,23 @@
                         int YBufferSzShift,
                         int nSfb,
                         int timeStep,
-                        int no_cols)
+                        int no_cols,
+                        FIXP_DBL* tonality)
 {
   if (tran_vector[1]==0) /* no transient was detected */
   {
     FIXP_DBL delta;
-    FIXP_DBL EnergiesM[NUMBER_TIME_SLOTS_2304][MAX_FREQ_COEFFS];
+    INT delta_e;
+    FIXP_DBL (*EnergiesM)[MAX_FREQ_COEFFS];
     FIXP_DBL EnergyTotal,newLowbandEnergy,newHighbandEnergy;
     INT border;
     INT sbrSlots = fMultI(GetInvInt(timeStep),no_cols);
+    C_ALLOC_SCRATCH_START(_EnergiesM, FIXP_DBL, NUMBER_TIME_SLOTS_2304*MAX_FREQ_COEFFS)
 
     FDK_ASSERT( sbrSlots * timeStep == no_cols );
 
+    EnergiesM = (FIXP_DBL(*)[MAX_FREQ_COEFFS])_EnergiesM;
+
     /*
       Get Lowband-energy over a range of 2 frames (Look half a frame back and ahead).
     */
@@ -324,16 +401,13 @@
 
     newHighbandEnergy = addHighbandEnergies(Energies,
                                             scaleEnergies,
+                                            YBufferWriteOffset,
                                             EnergiesM,
                                             freqBandTable,
                                             nSfb,
                                             sbrSlots,
                                             timeStep);
 
-    if ( h_sbrTransientDetector->frameShift != 0 ) {
-      if (tran_vector[1]==0)
-        tran_vector[0] = 0;
-    } else
     {
       /* prevLowBandEnergy: Corresponds to 1 frame, starting with half a frame look-behind
          newLowbandEnergy:  Corresponds to 1 frame, starting in the middle of the current frame */
@@ -343,23 +417,39 @@
          of a FIXFIX-frame with 2 envelopes. */
       border = (sbrSlots+1) >> 1;
 
+      if ( (INT)EnergyTotal&0xffffffe0 && (scaleEnergies[0]<32 || scaleEnergies[1]<32) ) /* i.e. > 31 */ {
       delta = spectralChange(EnergiesM,
                              scaleEnergies,
                              EnergyTotal,
                              nSfb,
                              0,
                              border,
-                             sbrSlots);
+                             YBufferWriteOffset,
+                             sbrSlots,
+                            &delta_e
+                             );
+      } else {
+        delta = FL2FXCONST_DBL(0.0f);
+        delta_e = 0;
 
-      if (delta > (h_sbrTransientDetector->split_thr >> LD_DATA_SHIFT)) /* delta scaled by 1/64 */
+        /* set tonality to 0 when energy is very low, since the amplitude
+           resolution should then be low as well                          */
+        *tonality = FL2FXCONST_DBL(0.0f);
+      }
+
+
+      if ( fIsLessThan(h_sbrTransientDetector->split_thr_m, h_sbrTransientDetector->split_thr_e, delta, delta_e) ) {
         tran_vector[0] = 1; /* Set flag for splitting */
-      else
+      } else {
         tran_vector[0] = 0;
+      }
+
     }
 
     /* Update prevLowBandEnergy */
     h_sbrTransientDetector->prevLowBandEnergy = newLowbandEnergy;
     h_sbrTransientDetector->prevHighBandEnergy = newHighbandEnergy;
+    C_ALLOC_SCRATCH_END(_EnergiesM, FIXP_DBL, NUMBER_TIME_SLOTS_2304*MAX_FREQ_COEFFS)
   }
 }
 
@@ -636,6 +726,7 @@
 
 int
 FDKsbrEnc_InitSbrTransientDetector(HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector,
+                                   UINT  sbrSyntaxFlags, /* SBR syntax flags derived from AOT. */
                                    INT   frameSize,
                                    INT   sampleFreq,
                                    sbrConfigurationPtr params,
@@ -649,8 +740,8 @@
 {
     INT totalBitrate = params->codecSettings.standardBitrate * params->codecSettings.nChannels;
     INT codecBitrate = params->codecSettings.bitRate;
-    FIXP_DBL bitrateFactor_fix, framedur_fix;
-    INT scale_0, scale_1;
+    FIXP_DBL bitrateFactor_m, framedur_fix;
+    INT bitrateFactor_e, tmp_e;
 
     FDKmemclear(h_sbrTransientDetector,sizeof(SBR_TRANSIENT_DETECTOR));
 
@@ -658,11 +749,12 @@
     h_sbrTransientDetector->tran_off = tran_off;
 
     if(codecBitrate) {
-      bitrateFactor_fix = fDivNorm((FIXP_DBL)totalBitrate, (FIXP_DBL)(codecBitrate<<2),&scale_0);
+      bitrateFactor_m = fDivNorm((FIXP_DBL)totalBitrate, (FIXP_DBL)(codecBitrate<<2),&bitrateFactor_e);
+      bitrateFactor_e += 2;
     }
     else {
-      bitrateFactor_fix = FL2FXCONST_DBL(1.0/4.0);
-      scale_0 = 0;
+      bitrateFactor_m = FL2FXCONST_DBL(1.0/4.0);
+      bitrateFactor_e = 2;
     }
 
     framedur_fix = fDivNorm(frameSize, sampleFreq);
@@ -674,9 +766,13 @@
     FIXP_DBL tmp = framedur_fix - FL2FXCONST_DBL(0.010);
 
     tmp = fixMax(tmp, FL2FXCONST_DBL(0.0001));
-    tmp = fDivNorm(FL2FXCONST_DBL(0.000075), fPow2(tmp), &scale_1);
+    tmp = fDivNorm(FL2FXCONST_DBL(0.000075), fPow2(tmp), &tmp_e);
 
-    scale_1 = (scale_1 + scale_0 + 2);
+    bitrateFactor_e = (tmp_e + bitrateFactor_e);
+
+  if(sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+    bitrateFactor_e--; /* divide by 2 */
+  }
 
     FDK_ASSERT(no_cols <= QMF_MAX_TIME_SLOTS);
     FDK_ASSERT(no_rows <= QMF_CHANNELS);
@@ -684,7 +780,8 @@
     h_sbrTransientDetector->no_cols = no_cols;
     h_sbrTransientDetector->tran_thr = (FIXP_DBL)((params->tran_thr << (32-24-1)) / no_rows);
     h_sbrTransientDetector->tran_fc = tran_fc;
-    h_sbrTransientDetector->split_thr = scaleValueSaturate(fMult(tmp, bitrateFactor_fix), scale_1);     
+    h_sbrTransientDetector->split_thr_m = fMult(tmp, bitrateFactor_m);
+    h_sbrTransientDetector->split_thr_e = bitrateFactor_e;
     h_sbrTransientDetector->no_rows = no_rows;
     h_sbrTransientDetector->mode = params->tran_det_mode;
     h_sbrTransientDetector->prevLowBandEnergy = FL2FXCONST_DBL(0.0f);
@@ -692,3 +789,281 @@
     return (0);
 }
 
+
+#define ENERGY_SCALING_SIZE 32
+
+INT FDKsbrEnc_InitSbrFastTransientDetector(
+        HANDLE_FAST_TRAN_DET h_sbrFastTransientDetector,
+        const INT time_slots_per_frame,
+        const INT bandwidth_qmf_slot,
+        const INT no_qmf_channels,
+        const INT sbr_qmf_1st_band
+        )
+{
+
+  int i, e;
+  int buff_size;
+  FIXP_DBL myExp;
+  FIXP_DBL myExpSlot;
+
+  h_sbrFastTransientDetector->lookahead = TRAN_DET_LOOKAHEAD;
+  h_sbrFastTransientDetector->nTimeSlots = time_slots_per_frame;
+
+  buff_size = h_sbrFastTransientDetector->nTimeSlots + h_sbrFastTransientDetector->lookahead;
+
+  for(i=0; i< buff_size; i++) {
+    h_sbrFastTransientDetector->delta_energy[i] = FL2FXCONST_DBL(0.0f);
+    h_sbrFastTransientDetector->energy_timeSlots[i] = FL2FXCONST_DBL(0.0f);
+    h_sbrFastTransientDetector->lowpass_energy[i] = FL2FXCONST_DBL(0.0f);
+    h_sbrFastTransientDetector->transientCandidates[i] = 0;
+  }
+
+  FDK_ASSERT(bandwidth_qmf_slot > 0.f);
+  h_sbrFastTransientDetector->stopBand  = fMin(TRAN_DET_STOP_FREQ/bandwidth_qmf_slot, no_qmf_channels);
+  h_sbrFastTransientDetector->startBand = fMin(sbr_qmf_1st_band, h_sbrFastTransientDetector->stopBand - TRAN_DET_MIN_QMFBANDS);
+
+  FDK_ASSERT(h_sbrFastTransientDetector->startBand < no_qmf_channels);
+  FDK_ASSERT(h_sbrFastTransientDetector->startBand < h_sbrFastTransientDetector->stopBand);
+  FDK_ASSERT(h_sbrFastTransientDetector->startBand > 1);
+  FDK_ASSERT(h_sbrFastTransientDetector->stopBand > 1);
+
+  /* the energy weighting and adding up has a headroom of 6 Bits,
+     so up to 64 bands can be added without potential overflow. */
+  FDK_ASSERT(h_sbrFastTransientDetector->stopBand - h_sbrFastTransientDetector->startBand <= 64);
+
+  /* QMF_HP_dB_SLOPE_FIX says that we want a 20 dB per 16 kHz HP filter.
+     The following lines map this to the QMF bandwidth. */
+  #define EXP_E 7 /* QMF_CHANNELS (=64) multiplications max, max. allowed sum is 0.5 */
+  myExp = fMultNorm(QMF_HP_dBd_SLOPE_FIX, (FIXP_DBL)bandwidth_qmf_slot, &e);
+  myExp = scaleValueSaturate(myExp, e+0+DFRACT_BITS-1-EXP_E);
+  myExpSlot = myExp;
+
+  for(i=0; i<QMF_CHANNELS; i++){
+    /* Calculate dBf over all qmf bands:
+       dBf = (10^(0.002266f/10*bw(slot)))^(band) =
+           = 2^(log2(10)*0.002266f/10*bw(slot)*band) =
+           = 2^(0.00075275f*bw(slot)*band)                                   */
+
+    FIXP_DBL dBf_m;        /* dBf mantissa        */
+    INT dBf_e;             /* dBf exponent        */
+    INT tmp;
+
+    INT dBf_int;           /* dBf integer part    */
+    FIXP_DBL dBf_fract;    /* dBf fractional part */
+
+    /* myExp*(i+1) = myExp_int - myExp_fract
+       myExp*(i+1) is split up here for better accuracy of CalcInvLdData(),
+       for its result can be split up into an integer and a fractional part */
+
+    /* Round up to next integer */
+    FIXP_DBL myExp_int   = (myExpSlot & (FIXP_DBL)0xfe000000) + (FIXP_DBL)0x02000000;
+
+    /* This is the fractional part that needs to be substracted */
+    FIXP_DBL myExp_fract = myExp_int - myExpSlot;
+
+    /* Calc integer part */
+    dBf_int   = CalcInvLdData(myExp_int);
+    /* The result needs to be re-scaled. The ld(myExp_int) had been scaled by EXP_E,
+       the CalcInvLdData expects the operand to be scaled by LD_DATA_SHIFT.
+       Therefore, the correctly scaled result is dBf_int^(2^(EXP_E-LD_DATA_SHIFT)),
+       which is dBf_int^2 */
+    dBf_int  *= dBf_int;
+
+    /* Calc fractional part */
+    dBf_fract = CalcInvLdData(-myExp_fract);
+    /* The result needs to be re-scaled. The ld(myExp_fract) had been scaled by EXP_E,
+       the CalcInvLdData expects the operand to be scaled by LD_DATA_SHIFT.
+       Therefore, the correctly scaled result is dBf_fract^(2^(EXP_E-LD_DATA_SHIFT)),
+       which is dBf_fract^2 */
+    dBf_fract = fMultNorm(dBf_fract, dBf_fract, &tmp);
+
+    /* Get worst case scaling of multiplication result */
+    dBf_e = (DFRACT_BITS-1 - tmp) - CountLeadingBits(dBf_int);
+
+    /* Now multiply integer with fractional part of the result, thus resulting
+       in the overall accurate fractional result */
+    dBf_m = fMultNorm(dBf_int, dBf_fract, &e);
+    dBf_m = scaleValueSaturate(dBf_m, e+DFRACT_BITS-1+tmp-dBf_e);
+    myExpSlot += myExp;
+
+    /* Keep the results */
+    h_sbrFastTransientDetector->dBf_m[i] = dBf_m;
+    h_sbrFastTransientDetector->dBf_e[i] = dBf_e;
+
+  }
+
+  /* Make sure that dBf is greater than 1.0 (because it should be a highpass) */
+  /* ... */
+
+  return 0;
+}
+
+void FDKsbrEnc_fastTransientDetect(
+        const HANDLE_FAST_TRAN_DET          h_sbrFastTransientDetector,
+        const FIXP_DBL              *const *Energies,
+        const int                   *const  scaleEnergies,
+        const INT                           YBufferWriteOffset,
+              UCHAR                 *const  tran_vector
+        )
+{
+  int timeSlot, band;
+
+  FIXP_DBL max_delta_energy;   /* helper to store maximum energy ratio          */
+  int max_delta_energy_scale;  /* helper to store scale of maximum energy ratio */
+  int ind_max             = 0; /* helper to store index of maximum energy ratio */
+  int isTransientInFrame  = 0;
+
+  const int nTimeSlots         = h_sbrFastTransientDetector->nTimeSlots;
+  const int lookahead          = h_sbrFastTransientDetector->lookahead;
+  const int startBand          = h_sbrFastTransientDetector->startBand;
+  const int stopBand           = h_sbrFastTransientDetector->stopBand;
+
+  int * transientCandidates    = h_sbrFastTransientDetector->transientCandidates;
+
+  FIXP_DBL * energy_timeSlots  = h_sbrFastTransientDetector->energy_timeSlots;
+  int * energy_timeSlots_scale = h_sbrFastTransientDetector->energy_timeSlots_scale;
+
+  FIXP_DBL * delta_energy      = h_sbrFastTransientDetector->delta_energy;
+  int * delta_energy_scale     = h_sbrFastTransientDetector->delta_energy_scale;
+
+  const FIXP_DBL thr           = TRAN_DET_THRSHLD;
+  const INT      thr_scale     = TRAN_DET_THRSHLD_SCALE;
+
+  /*reset transient info*/
+  tran_vector[2] = 0;
+
+  /* reset transient candidates */
+  FDKmemclear(transientCandidates+lookahead, nTimeSlots*sizeof(int));
+
+  for(timeSlot = lookahead; timeSlot < nTimeSlots + lookahead; timeSlot++) {
+    int i, norm;
+    FIXP_DBL tmpE           = FL2FXCONST_DBL(0.0f);
+    int headroomEnSlot      = DFRACT_BITS-1;
+
+    FIXP_DBL smallNRG = FL2FXCONST_DBL(1e-2f);
+    FIXP_DBL denominator;
+    INT denominator_scale;
+
+    /* determine minimum headroom of energy values for this timeslot */
+    for(band = startBand; band < stopBand; band++) {
+      int tmp_headroom = fNormz(Energies[timeSlot][band])-1;
+      if(tmp_headroom < headroomEnSlot){
+        headroomEnSlot = tmp_headroom;
+      }
+    }
+
+    for(i = 0, band = startBand; band < stopBand; band++, i++) {
+      /* energy is weighted by weightingfactor stored in dBf_m array */
+      /* dBf_m index runs from 0 to stopBand-startband               */
+      /* energy shifted by calculated headroom for maximum precision */
+      FIXP_DBL weightedEnergy = fMult(Energies[timeSlot][band]<<headroomEnSlot, h_sbrFastTransientDetector->dBf_m[i]);
+
+      /* energy is added up                                                */
+      /* shift by 6 to have a headroom for maximum 64 additions            */
+      /* shift by dBf_e to handle weighting factor dependent scale factors */
+      tmpE += weightedEnergy >> (6 + (10 - h_sbrFastTransientDetector->dBf_e[i]));
+    }
+
+    /* store calculated energy for timeslot */
+    energy_timeSlots[timeSlot] = tmpE;
+
+    /* calculate overall scale factor for energy of this timeslot                                                             */
+    /* =   original scale factor of energies (-scaleEnergies[0]+2*QMF_SCALE_OFFSET or -scaleEnergies[1]+2*QMF_SCALE_OFFSET    */
+    /*     depending on YBufferWriteOffset)                                                                                   */
+    /*   + weighting factor scale            (10)                                                                             */
+    /*   + adding up scale factor            ( 6)                                                                             */
+    /*   - headroom of energy value          (headroomEnSlot)                                                                 */
+    if(timeSlot < YBufferWriteOffset){
+      energy_timeSlots_scale[timeSlot] = (-scaleEnergies[0]+2*QMF_SCALE_OFFSET) + (10+6) - headroomEnSlot;
+    } else {
+      energy_timeSlots_scale[timeSlot] = (-scaleEnergies[1]+2*QMF_SCALE_OFFSET) + (10+6) - headroomEnSlot;
+    }
+
+    /* Add a small energy to the denominator, thus making the transient
+       detection energy-dependent. Loud transients are being detected,
+       silent ones not. */
+
+    /* make sure that smallNRG does not overflow */
+    if ( -energy_timeSlots_scale[timeSlot-1] + 1 > 5 )
+    {
+      denominator = smallNRG;
+      denominator_scale = 0;
+    } else {
+      /* Leave an additional headroom of 1 bit for this addition. */
+      smallNRG = scaleValue(smallNRG, -(energy_timeSlots_scale[timeSlot-1] + 1));
+      denominator = (energy_timeSlots[timeSlot-1]>>1) + smallNRG;
+      denominator_scale = energy_timeSlots_scale[timeSlot-1]+1;
+    }
+
+    delta_energy[timeSlot] = fDivNorm(energy_timeSlots[timeSlot], denominator, &norm);
+    delta_energy_scale[timeSlot] = energy_timeSlots_scale[timeSlot] - denominator_scale + norm;
+  }
+
+  /*get transient candidates*/
+  /* For every timeslot, check if delta(E) exceeds the threshold. If it did,
+     it could potentially be marked as a transient candidate. However, the 2
+     slots before the current one must not be transients with an energy higher
+     than 1.4*E(current). If both aren't transients or if the energy of the
+     current timesolot is more than 1.4 times higher than the energy in the
+     last or the one before the last slot, it is marked as a transient.*/
+
+  FDK_ASSERT(lookahead >= 2);
+  for(timeSlot = lookahead; timeSlot < nTimeSlots + lookahead; timeSlot++) {
+    FIXP_DBL energy_cur_slot_weighted = fMult(energy_timeSlots[timeSlot],FL2FXCONST_DBL(1.0f/1.4f));
+    if( !fIsLessThan(delta_energy[timeSlot], delta_energy_scale[timeSlot], thr, thr_scale) &&
+        ( ((transientCandidates[timeSlot-2]==0) && (transientCandidates[timeSlot-1]==0)) ||
+          !fIsLessThan(energy_cur_slot_weighted, energy_timeSlots_scale[timeSlot], energy_timeSlots[timeSlot-1], energy_timeSlots_scale[timeSlot-1] ) ||
+          !fIsLessThan(energy_cur_slot_weighted, energy_timeSlots_scale[timeSlot], energy_timeSlots[timeSlot-2], energy_timeSlots_scale[timeSlot-2] )
+        )
+      )
+{
+      /* in case of strong transients, subsequent
+       * qmf slots might be recognized as transients. */
+      transientCandidates[timeSlot] = 1;
+    }
+  }
+
+  /*get transient with max energy*/
+  max_delta_energy   = FL2FXCONST_DBL(0.0f);
+  max_delta_energy_scale = 0;
+  ind_max = 0;
+  isTransientInFrame = 0;
+  for(timeSlot = 0; timeSlot < nTimeSlots; timeSlot++) {
+    int scale = fMax(delta_energy_scale[timeSlot], max_delta_energy_scale);
+    if(transientCandidates[timeSlot] && ( (delta_energy[timeSlot] >> (scale - delta_energy_scale[timeSlot])) > (max_delta_energy >> (scale - max_delta_energy_scale)) ) ) {
+      max_delta_energy   = delta_energy[timeSlot];
+      max_delta_energy_scale = scale;
+      ind_max            = timeSlot;
+      isTransientInFrame = 1;
+    }
+  }
+
+  /*from all transient candidates take the one with the biggest energy*/
+  if(isTransientInFrame) {
+    tran_vector[0] = ind_max;
+    tran_vector[1] = 1;
+  } else {
+    /*reset transient info*/
+    tran_vector[0] = tran_vector[1] = 0;
+  }
+
+  /*check for transients in lookahead*/
+  for(timeSlot = nTimeSlots; timeSlot < nTimeSlots + lookahead; timeSlot++) {
+    if(transientCandidates[timeSlot]) {
+      tran_vector[2] = 1;
+    }
+  }
+
+  /*update buffers*/
+  for(timeSlot = 0; timeSlot < lookahead; timeSlot++) {
+    transientCandidates[timeSlot] = transientCandidates[nTimeSlots + timeSlot];
+
+    /* fixpoint stuff */
+    energy_timeSlots[timeSlot]    = energy_timeSlots[nTimeSlots + timeSlot];
+    energy_timeSlots_scale[timeSlot]  = energy_timeSlots_scale[nTimeSlots + timeSlot];
+
+    delta_energy[timeSlot]     = delta_energy[nTimeSlots + timeSlot];
+    delta_energy_scale[timeSlot]   = delta_energy_scale[nTimeSlots + timeSlot];
+  }
+}
+
diff --git a/libSBRenc/src/tran_det.h b/libSBRenc/src/tran_det.h
index 95b5d2e..6fe1023 100644
--- a/libSBRenc/src/tran_det.h
+++ b/libSBRenc/src/tran_det.h
@@ -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
@@ -96,7 +96,8 @@
   FIXP_DBL  transients[QMF_MAX_TIME_SLOTS+(QMF_MAX_TIME_SLOTS/2)];
   FIXP_DBL  thresholds[QMF_CHANNELS];
   FIXP_DBL  tran_thr;              /* Master threshold for transient signals */
-  FIXP_DBL  split_thr;             /* Threshold for splitting FIXFIX-frames into 2 env */
+  FIXP_DBL  split_thr_m;           /* Threshold for splitting FIXFIX-frames into 2 env */
+  INT       split_thr_e;           /* Scale for splitting threshold */
   FIXP_DBL  prevLowBandEnergy;     /* Energy of low band */
   FIXP_DBL  prevHighBandEnergy;    /* Energy of high band */
   INT    tran_fc;                  /* Number of lowband subbands to discard  */
@@ -112,6 +113,57 @@
 
 typedef SBR_TRANSIENT_DETECTOR *HANDLE_SBR_TRANSIENT_DETECTOR;
 
+#define TRAN_DET_LOOKAHEAD 2
+#define TRAN_DET_START_FREQ 4500  /*start frequency for transient detection*/
+#define TRAN_DET_STOP_FREQ  13500 /*stop frequency for transient detection*/
+#define TRAN_DET_MIN_QMFBANDS 4 /* minimum qmf bands for transient detection */
+#define QMF_HP_dBd_SLOPE_FIX FL2FXCONST_DBL(0.00075275f) /* 0.002266f/10 * log2(10) */
+#define TRAN_DET_THRSHLD FL2FXCONST_DBL(3.2f/4.f)
+#define TRAN_DET_THRSHLD_SCALE (2)
+
+typedef struct
+{
+  INT transientCandidates[QMF_MAX_TIME_SLOTS + TRAN_DET_LOOKAHEAD];
+  INT nTimeSlots;
+  INT lookahead;
+  INT startBand;
+  INT stopBand;
+
+  FIXP_DBL dBf_m[QMF_CHANNELS];
+  INT      dBf_e[QMF_CHANNELS];
+
+  FIXP_DBL energy_timeSlots[QMF_MAX_TIME_SLOTS + TRAN_DET_LOOKAHEAD];
+  INT      energy_timeSlots_scale[QMF_MAX_TIME_SLOTS + TRAN_DET_LOOKAHEAD];
+
+  FIXP_DBL delta_energy[QMF_MAX_TIME_SLOTS + TRAN_DET_LOOKAHEAD];
+  INT      delta_energy_scale[QMF_MAX_TIME_SLOTS + TRAN_DET_LOOKAHEAD];
+
+  FIXP_DBL lowpass_energy[QMF_MAX_TIME_SLOTS + TRAN_DET_LOOKAHEAD];
+  INT      lowpass_energy_scale[QMF_MAX_TIME_SLOTS + TRAN_DET_LOOKAHEAD];
+#if defined (FTD_LOG)
+  FDKFILE *ftd_log;
+#endif
+}
+FAST_TRAN_DETECTOR;
+typedef FAST_TRAN_DETECTOR *HANDLE_FAST_TRAN_DET;
+
+
+INT FDKsbrEnc_InitSbrFastTransientDetector(
+        HANDLE_FAST_TRAN_DET h_sbrFastTransientDetector,
+        const INT time_slots_per_frame,
+        const INT bandwidth_qmf_slot,
+        const INT no_qmf_channels,
+        const INT sbr_qmf_1st_band
+        );
+
+void FDKsbrEnc_fastTransientDetect(
+        const HANDLE_FAST_TRAN_DET          h_sbrFastTransientDetector,
+        const FIXP_DBL              *const *Energies,
+        const int                   *const  scaleEnergies,
+        const INT                           YBufferWriteOffset,
+              UCHAR                 *const  tran_vector
+        );
+
 void
 FDKsbrEnc_transientDetect(HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector,
                           FIXP_DBL **Energies,
@@ -124,6 +176,7 @@
 
 int
 FDKsbrEnc_InitSbrTransientDetector (HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector,
+                            UINT  sbrSyntaxFlags, /* SBR syntax flags derived from AOT. */
                             INT   frameSize,
                             INT   sampleFreq,
                             sbrConfigurationPtr params,
@@ -145,6 +198,6 @@
                         int YBufferSzShift,
                         int nSfb,
                         int timeStep,
-                        int no_cols);
-
+                        int no_cols,
+                        FIXP_DBL* tonality);
 #endif
diff --git a/libSYS/src/genericStds.cpp b/libSYS/src/genericStds.cpp
index 53abe06..89c422c 100644
--- a/libSYS/src/genericStds.cpp
+++ b/libSYS/src/genericStds.cpp
@@ -92,14 +92,14 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 
-#include "genericStds.h"
-
 #include <math.h>
 
+#include "genericStds.h"
+
 /* library info */
 #define SYS_LIB_VL0 1
 #define SYS_LIB_VL1 3
-#define SYS_LIB_VL2 7
+#define SYS_LIB_VL2 8
 #define SYS_LIB_TITLE "System Integration Library"
 #ifdef __ANDROID__
 #define SYS_LIB_BUILD_DATE ""