changeset 681:1d8b08df98c3 trunk

[svn] - synchronise with FAAD 2.5
author nenolod
date Tue, 20 Feb 2007 04:37:37 -0800
parents 3a06665a810e
children de446ca64592
files ChangeLog src/aac/libfaad2/analysis.h src/aac/libfaad2/bits.c src/aac/libfaad2/bits.h src/aac/libfaad2/cfft.c src/aac/libfaad2/cfft.h src/aac/libfaad2/cfft_tab.h src/aac/libfaad2/codebook/hcb.h src/aac/libfaad2/codebook/hcb_1.h src/aac/libfaad2/codebook/hcb_10.h src/aac/libfaad2/codebook/hcb_11.h src/aac/libfaad2/codebook/hcb_2.h src/aac/libfaad2/codebook/hcb_3.h src/aac/libfaad2/codebook/hcb_4.h src/aac/libfaad2/codebook/hcb_5.h src/aac/libfaad2/codebook/hcb_6.h src/aac/libfaad2/codebook/hcb_7.h src/aac/libfaad2/codebook/hcb_8.h src/aac/libfaad2/codebook/hcb_9.h src/aac/libfaad2/codebook/hcb_sf.h src/aac/libfaad2/common.c src/aac/libfaad2/decoder.c src/aac/libfaad2/decoder.h src/aac/libfaad2/drc.c src/aac/libfaad2/drc.h src/aac/libfaad2/drm_dec.c src/aac/libfaad2/drm_dec.h src/aac/libfaad2/error.c src/aac/libfaad2/error.h src/aac/libfaad2/filtbank.c src/aac/libfaad2/filtbank.h src/aac/libfaad2/fixed.h src/aac/libfaad2/hcr.c src/aac/libfaad2/huffman.c src/aac/libfaad2/huffman.h src/aac/libfaad2/ic_predict.c src/aac/libfaad2/ic_predict.h src/aac/libfaad2/iq_table.h src/aac/libfaad2/is.c src/aac/libfaad2/is.h src/aac/libfaad2/kbd_win.h src/aac/libfaad2/lt_predict.c src/aac/libfaad2/lt_predict.h src/aac/libfaad2/mdct.c src/aac/libfaad2/mdct.h src/aac/libfaad2/mdct_tab.h src/aac/libfaad2/mp4.c src/aac/libfaad2/mp4.h src/aac/libfaad2/ms.c src/aac/libfaad2/ms.h src/aac/libfaad2/output.c src/aac/libfaad2/output.h src/aac/libfaad2/pns.c src/aac/libfaad2/pns.h src/aac/libfaad2/ps_dec.c src/aac/libfaad2/ps_dec.h src/aac/libfaad2/ps_syntax.c src/aac/libfaad2/ps_tables.h src/aac/libfaad2/pulse.c src/aac/libfaad2/pulse.h src/aac/libfaad2/rvlc.c src/aac/libfaad2/rvlc.h src/aac/libfaad2/sbr_dct.c src/aac/libfaad2/sbr_dct.h src/aac/libfaad2/sbr_dec.c src/aac/libfaad2/sbr_dec.h src/aac/libfaad2/sbr_e_nf.c src/aac/libfaad2/sbr_e_nf.h src/aac/libfaad2/sbr_fbt.c src/aac/libfaad2/sbr_fbt.h src/aac/libfaad2/sbr_hfadj.c src/aac/libfaad2/sbr_hfadj.h src/aac/libfaad2/sbr_hfgen.c src/aac/libfaad2/sbr_hfgen.h src/aac/libfaad2/sbr_huff.c src/aac/libfaad2/sbr_huff.h src/aac/libfaad2/sbr_noise.h src/aac/libfaad2/sbr_qmf.c src/aac/libfaad2/sbr_qmf.h src/aac/libfaad2/sbr_qmf_c.h src/aac/libfaad2/sbr_syntax.c src/aac/libfaad2/sbr_syntax.h src/aac/libfaad2/sbr_tf_grid.c src/aac/libfaad2/sbr_tf_grid.h src/aac/libfaad2/sine_win.h src/aac/libfaad2/specrec.c src/aac/libfaad2/specrec.h src/aac/libfaad2/ssr.c src/aac/libfaad2/ssr.h src/aac/libfaad2/ssr_fb.c src/aac/libfaad2/ssr_fb.h src/aac/libfaad2/ssr_ipqf.c src/aac/libfaad2/ssr_ipqf.h src/aac/libfaad2/ssr_win.h src/aac/libfaad2/structs.h src/aac/libfaad2/syntax.c src/aac/libfaad2/syntax.h src/aac/libfaad2/tns.c src/aac/libfaad2/tns.h
diffstat 99 files changed, 2568 insertions(+), 1535 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Feb 20 04:36:01 2007 -0800
+++ b/ChangeLog	Tue Feb 20 04:37:37 2007 -0800
@@ -1,3 +1,11 @@
+2007-02-20 12:36:01 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
+  revision [1446]
+  - satisfy Nero AG attribution requirement for FAAD 2.5 code import
+  
+  trunk/src/aac/src/libmp4.c |    1 +
+  1 file changed, 1 insertion(+)
+
+
 2007-02-20 12:13:46 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
   revision [1444]
   - remove a bunch of pointless code. we don't do ID3 for raw AAC files at this time.
--- a/src/aac/libfaad2/analysis.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/analysis.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: analysis.h,v 1.14 2004/09/04 14:56:27 menno Exp $
+** $Id: analysis.h,v 1.16 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __ANALYSIS_H__
--- a/src/aac/libfaad2/bits.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/bits.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,22 +14,26 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: bits.c,v 1.39 2004/09/04 14:56:27 menno Exp $
+** $Id: bits.c,v 1.42 2006/07/07 12:35:24 sur Exp $
 **/
 
 #include "common.h"
 #include "structs.h"
 
 #include <stdlib.h>
-#include <string.h>
 #include "bits.h"
 
 /* initialize buffer, call once before first getbits or showbits */
@@ -40,25 +44,38 @@
     if (ld == NULL)
         return;
 
-    memset(ld, 0, sizeof(bitfile));
+    // useless
+    //memset(ld, 0, sizeof(bitfile));
 
     if (buffer_size == 0 || _buffer == NULL)
     {
         ld->error = 1;
-        ld->no_more_reading = 1;
         return;
     }
 
-    ld->buffer = faad_malloc((buffer_size+12)*sizeof(uint8_t));
-    memset(ld->buffer, 0, (buffer_size+12)*sizeof(uint8_t));
-    memcpy(ld->buffer, _buffer, buffer_size*sizeof(uint8_t));
+    ld->buffer = _buffer;
 
     ld->buffer_size = buffer_size;
+    ld->bytes_left  = buffer_size;
 
-    tmp = getdword((uint32_t*)ld->buffer);
+    if (ld->bytes_left >= 4)
+    {
+        tmp = getdword((uint32_t*)ld->buffer);
+        ld->bytes_left -= 4;
+    } else {
+        tmp = getdword_n((uint32_t*)ld->buffer, ld->bytes_left);
+        ld->bytes_left = 0;
+    }
     ld->bufa = tmp;
 
-    tmp = getdword((uint32_t*)ld->buffer + 1);
+    if (ld->bytes_left >= 4)
+    {
+        tmp = getdword((uint32_t*)ld->buffer + 1);
+        ld->bytes_left -= 4;
+    } else {
+        tmp = getdword_n((uint32_t*)ld->buffer + 1, ld->bytes_left);
+        ld->bytes_left = 0;
+    }
     ld->bufb = tmp;
 
     ld->start = (uint32_t*)ld->buffer;
@@ -66,21 +83,12 @@
 
     ld->bits_left = 32;
 
-    ld->bytes_used = 0;
-    ld->no_more_reading = 0;
     ld->error = 0;
 }
 
 void faad_endbits(bitfile *ld)
 {
-    if (ld)
-    {
-        if (ld->buffer)
-        {
-            faad_free(ld->buffer);
-            ld->buffer = NULL;
-        }
-    }
+    // void
 }
 
 uint32_t faad_get_processed_bits(bitfile *ld)
@@ -90,12 +98,12 @@
 
 uint8_t faad_byte_align(bitfile *ld)
 {
-    uint8_t remainder = (uint8_t)((32 - ld->bits_left) % 8);
+    int remainder = (32 - ld->bits_left) & 0x7;
 
     if (remainder)
     {
         faad_flushbits(ld, 8 - remainder);
-        return (8 - remainder);
+        return (uint8_t)(8 - remainder);
     }
     return 0;
 }
@@ -105,20 +113,22 @@
     uint32_t tmp;
 
     ld->bufa = ld->bufb;
-    if (ld->no_more_reading == 0)
+    if (ld->bytes_left >= 4)
     {
         tmp = getdword(ld->tail);
-        ld->tail++;
+        ld->bytes_left -= 4;
     } else {
-        tmp = 0;
+        tmp = getdword_n(ld->tail, ld->bytes_left);
+        ld->bytes_left = 0;
     }
     ld->bufb = tmp;
+    ld->tail++;
     ld->bits_left += (32 - bits);
-    ld->bytes_used += 4;
-    if (ld->bytes_used == ld->buffer_size)
-        ld->no_more_reading = 1;
-    if (ld->bytes_used > ld->buffer_size)
-        ld->error = 1;
+    //ld->bytes_left -= 4;
+//    if (ld->bytes_left == 0)
+//        ld->no_more_reading = 1;
+//    if (ld->bytes_left < 0)
+//        ld->error = 1;
 }
 
 /* rewind to beginning */
@@ -126,30 +136,79 @@
 {
     uint32_t tmp;
 
-    tmp = ld->start[0];
-#ifndef ARCH_IS_BIG_ENDIAN
-    BSWAP(tmp);
-#endif
+    ld->bytes_left = ld->buffer_size;
+
+    if (ld->bytes_left >= 4)
+    {
+        tmp = getdword((uint32_t*)&ld->start[0]);
+        ld->bytes_left -= 4;
+    } else {
+        tmp = getdword_n((uint32_t*)&ld->start[0], ld->bytes_left);
+        ld->bytes_left = 0;
+    }
     ld->bufa = tmp;
 
-    tmp = ld->start[1];
-#ifndef ARCH_IS_BIG_ENDIAN
-    BSWAP(tmp);
-#endif
+    if (ld->bytes_left >= 4)
+    {
+        tmp = getdword((uint32_t*)&ld->start[1]);
+        ld->bytes_left -= 4;
+    } else {
+        tmp = getdword_n((uint32_t*)&ld->start[1], ld->bytes_left);
+        ld->bytes_left = 0;
+    }
     ld->bufb = tmp;
+
     ld->bits_left = 32;
     ld->tail = &ld->start[2];
-    ld->bytes_used = 0;
-    ld->no_more_reading = 0;
+}
+
+/* reset to a certain point */
+void faad_resetbits(bitfile *ld, int bits)
+{
+    uint32_t tmp;
+    int words = bits >> 5;
+    int remainder = bits & 0x1F;
+
+    ld->bytes_left = ld->buffer_size - words*4;
+
+    if (ld->bytes_left >= 4)
+    {
+        tmp = getdword(&ld->start[words]);
+        ld->bytes_left -= 4;
+    } else {
+        tmp = getdword_n(&ld->start[words], ld->bytes_left);
+        ld->bytes_left = 0;
+    }
+    ld->bufa = tmp;
+
+    if (ld->bytes_left >= 4)
+    {
+        tmp = getdword(&ld->start[words+1]);
+        ld->bytes_left -= 4;
+    } else {
+        tmp = getdword_n(&ld->start[words+1], ld->bytes_left);
+        ld->bytes_left = 0;
+    }
+    ld->bufb = tmp;
+
+    ld->bits_left = 32 - remainder;
+    ld->tail = &ld->start[words+2];
+
+    /* recheck for reading too many bytes */
+    ld->error = 0;
+//    if (ld->bytes_left == 0)
+//        ld->no_more_reading = 1;
+//    if (ld->bytes_left < 0)
+//        ld->error = 1;
 }
 
 uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
                        DEBUGDEC)
 {
-    uint16_t i;
-    uint8_t temp;
-    uint16_t bytes = (uint16_t)bits / 8;
-    uint8_t remainder = (uint8_t)bits % 8;
+    int i;
+    unsigned int temp;
+    int bytes = bits >> 3;
+    int remainder = bits & 0x7;
 
     uint8_t *buffer = (uint8_t*)faad_malloc((bytes+1)*sizeof(uint8_t));
 
@@ -160,9 +219,9 @@
 
     if (remainder)
     {
-        temp = (uint8_t)faad_getbits(ld, remainder DEBUGVAR(print,var,dbg)) << (8-remainder);
+        temp = faad_getbits(ld, remainder DEBUGVAR(print,var,dbg)) << (8-remainder);
 
-        buffer[bytes] = temp;
+        buffer[bytes] = (uint8_t)temp;
     }
 
     return buffer;
@@ -207,7 +266,8 @@
     if (ld->bits_left == 0)
         ld->bits_left = 32;
 
-    ld->bytes_used = 0;
-    ld->no_more_reading = 0;
+    ld->bytes_left = ld->buffer_size;
     ld->error = 0;
 }
+
+/* EOF */
--- a/src/aac/libfaad2/bits.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/bits.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: bits.h,v 1.40 2004/09/04 14:56:27 menno Exp $
+** $Id: bits.h,v 1.42 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __BITS_H__
@@ -37,8 +42,10 @@
 #include <stdio.h>
 #endif
 
-#define BYTE_NUMBIT 8
-#define bit2byte(a) ((a+7)/BYTE_NUMBIT)
+#define BYTE_NUMBIT     8
+#define BYTE_NUMBIT_LD  3
+//#define bit2byte(a) ((a+7)/BYTE_NUMBIT)
+#define bit2byte(a) ((a+7)>>BYTE_NUMBIT_LD)
 
 typedef struct _bitfile
 {
@@ -47,25 +54,16 @@
     uint32_t bufb;
     uint32_t bits_left;
     uint32_t buffer_size; /* size of the buffer in bytes */
-    uint32_t bytes_used;
-    uint8_t no_more_reading;
+    uint32_t bytes_left;
     uint8_t error;
     uint32_t *tail;
     uint32_t *start;
-    void *buffer;
+    const void *buffer;
 } bitfile;
 
 
-#if defined (_WIN32) && !defined(_WIN32_WCE) && !defined(__MINGW32__)
-#define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
-#elif defined(LINUX) || defined(DJGPP) || defined(__MINGW32__)
-#define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) )
-#else
-#define BSWAP(a) \
-    ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))
-#endif
-
-static uint32_t bitmask[] = {
+#if 0
+static uint32_t const bitmask[] = {
     0x0, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF,
     0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF,
     0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF,
@@ -74,6 +72,7 @@
     /* added bitmask 32, correct?!?!?! */
     , 0xFFFFFFFF
 };
+#endif
 
 void faad_initbits(bitfile *ld, const void *buffer, const uint32_t buffer_size);
 void faad_endbits(bitfile *ld);
@@ -83,6 +82,7 @@
 uint32_t faad_get_processed_bits(bitfile *ld);
 void faad_flushbits_ex(bitfile *ld, uint32_t bits);
 void faad_rewindbits(bitfile *ld);
+void faad_resetbits(bitfile *ld, int bits);
 uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
                        DEBUGDEC);
 #ifdef DRM
@@ -93,7 +93,6 @@
 /* circumvent memory alignment errors on ARM */
 static INLINE uint32_t getdword(void *mem)
 {
-#ifdef ARM
     uint32_t tmp;
 #ifndef ARCH_IS_BIG_ENDIAN
     ((uint8_t*)&tmp)[0] = ((uint8_t*)mem)[3];
@@ -108,25 +107,52 @@
 #endif
 
     return tmp;
-#else
-    uint32_t tmp;
-    tmp = *(uint32_t*)mem;
+}
+
+/* reads only n bytes from the stream instead of the standard 4 */
+static /*INLINE*/ uint32_t getdword_n(void *mem, int n)
+{
+    uint32_t tmp = 0;
 #ifndef ARCH_IS_BIG_ENDIAN
-    BSWAP(tmp);
+    switch (n)
+    {
+    case 3:
+        ((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[2];
+    case 2:
+        ((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[1];
+    case 1:
+        ((uint8_t*)&tmp)[3] = ((uint8_t*)mem)[0];
+    default:
+        break;
+    }
+#else
+    switch (n)
+    {
+    case 3:
+        ((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[2];
+    case 2:
+        ((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[1];
+    case 1:
+        ((uint8_t*)&tmp)[0] = ((uint8_t*)mem)[0];
+    default:
+        break;
+    }
 #endif
+
     return tmp;
-#endif
 }
 
 static INLINE uint32_t faad_showbits(bitfile *ld, uint32_t bits)
 {
     if (bits <= ld->bits_left)
     {
-        return (ld->bufa >> (ld->bits_left - bits)) & bitmask[bits];
+        //return (ld->bufa >> (ld->bits_left - bits)) & bitmask[bits];
+        return (ld->bufa << (32 - ld->bits_left)) >> (32 - bits);
     }
 
     bits -= ld->bits_left;
-    return ((ld->bufa & bitmask[ld->bits_left]) << bits) | (ld->bufb >> (32 - bits));
+    //return ((ld->bufa & bitmask[ld->bits_left]) << bits) | (ld->bufb >> (32 - bits));
+    return ((ld->bufa & ((1<<ld->bits_left)-1)) << bits) | (ld->bufb >> (32 - bits));
 }
 
 static INLINE void faad_flushbits(bitfile *ld, uint32_t bits)
@@ -144,11 +170,11 @@
 }
 
 /* return next n bits (right adjusted) */
-static INLINE uint32_t faad_getbits(bitfile *ld, uint32_t n DEBUGDEC)
+static /*INLINE*/ uint32_t faad_getbits(bitfile *ld, uint32_t n DEBUGDEC)
 {
     uint32_t ret;
 
-    if (ld->no_more_reading || n == 0)
+    if (n == 0)
         return 0;
 
     ret = faad_showbits(ld, n);
@@ -230,22 +256,19 @@
         ld->start--;
         ld->bits_left += (32 - bits);
 
-        ld->bytes_used += 4;
-        if (ld->bytes_used == ld->buffer_size)
-            ld->no_more_reading = 1;
-        if (ld->bytes_used > ld->buffer_size)
+        ld->bytes_left -= 4;
+//        if (ld->bytes_left == 0)
+//            ld->no_more_reading = 1;
+        if (ld->bytes_left < 0)
             ld->error = 1;
     }
 }
 
-static INLINE uint32_t faad_getbits_rev(bitfile *ld, uint32_t n
+static /*INLINE*/ uint32_t faad_getbits_rev(bitfile *ld, uint32_t n
                                         DEBUGDEC)
 {
     uint32_t ret;
 
-    if (ld->no_more_reading)
-        return 0;
-
     if (n == 0)
         return 0;
 
@@ -261,28 +284,73 @@
 }
 
 #ifdef DRM
+/* CRC lookup table for G8 polynome in DRM standard */
+static const uint8_t crc_table_G8[256] = {
+    0x0, 0x1d, 0x3a, 0x27, 0x74, 0x69, 0x4e, 0x53,
+    0xe8, 0xf5, 0xd2, 0xcf, 0x9c, 0x81, 0xa6, 0xbb,
+    0xcd, 0xd0, 0xf7, 0xea, 0xb9, 0xa4, 0x83, 0x9e,
+    0x25, 0x38, 0x1f, 0x2, 0x51, 0x4c, 0x6b, 0x76,
+    0x87, 0x9a, 0xbd, 0xa0, 0xf3, 0xee, 0xc9, 0xd4,
+    0x6f, 0x72, 0x55, 0x48, 0x1b, 0x6, 0x21, 0x3c,
+    0x4a, 0x57, 0x70, 0x6d, 0x3e, 0x23, 0x4, 0x19,
+    0xa2, 0xbf, 0x98, 0x85, 0xd6, 0xcb, 0xec, 0xf1,
+    0x13, 0xe, 0x29, 0x34, 0x67, 0x7a, 0x5d, 0x40,
+    0xfb, 0xe6, 0xc1, 0xdc, 0x8f, 0x92, 0xb5, 0xa8,
+    0xde, 0xc3, 0xe4, 0xf9, 0xaa, 0xb7, 0x90, 0x8d,
+    0x36, 0x2b, 0xc, 0x11, 0x42, 0x5f, 0x78, 0x65,
+    0x94, 0x89, 0xae, 0xb3, 0xe0, 0xfd, 0xda, 0xc7,
+    0x7c, 0x61, 0x46, 0x5b, 0x8, 0x15, 0x32, 0x2f,
+    0x59, 0x44, 0x63, 0x7e, 0x2d, 0x30, 0x17, 0xa,
+    0xb1, 0xac, 0x8b, 0x96, 0xc5, 0xd8, 0xff, 0xe2,
+    0x26, 0x3b, 0x1c, 0x1, 0x52, 0x4f, 0x68, 0x75,
+    0xce, 0xd3, 0xf4, 0xe9, 0xba, 0xa7, 0x80, 0x9d,
+    0xeb, 0xf6, 0xd1, 0xcc, 0x9f, 0x82, 0xa5, 0xb8,
+    0x3, 0x1e, 0x39, 0x24, 0x77, 0x6a, 0x4d, 0x50,
+    0xa1, 0xbc, 0x9b, 0x86, 0xd5, 0xc8, 0xef, 0xf2,
+    0x49, 0x54, 0x73, 0x6e, 0x3d, 0x20, 0x7, 0x1a,
+    0x6c, 0x71, 0x56, 0x4b, 0x18, 0x5, 0x22, 0x3f,
+    0x84, 0x99, 0xbe, 0xa3, 0xf0, 0xed, 0xca, 0xd7,
+    0x35, 0x28, 0xf, 0x12, 0x41, 0x5c, 0x7b, 0x66,
+    0xdd, 0xc0, 0xe7, 0xfa, 0xa9, 0xb4, 0x93, 0x8e,
+    0xf8, 0xe5, 0xc2, 0xdf, 0x8c, 0x91, 0xb6, 0xab,
+    0x10, 0xd, 0x2a, 0x37, 0x64, 0x79, 0x5e, 0x43,
+    0xb2, 0xaf, 0x88, 0x95, 0xc6, 0xdb, 0xfc, 0xe1,
+    0x5a, 0x47, 0x60, 0x7d, 0x2e, 0x33, 0x14, 0x9,
+    0x7f, 0x62, 0x45, 0x58, 0xb, 0x16, 0x31, 0x2c,
+    0x97, 0x8a, 0xad, 0xb0, 0xe3, 0xfe, 0xd9, 0xc4,
+};
+
 static uint8_t faad_check_CRC(bitfile *ld, uint16_t len)
 {
-    uint8_t CRC;
-    uint16_t r=255;  /* Initialize to all ones */
+    int bytes, rem;
+    unsigned int CRC;
+    unsigned int r=255;  /* Initialize to all ones */
 
     /* CRC polynome used x^8 + x^4 + x^3 + x^2 +1 */
 #define GPOLY 0435
 
     faad_rewindbits(ld);
 
-    CRC = (uint8_t) ~faad_getbits(ld, 8
-        DEBUGVAR(1,999,"faad_check_CRC(): CRC"));          /* CRC is stored inverted */
+    CRC = (unsigned int) ~faad_getbits(ld, 8
+        DEBUGVAR(1,999,"faad_check_CRC(): CRC")) & 0xFF;          /* CRC is stored inverted */
+
+    bytes = len >> 3;
+    rem = len & 0x7;
 
-    for (; len>0; len--)
+    for (; bytes > 0; bytes--)
+    {
+        r = crc_table_G8[( r ^ faad_getbits(ld, 8 DEBUGVAR(1,998,"")) ) & 0xFF];
+    }
+    for (; rem > 0; rem--)
     {
         r = ( (r << 1) ^ (( ( faad_get1bit(ld
             DEBUGVAR(1,998,""))  & 1) ^ ((r >> 7) & 1)) * GPOLY )) & 0xFF;
     }
 
     if (r != CRC)
+  //  if (0)
     {
-        return 8;
+        return 28;
     } else {
         return 0;
     }
--- a/src/aac/libfaad2/cfft.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/cfft.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: cfft.c,v 1.30 2004/09/08 09:43:11 gcp Exp $
+** $Id: cfft.c,v 1.33 2006/08/07 18:09:05 menno Exp $
 **/
 
 /*
@@ -546,7 +551,7 @@
                 ComplexMult(&RE(c4), &RE(c5),
                     ti12, ti11, RE(t5), RE(t4));
                 ComplexMult(&IM(c4), &IM(c5),
-                    ti12, ti12, IM(t5), IM(t4));
+                    ti12, ti11, IM(t5), IM(t4));
 
                 RE(ch[ah+l1]) = RE(c2) + IM(c5);
                 IM(ch[ah+l1]) = IM(c2) - RE(c5);
@@ -648,7 +653,7 @@
                     ComplexMult(&RE(c4), &RE(c5),
                         ti12, ti11, RE(t5), RE(t4));
                     ComplexMult(&IM(c4), &IM(c5),
-                        ti12, ti12, IM(t5), IM(t4));
+                        ti12, ti11, IM(t5), IM(t4));
 
                     IM(d2) = IM(c2) - RE(c5);
                     IM(d3) = IM(c3) - RE(c4);
--- a/src/aac/libfaad2/cfft.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/cfft.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: cfft.h,v 1.20 2004/09/08 09:43:11 gcp Exp $
+** $Id: cfft.h,v 1.22 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __CFFT_H__
--- a/src/aac/libfaad2/cfft_tab.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/cfft_tab.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: cfft_tab.h,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: cfft_tab.h,v 1.19 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __CFFT_TAB_H__
--- a/src/aac/libfaad2/codebook/hcb.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb.h,v 1.6 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb.h,v 1.7 2006/05/07 18:09:41 menno Exp $
 **/
 
 #ifndef __HCB_H__
--- a/src/aac/libfaad2/codebook/hcb_1.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_1.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_1.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_1.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* 2-step huffman table HCB_1 */
--- a/src/aac/libfaad2/codebook/hcb_10.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_10.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_10.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_10.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* 2-step huffman table HCB_10 */
--- a/src/aac/libfaad2/codebook/hcb_11.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_11.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_11.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_11.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* 2-step huffman table HCB_11 */
--- a/src/aac/libfaad2/codebook/hcb_2.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_2.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_2.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_2.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* 2-step huffman table HCB_2 */
--- a/src/aac/libfaad2/codebook/hcb_3.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_3.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_3.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_3.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* Binary search huffman table HCB_3 */
--- a/src/aac/libfaad2/codebook/hcb_4.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_4.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_4.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_4.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* 2-step huffman table HCB_4 */
--- a/src/aac/libfaad2/codebook/hcb_5.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_5.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_5.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_5.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* Binary search huffman table HCB_5 */
--- a/src/aac/libfaad2/codebook/hcb_6.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_6.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_6.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_6.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* 2-step huffman table HCB_6 */
--- a/src/aac/libfaad2/codebook/hcb_7.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_7.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_7.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_7.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* Binary search huffman table HCB_7 */
--- a/src/aac/libfaad2/codebook/hcb_8.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_8.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_8.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_8.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* 2-step huffman table HCB_8 */
--- a/src/aac/libfaad2/codebook/hcb_9.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_9.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_9.h,v 1.3 2003/09/09 18:12:01 menno Exp $
+** $Id: hcb_9.h,v 1.4 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* Binary search huffman table HCB_9 */
--- a/src/aac/libfaad2/codebook/hcb_sf.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/codebook/hcb_sf.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcb_sf.h,v 1.5 2004/02/04 19:55:02 menno Exp $
+** $Id: hcb_sf.h,v 1.6 2006/05/07 18:09:41 menno Exp $
 **/
 
 /* Binary search huffman table HCB_SF */
--- a/src/aac/libfaad2/common.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/common.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: common.c,v 1.22 2004/09/08 09:43:11 gcp Exp $
+** $Id: common.c,v 1.24 2006/05/07 18:09:00 menno Exp $
 **/
 
 /* just some common functions that could be used anywhere */
@@ -229,16 +234,16 @@
  *  which gives a period of 18.410.713.077.675.721.215. The result is the
  *  XORed values of both generators.
  */
-uint32_t random_int(void)
+uint32_t ne_rng(uint32_t *__r1, uint32_t *__r2)
 {
     uint32_t  t1, t2, t3, t4;
 
-    t3   = t1 = __r1;   t4   = t2 = __r2;       // Parity calculation is done via table lookup, this is also available
+    t3   = t1 = *__r1;  t4   = t2 = *__r2;      // Parity calculation is done via table lookup, this is also available
     t1  &= 0xF5;        t2 >>= 25;              // on CPUs without parity, can be implemented in C and avoid unpredictable
     t1   = Parity [t1]; t2  &= 0x63;            // jumps and slow rotate through the carry flag operations.
     t1 <<= 31;          t2   = Parity [t2];
 
-    return (__r1 = (t3 >> 1) | t1 ) ^ (__r2 = (t4 + t4) | t2 );
+    return (*__r1 = (t3 >> 1) | t1 ) ^ (*__r2 = (t4 + t4) | t2 );
 }
 
 uint32_t ones32(uint32_t x)
--- a/src/aac/libfaad2/decoder.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/decoder.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: decoder.c,v 1.107 2004/09/08 09:43:11 gcp Exp $
+** $Id: decoder.c,v 1.109 2006/05/07 18:09:00 menno Exp $
 **/
 
 #include "common.h"
@@ -116,6 +121,9 @@
     hDecoder->frame = 0;
     hDecoder->sample_buffer = NULL;
 
+    hDecoder->__r1 = 1;
+    hDecoder->__r2 = 1;
+
     for (i = 0; i < MAX_CHANNELS; i++)
     {
         hDecoder->window_shape_prev[i] = 0;
@@ -194,6 +202,7 @@
     return 0;
 }
 
+
 int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer,
                                  uint32_t buffer_size,
                                  uint32_t *samplerate, uint8_t *channels)
@@ -203,6 +212,7 @@
     adif_header adif;
     adts_header adts;
 
+
     if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL))
         return -1;
 
@@ -257,7 +267,6 @@
         }
         faad_endbits(&ld);
     }
-    hDecoder->channelConfiguration = *channels;
 
 #if (defined(PS_DEC) || defined(DRM_PS))
     /* check if we have a mono file */
@@ -268,6 +277,8 @@
     }
 #endif
 
+    hDecoder->channelConfiguration = *channels;
+
 #ifdef SBR_DEC
     /* implicit signalling */
     if (*samplerate <= 24000 && !(hDecoder->config.dontUpSampleImplicitSBR))
@@ -422,8 +433,8 @@
     if ((channels == DRMCH_MONO) || (channels == DRMCH_STEREO))
         (*hDecoder)->sbr_present_flag = 0;
     else
-        (*hDecoder)->sbr_present_flag = 1;    
-#endif        
+        (*hDecoder)->sbr_present_flag = 1;
+#endif
 
     (*hDecoder)->fb = filter_bank_init((*hDecoder)->frameLength);
 
@@ -525,8 +536,14 @@
         chdir = hInfo->num_front_channels;
         if (chdir & 1)
         {
+#if (defined(PS_DEC) || defined(DRM_PS))
+            /* When PS is enabled output is always stereo */
+            hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT;
+            hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT;
+#else
             hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER;
             chdir--;
+#endif
         }
         for (i = 0; i < chdir; i += 2)
         {
@@ -565,8 +582,15 @@
         switch (hDecoder->channelConfiguration)
         {
         case 1:
+#if (defined(PS_DEC) || defined(DRM_PS))
+            /* When PS is enabled output is always stereo */
+            hInfo->num_front_channels = 2;
+            hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
+            hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
+#else
             hInfo->num_front_channels = 1;
             hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
+#endif
             break;
         case 2:
             hInfo->num_front_channels = 2;
@@ -722,13 +746,25 @@
         sample_buffer, sample_buffer_size);
 }
 
+#ifdef DRM
+
+#define ERROR_STATE_INIT 6
+
+static void conceal_output(NeAACDecHandle hDecoder, uint16_t frame_len,
+                           uint8_t out_ch, void *sample_buffer)
+{
+    return;
+}
+#endif
+
 static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
                               uint8_t *buffer, uint32_t buffer_size,
                               void **sample_buffer2, uint32_t sample_buffer_size)
 {
+    uint16_t i;
     uint8_t channels = 0;
     uint8_t output_channels = 0;
-    bitfile ld;
+    bitfile ld = {0};
     uint32_t bitsconsumed;
     uint16_t frame_len;
     void *sample_buffer;
@@ -753,6 +789,33 @@
     memset(hInfo, 0, sizeof(NeAACDecFrameInfo));
     memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0]));
 
