shithub: aacdec

Download patch

ref: baf45c811ae6a1a0691d16ee367ace9ff690375b
parent: 23379b57a2a748622f925ad5eebcfcc8c806e2a4
author: menno <menno>
date: Tue Feb 1 08:23:35 EST 2005

cvs sync

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+21 january 2005  gpascutto(at)nero.com
+    - hcr.c, drm_dec.c: updates for DRM PS standard, error resilience changes
+    - reverted above error resilience changes
+
+8 december 2004  mbakker(at)nero.com
+    - ps_dec.c, ps_syntax.c: PS fixes (OPD huffman table and modulo decoding)
+
+6 december 2004  gpascutto(at)nero.com
+    - drm_dec.c, drm_dec.h, sbr_dec.c: DRM PS Standards update
+
+5 december 2004  gpascutto(at)nero.com
+    - syntax.c, hcr.c, decoder.c, sbr_syntax.c, specrec.c:
+        Improved (DRM) error resilience
+
+18 october 2004  mbakker(at)nero.com
+    - sbr_dec.c, sbr_hfadj.c, common.h: fixed Low Power SBR decoding
+
+18 october 2004  mbakker(at)nero.com
+    - main.c: added "quiet" option to frontend
+
+5 october 2004  mbakker(at)nero.com
+    - decoder.c: skip ID3 tags in library
+
+24 september 2004  mbakker(at)nero.com
+    - syntax.c,h, lt_predict.c, mp4.c, decoder.c:
+         Added stereo DRM support, removed fake scalable support
+
+21 september 2004  mbakker(at)nero.com
+    - specrec.c, bits.h, common.h, error.h, sbr_hfadj.h, structs.h,
+      decoder.c, error.c, hcr.c, sbr_dec.c, sbr_hfadj.c, sbr_syntax.c, syntax.c:
+         Improved error detection and handling.
+
+16 september 2004  mbakker(at)nero.com
+    - specrec.c, bits.h, common.h, error.h, sbr_hfadj.h, structs.h,
+      decoder.c, error.c, hcr.c, sbr_dec.c, sbr_hfadj.c, sbr_syntax.c, syntax.c:
+         Improved error detection and handling.
+
 8 september 2004  mbakker(at)nero.com
     - specrec.c: fixed compilation without PS
 
--- a/README
+++ b/README
@@ -14,7 +14,7 @@
 
 ******************************************************************************
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker (mbakker(at)nero.com), Ahead Software AG
+** 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
@@ -30,7 +30,15 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** Commercial non-GPL licensing of this software is also possible.
+** 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 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.
 ******************************************************************************
 
@@ -54,27 +62,6 @@
 
 Sorry, try building a ChangeLog from CVS.
 
-__________________________________
-REDISTRIBUTED OPEN SOURCE PACKAGES
-
-This is the list of redistributed open source packages that are included 
-in FAAD2:
-
-Name:       mp4v2
-Version:    0.9.8.6
-Origin:     http://www.mpeg4ip.net
-Author:     David Mackie
-Directory:  common/mp4v2
-License:    MPL, Mozilla Public License, version 1.1
-
-Name:       mp4av
-Version:    0.9.8.6
-Origin:     http://www.mpeg4ip.net
-Author:     David Mackie
-Directory:  common/mp4av
-License:    MPL, Mozilla Public License, version 1.1
-
-
 ___________________
 DIRECTORY STRUCTURE
 
@@ -87,14 +74,8 @@
       faad - general common functions like filereading and streaming
              as well as getting info from aac files.
 
-      mp4v2 - MPEG-4 file reading library.
-      
-      mp4av - MPEG-4 file general function library.
-      
       mp4ff - Small MP4 file format library (includes tagging abilities).
       
-   CoreAAC - AAC DirectShow filter.
-
    frontend - command line frontend to the FAAD2 library, also supports
               MPEG-4 file decoding.
 
@@ -112,10 +93,6 @@
 
       QCDMp4 - Quintessential player MP4 plugin.
 
-      winamp - winamp2 AAC input plugin.
-
-      winamp3 - winamp3 AAC input plugin.
-      
       xmms - xmms AAC plugin
 
       mpeg4ip - plugin for the mpeg4ip player
--- a/common/mp4ff/drms.c
+++ b/common/mp4ff/drms.c
@@ -2,7 +2,7 @@
  * drms.c: DRMS
  *****************************************************************************
  * Copyright (C) 2004 VideoLAN
- * $Id: drms.c,v 1.6 2004/04/12 18:17:41 menno Exp $
+ * $Id: drms.c,v 1.7 2005/02/01 13:15:55 menno Exp $
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  *          Sam Hocevar <sam@zoy.org>
--- a/common/mp4ff/drms.h
+++ b/common/mp4ff/drms.h
@@ -2,7 +2,7 @@
  * drms.h : DRMS
  *****************************************************************************
  * Copyright (C) 2004 VideoLAN
- * $Id: drms.h,v 1.6 2004/04/12 18:17:41 menno Exp $
+ * $Id: drms.h,v 1.7 2005/02/01 13:15:55 menno Exp $
  *
  * Author: Jon Lech Johansen <jon-vl@nanocrew.net>
  *
--- a/common/mp4ff/mp4atom.c
+++ b/common/mp4ff/mp4atom.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4atom.c,v 1.21 2004/05/17 10:18:02 menno Exp $
+** $Id: mp4atom.c,v 1.22 2005/02/01 13:15:55 menno Exp $
 **/
 
 #include <stdlib.h>
--- a/common/mp4ff/mp4ff.c
+++ b/common/mp4ff/mp4ff.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4ff.c,v 1.16 2004/03/27 11:14:48 menno Exp $
+** $Id: mp4ff.c,v 1.17 2005/02/01 13:15:55 menno Exp $
 **/
 
 #include <stdlib.h>
--- a/common/mp4ff/mp4ff.h
+++ b/common/mp4ff/mp4ff.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4ff.h,v 1.21 2004/09/03 19:38:58 menno Exp $
+** $Id: mp4ff.h,v 1.22 2005/02/01 13:15:55 menno Exp $
 **/
 
 #ifndef MP4FF_H
--- a/common/mp4ff/mp4ff_int_types.h
+++ b/common/mp4ff/mp4ff_int_types.h
@@ -1,7 +1,7 @@
 #ifndef _MP4FF_INT_TYPES_H_
 #define _MP4FF_INT_TYPES_H_
 
-#ifdef _WIN32
+#if defined (_WIN32)
 
 typedef char int8_t;
 typedef unsigned char uint8_t;
@@ -20,4 +20,4 @@
 #endif
 
 
-#endif
\ No newline at end of file
+#endif
--- a/common/mp4ff/mp4ffint.h
+++ b/common/mp4ff/mp4ffint.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4ffint.h,v 1.18 2004/04/12 18:17:42 menno Exp $
+** $Id: mp4ffint.h,v 1.19 2005/02/01 13:15:55 menno Exp $
 **/
 
 #ifndef MP4FF_INTERNAL_H