+#ifdef USE_TIME_LIMIT
+    if ((TIME_LIMIT * get_sample_rate(hDecoder->sf_index)) > hDecoder->TL_count)
+    {
+        hDecoder->TL_count += 1024;
+    } else {
+        hInfo->error = (NUM_ERROR_MESSAGES-1);
+        goto error;
+    }
+#endif
+
+
+    /* check for some common metadata tag types in the bitstream
+     * No need to return an error
+     */
+    /* ID3 */
+    if (buffer_size >= 128)
+    {
+        if (memcmp(buffer, "TAG", 3) == 0)
+        {
+            /* found it */
+            hInfo->bytesconsumed = 128; /* 128 bytes fixed size */
+            /* no error, but no output either */
+            return NULL;
+        }
+    }
+
+
     /* initialize the bitstream */
     faad_initbits(&ld, buffer, buffer_size);
 
@@ -780,7 +843,7 @@
         /* We do not support stereo right now */
         if (0) //(hDecoder->channelConfiguration == 2)
         {
-            hInfo->error = 8; // Throw CRC error
+            hInfo->error = 28; // Throw CRC error
             goto error;
         }
 
@@ -808,14 +871,14 @@
 #endif
 
     /* decode the complete bitstream */
-#ifdef SCALABLE_DEC
-    if ((hDecoder->object_type == 6) || (hDecoder->object_type == DRM_ER_LC))
+#ifdef DRM
+    if (/*(hDecoder->object_type == 6) ||*/ (hDecoder->object_type == DRM_ER_LC))
     {
-        aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
+        DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
     } else {
 #endif
         raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
-#ifdef SCALABLE_DEC
+#ifdef DRM
     }
 #endif
 
@@ -978,10 +1041,16 @@
     }
 #endif
 
+
     sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer,
         output_channels, frame_len, hDecoder->config.outputFormat);
 
 
+#ifdef DRM
+    //conceal_output(hDecoder, frame_len, output_channels, sample_buffer);
+#endif
+
+
     hDecoder->postSeekResetFlag = 0;
 
     hDecoder->frame++;
@@ -1013,6 +1082,30 @@
 
 error:
 
+
+#ifdef DRM
+    hDecoder->error_state = ERROR_STATE_INIT;
+#endif
+
+    /* reset filterbank state */
+    for (i = 0; i < MAX_CHANNELS; i++)
+    {
+        if (hDecoder->fb_intermed[i] != NULL)
+        {
+            memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t));
+        }
+    }
+#ifdef SBR_DEC
+    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
+    {
+        if (hDecoder->sbr[i] != NULL)
+        {
+            sbrReset(hDecoder->sbr[i]);
+        }
+    }
+#endif
+
+
     faad_endbits(&ld);
 
     /* cleanup */
--- a/src/aac/libfaad2/decoder.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/decoder.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: decoder.h,v 1.44 2004/09/04 14:56:28 menno Exp $
+** $Id: decoder.h,v 1.46 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __DECODER_H__
--- a/src/aac/libfaad2/drc.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/drc.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: drc.c,v 1.24 2004/09/04 14:56:28 menno Exp $
+** $Id: drc.c,v 1.26 2006/05/07 18:09:00 menno Exp $
 **/
 
 #include "common.h"
--- a/src/aac/libfaad2/drc.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/drc.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: drc.h,v 1.18 2004/09/04 14:56:28 menno Exp $
+** $Id: drc.h,v 1.20 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __DRC_H__
--- a/src/aac/libfaad2/drm_dec.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/drm_dec.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
-** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR and PS decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: drm_dec.c,v 1.5 2004/09/04 14:56:28 menno Exp $
+** $Id: drm_dec.c,v 1.7 2006/05/07 18:09:00 menno Exp $
 **/
 
 #include <stdlib.h>
@@ -243,17 +248,9 @@
     { FRAC_CONST(0.929071574),  FRAC_CONST(0)           }
 };
 
-static const uint8_t sa_freq_scale[9][2] = 
+static const uint8_t sa_freq_scale[9] = 
 {
-    { 0, 0},  
-    { 1, 1},  
-    { 2, 2},  
-    { 3, 3},  
-    { 5, 5},  
-    { 7, 7},  
-    {10,10},  
-    {13,13},  
-    {46,23}
+    0, 1, 2, 3, 5, 7, 10, 13, 23
 };
 
 static const uint8_t pan_freq_scale[21] = 
@@ -290,9 +287,9 @@
     FRAC_CONST(0.48954165955695)
 };
 
-static const uint8_t delay_length[][2] = 
+static const uint8_t delay_length[3] = 
 {
-    { 1, 3 }, { 2, 4 }, { 3, 5 }
+    3, 4, 5
 };
 
 static const real_t delay_fraction[] = 
@@ -300,15 +297,9 @@
     FRAC_CONST(0.43), FRAC_CONST(0.75), FRAC_CONST(0.347)
 };
 
-static const real_t peak_decay[2] = 
-{
-    FRAC_CONST(0.58664621951003), FRAC_CONST(0.76592833836465)
-};
+static const real_t peak_decay = FRAC_CONST(0.76592833836465);
 