@@ -33,8 +33,8 @@
 #endif /* __cplusplus */
 
 #include "mp4ff_int_types.h"
+#include <stdlib.h>
 
-
 #if defined(_WIN32) && !defined(_WIN32_WCE)
 #define ITUNES_DRM
 
@@ -81,7 +81,6 @@
 #define FOURCC_priv VLC_FOURCC( 'p', 'r', 'i', 'v' )
 
 #endif
-
 #define MAX_TRACKS 1024
 #define TRACK_UNKNOWN 0
 #define TRACK_AUDIO   1
@@ -153,11 +152,14 @@
 #define ATOM_SCHI 25
 
 #ifdef HAVE_CONFIG_H
-#include "../../config.h"
+#include "../../config.h"   
 #endif
 
 #if !(defined(_WIN32) || defined(_WIN32_WCE))
 #define stricmp strcasecmp
+#else
+#define stricmp _stricmp
+#define strdup _strdup
 #endif
 
 /* file callback structure */
@@ -370,4 +372,4 @@
 }
 #endif /* __cplusplus */
 
-#endif
\ No newline at end of file
+#endif
--- a/common/mp4ff/mp4meta.c
+++ b/common/mp4ff/mp4meta.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4meta.c,v 1.15 2004/09/03 19:38:58 menno Exp $
+** $Id: mp4meta.c,v 1.16 2005/02/01 13:15:55 menno Exp $
 **/
 
 #ifdef USE_TAGGING
@@ -300,6 +300,8 @@
     while (sumsize < size)
     {
         subsize = mp4ff_atom_read_header(f, &atom_type, &header_size);
+        if (subsize == 0)
+            break;
         mp4ff_parse_tag(f, atom_type, (uint32_t)(subsize-header_size));
         sumsize += subsize;
     }
--- a/common/mp4ff/mp4sample.c
+++ b/common/mp4ff/mp4sample.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4sample.c,v 1.16 2004/03/27 11:14:49 menno Exp $
+** $Id: mp4sample.c,v 1.17 2005/02/01 13:15:55 menno Exp $
 **/
 
 #include <stdlib.h>