-static const real_t smooth_coeff[2] = 
-{
-    FRAC_CONST(0.6), FRAC_CONST(0.25)
-};
+static const real_t smooth_coeff = FRAC_CONST(0.25);
 
 /* Please note that these are the same tables as in plain PS */
 static const complex_t Q_Fract_allpass_Qmf[][3] = {
@@ -566,25 +557,22 @@
     {    
         if (ps->bs_sa_dt_flag && !ps->g_last_had_sa) 
         {        
-            for (band = 0; band < DRM_NUM_SA_BANDS; band++)
-            {   
-                ps->g_prev_sa_index[band] = 0;
-            }           
-        }       
-        if (ps->bs_sa_dt_flag)
-        {
+            /* wait until we get a DT frame */
+            ps->bs_enable_sa = 0;
+        } else if (ps->bs_sa_dt_flag) {
+            /* DT frame, we have a last frame, so we can decode */
             ps->g_sa_index[0] = sa_delta_clip(ps, ps->g_prev_sa_index[0]+ps->bs_sa_data[0]);            
-
         } else {
+            /* DF always decodable */
             ps->g_sa_index[0] = sa_delta_clip(ps,ps->bs_sa_data[0]);          
         }
         
         for (band = 1; band < DRM_NUM_SA_BANDS; band++)
         {   
-            if (ps->bs_sa_dt_flag)
+            if (ps->bs_sa_dt_flag && ps->g_last_had_sa)
             {
                 ps->g_sa_index[band] = sa_delta_clip(ps, ps->g_prev_sa_index[band] + ps->bs_sa_data[band]);
-            } else {
+            } else if (!ps->bs_sa_dt_flag) {
                 ps->g_sa_index[band] = sa_delta_clip(ps, ps->g_sa_index[band-1] + ps->bs_sa_data[band]);                
             }
         }
@@ -618,28 +606,19 @@
     {
         if (ps->bs_pan_dt_flag && !ps->g_last_had_pan) 
         {
-/* The DRM PS spec doesn't say anything about this case. (deltacoded in time without a previous frame)
-   AAC PS spec you must tread previous frame as 0, so that's what we try. 
-*/
-            for (band = 0; band < DRM_NUM_PAN_BANDS; band++)
-            {   
-                ps->g_prev_pan_index[band] = 0;
-            }
-        } 
-
-        if (ps->bs_pan_dt_flag)
-        {   
-             ps->g_pan_index[0] = pan_delta_clip(ps,  ps->g_prev_pan_index[0]+ps->bs_pan_data[0]);
+            ps->bs_enable_pan = 0;
+        }  else if (ps->bs_pan_dt_flag) {   
+            ps->g_pan_index[0] = pan_delta_clip(ps,  ps->g_prev_pan_index[0]+ps->bs_pan_data[0]);
         } else {
-             ps->g_pan_index[0] = pan_delta_clip(ps, ps->bs_pan_data[0]);
+            ps->g_pan_index[0] = pan_delta_clip(ps, ps->bs_pan_data[0]);
         }
     
         for (band = 1; band < DRM_NUM_PAN_BANDS; band++)
         {   
-            if (ps->bs_pan_dt_flag)
+            if (ps->bs_pan_dt_flag && ps->g_last_had_pan)
             {
                 ps->g_pan_index[band] = pan_delta_clip(ps, ps->g_prev_pan_index[band] + ps->bs_pan_data[band]);
-            } else {
+            } else if (!ps->bs_pan_dt_flag) {
                 ps->g_pan_index[band] = pan_delta_clip(ps, ps->g_pan_index[band-1] + ps->bs_pan_data[band]);
             }
         }
@@ -658,7 +637,7 @@
     }
 }
 
-static void drm_calc_sa_side_signal(drm_ps_info *ps, qmf_t X[38][64], uint8_t rateselect) 
+static void drm_calc_sa_side_signal(drm_ps_info *ps, qmf_t X[38][64]) 
 {      
     uint8_t s, b, k;
     complex_t qfrac, tmp0, tmp, in, R0;
@@ -673,7 +652,7 @@
     uint32_t in_re, in_im;
 #endif
 
-    for (b = 0; b < sa_freq_scale[DRM_NUM_SA_BANDS][rateselect]; b++)
+    for (b = 0; b < sa_freq_scale[DRM_NUM_SA_BANDS]; b++)
     {
         /* set delay indices */    
         for (k = 0; k < NUM_OF_LINKS; k++)
@@ -701,16 +680,16 @@
             power = MUL_R(RE(in),RE(in)) + MUL_R(IM(in),IM(in));
 #endif
 
-            ps->peakdecay_fast[b] = MUL_F(ps->peakdecay_fast[b], peak_decay[rateselect]);
+            ps->peakdecay_fast[b] = MUL_F(ps->peakdecay_fast[b], peak_decay);
             if (ps->peakdecay_fast[b] < power)
                 ps->peakdecay_fast[b] = power;
 
             peakdiff = ps->prev_peakdiff[b];
-            peakdiff += MUL_F((ps->peakdecay_fast[b] - power - ps->prev_peakdiff[b]), smooth_coeff[rateselect]);
+            peakdiff += MUL_F((ps->peakdecay_fast[b] - power - ps->prev_peakdiff[b]), smooth_coeff);
             ps->prev_peakdiff[b] = peakdiff;
 
             nrg = ps->prev_nrg[b];
-            nrg += MUL_F((power - ps->prev_nrg[b]), smooth_coeff[rateselect]);
+            nrg += MUL_F((power - ps->prev_nrg[b]), smooth_coeff);
             ps->prev_nrg[b] = nrg;
 
             if (MUL_R(peakdiff, gamma) <= nrg) {
@@ -763,7 +742,7 @@
 
             for (k = 0; k < NUM_OF_LINKS; k++)
             {
-                if (++temp_delay_ser[k] >= delay_length[k][rateselect])
+                if (++temp_delay_ser[k] >= delay_length[k])
                     temp_delay_ser[k] = 0;
             }
         }       
@@ -773,7 +752,7 @@
         ps->delay_buf_index_ser[k] = temp_delay_ser[k];
 }
 
-static void drm_add_ambiance(drm_ps_info *ps, uint8_t rateselect, qmf_t X_left[38][64], qmf_t X_right[38][64]) 
+static void drm_add_ambiance(drm_ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64]) 
 {
     uint8_t s, b, ifreq, qclass;    
     real_t sa_map[MAX_SA_BAND], sa_dir_map[MAX_SA_BAND], k_sa_map[MAX_SA_BAND], k_sa_dir_map[MAX_SA_BAND];
@@ -783,7 +762,7 @@
     {
         /* Instead of dequantization and mapping, we use an inverse mapping
            to look up all the values we need */
-        for (b = 0; b < sa_freq_scale[DRM_NUM_SA_BANDS][rateselect]; b++)
+        for (b = 0; b < sa_freq_scale[DRM_NUM_SA_BANDS]; b++)
         {
             const real_t inv_f_num_of_subsamples = FRAC_CONST(0.03333333333);
 
@@ -804,7 +783,7 @@
 
         for (s = 0; s < NUM_OF_SUBSAMPLES; s++)
         {
-            for (b = 0; b < sa_freq_scale[DRM_NUM_SA_BANDS][rateselect]; b++)
+            for (b = 0; b < sa_freq_scale[DRM_NUM_SA_BANDS]; b++)
             {                
                 QMF_RE(X_right[s][b]) = MUL_F(QMF_RE(X_left[s][b]), sa_dir_map[b]) - MUL_F(QMF_RE(ps->SA[s][b]), sa_map[b]);
                 QMF_IM(X_right[s][b]) = MUL_F(QMF_IM(X_left[s][b]), sa_dir_map[b]) - MUL_F(QMF_IM(ps->SA[s][b]), sa_map[b]);
@@ -814,7 +793,7 @@
                 sa_map[b]     += k_sa_map[b];
                 sa_dir_map[b] += k_sa_dir_map[b];
             }
-            for (b = sa_freq_scale[DRM_NUM_SA_BANDS][rateselect]; b < NUM_OF_QMF_CHANNELS; b++)
+            for (b = sa_freq_scale[DRM_NUM_SA_BANDS]; b < NUM_OF_QMF_CHANNELS; b++)
             {                
                 QMF_RE(X_right[s][b]) = QMF_RE(X_left[s][b]);
                 QMF_IM(X_right[s][b]) = QMF_IM(X_left[s][b]);
@@ -833,7 +812,7 @@
     }
 }
 
-static void drm_add_pan(drm_ps_info *ps, uint8_t rateselect, qmf_t X_left[38][64], qmf_t X_right[38][64]) 
+static void drm_add_pan(drm_ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64]) 
 {
     uint8_t s, b, qclass, ifreq;
     real_t tmp, coeff1, coeff2;
@@ -924,10 +903,8 @@
 }
 
 /* main DRM PS decoding function */
-uint8_t drm_ps_decode(drm_ps_info *ps, uint8_t guess, uint32_t samplerate, qmf_t X_left[38][64], qmf_t X_right[38][64])
-{
-    uint8_t rateselect = (samplerate >= 24000);
-    
+uint8_t drm_ps_decode(drm_ps_info *ps, uint8_t guess, qmf_t X_left[38][64], qmf_t X_right[38][64])
+{       
     if (ps == NULL) 
     {
         memcpy(X_right, X_left, sizeof(qmf_t)*30*64);
@@ -958,8 +935,8 @@
   
     ps->drm_ps_data_available = 0;
 
-    drm_calc_sa_side_signal(ps, X_left, rateselect);
-    drm_add_ambiance(ps, rateselect, X_left, X_right);
+    drm_calc_sa_side_signal(ps, X_left);
+    drm_add_ambiance(ps, X_left, X_right);
 
     if (ps->bs_enable_sa)
     {
@@ -973,7 +950,7 @@
     
     if (ps->bs_enable_pan)
     {
-        drm_add_pan(ps, rateselect, X_left, X_right);
+        drm_add_pan(ps, X_left, X_right);
     
         ps->g_last_had_pan = 1;        
 
--- a/src/aac/libfaad2/drm_dec.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/drm_dec.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: drm_dec.h,v 1.4 2004/09/04 14:56:28 menno Exp $
+** $Id: drm_dec.h,v 1.6 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __DRM_DEC_H__
@@ -88,7 +93,7 @@
 drm_ps_info *drm_ps_init(void);
 void drm_ps_free(drm_ps_info *ps);
 
-uint8_t drm_ps_decode(drm_ps_info *ps, uint8_t guess, uint32_t samplerate, qmf_t X_left[38][64], qmf_t X_right[38][64]);
+uint8_t drm_ps_decode(drm_ps_info *ps, uint8_t guess, qmf_t X_left[38][64], qmf_t X_right[38][64]);
 
 #ifdef __cplusplus
 }
--- a/src/aac/libfaad2/error.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/error.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: error.c,v 1.28 2004/09/04 14:56:28 menno Exp $
+** $Id: error.c,v 1.30 2006/05/07 18:09:00 menno Exp $
 **/
 
 #include "common.h"
@@ -56,6 +61,11 @@
     "Unexpected fill element with SBR data",
     "Not all elements were provided with SBR data",
     "LTP decoding not available",
-    "Output data buffer too small"
+    "Output data buffer too small",
+    "CRC error in DRM data",
+    "PNS not allowed in DRM data stream",
+    "No standard extension payload allowed in DRM",
+    "PCE shall be the first element in a frame",
+    "Bitstream value not allowed by specification"
 };
 
--- a/src/aac/libfaad2/error.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/error.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: error.h,v 1.22 2004/09/04 14:56:28 menno Exp $
+** $Id: error.h,v 1.24 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __ERROR_H__
@@ -32,7 +37,7 @@
 extern "C" {
 #endif
 
-#define NUM_ERROR_MESSAGES 28
+#define NUM_ERROR_MESSAGES 33
 extern char *err_msg[];
 
 #ifdef __cplusplus
--- a/src/aac/libfaad2/filtbank.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/filtbank.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: filtbank.c,v 1.41 2004/09/08 09:43:11 gcp Exp $
+** $Id: filtbank.c,v 1.43 2006/05/07 18:09:00 menno Exp $
 **/
 
 #include "common.h"
--- a/src/aac/libfaad2/filtbank.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/filtbank.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: filtbank.h,v 1.23 2004/09/08 09:43:11 gcp Exp $
+** $Id: filtbank.h,v 1.25 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __FILTBANK_H__
--- a/src/aac/libfaad2/fixed.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/fixed.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: fixed.h,v 1.26 2004/09/04 14:56:28 menno Exp $
+** $Id: fixed.h,v 1.28 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __FIXED_H__
@@ -36,6 +41,7 @@
 #include <cmnintrin.h>
 #endif
 
+
 #define COEF_BITS 28
 #define COEF_PRECISION (1 << COEF_BITS)
 #define REAL_BITS 14 // MAXIMUM OF 14 FOR FIXED POINT SBR
--- a/src/aac/libfaad2/hcr.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/hcr.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2004 G.C. Pascutto, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: hcr.c,v 1.18 2004/09/04 14:56:28 menno Exp $
+** $Id: hcr.c,v 1.21 2006/07/22 14:13:21 menno Exp $
 **/
 
 #include "common.h"
@@ -222,6 +227,7 @@
 
     uint16_t sp_offset[8];
     uint16_t g, i, sortloop, set, bitsread;
+    uint16_t bitsleft, codewordsleft;
     uint8_t w_idx, sfb, this_CB, last_CB, this_sec_CB; 
     
     const uint16_t nshort = hDecoder->frameLength/8;
@@ -236,7 +242,7 @@
     /* since there is spectral data, at least one codeword has nonzero length */
     if (ics->length_of_longest_codeword == 0)
         return 10;
-    
+
     if (sp_data_len < ics->length_of_longest_codeword)
         return 10; 
 
@@ -272,7 +278,7 @@
         for (sfb = 0; sfb < ics->max_sfb; sfb++)
         {
             /* loop over all in this sfb, 4 lines per loop */
-            for (w_idx = 0; 4*w_idx < (ics->swb_offset[sfb+1] - ics->swb_offset[sfb]); w_idx++)
+            for (w_idx = 0; 4*w_idx < (min(ics->swb_offset[sfb+1], ics->swb_offset_max) - ics->swb_offset[sfb]); w_idx++)
             {
                 for(g = 0; g < ics->num_window_groups; g++)
                 {
@@ -404,6 +410,22 @@
             rewrev_bits(&segment[i]);
     }
 
+    bitsleft = 0;    
+        
+    for (i = 0; i < numberOfSegments && !bitsleft; i++)
+        bitsleft += segment[i].len;
+
+    if (bitsleft) return 10;
+
+    codewordsleft = 0;
+
+    for (i = 0; (i < numberOfCodewords - numberOfSegments) && (!codewordsleft); i++)    
+        if (!codeword[i].decoded)            
+                codewordsleft++; 
+        
+    if (codewordsleft) return 10;
+
     return 0;
+
 }
 #endif
--- a/src/aac/libfaad2/huffman.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/huffman.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: huffman.c,v 1.22 2004/09/04 14:56:28 menno Exp $
+** $Id: huffman.c,v 1.24 2006/05/07 18:09:00 menno Exp $
 **/
 
 #include "common.h"
--- a/src/aac/libfaad2/huffman.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/huffman.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: huffman.h,v 1.24 2004/09/04 14:56:28 menno Exp $
+** $Id: huffman.h,v 1.26 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef __HUFFMAN_H__
--- a/src/aac/libfaad2/ic_predict.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ic_predict.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ic_predict.c,v 1.23 2004/09/04 14:56:28 menno Exp $
+** $Id: ic_predict.c,v 1.26 2006/05/17 18:49:21 menno Exp $
 **/
 
 #include "common.h"
@@ -39,11 +44,7 @@
 {
     int32_t flg;
     uint32_t tmp, tmp1, tmp2;
-    uint32_t *tmp3, *tmp4, *tmp5;
-    tmp3 = &tmp;
-    tmp4 = &tmp1;
-    tmp5 = &tmp2;
- 
+
     tmp = *(uint32_t*)pf;
     flg = tmp & (uint32_t)0x00008000;
     tmp &= (uint32_t)0xffff0000;
@@ -55,18 +56,17 @@
         tmp |= (uint32_t)0x00010000;       /* insert 1 lsb */
         tmp2 = tmp;                             /* add 1 lsb and elided one */
         tmp &= (uint32_t)0xff800000;       /* extract exponent and sign */
- 
-        *pf = *(float32_t*)tmp4 + *(float32_t*)tmp4 - *(float32_t*)tmp5;
+        
+        *pf = *(float32_t*)&tmp1 + *(float32_t*)&tmp2 - *(float32_t*)&tmp;
     } else {
-        *pf = *(float32_t*)tmp3;
+        *pf = *(float32_t*)&tmp;
     }
 }
 
 static int16_t quant_pred(float32_t x)
 {
     int16_t q;
-    float32_t *tmp1 = &x;
-    uint32_t *tmp = (uint32_t*)tmp1;
+    uint32_t *tmp = (uint32_t*)&x;
 
     q = (int16_t)(*tmp>>16);
 
@@ -76,8 +76,7 @@
 static float32_t inv_quant_pred(int16_t q)
 {
     float32_t x;
-    float32_t *tmp1 = &x;
-    uint32_t *tmp = (uint32_t*)tmp1;
+    uint32_t *tmp = (uint32_t*)&x;
     *tmp = ((uint32_t)q)<<16;
 
     return x;
@@ -87,7 +86,8 @@
 {
     uint16_t tmp;
     int16_t i, j;
-    real_t dr1, predictedvalue;
+    real_t dr1;
+	float32_t predictedvalue;
     real_t e0, e1;
     real_t k1, k2;
 
@@ -120,7 +120,7 @@
 #define B 0.953125
         real_t c = COR[0];
         real_t v = VAR[0];
-        real_t tmp;
+        float32_t tmp;
         if (c == 0 || v <= 1)
         {
             k1 = 0;
@@ -150,7 +150,7 @@
 #define B 0.953125
         real_t c = COR[1];
         real_t v = VAR[1];
-        real_t tmp;
+        float32_t tmp;
         if (c == 0 || v <= 1)
         {
             k2 = 0;
@@ -215,7 +215,7 @@
                 if (is_noise(ics, g, sfb))
                 {
                     offs = ics->swb_offset[sfb];
-                    offs2 = ics->swb_offset[sfb+1];
+                    offs2 = min(ics->swb_offset[sfb+1], ics->swb_offset_max);
 
                     for (i = offs; i < offs2; i++)
                         reset_pred_state(&state[i]);
@@ -247,7 +247,7 @@
         for (sfb = 0; sfb < max_pred_sfb(sf_index); sfb++)
         {
             uint16_t low  = ics->swb_offset[sfb];
-            uint16_t high = ics->swb_offset[sfb+1];
+            uint16_t high = min(ics->swb_offset[sfb+1], ics->swb_offset_max);
 
             for (bin = low; bin < high; bin++)
             {
--- a/src/aac/libfaad2/ic_predict.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ic_predict.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ic_predict.h,v 1.19 2004/09/04 14:56:28 menno Exp $
+** $Id: ic_predict.h,v 1.21 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifdef MAIN_DEC
--- a/src/aac/libfaad2/iq_table.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/iq_table.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: iq_table.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: iq_table.h,v 1.18 2006/05/07 18:09:00 menno Exp $
 **/
 
 #ifndef IQ_TABLE_H__
--- a/src/aac/libfaad2/is.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/is.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: is.c,v 1.24 2004/09/04 14:56:28 menno Exp $
+** $Id: is.c,v 1.26 2006/05/07 18:09:01 menno Exp $
 **/
 
 #include "common.h"
@@ -84,7 +89,7 @@
 
                     /* Scale from left to right channel,
                        do not touch left channel */
-                    for (i = icsr->swb_offset[sfb]; i < icsr->swb_offset[sfb+1]; i++)
+                    for (i = icsr->swb_offset[sfb]; i < min(icsr->swb_offset[sfb+1], ics->swb_offset_max); i++)
                     {
 #ifndef FIXED_POINT
                         r_spec[(group*nshort)+i] = MUL_R(l_spec[(group*nshort)+i], scale);
--- a/src/aac/libfaad2/is.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/is.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: is.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: is.h,v 1.18 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __IS_H__
--- a/src/aac/libfaad2/kbd_win.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/kbd_win.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: kbd_win.h,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: kbd_win.h,v 1.19 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __KBD_WIN_H__
--- a/src/aac/libfaad2/lt_predict.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/lt_predict.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: lt_predict.c,v 1.23 2004/09/04 14:56:28 menno Exp $
+** $Id: lt_predict.c,v 1.25 2006/05/07 18:09:01 menno Exp $
 **/
 
 
@@ -53,9 +58,6 @@
 #ifdef LD_DEC
         || (object_type == LD)
 #endif
-#ifdef SCALABLE_DEC
-        || (object_type == 6) /* TODO */
-#endif
         )
     {
         return 1;
@@ -120,7 +122,7 @@
                 if (ltp->long_used[sfb])
                 {
                     uint16_t low  = ics->swb_offset[sfb];
-                    uint16_t high = ics->swb_offset[sfb+1];
+                    uint16_t high = min(ics->swb_offset[sfb+1], ics->swb_offset_max);
 
                     for (bin = low; bin < high; bin++)
                     {
--- a/src/aac/libfaad2/lt_predict.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/lt_predict.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: lt_predict.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: lt_predict.h,v 1.18 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifdef LTP_DEC
--- a/src/aac/libfaad2/mdct.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/mdct.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: mdct.c,v 1.43 2004/09/04 14:56:28 menno Exp $
+** $Id: mdct.c,v 1.45 2006/05/07 18:09:01 menno Exp $
 **/
 
 /*
--- a/src/aac/libfaad2/mdct.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/mdct.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: mdct.h,v 1.26 2004/09/08 09:43:11 gcp Exp $
+** $Id: mdct.h,v 1.28 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __MDCT_H__
--- a/src/aac/libfaad2/mdct_tab.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/mdct_tab.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: mdct_tab.h,v 1.3 2004/09/04 14:56:28 menno Exp $
+** $Id: mdct_tab.h,v 1.5 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __MDCT_TAB_H__
--- a/src/aac/libfaad2/mp4.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/mp4.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4.c,v 1.32 2004/09/04 14:56:28 menno Exp $
+** $Id: mp4.c,v 1.35 2006/08/06 18:57:15 menno Exp $
 **/
 
 #include "common.h"
@@ -58,11 +63,7 @@
 #else
     0, /*  5 SBR */
 #endif
-#ifdef SCALABLE_DEC
-    1, /*  6 AAC Scalable */
-#else
     0, /*  6 AAC Scalable */
-#endif
     0, /*  7 TwinVQ */
     0, /*  8 CELP */
     0, /*  9 HVXC */
@@ -83,11 +84,7 @@
 #else
     0, /* 19 ER AAC LTP */
 #endif
-#ifdef SCALABLE_DEC
-    1, /* 20 ER AAC scalable */
-#else
     0, /* 20 ER AAC scalable */
-#endif
     0, /* 21 ER TwinVQ */
     0, /* 22 ER BSAC */
 #ifdef LD_DEC
@@ -248,7 +245,7 @@
 
         if (syncExtensionType == 0x2b7)
         {
-            mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
+            uint8_t tmp_OTi = (uint8_t)faad_getbits(&ld, 5
                 DEBUGVAR(1,10,"parse_audio_decoder_specific_info(): extensionAudioObjectType"));
 
             if (mp4ASC->objectTypeIndex == 5)
@@ -259,6 +256,10 @@
                 if (mp4ASC->sbr_present_flag)
                 {
                     uint8_t tmp;
+
+					/* Don't set OT to SBR until checked that it is actually there */
+					mp4ASC->objectTypeIndex = tmp_OTi;
+
                     tmp = (uint8_t)faad_getbits(&ld, 4
                         DEBUGVAR(1,12,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
 
--- a/src/aac/libfaad2/mp4.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/mp4.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4.h,v 1.21 2004/09/04 14:56:28 menno Exp $
+** $Id: mp4.h,v 1.23 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __MP4_H__
--- a/src/aac/libfaad2/ms.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ms.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ms.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: ms.c,v 1.19 2006/05/07 18:09:01 menno Exp $
 **/
 
 #include "common.h"
@@ -58,7 +63,7 @@
                     if ((ics->ms_used[g][sfb] || ics->ms_mask_present == 2) &&
                         !is_intensity(icsr, g, sfb) && !is_noise(ics, g, sfb))
                     {
-                        for (i = ics->swb_offset[sfb]; i < ics->swb_offset[sfb+1]; i++)
+                        for (i = ics->swb_offset[sfb]; i < min(ics->swb_offset[sfb+1], ics->swb_offset_max); i++)
                         {
                             k = (group*nshort) + i;
                             tmp = l_spec[k] - r_spec[k];
--- a/src/aac/libfaad2/ms.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ms.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ms.h,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: ms.h,v 1.17 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __MS_H__
--- a/src/aac/libfaad2/output.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/output.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: output.c,v 1.42 2004/09/04 14:56:28 menno Exp $
+** $Id: output.c,v 1.44 2006/05/07 18:09:01 menno Exp $
 **/
 
 #include "common.h"
--- a/src/aac/libfaad2/output.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/output.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: output.h,v 1.21 2004/09/04 14:56:28 menno Exp $
+** $Id: output.h,v 1.23 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __OUTPUT_H__
--- a/src/aac/libfaad2/pns.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/pns.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: pns.c,v 1.34 2004/09/04 14:56:28 menno Exp $
+** $Id: pns.c,v 1.36 2006/05/07 18:09:01 menno Exp $
 **/
 
 #include "common.h"
@@ -33,7 +38,8 @@
 
 /* static function declarations */
 static void gen_rand_vector(real_t *spec, int16_t scale_factor, uint16_t size,
-                            uint8_t sub);
+                            uint8_t sub,
+                            /* RNG states */ uint32_t *__r1, uint32_t *__r2);
 
 
 #ifdef FIXED_POINT
@@ -68,7 +74,7 @@
     return root;
 }
 
-static real_t pow2_table[] =
+static real_t const pow2_table[] =
 {
     COEF_CONST(1.0),
     COEF_CONST(1.18920711500272),
@@ -83,7 +89,8 @@
    multiplication/accumulation per random value.
 */
 static INLINE void gen_rand_vector(real_t *spec, int16_t scale_factor, uint16_t size,
-                                   uint8_t sub)
+                                   uint8_t sub,
+                                   /* RNG states */ uint32_t *__r1, uint32_t *__r2)
 {
 #ifndef FIXED_POINT
     uint16_t i;
@@ -93,7 +100,7 @@
 
     for (i = 0; i < size; i++)
     {
-        real_t tmp = scale*(real_t)(int32_t)random_int();
+        real_t tmp = scale*(real_t)(int32_t)ne_rng(__r1, __r2);
         spec[i] = tmp;
         energy += tmp*tmp;
     }
@@ -112,7 +119,7 @@
     for (i = 0; i < size; i++)
     {
         /* this can be replaced by a 16 bit random generator!!!! */
-        real_t tmp = (int32_t)random_int();
+        real_t tmp = (int32_t)ne_rng(__r1, __r2);
         if (tmp < 0)
             tmp = -(tmp & ((1<<(REAL_BITS-1))-1));
         else
@@ -152,7 +159,8 @@
 
 void pns_decode(ic_stream *ics_left, ic_stream *ics_right,
                 real_t *spec_left, real_t *spec_right, uint16_t frame_len,
-                uint8_t channel_pair, uint8_t object_type)
+                uint8_t channel_pair, uint8_t object_type,
+                /* RNG states */ uint32_t *__r1, uint32_t *__r2)
 {
     uint8_t g, sfb, b;
     uint16_t size, offs;
@@ -202,11 +210,11 @@
 #endif
 
                     offs = ics_left->swb_offset[sfb];
-                    size = ics_left->swb_offset[sfb+1] - offs;
+                    size = min(ics_left->swb_offset[sfb+1], ics_left->swb_offset_max) - offs;
 
                     /* Generate random vector */
                     gen_rand_vector(&spec_left[(group*nshort)+offs],
-                        ics_left->scale_factors[g][sfb], size, sub);
+                        ics_left->scale_factors[g][sfb], size, sub, __r1, __r2);
                 }
 
 /* From the spec:
@@ -233,7 +241,7 @@
                             uint16_t c;
 
                             offs = ics_right->swb_offset[sfb];
-                            size = ics_right->swb_offset[sfb+1] - offs;
+                            size = min(ics_right->swb_offset[sfb+1], ics_right->swb_offset_max) - offs;
 
                             for (c = 0; c < size; c++)
                             {
@@ -250,11 +258,11 @@
 #endif
 
                             offs = ics_right->swb_offset[sfb];
-                            size = ics_right->swb_offset[sfb+1] - offs;
+                            size = min(ics_right->swb_offset[sfb+1], ics_right->swb_offset_max) - offs;
 
                             /* Generate random vector */
                             gen_rand_vector(&spec_right[(group*nshort)+offs],
-                                ics_right->scale_factors[g][sfb], size, sub);
+                                ics_right->scale_factors[g][sfb], size, sub, __r1, __r2);
                         }
                     }
                 }
--- a/src/aac/libfaad2/pns.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/pns.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: pns.h,v 1.23 2004/09/04 14:56:28 menno Exp $
+** $Id: pns.h,v 1.25 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __PNS_H__
@@ -38,7 +43,8 @@
 
 void pns_decode(ic_stream *ics_left, ic_stream *ics_right,
                 real_t *spec_left, real_t *spec_right, uint16_t frame_len,
-                uint8_t channel_pair, uint8_t object_type);
+                uint8_t channel_pair, uint8_t object_type,
+                /* RNG states */ uint32_t *__r1, uint32_t *__r2);
 
 static INLINE uint8_t is_noise(ic_stream *ics, uint8_t group, uint8_t sfb)
 {
--- a/src/aac/libfaad2/ps_dec.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ps_dec.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
-** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR and PS decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ps_dec.c,v 1.10 2004/09/04 14:56:28 menno Exp $
+** $Id: ps_dec.c,v 1.12 2006/05/07 18:09:01 menno Exp $
 **/
 
 #include "common.h"
@@ -175,7 +180,7 @@
                          int8_t min_index, int8_t max_index);
 static void delta_modulo_decode(uint8_t enable, int8_t *index, int8_t *index_prev,
                                 uint8_t dt_flag, uint8_t nr_par, uint8_t stride,
-                                int8_t log2modulo);
+                                int8_t and_modulo);
 static void map20indexto34(int8_t *index, uint8_t bins);
 #ifdef PS_LOW_POWER
 static void map34indexto20(int8_t *index, uint8_t bins);
@@ -674,7 +679,7 @@
 /* in: log2 value of the modulo value to allow using AND instead of MOD */
 static void delta_modulo_decode(uint8_t enable, int8_t *index, int8_t *index_prev,
                                 uint8_t dt_flag, uint8_t nr_par, uint8_t stride,
-                                int8_t log2modulo)
+                                int8_t and_modulo)
 {
     int8_t i;
 
@@ -684,19 +689,19 @@
         {
             /* delta coded in frequency direction */
             index[0] = 0 + index[0];
-            index[0] &= log2modulo;
+            index[0] &= and_modulo;
 
             for (i = 1; i < nr_par; i++)
             {
                 index[i] = index[i-1] + index[i];
-                index[i] &= log2modulo;
+                index[i] &= and_modulo;
             }
         } else {
             /* delta coded in time direction */
             for (i = 0; i < nr_par; i++)
             {
                 index[i] = index_prev[i*stride] + index[i];
-                index[i] &= log2modulo;
+                index[i] &= and_modulo;
             }
         }
     } else {
@@ -841,11 +846,11 @@
 
         /* delta modulo decode ipd parameters */
         delta_modulo_decode(ps->enable_ipdopd, ps->ipd_index[env], ipd_index_prev,
-            ps->ipd_dt[env], ps->nr_ipdopd_par, 1, /*log2(8)*/ 3);
+            ps->ipd_dt[env], ps->nr_ipdopd_par, 1, 7);
 
         /* delta modulo decode opd parameters */
         delta_modulo_decode(ps->enable_ipdopd, ps->opd_index[env], opd_index_prev,
-            ps->opd_dt[env], ps->nr_ipdopd_par, 1, /*log2(8)*/ 3);
+            ps->opd_dt[env], ps->nr_ipdopd_par, 1, 7);
     }
 
     /* handle error case */
@@ -1027,7 +1032,7 @@
                            qmf_t X_hybrid_left[32][32], qmf_t X_hybrid_right[32][32])
 {
     uint8_t gr, n, m, bk;
-    uint8_t temp_delay = 0;
+    uint8_t temp_delay;
     uint8_t sb, maxsb;
     const complex_t *Phi_Fract_SubQmf;
     uint8_t temp_delay_ser[NO_ALLPASS_LINKS];
@@ -1418,6 +1423,26 @@
     FRAC_CONST(-0.000000000000000)
 };
 
+static real_t magnitude_c(complex_t c)
+{
+#ifdef FIXED_POINT
+#define ps_abs(A) (((A) > 0) ? (A) : (-(A)))
+#define ALPHA FRAC_CONST(0.948059448969)
+#define BETA  FRAC_CONST(0.392699081699)
+
+    real_t abs_inphase = ps_abs(RE(c));
+    real_t abs_quadrature = ps_abs(IM(c));
+
+    if (abs_inphase > abs_quadrature) {
+        return MUL_F(abs_inphase, ALPHA) + MUL_F(abs_quadrature, BETA);
+    } else {
+        return MUL_F(abs_quadrature, ALPHA) + MUL_F(abs_inphase, BETA);
+    }
+#else
+    return sqrt(RE(c)*RE(c) + IM(c)*IM(c));
+#endif
+}
+
 static void ps_mix_phase(ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64],
                          qmf_t X_hybrid_left[32][32], qmf_t X_hybrid_right[32][32])
 {
@@ -1438,20 +1463,6 @@
     const real_t *sf_iid;
     uint8_t no_iid_steps;
 
-    /* These could otherwise be used uninitialized, according to GCC 4.0.2 */
-    H22[1] = 0;
-    H21[1] = 0;
-    H12[1] = 0;
-    H11[1] = 0;
-    deltaH22[1] = 0;
-    deltaH21[1] = 0;
-    deltaH12[1] = 0;
-    deltaH11[1] = 0;
-    h22[1] = 0;
-    h21[1] = 0;
-    h12[1] = 0;
-    h11[1] = 0;
-
     if (ps->iid_mode >= 3)
     {
         no_iid_steps = 15;
@@ -1602,8 +1613,7 @@
             if ((ps->enable_ipdopd) && (bk < nr_ipdopd_par))
             {
                 int8_t i;
-                real_t xxyy, ppqq;
-                real_t yq, xp, xq, py, tmp;
+                real_t xy, pq, xypq;
 
                 /* ringbuffer index */
                 i = ps->phase_hist;
@@ -1636,7 +1646,7 @@
 
                 /* ringbuffer index */
                 if (i == 0)
-                { 
+                {
                     i = 2;
                 }
                 i--;
@@ -1666,53 +1676,54 @@
                 RE(phaseRight) = (float)cos(opd);
                 IM(phaseRight) = (float)sin(opd);
 #else
+
                 // x = IM(tempLeft)
                 // y = RE(tempLeft)
                 // p = IM(tempRight)
                 // q = RE(tempRight)
-                // cos(atan2(x,y)) = 1/sqrt(1 + (x*x)/(y*y))
-                // sin(atan2(x,y)) = x/(y*sqrt(1 + (x*x)/(y*y)))
-                // cos(atan2(x,y)-atan2(p,q)) = (y*q+x*p)/(y*q * sqrt(1 + (x*x)/(y*y)) * sqrt(1 + (p*p)/(q*q)));
-                // sin(atan2(x,y)-atan2(p,q)) = (x*q-p*y)/(y*q * sqrt(1 + (x*x)/(y*y)) * sqrt(1 + (p*p)/(q*q)));
+                // cos(atan2(x,y)) = y/sqrt((x*x) + (y*y))
+                // sin(atan2(x,y)) = x/sqrt((x*x) + (y*y))
+                // cos(atan2(x,y)-atan2(p,q)) = (y*q + x*p) / ( sqrt((x*x) + (y*y)) * sqrt((p*p) + (q*q)) );
+                // sin(atan2(x,y)-atan2(p,q)) = (x*q - y*p) / ( sqrt((x*x) + (y*y)) * sqrt((p*p) + (q*q)) );
 
-                /* (x*x)/(y*y)  (REAL > 0) */
-                xxyy = DIV_R(MUL_C(IM(tempLeft),IM(tempLeft)), MUL_C(RE(tempLeft),RE(tempLeft)));
-                ppqq = DIV_R(MUL_C(IM(tempRight),IM(tempRight)), MUL_C(RE(tempRight),RE(tempRight)));
-
-                /* 1 + (x*x)/(y*y)  (REAL > 1) */
-                xxyy += REAL_CONST(1);
-                ppqq += REAL_CONST(1);
+                xy = magnitude_c(tempRight);
+                pq = magnitude_c(tempLeft);
 
-                /* 1 / sqrt(1 + (x*x)/(y*y))  (FRAC <= 1) */
-                xxyy = DIV_R(FRAC_CONST(1), ps_sqrt(xxyy));
-                ppqq = DIV_R(FRAC_CONST(1), ps_sqrt(ppqq));
+                if (xy != 0)
+                {
+                    RE(phaseLeft) = DIV_R(RE(tempRight), xy);
+                    IM(phaseLeft) = DIV_R(IM(tempRight), xy);
+                } else {
+                    RE(phaseLeft) = 0;
+                    IM(phaseLeft) = 0;
+                }
+
+                xypq = MUL_R(xy, pq);
 
-                /* COEF */
-                yq = MUL_C(RE(tempLeft), RE(tempRight));
-                xp = MUL_C(IM(tempLeft), IM(tempRight));
-                xq = MUL_C(IM(tempLeft), RE(tempRight));
-                py = MUL_C(RE(tempLeft), IM(tempRight));
+                if (xypq != 0)
+                {
+                    real_t tmp1 = MUL_R(RE(tempRight), RE(tempLeft)) + MUL_R(IM(tempRight), IM(tempLeft));
+                    real_t tmp2 = MUL_R(IM(tempRight), RE(tempLeft)) - MUL_R(RE(tempRight), IM(tempLeft));
 
-                RE(phaseLeft) = xxyy;
-                IM(phaseLeft) = MUL_R(xxyy, (DIV_R(IM(tempLeft), RE(tempLeft))));
+                    RE(phaseRight) = DIV_R(tmp1, xypq);
+                    IM(phaseRight) = DIV_R(tmp2, xypq);
+                } else {
+                    RE(phaseRight) = 0;
+                    IM(phaseRight) = 0;
+                }
 
-                tmp = DIV_C(MUL_F(xxyy, ppqq), yq);
-
-                /* MUL_C(FRAC,COEF) = FRAC */
-                RE(phaseRight) = MUL_C(tmp, (yq+xp));
-                IM(phaseRight) = MUL_C(tmp, (xq-py));
 #endif
 
-                /* MUL_F(COEF, FRAC) = COEF */
-                IM(h11) = MUL_F(RE(h11), IM(phaseLeft));
-                IM(h12) = MUL_F(RE(h12), IM(phaseRight));
-                IM(h21) = MUL_F(RE(h21), IM(phaseLeft));
-                IM(h22) = MUL_F(RE(h22), IM(phaseRight));
+                /* MUL_F(COEF, REAL) = COEF */
+                IM(h11) = MUL_R(RE(h11), IM(phaseLeft));
+                IM(h12) = MUL_R(RE(h12), IM(phaseRight));
+                IM(h21) = MUL_R(RE(h21), IM(phaseLeft));
+                IM(h22) = MUL_R(RE(h22), IM(phaseRight));
 
-                RE(h11) = MUL_F(RE(h11), RE(phaseLeft));
-                RE(h12) = MUL_F(RE(h12), RE(phaseRight));
-                RE(h21) = MUL_F(RE(h21), RE(phaseLeft));
-                RE(h22) = MUL_F(RE(h22), RE(phaseRight));
+                RE(h11) = MUL_R(RE(h11), RE(phaseLeft));
+                RE(h12) = MUL_R(RE(h12), RE(phaseRight));
+                RE(h21) = MUL_R(RE(h21), RE(phaseLeft));
+                RE(h22) = MUL_R(RE(h22), RE(phaseRight));
             }
 
             /* length of the envelope n_e+1 - n_e (in time samples) */
@@ -1949,8 +1960,8 @@
 /* main Parametric Stereo decoding function */
 uint8_t ps_decode(ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64])
 {
-    qmf_t X_hybrid_left[32][32] = {{{0}}};
-    qmf_t X_hybrid_right[32][32] = {{{0}}};
+    qmf_t X_hybrid_left[32][32] = {{0}};
+    qmf_t X_hybrid_right[32][32] = {{0}};
 
     /* delta decoding of the bitstream data */
     ps_data_decode(ps);
--- a/src/aac/libfaad2/ps_dec.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ps_dec.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ps_dec.h,v 1.8 2004/09/04 14:56:28 menno Exp $
+** $Id: ps_dec.h,v 1.10 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __PS_DEC_H__
--- a/src/aac/libfaad2/ps_syntax.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ps_syntax.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
-** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR and PS decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 **
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ps_syntax.c,v 1.6 2004/09/04 14:56:28 menno Exp $
+** $Id: ps_syntax.c,v 1.9 2006/08/15 19:05:11 menno Exp $
 **/
 
 #include "common.h"
@@ -308,9 +313,9 @@
     { 2, 3 },                 /* index 1: 2 bits: 0x */
     { 4, 5 },                 /* index 2: 3 bits: 00x */
     { /*1*/ -30, /*7*/ -24 }, /* index 3: 3 bits: 01x */
-    { /*5*/ -26, 6 },         /* index 4: 4 bits: 000x */
-    { /*2*/ -29, /*6*/ -25 }, /* index 5: 4 bits: 001x */
-    { /*4*/ -27, /*3*/ -28 }  /* index 6: 5 bits: 0001x */
+    { /*5*/ -26, /*2*/ -29 }, /* index 4: 4 bits: 000x */
+    { /*6*/ -25, 6 },         /* index 5: 4 bits: 001x */
+    { /*4*/ -27, /*3*/ -28 }  /* index 6: 5 bits: 0011x */
 };
 
 /* static function declarations */
@@ -380,7 +385,10 @@
 
     /* we are here, but no header has been read yet */
     if (ps->header_read == 0)
+    {
+        ps->ps_data_available = 0;
         return 1;
+    }
 
     ps->frame_class = (uint8_t)faad_get1bit(ld
         DEBUGVAR(1,1006,"ps_data(): frame_class"));
@@ -394,7 +402,7 @@
         for (n = 1; n < ps->num_env+1; n++)
         {
             ps->border_position[n] = (uint8_t)faad_getbits(ld, 5
-                DEBUGVAR(1,1008,"ps_data(): border_position"));
+                DEBUGVAR(1,1008,"ps_data(): border_position")) + 1;
         }
     }
 
--- a/src/aac/libfaad2/ps_tables.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ps_tables.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ps_tables.h,v 1.3 2004/09/04 14:56:28 menno Exp $
+** $Id: ps_tables.h,v 1.6 2006/05/17 18:49:21 menno Exp $
 **/
 
 #ifndef __PS_TABLES_H__
@@ -541,7 +546,7 @@
 };
 
 #ifdef __cplusplus
-
+}
 #endif
 #endif
 
--- a/src/aac/libfaad2/pulse.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/pulse.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,17 +14,21 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
-** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
 **
-** $Id: pulse.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
+**
+** $Id: pulse.c,v 1.19 2006/05/07 18:09:01 menno Exp $
 **/
-
 #include "common.h"
 #include "structs.h"
 
@@ -37,7 +41,7 @@
     uint16_t k;
     pulse_info *pul = &(ics->pul);
 
-    k = ics->swb_offset[pul->pulse_start_sfb];
+    k = min(ics->swb_offset[pul->pulse_start_sfb], ics->swb_offset_max);
 
     for (i = 0; i <= pul->number_pulse; i++)
     {
--- a/src/aac/libfaad2/pulse.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/pulse.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: pulse.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: pulse.h,v 1.18 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __PULSE_H__
--- a/src/aac/libfaad2/rvlc.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/rvlc.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: rvlc.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: rvlc.c,v 1.19 2006/05/07 18:09:01 menno Exp $
 **/
 
 /* RVLC scalefactor decoding
--- a/src/aac/libfaad2/rvlc.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/rvlc.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: rvlc.h,v 1.13 2004/09/04 14:56:28 menno Exp $
+** $Id: rvlc.h,v 1.15 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __RVLC_SCF_H__
--- a/src/aac/libfaad2/sbr_dct.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_dct.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,30 +1,40 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_dct.c,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_dct.c,v 1.18 2006/05/26 19:21:35 menno Exp $
 **/
 
+
+/* Most of the DCT/DST codes here are generated using Spiral which is GPL
+ * For more info see: http://www.spiral.net/
+ */
+
 #include "common.h"
 
 #ifdef SBR_DEC
@@ -479,6 +489,413 @@
     y[1] = f397 - f396;
 }
 
+void DST4_32(real_t *y, real_t *x)
+{
+    real_t f0, f1, f2, f3, f4, f5, f6, f7, f8, f9;
+    real_t f10, f11, f12, f13, f14, f15, f16, f17, f18, f19;
+    real_t f20, f21, f22, f23, f24, f25, f26, f27, f28, f29;
+    real_t f30, f31, f32, f33, f34, f35, f36, f37, f38, f39;
+    real_t f40, f41, f42, f43, f44, f45, f46, f47, f48, f49;
+    real_t f50, f51, f52, f53, f54, f55, f56, f57, f58, f59;
+    real_t f60, f61, f62, f63, f64, f65, f66, f67, f68, f69;
+    real_t f70, f71, f72, f73, f74, f75, f76, f77, f78, f79;
+    real_t f80, f81, f82, f83, f84, f85, f86, f87, f88, f89;
+    real_t f90, f91, f92, f93, f94, f95, f96, f97, f98, f99;
+    real_t f100, f101, f102, f103, f104, f105, f106, f107, f108, f109;
+    real_t f110, f111, f112, f113, f114, f115, f116, f117, f118, f119;
+    real_t f120, f121, f122, f123, f124, f125, f126, f127, f128, f129;
+    real_t f130, f131, f132, f133, f134, f135, f136, f137, f138, f139;
+    real_t f140, f141, f142, f143, f144, f145, f146, f147, f148, f149;
+    real_t f150, f151, f152, f153, f154, f155, f156, f157, f158, f159;
+    real_t f160, f161, f162, f163, f164, f165, f166, f167, f168, f169;
+    real_t f170, f171, f172, f173, f174, f175, f176, f177, f178, f179;
+    real_t f180, f181, f182, f183, f184, f185, f186, f187, f188, f189;
+    real_t f190, f191, f192, f193, f194, f195, f196, f197, f198, f199;
+    real_t f200, f201, f202, f203, f204, f205, f206, f207, f208, f209;
+    real_t f210, f211, f212, f213, f214, f215, f216, f217, f218, f219;
+    real_t f220, f221, f222, f223, f224, f225, f226, f227, f228, f229;
+    real_t f230, f231, f232, f233, f234, f235, f236, f237, f238, f239;
+    real_t f240, f241, f242, f243, f244, f245, f246, f247, f248, f249;
+    real_t f250, f251, f252, f253, f254, f255, f256, f257, f258, f259;
+    real_t f260, f261, f262, f263, f264, f265, f266, f267, f268, f269;
+    real_t f270, f271, f272, f273, f274, f275, f276, f277, f278, f279;
+    real_t f280, f281, f282, f283, f284, f285, f286, f287, f288, f289;
+    real_t f290, f291, f292, f293, f294, f295, f296, f297, f298, f299;
+    real_t f300, f301, f302, f303, f304, f305, f306, f307, f308, f309;
+    real_t f310, f311, f312, f313, f314, f315, f316, f317, f318, f319;
+    real_t f320, f321, f322, f323, f324, f325, f326, f327, f328, f329;
+    real_t f330, f331, f332, f333, f334, f335;
+
+    f0 = x[0] - x[1];
+    f1 = x[2] - x[1];
+    f2 = x[2] - x[3];
+    f3 = x[4] - x[3];
+    f4 = x[4] - x[5];
+    f5 = x[6] - x[5];
+    f6 = x[6] - x[7];
+    f7 = x[8] - x[7];
+    f8 = x[8] - x[9];
+    f9 = x[10] - x[9];
+    f10 = x[10] - x[11];
+    f11 = x[12] - x[11];
+    f12 = x[12] - x[13];
+    f13 = x[14] - x[13];
+    f14 = x[14] - x[15];
+    f15 = x[16] - x[15];
+    f16 = x[16] - x[17];
+    f17 = x[18] - x[17];
+    f18 = x[18] - x[19];
+    f19 = x[20] - x[19];
+    f20 = x[20] - x[21];
+    f21 = x[22] - x[21];
+    f22 = x[22] - x[23];
+    f23 = x[24] - x[23];
+    f24 = x[24] - x[25];
+    f25 = x[26] - x[25];
+    f26 = x[26] - x[27];
+    f27 = x[28] - x[27];
+    f28 = x[28] - x[29];
+    f29 = x[30] - x[29];
+    f30 = x[30] - x[31];
+    f31 = MUL_F(FRAC_CONST(0.7071067811865476), f15);
+    f32 = x[0] - f31;
+    f33 = x[0] + f31;
+    f34 = f7 + f23;
+    f35 = MUL_C(COEF_CONST(1.3065629648763766), f7);
+    f36 = MUL_F(FRAC_CONST(-0.9238795325112866), f34);
+    f37 = MUL_F(FRAC_CONST(-0.5411961001461967), f23);
+    f38 = f35 + f36;
+    f39 = f37 - f36;
+    f40 = f33 - f39;
+    f41 = f33 + f39;
+    f42 = f32 - f38;
+    f43 = f32 + f38;
+    f44 = f11 - f19;
+    f45 = f11 + f19;
+    f46 = MUL_F(FRAC_CONST(0.7071067811865476), f45);
+    f47 = f3 - f46;
+    f48 = f3 + f46;
+    f49 = MUL_F(FRAC_CONST(0.7071067811865476), f44);
+    f50 = f49 - f27;
+    f51 = f49 + f27;
+    f52 = f51 + f48;
+    f53 = MUL_F(FRAC_CONST(-0.7856949583871021), f51);
+    f54 = MUL_F(FRAC_CONST(0.9807852804032304), f52);
+    f55 = MUL_C(COEF_CONST(1.1758756024193588), f48);
+    f56 = f53 + f54;
+    f57 = f55 - f54;
+    f58 = f50 + f47;
+    f59 = MUL_F(FRAC_CONST(-0.2758993792829430), f50);
+    f60 = MUL_F(FRAC_CONST(0.8314696123025452), f58);
+    f61 = MUL_C(COEF_CONST(1.3870398453221475), f47);
+    f62 = f59 + f60;
+    f63 = f61 - f60;
+    f64 = f41 - f56;
+    f65 = f41 + f56;
+    f66 = f43 - f62;
+    f67 = f43 + f62;
+    f68 = f42 - f63;
+    f69 = f42 + f63;
+    f70 = f40 - f57;
+    f71 = f40 + f57;
+    f72 = f5 - f9;
+    f73 = f5 + f9;
+    f74 = f13 - f17;
+    f75 = f13 + f17;
+    f76 = f21 - f25;
+    f77 = f21 + f25;
+    f78 = MUL_F(FRAC_CONST(0.7071067811865476), f75);
+    f79 = f1 - f78;
+    f80 = f1 + f78;
+    f81 = f73 + f77;
+    f82 = MUL_C(COEF_CONST(1.3065629648763766), f73);
+    f83 = MUL_F(FRAC_CONST(-0.9238795325112866), f81);
+    f84 = MUL_F(FRAC_CONST(-0.5411961001461967), f77);
+    f85 = f82 + f83;
+    f86 = f84 - f83;
+    f87 = f80 - f86;
+    f88 = f80 + f86;
+    f89 = f79 - f85;
+    f90 = f79 + f85;
+    f91 = MUL_F(FRAC_CONST(0.7071067811865476), f74);
+    f92 = f29 - f91;
+    f93 = f29 + f91;
+    f94 = f76 + f72;
+    f95 = MUL_C(COEF_CONST(1.3065629648763766), f76);
+    f96 = MUL_F(FRAC_CONST(-0.9238795325112866), f94);
+    f97 = MUL_F(FRAC_CONST(-0.5411961001461967), f72);
+    f98 = f95 + f96;
+    f99 = f97 - f96;
+    f100 = f93 - f99;
+    f101 = f93 + f99;
+    f102 = f92 - f98;
+    f103 = f92 + f98;
+    f104 = f101 + f88;
+    f105 = MUL_F(FRAC_CONST(-0.8971675863426361), f101);
+    f106 = MUL_F(FRAC_CONST(0.9951847266721968), f104);
+    f107 = MUL_C(COEF_CONST(1.0932018670017576), f88);
+    f108 = f105 + f106;
+    f109 = f107 - f106;
+    f110 = f90 - f103;
+    f111 = MUL_F(FRAC_CONST(-0.6666556584777466), f103);
+    f112 = MUL_F(FRAC_CONST(0.9569403357322089), f110);
+    f113 = MUL_C(COEF_CONST(1.2472250129866713), f90);
+    f114 = f112 - f111;
+    f115 = f113 - f112;
+    f116 = f102 + f89;
+    f117 = MUL_F(FRAC_CONST(-0.4105245275223571), f102);
+    f118 = MUL_F(FRAC_CONST(0.8819212643483549), f116);
+    f119 = MUL_C(COEF_CONST(1.3533180011743529), f89);
+    f120 = f117 + f118;
+    f121 = f119 - f118;
+    f122 = f87 - f100;
+    f123 = MUL_F(FRAC_CONST(-0.1386171691990915), f100);
+    f124 = MUL_F(FRAC_CONST(0.7730104533627370), f122);
+    f125 = MUL_C(COEF_CONST(1.4074037375263826), f87);
+    f126 = f124 - f123;
+    f127 = f125 - f124;
+    f128 = f65 - f108;
+    f129 = f65 + f108;
+    f130 = f67 - f114;
+    f131 = f67 + f114;
+    f132 = f69 - f120;
+    f133 = f69 + f120;
+    f134 = f71 - f126;
+    f135 = f71 + f126;
+    f136 = f70 - f127;
+    f137 = f70 + f127;
+    f138 = f68 - f121;
+    f139 = f68 + f121;
+    f140 = f66 - f115;
+    f141 = f66 + f115;
+    f142 = f64 - f109;
+    f143 = f64 + f109;
+    f144 = f0 + f30;
+    f145 = MUL_C(COEF_CONST(1.0478631305325901), f0);
+    f146 = MUL_F(FRAC_CONST(-0.9987954562051724), f144);
+    f147 = MUL_F(FRAC_CONST(-0.9497277818777548), f30);
+    f148 = f145 + f146;
+    f149 = f147 - f146;
+    f150 = f4 + f26;
+    f151 = MUL_F(FRAC_CONST(1.2130114330978077), f4);
+    f152 = MUL_F(FRAC_CONST(-0.9700312531945440), f150);
+    f153 = MUL_F(FRAC_CONST(-0.7270510732912803), f26);
+    f154 = f151 + f152;
+    f155 = f153 - f152;
+    f156 = f8 + f22;
+    f157 = MUL_C(COEF_CONST(1.3315443865537255), f8);
+    f158 = MUL_F(FRAC_CONST(-0.9039892931234433), f156);
+    f159 = MUL_F(FRAC_CONST(-0.4764341996931612), f22);
+    f160 = f157 + f158;
+    f161 = f159 - f158;
+    f162 = f12 + f18;
+    f163 = MUL_C(COEF_CONST(1.3989068359730781), f12);
+    f164 = MUL_F(FRAC_CONST(-0.8032075314806453), f162);
+    f165 = MUL_F(FRAC_CONST(-0.2075082269882124), f18);
+    f166 = f163 + f164;
+    f167 = f165 - f164;
+    f168 = f16 + f14;
+    f169 = MUL_C(COEF_CONST(1.4125100802019777), f16);
+    f170 = MUL_F(FRAC_CONST(-0.6715589548470187), f168);
+    f171 = MUL_F(FRAC_CONST(0.0693921705079402), f14);
+    f172 = f169 + f170;
+    f173 = f171 - f170;
+    f174 = f20 + f10;
+    f175 = MUL_C(COEF_CONST(1.3718313541934939), f20);
+    f176 = MUL_F(FRAC_CONST(-0.5141027441932219), f174);
+    f177 = MUL_F(FRAC_CONST(0.3436258658070501), f10);
+    f178 = f175 + f176;
+    f179 = f177 - f176;
+    f180 = f24 + f6;
+    f181 = MUL_C(COEF_CONST(1.2784339185752409), f24);
+    f182 = MUL_F(FRAC_CONST(-0.3368898533922200), f180);
+    f183 = MUL_F(FRAC_CONST(0.6046542117908008), f6);
+    f184 = f181 + f182;
+    f185 = f183 - f182;
+    f186 = f28 + f2;
+    f187 = MUL_C(COEF_CONST(1.1359069844201433), f28);
+    f188 = MUL_F(FRAC_CONST(-0.1467304744553624), f186);
+    f189 = MUL_F(FRAC_CONST(0.8424460355094185), f2);
+    f190 = f187 + f188;
+    f191 = f189 - f188;
+    f192 = f149 - f173;
+    f193 = f149 + f173;
+    f194 = f148 - f172;
+    f195 = f148 + f172;
+    f196 = f155 - f179;
+    f197 = f155 + f179;
+    f198 = f154 - f178;
+    f199 = f154 + f178;
+    f200 = f161 - f185;
+    f201 = f161 + f185;
+    f202 = f160 - f184;
+    f203 = f160 + f184;
+    f204 = f167 - f191;
+    f205 = f167 + f191;
+    f206 = f166 - f190;
+    f207 = f166 + f190;
+    f208 = f192 + f194;
+    f209 = MUL_C(COEF_CONST(1.1758756024193588), f192);
+    f210 = MUL_F(FRAC_CONST(-0.9807852804032304), f208);
+    f211 = MUL_F(FRAC_CONST(-0.7856949583871021), f194);
+    f212 = f209 + f210;
+    f213 = f211 - f210;
+    f214 = f196 + f198;
+    f215 = MUL_C(COEF_CONST(1.3870398453221475), f196);
+    f216 = MUL_F(FRAC_CONST(-0.5555702330196022), f214);
+    f217 = MUL_F(FRAC_CONST(0.2758993792829431), f198);
+    f218 = f215 + f216;
+    f219 = f217 - f216;
+    f220 = f200 + f202;
+    f221 = MUL_F(FRAC_CONST(0.7856949583871022), f200);
+    f222 = MUL_F(FRAC_CONST(0.1950903220161283), f220);
+    f223 = MUL_C(COEF_CONST(1.1758756024193586), f202);
+    f224 = f221 + f222;
+    f225 = f223 - f222;
+    f226 = f204 + f206;
+    f227 = MUL_F(FRAC_CONST(-0.2758993792829430), f204);
+    f228 = MUL_F(FRAC_CONST(0.8314696123025452), f226);
+    f229 = MUL_C(COEF_CONST(1.3870398453221475), f206);
+    f230 = f227 + f228;
+    f231 = f229 - f228;
+    f232 = f193 - f201;
+    f233 = f193 + f201;
+    f234 = f195 - f203;
+    f235 = f195 + f203;
+    f236 = f197 - f205;
+    f237 = f197 + f205;
+    f238 = f199 - f207;
+    f239 = f199 + f207;
+    f240 = f213 - f225;
+    f241 = f213 + f225;
+    f242 = f212 - f224;
+    f243 = f212 + f224;
+    f244 = f219 - f231;
+    f245 = f219 + f231;
+    f246 = f218 - f230;
+    f247 = f218 + f230;
+    f248 = f232 + f234;
+    f249 = MUL_C(COEF_CONST(1.3065629648763766), f232);
+    f250 = MUL_F(FRAC_CONST(-0.9238795325112866), f248);
+    f251 = MUL_F(FRAC_CONST(-0.5411961001461967), f234);
+    f252 = f249 + f250;
+    f253 = f251 - f250;
+    f254 = f236 + f238;
+    f255 = MUL_F(FRAC_CONST(0.5411961001461969), f236);
+    f256 = MUL_F(FRAC_CONST(0.3826834323650898), f254);
+    f257 = MUL_C(COEF_CONST(1.3065629648763766), f238);
+    f258 = f255 + f256;
+    f259 = f257 - f256;
+    f260 = f240 + f242;
+    f261 = MUL_C(COEF_CONST(1.3065629648763766), f240);
+    f262 = MUL_F(FRAC_CONST(-0.9238795325112866), f260);
+    f263 = MUL_F(FRAC_CONST(-0.5411961001461967), f242);
+    f264 = f261 + f262;
+    f265 = f263 - f262;
+    f266 = f244 + f246;
+    f267 = MUL_F(FRAC_CONST(0.5411961001461969), f244);
+    f268 = MUL_F(FRAC_CONST(0.3826834323650898), f266);
+    f269 = MUL_C(COEF_CONST(1.3065629648763766), f246);
+    f270 = f267 + f268;
+    f271 = f269 - f268;
+    f272 = f233 - f237;
+    f273 = f233 + f237;
+    f274 = f235 - f239;
+    f275 = f235 + f239;
+    f276 = f253 - f259;
+    f277 = f253 + f259;
+    f278 = f252 - f258;
+    f279 = f252 + f258;
+    f280 = f241 - f245;
+    f281 = f241 + f245;
+    f282 = f243 - f247;
+    f283 = f243 + f247;
+    f284 = f265 - f271;
+    f285 = f265 + f271;
+    f286 = f264 - f270;
+    f287 = f264 + f270;
+    f288 = f272 - f274;
+    f289 = f272 + f274;
+    f290 = MUL_F(FRAC_CONST(0.7071067811865474), f288);
+    f291 = MUL_F(FRAC_CONST(0.7071067811865474), f289);
+    f292 = f276 - f278;
+    f293 = f276 + f278;
+    f294 = MUL_F(FRAC_CONST(0.7071067811865474), f292);
+    f295 = MUL_F(FRAC_CONST(0.7071067811865474), f293);
+    f296 = f280 - f282;
+    f297 = f280 + f282;
+    f298 = MUL_F(FRAC_CONST(0.7071067811865474), f296);
+    f299 = MUL_F(FRAC_CONST(0.7071067811865474), f297);
+    f300 = f284 - f286;
+    f301 = f284 + f286;
+    f302 = MUL_F(FRAC_CONST(0.7071067811865474), f300);
+    f303 = MUL_F(FRAC_CONST(0.7071067811865474), f301);
+    f304 = f129 - f273;
+    f305 = f129 + f273;
+    f306 = f131 - f281;
+    f307 = f131 + f281;
+    f308 = f133 - f285;
+    f309 = f133 + f285;
+    f310 = f135 - f277;
+    f311 = f135 + f277;
+    f312 = f137 - f295;
+    f313 = f137 + f295;
+    f314 = f139 - f303;
+    f315 = f139 + f303;
+    f316 = f141 - f299;
+    f317 = f141 + f299;
+    f318 = f143 - f291;
+    f319 = f143 + f291;
+    f320 = f142 - f290;
+    f321 = f142 + f290;
+    f322 = f140 - f298;
+    f323 = f140 + f298;
+    f324 = f138 - f302;
+    f325 = f138 + f302;
+    f326 = f136 - f294;
+    f327 = f136 + f294;
+    f328 = f134 - f279;
+    f329 = f134 + f279;
+    f330 = f132 - f287;
+    f331 = f132 + f287;
+    f332 = f130 - f283;
+    f333 = f130 + f283;
+    f334 = f128 - f275;
+    f335 = f128 + f275;
+    y[31] = MUL_F(FRAC_CONST(0.5001506360206510), f305);
+    y[30] = MUL_F(FRAC_CONST(0.5013584524464084), f307);
+    y[29] = MUL_F(FRAC_CONST(0.5037887256810443), f309);
+    y[28] = MUL_F(FRAC_CONST(0.5074711720725553), f311);
+    y[27] = MUL_F(FRAC_CONST(0.5124514794082247), f313);
+    y[26] = MUL_F(FRAC_CONST(0.5187927131053328), f315);
+    y[25] = MUL_F(FRAC_CONST(0.5265773151542700), f317);
+    y[24] = MUL_F(FRAC_CONST(0.5359098169079920), f319);
+    y[23] = MUL_F(FRAC_CONST(0.5469204379855088), f321);
+    y[22] = MUL_F(FRAC_CONST(0.5597698129470802), f323);
+    y[21] = MUL_F(FRAC_CONST(0.5746551840326600), f325);
+    y[20] = MUL_F(FRAC_CONST(0.5918185358574165), f327);
+    y[19] = MUL_F(FRAC_CONST(0.6115573478825099), f329);
+    y[18] = MUL_F(FRAC_CONST(0.6342389366884031), f331);
+    y[17] = MUL_F(FRAC_CONST(0.6603198078137061), f333);
+    y[16] = MUL_F(FRAC_CONST(0.6903721282002123), f335);
+    y[15] = MUL_F(FRAC_CONST(0.7251205223771985), f334);
+    y[14] = MUL_F(FRAC_CONST(0.7654941649730891), f332);
+    y[13] = MUL_F(FRAC_CONST(0.8127020908144905), f330);
+    y[12] = MUL_F(FRAC_CONST(0.8683447152233481), f328);
+    y[11] = MUL_F(FRAC_CONST(0.9345835970364075), f326);
+    y[10] = MUL_C(COEF_CONST(1.0144082649970547), f324);
+    y[9] = MUL_C(COEF_CONST(1.1120716205797176), f322);
+    y[8] = MUL_C(COEF_CONST(1.2338327379765710), f320);
+    y[7] = MUL_C(COEF_CONST(1.3892939586328277), f318);
+    y[6] = MUL_C(COEF_CONST(1.5939722833856311), f316);
+    y[5] = MUL_C(COEF_CONST(1.8746759800084078), f314);
+    y[4] = MUL_C(COEF_CONST(2.2820500680051619), f312);
+    y[3] = MUL_C(COEF_CONST(2.9246284281582162), f310);
+    y[2] = MUL_C(COEF_CONST(4.0846110781292477), f308);
+    y[1] = MUL_C(COEF_CONST(6.7967507116736332), f306);
+    y[0] = MUL_R(REAL_CONST(20.3738781672314530), f304);
+}
+
 #ifdef SBR_LOW_POWER
 
 void DCT2_16_unscaled(real_t *y, real_t *x)
@@ -1811,7 +2228,7 @@
 {
     // Tables with bit reverse values for 5 bits, bit reverse of i at i-th position
     const uint8_t bit_rev_tab[32] = { 0,16,8,24,4,20,12,28,2,18,10,26,6,22,14,30,1,17,9,25,5,21,13,29,3,19,11,27,7,23,15,31 };
-    uint16_t i, i_rev;
+    uint32_t i, i_rev;
 
     /* Step 2: modulate */
     // 3*32=96 multiplications
@@ -1859,413 +2276,6 @@
 
 }
 
-void DST4_32(real_t *y, real_t *x)
-{
-    real_t f0, f1, f2, f3, f4, f5, f6, f7, f8, f9;
-    real_t f10, f11, f12, f13, f14, f15, f16, f17, f18, f19;
-    real_t f20, f21, f22, f23, f24, f25, f26, f27, f28, f29;
-    real_t f30, f31, f32, f33, f34, f35, f36, f37, f38, f39;
-    real_t f40, f41, f42, f43, f44, f45, f46, f47, f48, f49;
-    real_t f50, f51, f52, f53, f54, f55, f56, f57, f58, f59;
-    real_t f60, f61, f62, f63, f64, f65, f66, f67, f68, f69;
-    real_t f70, f71, f72, f73, f74, f75, f76, f77, f78, f79;
-    real_t f80, f81, f82, f83, f84, f85, f86, f87, f88, f89;
-    real_t f90, f91, f92, f93, f94, f95, f96, f97, f98, f99;
-    real_t f100, f101, f102, f103, f104, f105, f106, f107, f108, f109;
-    real_t f110, f111, f112, f113, f114, f115, f116, f117, f118, f119;
-    real_t f120, f121, f122, f123, f124, f125, f126, f127, f128, f129;
-    real_t f130, f131, f132, f133, f134, f135, f136, f137, f138, f139;
-    real_t f140, f141, f142, f143, f144, f145, f146, f147, f148, f149;
-    real_t f150, f151, f152, f153, f154, f155, f156, f157, f158, f159;
-    real_t f160, f161, f162, f163, f164, f165, f166, f167, f168, f169;
-    real_t f170, f171, f172, f173, f174, f175, f176, f177, f178, f179;
-    real_t f180, f181, f182, f183, f184, f185, f186, f187, f188, f189;
-    real_t f190, f191, f192, f193, f194, f195, f196, f197, f198, f199;
-    real_t f200, f201, f202, f203, f204, f205, f206, f207, f208, f209;
-    real_t f210, f211, f212, f213, f214, f215, f216, f217, f218, f219;
-    real_t f220, f221, f222, f223, f224, f225, f226, f227, f228, f229;
-    real_t f230, f231, f232, f233, f234, f235, f236, f237, f238, f239;
-    real_t f240, f241, f242, f243, f244, f245, f246, f247, f248, f249;
-    real_t f250, f251, f252, f253, f254, f255, f256, f257, f258, f259;
-    real_t f260, f261, f262, f263, f264, f265, f266, f267, f268, f269;
-    real_t f270, f271, f272, f273, f274, f275, f276, f277, f278, f279;
-    real_t f280, f281, f282, f283, f284, f285, f286, f287, f288, f289;
-    real_t f290, f291, f292, f293, f294, f295, f296, f297, f298, f299;
-    real_t f300, f301, f302, f303, f304, f305, f306, f307, f308, f309;
-    real_t f310, f311, f312, f313, f314, f315, f316, f317, f318, f319;
-    real_t f320, f321, f322, f323, f324, f325, f326, f327, f328, f329;
-    real_t f330, f331, f332, f333, f334, f335;
-
-    f0 = x[0] - x[1];
-    f1 = x[2] - x[1];
-    f2 = x[2] - x[3];
-    f3 = x[4] - x[3];
-    f4 = x[4] - x[5];
-    f5 = x[6] - x[5];
-    f6 = x[6] - x[7];
-    f7 = x[8] - x[7];
-    f8 = x[8] - x[9];
-    f9 = x[10] - x[9];
-    f10 = x[10] - x[11];
-    f11 = x[12] - x[11];
-    f12 = x[12] - x[13];
-    f13 = x[14] - x[13];
-    f14 = x[14] - x[15];
-    f15 = x[16] - x[15];
-    f16 = x[16] - x[17];
-    f17 = x[18] - x[17];
-    f18 = x[18] - x[19];
-    f19 = x[20] - x[19];
-    f20 = x[20] - x[21];
-    f21 = x[22] - x[21];
-    f22 = x[22] - x[23];
-    f23 = x[24] - x[23];
-    f24 = x[24] - x[25];
-    f25 = x[26] - x[25];
-    f26 = x[26] - x[27];
-    f27 = x[28] - x[27];
-    f28 = x[28] - x[29];
-    f29 = x[30] - x[29];
-    f30 = x[30] - x[31];
-    f31 = MUL_F(FRAC_CONST(0.7071067811865476), f15);
-    f32 = x[0] - f31;
-    f33 = x[0] + f31;
-    f34 = f7 + f23;
-    f35 = MUL_C(COEF_CONST(1.3065629648763766), f7);
-    f36 = MUL_F(FRAC_CONST(-0.9238795325112866), f34);
-    f37 = MUL_F(FRAC_CONST(-0.5411961001461967), f23);
-    f38 = f35 + f36;
-    f39 = f37 - f36;
-    f40 = f33 - f39;
-    f41 = f33 + f39;
-    f42 = f32 - f38;
-    f43 = f32 + f38;
-    f44 = f11 - f19;
-    f45 = f11 + f19;
-    f46 = MUL_F(FRAC_CONST(0.7071067811865476), f45);
-    f47 = f3 - f46;
-    f48 = f3 + f46;
-    f49 = MUL_F(FRAC_CONST(0.7071067811865476), f44);
-    f50 = f49 - f27;
-    f51 = f49 + f27;
-    f52 = f51 + f48;
-    f53 = MUL_F(FRAC_CONST(-0.7856949583871021), f51);
-    f54 = MUL_F(FRAC_CONST(0.9807852804032304), f52);
-    f55 = MUL_C(COEF_CONST(1.1758756024193588), f48);
-    f56 = f53 + f54;
-    f57 = f55 - f54;
-    f58 = f50 + f47;
-    f59 = MUL_F(FRAC_CONST(-0.2758993792829430), f50);
-    f60 = MUL_F(FRAC_CONST(0.8314696123025452), f58);
-    f61 = MUL_C(COEF_CONST(1.3870398453221475), f47);
-    f62 = f59 + f60;
-    f63 = f61 - f60;
-    f64 = f41 - f56;
-    f65 = f41 + f56;
-    f66 = f43 - f62;
-    f67 = f43 + f62;
-    f68 = f42 - f63;
-    f69 = f42 + f63;
-    f70 = f40 - f57;
-    f71 = f40 + f57;
-    f72 = f5 - f9;
-    f73 = f5 + f9;
-    f74 = f13 - f17;
-    f75 = f13 + f17;
-    f76 = f21 - f25;
-    f77 = f21 + f25;
-    f78 = MUL_F(FRAC_CONST(0.7071067811865476), f75);
-    f79 = f1 - f78;
-    f80 = f1 + f78;
-    f81 = f73 + f77;
-    f82 = MUL_C(COEF_CONST(1.3065629648763766), f73);
-    f83 = MUL_F(FRAC_CONST(-0.9238795325112866), f81);
-    f84 = MUL_F(FRAC_CONST(-0.5411961001461967), f77);
-    f85 = f82 + f83;
-    f86 = f84 - f83;
-    f87 = f80 - f86;
-    f88 = f80 + f86;
-    f89 = f79 - f85;
-    f90 = f79 + f85;
-    f91 = MUL_F(FRAC_CONST(0.7071067811865476), f74);
-    f92 = f29 - f91;
-    f93 = f29 + f91;
-    f94 = f76 + f72;
-    f95 = MUL_C(COEF_CONST(1.3065629648763766), f76);
-    f96 = MUL_F(FRAC_CONST(-0.9238795325112866), f94);
-    f97 = MUL_F(FRAC_CONST(-0.5411961001461967), f72);
-    f98 = f95 + f96;
-    f99 = f97 - f96;
-    f100 = f93 - f99;
-    f101 = f93 + f99;
-    f102 = f92 - f98;
-    f103 = f92 + f98;
-    f104 = f101 + f88;
-    f105 = MUL_F(FRAC_CONST(-0.8971675863426361), f101);
-    f106 = MUL_F(FRAC_CONST(0.9951847266721968), f104);
-    f107 = MUL_C(COEF_CONST(1.0932018670017576), f88);
-    f108 = f105 + f106;
-    f109 = f107 - f106;
-    f110 = f90 - f103;
-    f111 = MUL_F(FRAC_CONST(-0.6666556584777466), f103);
-    f112 = MUL_F(FRAC_CONST(0.9569403357322089), f110);
-    f113 = MUL_C(COEF_CONST(1.2472250129866713), f90);
-    f114 = f112 - f111;
-    f115 = f113 - f112;
-    f116 = f102 + f89;
-    f117 = MUL_F(FRAC_CONST(-0.4105245275223571), f102);
-    f118 = MUL_F(FRAC_CONST(0.8819212643483549), f116);
-    f119 = MUL_C(COEF_CONST(1.3533180011743529), f89);
-    f120 = f117 + f118;
-    f121 = f119 - f118;
-    f122 = f87 - f100;
-    f123 = MUL_F(FRAC_CONST(-0.1386171691990915), f100);
-    f124 = MUL_F(FRAC_CONST(0.7730104533627370), f122);
-    f125 = MUL_C(COEF_CONST(1.4074037375263826), f87);
-    f126 = f124 - f123;
-    f127 = f125 - f124;
-    f128 = f65 - f108;
-    f129 = f65 + f108;
-    f130 = f67 - f114;
-    f131 = f67 + f114;
-    f132 = f69 - f120;
-    f133 = f69 + f120;
-    f134 = f71 - f126;
-    f135 = f71 + f126;
-    f136 = f70 - f127;
-    f137 = f70 + f127;
-    f138 = f68 - f121;
-    f139 = f68 + f121;
-    f140 = f66 - f115;
-    f141 = f66 + f115;
-    f142 = f64 - f109;
-    f143 = f64 + f109;
-    f144 = f0 + f30;
-    f145 = MUL_C(COEF_CONST(1.0478631305325901), f0);
-    f146 = MUL_F(FRAC_CONST(-0.9987954562051724), f144);
-    f147 = MUL_F(FRAC_CONST(-0.9497277818777548), f30);
-    f148 = f145 + f146;
-    f149 = f147 - f146;
-    f150 = f4 + f26;
-    f151 = MUL_F(FRAC_CONST(1.2130114330978077), f4);
-    f152 = MUL_F(FRAC_CONST(-0.9700312531945440), f150);
-    f153 = MUL_F(FRAC_CONST(-0.7270510732912803), f26);
-    f154 = f151 + f152;
-    f155 = f153 - f152;
-    f156 = f8 + f22;
-    f157 = MUL_C(COEF_CONST(1.3315443865537255), f8);
-    f158 = MUL_F(FRAC_CONST(-0.9039892931234433), f156);
-    f159 = MUL_F(FRAC_CONST(-0.4764341996931612), f22);
-    f160 = f157 + f158;
-    f161 = f159 - f158;
-    f162 = f12 + f18;
-    f163 = MUL_C(COEF_CONST(1.3989068359730781), f12);
-    f164 = MUL_F(FRAC_CONST(-0.8032075314806453), f162);
-    f165 = MUL_F(FRAC_CONST(-0.2075082269882124), f18);
-    f166 = f163 + f164;
-    f167 = f165 - f164;
-    f168 = f16 + f14;
-    f169 = MUL_C(COEF_CONST(1.4125100802019777), f16);
-    f170 = MUL_F(FRAC_CONST(-0.6715589548470187), f168);
-    f171 = MUL_F(FRAC_CONST(0.0693921705079402), f14);
-    f172 = f169 + f170;
-    f173 = f171 - f170;
-    f174 = f20 + f10;
-    f175 = MUL_C(COEF_CONST(1.3718313541934939), f20);
-    f176 = MUL_F(FRAC_CONST(-0.5141027441932219), f174);
-    f177 = MUL_F(FRAC_CONST(0.3436258658070501), f10);
-    f178 = f175 + f176;
-    f179 = f177 - f176;
-    f180 = f24 + f6;
-    f181 = MUL_C(COEF_CONST(1.2784339185752409), f24);
-    f182 = MUL_F(FRAC_CONST(-0.3368898533922200), f180);
-    f183 = MUL_F(FRAC_CONST(0.6046542117908008), f6);
-    f184 = f181 + f182;
-    f185 = f183 - f182;
-    f186 = f28 + f2;
-    f187 = MUL_C(COEF_CONST(1.1359069844201433), f28);
-    f188 = MUL_F(FRAC_CONST(-0.1467304744553624), f186);
-    f189 = MUL_F(FRAC_CONST(0.8424460355094185), f2);
-    f190 = f187 + f188;
-    f191 = f189 - f188;
-    f192 = f149 - f173;
-    f193 = f149 + f173;
-    f194 = f148 - f172;
-    f195 = f148 + f172;
-    f196 = f155 - f179;
-    f197 = f155 + f179;
-    f198 = f154 - f178;
-    f199 = f154 + f178;
-    f200 = f161 - f185;
-    f201 = f161 + f185;
-    f202 = f160 - f184;
-    f203 = f160 + f184;
-    f204 = f167 - f191;
-    f205 = f167 + f191;
-    f206 = f166 - f190;
-    f207 = f166 + f190;
-    f208 = f192 + f194;
-    f209 = MUL_C(COEF_CONST(1.1758756024193588), f192);
-    f210 = MUL_F(FRAC_CONST(-0.9807852804032304), f208);
-    f211 = MUL_F(FRAC_CONST(-0.7856949583871021), f194);
-    f212 = f209 + f210;
-    f213 = f211 - f210;
-    f214 = f196 + f198;
-    f215 = MUL_C(COEF_CONST(1.3870398453221475), f196);
-    f216 = MUL_F(FRAC_CONST(-0.5555702330196022), f214);
-    f217 = MUL_F(FRAC_CONST(0.2758993792829431), f198);
-    f218 = f215 + f216;
-    f219 = f217 - f216;
-    f220 = f200 + f202;
-    f221 = MUL_F(FRAC_CONST(0.7856949583871022), f200);
-    f222 = MUL_F(FRAC_CONST(0.1950903220161283), f220);
-    f223 = MUL_C(COEF_CONST(1.1758756024193586), f202);
-    f224 = f221 + f222;
-    f225 = f223 - f222;
-    f226 = f204 + f206;
-    f227 = MUL_F(FRAC_CONST(-0.2758993792829430), f204);
-    f228 = MUL_F(FRAC_CONST(0.8314696123025452), f226);
-    f229 = MUL_C(COEF_CONST(1.3870398453221475), f206);
-    f230 = f227 + f228;
-    f231 = f229 - f228;
-    f232 = f193 - f201;
-    f233 = f193 + f201;
-    f234 = f195 - f203;
-    f235 = f195 + f203;
-    f236 = f197 - f205;
-    f237 = f197 + f205;
-    f238 = f199 - f207;
-    f239 = f199 + f207;
-    f240 = f213 - f225;
-    f241 = f213 + f225;
-    f242 = f212 - f224;
-    f243 = f212 + f224;
-    f244 = f219 - f231;
-    f245 = f219 + f231;
-    f246 = f218 - f230;
-    f247 = f218 + f230;
-    f248 = f232 + f234;
-    f249 = MUL_C(COEF_CONST(1.3065629648763766), f232);
-    f250 = MUL_F(FRAC_CONST(-0.9238795325112866), f248);
-    f251 = MUL_F(FRAC_CONST(-0.5411961001461967), f234);
-    f252 = f249 + f250;
-    f253 = f251 - f250;
-    f254 = f236 + f238;
-    f255 = MUL_F(FRAC_CONST(0.5411961001461969), f236);
-    f256 = MUL_F(FRAC_CONST(0.3826834323650898), f254);
-    f257 = MUL_C(COEF_CONST(1.3065629648763766), f238);
-    f258 = f255 + f256;
-    f259 = f257 - f256;
-    f260 = f240 + f242;
-    f261 = MUL_C(COEF_CONST(1.3065629648763766), f240);
-    f262 = MUL_F(FRAC_CONST(-0.9238795325112866), f260);
-    f263 = MUL_F(FRAC_CONST(-0.5411961001461967), f242);
-    f264 = f261 + f262;
-    f265 = f263 - f262;
-    f266 = f244 + f246;
-    f267 = MUL_F(FRAC_CONST(0.5411961001461969), f244);
-    f268 = MUL_F(FRAC_CONST(0.3826834323650898), f266);
-    f269 = MUL_C(COEF_CONST(1.3065629648763766), f246);
-    f270 = f267 + f268;
-    f271 = f269 - f268;
-    f272 = f233 - f237;
-    f273 = f233 + f237;
-    f274 = f235 - f239;
-    f275 = f235 + f239;
-    f276 = f253 - f259;
-    f277 = f253 + f259;
-    f278 = f252 - f258;
-    f279 = f252 + f258;
-    f280 = f241 - f245;
-    f281 = f241 + f245;
-    f282 = f243 - f247;
-    f283 = f243 + f247;
-    f284 = f265 - f271;
-    f285 = f265 + f271;
-    f286 = f264 - f270;
-    f287 = f264 + f270;
-    f288 = f272 - f274;
-    f289 = f272 + f274;
-    f290 = MUL_F(FRAC_CONST(0.7071067811865474), f288);
-    f291 = MUL_F(FRAC_CONST(0.7071067811865474), f289);
-    f292 = f276 - f278;
-    f293 = f276 + f278;
-    f294 = MUL_F(FRAC_CONST(0.7071067811865474), f292);
-    f295 = MUL_F(FRAC_CONST(0.7071067811865474), f293);
-    f296 = f280 - f282;
-    f297 = f280 + f282;
-    f298 = MUL_F(FRAC_CONST(0.7071067811865474), f296);
-    f299 = MUL_F(FRAC_CONST(0.7071067811865474), f297);
-    f300 = f284 - f286;
-    f301 = f284 + f286;
-    f302 = MUL_F(FRAC_CONST(0.7071067811865474), f300);
-    f303 = MUL_F(FRAC_CONST(0.7071067811865474), f301);
-    f304 = f129 - f273;
-    f305 = f129 + f273;
-    f306 = f131 - f281;
-    f307 = f131 + f281;
-    f308 = f133 - f285;
-    f309 = f133 + f285;
-    f310 = f135 - f277;
-    f311 = f135 + f277;
-    f312 = f137 - f295;
-    f313 = f137 + f295;
-    f314 = f139 - f303;
-    f315 = f139 + f303;
-    f316 = f141 - f299;
-    f317 = f141 + f299;
-    f318 = f143 - f291;
-    f319 = f143 + f291;
-    f320 = f142 - f290;
-    f321 = f142 + f290;
-    f322 = f140 - f298;
-    f323 = f140 + f298;
-    f324 = f138 - f302;
-    f325 = f138 + f302;
-    f326 = f136 - f294;
-    f327 = f136 + f294;
-    f328 = f134 - f279;
-    f329 = f134 + f279;
-    f330 = f132 - f287;
-    f331 = f132 + f287;
-    f332 = f130 - f283;
-    f333 = f130 + f283;
-    f334 = f128 - f275;
-    f335 = f128 + f275;
-    y[31] = MUL_F(FRAC_CONST(0.5001506360206510), f305);
-    y[30] = MUL_F(FRAC_CONST(0.5013584524464084), f307);
-    y[29] = MUL_F(FRAC_CONST(0.5037887256810443), f309);
-    y[28] = MUL_F(FRAC_CONST(0.5074711720725553), f311);
-    y[27] = MUL_F(FRAC_CONST(0.5124514794082247), f313);
-    y[26] = MUL_F(FRAC_CONST(0.5187927131053328), f315);
-    y[25] = MUL_F(FRAC_CONST(0.5265773151542700), f317);
-    y[24] = MUL_F(FRAC_CONST(0.5359098169079920), f319);
-    y[23] = MUL_F(FRAC_CONST(0.5469204379855088), f321);
-    y[22] = MUL_F(FRAC_CONST(0.5597698129470802), f323);
-    y[21] = MUL_F(FRAC_CONST(0.5746551840326600), f325);
-    y[20] = MUL_F(FRAC_CONST(0.5918185358574165), f327);
-    y[19] = MUL_F(FRAC_CONST(0.6115573478825099), f329);
-    y[18] = MUL_F(FRAC_CONST(0.6342389366884031), f331);
-    y[17] = MUL_F(FRAC_CONST(0.6603198078137061), f333);
-    y[16] = MUL_F(FRAC_CONST(0.6903721282002123), f335);
-    y[15] = MUL_F(FRAC_CONST(0.7251205223771985), f334);
-    y[14] = MUL_F(FRAC_CONST(0.7654941649730891), f332);
-    y[13] = MUL_F(FRAC_CONST(0.8127020908144905), f330);
-    y[12] = MUL_F(FRAC_CONST(0.8683447152233481), f328);
-    y[11] = MUL_F(FRAC_CONST(0.9345835970364075), f326);
-    y[10] = MUL_C(COEF_CONST(1.0144082649970547), f324);
-    y[9] = MUL_C(COEF_CONST(1.1120716205797176), f322);
-    y[8] = MUL_C(COEF_CONST(1.2338327379765710), f320);
-    y[7] = MUL_C(COEF_CONST(1.3892939586328277), f318);
-    y[6] = MUL_C(COEF_CONST(1.5939722833856311), f316);
-    y[5] = MUL_C(COEF_CONST(1.8746759800084078), f314);
-    y[4] = MUL_C(COEF_CONST(2.2820500680051619), f312);
-    y[3] = MUL_C(COEF_CONST(2.9246284281582162), f310);
-    y[2] = MUL_C(COEF_CONST(4.0846110781292477), f308);
-    y[1] = MUL_C(COEF_CONST(6.7967507116736332), f306);
-    y[0] = MUL_R(REAL_CONST(20.3738781672314530), f304);
-}
-
 #endif
 
 #endif
--- a/src/aac/libfaad2/sbr_dct.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_dct.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_dct.h,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_dct.h,v 1.17 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __SBR_DCT_H__
--- a/src/aac/libfaad2/sbr_dec.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_dec.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_dec.c,v 1.39 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_dec.c,v 1.41 2006/05/07 18:09:01 menno Exp $
 **/
 
 
@@ -176,6 +181,72 @@
     }
 }
 
+void sbrReset(sbr_info *sbr)
+{
+    uint8_t j;
+    if (sbr->qmfa[0] != NULL)
+        memset(sbr->qmfa[0]->x, 0, 2 * sbr->qmfa[0]->channels * 10 * sizeof(real_t));
+    if (sbr->qmfa[1] != NULL)
+        memset(sbr->qmfa[1]->x, 0, 2 * sbr->qmfa[1]->channels * 10 * sizeof(real_t));
+    if (sbr->qmfs[0] != NULL)
+        memset(sbr->qmfs[0]->v, 0, 2 * sbr->qmfs[0]->channels * 20 * sizeof(real_t));
+    if (sbr->qmfs[1] != NULL)
+        memset(sbr->qmfs[1]->v, 0, 2 * sbr->qmfs[1]->channels * 20 * sizeof(real_t));
+
+    for (j = 0; j < 5; j++)
+    {
+        if (sbr->G_temp_prev[0][j] != NULL)
+            memset(sbr->G_temp_prev[0][j], 0, 64*sizeof(real_t));
+        if (sbr->G_temp_prev[1][j] != NULL)
+            memset(sbr->G_temp_prev[1][j], 0, 64*sizeof(real_t));
+        if (sbr->Q_temp_prev[0][j] != NULL)
+            memset(sbr->Q_temp_prev[0][j], 0, 64*sizeof(real_t));
+        if (sbr->Q_temp_prev[1][j] != NULL)
+            memset(sbr->Q_temp_prev[1][j], 0, 64*sizeof(real_t));
+    }
+
+    memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
+    memset(sbr->Xsbr[1], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
+    
+    sbr->GQ_ringbuf_index[0] = 0;
+    sbr->GQ_ringbuf_index[1] = 0;
+    sbr->header_count = 0;
+    sbr->Reset = 1;
+
+    sbr->L_E_prev[0] = 0;
+    sbr->L_E_prev[1] = 0;
+    sbr->bs_freq_scale = 2;
+    sbr->bs_alter_scale = 1;
+    sbr->bs_noise_bands = 2;
+    sbr->bs_limiter_bands = 2;
+    sbr->bs_limiter_gains = 2;
+    sbr->bs_interpol_freq = 1;
+    sbr->bs_smoothing_mode = 1;
+    sbr->bs_start_freq = 5;
+    sbr->bs_amp_res = 1;
+    sbr->bs_samplerate_mode = 1;
+    sbr->prevEnvIsShort[0] = -1;
+    sbr->prevEnvIsShort[1] = -1;
+    sbr->bsco = 0;
+    sbr->bsco_prev = 0;
+    sbr->M_prev = 0;
+    sbr->bs_start_freq_prev = -1;
+
+    sbr->f_prev[0] = 0;
+    sbr->f_prev[1] = 0;
+    for (j = 0; j < MAX_M; j++)
+    {
+        sbr->E_prev[0][j] = 0;
+        sbr->Q_prev[0][j] = 0;
+        sbr->E_prev[1][j] = 0;
+        sbr->Q_prev[1][j] = 0;
+        sbr->bs_add_harmonic_prev[0][j] = 0;
+        sbr->bs_add_harmonic_prev[1][j] = 0;
+    }
+    sbr->bs_add_harmonic_flag_prev[0] = 0;
+    sbr->bs_add_harmonic_flag_prev[1] = 0;
+}
+
 static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch)
 {
     uint8_t i;
@@ -226,11 +297,12 @@
     }
 }
 
-static void sbr_process_channel(sbr_info *sbr, real_t *channel_buf, qmf_t X[MAX_NTSR][64],
-                                uint8_t ch, uint8_t dont_process,
-                                const uint8_t downSampledSBR)
+static uint8_t sbr_process_channel(sbr_info *sbr, real_t *channel_buf, qmf_t X[MAX_NTSR][64],
+                                   uint8_t ch, uint8_t dont_process,
+                                   const uint8_t downSampledSBR)
 {
     int16_t k, l;
+    uint8_t ret = 0;
 
 #ifdef SBR_LOW_POWER
     ALIGN real_t deg[64];
@@ -278,7 +350,7 @@
             ,ch);
 #endif
 
-#ifdef SBR_LOW_POWER
+#if 0 //def SBR_LOW_POWER
         for (l = sbr->t_E[ch][0]; l < sbr->t_E[ch][sbr->L_E[ch]]; l++)
         {
             for (k = 0; k < sbr->kx; k++)
@@ -290,12 +362,16 @@
 
 #if 1
         /* hf adjustment */
-        hf_adjustment(sbr, sbr->Xsbr[ch]
+        ret = hf_adjustment(sbr, sbr->Xsbr[ch]
 #ifdef SBR_LOW_POWER
             ,deg
 #endif
             ,ch);
 #endif
+        if (ret > 0)
+        {
+            dont_process = 1;
+        }
     }
 
     if ((sbr->just_seeked != 0) || dont_process)
@@ -367,6 +443,8 @@
 #endif
         }
     }
+
+    return ret;
 }
 
 uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan,
@@ -400,7 +478,7 @@
         sbr->just_seeked = 0;
     }
 
-    sbr_process_channel(sbr, left_chan, X, 0, dont_process, downSampledSBR);
+    sbr->ret += sbr_process_channel(sbr, left_chan, X, 0, dont_process, downSampledSBR);
     /* subband synthesis */
     if (downSampledSBR)
     {
@@ -409,7 +487,7 @@
         sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X, left_chan);
     }
 
-    sbr_process_channel(sbr, right_chan, X, 1, dont_process, downSampledSBR);
+    sbr->ret += sbr_process_channel(sbr, right_chan, X, 1, dont_process, downSampledSBR);
     /* subband synthesis */
     if (downSampledSBR)
     {
@@ -483,7 +561,7 @@
         sbr->just_seeked = 0;
     }
 
-    sbr_process_channel(sbr, channel, X, 0, dont_process, downSampledSBR);
+    sbr->ret += sbr_process_channel(sbr, channel, X, 0, dont_process, downSampledSBR);
     /* subband synthesis */
     if (downSampledSBR)
     {
@@ -526,8 +604,8 @@
     uint8_t l, k;
     uint8_t dont_process = 0;
     uint8_t ret = 0;
-    ALIGN qmf_t X_left[38][64] = {{{0}}};
-    ALIGN qmf_t X_right[38][64] = {{{0}}}; /* must set this to 0 */
+    ALIGN qmf_t X_left[38][64] = {{0}};
+    ALIGN qmf_t X_right[38][64] = {{0}}; /* must set this to 0 */
 
     if (sbr == NULL)
         return 20;
@@ -558,7 +636,7 @@
         sbr->qmfs[1] = qmfs_init((downSampledSBR)?32:64);
     }
 
-    sbr_process_channel(sbr, left_channel, X_left, 0, dont_process, downSampledSBR);
+    sbr->ret += sbr_process_channel(sbr, left_channel, X_left, 0, dont_process, downSampledSBR);
 
     /* copy some extra data for PS */
     for (l = 32; l < 38; l++)
@@ -574,7 +652,7 @@
 #ifdef DRM_PS
     if (sbr->Is_DRM_SBR)
     {
-        drm_ps_decode(sbr->drm_ps, (sbr->ret > 0), sbr->sample_rate, X_left, X_right);
+        drm_ps_decode(sbr->drm_ps, (sbr->ret > 0), X_left, X_right);
     } else {
 #endif
 #ifdef PS_DEC
--- a/src/aac/libfaad2/sbr_dec.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_dec.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_dec.h,v 1.35 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_dec.h,v 1.37 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __SBR_DEC_H__
@@ -183,6 +188,7 @@
 #endif
 #if (defined(PS_DEC) || defined(DRM_PS))
     uint8_t ps_used;
+    uint8_t psResetFlag;
 #endif
 
     /* to get it compiling */
@@ -231,6 +237,7 @@
 #endif
                         );
 void sbrDecodeEnd(sbr_info *sbr);
+void sbrReset(sbr_info *sbr);
 
 uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan,
                              const uint8_t just_seeked, const uint8_t downSampledSBR);
--- a/src/aac/libfaad2/sbr_e_nf.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_e_nf.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_e_nf.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_e_nf.c,v 1.19 2006/05/07 18:09:01 menno Exp $
 **/
 
 #include "common.h"
--- a/src/aac/libfaad2/sbr_e_nf.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_e_nf.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_e_nf.h,v 1.14 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_e_nf.h,v 1.16 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __SBR_E_NF_H__
--- a/src/aac/libfaad2/sbr_fbt.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_fbt.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_fbt.c,v 1.17 2004/09/08 09:43:11 gcp Exp $
+** $Id: sbr_fbt.c,v 1.19 2006/05/07 18:09:01 menno Exp $
 **/
 
 /* Calculate frequency band tables */
--- a/src/aac/libfaad2/sbr_fbt.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_fbt.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_fbt.h,v 1.14 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_fbt.h,v 1.16 2006/05/07 18:09:01 menno Exp $
 **/
 
 #ifndef __SBR_FBT_H__
--- a/src/aac/libfaad2/sbr_hfadj.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_hfadj.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_hfadj.c,v 1.18 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_hfadj.c,v 1.20 2006/05/07 18:09:01 menno Exp $
 **/
 
 /* High Frequency adjustment */
@@ -39,8 +44,8 @@
 
 
 /* static function declarations */
-static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
-                                      qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
+static uint8_t estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
+                                         qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
 static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch);
 #ifdef SBR_LOW_POWER
 static void calc_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch);
@@ -49,13 +54,14 @@
 static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
 
 
-void hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
+uint8_t hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
 #ifdef SBR_LOW_POWER
-                   ,real_t *deg /* aliasing degree */
+                      ,real_t *deg /* aliasing degree */
 #endif
-                   ,uint8_t ch)
+                      ,uint8_t ch)
 {
     ALIGN sbr_hfadj_info adj = {{{0}}};
+    uint8_t ret = 0;
 
     if (sbr->bs_frame_class[ch] == FIXFIX)
     {
@@ -72,7 +78,9 @@
             sbr->l_A[ch] = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
     }
 
-    estimate_current_envelope(sbr, &adj, Xsbr, ch);
+    ret = estimate_current_envelope(sbr, &adj, Xsbr, ch);
+    if (ret > 0)
+        return 1;
 
     calculate_gain(sbr, &adj, ch);
 
@@ -82,6 +90,8 @@
 #endif
 
     hf_assembly(sbr, &adj, Xsbr, ch);
+
+    return 0;
 }
 
 static uint8_t get_S_mapped(sbr_info *sbr, uint8_t ch, uint8_t l, uint8_t current_band)
@@ -125,8 +135,8 @@
     return 0;
 }
 
-static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
-                                      qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch)
+static uint8_t estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
+                                         qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch)
 {
     uint8_t m, l, j, k, k_l, k_h, p;
     real_t nrg, div;
@@ -142,6 +152,9 @@
 
             div = (real_t)(u_i - l_i);
 
+            if (div == 0)
+                div = 1;
+
             for (m = 0; m < sbr->M; m++)
             {
                 nrg = 0;
@@ -192,6 +205,9 @@
 
                     div = (real_t)((u_i - l_i)*(k_h - k_l));
 
+                    if (div == 0)
+                        div = 1;
+
                     for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
                     {
                         for (j = k_l; j < k_h; j++)
@@ -225,6 +241,8 @@
             }
         }
     }