--- a/common/mp4ff/mp4tagupdate.c
+++ b/common/mp4ff/mp4tagupdate.c
@@ -529,7 +529,7 @@
 	{
 		udta_offset = mp4ff_position(f);
 		udta_size = mp4ff_read_int32(f);
-		if (find_atom_v2(f,udta_offset+8,udta_size-8,"meta",4,"ilst")<2)
+		if (!find_atom_v2(f,udta_offset+8,udta_size-8,"meta",4,"ilst"))
 		{
 			membuffer * buf;
 			void * new_meta_buffer;
--- a/common/mp4ff/mp4util.c
+++ b/common/mp4ff/mp4util.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4util.c,v 1.16 2004/03/27 11:14:49 menno Exp $
+** $Id: mp4util.c,v 1.17 2005/02/01 13:15:55 menno Exp $
 **/
 
 #include "mp4ffint.h"
--- a/frontend/audio.c
+++ b/frontend/audio.c
@@ -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, 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
 ** 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
+** 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 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: audio.c,v 1.24 2004/03/10 19:45:40 menno Exp $
+** $Id: audio.c,v 1.25 2005/02/01 13:15:56 menno Exp $
 **/
 
 #ifdef _WIN32
--- a/frontend/audio.h
+++ b/frontend/audio.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: audio.h,v 1.15 2004/03/10 19:45:40 menno Exp $
+** $Id: audio.h,v 1.16 2005/02/01 13:15:56 menno Exp $
 **/
 
 #ifndef AUDIO_H_INCLUDED
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -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, 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
 ** 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
+** 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 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: main.c,v 1.76 2004/03/27 11:14:49 menno Exp $
+** $Id: main.c,v 1.77 2005/02/01 13:15:56 menno Exp $
 **/
 
 #ifdef _WIN32
@@ -50,6 +55,23 @@
 #define MAX_CHANNELS 6 /* make this higher to support files with
                           more channels */
 
+
+static int quiet = 0;
+
+void faad_fprintf(FILE *stream, const char *fmt, ...)
+{
+    va_list ap;
+
+    if (!quiet)
+    {
+        va_start(ap, fmt);
+        
+        vfprintf(stream, fmt, ap);
+
+        va_end(ap);
+    }
+}
+
 /* FAAD file buffering routines */
 typedef struct {
     long bytes_into_buffer;
@@ -235,30 +257,30 @@
     int i;
     long channelMask = aacChannelConfig2wavexChannelMask(frameInfo);
 
-    fprintf(stderr, "  ---------------------\n");
+    faad_fprintf(stderr, "  ---------------------\n");
     if (frameInfo->num_lfe_channels > 0)
     {
-        fprintf(stderr, " | Config: %2d.%d Ch     |", frameInfo->channels-frameInfo->num_lfe_channels, frameInfo->num_lfe_channels);
+        faad_fprintf(stderr, " | Config: %2d.%d Ch     |", frameInfo->channels-frameInfo->num_lfe_channels, frameInfo->num_lfe_channels);
     } else {
-        fprintf(stderr, " | Config: %2d Ch       |", frameInfo->channels);
+        faad_fprintf(stderr, " | Config: %2d Ch       |", frameInfo->channels);
     }
     if (channelMask)
-        fprintf(stderr, " WARNING: channels are reordered according to\n");
+        faad_fprintf(stderr, " WARNING: channels are reordered according to\n");
     else
-        fprintf(stderr, "\n");
-    fprintf(stderr, "  ---------------------");
+        faad_fprintf(stderr, "\n");
+    faad_fprintf(stderr, "  ---------------------");
     if (channelMask)
-        fprintf(stderr, "  MS defaults defined in WAVE_FORMAT_EXTENSIBLE\n");
+        faad_fprintf(stderr, "  MS defaults defined in WAVE_FORMAT_EXTENSIBLE\n");
     else
-        fprintf(stderr, "\n");
-    fprintf(stderr, " | Ch |    Position    |\n");
-    fprintf(stderr, "  ---------------------\n");
+        faad_fprintf(stderr, "\n");
+    faad_fprintf(stderr, " | Ch |    Position    |\n");
+    faad_fprintf(stderr, "  ---------------------\n");
     for (i = 0; i < frameInfo->channels; i++)
     {
-        fprintf(stderr, " | %.2d | %-14s |\n", i, position2string((int)frameInfo->channel_position[i]));
+        faad_fprintf(stderr, " | %.2d | %-14s |\n", i, position2string((int)frameInfo->channel_position[i]));
     }
-    fprintf(stderr, "  ---------------------\n");
-    fprintf(stderr, "\n");
+    faad_fprintf(stderr, "  ---------------------\n");
+    faad_fprintf(stderr, "\n");
 }
 
 int FindAdtsSRIndex(int sr)
@@ -336,38 +358,39 @@
 
 void usage(void)
 {
-    fprintf(stdout, "\nUsage:\n");
-    fprintf(stdout, "%s [options] infile.aac\n", progName);
-    fprintf(stdout, "Options:\n");
-    fprintf(stdout, " -h    Shows this help screen.\n");
-    fprintf(stdout, " -i    Shows info about the input file.\n");
-    fprintf(stdout, " -a X  Write MPEG-4 AAC ADTS output file.\n");
-    fprintf(stdout, " -t    Assume old ADTS format.\n");
-    fprintf(stdout, " -o X  Set output filename.\n");
-    fprintf(stdout, " -f X  Set output format. Valid values for X are:\n");
-    fprintf(stdout, "        1:  Microsoft WAV format (default).\n");
-    fprintf(stdout, "        2:  RAW PCM data.\n");
-    fprintf(stdout, " -b X  Set output sample format. Valid values for X are:\n");
-    fprintf(stdout, "        1:  16 bit PCM data (default).\n");
-    fprintf(stdout, "        2:  24 bit PCM data.\n");
-    fprintf(stdout, "        3:  32 bit PCM data.\n");
-    fprintf(stdout, "        4:  32 bit floating point data.\n");
-    fprintf(stdout, "        5:  64 bit floating point data.\n");
-    fprintf(stdout, " -s X  Force the samplerate to X (for RAW files).\n");
-    fprintf(stdout, " -l X  Set object type. Supported object types:\n");
-    fprintf(stdout, "        1:  Main object type.\n");
-    fprintf(stdout, "        2:  LC (Low Complexity) object type.\n");
-    fprintf(stdout, "        4:  LTP (Long Term Prediction) object type.\n");
-    fprintf(stdout, "        23: LD (Low Delay) object type.\n");
-    fprintf(stdout, " -d    Down matrix 5.1 to 2 channels\n");
-    fprintf(stdout, " -w    Write output to stdio instead of a file.\n");
-    fprintf(stdout, " -g    Disable gapless decoding.\n");
-    fprintf(stdout, "Example:\n");
-    fprintf(stdout, "       %s infile.aac\n", progName);
-    fprintf(stdout, "       %s infile.mp4\n", progName);
-    fprintf(stdout, "       %s -o outfile.wav infile.aac\n", progName);
-    fprintf(stdout, "       %s -w infile.aac > outfile.wav\n", progName);
-    fprintf(stdout, "       %s -a outfile.aac infile.aac\n", progName);
+    faad_fprintf(stdout, "\nUsage:\n");
+    faad_fprintf(stdout, "%s [options] infile.aac\n", progName);
+    faad_fprintf(stdout, "Options:\n");
+    faad_fprintf(stdout, " -h    Shows this help screen.\n");
+    faad_fprintf(stdout, " -i    Shows info about the input file.\n");
+    faad_fprintf(stdout, " -a X  Write MPEG-4 AAC ADTS output file.\n");
+    faad_fprintf(stdout, " -t    Assume old ADTS format.\n");
+    faad_fprintf(stdout, " -o X  Set output filename.\n");
+    faad_fprintf(stdout, " -f X  Set output format. Valid values for X are:\n");
+    faad_fprintf(stdout, "        1:  Microsoft WAV format (default).\n");
+    faad_fprintf(stdout, "        2:  RAW PCM data.\n");
+    faad_fprintf(stdout, " -b X  Set output sample format. Valid values for X are:\n");
+    faad_fprintf(stdout, "        1:  16 bit PCM data (default).\n");
+    faad_fprintf(stdout, "        2:  24 bit PCM data.\n");
+    faad_fprintf(stdout, "        3:  32 bit PCM data.\n");
+    faad_fprintf(stdout, "        4:  32 bit floating point data.\n");
+    faad_fprintf(stdout, "        5:  64 bit floating point data.\n");
+    faad_fprintf(stdout, " -s X  Force the samplerate to X (for RAW files).\n");
+    faad_fprintf(stdout, " -l X  Set object type. Supported object types:\n");
+    faad_fprintf(stdout, "        1:  Main object type.\n");
+    faad_fprintf(stdout, "        2:  LC (Low Complexity) object type.\n");
+    faad_fprintf(stdout, "        4:  LTP (Long Term Prediction) object type.\n");
+    faad_fprintf(stdout, "        23: LD (Low Delay) object type.\n");
+    faad_fprintf(stdout, " -d    Down matrix 5.1 to 2 channels\n");
+    faad_fprintf(stdout, " -w    Write output to stdio instead of a file.\n");
+    faad_fprintf(stdout, " -g    Disable gapless decoding.\n");
+    faad_fprintf(stdout, " -q    Quiet - suppresses status messages.\n");
+    faad_fprintf(stdout, "Example:\n");
+    faad_fprintf(stdout, "       %s infile.aac\n", progName);
+    faad_fprintf(stdout, "       %s infile.mp4\n", progName);
+    faad_fprintf(stdout, "       %s -o outfile.wav infile.aac\n", progName);
+    faad_fprintf(stdout, "       %s -w infile.aac > outfile.wav\n", progName);
+    faad_fprintf(stdout, "       %s -a outfile.aac infile.aac\n", progName);
     return;
 }
 
@@ -409,7 +432,7 @@
         adtsFile = fopen(adts_fn, "wb");
         if (adtsFile == NULL)
         {
-            fprintf(stderr, "Error opening file: %s\n", adts_fn);
+            faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
             return 1;
         }
     }
@@ -418,7 +441,7 @@
     if (b.infile == NULL)
     {
         /* unable to open file */
-        fprintf(stderr, "Error opening file: %s\n", aacfile);
+        faad_fprintf(stderr, "Error opening file: %s\n", aacfile);
         return 1;
     }
 
@@ -428,7 +451,7 @@
 
     if (!(b.buffer = (unsigned char*)malloc(FAAD_MIN_STREAMSIZE*MAX_CHANNELS)))
     {
-        fprintf(stderr, "Memory allocation error\n");
+        faad_fprintf(stderr, "Memory allocation error\n");
         return 0;
     }
     memset(b.buffer, 0, FAAD_MIN_STREAMSIZE*MAX_CHANNELS);
@@ -509,7 +532,7 @@
         b.bytes_into_buffer, &samplerate, &channels)) < 0)
     {
         /* If some error initializing occured, skip the file */
-        fprintf(stderr, "Error initializing decoder library.\n");
+        faad_fprintf(stderr, "Error initializing decoder library.\n");
         if (b.buffer)
             free(b.buffer);
         NeAACDecClose(hDecoder);
@@ -520,18 +543,18 @@
     fill_buffer(&b);
 
     /* print AAC file info */
-    fprintf(stderr, "%s file info:\n", aacfile);
+    faad_fprintf(stderr, "%s file info:\n", aacfile);
     switch (header_type)
     {
     case 0:
-        fprintf(stderr, "RAW\n\n");
+        faad_fprintf(stderr, "RAW\n\n");
         break;
     case 1:
-        fprintf(stderr, "ADTS, %.3f sec, %d kbps, %d Hz\n\n",
+        faad_fprintf(stderr, "ADTS, %.3f sec, %d kbps, %d Hz\n\n",
             length, bitrate, samplerate);
         break;
     case 2:
-        fprintf(stderr, "ADIF, %.3f sec, %d kbps, %d Hz\n\n",
+        faad_fprintf(stderr, "ADIF, %.3f sec, %d kbps, %d Hz\n\n",
             length, bitrate, samplerate);
         break;
     }
@@ -570,7 +593,7 @@
 
         if (frameInfo.error > 0)
         {
-            fprintf(stderr, "Error: %s\n",
+            faad_fprintf(stderr, "Error: %s\n",
                 NeAACDecGetErrorMessage(frameInfo.error));
         }
 
@@ -600,7 +623,7 @@
                     return 0;
                 }
             } else {
-                fprintf(stderr, "Writing output MPEG-4 AAC ADTS file.\n\n");
+                faad_fprintf(stderr, "Writing output MPEG-4 AAC ADTS file.\n\n");
             }
             first_time = 0;
         }
@@ -610,7 +633,7 @@
         {
             old_percent = percent;
             sprintf(percents, "%d%% decoding %s.", percent, aacfile);
-            fprintf(stderr, "%s\r", percents);
+            faad_fprintf(stderr, "%s\r", percents);
 #ifdef _WIN32
             SetConsoleTitle(percents);
 #endif
@@ -744,7 +767,7 @@
         adtsFile = fopen(adts_fn, "wb");
         if (adtsFile == NULL)
         {
-            fprintf(stderr, "Error opening file: %s\n", adts_fn);
+            faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
             return 1;
         }
     }
@@ -753,13 +776,13 @@
     if (!infile)
     {
         /* unable to open file */
-        fprintf(stderr, "Error opening file: %s\n", mp4file);
+        faad_fprintf(stderr, "Error opening file: %s\n", mp4file);
         return 1;
     }
 
     if ((track = GetAACTrack(infile)) < 0)
     {
-        fprintf(stderr, "Unable to find correct AAC sound track in the MP4 file.\n");
+        faad_fprintf(stderr, "Unable to find correct AAC sound track in the MP4 file.\n");
         NeAACDecClose(hDecoder);
         mp4ff_close(infile);
         free(mp4cb);
@@ -775,7 +798,7 @@
                     &samplerate, &channels) < 0)
     {
         /* If some error initializing occured, skip the file */
-        fprintf(stderr, "Error initializing decoder library.\n");
+        faad_fprintf(stderr, "Error initializing decoder library.\n");
         NeAACDecClose(hDecoder);
         mp4ff_close(infile);
         free(mp4cb);
@@ -798,7 +821,7 @@
     }
 
     /* print some mp4 file info */