+
+    return 0;
 }
 
 #ifdef FIXED_POINT
@@ -1170,6 +1188,7 @@
             real_t den = 0;
             real_t acc1 = 0;
             real_t acc2 = 0;
+            uint8_t current_res_band_size = 0;
 
             uint8_t ml1, ml2;
 
@@ -1341,15 +1360,27 @@
 {
     uint8_t l, k, i;
     uint8_t grouping;
+    uint8_t S_mapped;
 
     for (l = 0; l < sbr->L_E[ch]; l++)
     {
+        uint8_t current_res_band = 0;
         i = 0;
         grouping = 0;
 
+        S_mapped = get_S_mapped(sbr, ch, l, current_res_band);
+
         for (k = sbr->kx; k < sbr->kx + sbr->M - 1; k++)
         {
-            if (deg[k + 1] && adj->S_mapped[l][k-sbr->kx] == 0)
+            if (k == sbr->f_table_res[sbr->f[ch][l]][current_res_band+1])
+            {
+                /* step to next resolution band */
+                current_res_band++;
+
+                S_mapped = get_S_mapped(sbr, ch, l, current_res_band);
+            }
+
+            if (deg[k + 1] && S_mapped == 0)
             {
                 if (grouping == 0)
                 {
@@ -1360,7 +1391,7 @@
             } else {
                 if (grouping)
                 {
-                    if (adj->S_mapped[l][k-sbr->kx])
+                    if (S_mapped)
                     {
                         sbr->f_group[l][i] = k;
                     } else {
--- a/src/aac/libfaad2/sbr_hfadj.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_hfadj.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_hfadj.h,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_hfadj.h,v 1.17 2006/05/07 18:09:02 menno Exp $
 **/
 
 #ifndef __SBR_HFADJ_H__
@@ -40,11 +45,11 @@
 } sbr_hfadj_info;
 
 
-void hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
+uint8_t hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
 #ifdef SBR_LOW_POWER
-                   ,real_t *deg
+                      ,real_t *deg
 #endif
-                   ,uint8_t ch);
+                      ,uint8_t ch);
 
 
 #ifdef __cplusplus
--- a/src/aac/libfaad2/sbr_hfgen.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_hfgen.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_hfgen.c,v 1.22 2004/09/08 09:43:11 gcp Exp $
+** $Id: sbr_hfgen.c,v 1.24 2006/05/07 18:09:02 menno Exp $
 **/
 
 /* High Frequency generation */
@@ -36,7 +41,6 @@
 #include "sbr_hfgen.h"
 #include "sbr_fbt.h"
 
-
 /* static function declarations */
 #ifdef SBR_LOW_POWER
 static void calc_prediction_coef_lp(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
--- a/src/aac/libfaad2/sbr_hfgen.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_hfgen.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_hfgen.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_hfgen.h,v 1.18 2006/05/07 18:09:02 menno Exp $
 **/
 
 #ifndef __SBR_HFGEN_H__
--- a/src/aac/libfaad2/sbr_huff.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_huff.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_huff.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_huff.c,v 1.19 2006/05/07 18:09:02 menno Exp $
 **/
 
 #include "common.h"
--- a/src/aac/libfaad2/sbr_huff.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_huff.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_huff.h,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_huff.h,v 1.19 2006/05/07 18:09:02 menno Exp $
 **/
 
 #ifndef __SBR_HUFF_H__
--- a/src/aac/libfaad2/sbr_noise.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_noise.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_noise.h,v 1.13 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_noise.h,v 1.15 2006/05/07 18:09:02 menno Exp $
 **/
 
 #ifndef __SBR_NOISE_H__
--- a/src/aac/libfaad2/sbr_qmf.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_qmf.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_qmf.c,v 1.27 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_qmf.c,v 1.30 2006/05/26 19:21:35 menno Exp $
 **/
 
 #include "common.h"
@@ -72,7 +77,7 @@
 #else
     ALIGN real_t y[32];
 #endif
-    uint16_t in = 0;
+    uint32_t in = 0;
     uint8_t l;
 
     /* qmf subsample l */
@@ -251,7 +256,7 @@
 {
     ALIGN real_t x[16];
     ALIGN real_t y[16];
-    int16_t n, k, out = 0;
+    int32_t n, k, out = 0;
     uint8_t l;
 
     /* qmf subsample l */
@@ -320,7 +325,7 @@
 {
     ALIGN real_t x[64];
     ALIGN real_t y[64];
-    int16_t n, k, out = 0;
+    int32_t n, k, out = 0;
     uint8_t l;
 
 
@@ -392,7 +397,7 @@
 #ifndef FIXED_POINT
     real_t scale = 1.f/64.f;
 #endif
-    int16_t n, k, out = 0;
+    int32_t n, k, out = 0;
     uint8_t l;
 
 
@@ -475,7 +480,7 @@
 #ifndef FIXED_POINT
     real_t scale = 1.f/64.f;
 #endif
-    int16_t n, k, out = 0;
+    int32_t n, k, out = 0;
     uint8_t l;
 
 
--- a/src/aac/libfaad2/sbr_qmf.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_qmf.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_qmf.h,v 1.21 2004/09/08 09:43:11 gcp Exp $
+** $Id: sbr_qmf.h,v 1.23 2006/05/07 18:09:02 menno Exp $
 **/
 
 #ifndef __SBR_QMF_H__
--- a/src/aac/libfaad2/sbr_qmf_c.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_qmf_c.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_qmf_c.h,v 1.13 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_qmf_c.h,v 1.15 2006/05/07 18:09:02 menno Exp $
 **/
 
 #ifndef __SBR_QMF_C_H__
--- a/src/aac/libfaad2/sbr_syntax.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_syntax.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_syntax.c,v 1.34 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_syntax.c,v 1.36 2006/05/07 18:09:02 menno Exp $
 **/
 
 #include "common.h"
@@ -46,6 +51,7 @@
 #include "analysis.h"
 
 /* static function declarations */
+/* static function declarations */
 static void sbr_header(bitfile *ld, sbr_info *sbr);
 static uint8_t calc_sbr_tables(sbr_info *sbr, uint8_t start_freq, uint8_t stop_freq,
                                uint8_t samplerate_mode, uint8_t freq_scale,
@@ -131,16 +137,23 @@
 }
 
 /* table 2 */
-uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt)
+uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt,
+                           uint8_t psResetFlag)
 {
     uint8_t result = 0;
     uint16_t num_align_bits = 0;
-    uint16_t num_sbr_bits = (uint16_t)faad_get_processed_bits(ld);
+    uint16_t num_sbr_bits1 = (uint16_t)faad_get_processed_bits(ld);
+    uint16_t num_sbr_bits2;
 
     uint8_t saved_start_freq, saved_samplerate_mode;
     uint8_t saved_stop_freq, saved_freq_scale;
     uint8_t saved_alter_scale, saved_xover_band;
 
+#if (defined(PS_DEC) || defined(DRM_PS))
+    if (psResetFlag)
+        sbr->psResetFlag = psResetFlag;
+#endif
+
 #ifdef DRM
     if (!sbr->Is_DRM_SBR)
 #endif
@@ -206,28 +219,40 @@
             {
                 calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq,
                     saved_samplerate_mode, saved_freq_scale,
-                    saved_alter_scale, saved_xover_band);
+                    saved_alter_scale, saved_xover_band);          
             }
 
-            /* we should be able to safely set result to 0 now */
-            result = 0;
+            /* we should be able to safely set result to 0 now, */
+            /* but practise indicates this doesn't work well */
         }
     } else {
         result = 1;
     }
 
+    num_sbr_bits2 = (uint16_t)faad_get_processed_bits(ld) - num_sbr_bits1;
+
+    /* check if we read more bits then were available for sbr */
+    if (8*cnt < num_sbr_bits2)
+    {
+        faad_resetbits(ld, num_sbr_bits1 + 8*cnt);
+        num_sbr_bits2 = 8*cnt;
+
+#ifdef PS_DEC
+        /* turn off PS for the unfortunate case that we randomly read some
+         * PS data that looks correct */
+        sbr->ps_used = 0;
+#endif
+
+        /* Make sure it doesn't decode SBR in this frame, or we'll get glitches */
+        return 1;
+    }
+
 #ifdef DRM
     if (!sbr->Is_DRM_SBR)
 #endif
-    {
-        num_sbr_bits = (uint16_t)faad_get_processed_bits(ld) - num_sbr_bits;
-
-        /* check if we read more bits then were available for sbr */
-        if (8*cnt < num_sbr_bits)
-            return 1;
-
+    {       
         /* -4 does not apply, bs_extension_type is re-read in this function */
-        num_align_bits = 8*cnt /*- 4*/ - num_sbr_bits;
+        num_align_bits = 8*cnt /*- 4*/ - num_sbr_bits2;
 
         while (num_align_bits > 7)
         {
@@ -364,11 +389,14 @@
 #ifdef DRM
     /* bs_coupling, from sbr_channel_pair_base_element(bs_amp_res) */
     if (sbr->Is_DRM_SBR)
+    {
         faad_get1bit(ld);
+    }
 #endif
 
     if ((result = sbr_grid(ld, sbr, 0)) > 0)
         return result;
+
     sbr_dtdf(ld, sbr, 0);
     invf_mode(ld, sbr, 0);
     sbr_envelope(ld, sbr, 0);
@@ -431,7 +459,11 @@
                 } else {
                     /* to be safe make it 3, will switch to "default"
                      * in sbr_extension() */
+#ifdef DRM
+                    return 1;
+#else
                     sbr->bs_extension_id = 3;
+#endif
                 }
             }
 #endif
@@ -829,6 +861,10 @@
         {
             sbr->ps = ps_init(get_sr_index(sbr->sample_rate));
         }
+        if (sbr->psResetFlag)
+        {
+            sbr->ps->header_read = 0;
+        }
         ret = ps_data(sbr->ps, ld, &header);
 
         /* enable PS if and only if: a header has been decoded */
@@ -837,6 +873,11 @@
             sbr->ps_used = 1;
         }
 
+        if (header == 1)
+        {
+            sbr->psResetFlag = 0;
+        }
+
         return ret;
 #endif
 #ifdef DRM_PS
--- a/src/aac/libfaad2/sbr_syntax.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_syntax.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_syntax.h,v 1.19 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_syntax.h,v 1.21 2006/05/07 18:09:02 menno Exp $
 **/
 
 #ifndef __SBR_SYNTAX_H__
@@ -55,7 +60,8 @@
 #define NOISE_FLOOR_OFFSET 6
 
 
-uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt);
+uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt,
+                           uint8_t resetFlag);
 
 #ifdef __cplusplus
 }
--- a/src/aac/libfaad2/sbr_tf_grid.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_tf_grid.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_tf_grid.c,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_tf_grid.c,v 1.17 2006/05/07 18:09:02 menno Exp $
 **/
 
 /* Time/Frequency grid */
--- a/src/aac/libfaad2/sbr_tf_grid.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sbr_tf_grid.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_tf_grid.h,v 1.13 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_tf_grid.h,v 1.15 2006/05/07 18:09:02 menno Exp $
 **/
 
 #ifndef __SBR_TF_GRID_H__
--- a/src/aac/libfaad2/sine_win.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/sine_win.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: sine_win.h,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sine_win.h,v 1.17 2006/05/07 18:09:02 menno Exp $
 **/
 
 #ifndef __SINE_WIN_H__
--- a/src/aac/libfaad2/specrec.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/specrec.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: specrec.c,v 1.56 2004/09/08 09:43:11 gcp Exp $
+** $Id: specrec.c,v 1.58 2006/05/07 18:09:03 menno Exp $
 **/
 
 /*
@@ -327,6 +332,11 @@
         }
 #endif
 
+        if (ics->max_sfb > ics->num_swb)
+        {
+            return 32;
+        }
+
         /* preparation of sect_sfb_offset for long blocks */
         /* also copy the last value! */
 #ifdef LD_DEC
@@ -348,6 +358,7 @@
             }
             ics->sect_sfb_offset[0][ics->num_swb] = hDecoder->frameLength;
             ics->swb_offset[ics->num_swb] = hDecoder->frameLength;
+            ics->swb_offset_max = hDecoder->frameLength;
         } else {
 #endif
             for (i = 0; i < ics->num_swb; i++)
@@ -357,6 +368,7 @@
             }
             ics->sect_sfb_offset[0][ics->num_swb] = hDecoder->frameLength;
             ics->swb_offset[ics->num_swb] = hDecoder->frameLength;
+            ics->swb_offset_max = hDecoder->frameLength;
 #ifdef LD_DEC
         }
 #endif
@@ -367,9 +379,15 @@
         ics->window_group_length[ics->num_window_groups-1] = 1;
         ics->num_swb = num_swb_128_window[sf_index];
 
+        if (ics->max_sfb > ics->num_swb)
+        {
+            return 32;
+        }
+
         for (i = 0; i < ics->num_swb; i++)
             ics->swb_offset[i] = swb_offset_128_window[sf_index][i];
         ics->swb_offset[ics->num_swb] = hDecoder->frameLength/8;
+        ics->swb_offset_max = hDecoder->frameLength/8;
 
         for (i = 0; i < ics->num_windows-1; i++) {
             if (bit_set(ics->scale_factor_grouping, 6-i) == 0)
@@ -405,13 +423,13 @@
         }
         return 0;
     default:
-        return 1;
+        return 32;
     }
 }
 
 /* iquant() *
- * output = sign(input)*abs(input)^(4/3)
- */
+/* output = sign(input)*abs(input)^(4/3) */
+/**/
 static INLINE real_t iquant(int16_t q, const real_t *tab, uint8_t *error)
 {
 #ifdef FIXED_POINT
@@ -667,18 +685,21 @@
 static uint8_t allocate_single_channel(NeAACDecHandle hDecoder, uint8_t channel,
                                        uint8_t output_channels)
 {
-    uint8_t mul = 1;
+    int mul = 1;
 
 #ifdef MAIN_DEC
     /* MAIN object type prediction */
     if (hDecoder->object_type == MAIN)
     {
         /* allocate the state only when needed */
-        if (hDecoder->pred_stat[channel] == NULL)
+        if (hDecoder->pred_stat[channel] != NULL)
         {
-            hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state));
-            reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength);
+            faad_free(hDecoder->pred_stat[channel]);
+            hDecoder->pred_stat[channel] = NULL;
         }
+
+        hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state));
+        reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength);
     }
 #endif
 
@@ -686,15 +707,23 @@
     if (is_ltp_ot(hDecoder->object_type))
     {
         /* allocate the state only when needed */
-        if (hDecoder->lt_pred_stat[channel] == NULL)
+        if (hDecoder->lt_pred_stat[channel] != NULL)
         {
-            hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t));
-            memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t));
+            faad_free(hDecoder->lt_pred_stat[channel]);
+            hDecoder->lt_pred_stat[channel] = NULL;
         }
+
+        hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t));
+        memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t));
     }
 #endif
 
-    if (hDecoder->time_out[channel] == NULL)
+    if (hDecoder->time_out[channel] != NULL)
+    {
+        faad_free(hDecoder->time_out[channel]);
+        hDecoder->time_out[channel] = NULL;
+    }
+
     {
         mul = 1;
 #ifdef SBR_DEC
@@ -709,23 +738,30 @@
         hDecoder->time_out[channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t));
         memset(hDecoder->time_out[channel], 0, mul*hDecoder->frameLength*sizeof(real_t));
     }
+
 #if (defined(PS_DEC) || defined(DRM_PS))
     if (output_channels == 2)
     {
-        if (hDecoder->time_out[channel+1] == NULL)
+        if (hDecoder->time_out[channel+1] != NULL)
         {
-            hDecoder->time_out[channel+1] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t));
-            memset(hDecoder->time_out[channel+1], 0, mul*hDecoder->frameLength*sizeof(real_t));
+            faad_free(hDecoder->time_out[channel+1]);
+            hDecoder->time_out[channel+1] = NULL;
         }
+
+        hDecoder->time_out[channel+1] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t));
+        memset(hDecoder->time_out[channel+1], 0, mul*hDecoder->frameLength*sizeof(real_t));
     }
 #endif
 
-    if (hDecoder->fb_intermed[channel] == NULL)
+    if (hDecoder->fb_intermed[channel] != NULL)
     {
-        hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t));
-        memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t));
+        faad_free(hDecoder->fb_intermed[channel]);
+        hDecoder->fb_intermed[channel] = NULL;
     }
 
+    hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t));
+    memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t));
+
 #ifdef SSR_DEC
     if (hDecoder->object_type == SSR)
     {
@@ -750,7 +786,7 @@
 static uint8_t allocate_channel_pair(NeAACDecHandle hDecoder,
                                      uint8_t channel, uint8_t paired_channel)
 {
-    uint8_t mul = 1;
+    int mul = 1;
 
 #ifdef MAIN_DEC
     /* MAIN object type prediction */
@@ -855,7 +891,8 @@
 uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics,
                                    element *sce, int16_t *spec_data)
 {
-    uint8_t retval, output_channels;
+    uint8_t retval;
+    int output_channels;
     ALIGN real_t spec_coef[1024];
 
 #ifdef PROFILE
@@ -864,8 +901,13 @@
 
 
     /* always allocate 2 channels, PS can always "suddenly" turn up */
-#if (defined(PS_DEC) || defined(DRM_PS))
+#if ( (defined(DRM) && defined(DRM_PS)) )
     output_channels = 2;
+#elif defined(PS_DEC)
+    if (hDecoder->ps_used[hDecoder->fr_ch_ele])
+        output_channels = 2;
+    else
+        output_channels = 1;
 #else
     output_channels = 1;
 #endif
@@ -876,7 +918,17 @@
         hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;
     } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != output_channels) {
         /* element inconsistency */
-        return 21;
+
+        /* this only happens if PS is actually found but not in the first frame
+         * this means that there is only 1 bitstream element!
+         */
+
+        /* reset the allocation */
+        hDecoder->element_alloced[hDecoder->fr_ch_ele] = 0;
+
+        hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;
+
+        //return 21;
     }
 
     if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0)
@@ -901,7 +953,8 @@
 
 
     /* pns decoding */
-    pns_decode(ics, NULL, spec_coef, NULL, hDecoder->frameLength, 0, hDecoder->object_type);
+    pns_decode(ics, NULL, spec_coef, NULL, hDecoder->frameLength, 0, hDecoder->object_type,
+        &(hDecoder->__r1), &(hDecoder->__r2));
 
 #ifdef MAIN_DEC
     /* MAIN object type prediction */