-    fprintf(stderr, "%s file info:\n\n", mp4file);
+    faad_fprintf(stderr, "%s file info:\n\n", mp4file);
     {
         char *tag = NULL, *item = NULL;
         int k, j;
@@ -814,7 +837,7 @@
 
         *song_length = seconds;
 
-        fprintf(stderr, "%s\t%.3f secs, %d ch, %d Hz\n\n", ot[(mp4ASC.objectTypeIndex > 5)?0:mp4ASC.objectTypeIndex],
+        faad_fprintf(stderr, "%s\t%.3f secs, %d ch, %d Hz\n\n", ot[(mp4ASC.objectTypeIndex > 5)?0:mp4ASC.objectTypeIndex],
             seconds, mp4ASC.channelsConfiguration, mp4ASC.samplingFrequency);
 
 #define PRINT_MP4_METADATA
@@ -826,13 +849,13 @@
             {
                 if (item != NULL && tag != NULL)
                 {
-                    fprintf(stderr, "%s: %s\n", item, tag);
+                    faad_fprintf(stderr, "%s: %s\n", item, tag);
                     free(item); item = NULL;
                     free(tag); tag = NULL;
                 }
             }
         }
-        if (j > 0) fprintf(stderr, "\n");
+        if (j > 0) faad_fprintf(stderr, "\n");
 #endif
     }
 