@@ -985,8 +1038,8 @@
     if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
         && hDecoder->sbr_alloced[hDecoder->fr_ch_ele])
     {
-        uint8_t ele = hDecoder->fr_ch_ele;
-        uint8_t ch = sce->channel;
+        int ele = hDecoder->fr_ch_ele;
+        int ch = sce->channel;
 
         /* following case can happen when forceUpSampling == 1 */
         if (hDecoder->sbr[ele] == NULL)
@@ -1001,9 +1054,9 @@
         }
 
         if (sce->ics1.window_sequence == EIGHT_SHORT_SEQUENCE)
-            hDecoder->sbr[ele]->maxAACLine = 8*sce->ics1.swb_offset[max(sce->ics1.max_sfb-1, 0)];
+            hDecoder->sbr[ele]->maxAACLine = 8*min(sce->ics1.swb_offset[max(sce->ics1.max_sfb-1, 0)], sce->ics1.swb_offset_max);
         else
-            hDecoder->sbr[ele]->maxAACLine = sce->ics1.swb_offset[max(sce->ics1.max_sfb-1, 0)];
+            hDecoder->sbr[ele]->maxAACLine = min(sce->ics1.swb_offset[max(sce->ics1.max_sfb-1, 0)], sce->ics1.swb_offset_max);
 
         /* check if any of the PS tools is used */
 #if (defined(PS_DEC) || defined(DRM_PS))
@@ -1030,11 +1083,12 @@
 
     /* copy L to R when no PS is used */
 #if (defined(PS_DEC) || defined(DRM_PS))
-    if ((hDecoder->ps_used[hDecoder->fr_ch_ele] == 0))
+    if ((hDecoder->ps_used[hDecoder->fr_ch_ele] == 0) &&
+        (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2))
     {
-        uint8_t ele = hDecoder->fr_ch_ele;
-        uint8_t ch = sce->channel;
-        uint16_t frame_size = (hDecoder->sbr_alloced[ele]) ? 2 : 1;
+        int ele = hDecoder->fr_ch_ele;
+        int ch = sce->channel;
+        int frame_size = (hDecoder->sbr_alloced[ele]) ? 2 : 1;
         frame_size *= hDecoder->frameLength*sizeof(real_t);
 
         memcpy(hDecoder->time_out[ch+1], hDecoder->time_out[ch], frame_size);
@@ -1080,10 +1134,13 @@
     /* pns decoding */
     if (ics1->ms_mask_present)
     {
-        pns_decode(ics1, ics2, spec_coef1, spec_coef2, hDecoder->frameLength, 1, hDecoder->object_type);
+        pns_decode(ics1, ics2, spec_coef1, spec_coef2, hDecoder->frameLength, 1, hDecoder->object_type,
+            &(hDecoder->__r1), &(hDecoder->__r2));
     } else {
-        pns_decode(ics1, NULL, spec_coef1, NULL, hDecoder->frameLength, 0, hDecoder->object_type);
-        pns_decode(ics2, NULL, spec_coef2, NULL, hDecoder->frameLength, 0, hDecoder->object_type);
+        pns_decode(ics1, NULL, spec_coef1, NULL, hDecoder->frameLength, 0, hDecoder->object_type,
+            &(hDecoder->__r1), &(hDecoder->__r2));
+        pns_decode(ics2, NULL, spec_coef2, NULL, hDecoder->frameLength, 0, hDecoder->object_type,
+            &(hDecoder->__r1), &(hDecoder->__r2));
     }
 
     /* mid/side decoding */
@@ -1235,9 +1292,9 @@
     if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
         && hDecoder->sbr_alloced[hDecoder->fr_ch_ele])
     {
-        uint8_t ele = hDecoder->fr_ch_ele;
-        uint8_t ch0 = cpe->channel;
-        uint8_t ch1 = cpe->paired_channel;
+        int ele = hDecoder->fr_ch_ele;
+        int ch0 = cpe->channel;
+        int ch1 = cpe->paired_channel;
 
         /* following case can happen when forceUpSampling == 1 */
         if (hDecoder->sbr[ele] == NULL)
@@ -1252,9 +1309,9 @@
         }
 
         if (cpe->ics1.window_sequence == EIGHT_SHORT_SEQUENCE)
-            hDecoder->sbr[ele]->maxAACLine = 8*cpe->ics1.swb_offset[max(cpe->ics1.max_sfb-1, 0)];
+            hDecoder->sbr[ele]->maxAACLine = 8*min(cpe->ics1.swb_offset[max(cpe->ics1.max_sfb-1, 0)], cpe->ics1.swb_offset_max);
         else