@@ -862,7 +885,7 @@
         rc = mp4ff_read_sample(infile, track, sampleId, &buffer,  &buffer_size);
         if (rc == 0)
         {
-            fprintf(stderr, "Reading from MP4 file failed.\n");
+            faad_fprintf(stderr, "Reading from MP4 file failed.\n");
             NeAACDecClose(hDecoder);
             mp4ff_close(infile);
             free(mp4cb);
@@ -895,7 +918,7 @@
 
                 if (!useAacLength && !initial && (sampleId < numSamples/2) && (sample_count != frameInfo.samples))
                 {
-                    fprintf(stderr, "MP4 seems to have incorrect frame duration, using values from AAC data.\n");
+                    faad_fprintf(stderr, "MP4 seems to have incorrect frame duration, using values from AAC data.\n");
                     useAacLength = 1;
                     sample_count = frameInfo.samples;
                 }
@@ -946,7 +969,7 @@
         {
             old_percent = percent;
             sprintf(percents, "%d%% decoding %s.", percent, mp4file);
-            fprintf(stderr, "%s\r", percents);
+            faad_fprintf(stderr, "%s\r", percents);
 #ifdef _WIN32
             SetConsoleTitle(percents);
 #endif
@@ -959,7 +982,7 @@
 
         if (frameInfo.error > 0)
         {
-            fprintf(stderr, "Warning: %s\n",
+            faad_fprintf(stderr, "Warning: %s\n",
                 NeAACDecGetErrorMessage(frameInfo.error));
         }
     }
@@ -1015,19 +1038,6 @@
 
     unsigned long cap = NeAACDecGetCapabilities();
 
-    fprintf(stderr, " *********** Ahead Software MPEG-4 AAC Decoder V%s ******************\n\n", FAAD2_VERSION);
-    fprintf(stderr, " Build: %s\n", __DATE__);
-    fprintf(stderr, " Copyright 2002-2004: Ahead Software AG\n");
-    fprintf(stderr, " http://www.audiocoding.com\n");
-    if (cap & FIXED_POINT_CAP)
-        fprintf(stderr, " Fixed point version\n");
-    else
-        fprintf(stderr, " Floating point version\n");
-    fprintf(stderr, "\n");
-    fprintf(stderr, " This program is free software; you can redistribute it and/or modify\n");
-    fprintf(stderr, " it under the terms of the GNU General Public License.\n");
-    fprintf(stderr, "\n");
-    fprintf(stderr, " **************************************************************************\n\n");
 
     /* begin process command line */
     progName = argv[0];
@@ -1035,6 +1045,7 @@
         int c = -1;
         int option_index = 0;
         static struct option long_options[] = {
+            { "quiet",      0, 0, 'q' },
             { "outfile",    0, 0, 'o' },
             { "adtsout",    0, 0, 'a' },
             { "oldformat",  0, 0, 't' },
@@ -1049,7 +1060,7 @@
             { "help",       0, 0, 'h' }
         };
 
-        c = getopt_long(argc, argv, "o:a:s:f:b:l:wgdhit",
+        c = getopt_long(argc, argv, "o:a:s:f:b:l:wgdhitq",
             long_options, &option_index);
 
         if (c == -1)
@@ -1146,11 +1157,30 @@
         case 'h':
             showHelp = 1;
             break;
+        case 'q':
+            quiet = 1;
+            break;
         default:
             break;
         }
     }
 
+
+    faad_fprintf(stderr, " *********** Ahead Software MPEG-4 AAC Decoder V%s ******************\n\n", FAAD2_VERSION);
+    faad_fprintf(stderr, " Build: %s\n", __DATE__);
+    faad_fprintf(stderr, " Copyright 2002-2004: Ahead Software AG\n");
+    faad_fprintf(stderr, " http://www.audiocoding.com\n");
+    if (cap & FIXED_POINT_CAP)
+        faad_fprintf(stderr, " Fixed point version\n");
+    else
+        faad_fprintf(stderr, " Floating point version\n");
+    faad_fprintf(stderr, "\n");
+    faad_fprintf(stderr, " This program is free software; you can redistribute it and/or modify\n");
+    faad_fprintf(stderr, " it under the terms of the GNU General Public License.\n");
+    faad_fprintf(stderr, "\n");
+    faad_fprintf(stderr, " **************************************************************************\n\n");
+
+
     /* check that we have at least two non-option arguments */
     /* Print help if requested */
     if (((argc - optind) < 1) || showHelp)
@@ -1194,7 +1224,7 @@
     hMP4File = fopen(aacFileName, "rb");
     if (!hMP4File)
     {
-        fprintf(stderr, "Error opening file: %s\n", aacFileName);
+        faad_fprintf(stderr, "Error opening file: %s\n", aacFileName);
         return 1;
     }
     fread(header, 1, 8, hMP4File);
@@ -1223,7 +1253,7 @@
          */
         float dec_length = (float)(clock() - begin)/(float)CLOCKS_PER_SEC;
 #endif
-        fprintf(stderr, "Decoding %s took: %5.2f sec. %5.2fx real-time.\n", aacFileName,
+        faad_fprintf(stderr, "Decoding %s took: %5.2f sec. %5.2fx real-time.\n", aacFileName,
             dec_length, length/dec_length);
     }
 
--- a/include/faad.h
+++ b/include/faad.h
@@ -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, 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
 ** 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
+** 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 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: faad.h,v 1.47 2004/04/03 19:08:37 menno Exp $
+** $Id: faad.h,v 1.48 2005/02/01 13:15:56 menno Exp $
 **/
 
 /* warn people for update */
--- a/include/neaacdec.h
+++ b/include/neaacdec.h
@@ -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, 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
 ** 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
+** 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 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: neaacdec.h,v 1.5 2004/09/04 14:56:27 menno Exp $
+** $Id: neaacdec.h,v 1.6 2005/02/01 13:15:56 menno Exp $
 **/
 
 #ifndef __NEAACDEC_H__
--- a/libfaad/analysis.h
+++ b/libfaad/analysis.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: analysis.h,v 1.14 2004/09/04 14:56:27 menno Exp $
+** $Id: analysis.h,v 1.15 2005/02/01 13:15:56 menno Exp $
 **/
 
 #ifndef __ANALYSIS_H__
--- a/libfaad/bits.c
+++ b/libfaad/bits.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: bits.c,v 1.39 2004/09/04 14:56:27 menno Exp $
+** $Id: bits.c,v 1.40 2005/02/01 13:15:56 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/bits.h
+++ b/libfaad/bits.h
@@ -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, 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
 ** 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
+** 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 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: bits.h,v 1.40 2004/09/04 14:56:27 menno Exp $
+** $Id: bits.h,v 1.41 2005/02/01 13:15:56 menno Exp $
 **/
 
 #ifndef __BITS_H__
@@ -281,8 +286,9 @@
     }
 
     if (r != CRC)
+  //  if (0)
     {
-        return 8;
+        return 28;
     } else {
         return 0;
     }
--- a/libfaad/cfft_tab.h
+++ b/libfaad/cfft_tab.h
@@ -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, 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
 ** 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
+** 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 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: cfft_tab.h,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: cfft_tab.h,v 1.18 2005/02/01 13:15:56 menno Exp $
 **/
 
 #ifndef __CFFT_TAB_H__
--- a/libfaad/common.c
+++ b/libfaad/common.c
@@ -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, 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
 ** 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
+** 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 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: common.c,v 1.22 2004/09/08 09:43:11 gcp Exp $
+** $Id: common.c,v 1.23 2005/02/01 13:23:34 menno Exp $
 **/
 
 /* just some common functions that could be used anywhere */
--- a/libfaad/common.h
+++ b/libfaad/common.h
@@ -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, 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
 ** 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
+** 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 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: common.h,v 1.65 2004/09/08 09:43:11 gcp Exp $
+** $Id: common.h,v 1.66 2005/02/01 13:23:35 menno Exp $
 **/
 
 #ifndef __COMMON_H__
@@ -36,7 +41,12 @@
 #  include "../config.h"
 #endif
 
+#if 1
 #define INLINE __inline
+#else
+#define INLINE inline
+#endif
+
 #if 0 //defined(_WIN32) && !defined(_WIN32_WCE)
 #define ALIGN __declspec(align(16))
 #else
@@ -65,7 +75,6 @@
 #define FIXED_POINT
 #endif
 
-
 #define ERROR_RESILIENCE
 
 
@@ -77,8 +86,6 @@
 #define LTP_DEC
 /* Allow decoding of LD profile AAC */
 #define LD_DEC
-/* Allow decoding of scalable profiles */
-//#define SCALABLE_DEC
 /* Allow decoding of Digital Radio Mondiale (DRM) */
 //#define DRM
 //#define DRM_PS
@@ -112,6 +119,10 @@
 //#define SBR_LOW_POWER
 #define PS_DEC
 
+#ifdef SBR_LOW_POWER
+#undef PS_DEC
+#endif
+
 /* FIXED POINT: No MAIN decoding */
 #ifdef FIXED_POINT
 # ifdef MAIN_DEC
@@ -120,9 +131,13 @@
 #endif // FIXED_POINT
 
 #ifdef DRM
-# ifndef SCALABLE_DEC
-#  define SCALABLE_DEC
+# ifndef ALLOW_SMALL_FRAMELENGTH
+#  define ALLOW_SMALL_FRAMELENGTH
 # endif
+# undef LD_DEC
+# undef LTP_DEC
+# undef MAIN_DEC
+# undef SSR_DEC
 #endif
 
 
@@ -195,11 +210,16 @@
 #  include <stdint.h>
 # else
 /* we need these... */
+#ifndef __TCS__
 typedef unsigned long long uint64_t;
+typedef long long int64_t;
+#else
+typedef unsigned long uint64_t;
+typedef long int64_t;
+#endif
 typedef unsigned long uint32_t;
 typedef unsigned short uint16_t;
 typedef unsigned char uint8_t;
-typedef long long int64_t;
 typedef long int32_t;
 typedef short int16_t;
 typedef char int8_t;
@@ -206,7 +226,7 @@
 # endif
 #endif
 #if HAVE_UNISTD_H
-# include <unistd.h>
+//# include <unistd.h>
 #endif
 
 #ifndef HAVE_FLOAT32_T
--- a/libfaad/decoder.h
+++ b/libfaad/decoder.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: decoder.h,v 1.44 2004/09/04 14:56:28 menno Exp $
+** $Id: decoder.h,v 1.45 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifndef __DECODER_H__
--- a/libfaad/drc.c
+++ b/libfaad/drc.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: drc.c,v 1.24 2004/09/04 14:56:28 menno Exp $
+** $Id: drc.c,v 1.25 2005/02/01 13:15:57 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/drc.h
+++ b/libfaad/drc.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: drc.h,v 1.18 2004/09/04 14:56:28 menno Exp $
+** $Id: drc.h,v 1.19 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifndef __DRC_H__
--- a/libfaad/drm_dec.c
+++ b/libfaad/drm_dec.c
@@ -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, 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
 ** 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
+** 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 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: drm_dec.c,v 1.5 2004/09/04 14:56:28 menno Exp $
+** $Id: drm_dec.c,v 1.6 2005/02/01 13:15:57 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/libfaad/drm_dec.h
+++ b/libfaad/drm_dec.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: drm_dec.h,v 1.4 2004/09/04 14:56:28 menno Exp $
+** $Id: drm_dec.h,v 1.5 2005/02/01 13:15:57 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/libfaad/error.c
+++ b/libfaad/error.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: error.c,v 1.28 2004/09/04 14:56:28 menno Exp $
+** $Id: error.c,v 1.29 2005/02/01 13:15:57 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/libfaad/error.h
+++ b/libfaad/error.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: error.h,v 1.22 2004/09/04 14:56:28 menno Exp $
+** $Id: error.h,v 1.23 2005/02/01 13:15:57 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/libfaad/fixed.h
+++ b/libfaad/fixed.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: fixed.h,v 1.26 2004/09/04 14:56:28 menno Exp $
+** $Id: fixed.h,v 1.27 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifndef __FIXED_H__
@@ -35,6 +40,7 @@
 #if defined(_WIN32_WCE) && defined(_ARM_)
 #include <cmnintrin.h>
 #endif
+
 
 #define COEF_BITS 28
 #define COEF_PRECISION (1 << COEF_BITS)
--- a/libfaad/hcr.c
+++ b/libfaad/hcr.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: hcr.c,v 1.18 2004/09/04 14:56:28 menno Exp $
+** $Id: hcr.c,v 1.19 2005/02/01 13:15:57 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; 
 
@@ -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/libfaad/huffman.c
+++ b/libfaad/huffman.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: huffman.c,v 1.22 2004/09/04 14:56:28 menno Exp $
+** $Id: huffman.c,v 1.23 2005/02/01 13:15:57 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/huffman.h
+++ b/libfaad/huffman.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: huffman.h,v 1.24 2004/09/04 14:56:28 menno Exp $
+** $Id: huffman.h,v 1.25 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifndef __HUFFMAN_H__
--- a/libfaad/ic_predict.c
+++ b/libfaad/ic_predict.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: ic_predict.c,v 1.23 2004/09/04 14:56:28 menno Exp $
+** $Id: ic_predict.c,v 1.24 2005/02/01 13:15:57 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/ic_predict.h
+++ b/libfaad/ic_predict.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: ic_predict.h,v 1.19 2004/09/04 14:56:28 menno Exp $
+** $Id: ic_predict.h,v 1.20 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifdef MAIN_DEC
--- a/libfaad/iq_table.h
+++ b/libfaad/iq_table.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: iq_table.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: iq_table.h,v 1.17 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifndef IQ_TABLE_H__
--- a/libfaad/is.c
+++ b/libfaad/is.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: is.c,v 1.24 2004/09/04 14:56:28 menno Exp $
+** $Id: is.c,v 1.25 2005/02/01 13:15:57 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/is.h
+++ b/libfaad/is.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: is.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: is.h,v 1.17 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifndef __IS_H__
--- a/libfaad/kbd_win.h
+++ b/libfaad/kbd_win.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: kbd_win.h,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: kbd_win.h,v 1.18 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifndef __KBD_WIN_H__
--- a/libfaad/lt_predict.c
+++ b/libfaad/lt_predict.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: lt_predict.c,v 1.23 2004/09/04 14:56:28 menno Exp $
+** $Id: lt_predict.c,v 1.24 2005/02/01 13:15:57 menno Exp $
 **/
 
 
@@ -52,9 +57,6 @@
 #endif
 #ifdef LD_DEC
         || (object_type == LD)