-            hDecoder->sbr[ele]->maxAACLine = cpe->ics1.swb_offset[max(cpe->ics1.max_sfb-1, 0)];
+            hDecoder->sbr[ele]->maxAACLine = min(cpe->ics1.swb_offset[max(cpe->ics1.max_sfb-1, 0)], cpe->ics1.swb_offset_max);
 
         retval = sbrDecodeCoupleFrame(hDecoder->sbr[ele],
             hDecoder->time_out[ch0], hDecoder->time_out[ch1],
--- a/src/aac/libfaad2/specrec.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/specrec.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: specrec.h,v 1.28 2004/09/04 14:56:29 menno Exp $
+** $Id: specrec.h,v 1.30 2006/05/07 18:09:03 menno Exp $
 **/
 
 #ifndef __SPECREC_H__
--- a/src/aac/libfaad2/ssr.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ssr.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ssr.c,v 1.15 2004/09/04 14:56:29 menno Exp $
+** $Id: ssr.c,v 1.17 2006/05/07 18:09:03 menno Exp $
 **/
 
 #include "common.h"
--- a/src/aac/libfaad2/ssr.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ssr.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ssr.h,v 1.15 2004/09/04 14:56:29 menno Exp $
+** $Id: ssr.h,v 1.17 2006/05/07 18:09:03 menno Exp $
 **/
 
 #ifndef __SSR_H__
--- a/src/aac/libfaad2/ssr_fb.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ssr_fb.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ssr_fb.c,v 1.13 2004/09/04 14:56:29 menno Exp $
+** $Id: ssr_fb.c,v 1.15 2006/05/07 18:09:03 menno Exp $
 **/
 
 #include "common.h"
--- a/src/aac/libfaad2/ssr_fb.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ssr_fb.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
-** FAAD - Freeware Advanced Audio Decoder
-** Copyright (C) 2002 M. Bakker
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003-2005 M. Bakker, Ahead Software AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,9 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
 **
-** $Id: ssr_fb.h,v 1.13 2004/09/04 14:56:29 menno Exp $
+** Software using this code must display the following message visibly in the
+** software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Ahead Software, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+**
+** $Id: ssr_fb.h,v 1.14 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SSR_FB_H__
--- a/src/aac/libfaad2/ssr_ipqf.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ssr_ipqf.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: ssr_ipqf.c,v 1.14 2004/09/04 14:56:29 menno Exp $
+** $Id: ssr_ipqf.c,v 1.16 2006/05/07 18:09:03 menno Exp $
 **/
 
 #include "common.h"
--- a/src/aac/libfaad2/ssr_ipqf.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ssr_ipqf.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
-** FAAD - Freeware Advanced Audio Decoder
-** Copyright (C) 2002 M. Bakker
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003-2005 M. Bakker, Ahead Software AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,9 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
 **
-** $Id: ssr_ipqf.h,v 1.14 2004/09/04 14:56:29 menno Exp $
+** Software using this code must display the following message visibly in the
+** software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Ahead Software, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+**
+** $Id: ssr_ipqf.h,v 1.15 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SSR_IPQF_H__
--- a/src/aac/libfaad2/ssr_win.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/ssr_win.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
-** FAAD - Freeware Advanced Audio Decoder
-** Copyright (C) 2002 M. Bakker
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003-2005 M. Bakker, Ahead Software AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,9 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
 **
-** $Id: ssr_win.h,v 1.13 2004/09/04 14:56:29 menno Exp $
+** Software using this code must display the following message visibly in the
+** software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Ahead Software, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+**
+** $Id: ssr_win.h,v 1.14 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SSR_WIN_H__
--- a/src/aac/libfaad2/structs.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/structs.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,28 +1,33 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
-**
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
-**
+** 
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
-**
+** 
 ** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: structs.h,v 1.42 2004/09/08 09:43:11 gcp Exp $
+** $Id: structs.h,v 1.44 2006/05/07 18:09:03 menno Exp $
 **/
 
 #ifndef __STRUCTS_H__
@@ -46,13 +51,13 @@
 
 /* used to save the prediction state */
 typedef struct {
-    signed short r[2];
-    signed short COR[2];
-    signed short VAR[2];
+    int16_t r[2];
+    int16_t COR[2];
+    int16_t VAR[2];
 } pred_state;
 
 typedef struct {
-    unsigned short N;
+    uint16_t N;
     cfft_info *cfft;
     complex_t *sincos;
 #ifdef PROFILE
@@ -81,17 +86,17 @@
 
 typedef struct
 {
-    unsigned char present;
+    uint8_t present;
 
-    unsigned char num_bands;
-    unsigned char pce_instance_tag;
-    unsigned char excluded_chns_present;
-    unsigned char band_top[17];
-    unsigned char prog_ref_level;
-    unsigned char dyn_rng_sgn[17];
-    unsigned char dyn_rng_ctl[17];
-    unsigned char exclude_mask[MAX_CHANNELS];
-    unsigned char additional_excluded_chns[MAX_CHANNELS];
+    uint8_t num_bands;
+    uint8_t pce_instance_tag;
+    uint8_t excluded_chns_present;
+    uint8_t band_top[17];
+    uint8_t prog_ref_level;
+    uint8_t dyn_rng_sgn[17];
+    uint8_t dyn_rng_ctl[17];
+    uint8_t exclude_mask[MAX_CHANNELS];
+    uint8_t additional_excluded_chns[MAX_CHANNELS];
 
     real_t ctrl1;
     real_t ctrl2;
@@ -99,81 +104,81 @@
 
 typedef struct
 {
-    unsigned char element_instance_tag;
-    unsigned char object_type;
-    unsigned char sf_index;
-    unsigned char num_front_channel_elements;
-    unsigned char num_side_channel_elements;
-    unsigned char num_back_channel_elements;
-    unsigned char num_lfe_channel_elements;
-    unsigned char num_assoc_data_elements;
-    unsigned char num_valid_cc_elements;
-    unsigned char mono_mixdown_present;
-    unsigned char mono_mixdown_element_number;
-    unsigned char stereo_mixdown_present;
-    unsigned char stereo_mixdown_element_number;
-    unsigned char matrix_mixdown_idx_present;
-    unsigned char pseudo_surround_enable;
-    unsigned char matrix_mixdown_idx;
-    unsigned char front_element_is_cpe[16];
-    unsigned char front_element_tag_select[16];
-    unsigned char side_element_is_cpe[16];
-    unsigned char side_element_tag_select[16];
-    unsigned char back_element_is_cpe[16];
-    unsigned char back_element_tag_select[16];
-    unsigned char lfe_element_tag_select[16];
-    unsigned char assoc_data_element_tag_select[16];
-    unsigned char cc_element_is_ind_sw[16];
-    unsigned char valid_cc_element_tag_select[16];
+    uint8_t element_instance_tag;
+    uint8_t object_type;
+    uint8_t sf_index;
+    uint8_t num_front_channel_elements;
+    uint8_t num_side_channel_elements;
+    uint8_t num_back_channel_elements;
+    uint8_t num_lfe_channel_elements;
+    uint8_t num_assoc_data_elements;
+    uint8_t num_valid_cc_elements;
+    uint8_t mono_mixdown_present;
+    uint8_t mono_mixdown_element_number;
+    uint8_t stereo_mixdown_present;
+    uint8_t stereo_mixdown_element_number;
+    uint8_t matrix_mixdown_idx_present;
+    uint8_t pseudo_surround_enable;
+    uint8_t matrix_mixdown_idx;
+    uint8_t front_element_is_cpe[16];
+    uint8_t front_element_tag_select[16];
+    uint8_t side_element_is_cpe[16];
+    uint8_t side_element_tag_select[16];
+    uint8_t back_element_is_cpe[16];
+    uint8_t back_element_tag_select[16];
+    uint8_t lfe_element_tag_select[16];
+    uint8_t assoc_data_element_tag_select[16];
+    uint8_t cc_element_is_ind_sw[16];
+    uint8_t valid_cc_element_tag_select[16];
 
-    unsigned char channels;
+    uint8_t channels;
 
-    unsigned char comment_field_bytes;
-    unsigned char comment_field_data[257];
+    uint8_t comment_field_bytes;
+    uint8_t comment_field_data[257];
 
     /* extra added values */
-    unsigned char num_front_channels;
-    unsigned char num_side_channels;
-    unsigned char num_back_channels;
-    unsigned char num_lfe_channels;
-    unsigned char sce_channel[16];
-    unsigned char cpe_channel[16];
+    uint8_t num_front_channels;
+    uint8_t num_side_channels;
+    uint8_t num_back_channels;
+    uint8_t num_lfe_channels;
+    uint8_t sce_channel[16];
+    uint8_t cpe_channel[16];
 } program_config;
 
 typedef struct
 {
-    unsigned short syncword;
-    unsigned char id;
-    unsigned char layer;
-    unsigned char protection_absent;
-    unsigned char profile;
-    unsigned char sf_index;
-    unsigned char private_bit;
-    unsigned char channel_configuration;
-    unsigned char original;
-    unsigned char home;
-    unsigned char emphasis;
-    unsigned char copyright_identification_bit;
-    unsigned char copyright_identification_start;
-    unsigned short aac_frame_length;
-    unsigned short adts_buffer_fullness;
-    unsigned char no_raw_data_blocks_in_frame;
-    unsigned short crc_check;
+    uint16_t syncword;
+    uint8_t id;
+    uint8_t layer;
+    uint8_t protection_absent;
+    uint8_t profile;
+    uint8_t sf_index;
+    uint8_t private_bit;
+    uint8_t channel_configuration;
+    uint8_t original;
+    uint8_t home;
+    uint8_t emphasis;
+    uint8_t copyright_identification_bit;
+    uint8_t copyright_identification_start;
+    uint16_t aac_frame_length;
+    uint16_t adts_buffer_fullness;
+    uint8_t no_raw_data_blocks_in_frame;
+    uint16_t crc_check;
 
     /* control param */
-    unsigned char old_format;
+    uint8_t old_format;
 } adts_header;
 
 typedef struct
 {
-    unsigned char copyright_id_present;
-    signed char copyright_id[10];
-    unsigned char original_copy;
-    unsigned char home;
-    unsigned char bitstream_type;
-    unsigned long bitrate;
-    unsigned char num_program_config_elements;
-    unsigned long adif_buffer_fullness;
+    uint8_t copyright_id_present;
+    int8_t copyright_id[10];
+    uint8_t original_copy;
+    uint8_t home;
+    uint8_t bitstream_type;
+    uint32_t bitrate;
+    uint8_t num_program_config_elements;
+    uint32_t adif_buffer_fullness;
 
     /* maximum of 16 PCEs */
     program_config pce[16];
@@ -182,90 +187,92 @@
 #ifdef LTP_DEC
 typedef struct
 {
-    unsigned char last_band;
-    unsigned char data_present;
-    unsigned short lag;
-    unsigned char lag_update;
-    unsigned char coef;
-    unsigned char long_used[MAX_SFB];
-    unsigned char short_used[8];
-    unsigned char short_lag_present[8];
-    unsigned char short_lag[8];
+    uint8_t last_band;
+    uint8_t data_present;
+    uint16_t lag;
+    uint8_t lag_update;
+    uint8_t coef;
+    uint8_t long_used[MAX_SFB];
+    uint8_t short_used[8];
+    uint8_t short_lag_present[8];
+    uint8_t short_lag[8];
 } ltp_info;
 #endif
 
 #ifdef MAIN_DEC
 typedef struct
 {
-    unsigned char limit;
-    unsigned char predictor_reset;
-    unsigned char predictor_reset_group_number;
-    unsigned char prediction_used[MAX_SFB];
+    uint8_t limit;
+    uint8_t predictor_reset;
+    uint8_t predictor_reset_group_number;
+    uint8_t prediction_used[MAX_SFB];
 } pred_info;
 #endif
 
 typedef struct
 {
-    unsigned char number_pulse;
-    unsigned char pulse_start_sfb;
-    unsigned char pulse_offset[4];
-    unsigned char pulse_amp[4];
+    uint8_t number_pulse;
+    uint8_t pulse_start_sfb;
+    uint8_t pulse_offset[4];
+    uint8_t pulse_amp[4];
 } pulse_info;
 
 typedef struct
 {
-    unsigned char n_filt[8];
-    unsigned char coef_res[8];
-    unsigned char length[8][4];
-    unsigned char order[8][4];
-    unsigned char direction[8][4];
-    unsigned char coef_compress[8][4];
-    unsigned char coef[8][4][32];
+    uint8_t n_filt[8];
+    uint8_t coef_res[8];
+    uint8_t length[8][4];
+    uint8_t order[8][4];
+    uint8_t direction[8][4];
+    uint8_t coef_compress[8][4];
+    uint8_t coef[8][4][32];
 } tns_info;
 
 #ifdef SSR_DEC
 typedef struct
 {
-    unsigned char max_band;
+    uint8_t max_band;
 
-    unsigned char adjust_num[4][8];
-    unsigned char alevcode[4][8][8];
-    unsigned char aloccode[4][8][8];
+    uint8_t adjust_num[4][8];
+    uint8_t alevcode[4][8][8];
+    uint8_t aloccode[4][8][8];
 } ssr_info;
 #endif
 
 typedef struct
 {
-    unsigned char max_sfb;
+    uint8_t max_sfb;
 
-    unsigned char num_swb;
-    unsigned char num_window_groups;
-    unsigned char num_windows;
-    unsigned char window_sequence;
-    unsigned char window_group_length[8];
-    unsigned char window_shape;
-    unsigned char scale_factor_grouping;
-    unsigned short sect_sfb_offset[8][15*8];
-    unsigned short swb_offset[52];
+    uint8_t num_swb;
+    uint8_t num_window_groups;
+    uint8_t num_windows;
+    uint8_t window_sequence;
+    uint8_t window_group_length[8];
+    uint8_t window_shape;
+    uint8_t scale_factor_grouping;
+    uint16_t sect_sfb_offset[8][15*8];
+    uint16_t swb_offset[52];
+    uint16_t swb_offset_max;
 
-    unsigned char sect_cb[8][15*8];
-    unsigned short sect_start[8][15*8];
-    unsigned short sect_end[8][15*8];
-    unsigned char sfb_cb[8][8*15];
-    unsigned char num_sec[8]; /* number of sections in a group */
+    uint8_t sect_cb[8][15*8];
+    uint16_t sect_start[8][15*8];
+    uint16_t sect_end[8][15*8];
+    uint8_t sfb_cb[8][8*15];
+    uint8_t num_sec[8]; /* number of sections in a group */
 
-    unsigned char global_gain;
-    signed short scale_factors[8][51]; /* [0..255] */
+    uint8_t global_gain;
+    int16_t scale_factors[8][51]; /* [0..255] */
 
-    unsigned char ms_mask_present;
-    unsigned char ms_used[MAX_WINDOW_GROUPS][MAX_SFB];
-
-    unsigned char noise_used;
+    uint8_t ms_mask_present;
+    uint8_t ms_used[MAX_WINDOW_GROUPS][MAX_SFB];
 
-    unsigned char pulse_data_present;
-    unsigned char tns_data_present;
-    unsigned char gain_control_data_present;
-    unsigned char predictor_data_present;
+    uint8_t noise_used;
+    uint8_t is_used;
+
+    uint8_t pulse_data_present;
+    uint8_t tns_data_present;
+    uint8_t gain_control_data_present;
+    uint8_t predictor_data_present;
 
     pulse_info pul;
     tns_info tns;
@@ -282,26 +289,26 @@
 
 #ifdef ERROR_RESILIENCE
     /* ER HCR data */
-    unsigned short length_of_reordered_spectral_data;
-    unsigned char length_of_longest_codeword;
+    uint16_t length_of_reordered_spectral_data;
+    uint8_t length_of_longest_codeword;
     /* ER RLVC data */
-    unsigned char sf_concealment;
-    unsigned char rev_global_gain;
-    unsigned short length_of_rvlc_sf;
-    unsigned short dpcm_noise_nrg;
-    unsigned char sf_escapes_present;
-    unsigned char length_of_rvlc_escapes;
-    unsigned short dpcm_noise_last_position;
+    uint8_t sf_concealment;
+    uint8_t rev_global_gain;
+    uint16_t length_of_rvlc_sf;
+    uint16_t dpcm_noise_nrg;
+    uint8_t sf_escapes_present;
+    uint8_t length_of_rvlc_escapes;
+    uint16_t dpcm_noise_last_position;
 #endif
 } ic_stream; /* individual channel stream */
 
 typedef struct
 {
-    unsigned char channel;
-    signed short paired_channel;
+    uint8_t channel;
+    int16_t paired_channel;
 
-    unsigned char element_instance_tag;
-    unsigned char common_window;
+    uint8_t element_instance_tag;
+    uint8_t common_window;
 
     ic_stream ics1;
     ic_stream ics2;
@@ -310,109 +317,109 @@
 typedef struct mp4AudioSpecificConfig
 {
     /* Audio Specific Info */
-    unsigned char objectTypeIndex;
-    unsigned char samplingFrequencyIndex;
-    unsigned long samplingFrequency;
-    unsigned char channelsConfiguration;
+    /*uint8_t*/ unsigned char objectTypeIndex;
+    /*uint8_t*/ unsigned char samplingFrequencyIndex;
+    /*uint32_t*/ unsigned long samplingFrequency;
+    /*uint8_t*/ unsigned char channelsConfiguration;
 
     /* GA Specific Info */
-    unsigned char frameLengthFlag;
-    unsigned char dependsOnCoreCoder;
-    unsigned short coreCoderDelay;
-    unsigned char extensionFlag;
-    unsigned char aacSectionDataResilienceFlag;
-    unsigned char aacScalefactorDataResilienceFlag;
-    unsigned char aacSpectralDataResilienceFlag;
-    unsigned char epConfig;
+    /*uint8_t*/ unsigned char frameLengthFlag;
+    /*uint8_t*/ unsigned char dependsOnCoreCoder;
+    /*uint16_t*/ unsigned short coreCoderDelay;
+    /*uint8_t*/ unsigned char extensionFlag;
+    /*uint8_t*/ unsigned char aacSectionDataResilienceFlag;
+    /*uint8_t*/ unsigned char aacScalefactorDataResilienceFlag;
+    /*uint8_t*/ unsigned char aacSpectralDataResilienceFlag;
+    /*uint8_t*/ unsigned char epConfig;
 
-    signed char sbr_present_flag;
-    unsigned char forceUpSampling;
-    unsigned char downSampledSBR;
+    /*uint8_t*/ char sbr_present_flag;
+    /*uint8_t*/ char forceUpSampling;
+    /*uint8_t*/ char downSampledSBR;
 } mp4AudioSpecificConfig;
 
 typedef struct NeAACDecConfiguration
 {
-    unsigned char defObjectType;
-    unsigned long defSampleRate;
-    unsigned char outputFormat;
-    unsigned char downMatrix;
-    unsigned char useOldADTSFormat;
-    unsigned char dontUpSampleImplicitSBR;
+    /*uint8_t*/ unsigned char defObjectType;
+    /*uint32_t*/ unsigned long defSampleRate;
+    /*uint8_t*/ unsigned char outputFormat;
+    /*uint8_t*/ unsigned char downMatrix;
+    /*uint8_t*/ unsigned char useOldADTSFormat;
+    /*uint8_t*/ unsigned char dontUpSampleImplicitSBR;
 } NeAACDecConfiguration, *NeAACDecConfigurationPtr;
 
 typedef struct NeAACDecFrameInfo
 {
-    unsigned long bytesconsumed;
-    unsigned long samples;
-    unsigned char channels;
-    unsigned char error;
-    unsigned long samplerate;
+    /*uint32_t*/ unsigned long bytesconsumed;
+    /*uint32_t*/ unsigned long samples;
+    /*uint8_t*/ unsigned char channels;
+    /*uint8_t*/ unsigned char error;
+    /*uint32_t*/ unsigned long samplerate;
 
     /* SBR: 0: off, 1: on; normal, 2: on; downsampled */
-    unsigned char sbr;
+    /*uint8_t*/ unsigned char sbr;
 
     /* MPEG-4 ObjectType */
-    unsigned char object_type;
+    /*uint8_t*/ unsigned char object_type;
 
     /* AAC header type; MP4 will be signalled as RAW also */
-    unsigned char header_type;
+    /*uint8_t*/ unsigned char header_type;
 
     /* multichannel configuration */
-    unsigned char num_front_channels;
-    unsigned char num_side_channels;
-    unsigned char num_back_channels;
-    unsigned char num_lfe_channels;
-    unsigned char channel_position[MAX_CHANNELS];
+    /*uint8_t*/ unsigned char num_front_channels;
+    /*uint8_t*/ unsigned char num_side_channels;
+    /*uint8_t*/ unsigned char num_back_channels;
+    /*uint8_t*/ unsigned char num_lfe_channels;
+    /*uint8_t*/ unsigned char channel_position[MAX_CHANNELS];
 
     /* PS: 0: off, 1: on */
-    unsigned char ps;
+    /*uint8_t*/ unsigned char ps;
 } NeAACDecFrameInfo;
 
 typedef struct
 {
-    unsigned char adts_header_present;
-    unsigned char adif_header_present;
-    unsigned char sf_index;
-    unsigned char object_type;
-    unsigned char channelConfiguration;
+    uint8_t adts_header_present;
+    uint8_t adif_header_present;
+    uint8_t sf_index;
+    uint8_t object_type;
+    uint8_t channelConfiguration;
 #ifdef ERROR_RESILIENCE
-    unsigned char aacSectionDataResilienceFlag;
-    unsigned char aacScalefactorDataResilienceFlag;
-    unsigned char aacSpectralDataResilienceFlag;
+    uint8_t aacSectionDataResilienceFlag;
+    uint8_t aacScalefactorDataResilienceFlag;
+    uint8_t aacSpectralDataResilienceFlag;
 #endif
-    unsigned short frameLength;
-    unsigned char postSeekResetFlag;
+    uint16_t frameLength;
+    uint8_t postSeekResetFlag;
 
-    unsigned long frame;
+    uint32_t frame;
 
-    unsigned char downMatrix;
-    unsigned char upMatrix;
-    unsigned char first_syn_ele;
-    unsigned char has_lfe;
+    uint8_t downMatrix;
+    uint8_t upMatrix;
+    uint8_t first_syn_ele;
+    uint8_t has_lfe;
     /* number of channels in current frame */
-    unsigned char fr_channels;
+    uint8_t fr_channels;
     /* number of elements in current frame */
-    unsigned char fr_ch_ele;
+    uint8_t fr_ch_ele;
 
     /* element_output_channels:
        determines the number of channels the element will output
     */
-    unsigned char element_output_channels[MAX_SYNTAX_ELEMENTS];
+    uint8_t element_output_channels[MAX_SYNTAX_ELEMENTS];
     /* element_alloced:
        determines whether the data needed for the element is allocated or not
     */
-    unsigned char element_alloced[MAX_SYNTAX_ELEMENTS];
+    uint8_t element_alloced[MAX_SYNTAX_ELEMENTS];
     /* alloced_channels:
        determines the number of channels where output data is allocated for
     */
-    unsigned char alloced_channels;
+    uint8_t alloced_channels;
 
     /* output data buffer */
     void *sample_buffer;
 
-    unsigned char window_shape_prev[MAX_CHANNELS];
+    uint8_t window_shape_prev[MAX_CHANNELS];
 #ifdef LTP_DEC
-    unsigned short ltp_lag[MAX_CHANNELS];
+    uint16_t ltp_lag[MAX_CHANNELS];
 #endif
     fb_info *fb;
     drc_info *drc;
@@ -421,17 +428,17 @@
     real_t *fb_intermed[MAX_CHANNELS];
 
 #ifdef SBR_DEC
-    signed char sbr_present_flag;
-    signed char forceUpSampling;
-    signed char downSampledSBR;
+    int8_t sbr_present_flag;
+    int8_t forceUpSampling;
+    int8_t downSampledSBR;
     /* determines whether SBR data is allocated for the gives element */
-    unsigned char sbr_alloced[MAX_SYNTAX_ELEMENTS];
+    uint8_t sbr_alloced[MAX_SYNTAX_ELEMENTS];
 
     sbr_info *sbr[MAX_SYNTAX_ELEMENTS];
 #endif
 #if (defined(PS_DEC) || defined(DRM_PS))
-    unsigned char ps_used[MAX_SYNTAX_ELEMENTS];
-    unsigned char ps_used_global;
+    uint8_t ps_used[MAX_SYNTAX_ELEMENTS];
+    uint8_t ps_used_global;
 #endif
 
 #ifdef SSR_DEC
@@ -444,14 +451,22 @@
     pred_state *pred_stat[MAX_CHANNELS];
 #endif
 #ifdef LTP_DEC
-    signed short *lt_pred_stat[MAX_CHANNELS];
+    int16_t *lt_pred_stat[MAX_CHANNELS];
 #endif
 
+#ifdef DRM
+    uint8_t error_state;
+#endif
+
+    /* RNG states */
+    uint32_t __r1;
+    uint32_t __r2;
+
     /* Program Config Element */
-    unsigned char pce_set;
+    uint8_t pce_set;
     program_config pce;
-    unsigned char element_id[MAX_CHANNELS];
-    unsigned char internal_channel[MAX_CHANNELS];
+    uint8_t element_id[MAX_CHANNELS];
+    uint8_t internal_channel[MAX_CHANNELS];
 
     /* Configuration data */
     NeAACDecConfiguration config;
--- a/src/aac/libfaad2/syntax.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/syntax.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: syntax.c,v 1.82 2004/09/04 14:56:29 menno Exp $
+** $Id: syntax.c,v 1.87 2006/08/15 19:22:15 menno Exp $
 **/
 
 /*
@@ -93,9 +98,11 @@
 static void adts_error_check(adts_header *adts, bitfile *ld);
 static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc);
 static uint8_t excluded_channels(bitfile *ld, drc_info *drc);
-#ifdef SCALABLE_DEC
-static int8_t aac_scalable_main_header(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2,
-                                       bitfile *ld, uint8_t this_layer_stereo);
+static uint8_t side_info(NeAACDecHandle hDecoder, element *ele,
+                         bitfile *ld, ic_stream *ics, uint8_t scal_flag);
+#ifdef DRM
+static int8_t DRM_aac_scalable_main_header(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2,
+                                           bitfile *ld, uint8_t this_layer_stereo);
 #endif
 
 
@@ -413,6 +420,7 @@
                     bitfile *ld, program_config *pce, drc_info *drc)
 {
     uint8_t id_syn_ele;
+    uint8_t ele_this_frame = 0;
 
     hDecoder->fr_channels = 0;
     hDecoder->fr_ch_ele = 0;
@@ -429,36 +437,55 @@
         {
             switch (id_syn_ele) {
             case ID_SCE:
+                ele_this_frame++;
                 if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele;
                 decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele);
                 if (hInfo->error > 0)
                     return;
                 break;
             case ID_CPE:
+                ele_this_frame++;
                 if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele;
                 decode_cpe(hDecoder, hInfo, ld, id_syn_ele);
                 if (hInfo->error > 0)
                     return;
                 break;
             case ID_LFE:
+#ifdef DRM
+                hInfo->error = 32;
+#else
+                ele_this_frame++;
                 hDecoder->has_lfe++;
                 decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele);
+#endif
                 if (hInfo->error > 0)
                     return;
                 break;
             case ID_CCE: /* not implemented yet, but skip the bits */
+#ifdef DRM
+                hInfo->error = 32;
+#else
+                ele_this_frame++;
 #ifdef COUPLING_DEC
                 hInfo->error = coupling_channel_element(hDecoder, ld);
 #else
                 hInfo->error = 6;
 #endif
+#endif
                 if (hInfo->error > 0)
                     return;
                 break;
             case ID_DSE:
+                ele_this_frame++;
                 data_stream_element(hDecoder, ld);
                 break;
             case ID_PCE:
+                if (ele_this_frame != 0)
+                {
+                    hInfo->error = 31;
+                    return;
+                }
+                ele_this_frame++;
                 /* 14496-4: 5.6.4.1.2.1.3: */
                 /* program_configuration_element()'s in access units shall be ignored */
                 program_config_element(pce, ld);
@@ -467,6 +494,7 @@
                 //hDecoder->pce_set = 1;
                 break;
             case ID_FIL:
+                ele_this_frame++;
                 /* one sbr_info describes a channel_element not a channel! */
                 /* if we encounter SBR data here: error */
                 /* SBR data will be read directly in the SCE/LFE/CPE element */
@@ -577,6 +605,10 @@
     if (retval > 0)
         return retval;
 
+    /* IS not allowed in single channel */
+    if (ics->is_used)
+        return 32;
+
 #ifdef SBR_DEC
     /* check if next bitstream element is a fill element */
     /* if so, read it now so SBR decoding can be done in case of a file with SBR */
@@ -627,6 +659,11 @@
 
         ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2
             DEBUGVAR(1,41,"channel_pair_element(): ms_mask_present"));
+        if (ics1->ms_mask_present == 3)
+        {
+            /* bitstream error */
+            return 32;
+        }
         if (ics1->ms_mask_present == 1)
         {
             uint8_t g, sfb;
@@ -730,14 +767,23 @@
                         uint8_t common_window)
 {
     uint8_t retval = 0;
+    uint8_t ics_reserved_bit;
 
-    /* ics->ics_reserved_bit = */ faad_get1bit(ld
+    ics_reserved_bit = faad_get1bit(ld
         DEBUGVAR(1,43,"ics_info(): ics_reserved_bit"));
+    if (ics_reserved_bit != 0)
+        return 32;
     ics->window_sequence = (uint8_t)faad_getbits(ld, 2
         DEBUGVAR(1,44,"ics_info(): window_sequence"));
     ics->window_shape = faad_get1bit(ld
         DEBUGVAR(1,45,"ics_info(): window_shape"));
 
+#ifdef LD_DEC
+    /* No block switching in LD */
+    if ((hDecoder->object_type == LD) && (ics->window_sequence != ONLY_LONG_SEQUENCE))
+        return 32;
+#endif
+
     if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
     {
         ics->max_sfb = (uint8_t)faad_getbits(ld, 4
@@ -753,6 +799,7 @@
     if ((retval = window_grouping_info(hDecoder, ics)) > 0)
         return retval;
 
+
     /* should be an error */
     /* check the range of max_sfb */
     if (ics->max_sfb > ics->num_swb)
@@ -922,6 +969,10 @@
         return result;
     }
 
+    /* IS not allowed in single channel */
+    if (ics->is_used)
+        return 32;
+
     for (c = 1; c < num_gain_element_lists; c++)
     {
         uint8_t cge;
@@ -1029,7 +1080,8 @@
             hDecoder->sbr_present_flag = 1;
 
             /* parse the SBR data */
-            hDecoder->sbr[sbr_ele]->ret = sbr_extension_data(ld, hDecoder->sbr[sbr_ele], count);
+            hDecoder->sbr[sbr_ele]->ret = sbr_extension_data(ld, hDecoder->sbr[sbr_ele], count,
+                hDecoder->postSeekResetFlag);
 
 #if 0
             if (hDecoder->sbr[sbr_ele]->ret > 0)
@@ -1049,10 +1101,14 @@
 #endif
         } else {
 #endif
+#ifndef DRM
             while (count > 0)
             {
                 count -= extension_payload(ld, drc, count);
             }
+#else
+            return 30;
+#endif
 #ifdef SBR_DEC
         }
 #endif
@@ -1157,10 +1213,10 @@
 }
 #endif
 
-#ifdef SCALABLE_DEC
+#ifdef DRM
 /* Table 4.4.13 ASME */
-void aac_scalable_main_element(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
-                               bitfile *ld, program_config *pce, drc_info *drc)
+void DRM_aac_scalable_main_element(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
+                                   bitfile *ld, program_config *pce, drc_info *drc)
 {
     uint8_t retval = 0;
     uint8_t channels = hDecoder->fr_channels = 0;
@@ -1175,7 +1231,7 @@
 
     hDecoder->fr_ch_ele = 0;
 
-    hInfo->error = aac_scalable_main_header(hDecoder, ics1, ics2, ld, this_layer_stereo);
+    hInfo->error = DRM_aac_scalable_main_header(hDecoder, ics1, ics2, ld, this_layer_stereo);
     if (hInfo->error > 0)
         return;
 
@@ -1189,22 +1245,77 @@
         hDecoder->element_id[0] = ID_SCE;
     }
 
-    for (ch = 0; ch < (this_layer_stereo ? 2 : 1); ch++)
+    if (this_layer_stereo)
     {
-        ic_stream *ics;
-        if (ch == 0)
-        {
-            ics = ics1;
-            spec_data = spec_data1;
-        } else {
-            ics = ics2;
-            spec_data = spec_data2;
-        }
+        cpe.channel        = 0;
+        cpe.paired_channel = 1;
+    }
+
+
+    /* Stereo2 / Mono1 */
+    ics1->tns_data_present = faad_get1bit(ld);
 
-        hInfo->error = individual_channel_stream(hDecoder, &cpe, ld, ics, 1, spec_data);
+#if defined(LTP_DEC)
+    ics1->ltp.data_present = faad_get1bit(ld);
+#elif defined (DRM)
+    if(faad_get1bit(ld)) {
+         hInfo->error = 26;
+         return;
+    }
+#else
+    faad_get1bit(ld);
+#endif    
+
+    hInfo->error = side_info(hDecoder, &cpe, ld, ics1, 1);
+    if (hInfo->error > 0)
+        return;
+    if (this_layer_stereo)
+    {
+        /* Stereo3 */
+        ics2->tns_data_present = faad_get1bit(ld);
+#ifdef LTP_DEC
+        ics1->ltp.data_present =
+#endif
+            faad_get1bit(ld);
+        hInfo->error = side_info(hDecoder, &cpe, ld, ics2, 1);
         if (hInfo->error > 0)
             return;
     }
+    /* Stereo4 / Mono2 */
+    if (ics1->tns_data_present)
+        tns_data(ics1, &(ics1->tns), ld);
+    if (this_layer_stereo)
+    {
+        /* Stereo5 */
+        if (ics2->tns_data_present)
+            tns_data(ics2, &(ics2->tns), ld);
+    }
+
+#ifdef DRM
+    /* CRC check */
+    if (hDecoder->object_type == DRM_ER_LC)
+    {
+        if ((hInfo->error = (uint8_t)faad_check_CRC(ld, (uint16_t)faad_get_processed_bits(ld) - 8)) > 0)
+            return;
+    }
+#endif
+
+    /* Stereo6 / Mono3 */
+    /* error resilient spectral data decoding */
+    if ((hInfo->error = reordered_spectral_data(hDecoder, ics1, ld, spec_data1)) > 0)
+    {
+        return;
+    }
+    if (this_layer_stereo)
+    {
+        /* Stereo7 */
+        /* error resilient spectral data decoding */
+        if ((hInfo->error = reordered_spectral_data(hDecoder, ics2, ld, spec_data2)) > 0)
+        {
+            return;
+        }
+    }
+
 
 #ifdef DRM
 #ifdef SBR_DEC
@@ -1244,6 +1355,7 @@
 
         /* Set SBR data */
         /* consider 8 bits from AAC-CRC */
+        /* SBR buffer size is original buffer size minus AAC buffer size */
         count = (uint16_t)bit2byte(buffer_size*8 - bitsconsumed);
         faad_initbits(&ld_sbr, revbuffer, count);
 
@@ -1252,7 +1364,7 @@
 
         faad_getbits(&ld_sbr, 8); /* Skip 8-bit CRC */
 
-        hDecoder->sbr[0]->ret = sbr_extension_data(&ld_sbr, hDecoder->sbr[0], count);
+        hDecoder->sbr[0]->ret = sbr_extension_data(&ld_sbr, hDecoder->sbr[0], count, hDecoder->postSeekResetFlag);
 #if (defined(PS_DEC) || defined(DRM_PS))
         if (hDecoder->sbr[0]->ps_used)
         {
@@ -1261,6 +1373,11 @@
         }
 #endif
 
+        if (ld_sbr.error)
+        {
+            hDecoder->sbr[0]->ret = 1;
+        }
+
         /* check CRC */
         /* no need to check it if there was already an error */
         if (hDecoder->sbr[0]->ret == 0)
@@ -1269,7 +1386,7 @@
         /* SBR data was corrupted, disable it until the next header */
         if (hDecoder->sbr[0]->ret != 0)
         {
-            hDecoder->sbr[0]->header_count = 0;  
+            hDecoder->sbr[0]->header_count = 0;
         }
 
         faad_endbits(&ld_sbr);
@@ -1308,15 +1425,18 @@
 }
 
 /* Table 4.4.15 */
-static int8_t aac_scalable_main_header(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2,
-                                       bitfile *ld, uint8_t this_layer_stereo)
+static int8_t DRM_aac_scalable_main_header(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2,
+                                           bitfile *ld, uint8_t this_layer_stereo)
 {
     uint8_t retval = 0;
     uint8_t ch;
     ic_stream *ics;
+    uint8_t ics_reserved_bit;
 
-    /* ics1->ics_reserved_bit = */ faad_get1bit(ld
+    ics_reserved_bit = faad_get1bit(ld
         DEBUGVAR(1,300,"aac_scalable_main_header(): ics_reserved_bits"));
+    if (ics_reserved_bit != 0)
+        return 32;
     ics1->window_sequence = (uint8_t)faad_getbits(ld, 2
         DEBUGVAR(1,301,"aac_scalable_main_header(): window_sequence"));
     ics1->window_shape = faad_get1bit(ld
@@ -1346,6 +1466,11 @@
     {
         ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2
             DEBUGVAR(1,306,"aac_scalable_main_header(): ms_mask_present"));
+        if (ics1->ms_mask_present == 3)
+        {
+            /* bitstream error */
+            return 32;
+        }
         if (ics1->ms_mask_present == 1)
         {
             uint8_t g, sfb;
@@ -1364,70 +1489,12 @@
         ics1->ms_mask_present = 0;
     }
 
-    if (0)
-    {
-        faad_get1bit(ld
-            DEBUGVAR(1,308,"aac_scalable_main_header(): tns_channel_mono_layer"));
-    }
-
-    for (ch = 0; ch < (this_layer_stereo ? 2 : 1); ch++)
-    {
-        if (ch == 0)
-            ics = ics1;
-        else
-            ics = ics2;
-
-        if ( 1 /*!tvq_layer_pesent || (tns_aac_tvq_en[ch] == 1)*/)
-        {
-            if ((ics->tns_data_present = faad_get1bit(ld
-                DEBUGVAR(1,309,"aac_scalable_main_header(): tns_data_present"))) & 1)
-            {
-#ifdef DRM
-                /* different order of data units in DRM */
-                if (hDecoder->object_type != DRM_ER_LC)
-#endif
-                {
-                    tns_data(ics, &(ics->tns), ld);
-                }
-            }
-        }
-#if 0
-        if (0 /*core_flag || tvq_layer_pesent*/)
-        {
-            if ((ch==0) || ((ch==1) && (core_stereo || tvq_stereo))
-                diff_control_data();
-            if (mono_stereo_flag)
-                diff_control_data_lr();
-        } else {
-#endif
-            if ((
-#ifdef LTP_DEC
-                ics->ltp.data_present =
-#endif
-                faad_get1bit(ld DEBUGVAR(1,310,"aac_scalable_main_header(): ltp.data_present"))) & 1)
-            {
-#ifdef LTP_DEC
-                if ((retval = ltp_data(hDecoder, ics, &(ics->ltp), ld)) > 0)
-                {
-                    return retval;
-                }
-#else
-                return 26;
-#endif
-            }
-#if 0
-        }
-#endif
-    }
-
     return 0;
 }
 #endif
 
-/* Table 4.4.24 */
-static uint8_t individual_channel_stream(NeAACDecHandle hDecoder, element *ele,
-                                         bitfile *ld, ic_stream *ics, uint8_t scal_flag,
-                                         int16_t *spec_data)
+static uint8_t side_info(NeAACDecHandle hDecoder, element *ele,
+                         bitfile *ld, ic_stream *ics, uint8_t scal_flag)
 {
     uint8_t result;
 
@@ -1513,6 +1580,21 @@
         if ((result = rvlc_decode_scale_factors(ics, ld)) > 0)
             return result;
     }
+#endif
+
+    return 0;
+}
+
+/* Table 4.4.24 */
+static uint8_t individual_channel_stream(NeAACDecHandle hDecoder, element *ele,
+                                         bitfile *ld, ic_stream *ics, uint8_t scal_flag,
+                                         int16_t *spec_data)
+{
+    uint8_t result;
+
+    result = side_info(hDecoder, ele, ld, ics, scal_flag);
+    if (result > 0)
+        return result;
 
     if (hDecoder->object_type >= ER_OBJECT_START) 
     {
@@ -1523,10 +1605,13 @@
 #ifdef DRM
     /* CRC check */
     if (hDecoder->object_type == DRM_ER_LC)
+    {
         if ((result = (uint8_t)faad_check_CRC(ld, (uint16_t)faad_get_processed_bits(ld) - 8)) > 0)
             return result;
+    }
 #endif
 
+#ifdef ERROR_RESILIENCE
     if (hDecoder->aacSpectralDataResilienceFlag)
     {
         /* error resilient spectral data decoding */
@@ -1594,7 +1679,7 @@
 
             /* if "faad_getbits" detects error and returns "0", "k" is never
                incremented and we cannot leave the while loop */
-            if ((ld->error != 0) || (ld->no_more_reading))
+            if (ld->error != 0)
                 return 14;
 
 #ifdef ERROR_RESILIENCE
@@ -1605,12 +1690,23 @@
             ics->sect_cb[g][i] = (uint8_t)faad_getbits(ld, sect_cb_bits
                 DEBUGVAR(1,71,"section_data(): sect_cb"));
 
+            if (ics->sect_cb[g][i] == 12)
+                return 32;
+
 #if 0
             printf("%d\n", ics->sect_cb[g][i]);
 #endif
 
+#ifndef DRM
             if (ics->sect_cb[g][i] == NOISE_HCB)
                 ics->noise_used = 1;
+#else
+            /* PNS not allowed in DRM */
+            if (ics->sect_cb[g][i] == NOISE_HCB)
+                return 29;
+#endif
+            if (ics->sect_cb[g][i] == INTENSITY_HCB2 || ics->sect_cb[g][i] == INTENSITY_HCB)
+                ics->is_used = 1;
 
 #ifdef ERROR_RESILIENCE
             if (hDecoder->aacSectionDataResilienceFlag)
@@ -1651,10 +1747,18 @@
             printf("%d\n", ics->sect_end[g][i]);
 #endif
 
-            if (k + sect_len >= 8*15)
-                return 15;
-            if (i >= 8*15)
-                return 15;
+            if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
+            {
+                if (k + sect_len > 8*15)
+                    return 15;
+                if (i >= 8*15)
+                    return 15;
+            } else {
+                if (k + sect_len > MAX_SFB)
+                    return 15;
+                if (i >= MAX_SFB)
+                    return 15;
+            }
 
             for (sfb = k; sfb < k + sect_len; sfb++)
             {
@@ -1675,6 +1779,13 @@
             i++;
         }
         ics->num_sec[g] = i;
+
+        /* the sum of all sect_len_incr elements for a given window
+         * group shall equal max_sfb */
+        if (k != ics->max_sfb)
+        {
+            return 32;
+        }
 #if 0
         printf("%d\n", ics->num_sec[g]);
 #endif
@@ -1735,6 +1846,7 @@
                 break;
             case NOISE_HCB: /* noise books */
 
+#ifndef DRM
                 /* decode noise energy */
                 if (noise_pcm_flag)
                 {
@@ -1750,6 +1862,10 @@
 #ifdef SF_PRINT
                 printf("%d\n", ics->scale_factors[g][sfb]);
 #endif
+#else
+                /* PNS not allowed in DRM */
+                return 29;
+#endif
 
                 break;
             default: /* spectral books */
@@ -1810,7 +1926,7 @@
 /* Table 4.4.27 */
 static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld)
 {
-    uint8_t w, filt, i, start_coef_bits = 0, coef_bits;
+    uint8_t w, filt, i, start_coef_bits, coef_bits;
     uint8_t n_filt_bits = 2;
     uint8_t length_bits = 6;
     uint8_t order_bits = 5;
@@ -2127,7 +2243,7 @@
         n++;
         drc->num_bands += band_incr;
 
-        for (i = 0; i < drc->num_bands; i++);
+        for (i = 0; i < drc->num_bands; i++)
         {
             drc->band_top[i] = (uint8_t)faad_getbits(ld, 8
                 DEBUGVAR(1,97,"dynamic_range_info(): band_top"));
--- a/src/aac/libfaad2/syntax.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/syntax.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: syntax.h,v 1.54 2004/09/04 14:56:29 menno Exp $
+** $Id: syntax.h,v 1.56 2006/05/07 18:09:03 menno Exp $
 **/
 
 #ifndef __SYNTAX_H__
@@ -114,9 +119,10 @@
                     bitfile *ld, program_config *pce, drc_info *drc);
 uint8_t reordered_spectral_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld,
                                 int16_t *spectral_data);
-void aac_scalable_main_element(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
-                               bitfile *ld, program_config *pce, drc_info *drc);
-
+#ifdef DRM
+void DRM_aac_scalable_main_element(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
+                                   bitfile *ld, program_config *pce, drc_info *drc);
+#endif
 
 #ifdef __cplusplus
 }
--- a/src/aac/libfaad2/tns.c	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/tns.c	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: tns.c,v 1.35 2004/09/04 14:56:29 menno Exp $
+** $Id: tns.c,v 1.38 2006/05/17 18:49:21 menno Exp $
 **/
 
 #include "common.h"
@@ -106,11 +111,11 @@
 
             start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
             start = min(start, ics->max_sfb);
-            start = ics->swb_offset[start];
+            start = min(ics->swb_offset[start], ics->swb_offset_max);
 
             end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
             end = min(end, ics->max_sfb);
-            end = ics->swb_offset[end];
+            end = min(ics->swb_offset[end], ics->swb_offset_max);
 
             size = end - start;
             if (size <= 0)
@@ -160,11 +165,11 @@
 
             start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
             start = min(start, ics->max_sfb);
-            start = ics->swb_offset[start];
+            start = min(ics->swb_offset[start], ics->swb_offset_max);
 
             end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
             end = min(end, ics->max_sfb);
-            end = ics->swb_offset[end];
+            end = min(ics->swb_offset[end], ics->swb_offset_max);
 
             size = end - start;
             if (size <= 0)
@@ -292,7 +297,7 @@
         y = *spectrum;
 
         for (j = 0; j < order; j++)
-            y += MUL_C(state[j], lpc[j+1]);
+            y += MUL_C(state[state_index+j], lpc[j+1]);
 
         /* double ringbuffer state */
         state_index--;
--- a/src/aac/libfaad2/tns.h	Tue Feb 20 04:36:01 2007 -0800
+++ b/src/aac/libfaad2/tns.h	Tue Feb 20 04:37:37 2007 -0800
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -14,15 +14,20 @@
 ** 
 ** You should have received a copy of the GNU General Public License
 ** along with this program; if not, write to the Free Software 
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
 ** Any non-GPL usage of this software or parts of this software is strictly
 ** forbidden.
 **
+** Software using this code must display the following message visibly in or
+** on each copy of the software:
+** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
+** in, for example, the about-box or help/startup screen.
+**
 ** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: tns.h,v 1.19 2004/09/04 14:56:29 menno Exp $
+** $Id: tns.h,v 1.21 2006/05/07 18:09:03 menno Exp $
 **/
 
 #ifndef __TNS_H__