-#endif
-#ifdef SCALABLE_DEC
-        || (object_type == 6) /* TODO */
 #endif
         )
     {
--- a/libfaad/lt_predict.h
+++ b/libfaad/lt_predict.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: lt_predict.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: lt_predict.h,v 1.17 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifdef LTP_DEC
--- a/libfaad/mdct.c
+++ b/libfaad/mdct.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: mdct.c,v 1.43 2004/09/04 14:56:28 menno Exp $
+** $Id: mdct.c,v 1.44 2005/02/01 13:15:57 menno Exp $
 **/
 
 /*
--- a/libfaad/mdct_tab.h
+++ b/libfaad/mdct_tab.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: mdct_tab.h,v 1.3 2004/09/04 14:56:28 menno Exp $
+** $Id: mdct_tab.h,v 1.4 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifndef __MDCT_TAB_H__
--- a/libfaad/mp4.c
+++ b/libfaad/mp4.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: mp4.c,v 1.32 2004/09/04 14:56:28 menno Exp $
+** $Id: mp4.c,v 1.33 2005/02/01 13:15:57 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
--- a/libfaad/mp4.h
+++ b/libfaad/mp4.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: mp4.h,v 1.21 2004/09/04 14:56:28 menno Exp $
+** $Id: mp4.h,v 1.22 2005/02/01 13:15:57 menno Exp $
 **/
 
 #ifndef __MP4_H__
--- a/libfaad/ms.c
+++ b/libfaad/ms.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: ms.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: ms.c,v 1.18 2005/02/01 13:15:58 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/ms.h
+++ b/libfaad/ms.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: ms.h,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: ms.h,v 1.16 2005/02/01 13:15:58 menno Exp $
 **/
 
 #ifndef __MS_H__
--- a/libfaad/output.c
+++ b/libfaad/output.c
@@ -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, 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
 ** 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
+** 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 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: output.c,v 1.42 2004/09/04 14:56:28 menno Exp $
+** $Id: output.c,v 1.43 2005/02/01 13:15:58 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/output.h
+++ b/libfaad/output.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: output.h,v 1.21 2004/09/04 14:56:28 menno Exp $
+** $Id: output.h,v 1.22 2005/02/01 13:15:58 menno Exp $
 **/
 
 #ifndef __OUTPUT_H__
--- a/libfaad/pns.c
+++ b/libfaad/pns.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: pns.c,v 1.34 2004/09/04 14:56:28 menno Exp $
+** $Id: pns.c,v 1.35 2005/02/01 13:15:58 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/pns.h
+++ b/libfaad/pns.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: pns.h,v 1.23 2004/09/04 14:56:28 menno Exp $
+** $Id: pns.h,v 1.24 2005/02/01 13:15:58 menno Exp $
 **/
 
 #ifndef __PNS_H__
--- a/libfaad/ps_dec.c
+++ b/libfaad/ps_dec.c
@@ -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, 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
 ** 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
+** 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 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: ps_dec.c,v 1.10 2004/09/04 14:56:28 menno Exp $
+** $Id: ps_dec.c,v 1.11 2005/02/01 13:15:58 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,12 +689,12 @@
         {
             /* 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 */
@@ -696,7 +701,7 @@
             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 */
@@ -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])
 {
@@ -1588,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;
@@ -1622,7 +1646,7 @@
 
                 /* ringbuffer index */
                 if (i == 0)
-                { 
+                {
                     i = 2;
                 }
                 i--;
@@ -1652,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)));
+                xy = magnitude_c(tempRight);
+                pq = magnitude_c(tempLeft);
 
-                /* 1 + (x*x)/(y*y)  (REAL > 1) */
-                xxyy += REAL_CONST(1);
-                ppqq += REAL_CONST(1);
+                if (xy != 0)
+                {
+                    RE(phaseLeft) = DIV_R(RE(tempRight), xy);
+                    IM(phaseLeft) = DIV_R(IM(tempRight), xy);
+                } else {
+                    RE(phaseLeft) = 0;
+                    IM(phaseLeft) = 0;
+                }
 
-                /* 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));
+                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) */
--- a/libfaad/ps_dec.h
+++ b/libfaad/ps_dec.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: ps_dec.h,v 1.8 2004/09/04 14:56:28 menno Exp $
+** $Id: ps_dec.h,v 1.9 2005/02/01 13:15:58 menno Exp $
 **/
 
 #ifndef __PS_DEC_H__
--- a/libfaad/ps_syntax.c
+++ b/libfaad/ps_syntax.c
@@ -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, 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
 ** 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
+** 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 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: ps_syntax.c,v 1.6 2004/09/04 14:56:28 menno Exp $
+** $Id: ps_syntax.c,v 1.7 2005/02/01 13:15:58 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 */
--- a/libfaad/ps_tables.h
+++ b/libfaad/ps_tables.h
@@ -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, 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
 ** 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
+** 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 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: ps_tables.h,v 1.3 2004/09/04 14:56:28 menno Exp $
+** $Id: ps_tables.h,v 1.4 2005/02/01 13:15:58 menno Exp $
 **/
 
 #ifndef __PS_TABLES_H__
--- a/libfaad/pulse.c
+++ b/libfaad/pulse.c
@@ -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, 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
@@ -19,12 +19,16 @@
 ** 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 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: pulse.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: pulse.c,v 1.18 2005/02/01 13:15:58 menno Exp $
 **/
-
 #include "common.h"
 #include "structs.h"
 
--- a/libfaad/pulse.h
+++ b/libfaad/pulse.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: pulse.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: pulse.h,v 1.17 2005/02/01 13:15:58 menno Exp $
 **/
 
 #ifndef __PULSE_H__
--- a/libfaad/rvlc.c
+++ b/libfaad/rvlc.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: rvlc.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: rvlc.c,v 1.18 2005/02/01 13:15:58 menno Exp $
 **/
 
 /* RVLC scalefactor decoding
--- a/libfaad/rvlc.h
+++ b/libfaad/rvlc.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: rvlc.h,v 1.13 2004/09/04 14:56:28 menno Exp $
+** $Id: rvlc.h,v 1.14 2005/02/01 13:15:58 menno Exp $
 **/
 
 #ifndef __RVLC_SCF_H__
--- a/libfaad/sbr_dct.c
+++ b/libfaad/sbr_dct.c
@@ -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, 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
 ** 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
+** 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 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: sbr_dct.c,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_dct.c,v 1.16 2005/02/01 13:15:58 menno Exp $
 **/
 
 #include "common.h"
@@ -1811,7 +1816,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
--- a/libfaad/sbr_dct.h
+++ b/libfaad/sbr_dct.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_dct.h,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_dct.h,v 1.16 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_DCT_H__
--- a/libfaad/sbr_dec.c
+++ b/libfaad/sbr_dec.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_dec.c,v 1.39 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_dec.c,v 1.40 2005/02/01 13:15:59 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)
     {
@@ -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/libfaad/sbr_dec.h
+++ b/libfaad/sbr_dec.h
@@ -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, 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
 ** 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
+** 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 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: sbr_dec.h,v 1.35 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_dec.h,v 1.36 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_DEC_H__
@@ -231,6 +236,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/libfaad/sbr_e_nf.c
+++ b/libfaad/sbr_e_nf.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_e_nf.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_e_nf.c,v 1.18 2005/02/01 13:15:59 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/sbr_e_nf.h
+++ b/libfaad/sbr_e_nf.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_e_nf.h,v 1.14 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_e_nf.h,v 1.15 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_E_NF_H__
--- a/libfaad/sbr_fbt.h
+++ b/libfaad/sbr_fbt.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_fbt.h,v 1.14 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_fbt.h,v 1.15 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_FBT_H__
--- a/libfaad/sbr_hfadj.c
+++ b/libfaad/sbr_hfadj.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_hfadj.c,v 1.18 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_hfadj.c,v 1.19 2005/02/01 13:15:59 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
@@ -1342,16 +1360,28 @@
 {
     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)
                 {
                     sbr->f_group[l][i] = k;
@@ -1361,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/libfaad/sbr_hfadj.h
+++ b/libfaad/sbr_hfadj.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_hfadj.h,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_hfadj.h,v 1.16 2005/02/01 13:15:59 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/libfaad/sbr_hfgen.h
+++ b/libfaad/sbr_hfgen.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_hfgen.h,v 1.16 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_hfgen.h,v 1.17 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_HFGEN_H__
--- a/libfaad/sbr_huff.c
+++ b/libfaad/sbr_huff.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_huff.c,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_huff.c,v 1.18 2005/02/01 13:15:59 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/sbr_huff.h
+++ b/libfaad/sbr_huff.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_huff.h,v 1.17 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_huff.h,v 1.18 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_HUFF_H__
--- a/libfaad/sbr_noise.h
+++ b/libfaad/sbr_noise.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_noise.h,v 1.13 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_noise.h,v 1.14 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_NOISE_H__
--- a/libfaad/sbr_qmf.c
+++ b/libfaad/sbr_qmf.c
@@ -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, 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
 ** 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
+** 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 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: sbr_qmf.c,v 1.27 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_qmf.c,v 1.28 2005/02/01 13:15:59 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/libfaad/sbr_qmf_c.h
+++ b/libfaad/sbr_qmf_c.h
@@ -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, 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
 ** 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
+** 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 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: sbr_qmf_c.h,v 1.13 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_qmf_c.h,v 1.14 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_QMF_C_H__
--- a/libfaad/sbr_syntax.c
+++ b/libfaad/sbr_syntax.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_syntax.c,v 1.34 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_syntax.c,v 1.35 2005/02/01 13:15:59 menno Exp $
 **/
 
 #include "common.h"
@@ -206,26 +211,28 @@
             {
                 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_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;
     }
 
 #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;
 
@@ -364,11 +371,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 +441,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
--- a/libfaad/sbr_syntax.h
+++ b/libfaad/sbr_syntax.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_syntax.h,v 1.19 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_syntax.h,v 1.20 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_SYNTAX_H__
--- a/libfaad/sbr_tf_grid.c
+++ b/libfaad/sbr_tf_grid.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_tf_grid.c,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_tf_grid.c,v 1.16 2005/02/01 13:15:59 menno Exp $
 **/
 
 /* Time/Frequency grid */
--- a/libfaad/sbr_tf_grid.h
+++ b/libfaad/sbr_tf_grid.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sbr_tf_grid.h,v 1.13 2004/09/04 14:56:28 menno Exp $
+** $Id: sbr_tf_grid.h,v 1.14 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SBR_TF_GRID_H__
--- a/libfaad/sine_win.h
+++ b/libfaad/sine_win.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: sine_win.h,v 1.15 2004/09/04 14:56:28 menno Exp $
+** $Id: sine_win.h,v 1.16 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SINE_WIN_H__
--- a/libfaad/specrec.h
+++ b/libfaad/specrec.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: specrec.h,v 1.28 2004/09/04 14:56:29 menno Exp $
+** $Id: specrec.h,v 1.29 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SPECREC_H__
--- a/libfaad/ssr.c
+++ b/libfaad/ssr.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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.c,v 1.15 2004/09/04 14:56:29 menno Exp $
+** $Id: ssr.c,v 1.16 2005/02/01 13:15:59 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/ssr.h
+++ b/libfaad/ssr.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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.h,v 1.15 2004/09/04 14:56:29 menno Exp $
+** $Id: ssr.h,v 1.16 2005/02/01 13:15:59 menno Exp $
 **/
 
 #ifndef __SSR_H__
--- a/libfaad/ssr_fb.c
+++ b/libfaad/ssr_fb.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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.c,v 1.13 2004/09/04 14:56:29 menno Exp $
+** $Id: ssr_fb.c,v 1.14 2005/02/01 13:15:59 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/ssr_fb.h
+++ b/libfaad/ssr_fb.h
@@ -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
@@ -16,7 +16,18 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: ssr_fb.h,v 1.13 2004/09/04 14:56:29 menno Exp $
+** 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 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/libfaad/ssr_ipqf.c
+++ b/libfaad/ssr_ipqf.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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.c,v 1.14 2004/09/04 14:56:29 menno Exp $
+** $Id: ssr_ipqf.c,v 1.15 2005/02/01 13:15:59 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/ssr_ipqf.h
+++ b/libfaad/ssr_ipqf.h
@@ -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
@@ -16,7 +16,18 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: ssr_ipqf.h,v 1.14 2004/09/04 14:56:29 menno Exp $
+** 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 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/libfaad/ssr_win.h
+++ b/libfaad/ssr_win.h
@@ -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
@@ -16,7 +16,18 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: ssr_win.h,v 1.13 2004/09/04 14:56:29 menno Exp $
+** 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 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/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: syntax.c,v 1.82 2004/09/04 14:56:29 menno Exp $
+** $Id: syntax.c,v 1.83 2005/02/01 13:15:59 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,6 +437,7 @@
         {
             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)
@@ -435,6 +444,7 @@
                     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)
@@ -441,24 +451,41 @@
                     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;
@@ -1049,10 +1100,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 +1212,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 +1230,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,24 +1244,79 @@
         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;
+    }
 
-        hInfo->error = individual_channel_stream(hDecoder, &cpe, ld, ics, 1, spec_data);
+
+    /* Stereo2 / Mono1 */
+    ics1->tns_data_present = faad_get1bit(ld);
+
+#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
     /* In case of DRM we need to read the SBR info before channel reconstruction */
     if ((hDecoder->sbr_present_flag == 1) && (hDecoder->object_type == DRM_ER_LC))
@@ -1244,6 +1354,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);
 
@@ -1261,6 +1372,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 +1385,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 +1424,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 +1465,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 +1488,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,7 +1579,22 @@
         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) 
     {
         if (ics->tns_data_present)
@@ -1523,10 +1604,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 */
@@ -1605,12 +1689,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 +1746,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 +1778,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 +1845,7 @@
                 break;
             case NOISE_HCB: /* noise books */
 
+#ifndef DRM
                 /* decode noise energy */
                 if (noise_pcm_flag)
                 {
@@ -1749,6 +1860,10 @@
                 ics->scale_factors[g][sfb] = noise_energy;
 #ifdef SF_PRINT
                 printf("%d\n", ics->scale_factors[g][sfb]);
+#endif
+#else
+                /* PNS not allowed in DRM */
+                return 29;
 #endif
 
                 break;
--- a/libfaad/syntax.h
+++ b/libfaad/syntax.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: syntax.h,v 1.54 2004/09/04 14:56:29 menno Exp $
+** $Id: syntax.h,v 1.55 2005/02/01 13:15:59 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/libfaad/tns.c
+++ b/libfaad/tns.c
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: tns.c,v 1.35 2004/09/04 14:56:29 menno Exp $
+** $Id: tns.c,v 1.36 2005/02/01 13:16:00 menno Exp $
 **/
 
 #include "common.h"
--- a/libfaad/tns.h
+++ b/libfaad/tns.h
@@ -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, 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
@@ -19,10 +19,15 @@
 ** 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 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: tns.h,v 1.19 2004/09/04 14:56:29 menno Exp $
+** $Id: tns.h,v 1.20 2005/02/01 13:16:00 menno Exp $
 **/
 
 #ifndef __TNS_H__