shithub: aacdec

Download patch

ref: 26d190b3b044f04affebc0ea91152cae4c8203ca
parent: 3c9ab2e25aaeac7a39ed5e745a252794f569a960
author: menno <menno>
date: Mon Feb 18 05:01:06 EST 2002

some restructuring -> better cache performance and lower memory usage
library interface changed a bit so programs using this should change a bit

--- a/TODO
+++ b/TODO
@@ -8,6 +8,5 @@
 
 - Reintroduce:
  - Sonique plugin
- - XMMS plugin
  - CoolEdit plugin
 
--- a/frontend/faad.dsp
+++ b/frontend/faad.dsp
@@ -50,7 +50,7 @@
 # ADD BSC32 /nologo
 LINK32=xilink6.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /machine:I386
+# ADD LINK32 ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /machine:I386
 
 !ELSEIF  "$(CFG)" == "faad - Win32 Debug"
 
@@ -74,7 +74,7 @@
 # ADD BSC32 /nologo
 LINK32=xilink6.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
 
 !ENDIF 
 
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: main.c,v 1.12 2002/02/04 09:17:43 menno Exp $
+** $Id: main.c,v 1.13 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifdef _WIN32
@@ -153,7 +153,8 @@
                   int def_srate, int use_ltp, int outputFormat, int fileType)
 {
     int tagsize;
-    unsigned long samplerate, channels;
+    unsigned long samplerate;
+    unsigned char channels;
     void *sample_buffer;
 
     FILE *infile;
@@ -297,12 +298,13 @@
         if (!strcmp(trackType, MP4_AUDIO_TRACK_TYPE))
         {
             unsigned char *buff = NULL;
-            int buff_size = 0, dummy;
+            int buff_size = 0;
+            unsigned long dummy32; unsigned char dummy8;
             MP4GetTrackESConfiguration(infile, trackId, &buff, &buff_size);
 
             if (buff)
             {
-                rc = AudioSpecificConfig(buff, &dummy, &dummy, &dummy, &dummy);
+                rc = AudioSpecificConfig(buff, &dummy32, &dummy8, &dummy8, &dummy8);
                 free(buff);
 
                 if (rc < 0)
@@ -326,7 +328,8 @@
                   int outputFormat, int fileType)
 {
     int track;
-    unsigned long samplerate, channels;
+    unsigned long samplerate;
+    unsigned char channels;
     void *sample_buffer;
 
     MP4FileHandle infile;
--- a/include/faad.h
+++ b/include/faad.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: faad.h,v 1.3 2002/01/20 17:00:48 menno Exp $
+** $Id: faad.h,v 1.4 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __AACDEC_H__
@@ -29,7 +29,7 @@
 #ifdef _WIN32
   #pragma pack(push, 8)
   #ifndef FAADAPI
-    #define FAADAPI __stdcall
+    #define FAADAPI __cdecl
   #endif
 #else
   #ifndef FAADAPI
@@ -54,54 +54,54 @@
 
 
 typedef void *faacDecHandle;
-typedef void *faacProgConfig;
 
+
 typedef struct faacDecConfiguration
 {
-    short defObjectType;
+    unsigned char defObjectType;
     unsigned long defSampleRate;
-    unsigned long outputFormat;
+    unsigned char outputFormat;
 } faacDecConfiguration, *faacDecConfigurationPtr;
 
 typedef struct faacDecFrameInfo
 {
-    int bytesconsumed;
-    int samples;
-    int channels;
-    int error;
+    unsigned long bytesconsumed;
+    unsigned long samples;
+    unsigned char channels;
+    unsigned char error;
 } faacDecFrameInfo;
 
-char* FAADAPI faacDecGetErrorMessage(int errcode);
+unsigned char* FAADAPI faacDecGetErrorMessage(unsigned char errcode);
 
 faacDecHandle FAADAPI faacDecOpen();
 
 faacDecConfigurationPtr FAADAPI faacDecGetCurrentConfiguration(faacDecHandle hDecoder);
 
-int FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
+unsigned char FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
                                     faacDecConfigurationPtr config);
 
 /* Init the library based on info from the AAC file (ADTS/ADIF) */
-int FAADAPI faacDecInit(faacDecHandle hDecoder,
+long FAADAPI faacDecInit(faacDecHandle hDecoder,
                         unsigned char *buffer,
                         unsigned long *samplerate,
-                        unsigned long *channels);
+                        unsigned char *channels);
 
 /* Init the library using a DecoderSpecificInfo */
-int FAADAPI faacDecInit2(faacDecHandle hDecoder, unsigned char *pBuffer,
+char FAADAPI faacDecInit2(faacDecHandle hDecoder, unsigned char *pBuffer,
                          unsigned long SizeOfDecoderSpecificInfo,
-                         unsigned long *samplerate, unsigned long *channels);
+                         unsigned long *samplerate, unsigned char *channels);
 
+void FAADAPI faacDecClose(faacDecHandle hDecoder);
+
 void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
                             faacDecFrameInfo *hInfo,
                             unsigned char *buffer);
 
-void FAADAPI faacDecClose(faacDecHandle hDecoder);
-
-int FAADAPI AudioSpecificConfig(unsigned char *pBuffer,
+char FAADAPI AudioSpecificConfig(unsigned char *pBuffer,
                                 unsigned long *samplerate,
-                                unsigned long *channels,
-                                unsigned long *sf_index,
-                                unsigned long *object_type);
+                                unsigned char *channels,
+                                unsigned char *sf_index,
+                                unsigned char *object_type);
 
 #ifdef _WIN32
   #pragma pack(pop)
--- a/libfaad/analysis.h
+++ b/libfaad/analysis.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: analysis.h,v 1.1 2002/01/22 09:11:24 menno Exp $
+** $Id: analysis.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __ANALYSIS_H__
@@ -28,9 +28,9 @@
 
 
 #ifdef ANALYSIS
-#define DEBUGDEC        ,int print,int var,char *dbg
+#define DEBUGDEC        ,uint8_t print,uint16_t var,uint8_t *dbg
 #define DEBUGVAR(A,B,C) ,A,B,C
-extern int dbg_count;
+extern uint16_t dbg_count;
 #else
 #define DEBUGDEC
 #define DEBUGVAR(A,B,C)
--- a/libfaad/bits.c
+++ b/libfaad/bits.c
@@ -16,26 +16,26 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: bits.c,v 1.4 2002/02/15 20:52:09 menno Exp $
+** $Id: bits.c,v 1.5 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "common.h"
 #include "bits.h"
 
-
 /* initialize buffer, call once before first getbits or showbits */
 void faad_initbits(bitfile *ld, void *buffer)
 {
-    unsigned long tmp;
+    uint32_t tmp;
 
-    ld->start = (unsigned long*)buffer;
+    ld->start = (uint32_t*)buffer;
 
-    tmp = *(unsigned long*)buffer;
+    tmp = *(uint32_t*)buffer;
 #ifndef ARCH_IS_BIG_ENDIAN
     BSWAP(tmp);
 #endif
     ld->bufa = tmp;
 
-    tmp = *((unsigned long*)buffer + 1);
+    tmp = *((uint32_t*)buffer + 1);
 #ifndef ARCH_IS_BIG_ENDIAN
     BSWAP(tmp);
 #endif
@@ -42,17 +42,17 @@
     ld->bufb = tmp;
 
     ld->pos = 0;
-    ld->tail = ((unsigned long*)buffer + 2);
+    ld->tail = ((uint32_t*)buffer + 2);
 }
 
-int faad_get_processed_bits(bitfile *ld)
+uint32_t faad_get_processed_bits(bitfile *ld)
 {
     return 8 * (4*(ld->tail - ld->start) - 4) - (32 - ld->pos);
 }
 
-unsigned int faad_byte_align(bitfile *ld)
+uint8_t faad_byte_align(bitfile *ld)
 {
-    unsigned long remainder = ld->pos % 8;
+    uint8_t remainder = (uint8_t)(ld->pos % 8);
 
     if (remainder)
     {
--- a/libfaad/bits.h
+++ b/libfaad/bits.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: bits.h,v 1.4 2002/02/15 20:52:09 menno Exp $
+** $Id: bits.h,v 1.5 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __BITS_H__
@@ -32,27 +32,24 @@
 #endif
 
 #define BYTE_NUMBIT 8
-#define bit2byte(a) ((a)/BYTE_NUMBIT)
+#define bit2byte(a) ((a+7)/BYTE_NUMBIT)
 
 typedef struct _bitfile
 {
     /* bit input */
-	unsigned long bufa;
-	unsigned long bufb;
-	unsigned long pos;
-	unsigned long *tail;
-	unsigned long *start;
+	uint32_t bufa;
+	uint32_t bufb;
+	uint32_t pos;
+	uint32_t *tail;
+	uint32_t *start;
 } bitfile;
 
 
-#if defined _WIN32
-#define bits_inline __inline
+#if defined(_WIN32)
 #define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
 #elif defined(LINUX) || defined(DJGPP)
-#define bits_inline inline
 #define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) )
 #else
-#define bits_inline
 #define BSWAP(a) \
 	 ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))
 #endif
@@ -59,13 +56,13 @@
 
 
 void faad_initbits(bitfile *ld, void *buffer);
-unsigned int faad_byte_align(bitfile *ld);
-int faad_get_processed_bits(bitfile *ld);
+uint8_t faad_byte_align(bitfile *ld);
+uint32_t faad_get_processed_bits(bitfile *ld);
 
 
-static bits_inline unsigned int faad_showbits(bitfile *ld, int bits)
+static INLINE uint32_t faad_showbits(bitfile *ld, uint8_t bits)
 {
-    int nbit = (bits + ld->pos) - 32;
+    int32_t nbit = (bits + ld->pos) - 32;
     if (nbit > 0) 
     {
         return ((ld->bufa & (0xffffffff >> ld->pos)) << nbit) |
@@ -75,16 +72,16 @@
     }
 }
 
-static bits_inline void faad_flushbits(bitfile *ld, int bits)
+static INLINE void faad_flushbits(bitfile *ld, uint8_t bits)
 {
 	ld->pos += bits;
 
 	if (ld->pos >= 32) 
 	{
-		unsigned long tmp;
+		uint32_t tmp;
 
 		ld->bufa = ld->bufb;
-		tmp = *(unsigned long*)ld->tail;
+		tmp = *(uint32_t*)ld->tail;
 #ifndef ARCH_IS_BIG_ENDIAN
 		BSWAP(tmp);
 #endif
@@ -95,9 +92,9 @@
 }
 
 /* return next n bits (right adjusted) */
-static bits_inline unsigned int faad_getbits(bitfile *ld, int n DEBUGDEC)
+static INLINE uint32_t faad_getbits(bitfile *ld, uint8_t n DEBUGDEC)
 {
-	unsigned long ret = faad_showbits(ld, n);
+	uint32_t ret = faad_showbits(ld, n);
 	faad_flushbits(ld, n);
 
 #ifdef ANALYSIS
@@ -108,9 +105,9 @@
 	return ret;
 }
 
-static bits_inline unsigned int faad_get1bit(bitfile *ld DEBUGDEC)
+static INLINE uint8_t faad_get1bit(bitfile *ld DEBUGDEC)
 {
-    return faad_getbits(ld, 1 DEBUGVAR(print,var,dbg));
+    return (uint8_t)faad_getbits(ld, 1 DEBUGVAR(print,var,dbg));
 }
 
 #ifdef __cplusplus
--- a/libfaad/codebook/hcb.h
+++ b/libfaad/codebook/hcb.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb.h,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __HCB_H__
@@ -74,38 +74,38 @@
 /* 1st step table */
 typedef struct
 {
-    unsigned char offset;
-    unsigned char extra_bits;
+    uint8_t offset;
+    uint8_t extra_bits;
 } hcb;
 
 /* 2nd step table with quadruple data */
 typedef struct
 {
-    unsigned char bits;
-    char x;
-    char y;
+    uint8_t bits;
+    int8_t x;
+    int8_t y;
 } hcb_2_pair;
 
 typedef struct
 {
-    unsigned char bits;
-    char x;
-    char y;
-    char v;
-    char w;
+    uint8_t bits;
+    int8_t x;
+    int8_t y;
+    int8_t v;
+    int8_t w;
 } hcb_2_quad;
 
 /* binary search table */
 typedef struct
 {
-    unsigned char is_leaf;
-    char data[4];
+    uint8_t is_leaf;
+    int8_t data[4];
 } hcb_bin_quad;
 
 typedef struct
 {
-    unsigned char is_leaf;
-    char data[2];
+    uint8_t is_leaf;
+    int8_t data[2];
 } hcb_bin_pair;
 
 extern hcb hcb1_1[];
@@ -129,7 +129,7 @@
 extern hcb_bin_pair hcb7[];
 extern hcb_bin_pair hcb9[];
 
-extern char hcb_sf[][2];
+extern uint8_t hcb_sf[][2];
 
 #ifdef __cplusplus
 }
--- a/libfaad/codebook/hcb_1.c
+++ b/libfaad/codebook/hcb_1.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_1.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_1.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* 2-step huffman table HCB_1 */
--- a/libfaad/codebook/hcb_10.c
+++ b/libfaad/codebook/hcb_10.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_10.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_10.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* 2-step huffman table HCB_10 */
--- a/libfaad/codebook/hcb_11.c
+++ b/libfaad/codebook/hcb_11.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_11.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_11.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* 2-step huffman table HCB_11 */
--- a/libfaad/codebook/hcb_2.c
+++ b/libfaad/codebook/hcb_2.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_2.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_2.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* 2-step huffman table HCB_2 */
--- a/libfaad/codebook/hcb_3.c
+++ b/libfaad/codebook/hcb_3.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_3.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_3.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* Binary search huffman table HCB_3 */
--- a/libfaad/codebook/hcb_4.c
+++ b/libfaad/codebook/hcb_4.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_4.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_4.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* 2-step huffman table HCB_4 */
--- a/libfaad/codebook/hcb_5.c
+++ b/libfaad/codebook/hcb_5.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_5.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_5.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* Binary search huffman table HCB_5 */
--- a/libfaad/codebook/hcb_6.c
+++ b/libfaad/codebook/hcb_6.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_6.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_6.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* 2-step huffman table HCB_6 */
--- a/libfaad/codebook/hcb_7.c
+++ b/libfaad/codebook/hcb_7.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_7.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_7.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* Binary search huffman table HCB_7 */
--- a/libfaad/codebook/hcb_8.c
+++ b/libfaad/codebook/hcb_8.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_8.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_8.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* 2-step huffman table HCB_8 */
--- a/libfaad/codebook/hcb_9.c
+++ b/libfaad/codebook/hcb_9.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_9.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_9.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* Binary search huffman table HCB_9 */
--- a/libfaad/codebook/hcb_sf.c
+++ b/libfaad/codebook/hcb_sf.c
@@ -16,15 +16,16 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcb_sf.c,v 1.1 2002/02/15 20:52:10 menno Exp $
+** $Id: hcb_sf.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "../common.h"
 #include "hcb.h"
 
 /* Binary search huffman table HCB_SF */
 
 
-extern char hcb_sf[][2] = {
+extern uint8_t hcb_sf[][2] = {
     { /*  0 */  1, 2 },
     { /*  1 */  60, 0 },
     { /*  2 */  1, 2 },
--- /dev/null
+++ b/libfaad/common.h
@@ -1,0 +1,119 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**  
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+** 
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+** 
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** $Id: common.h,v 1.1 2002/02/18 10:01:05 menno Exp $
+**/
+
+#ifndef __COMMON_H__
+#define __COMMON_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#ifdef LINUX
+#define INLINE inline
+#else
+#ifdef _WIN32
+#define INLINE __inline
+#else
+#define INLINE
+#endif
+#endif
+
+#ifndef max
+#define max(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+#ifndef min
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846f
+#endif
+#ifndef M_PI_2 /* PI/2 */
+#define M_PI_2 1.57079632679489661923
+#endif
+
+
+//#define USE_DOUBLE_PRECISION
+
+
+#if defined(_WIN32)
+
+
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int8 uint8_t;
+typedef __int32 int32_t;
+typedef __int16 int16_t;
+typedef __int8  int8_t;
+typedef float float32_t;
+
+#ifndef USE_DOUBLE_PRECISION
+typedef float real_t;
+#ifdef __ICL /* only Intel C compiler has fmath ??? */
+#define USE_FMATH
+#endif
+#else
+typedef double real_t;
+#endif
+
+
+#elif defined(LINUX) || defined(DJGPP)
+
+
+#if defined(LINUX)
+#include <stdint.h>
+#else
+typedef unsigned long uint32_t;
+typedef unsigned short uint16_t;
+typedef unsigned char uint8_t;
+typedef long int32_t;
+typedef short int16_t;
+typedef char int8_t;
+typedef float float32_t;
+#endif
+
+#ifndef USE_DOUBLE_PRECISION
+typedef float real_t;
+#else
+typedef double real_t;
+#endif
+
+
+#else /* Some other OS */
+
+
+#include <inttypes.h>
+
+#ifndef USE_DOUBLE_PRECISION
+typedef float real_t;
+#else
+typedef double real_t;
+#endif
+
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- a/libfaad/data.c
+++ b/libfaad/data.c
@@ -16,22 +16,23 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: data.c,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: data.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "common.h"
 #include "data.h"
 
-extern short num_swb_long_window[] =
+extern uint8_t num_swb_long_window[] =
 {
     41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40
 };
 
-extern short num_swb_short_window[] =
+extern uint8_t num_swb_short_window[] =
 {
     12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15
 };
 
-static short swb_offset_long_96[] =
+static uint16_t swb_offset_long_96[] =
 {
     0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56,
     64, 72, 80, 88, 96, 108, 120, 132, 144, 156, 172, 188, 212, 240,
@@ -38,12 +39,12 @@
     276, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024
 };
 
-static short swb_offset_short_96[] =
+static uint16_t swb_offset_short_96[] =
 {
     0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128
 };
 
-static short swb_offset_long_64[] =
+static uint16_t swb_offset_long_64[] =
 {
     0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56,
     64, 72, 80, 88, 100, 112, 124, 140, 156, 172, 192, 216, 240, 268,
@@ -51,13 +52,13 @@
     864, 904, 944, 984, 1024
 };
 
-static short swb_offset_short_64[] =
+static uint16_t swb_offset_short_64[] =
 {
     0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128
 };
 
 
-static short swb_offset_long_48[] =
+static uint16_t swb_offset_long_48[] =
 {
     0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72,
     80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292,
@@ -65,12 +66,12 @@
     768, 800, 832, 864, 896, 928, 1024
 };
 
-static short swb_offset_short_48[] =
+static uint16_t swb_offset_short_48[] =
 {
     0, 4, 8, 12, 16, 20, 28, 36, 44, 56, 68, 80, 96, 112, 128
 };
 
-static short swb_offset_long_32[] =
+static uint16_t swb_offset_long_32[] =
 {
     0, 4,  8,  12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72,
     80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292,
@@ -78,7 +79,7 @@
     768, 800, 832, 864, 896, 928, 960, 992, 1024
 };
 
-static short swb_offset_long_24[] =
+static uint16_t swb_offset_long_24[] =
 {
     0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68,
     76, 84, 92, 100, 108, 116, 124, 136, 148, 160, 172, 188, 204, 220,
@@ -86,12 +87,12 @@
     768, 832, 896, 960, 1024
 };
 
-static short swb_offset_short_24[] =
+static uint16_t swb_offset_short_24[] =
 {
     0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 64, 76, 92, 108, 128
 };
 
-static short swb_offset_long_16[] =
+static uint16_t swb_offset_long_16[] =
 {
     0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 100, 112, 124,
     136, 148, 160, 172, 184, 196, 212, 228, 244, 260, 280, 300, 320, 344,
@@ -98,12 +99,12 @@
     368, 396, 424, 456, 492, 532, 572, 616, 664, 716, 772, 832, 896, 960, 1024
 };
 
-static short swb_offset_short_16[] =
+static uint16_t swb_offset_short_16[] =
 {
     0, 4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 60, 72, 88, 108, 128
 };
 
-static short swb_offset_long_8[] =
+static uint16_t swb_offset_long_8[] =
 {
     0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 172,
     188, 204, 220, 236, 252, 268, 288, 308, 328, 348, 372, 396, 420, 448,
@@ -110,12 +111,12 @@
     476, 508, 544, 580, 620, 664, 712, 764, 820, 880, 944, 1024
 };
 
-static short swb_offset_short_8[] =
+static uint16_t swb_offset_short_8[] =
 {
     0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 60, 72, 88, 108, 128
 };
 
-extern short *swb_offset_long_window[] =
+extern uint16_t *swb_offset_long_window[] =
 {
     swb_offset_long_96,      /* 96000 */
     swb_offset_long_96,      /* 88200 */
@@ -131,7 +132,7 @@
     swb_offset_long_8        /* 8000  */
 };
 
-extern short *swb_offset_short_window[] =
+extern uint16_t *swb_offset_short_window[] =
 {
     swb_offset_short_96,      /* 96000 */
     swb_offset_short_96,      /* 88200 */
@@ -147,7 +148,7 @@
     swb_offset_short_8        /* 8000  */
 };
 
-extern short pred_sfb_max[] =
+extern uint8_t pred_sfb_max[] =
 {
     33,     /* 96000 */
     33,     /* 88200 */
@@ -163,7 +164,7 @@
     34      /* 8000  */
 };
 
-extern unsigned long sample_rates[] =
+extern uint32_t sample_rates[] =
 {
     96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000,
     12000, 11025, 8000
--- a/libfaad/data.h
+++ b/libfaad/data.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: data.h,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: data.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __DATA_H__
@@ -26,12 +26,12 @@
 extern "C" {
 #endif
 
-extern short num_swb_long_window[];
-extern short num_swb_short_window[];
-extern short *swb_offset_long_window[];
-extern short *swb_offset_short_window[];
-extern short pred_sfb_max[];
-extern unsigned long sample_rates[];
+extern uint8_t num_swb_long_window[];
+extern uint8_t num_swb_short_window[];
+extern uint16_t *swb_offset_long_window[];
+extern uint16_t *swb_offset_short_window[];
+extern uint8_t pred_sfb_max[];
+extern uint32_t sample_rates[];
 
 #ifdef __cplusplus
 }
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -16,11 +16,12 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: decoder.c,v 1.7 2002/01/27 09:10:46 menno Exp $
+** $Id: decoder.c,v 1.8 2002/02/18 10:01:05 menno Exp $
 **/
 
 #include <stdlib.h>
 #include <memory.h>
+#include "common.h"
 #include "decoder.h"
 #include "mp4.h"
 #include "syntax.h"
@@ -37,10 +38,10 @@
 #include "output.h"
 
 #ifdef ANALYSIS
-int dbg_count;
+uint16_t dbg_count;
 #endif
 
-char* FAADAPI faacDecGetErrorMessage(int errcode)
+uint8_t* FAADAPI faacDecGetErrorMessage(uint8_t errcode)
 {
     return err_msg[errcode];
 }
@@ -47,7 +48,7 @@
 
 faacDecHandle FAADAPI faacDecOpen()
 {
-    int i;
+    uint8_t i;
     faacDecHandle hDecoder = NULL;
 
     if ((hDecoder = (faacDecHandle)malloc(sizeof(faacDecStruct))) == NULL)
@@ -93,7 +94,7 @@
     return config;
 }
 
-int FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
+uint8_t FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
                                     faacDecConfigurationPtr config)
 {
     hDecoder->config.defObjectType = config->defObjectType;
@@ -105,7 +106,7 @@
 }
 
 /* Returns the sample rate index */
-static int get_sr_index(unsigned long samplerate)
+static uint8_t get_sr_index(uint32_t samplerate)
 {
     if (92017 <= samplerate) return 0;
     if (75132 <= samplerate) return 1;
@@ -122,8 +123,8 @@
     return 11;
 }
 
-int FAADAPI faacDecInit(faacDecHandle hDecoder, unsigned char *buffer,
-                        unsigned long *samplerate, unsigned long *channels)
+int32_t FAADAPI faacDecInit(faacDecHandle hDecoder, uint8_t *buffer,
+                        uint32_t *samplerate, uint8_t *channels)
 {
     bitfile ld;
     adif_header adif;
@@ -176,11 +177,11 @@
 }
 
 /* Init the library using a DecoderSpecificInfo */
-int FAADAPI faacDecInit2(faacDecHandle hDecoder, unsigned char *pBuffer,
-                         unsigned long SizeOfDecoderSpecificInfo,
-                         unsigned long *samplerate, unsigned long *channels)
+int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
+                         uint32_t SizeOfDecoderSpecificInfo,
+                         uint32_t *samplerate, uint8_t *channels)
 {
-    int rc;
+    int8_t rc;
 
     hDecoder->adif_header_present = 0;
     hDecoder->adts_header_present = 0;
@@ -207,7 +208,7 @@
 
 void FAADAPI faacDecClose(faacDecHandle hDecoder)
 {
-    int i;
+    uint8_t i;
 
     for (i = 0; i < MAX_CHANNELS; i++)
     {
@@ -226,39 +227,40 @@
 
 void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
                             faacDecFrameInfo *hInfo,
-                            unsigned char *buffer)
+                            uint8_t *buffer)
 {
-    int id_syn_ele, ele, ch, i;
+    int32_t i;
+    uint8_t id_syn_ele, ele, ch;
     adts_header adts;
-    int channels, ch_ele;
+    uint8_t channels, ch_ele;
     bitfile *ld = malloc(sizeof(bitfile));
 
     /* local copys of globals */
-    int sf_index           =  hDecoder->sf_index;
-    int object_type        =  hDecoder->object_type;
+    uint8_t sf_index       =  hDecoder->sf_index;
+    uint8_t object_type    =  hDecoder->object_type;
     pred_state **pred_stat =  hDecoder->pred_stat;
-    float **lt_pred_stat   =  hDecoder->lt_pred_stat;
+    real_t **lt_pred_stat  =  hDecoder->lt_pred_stat;
 #if IQ_TABLE_SIZE
-    float *iq_table        =  hDecoder->iq_table;
+    real_t *iq_table       =  hDecoder->iq_table;
 #else
-    float *iq_table        =  NULL;
+    real_t *iq_table       =  NULL;
 #endif
 #if POW_TABLE_SIZE
-    float *pow2_table      =  hDecoder->pow2_table;
+    real_t *pow2_table     =  hDecoder->pow2_table;
 #else
-    float *pow2_table      =  NULL;
+    real_t *pow2_table     =  NULL;
 #endif
-    int *window_shape_prev =  hDecoder->window_shape_prev;
-    float **time_state     =  hDecoder->time_state;
-    float **time_out       =  hDecoder->time_out;
+    uint8_t *window_shape_prev =  hDecoder->window_shape_prev;
+    real_t **time_state    =  hDecoder->time_state;
+    real_t **time_out      =  hDecoder->time_out;
     fb_info *fb            = &hDecoder->fb;
     drc_info *drc          = &hDecoder->drc;
-    int outputFormat       =  hDecoder->config.outputFormat;
+    uint8_t outputFormat   =  hDecoder->config.outputFormat;
 
     program_config pce;
     element *syntax_elements[MAX_SYNTAX_ELEMENTS];
-    short *spec_data[MAX_CHANNELS];
-    float *spec_coef[MAX_CHANNELS];
+    int16_t *spec_data[MAX_CHANNELS];
+    real_t *spec_coef[MAX_CHANNELS];
 
     void *sample_buffer;
 
@@ -287,14 +289,14 @@
 #endif
 
     /* Table 4.4.3: raw_data_block() */
-    while ((id_syn_ele = faad_getbits(ld, LEN_SE_ID
+    while ((id_syn_ele = (uint8_t)faad_getbits(ld, LEN_SE_ID
         DEBUGVAR(1,4,"faacDecDecode(): id_syn_ele"))) != ID_END)
     {
         switch (id_syn_ele) {
         case ID_SCE:
         case ID_LFE:
-            spec_data[channels]   = (short*)malloc(1024*sizeof(short));
-            spec_coef[channels]   = (float*)malloc(1024*sizeof(float));
+            spec_data[channels]   = (int16_t*)malloc(1024*sizeof(int16_t));
+            spec_coef[channels]   = (real_t*)malloc(1024*sizeof(real_t));
 
             syntax_elements[ch_ele] = (element*)malloc(sizeof(element));
             memset(syntax_elements[ch_ele], 0, sizeof(element));
@@ -313,10 +315,10 @@
             ch_ele++;
             break;
         case ID_CPE:
-            spec_data[channels]   = (short*)malloc(1024*sizeof(short));
-            spec_data[channels+1] = (short*)malloc(1024*sizeof(short));
-            spec_coef[channels]   = (float*)malloc(1024*sizeof(float));
-            spec_coef[channels+1] = (float*)malloc(1024*sizeof(float));
+            spec_data[channels]   = (int16_t*)malloc(1024*sizeof(int16_t));
+            spec_data[channels+1] = (int16_t*)malloc(1024*sizeof(int16_t));
+            spec_coef[channels]   = (real_t*)malloc(1024*sizeof(real_t));
+            spec_coef[channels+1] = (real_t*)malloc(1024*sizeof(real_t));
 
             syntax_elements[ch_ele] = (element*)malloc(sizeof(element));
             memset(syntax_elements[ch_ele], 0, sizeof(element));
@@ -366,7 +368,7 @@
     hInfo->channels = channels;
 
     if (hDecoder->sample_buffer == NULL)
-        hDecoder->sample_buffer = malloc(1024*channels*sizeof(float));
+        hDecoder->sample_buffer = malloc(1024*channels*sizeof(float32_t));
 
     sample_buffer = hDecoder->sample_buffer;
 
@@ -380,10 +382,10 @@
         {
             if (syntax_elements[i]->channel == ch)
             {
-                ics = &syntax_elements[i]->ics1;
+                ics = &(syntax_elements[i]->ics1);
                 break;
             } else if (syntax_elements[i]->paired_channel == ch) {
-                ics = &syntax_elements[i]->ics2;
+                ics = &(syntax_elements[i]->ics2);
                 break;
             }
         }
@@ -404,8 +406,8 @@
     */
     for (ch = 0; ch < channels; ch++)
     {
-        int pch = 0;
-        int right_channel;
+        uint8_t pch = 0;
+        uint8_t right_channel;
         ic_stream *ics, *icsr;
         ltp_info *ltp;
 
@@ -414,14 +416,14 @@
         {
             if (syntax_elements[i]->channel == ch)
             {
-                ics = &syntax_elements[i]->ics1;
-                icsr = &syntax_elements[i]->ics2;
+                ics = &(syntax_elements[i]->ics1);
+                icsr = &(syntax_elements[i]->ics2);
                 ltp = &(ics->ltp);
                 pch = syntax_elements[i]->paired_channel;
                 right_channel = 0;
                 break;
             } else if (syntax_elements[i]->paired_channel == ch) {
-                ics = &syntax_elements[i]->ics2;
+                ics = &(syntax_elements[i]->ics2);
                 ltp = &(ics->ltp2);
                 right_channel = 1;
                 break;
@@ -464,8 +466,8 @@
             /* allocate the state only when needed */
             if ((lt_pred_stat[ch] == NULL) && ics->predictor_data_present)
             {
-                lt_pred_stat[ch] = malloc(1024*3 * sizeof(float));
-                memset(lt_pred_stat[ch], 0, 1024*3 * sizeof(float));
+                lt_pred_stat[ch] = malloc(1024*3 * sizeof(real_t));
+                memset(lt_pred_stat[ch], 0, 1024*3 * sizeof(real_t));
             }
 
             /* long term prediction */
@@ -478,7 +480,7 @@
         }
 
         /* tns decoding */
-        tns_decode_frame(ics, &ics->tns, sf_index, object_type, spec_coef[ch]);
+        tns_decode_frame(ics, &(ics->tns), sf_index, object_type, spec_coef[ch]);
 
         /* drc decoding */
         if (drc->present)
@@ -489,9 +491,9 @@
 
         if (time_state[ch] == NULL)
         {
-            float *tp;
+            real_t *tp;
 
-            time_state[ch] = malloc(1024*sizeof(float));
+            time_state[ch] = malloc(1024*sizeof(real_t));
             tp = time_state[ch];
             for (i = 1024/16-1; i >= 0; --i)
             {
@@ -503,7 +505,7 @@
         }
         if (time_out[ch] == NULL)
         {
-            time_out[ch] = malloc(1024*2*sizeof(float));
+            time_out[ch] = malloc(1024*2*sizeof(real_t));
         }
 
         /* filter bank */
--- a/libfaad/decoder.h
+++ b/libfaad/decoder.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: decoder.h,v 1.2 2002/01/19 09:39:41 menno Exp $
+** $Id: decoder.h,v 1.3 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __DECODER_H__
@@ -26,10 +26,10 @@
 extern "C" {
 #endif
 
-#ifdef WIN32
+#ifdef _WIN32
   #pragma pack(push, 8)
   #ifndef FAADAPI
-    #define FAADAPI __stdcall
+    #define FAADAPI __cdecl
   #endif
 #else
   #ifndef FAADAPI
@@ -51,48 +51,48 @@
 
 typedef struct faacDecConfiguration
 {
-    short defObjectType;
-    unsigned long defSampleRate;
-    unsigned long outputFormat;
+    uint8_t defObjectType;
+    uint32_t defSampleRate;
+    uint8_t outputFormat;
 } faacDecConfiguration, *faacDecConfigurationPtr;
 
 typedef struct faacDecFrameInfo
 {
-    int bytesconsumed;
-    int samples;
-    int channels;
-    int error;
+    uint32_t bytesconsumed;
+    uint32_t samples;
+    uint8_t channels;
+    uint8_t error;
 } faacDecFrameInfo;
 
 typedef struct
 {
-    int adts_header_present;
-    int adif_header_present;
-    int sf_index;
-    int object_type;
+    uint8_t adts_header_present;
+    uint8_t adif_header_present;
+    uint8_t sf_index;
+    uint8_t object_type;
 
-    int frame;
+    uint32_t frame;
 
     void *sample_buffer;
 
-    int window_shape_prev[MAX_CHANNELS];
+    uint8_t window_shape_prev[MAX_CHANNELS];
     fb_info fb;
     drc_info drc;
 
-    float *time_state[MAX_CHANNELS];
-    float *time_out[MAX_CHANNELS];
+    real_t *time_state[MAX_CHANNELS];
+    real_t *time_out[MAX_CHANNELS];
 
     pred_state *pred_stat[MAX_CHANNELS];
-    float *lt_pred_stat[MAX_CHANNELS];
+    real_t *lt_pred_stat[MAX_CHANNELS];
 
-    float exp_table[256];
-    float mnt_table[128];
+    real_t exp_table[256];
+    real_t mnt_table[128];
 
 #if IQ_TABLE_SIZE
-    float iq_table[IQ_TABLE_SIZE];
+    real_t iq_table[IQ_TABLE_SIZE];
 #endif
 #if POW_TABLE_SIZE
-    float pow2_table[POW_TABLE_SIZE];
+    real_t pow2_table[POW_TABLE_SIZE];
 #endif
 
     /* Configuration data */
@@ -100,33 +100,33 @@
 } faacDecStruct, *faacDecHandle;
 
 
-char* FAADAPI faacDecGetErrorMessage(int errcode);
+uint8_t* FAADAPI faacDecGetErrorMessage(uint8_t errcode);
 
 faacDecHandle FAADAPI faacDecOpen();
 
 faacDecConfigurationPtr FAADAPI faacDecGetCurrentConfiguration(faacDecHandle hDecoder);
 
-int FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
+uint8_t FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
                                     faacDecConfigurationPtr config);
 
 /* Init the library based on info from the AAC file (ADTS/ADIF) */
-int FAADAPI faacDecInit(faacDecHandle hDecoder,
-                        unsigned char *buffer,
-                        unsigned long *samplerate,
-                        unsigned long *channels);
+int32_t FAADAPI faacDecInit(faacDecHandle hDecoder,
+                        uint8_t *buffer,
+                        uint32_t *samplerate,
+                        uint8_t *channels);
 
 /* Init the library using a DecoderSpecificInfo */
-int FAADAPI faacDecInit2(faacDecHandle hDecoder, unsigned char *pBuffer,
-                         unsigned long SizeOfDecoderSpecificInfo,
-                         unsigned long *samplerate, unsigned long *channels);
+int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
+                         uint32_t SizeOfDecoderSpecificInfo,
+                         uint32_t *samplerate, uint8_t *channels);
 
 void FAADAPI faacDecClose(faacDecHandle hDecoder);
 
 void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
                             faacDecFrameInfo *hInfo,
-                            unsigned char *buffer);
+                            uint8_t *buffer);
 
-#ifdef WIN32
+#ifdef _WIN32
   #pragma pack(pop)
 #endif
 
--- a/libfaad/drc.c
+++ b/libfaad/drc.c
@@ -16,10 +16,12 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: drc.c,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: drc.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
-#ifdef __ICL
+#include "common.h"
+
+#ifdef USE_FMATH
 #include <mathf.h>
 #else
 #include <math.h>
@@ -28,7 +30,7 @@
 #include "syntax.h"
 #include "drc.h"
 
-void init_drc(drc_info *drc, float cut, float boost)
+void init_drc(drc_info *drc, real_t cut, real_t boost)
 {
     memset(drc, 0, sizeof(drc_info));
 
@@ -41,11 +43,11 @@
     drc->dyn_rng_ctl[0] = 0;
 }
 
-void drc_decode(drc_info *drc, float *spec)
+void drc_decode(drc_info *drc, real_t *spec)
 {
-    int i, bd, top;
-    float factor;
-    int bottom = 0;
+    uint16_t i, bd, top;
+    real_t factor;
+    uint16_t bottom = 0;
 
     if (drc->num_bands == 1)
         drc->band_top[0] = 1024/4 - 1;
@@ -56,16 +58,16 @@
 
         /* Decode DRC gain factor */
         if (drc->dyn_rng_sgn[bd])  /* compress */
-#ifdef __ICL
+#ifdef USE_FMATH
             factor = powf(2.0f, (-drc->ctrl1 * drc->dyn_rng_ctl[bd]/24.0f));
 #else
-            factor = (float)pow(2.0, (-drc->ctrl1 * drc->dyn_rng_ctl[bd]/24.0));
+            factor = (real_t)pow(2.0, (-drc->ctrl1 * drc->dyn_rng_ctl[bd]/24.0));
 #endif
         else /* boost */
-#ifdef __ICL
-            factor = powf(2.0f, ( drc->ctrl2 * drc->dyn_rng_ctl[bd]/24.0f));
+#ifdef USE_FMATH
+            factor = powf(2.0f, (drc->ctrl2 * drc->dyn_rng_ctl[bd]/24.0f));
 #else
-            factor = (float)pow(2.0, ( drc->ctrl2 * drc->dyn_rng_ctl[bd]/24.0));
+            factor = (real_t)pow(2.0, (drc->ctrl2 * drc->dyn_rng_ctl[bd]/24.0));
 #endif
 
         /* Level alignment between different programs (if desired) */
@@ -76,14 +78,14 @@
            modification avoids problems with reduced DAC SNR (if signal is
            attenuated) or clipping (if signal is boosted)
          */
-#ifdef __ICL
+#ifdef USE_FMATH
         factor *= powf(0.5f, ((DRC_REF_LEVEL - drc->prog_ref_level)/24.0f));
 #else
-        factor *= (float)pow(0.5, ((DRC_REF_LEVEL - drc->prog_ref_level)/24.0));
+        factor *= (real_t)pow(0.5, ((DRC_REF_LEVEL - drc->prog_ref_level)/24.0));
 #endif
 
         /* Apply gain factor */
-        for (i = bottom; i<top; i++)
+        for (i = bottom; i < top; i++)
             spec[i] *= factor;
 
         bottom = top;
--- a/libfaad/drc.h
+++ b/libfaad/drc.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: drc.h,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: drc.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __DRC_H__
@@ -28,8 +28,8 @@
 
 #define DRC_REF_LEVEL 20*4 /* -20 dB */
 
-void init_drc(drc_info *drc, float cut, float boost);
-void drc_decode(drc_info *drc, float *spec);
+void init_drc(drc_info *drc, real_t cut, real_t boost);
+void drc_decode(drc_info *drc, real_t *spec);
 
 
 #ifdef __cplusplus
--- a/libfaad/error.c
+++ b/libfaad/error.c
@@ -16,12 +16,13 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: error.c,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: error.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "common.h"
 #include "error.h"
 
-extern char *err_msg[] = {
+extern uint8_t *err_msg[] = {
     "No error",
     "Gain control not yet implemented",
     "Pulse coding not allowed in short blocks",
--- a/libfaad/error.h
+++ b/libfaad/error.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: error.h,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: error.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __ERROR_H__
@@ -26,7 +26,7 @@
 extern "C" {
 #endif
 
-extern char *err_msg[];
+extern uint8_t *err_msg[];
 
 #ifdef __cplusplus
 }
--- a/libfaad/filtbank.c
+++ b/libfaad/filtbank.c
@@ -16,11 +16,13 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: filtbank.c,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: filtbank.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "common.h"
+
 #include <stdlib.h>
-#ifdef __ICL
+#ifdef USE_FMATH
 #include <mathf.h>
 #else
 #include <math.h>
@@ -31,31 +33,18 @@
 #include "kbd_win.h"
 #include "mdct.h"
 
-#ifndef PI
-#define PI 3.14159265359f
-#endif
 
-#ifdef LINUX
-#define INLINE inline
-#else
-#ifdef WIN32
-#define INLINE __inline
-#else
-#define INLINE
-#endif
-#endif
+real_t *long_window[2];
+real_t *short_window[2];
 
-float *long_window[2];
-float *short_window[2];
-
 void filter_bank_init(fb_info *fb)
 {
-    int i;
+    uint16_t i;
 
     make_fft_order(fb->unscrambled64, fb->unscrambled512);
 
-    fb->sin_long  = malloc(BLOCK_LEN_LONG*sizeof(float));
-    fb->sin_short = malloc(BLOCK_LEN_SHORT*sizeof(float));
+    fb->sin_long  = malloc(BLOCK_LEN_LONG*sizeof(real_t));
+    fb->sin_short = malloc(BLOCK_LEN_SHORT*sizeof(real_t));
 
     long_window[0]  = fb->sin_long;
     long_window[1]  = kbd_long;
@@ -64,16 +53,16 @@
 
     /* calculate the sine windows */
     for (i = 0; i < BLOCK_LEN_LONG; i++)
-#ifdef __ICL
-        fb->sin_long[i] = sinf(PI / (2.0f * BLOCK_LEN_LONG) * (i + 0.5));
+#ifdef USE_FMATH
+        fb->sin_long[i] = sinf(M_PI / (2.0f * BLOCK_LEN_LONG) * (i + 0.5));
 #else
-        fb->sin_long[i] = (float)sin(PI / (2.0 * BLOCK_LEN_LONG) * (i + 0.5));
+        fb->sin_long[i] = (real_t)sin(M_PI / (2.0 * BLOCK_LEN_LONG) * (i + 0.5));
 #endif
     for (i = 0; i < BLOCK_LEN_SHORT; i++)
-#ifdef __ICL
-        fb->sin_short[i] = sinf(PI / (2.0f * BLOCK_LEN_SHORT) * (i + 0.5));
+#ifdef USE_FMATH
+        fb->sin_short[i] = sinf(M_PI / (2.0f * BLOCK_LEN_SHORT) * (i + 0.5));
 #else
-        fb->sin_short[i] = (float)sin(PI / (2.0 * BLOCK_LEN_SHORT) * (i + 0.5));
+        fb->sin_short[i] = (real_t)sin(M_PI / (2.0 * BLOCK_LEN_SHORT) * (i + 0.5));
 #endif
 }
 
@@ -83,9 +72,9 @@
     if (fb->sin_short) free(fb->sin_short);
 }
 
-static INLINE void vcopy(float *src, float *dest, int vlen)
+static INLINE void vcopy(real_t *src, real_t *dest, uint16_t vlen)
 {
-    int i;
+    int16_t i;
 
     assert(vlen % 16 == 0);
 
@@ -98,9 +87,9 @@
     }
 }
 
-static INLINE void vzero(float *dest, int vlen)
+static INLINE void vzero(real_t *dest, uint16_t vlen)
 {
-    int i;
+    int16_t i;
 
     assert(vlen % 16 == 0);
 
@@ -113,9 +102,9 @@
     }
 }
 
-static INLINE void vmult1(float *src1, float *src2, float *dest, int vlen)
+static INLINE void vmult1(real_t *src1, real_t *src2, real_t *dest, uint16_t vlen)
 {
-    int i;
+    int16_t i;
 
     assert(vlen % 16 == 0);
 
@@ -132,9 +121,9 @@
     }
 }
 
-static INLINE void vmult2(float *src1, float *src2, float *dest, int vlen)
+static INLINE void vmult2(real_t *src1, real_t *src2, real_t *dest, uint16_t vlen)
 {
-    int i;
+    int16_t i;
 
     assert(vlen % 16 == 0);
 
@@ -151,9 +140,9 @@
     }
 }
 
-static INLINE void vadd(float *src1, float *src2, float *dest, int vlen)
+static INLINE void vadd(real_t *src1, real_t *src2, real_t *dest, uint16_t vlen)
 {
-    int i;
+    int16_t i;
 
     assert(vlen % 16 == 0);
 
@@ -170,7 +159,7 @@
     }
 }
 
-static INLINE void imdct(fb_info *fb, float *in_data, float *out_data, int len)
+static INLINE void imdct(fb_info *fb, real_t *in_data, real_t *out_data, uint16_t len)
 {
     switch (len)
     {
@@ -183,7 +172,7 @@
     }
 }
 
-static INLINE void mdct(fb_info *fb, float *in_data, float *out_data, int len)
+static INLINE void mdct(fb_info *fb, real_t *in_data, real_t *out_data, uint16_t len)
 {
     switch (len)
     {
@@ -196,24 +185,24 @@
     }
 }
 
-void ifilter_bank(fb_info *fb, int window_sequence, int window_shape,
-                  int window_shape_prev, float *freq_in, float *time_buff,
-                  float *time_out)
+void ifilter_bank(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
+                  uint8_t window_shape_prev, real_t *freq_in, real_t *time_buff,
+                  real_t *time_out)
 {
-    float *o_buf, transf_buf[2*BLOCK_LEN_LONG];
+    real_t *o_buf, transf_buf[2*BLOCK_LEN_LONG];
 
-    float *window_long;
-    float *window_long_prev;
-    float *window_short;
-    float *window_short_prev;
-    float *window_short_prev_ptr;
+    real_t *window_long;
+    real_t *window_long_prev;
+    real_t *window_short;
+    real_t *window_short_prev;
+    real_t *window_short_prev_ptr;
 
-    float *fp;
-    int win;
-    int nlong = 1024;
-    int nshort = 128;
+    real_t *fp;
+    int8_t win;
+    uint16_t nlong = 1024;
+    uint16_t nshort = 128;
 
-    int nflat_ls = (nlong-nshort)/2;
+    uint16_t nflat_ls = (nlong-nshort)/2;
 
     window_long       =  long_window[window_shape];
     window_long_prev  =  long_window[window_shape_prev];
@@ -322,22 +311,22 @@
 }
 
 /* only works for LTP -> no overlapping */
-void filter_bank_ltp(fb_info *fb, int window_sequence, int window_shape,
-                     int window_shape_prev, float *in_data, float *out_mdct)
+void filter_bank_ltp(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
+                     uint8_t window_shape_prev, real_t *in_data, real_t *out_mdct)
 {
-    int win;
-    float windowed_buf[2*1024];
-    float *p_o_buf;
+    int8_t win;
+    real_t windowed_buf[2*1024];
+    real_t *p_o_buf;
 
-    float *window_long;
-    float *window_long_prev;
-    float *window_short;
-    float *window_short_prev;
-    float *window_short_prev_ptr;
+    real_t *window_long;
+    real_t *window_long_prev;
+    real_t *window_short;
+    real_t *window_short_prev;
+    real_t *window_short_prev_ptr;
 
-    int nlong = 1024;
-    int nshort = 128;
-    int nflat_ls = (nlong-nshort)/2;
+    uint16_t nlong = 1024;
+    uint16_t nshort = 128;
+    uint16_t nflat_ls = (nlong-nshort)/2;
 
 
     window_long       =  long_window[window_shape];
--- a/libfaad/filtbank.h
+++ b/libfaad/filtbank.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: filtbank.h,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: filtbank.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __FILTBANK_H__
@@ -33,21 +33,30 @@
 
 typedef struct
 {
-    short unscrambled64[64];
-    short unscrambled512[512];
+    uint16_t unscrambled64[64];
+    uint16_t unscrambled512[512];
 
-    float *sin_long;
-    float *sin_short;
+    real_t *sin_long;
+    real_t *sin_short;
 } fb_info;
 
 void filter_bank_init(fb_info *fb);
 void filter_bank_end(fb_info *fb);
 
-void filter_bank_ltp(fb_info *fb, int window_sequence, int window_shape,
-                     int window_shape_prev, float *in_data, float *out_mdct);
-void ifilter_bank(fb_info *fb, int window_sequence, int window_shape, 
-                  int window_shape_prev, float *freq_in, float *time_buff,
-                  float *time_out);
+void filter_bank_ltp(fb_info *fb,
+                     uint8_t window_sequence,
+                     uint8_t window_shape,
+                     uint8_t window_shape_prev,
+                     real_t *in_data,
+                     real_t *out_mdct);
+
+void ifilter_bank(fb_info *fb,
+                  uint8_t window_sequence,
+                  uint8_t window_shape,
+                  uint8_t window_shape_prev,
+                  real_t *freq_in,
+                  real_t *time_buff,
+                  real_t *time_out);
 
 #ifdef __cplusplus
 }
--- a/libfaad/huffman.h
+++ b/libfaad/huffman.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: huffman.h,v 1.4 2002/02/15 20:52:09 menno Exp $
+** $Id: huffman.h,v 1.5 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __HUFFMAN_H__
@@ -34,21 +34,13 @@
 #include "codebook/hcb.h"
 
 
-#if defined(LINUX)
-#define huff_inline inline
-#elif defined(_WIN32)
-#define huff_inline __inline
-#else
-#define huff_inline
-#endif
-
-static huff_inline int huffman_scale_factor(bitfile *ld)
+static INLINE uint8_t huffman_scale_factor(bitfile *ld)
 {
-    unsigned int offset = 0;
+    uint16_t offset = 0;
 
     while (hcb_sf[offset][1])
     {
-        int b = faad_get1bit(ld);
+        uint8_t b = faad_get1bit(ld);
         offset += hcb_sf[offset][b];
     }
     return hcb_sf[offset][0];
@@ -71,14 +63,14 @@
     0, 0, 0, 0, 0, hcb5, 0, hcb7, 0, hcb9, 0, 0
 };
 
-static int hcbN[] = { 0, 5, 5, 0, 5, 0, 5, 0, 5, 0, 6, 5 };
+static uint8_t hcbN[] = { 0, 5, 5, 0, 5, 0, 5, 0, 5, 0, 6, 5 };
 
 
-static huff_inline void huffman_spectral_data(int cb, bitfile *ld, short *sp)
+static INLINE void huffman_spectral_data(uint8_t cb, bitfile *ld, int16_t *sp)
 {
-    unsigned int cw;
-    unsigned int offset = 0;
-    unsigned int extra_bits;
+    uint32_t cw;
+    uint16_t offset = 0;
+    uint8_t extra_bits;
 
     switch (cb)
     {
@@ -94,7 +86,7 @@
         {
             /* we know for sure it's more than hcbN[cb] bits long */
             faad_flushbits(ld, hcbN[cb]);
-            offset += faad_showbits(ld, extra_bits);
+            offset += (uint16_t)faad_showbits(ld, extra_bits);
             faad_flushbits(ld, hcb_2_quad_table[cb][offset].bits - hcbN[cb]);
         } else {
             faad_flushbits(ld, hcb_2_quad_table[cb][offset].bits);
@@ -119,7 +111,7 @@
         {
             /* we know for sure it's more than hcbN[cb] bits long */
             faad_flushbits(ld, hcbN[cb]);
-            offset += faad_showbits(ld, extra_bits);
+            offset += (uint16_t)faad_showbits(ld, extra_bits);
             faad_flushbits(ld, hcb_2_pair_table[cb][offset].bits - hcbN[cb]);
         } else {
             faad_flushbits(ld, hcb_2_pair_table[cb][offset].bits);
@@ -133,7 +125,7 @@
 
         while (!hcb3[offset].is_leaf)
         {
-            int b = faad_get1bit(ld);
+            uint8_t b = faad_get1bit(ld);
             offset += hcb3[offset].data[b];
         }
 
@@ -150,7 +142,7 @@
 
         while (!hcb_bin_table[cb][offset].is_leaf)
         {
-            int b = faad_get1bit(ld);
+            uint8_t b = faad_get1bit(ld);
             offset += hcb_bin_table[cb][offset].data[b];
         }
 
@@ -161,9 +153,9 @@
     }
 }
 
-static huff_inline void huffman_sign_bits(bitfile *ld, short *sp, int len)
+static INLINE void huffman_sign_bits(bitfile *ld, int16_t *sp, uint8_t len)
 {
-    int i;
+    uint8_t i;
 
     for(i = 0; i < len; i++)
     {
@@ -178,9 +170,10 @@
     }
 }
 
-static huff_inline short huffman_getescape(bitfile *ld, short sp)
+static INLINE int32_t huffman_getescape(bitfile *ld, int16_t sp)
 {
-    int i, off, neg;
+    uint8_t neg, i;
+    int32_t j, off;
 
     if (sp < 0) {
         if(sp != -16)
@@ -210,10 +203,10 @@
             DEBUGVAR(1,9,"huffman_getescape(): escape"));
     }
 
-    i = off + (1<<i);
+    j = off + (1<<i);
     if (neg)
-        i = -i;
-    return i;
+        j = -j;
+    return j;
 }
 
 #ifdef __cplusplus
--- a/libfaad/ic_predict.c
+++ b/libfaad/ic_predict.c
@@ -16,49 +16,45 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: ic_predict.c,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: ic_predict.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
-#ifdef __ICL
-#include <mathf.h>
-#else
-#include <math.h>
-#endif
+#include "common.h"
 #include "syntax.h"
 #include "ic_predict.h"
 #include "pns.h"
 
-static void flt_round_inf(float *pf)
+static void flt_round_inf(real_t *pf)
 {
-    int flg;
-    unsigned long tmp;
-    float *pt = (float *)&tmp;
+    int32_t flg;
+    uint32_t tmp;
+    real_t *pt = (real_t *)&tmp;
 
     *pt = *pf;
-    flg = tmp & (unsigned long)0x00008000;
-    tmp &= (unsigned long)0xffff0000;
+    flg = tmp & (uint32_t)0x00008000;
+    tmp &= (uint32_t)0xffff0000;
     *pf = *pt;
 
     /* round 1/2 lsb toward infinity */
     if (flg)
     {
-        tmp &= (unsigned long)0xff800000; /* extract exponent and sign */
-        tmp |= (unsigned long)0x00010000; /* insert 1 lsb */
-        *pf += *pt;                       /* add 1 lsb and elided one */
-        tmp &= (unsigned long)0xff800000; /* extract exponent and sign */
-        *pf -= *pt;                       /* subtract elided one */
+        tmp &= (uint32_t)0xff800000; /* extract exponent and sign */
+        tmp |= (uint32_t)0x00010000; /* insert 1 lsb */
+        *pf += *pt;                  /* add 1 lsb and elided one */
+        tmp &= (uint32_t)0xff800000; /* extract exponent and sign */
+        *pf -= *pt;                  /* subtract elided one */
     }
 }
 
-static void ic_predict(pred_state *state, float input, float *output, int pred)
+static void ic_predict(pred_state *state, real_t input, real_t *output, uint8_t pred)
 {
-    float dr1, predictedvalue;
-    float e0, e1;
-    float k1, k2;
+    real_t dr1, predictedvalue;
+    real_t e0, e1;
+    real_t k1, k2;
 
-    float *r;
-    float *KOR;
-    float *VAR;
+    real_t *r;
+    real_t *KOR;
+    real_t *VAR;
 
     r   = state->r;   /* delay elements */
     KOR = state->KOR; /* correlations */
@@ -106,8 +102,8 @@
 
 void pns_reset_pred_state(ic_stream *ics, pred_state *state)
 {
-    int sfb, g, b, i;
-    int offs, size;
+    uint8_t sfb, g, b;
+    uint16_t i, offs, size;
 
     /* prediction only for long blocks */
     if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
@@ -134,7 +130,7 @@
 
 void reset_all_predictors(pred_state *state)
 {
-    int i;
+    uint16_t i;
 
     for (i = 0; i < 1024; i++)
         reset_pred_state(&state[i]);
@@ -141,9 +137,10 @@
 }
 
 /* intra channel prediction */
-void ic_prediction(ic_stream *ics, float *spec, pred_state *state)
+void ic_prediction(ic_stream *ics, real_t *spec, pred_state *state)
 {
-    int sfb, bin;
+    uint8_t sfb;
+    uint16_t bin;
 
     if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
     {
@@ -151,8 +148,8 @@
     } else {
         for (sfb = 0; sfb < ics->pred.limit; sfb++)
         {
-            int low  = ics->swb_offset[sfb];
-            int high = ics->swb_offset[sfb+1];
+            uint16_t low  = ics->swb_offset[sfb];
+            uint16_t high = ics->swb_offset[sfb+1];
 
             for (bin = low; bin < high; bin++)
             {
--- a/libfaad/ic_predict.h
+++ b/libfaad/ic_predict.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: ic_predict.h,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: ic_predict.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __IC_PREDICT_H__
@@ -33,15 +33,15 @@
 
 /* used to save the state */
 typedef struct {
-    float r[2];
-    float KOR[2];
-    float VAR[2];
+    real_t r[2];
+    real_t KOR[2];
+    real_t VAR[2];
 } pred_state;
 
 
 void pns_reset_pred_state(ic_stream *ics, pred_state *state);
 void reset_all_predictors(pred_state *state);
-void ic_prediction(ic_stream *ics, float *spec, pred_state *state);
+void ic_prediction(ic_stream *ics, real_t *spec, pred_state *state);
 
 
 #ifdef __cplusplus
--- a/libfaad/is.c
+++ b/libfaad/is.c
@@ -16,10 +16,12 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: is.c,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: is.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
-#ifdef __ICL
+#include "common.h"
+
+#ifdef USE_FMATH
 #include <mathf.h>
 #else
 #include <math.h>
@@ -27,12 +29,13 @@
 #include "syntax.h"
 #include "is.h"
 
-void is_decode(ic_stream *ics, ic_stream *icsr, float *l_spec, float *r_spec)
+void is_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec)
 {
-    int g, sfb, b, i, k;
-    float scale;
+    uint8_t g, sfb, b;
+    uint16_t i, k;
+    real_t scale;
 
-    int group = 0;
+    uint8_t group = 0;
 
     for (g = 0; g < icsr->num_window_groups; g++)
     {
@@ -52,10 +55,10 @@
 
                     scale = is_intensity(icsr, g, sfb) *
                         invert_intensity(ics, g, sfb) *
-#ifdef __ICL
+#ifdef USE_FMATH
                         powf(0.5f, (0.25f*icsr->scale_factors[g][sfb]));
 #else
-                        (float)pow(0.5, (0.25*icsr->scale_factors[g][sfb]));
+                        (real_t)pow(0.5, (0.25*icsr->scale_factors[g][sfb]));
 #endif
 
                     /* Scale from left to right channel,
--- a/libfaad/is.h
+++ b/libfaad/is.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: is.h,v 1.2 2002/01/19 09:39:41 menno Exp $
+** $Id: is.h,v 1.3 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __IS_H__
@@ -28,9 +28,9 @@
 
 #include "syntax.h"
 
-void is_decode(ic_stream *ics, ic_stream *icsr, float *l_spec, float *r_spec);
+void is_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec);
 
-static __inline int is_intensity(ic_stream *ics, int group, int sfb)
+static INLINE int8_t is_intensity(ic_stream *ics, uint8_t group, uint8_t sfb)
 {
     switch (ics->sfb_cb[group][sfb])
     {
@@ -43,7 +43,7 @@
     }
 }
 
-static __inline int invert_intensity(ic_stream *ics, int group, int sfb)
+static INLINE int8_t invert_intensity(ic_stream *ics, uint8_t group, uint8_t sfb)
 {
     if (ics->ms_mask_present == 1)
         return (1-2*ics->ms_used[group][sfb]);
--- a/libfaad/kbd_win.h
+++ b/libfaad/kbd_win.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: kbd_win.h,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: kbd_win.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __KBD_WIN_H__
@@ -30,7 +30,7 @@
 #pragma warning(disable:4305)
 #endif
 
-float kbd_long[] =
+real_t kbd_long[] =
 {
     0.00029256153896361,
     0.00042998567353047,
@@ -1059,7 +1059,7 @@
 };
 
 
-float kbd_short[] =
+real_t kbd_short[] =
 {
     4.3795702929468881e-005,
     0.00011867384265436617,
--- a/libfaad/libfaad.dsp
+++ b/libfaad/libfaad.dsp
@@ -221,6 +221,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\common.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\data.h
 # End Source File
 # Begin Source File
--- a/libfaad/lt_predict.c
+++ b/libfaad/lt_predict.c
@@ -16,28 +16,29 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: lt_predict.c,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: lt_predict.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "common.h"
 #include "syntax.h"
 #include "lt_predict.h"
 #include "filtbank.h"
 #include "tns.h"
 
-static float codebook[8] =
+static real_t codebook[8] =
 {
     0.570829f, 0.696616f, 0.813004f, 0.911304f, 0.984900f, 1.067894f,
     1.194601f, 1.369533f
 };
 
-void lt_prediction(ic_stream *ics, ltp_info *ltp, float *spec,
-                   float *lt_pred_stat, fb_info *fb, int win_shape,
-                   int win_shape_prev, int sr_index, int object_type)
+void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec,
+                   real_t *lt_pred_stat, fb_info *fb, uint8_t win_shape,
+                   uint8_t win_shape_prev, uint8_t sr_index, uint8_t object_type)
 {
-    int sfb, i, bin;
-    int num_samples;
-    float x_est[2*1024];
-    float X_est[2*1024];
+    uint8_t sfb;
+    uint16_t bin, i, num_samples;
+    real_t x_est[2*1024];
+    real_t X_est[2*1024];
 
     if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
     {
@@ -62,8 +63,8 @@
             {
                 if (ltp->long_used[sfb])
                 {
-                    int low  = ics->swb_offset[sfb];
-                    int high = ics->swb_offset[sfb+1];
+                    uint16_t low  = ics->swb_offset[sfb];
+                    uint16_t high = ics->swb_offset[sfb+1];
 
                     for (bin = low; bin < high; bin++)
                     {
@@ -75,11 +76,11 @@
     }
 }
 
-void lt_update_state(float *lt_pred_stat, float *time, float *overlap)
+void lt_update_state(real_t *lt_pred_stat, real_t *time, real_t *overlap)
 {
-    int i;
+    uint16_t i;
 
-    for(i = 0; i < 1024; i++)
+    for (i = 0; i < 1024; i++)
     {
         lt_pred_stat[i]          = lt_pred_stat[i + 1024];
         lt_pred_stat[1024 + i]   = time[i];
--- a/libfaad/lt_predict.h
+++ b/libfaad/lt_predict.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: lt_predict.h,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: lt_predict.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __LT_PREDICT_H__
@@ -28,10 +28,19 @@
 
 #include "filtbank.h"
 
-void lt_prediction(ic_stream *ics, ltp_info *ltp, float *spec,
-                   float *lt_pred_stat, fb_info *fb, int win_shape,
-                   int win_shape_prev, int sr_index, int object_type);
-void lt_update_state(float *lt_pred_stat, float *time, float *overlap);
+void lt_prediction(ic_stream *ics,
+                   ltp_info *ltp,
+                   real_t *spec,
+                   real_t *lt_pred_stat,
+                   fb_info *fb,
+                   uint8_t win_shape,
+                   uint8_t win_shape_prev,
+                   uint8_t sr_index,
+                   uint8_t object_type);
+
+void lt_update_state(real_t *lt_pred_stat,
+                     real_t *time,
+                     real_t *overlap);
 
 #ifdef __cplusplus
 }
--- a/libfaad/mdct.c
+++ b/libfaad/mdct.c
@@ -16,10 +16,12 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: mdct.c,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: mdct.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
-#ifdef __ICL
+#include "common.h"
+
+#ifdef USE_FMATH
 #include <mathf.h>
 #else
 #include <math.h>
@@ -26,27 +28,20 @@
 #endif
 #include "mdct.h"
 
-#ifndef M_PI /* PI */
-#define M_PI 3.14159265358979323846
-#endif
 
-#ifndef M_PI_2 /* PI/2 */
-#define M_PI_2 1.57079632679489661923
-#endif
-
-void MDCT_long(fftw_real *in_data, fftw_real *out_data, short *unscrambled)
+void MDCT_long(fftw_real *in_data, fftw_real *out_data, uint16_t *unscrambled)
 {
     fftw_complex FFTarray[512];
     fftw_real tempr, tempi, c, s, cold, cfreq, sfreq;
     fftw_real fac,cosfreq8,sinfreq8;
-    int i;
-    int b = 2048 >> 1;
-    int N4 = 2048 >> 2;
-    int N2 = 2048 >> 1;
-    int a = 2048 - b;
-    int a2 = a >> 1;
-    int a4 = a >> 2;
-    int b4 = b >> 2;
+    uint16_t i;
+    uint16_t b = 2048 >> 1;
+    uint16_t N4 = 2048 >> 2;
+    uint16_t N2 = 2048 >> 1;
+    uint16_t a = 2048 - b;
+    uint16_t a2 = a >> 1;
+    uint16_t a4 = a >> 2;
+    uint16_t b4 = b >> 2;
 
 
     fac = 2.; /* 2 from MDCT inverse  to forward */
@@ -62,7 +57,7 @@
 
     for (i = 0; i < N4; i++)
     {
-        int n = 2048 / 2 - 1 - 2 * i;
+        uint16_t n = 2048 / 2 - 1 - 2 * i;
         if (i < b4)
             tempr = in_data[a2 + n] + in_data[2048 + a2 - 1 - n];
         else
@@ -96,7 +91,7 @@
     for (i = 0; i < N4; i++)
     {
         /* get post-twiddled FFT output  */
-        int unscr = unscrambled[i];
+        uint16_t unscr = unscrambled[i];
 
         tempr = fac * (FFTarray[unscr].re * c + FFTarray[unscr].im * s);
         tempi = fac * (FFTarray[unscr].im * c - FFTarray[unscr].re * s);
@@ -114,19 +109,19 @@
     }
 }
 
-void MDCT_short(fftw_real *in_data, fftw_real *out_data, short *unscrambled)
+void MDCT_short(fftw_real *in_data, fftw_real *out_data, uint16_t *unscrambled)
 {
     fftw_complex FFTarray[64];    /* the array for in-place FFT */
     fftw_real tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
     fftw_real fac,cosfreq8,sinfreq8;
-    int i;
-    int b = 256 >> 1;
-    int N4 = 256 >> 2;
-    int N2 = 256 >> 1;
-    int a = 256 - b;
-    int a2 = a >> 1;
-    int a4 = a >> 2;
-    int b4 = b >> 2;
+    uint16_t i;
+    uint16_t b = 256 >> 1;
+    uint16_t N4 = 256 >> 2;
+    uint16_t N2 = 256 >> 1;
+    uint16_t a = 256 - b;
+    uint16_t a2 = a >> 1;
+    uint16_t a4 = a >> 2;
+    uint16_t b4 = b >> 2;
 
 
     /* Choosing to allocate 2/N factor to Inverse Xform! */
@@ -143,7 +138,7 @@
 
     for (i = 0; i < N4; i++)
     {
-        int n = 256 / 2 - 1 - 2 * i;
+        uint16_t n = 256 / 2 - 1 - 2 * i;
         if (i < b4)
             tempr = in_data[a2 + n] + in_data[256 + a2 - 1 - n];
         else
@@ -175,7 +170,7 @@
     /* post-twiddle FFT output and then get output data */
     for (i = 0; i < N4; i++)
     {
-        int unscr = unscrambled[i];
+        uint16_t unscr = unscrambled[i];
 
         tempr = fac * (FFTarray[unscr].re * c + FFTarray[unscr].im * s);
         tempi = fac * (FFTarray[unscr].im * c - FFTarray[unscr].re * s);
@@ -193,16 +188,16 @@
     }
 }
 
-void IMDCT_long(fftw_real *in_data, fftw_real *out_data, short *unscrambled)
+void IMDCT_long(fftw_real *in_data, fftw_real *out_data, uint16_t *unscrambled)
 {
     fftw_complex FFTarray[512];    /* the array for in-place FFT */
     fftw_real tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
 
     fftw_real fac, cosfreq8, sinfreq8;
-    int i;
-    int Nd2 = 2048 >> 1;
-    int Nd4 = 2048 >> 2;
-    int Nd8 = 2048 >> 3;
+    uint16_t i;
+    uint16_t Nd2 = 2048 >> 1;
+    uint16_t Nd4 = 2048 >> 2;
+    uint16_t Nd8 = 2048 >> 3;
 
     /* Choosing to allocate 2/N factor to Inverse Xform! */
     fac = 0.0009765625f;
@@ -218,7 +213,7 @@
 
     for (i = 0; i < Nd4; i++)
     {
-        int unscr = unscrambled[i];
+        uint16_t unscr = unscrambled[i];
 
         tempr = -in_data[2 * i];
         tempi =  in_data[Nd2 - 1 - 2 * i];
@@ -267,15 +262,15 @@
     }
 }
 
-void IMDCT_short(fftw_real *in_data, fftw_real *out_data, short *unscrambled)
+void IMDCT_short(fftw_real *in_data, fftw_real *out_data, uint16_t *unscrambled)
 {
     fftw_complex FFTarray[64];    /* the array for in-place FFT */
     fftw_real tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
     fftw_real fac, cosfreq8, sinfreq8;
-    int i;
-    int Nd2 = 256 >> 1;
-    int Nd4 = 256 >> 2;
-    int Nd8 = 256 >> 3;
+    uint16_t i;
+    uint16_t Nd2 = 256 >> 1;
+    uint16_t Nd4 = 256 >> 2;
+    uint16_t Nd8 = 256 >> 3;
 
     /* Choosing to allocate 2/N factor to Inverse Xform! */
     fac = 0.0078125f; /* remaining 2/N from 4/N IFFT factor */
@@ -291,7 +286,7 @@
 
     for (i = 0; i < Nd4; i++)
     {
-        int unscr = unscrambled[i];
+        uint16_t unscr = unscrambled[i];
 
         tempr = -in_data[2 * i];
         tempi = in_data[Nd2 - 1 - 2 * i];
@@ -2952,8 +2947,8 @@
      PFFTWI(twiddle_4)(input, PFFTW(W_512), 128);
 }
 
-void  PFFTW(twiddle_4) (fftw_complex * A, const fftw_complex * W, int iostride) {
-     int i;
+void  PFFTW(twiddle_4) (fftw_complex * A, const fftw_complex * W, uint16_t iostride) {
+     uint16_t i;
      fftw_complex *inout;
      inout = A;
      {
@@ -3065,8 +3060,8 @@
      } while (i > 0);
 }
 
-void PFFTWI(twiddle_4) (fftw_complex * A, const fftw_complex * W, int iostride) {
-     int i;
+void PFFTWI(twiddle_4) (fftw_complex * A, const fftw_complex * W, uint16_t iostride) {
+     uint16_t i;
      fftw_complex *inout;
      inout = A;
      {
@@ -3182,10 +3177,10 @@
      } while (i > 0);
 }
 
-int PFFTW(permutation_64)(int i)
+uint16_t PFFTW(permutation_64)(uint16_t i)
 {
-    int i1 = i % 4;
-    int i2 = i / 4;
+    uint16_t i1 = i % 4;
+    uint16_t i2 = i / 4;
     if (i1 <= 2)
        return (i1 * 16 + i2);
     else
@@ -3192,10 +3187,10 @@
        return (i1 * 16 + ((i2 + 1) % 16));
 }
 
-int PFFTW(permutation_128)(int i)
+uint16_t PFFTW(permutation_128)(uint16_t i)
 {
-    int i1 = i % 4;
-    int i2 = i / 4;
+    uint16_t i1 = i % 4;
+    uint16_t i2 = i / 4;
     if (i1 <= 2)
        return (i1 * 32 + i2);
     else
@@ -3202,10 +3197,10 @@
        return (i1 * 32 + ((i2 + 1) % 32));
 }
 
-int PFFTW(permutation_512)(int i)
+uint16_t PFFTW(permutation_512)(uint16_t i)
 {
-    int i1 = i % 4;
-    int i2 = i / 4;
+    uint16_t i1 = i % 4;
+    uint16_t i2 = i / 4;
     if (i1 <= 2)
        return (i1 * 128 + PFFTW(permutation_128)(i2));
     else
@@ -3212,9 +3207,9 @@
        return (i1 * 128 + PFFTW(permutation_128)((i2 + 1) % 128));
 }
 
-void make_fft_order(short *unscrambled64, short *unscrambled512)
+void make_fft_order(uint16_t *unscrambled64, uint16_t *unscrambled512)
 {
-    int i;
+    uint16_t i;
 
     for (i = 0; i < 64; i++)
         unscrambled64[i] = PFFTW(permutation_64)(i);
--- a/libfaad/mdct.h
+++ b/libfaad/mdct.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: mdct.h,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: mdct.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __MDCT_H__
@@ -26,7 +26,7 @@
 extern "C" {
 #endif
 
-typedef float fftw_real;
+typedef real_t fftw_real;
 
 typedef struct {
      fftw_real re, im;
@@ -38,7 +38,7 @@
 #define DEFINE_PFFTW(size)          \
  void pfftwi_##size(fftw_complex *input);   \
  void pfftw_##size(fftw_complex *input);    \
- int  pfftw_permutation_##size(int i);
+ uint16_t pfftw_permutation_##size(uint16_t i);
 
 DEFINE_PFFTW(16)
 DEFINE_PFFTW(32)
@@ -46,12 +46,12 @@
 DEFINE_PFFTW(128)
 DEFINE_PFFTW(512)
 
-void make_fft_order(short *unscrambled64, short *unscrambled512);
-void IMDCT_long(fftw_real *in_data, fftw_real *out_data, short *unscrambled);
-void IMDCT_short(fftw_real *in_data, fftw_real *out_data, short *unscrambled);
+void make_fft_order(uint16_t *unscrambled64, uint16_t *unscrambled512);
+void IMDCT_long(fftw_real *in_data, fftw_real *out_data, uint16_t *unscrambled);
+void IMDCT_short(fftw_real *in_data, fftw_real *out_data, uint16_t *unscrambled);
 
-void MDCT_long(fftw_real *in_data, fftw_real *out_data, short *unscrambled);
-void MDCT_short(fftw_real *in_data, fftw_real *out_data, short *unscrambled);
+void MDCT_long(fftw_real *in_data, fftw_real *out_data, uint16_t *unscrambled);
+void MDCT_short(fftw_real *in_data, fftw_real *out_data, uint16_t *unscrambled);
 
 #define PFFTW(name)  CONCAT(pfftw_, name)
 #define PFFTWI(name)  CONCAT(pfftwi_, name)
@@ -59,8 +59,8 @@
 #define CONCAT(a, b) CONCAT_AUX(a,b)
 #define FFTW_KONST(x) ((fftw_real) x)
 
-void PFFTW(twiddle_4)(fftw_complex *A, const fftw_complex *W, int iostride);
-void PFFTWI(twiddle_4)(fftw_complex *A, const fftw_complex *W, int iostride);
+void PFFTW(twiddle_4)(fftw_complex *A, const fftw_complex *W, uint16_t iostride);
+void PFFTWI(twiddle_4)(fftw_complex *A, const fftw_complex *W, uint16_t iostride);
 
 #ifdef __cplusplus
 }
--- a/libfaad/mp4.c
+++ b/libfaad/mp4.c
@@ -16,9 +16,10 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: mp4.c,v 1.1 2002/01/20 16:57:55 menno Exp $
+** $Id: mp4.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "common.h"
 #include "bits.h"
 #include "mp4.h"
 #include "data.h"
@@ -25,7 +26,7 @@
 #include "syntax.h"
 
 /* defines if an object type can be decoded by this library or not */
-static unsigned long ObjectTypesTable[32] = {
+static uint8_t ObjectTypesTable[32] = {
     0, /* NULL */
     1, /* AAC Main */
     1, /* AAC LC */
@@ -46,26 +47,25 @@
 };
 
 /* Table 1.6.1 */
-int FAADAPI AudioSpecificConfig(unsigned char *pBuffer,
-                                unsigned long *samplerate,
-                                unsigned long *channels,
-                                unsigned long *sf_index,
-                                unsigned long *object_type)
+int8_t FAADAPI AudioSpecificConfig(uint8_t *pBuffer,
+                                uint32_t *samplerate,
+                                uint8_t *channels,
+                                uint8_t *sf_index,
+                                uint8_t *object_type)
 {
     bitfile ld;
-    unsigned long ObjectTypeIndex, SamplingFrequencyIndex,
-        ChannelsConfiguration;
+    uint8_t ObjectTypeIndex, SamplingFrequencyIndex, ChannelsConfiguration;
 
     faad_initbits(&ld, pBuffer);
     faad_byte_align(&ld);
 
-    ObjectTypeIndex = faad_getbits(&ld, 5
+    ObjectTypeIndex = (uint8_t)faad_getbits(&ld, 5
         DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
 
-    SamplingFrequencyIndex = faad_getbits(&ld, 4
+    SamplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4
         DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex"));
 
-    ChannelsConfiguration = faad_getbits(&ld, 4
+    ChannelsConfiguration = (uint8_t)faad_getbits(&ld, 4
         DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration"));
 
     *samplerate = sample_rates[SamplingFrequencyIndex];
--- a/libfaad/mp4.h
+++ b/libfaad/mp4.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: mp4.h,v 1.1 2002/01/20 16:57:55 menno Exp $
+** $Id: mp4.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __MP4_H__
@@ -28,11 +28,11 @@
 
 #include "decoder.h"
 
-int FAADAPI AudioSpecificConfig(unsigned char *pBuffer,
-                                unsigned long *samplerate,
-                                unsigned long *channels,
-                                unsigned long *sf_index,
-                                unsigned long *object_type);
+int8_t FAADAPI AudioSpecificConfig(uint8_t *pBuffer,
+                                uint32_t *samplerate,
+                                uint8_t *channels,
+                                uint8_t *sf_index,
+                                uint8_t *object_type);
 
 #ifdef __cplusplus
 }
--- a/libfaad/ms.c
+++ b/libfaad/ms.c
@@ -16,21 +16,22 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: ms.c,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: ms.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "common.h"
 #include "syntax.h"
 #include "ms.h"
 #include "is.h"
 #include "pns.h"
 
-void ms_decode(ic_stream *ics, ic_stream *icsr, float *l_spec, float *r_spec)
+void ms_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec)
 {
-    int g, b, sfb, i;
-    int group = 0;
+    uint8_t g, b, sfb;
+    uint8_t group = 0;
 
-    int k;
-    float tmp;
+    uint16_t i, k;
+    real_t tmp;
 
     if (ics->ms_mask_present >= 1)
     {
--- a/libfaad/ms.h
+++ b/libfaad/ms.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: ms.h,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: ms.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __MS_H__
@@ -26,7 +26,7 @@
 extern "C" {
 #endif
 
-void ms_decode(ic_stream *ics, ic_stream *icsr, float *l_spec, float *r_spec);
+void ms_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec);
 
 #ifdef __cplusplus
 }
--- a/libfaad/output.c
+++ b/libfaad/output.c
@@ -16,10 +16,12 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: output.c,v 1.2 2002/01/25 20:15:07 menno Exp $
+** $Id: output.c,v 1.3 2002/02/18 10:01:05 menno Exp $
 **/
 
-#ifdef __ICL
+#include "common.h"
+
+#ifdef USE_FMATH
 #include <mathf.h>
 #else
 #include <math.h>
@@ -27,17 +29,18 @@
 #include "output.h"
 #include "decoder.h"
 
-#define ftol(A,B) {tmp = *(int*) & A - 0x4B7F8000; \
-                   B = (short)((tmp==(short)tmp) ? tmp : (tmp>>31)^0x7FFF);}
-#ifdef __ICL
-#define ROUND(x) ((long)floorf((x) + 0.5f))
+
+#define ftol(A,B) {tmp = *(int32_t*) & A - 0x4B7F8000; \
+                   B = (int16_t)((tmp==(int16_t)tmp) ? tmp : (tmp>>31)^0x7FFF);}
+#ifdef USE_FMATH
+#define ROUND(x) ((int32_t)floorf((x) + 0.5f))
 #else
-#define ROUND(x) ((long)floor((x) + 0.5))
+#define ROUND(x) ((int32_t)floor((x) + 0.5))
 #endif
 
 #define HAVE_IEEE754_FLOAT
 #ifdef HAVE_IEEE754_FLOAT
-#define ROUND32(x) (floattmp = (x) + (long)0x00FD8000L, *(long*)(&floattmp) - (long)0x4B7D8000L)
+#define ROUND32(x) (floattmp = (x) + (int32_t)0x00FD8000L, *(int32_t*)(&floattmp) - (int32_t)0x4B7D8000L)
 #else
 #define ROUND32(x) ROUND(x)
 #endif
@@ -45,14 +48,15 @@
 #define FLOAT_SCALE (1.0f/(1<<15))
 
 
-void* output_to_PCM(float **input, void *sample_buffer, int channels,
-                    int format)
+void* output_to_PCM(real_t **input, void *sample_buffer, uint8_t channels,
+                    uint8_t format)
 {
-    int ch, i;
+    uint8_t ch;
+    uint16_t i;
 
-    short *short_sample_buffer = (short*)sample_buffer;
-    int   *int_sample_buffer = (int*)sample_buffer;
-    float *float_sample_buffer = (float*)sample_buffer;
+    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
+    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
+    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
 
     /* Copy output to a standard PCM buffer */
     switch (format)
@@ -62,8 +66,8 @@
         {
             for(i = 0; i < 1024; i++)
             {
-                int tmp;
-                float ftemp;
+                int32_t tmp;
+                real_t ftemp;
 
                 ftemp = input[ch][i] + 0xff8000;
                 ftol(ftemp, short_sample_buffer[(i*channels)+ch]);
@@ -82,7 +86,7 @@
     case FAAD_FMT_32BIT:
         for (ch = 0; ch < channels; ch++)
         {
-            float floattmp;
+            real_t floattmp;
 
             for(i = 0; i < 1024; i++)
             {
--- a/libfaad/output.h
+++ b/libfaad/output.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: output.h,v 1.1 2002/01/14 19:15:56 menno Exp $
+** $Id: output.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __OUTPUT_H__
@@ -26,8 +26,10 @@
 extern "C" {
 #endif
 
-void* output_to_PCM(float **input, void *samplebuffer, int channels,
-                    int format);
+void* output_to_PCM(real_t **input,
+                    void *samplebuffer,
+                    uint8_t channels,
+                    uint8_t format);
 
 
 #ifdef __cplusplus
--- a/libfaad/pns.c
+++ b/libfaad/pns.c
@@ -16,10 +16,12 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: pns.c,v 1.2 2002/01/25 20:15:07 menno Exp $
+** $Id: pns.c,v 1.3 2002/02/18 10:01:05 menno Exp $
 **/
 
-#ifdef __ICL
+#include "common.h"
+
+#ifdef USE_FMATH
 #include <mathf.h>
 #else
 #include <math.h>
@@ -44,9 +46,9 @@
 
 
 
-static __inline long random2()
+static INLINE int32_t random2()
 {
-    static long state = 1;
+    static int32_t state = 1;
 
     state = (1664525L * state) + 1013904223L;  /* Numerical recipes */
 
@@ -58,25 +60,25 @@
    value. A suitable random number generator can be realized using one
    multiplication/accumulation per random value.
 */
-static __inline void gen_rand_vector(float *spec, int scale_factor, int size)
+static INLINE void gen_rand_vector(real_t *spec, uint16_t scale_factor, uint16_t size)
 {
-    int i;
-    float scale;
+    uint16_t i;
+    real_t scale;
 
     for (i = 0; i < size; i++)
     {
-        spec[i] = (float)random2();
+        spec[i] = (real_t)random2();
     }
 
     /* 14496-3 says:
-       scale = 1.0f/(size * (float)sqrt(MEAN_NRG));
+       scale = 1.0f/(size * (real_t)sqrt(MEAN_NRG));
     */
-#ifdef __ICL
+#ifdef USE_FMATH
     scale = 1.0f/sqrtf(size * MEAN_NRG);
     scale *= powf(2.0f, 0.25f*scale_factor);
 #else
-    scale = 1.0f/(float)sqrt(size * MEAN_NRG);
-    scale *= (float)pow(2.0, 0.25*scale_factor);
+    scale = 1.0f/(real_t)sqrt(size * MEAN_NRG);
+    scale *= (real_t)pow(2.0, 0.25*scale_factor);
 #endif
 
     /* Scale random vector to desired target energy */
@@ -84,12 +86,12 @@
         spec[i] *= scale;
 }
 
-void pns_decode(ic_stream *ics, float *spec)
+void pns_decode(ic_stream *ics, real_t *spec)
 {
-    int g, sfb, b, i;
-    int size, offs;
+    uint8_t g, sfb, b;
+    uint16_t size, offs;
 
-    int group = 0;
+    uint8_t group = 0;
 
     for (g = 0; g < ics->num_window_groups; g++)
     {
--- a/libfaad/pns.h
+++ b/libfaad/pns.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: pns.h,v 1.3 2002/01/25 20:15:07 menno Exp $
+** $Id: pns.h,v 1.4 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __PNS_H__
@@ -27,17 +27,18 @@
 #endif
 
 #include "syntax.h"
+#include "common.h"
 
 #define NOISE_OFFSET 90
 #define MEAN_NRG 1.537228e+18 /* (2^31)^2 / 3 */
 
 
-void pns_decode(ic_stream *ics, float *spec);
+void pns_decode(ic_stream *ics, real_t *spec);
 
-static __inline long random2();
-static void gen_rand_vector(float *spec, int scale_factor, int size);
+static INLINE int32_t random2();
+static void gen_rand_vector(real_t *spec, uint16_t scale_factor, uint16_t size);
 
-static __inline int is_noise(ic_stream *ics, int group, int sfb)
+static INLINE uint8_t is_noise(ic_stream *ics, uint8_t group, uint8_t sfb)
 {
     if (ics->sfb_cb[group][sfb] == NOISE_HCB)
         return 1;
--- a/libfaad/pulse.c
+++ b/libfaad/pulse.c
@@ -16,16 +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: pulse.c,v 1.1 2002/01/14 19:15:57 menno Exp $
+** $Id: pulse.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
+#include "common.h"
 #include "syntax.h"
 #include "pulse.h"
 
-void pulse_decode(ic_stream *ics, short *spec_data)
+void pulse_decode(ic_stream *ics, int16_t *spec_data)
 {
-    int i, k;
-    pulse_info *pul = &ics->pul;
+    uint8_t i;
+    uint16_t k;
+    pulse_info *pul = &(ics->pul);
 
     k = ics->swb_offset[pul->pulse_start_sfb];
 
--- a/libfaad/pulse.h
+++ b/libfaad/pulse.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: pulse.h,v 1.1 2002/01/14 19:15:57 menno Exp $
+** $Id: pulse.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __PULSE_H__
@@ -26,7 +26,7 @@
 extern "C" {
 #endif
 
-void pulse_decode(ic_stream *ics, short *spec_coef);
+void pulse_decode(ic_stream *ics, int16_t *spec_coef);
 
 #ifdef __cplusplus
 }
--- a/libfaad/specrec.c
+++ b/libfaad/specrec.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: specrec.c,v 1.2 2002/02/11 11:34:18 menno Exp $
+** $Id: specrec.c,v 1.3 2002/02/18 10:01:05 menno Exp $
 **/
 
 /*
@@ -26,7 +26,9 @@
    - applying scalefactors
 */
 
-#ifdef __ICL
+#include "common.h"
+
+#ifdef USE_FMATH
 #include <mathf.h>
 #else
 #include <math.h>
@@ -51,9 +53,9 @@
     in section named section. This offset depends on window_sequence and
     scale_factor_grouping and is needed to decode the spectral_data().
 */
-int window_grouping_info(ic_stream *ics, int fs_index)
+uint8_t window_grouping_info(ic_stream *ics, uint8_t fs_index)
 {
-    int i, g;
+    uint8_t i, g;
 
     switch (ics->window_sequence) {
     case ONLY_LONG_SEQUENCE:
@@ -94,9 +96,10 @@
         /* preparation of sect_sfb_offset for short blocks */
         for (g = 0; g < ics->num_window_groups; g++)
         {
-            int width;
-            int sect_sfb = 0;
-            int offset = 0;
+            uint16_t width;
+            uint8_t sect_sfb = 0;
+            uint16_t offset = 0;
+
             for (i = 0; i < ics->num_swb; i++)
             {
                 width = swb_offset_short_window[fs_index][i+1] -
@@ -133,16 +136,18 @@
   - Within a scalefactor window band, the coefficients are in ascending
     spectral order.
 */
-void quant_to_spec(ic_stream *ics, float *spec_data)
+void quant_to_spec(ic_stream *ics, real_t *spec_data)
 {
-    int g, width, sfb, win, bin;
-    float *start_inptr, *start_win_ptr, *win_ptr;
+    int8_t i;
+    uint8_t g, sfb, win;
+    uint16_t width, bin;
+    real_t *start_inptr, *start_win_ptr, *win_ptr;
 
-    float tmp_spec[1024];
-    float *tmp_spec_ptr, *spec_ptr;
+    real_t tmp_spec[1024];
+    real_t *tmp_spec_ptr, *spec_ptr;
 
     tmp_spec_ptr = tmp_spec;
-    for (g = 1024/16-1; g >= 0; --g)
+    for (i = 1024/16-1; i >= 0; --i)
     {
         *tmp_spec_ptr++ = 0; *tmp_spec_ptr++ = 0;
         *tmp_spec_ptr++ = 0; *tmp_spec_ptr++ = 0;
@@ -160,8 +165,8 @@
 
     for (g = 0; g < ics->num_window_groups; g++)
     {
-        int j = 0;
-        int win_inc = 0;
+        uint16_t j = 0;
+        uint16_t win_inc = 0;
 
         start_inptr = spec_ptr;
 
@@ -195,7 +200,7 @@
     spec_ptr = spec_data;
     tmp_spec_ptr = tmp_spec;
 
-    for (g = 1024/16 - 1; g >= 0; --g)
+    for (i = 1024/16 - 1; i >= 0; --i)
     {
         *spec_ptr++ = *tmp_spec_ptr++; *spec_ptr++ = *tmp_spec_ptr++;
         *spec_ptr++ = *tmp_spec_ptr++; *spec_ptr++ = *tmp_spec_ptr++;
@@ -208,17 +213,17 @@
     }
 }
 
-void build_tables(float *iq_table, float *pow2_table)
+void build_tables(real_t *iq_table, real_t *pow2_table)
 {
-    int i;
+    uint16_t i;
 
     /* build pow() table for inverse quantization */
     for(i = 0; i < IQ_TABLE_SIZE; i++)
     {
-#ifdef __ICL
+#ifdef USE_FMATH
         iq_table[i] = powf(i, 4.0f/3.0f);
 #else
-        iq_table[i] = (float)pow(i, 4.0/3.0);
+        iq_table[i] = (real_t)pow(i, 4.0/3.0);
 #endif
     }
 
@@ -225,69 +230,82 @@
     /* build pow(2, 0.25) table for scalefactors */
     for(i = 0; i < POW_TABLE_SIZE; i++)
     {
-#ifdef __ICL
+#ifdef USE_FMATH
         pow2_table[i] = powf(2.0f, 0.25f * (i-100));
 #else
-        pow2_table[i] = (float)pow(2.0, 0.25 * (i-100));
+        pow2_table[i] = (real_t)pow(2.0, 0.25 * (i-100));
 #endif
     }
 }
 
-void inverse_quantization(float *x_invquant, short *x_quant, float *iq_table)
+static INLINE real_t iquant(int16_t q, real_t *iq_table)
 {
-    int i;
-
-    for(i = 0; i < 1024; i++)
+    if (q > 0)
     {
-        short q = x_quant[i];
-
-        if (q > 0)
-        {
-            if (q < IQ_TABLE_SIZE)
-                x_invquant[i] = iq_table[q];
-            else
-#ifdef __ICL
-                x_invquant[i] = powf(q, 4.0f/3.0f);
+        if (q < IQ_TABLE_SIZE)
+            return iq_table[q];
+        else
+#ifdef USE_FMATH
+            return powf(q, 4.0f/3.0f);
 #else
-                x_invquant[i] = (float)pow(q, 4.0/3.0);
+            return (real_t)pow(q, 4.0/3.0);
 #endif
-        } else if (q < 0) {
-            q = -q;
-            if (q < IQ_TABLE_SIZE)
-                x_invquant[i] = -iq_table[q];
-            else
-#ifdef __ICL
-                x_invquant[i] = -powf(q, 4.0f/3.0f);
+    } else if (q < 0) {
+        q = -q;
+        if (q < IQ_TABLE_SIZE)
+            return -iq_table[q];
+        else
+#ifdef USE_FMATH
+            return -powf(q, 4.0f/3.0f);
 #else
-                x_invquant[i] = -(float)pow(q, 4.0/3.0);
+            return -(real_t)pow(q, 4.0/3.0);
 #endif
-        } else {
-            x_invquant[i] = 0.0f;
-        }
+    } else {
+        return 0.0f;
     }
 }
 
-static __inline float get_scale_factor_gain(int scale_factor, float *pow2_table)
+void inverse_quantization(real_t *x_invquant, int16_t *x_quant, real_t *iq_table)
 {
-    if ((scale_factor >= 0) && (scale_factor < POW_TABLE_SIZE))
+    int8_t i;
+    int16_t *in_ptr = x_quant;
+    real_t *out_ptr = x_invquant;
+
+    for(i = 1024/8-1; i >= 0; --i)
+    {
+        *out_ptr++ = iquant(*in_ptr++, iq_table);
+        *out_ptr++ = iquant(*in_ptr++, iq_table);
+        *out_ptr++ = iquant(*in_ptr++, iq_table);
+        *out_ptr++ = iquant(*in_ptr++, iq_table);
+        *out_ptr++ = iquant(*in_ptr++, iq_table);
+        *out_ptr++ = iquant(*in_ptr++, iq_table);
+        *out_ptr++ = iquant(*in_ptr++, iq_table);
+        *out_ptr++ = iquant(*in_ptr++, iq_table);
+    }
+}
+
+static INLINE real_t get_scale_factor_gain(uint16_t scale_factor, real_t *pow2_table)
+{
+    if (scale_factor < POW_TABLE_SIZE)
         return pow2_table[scale_factor];
     else
-#ifdef __ICL
+#ifdef USE_FMATH
         return powf(2.0f, 0.25f * (scale_factor - 100));
 #else
-        return (float)pow(2.0, 0.25 * (scale_factor - 100));
+        return (real_t)pow(2.0, 0.25 * (scale_factor - 100));
 #endif
 }
 
-void apply_scalefactors(ic_stream *ics, float *x_invquant, float *pow2_table)
+void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table)
 {
-    int g, sfb, top;
-    float *fp, scale;
-    int groups = 0;
+    uint8_t g, sfb;
+    uint16_t top;
+    real_t *fp, scale;
+    uint8_t groups = 0;
 
     for (g = 0; g < ics->num_window_groups; g++)
     {
-        int k = 0;
+        uint16_t k = 0;
 
         /* using this 128*groups doesn't hurt long blocks, because
            long blocks only have 1 group, so that means 'groups' is
--- a/libfaad/specrec.h
+++ b/libfaad/specrec.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: specrec.h,v 1.1 2002/01/14 19:15:57 menno Exp $
+** $Id: specrec.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __SPECREC_H__
@@ -32,11 +32,11 @@
 #define POW_TABLE_SIZE  200
 
 
-int window_grouping_info(ic_stream *ics, int fs_index);
-void quant_to_spec(ic_stream *ics, float *spec_data);
-void build_tables(float *iq_table, float *pow2_table);
-void inverse_quantization(float *x_invquant, short *x_quant, float *iq_table);
-void apply_scalefactors(ic_stream *ics, float *x_invquant, float *pow2_table);
+uint8_t window_grouping_info(ic_stream *ics, uint8_t fs_index);
+void quant_to_spec(ic_stream *ics, real_t *spec_data);
+void build_tables(real_t *iq_table, real_t *pow2_table);
+void inverse_quantization(real_t *x_invquant, int16_t *x_quant, real_t *iq_table);
+void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table);
 
 
 #ifdef __cplusplus
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.c,v 1.6 2002/02/11 11:34:18 menno Exp $
+** $Id: syntax.c,v 1.7 2002/02/18 10:01:05 menno Exp $
 **/
 
 /*
@@ -29,6 +29,7 @@
 
 #include <stdlib.h>
 #include <memory.h>
+#include "common.h"
 #include "syntax.h"
 #include "specrec.h"
 #include "huffman.h"
@@ -39,10 +40,10 @@
 
 
 /* Table 4.4.1 */
-int GASpecificConfig(bitfile *ld, unsigned long *channelConfiguration)
+uint8_t GASpecificConfig(bitfile *ld, uint8_t *channelConfiguration)
 {
-    int frameLengthFlag, dependsOnCoreCoder, coreCoderDelay;
-    int extensionFlag;
+    uint8_t frameLengthFlag, dependsOnCoreCoder, extensionFlag;
+    uint16_t coreCoderDelay;
     program_config pce;
 
     /* 1024 or 960 */
@@ -53,7 +54,7 @@
         DEBUGVAR(1,139,"GASpecificConfig(): DependsOnCoreCoder"));
     if (dependsOnCoreCoder == 1)
     {
-        coreCoderDelay = faad_getbits(ld, 14
+        coreCoderDelay = (uint16_t)faad_getbits(ld, 14
             DEBUGVAR(1,140,"GASpecificConfig(): CoreCoderDelay"));
     }
 
@@ -82,30 +83,30 @@
    PCEs transmitted in raw data blocks cannot be used to convey decoder
    configuration information.
 */
-int program_config_element(program_config *pce, bitfile *ld)
+uint8_t program_config_element(program_config *pce, bitfile *ld)
 {
-    int i;
+    uint8_t i;
 
     pce->channels = 0;
 
-    pce->element_instance_tag = faad_getbits(ld, 4
+    pce->element_instance_tag = (uint8_t)faad_getbits(ld, 4
         DEBUGVAR(1,10,"program_config_element(): element_instance_tag"));
 
-    pce->object_type = faad_getbits(ld, 2
+    pce->object_type = (uint8_t)faad_getbits(ld, 2
         DEBUGVAR(1,11,"program_config_element(): object_type"));
-    pce->sf_index = faad_getbits(ld, 4
+    pce->sf_index = (uint8_t)faad_getbits(ld, 4
         DEBUGVAR(1,12,"program_config_element(): sf_index"));
-    pce->num_front_channel_elements = faad_getbits(ld, 4
+    pce->num_front_channel_elements = (uint8_t)faad_getbits(ld, 4
         DEBUGVAR(1,13,"program_config_element(): num_front_channel_elements"));
-    pce->num_side_channel_elements = faad_getbits(ld, 4
+    pce->num_side_channel_elements = (uint8_t)faad_getbits(ld, 4
         DEBUGVAR(1,14,"program_config_element(): num_side_channel_elements"));
-    pce->num_back_channel_elements = faad_getbits(ld, 4
+    pce->num_back_channel_elements = (uint8_t)faad_getbits(ld, 4
         DEBUGVAR(1,15,"program_config_element(): num_back_channel_elements"));
-    pce->num_lfe_channel_elements = faad_getbits(ld, 2
+    pce->num_lfe_channel_elements = (uint8_t)faad_getbits(ld, 2
         DEBUGVAR(1,16,"program_config_element(): num_lfe_channel_elements"));
-    pce->num_assoc_data_elements = faad_getbits(ld, 3
+    pce->num_assoc_data_elements = (uint8_t)faad_getbits(ld, 3
         DEBUGVAR(1,17,"program_config_element(): num_assoc_data_elements"));
-    pce->num_valid_cc_elements = faad_getbits(ld, 4
+    pce->num_valid_cc_elements = (uint8_t)faad_getbits(ld, 4
         DEBUGVAR(1,18,"program_config_element(): num_valid_cc_elements"));
 
     pce->mono_mixdown_present = faad_get1bit(ld
@@ -112,7 +113,7 @@
         DEBUGVAR(1,19,"program_config_element(): mono_mixdown_present"));
     if (pce->mono_mixdown_present == 1)
     {
-        pce->mono_mixdown_element_number = faad_getbits(ld, 4
+        pce->mono_mixdown_element_number = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,20,"program_config_element(): mono_mixdown_element_number"));
     }
 
@@ -120,7 +121,7 @@
         DEBUGVAR(1,21,"program_config_element(): stereo_mixdown_present"));
     if (pce->stereo_mixdown_present == 1)
     {
-        pce->stereo_mixdown_element_number = faad_getbits(ld, 4
+        pce->stereo_mixdown_element_number = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,22,"program_config_element(): stereo_mixdown_element_number"));
     }
 
@@ -128,7 +129,7 @@
         DEBUGVAR(1,23,"program_config_element(): matrix_mixdown_idx_present"));
     if (pce->matrix_mixdown_idx_present == 1)
     {
-        pce->matrix_mixdown_idx = faad_getbits(ld, 2
+        pce->matrix_mixdown_idx = (uint8_t)faad_getbits(ld, 2
             DEBUGVAR(1,24,"program_config_element(): matrix_mixdown_idx"));
         pce->pseudo_surround_enable = faad_get1bit(ld
             DEBUGVAR(1,25,"program_config_element(): pseudo_surround_enable"));
@@ -143,7 +144,7 @@
         } else {
             pce->channels++;
         }
-        pce->front_element_tag_select[i] = faad_getbits(ld, 4
+        pce->front_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,27,"program_config_element(): front_element_tag_select"));
     }
 
@@ -156,7 +157,7 @@
         } else {
             pce->channels++;
         }
-        pce->side_element_tag_select[i] = faad_getbits(ld, 4
+        pce->side_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,29,"program_config_element(): side_element_tag_select"));
     }
 
@@ -169,7 +170,7 @@
         } else {
             pce->channels++;
         }
-        pce->back_element_tag_select[i] = faad_getbits(ld, 4
+        pce->back_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,31,"program_config_element(): back_element_tag_select"));
     }
 
@@ -176,12 +177,12 @@
     for (i = 0; i < pce->num_lfe_channel_elements; i++)
     {
         pce->channels++;
-        pce->lfe_element_tag_select[i] = faad_getbits(ld, 4
+        pce->lfe_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,32,"program_config_element(): lfe_element_tag_select"));
     }
 
     for (i = 0; i < pce->num_assoc_data_elements; i++)
-        pce->assoc_data_element_tag_select[i] = faad_getbits(ld, 4
+        pce->assoc_data_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
         DEBUGVAR(1,33,"program_config_element(): assoc_data_element_tag_select"));
 
     for (i = 0; i < pce->num_valid_cc_elements; i++)
@@ -191,18 +192,18 @@
 
         pce->cc_element_is_ind_sw[i] = faad_get1bit(ld
             DEBUGVAR(1,34,"program_config_element(): cc_element_is_ind_sw"));
-        pce->valid_cc_element_tag_select[i] = faad_getbits(ld, 4
+        pce->valid_cc_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,35,"program_config_element(): valid_cc_element_tag_select"));
     }
 
     faad_byte_align(ld);
 
-    pce->comment_field_bytes = faad_getbits(ld, 8
+    pce->comment_field_bytes = (uint8_t)faad_getbits(ld, 8
         DEBUGVAR(1,36,"program_config_element(): comment_field_bytes"));
-    i = 0;
+
     for (i = 0; i < pce->comment_field_bytes; i++)
     {
-        pce->comment_field_data[i] = faad_getbits(ld, 8
+        pce->comment_field_data[i] = (uint8_t)faad_getbits(ld, 8
             DEBUGVAR(1,37,"program_config_element(): comment_field_data"));
     }
     pce->comment_field_data[i] = 0;
@@ -212,12 +213,12 @@
 
 /* Table 4.4.4 and */
 /* Table 4.4.9 */
-int single_lfe_channel_element(element *sce, bitfile *ld, short *spec_data,
-                               int sf_index, int object_type)
+uint8_t single_lfe_channel_element(element *sce, bitfile *ld, int16_t *spec_data,
+                               uint8_t sf_index, uint8_t object_type)
 {
-    ic_stream *ics = &sce->ics1;
+    ic_stream *ics = &(sce->ics1);
 
-    sce->element_instance_tag = faad_getbits(ld, LEN_TAG
+    sce->element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
         DEBUGVAR(1,38,"single_lfe_channel_element(): element_instance_tag"));
 
     return individual_channel_stream(sce, ld, ics, 0, spec_data, sf_index,
@@ -225,15 +226,14 @@
 }
 
 /* Table 4.4.5 */
-int channel_pair_element(element *cpe, bitfile *ld, short *spec_data1,
-                         short *spec_data2, int sf_index, int object_type)
+uint8_t channel_pair_element(element *cpe, bitfile *ld, int16_t *spec_data1,
+                         int16_t *spec_data2, uint8_t sf_index, uint8_t object_type)
 {
-    int result;
+    uint8_t result;
+    ic_stream *ics1 = &(cpe->ics1);
+    ic_stream *ics2 = &(cpe->ics2);
 
-    ic_stream *ics1 = &cpe->ics1;
-    ic_stream *ics2 = &cpe->ics2;
-
-    cpe->element_instance_tag = faad_getbits(ld, LEN_TAG
+    cpe->element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
         DEBUGVAR(1,39,"channel_pair_element(): element_instance_tag"));
 
     if ((cpe->common_window = faad_get1bit(ld
@@ -244,11 +244,11 @@
             object_type)) > 0)
             return result;
 
-        ics1->ms_mask_present = faad_getbits(ld, 2
+        ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2
             DEBUGVAR(1,41,"channel_pair_element(): ms_mask_present"));
         if (ics1->ms_mask_present == 1)
         {
-            int g, sfb;
+            uint8_t g, sfb;
             for (g = 0; g < ics1->num_window_groups; g++)
             {
                 for (sfb = 0; sfb < ics1->max_sfb; sfb++)
@@ -275,12 +275,12 @@
 }
 
 /* Table 4.4.6 */
-static int ics_info(ic_stream *ics, bitfile *ld, int common_window,
-                    int sf_index, int object_type)
+static uint8_t ics_info(ic_stream *ics, bitfile *ld, uint8_t common_window,
+                    uint8_t sf_index, uint8_t object_type)
 {
     /* ics->ics_reserved_bit = */ faad_get1bit(ld
         DEBUGVAR(1,43,"ics_info(): ics_reserved_bit"));
-    ics->window_sequence = faad_getbits(ld, 2
+    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"));
@@ -287,12 +287,12 @@
 
     if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
     {
-        ics->max_sfb = faad_getbits(ld, 4
+        ics->max_sfb = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,46,"ics_info(): max_sfb (short)"));
-        ics->scale_factor_grouping = faad_getbits(ld, 7
+        ics->scale_factor_grouping = (uint8_t)faad_getbits(ld, 7
             DEBUGVAR(1,47,"ics_info(): scale_factor_grouping"));
     } else {
-        ics->max_sfb = faad_getbits(ld, 6
+        ics->max_sfb = (uint8_t)faad_getbits(ld, 6
             DEBUGVAR(1,48,"ics_info(): max_sfb (long)"));
 
         if (object_type == LTP)
@@ -303,7 +303,7 @@
                 if ((ics->ltp.data_present = faad_get1bit(ld
                     DEBUGVAR(1,50,"ics_info(): ltp.data_present"))) & 1)
                 {
-                    ltp_data(ics, &ics->ltp, ld);
+                    ltp_data(ics, &(ics->ltp), ld);
                 }
                 if (common_window)
                 {
@@ -310,7 +310,7 @@
                     if ((ics->ltp2.data_present = faad_get1bit(ld
                         DEBUGVAR(1,51,"ics_info(): ltp2.data_present"))) & 1)
                     {
-                        ltp_data(ics, &ics->ltp2, ld);
+                        ltp_data(ics, &(ics->ltp2), ld);
                     }
                 }
             }
@@ -318,13 +318,14 @@
             if ((ics->predictor_data_present = faad_get1bit(ld
                 DEBUGVAR(1,52,"ics_info(): predictor_data_present"))) & 1)
             {
-                int sfb;
+                uint8_t sfb;
+
                 ics->pred.limit = min(ics->max_sfb, pred_sfb_max[sf_index]);
 
                 if ((ics->pred.predictor_reset = faad_get1bit(ld
                     DEBUGVAR(1,53,"ics_info(): pred.predictor_reset"))) & 1)
                 {
-                    ics->pred.predictor_reset_group_number = faad_getbits(ld, 5
+                    ics->pred.predictor_reset_group_number = (uint8_t)faad_getbits(ld, 5
                         DEBUGVAR(1,54,"ics_info(): pred.predictor_reset_group_number"));
                 }
 
@@ -344,26 +345,26 @@
 /* Table 4.4.7 */
 static void pulse_data(pulse_info *pul, bitfile *ld)
 {
-    int i;
+    uint8_t i;
 
-    pul->number_pulse = faad_getbits(ld, 2
+    pul->number_pulse = (uint8_t)faad_getbits(ld, 2
         DEBUGVAR(1,56,"pulse_data(): number_pulse"));
-    pul->pulse_start_sfb = faad_getbits(ld, 6
+    pul->pulse_start_sfb = (uint8_t)faad_getbits(ld, 6
         DEBUGVAR(1,57,"pulse_data(): pulse_start_sfb"));
 
     for (i = 0; i < pul->number_pulse+1; i++) {
-        pul->pulse_offset[i] = faad_getbits(ld, 5
+        pul->pulse_offset[i] = (uint8_t)faad_getbits(ld, 5
             DEBUGVAR(1,58,"pulse_data(): pulse_offset"));
-        pul->pulse_amp[i] = faad_getbits(ld, 4
+        pul->pulse_amp[i] = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,59,"pulse_data(): pulse_amp"));
     }
 }
 
 /* Table 4.4.10 */
-int data_stream_element(bitfile *ld)
+uint16_t data_stream_element(bitfile *ld)
 {
-    int i, byte_aligned, count;
-    char data_stream_byte;
+    uint8_t byte_aligned;
+    uint16_t i, count;
 
     /* element_instance_tag = */ faad_getbits(ld, LEN_TAG
         DEBUGVAR(1,60,"data_stream_element(): element_instance_tag"));
@@ -381,7 +382,7 @@
 
     for (i = 0; i < count; i++)
     {
-        data_stream_byte = faad_getbits(ld, LEN_BYTE
+        faad_getbits(ld, LEN_BYTE
             DEBUGVAR(1,64,"data_stream_element(): data_stream_byte"));
     }
 
@@ -389,15 +390,15 @@
 }
 
 /* Table 4.4.11 */
-int fill_element(bitfile *ld, drc_info *drc)
+uint8_t fill_element(bitfile *ld, drc_info *drc)
 {
-    int count;
+    uint16_t count;
 
-    count = faad_getbits(ld, 4
+    count = (uint16_t)faad_getbits(ld, 4
         DEBUGVAR(1,65,"fill_element(): count"));
     if (count == 15)
     {
-        count += faad_getbits(ld, 8
+        count += (uint16_t)faad_getbits(ld, 8
             DEBUGVAR(1,66,"fill_element(): extra count")) - 1;
     }
 
@@ -410,14 +411,14 @@
 }
 
 /* Table 4.4.24 */
-static int individual_channel_stream(element *ele, bitfile *ld,
-                                     ic_stream *ics, int scal_flag,
-                                     short *spec_data, int sf_index,
-                                     int object_type)
+static uint8_t individual_channel_stream(element *ele, bitfile *ld,
+                                     ic_stream *ics, uint8_t scal_flag,
+                                     int16_t *spec_data, uint8_t sf_index,
+                                     uint8_t object_type)
 {
-    int result;
+    uint8_t result;
 
-    ics->global_gain = faad_getbits(ld, 8
+    ics->global_gain = (uint8_t)faad_getbits(ld, 8
         DEBUGVAR(1,67,"individual_channel_stream(): global_gain"));
 
     if (!ele->common_window && !scal_flag)
@@ -436,7 +437,7 @@
         if ((ics->pulse_data_present = faad_get1bit(ld
             DEBUGVAR(1,68,"individual_channel_stream(): pulse_data_present"))) & 1)
         {
-            pulse_data(&ics->pul, ld);
+            pulse_data(&(ics->pul), ld);
         }
 
         /* get tns data */
@@ -443,7 +444,7 @@
         if ((ics->tns_data_present = faad_get1bit(ld
             DEBUGVAR(1,69,"individual_channel_stream(): tns_data_present"))) & 1)
         {
-            tns_data(ics, &ics->tns, ld);
+            tns_data(ics, &(ics->tns), ld);
         }
 
         /* get gain control data */
@@ -473,8 +474,8 @@
 /* Table 4.4.25 */
 static void section_data(ic_stream *ics, bitfile *ld)
 {
-    int g;
-    int sect_esc_val, sect_bits;
+    uint8_t g;
+    uint8_t sect_esc_val, sect_bits;
 
     if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
         sect_bits = 3;
@@ -484,19 +485,19 @@
 
     for (g = 0; g < ics->num_window_groups; g++)
     {
-        int k = 0;
-        int i = 0;
+        uint16_t k = 0;
+        uint8_t i = 0;
 
         while (k < ics->max_sfb)
         {
-            int sfb;
-            int sect_len_incr;
-            int sect_len = 0;
+            uint8_t sfb;
+            uint8_t sect_len_incr;
+            uint16_t sect_len = 0;
 
-            ics->sect_cb[g][i] = faad_getbits(ld, 4
+            ics->sect_cb[g][i] = (uint8_t)faad_getbits(ld, 4
                 DEBUGVAR(1,71,"section_data(): sect_cb"));
 
-            while ((sect_len_incr = faad_getbits(ld, sect_bits
+            while ((sect_len_incr = (uint8_t)faad_getbits(ld, sect_bits
                 DEBUGVAR(1,72,"section_data(): sect_len_incr"))) == sect_esc_val)
             {
                 sect_len += sect_esc_val;
@@ -524,13 +525,14 @@
   differentially coded relative to the global gain.
 */
 /* Table 4.4.26 */
-static int scale_factor_data(ic_stream *ics, bitfile *ld)
+static uint8_t scale_factor_data(ic_stream *ics, bitfile *ld)
 {
-    int g, sfb, t;
-    int noise_pcm_flag = 1;
-    int scale_factor = ics->global_gain;
-    int is_position = 0;
-    int noise_energy = ics->global_gain - 90;
+    uint8_t g, sfb;
+    int8_t t;
+    uint8_t noise_pcm_flag = 1;
+    int16_t scale_factor = ics->global_gain;
+    int16_t is_position = 0;
+    int16_t noise_energy = ics->global_gain - 90;
 
     for (g = 0; g < ics->num_window_groups; g++)
     {
@@ -587,10 +589,10 @@
 /* Table 4.4.27 */
 static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld)
 {
-    int w, filt, i, start_coef_bits, coef_bits;
-    int n_filt_bits = 2;
-    int length_bits = 6;
-    int order_bits = 5;
+    uint8_t w, filt, i, start_coef_bits, coef_bits;
+    uint8_t n_filt_bits = 2;
+    uint8_t length_bits = 6;
+    uint8_t order_bits = 5;
 
     if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
     {
@@ -601,7 +603,7 @@
 
     for (w = 0; w < ics->num_windows; w++)
     {
-        tns->n_filt[w] = faad_getbits(ld, n_filt_bits
+        tns->n_filt[w] = (uint8_t)faad_getbits(ld, n_filt_bits
             DEBUGVAR(1,74,"tns_data(): n_filt"));
 
         if (tns->n_filt[w])
@@ -617,9 +619,9 @@
 
         for (filt = 0; filt < tns->n_filt[w]; filt++)
         {
-            tns->length[w][filt] = faad_getbits(ld, length_bits
+            tns->length[w][filt] = (uint8_t)faad_getbits(ld, length_bits
                 DEBUGVAR(1,76,"tns_data(): length"));
-            tns->order[w][filt]  = faad_getbits(ld, order_bits
+            tns->order[w][filt]  = (uint8_t)faad_getbits(ld, order_bits
                 DEBUGVAR(1,77,"tns_data(): order"));
             if (tns->order[w][filt])
             {
@@ -631,7 +633,7 @@
                 coef_bits = start_coef_bits - tns->coef_compress[w][filt];
                 for (i = 0; i < tns->order[w][filt]; i++)
                 {
-                    tns->coef[w][filt][i] = faad_getbits(ld, coef_bits
+                    tns->coef[w][filt][i] = (uint8_t)faad_getbits(ld, coef_bits
                         DEBUGVAR(1,80,"tns_data(): coef"));
                 }
             }
@@ -646,11 +648,11 @@
 */
 static void ltp_data(ic_stream *ics, ltp_info *ltp, bitfile *ld)
 {
-    int sfb, w;
+    uint8_t sfb, w;
 
-    ltp->lag = faad_getbits(ld, 11
+    ltp->lag = (uint16_t)faad_getbits(ld, 11
         DEBUGVAR(1,81,"ltp_data(): lag"));
-    ltp->coef = faad_getbits(ld, 3
+    ltp->coef = (uint8_t)faad_getbits(ld, 3
         DEBUGVAR(1,82,"ltp_data(): coef"));
 
     if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
@@ -664,7 +666,7 @@
                     DEBUGVAR(1,84,"ltp_data(): short_lag_present"));
                 if (ltp->short_lag_present[w])
                 {
-                    ltp->short_lag[w] = faad_getbits(ld, 4
+                    ltp->short_lag[w] = (uint8_t)faad_getbits(ld, 4
                         DEBUGVAR(1,85,"ltp_data(): short_lag"));
                 }
 			}
@@ -682,16 +684,17 @@
 
 /* defines whether a huffman codebook is unsigned or not */
 /* Table 4.6.2 */
-static int unsigned_cb[] = { 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
+static uint8_t unsigned_cb[] = { 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
 
 /* Table 4.4.29 */
-static int spectral_data(ic_stream *ics, bitfile *ld, short *spectral_data)
+static uint8_t spectral_data(ic_stream *ics, bitfile *ld, int16_t *spectral_data)
 {
-    int g, i, k, inc;
-    short *sp;
-    int p = 0;
-    int groups = 0;
-    int sect_cb;
+    int8_t i;
+    uint8_t g, inc;
+    int16_t *sp;
+    uint16_t k, p = 0;
+    uint8_t groups = 0;
+    uint8_t sect_cb;
 
     sp = spectral_data;
     for (i = 1024/16-1; i >= 0; --i)
@@ -745,10 +748,10 @@
 }
 
 /* Table 4.4.30 */
-static int extension_payload(bitfile *ld, drc_info *drc, int count)
+static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count)
 {
-    int i, n;
-    int extension_type = faad_getbits(ld, 4
+    uint16_t i, n;
+    uint8_t extension_type = faad_getbits(ld, 4
         DEBUGVAR(1,87,"extension_payload(): extension_type"));
 
     switch (extension_type)
@@ -779,10 +782,10 @@
 }
 
 /* Table 4.4.31 */
-static int dynamic_range_info(bitfile *ld, drc_info *drc)
+static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc)
 {
-    int i, n = 1;
-    int band_incr;
+    uint8_t i, n = 1;
+    uint8_t band_incr;
 
     drc->num_bands = 1;
 
@@ -789,7 +792,7 @@
     if (faad_get1bit(ld
         DEBUGVAR(1,90,"dynamic_range_info(): has instance_tag")) & 1)
     {
-        drc->pce_instance_tag = faad_getbits(ld, 4
+        drc->pce_instance_tag = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,91,"dynamic_range_info(): pce_instance_tag"));
         /* drc->drc_tag_reserved_bits = */ faad_getbits(ld, 4
             DEBUGVAR(1,92,"dynamic_range_info(): drc_tag_reserved_bits"));
@@ -815,7 +818,7 @@
 
         for (i = 0; i < drc->num_bands; i++);
         {
-            drc->band_top[i] = faad_getbits(ld, 8
+            drc->band_top[i] = (uint8_t)faad_getbits(ld, 8
                 DEBUGVAR(1,97,"dynamic_range_info(): band_top"));
             n++;
         }
@@ -824,7 +827,7 @@
     if (faad_get1bit(ld
         DEBUGVAR(1,98,"dynamic_range_info(): has prog_ref_level")) & 1)
     {
-        drc->prog_ref_level = faad_getbits(ld, 7
+        drc->prog_ref_level = (uint8_t)faad_getbits(ld, 7
             DEBUGVAR(1,99,"dynamic_range_info(): prog_ref_level"));
         /* drc->prog_ref_level_reserved_bits = */ faad_get1bit(ld
             DEBUGVAR(1,100,"dynamic_range_info(): prog_ref_level_reserved_bits"));
@@ -835,7 +838,7 @@
     {
         drc->dyn_rng_sgn[i] = faad_get1bit(ld
             DEBUGVAR(1,101,"dynamic_range_info(): dyn_rng_sgn"));
-        drc->dyn_rng_ctl[i] = faad_getbits(ld, 7
+        drc->dyn_rng_ctl[i] = (uint8_t)faad_getbits(ld, 7
             DEBUGVAR(1,102,"dynamic_range_info(): dyn_rng_ctl"));
         n++;
     }
@@ -844,10 +847,10 @@
 }
 
 /* Table 4.4.32 */
-static int excluded_channels(bitfile *ld, drc_info *drc)
+static uint8_t excluded_channels(bitfile *ld, drc_info *drc)
 {
-    int i, n = 0;
-    int num_excl_chan = 7;
+    uint8_t i, n = 0;
+    uint8_t num_excl_chan = 7;
 
     for (i = 0; i < 7; i++)
     {
@@ -876,7 +879,7 @@
 /* Table 1.A.2 */
 void get_adif_header(adif_header *adif, bitfile *ld)
 {
-    int i;
+    uint8_t i;
 
     /* adif_id[0] = */ faad_getbits(ld, 8
         DEBUGVAR(1,106,"get_adif_header(): adif_id[0]"));
@@ -892,7 +895,7 @@
     {
         for (i = 0; i < 72/8; i++)
         {
-            adif->copyright_id[i] = faad_getbits(ld, 8
+            adif->copyright_id[i] = (int8_t)faad_getbits(ld, 8
                 DEBUGVAR(1,111,"get_adif_header(): copyright_id"));
         }
         adif->copyright_id[i] = 0;
@@ -905,7 +908,7 @@
         DEBUGVAR(1,114,"get_adif_header(): bitstream_type"));
     adif->bitrate = faad_getbits(ld, 23
         DEBUGVAR(1,115,"get_adif_header(): bitrate"));
-    adif->num_program_config_elements = faad_getbits(ld, 4
+    adif->num_program_config_elements = (uint8_t)faad_getbits(ld, 4
         DEBUGVAR(1,116,"get_adif_header(): num_program_config_elements"));
 
     for (i = 0; i < adif->num_program_config_elements + 1; i++)
@@ -923,7 +926,7 @@
 }
 
 /* Table 1.A.5 */
-int adts_frame(adts_header *adts, bitfile *ld)
+uint8_t adts_frame(adts_header *adts, bitfile *ld)
 {
     /* faad_byte_align(ld); */
     if (adts_fixed_header(adts, ld))
@@ -935,14 +938,15 @@
 }
 
 /* Table 1.A.6 */
-static int adts_fixed_header(adts_header *adts, bitfile *ld)
+static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld)
 {
-    int i, sync_err = 1;
+    uint16_t i;
+    uint8_t sync_err = 1;
 
     /* try to recover from sync errors */
     for (i = 0; i < 768; i++)
     {
-        adts->syncword = faad_showbits(ld, 12);
+        adts->syncword = (uint16_t)faad_showbits(ld, 12);
         if (adts->syncword != 0xFFF)
         {
             faad_getbits(ld, 8
@@ -959,17 +963,17 @@
 
     adts->id = faad_get1bit(ld
         DEBUGVAR(1,119,"adts_fixed_header(): id"));
-    adts->layer = faad_getbits(ld, 2
+    adts->layer = (uint8_t)faad_getbits(ld, 2
         DEBUGVAR(1,120,"adts_fixed_header(): layer"));
     adts->protection_absent = faad_get1bit(ld
         DEBUGVAR(1,121,"adts_fixed_header(): protection_absent"));
-    adts->profile = faad_getbits(ld, 2
+    adts->profile = (uint8_t)faad_getbits(ld, 2
         DEBUGVAR(1,122,"adts_fixed_header(): profile"));
-    adts->sf_index = faad_getbits(ld, 4
+    adts->sf_index = (uint8_t)faad_getbits(ld, 4
         DEBUGVAR(1,123,"adts_fixed_header(): sf_index"));
     adts->private_bit = faad_get1bit(ld
         DEBUGVAR(1,124,"adts_fixed_header(): private_bit"));
-    adts->channel_configuration = faad_getbits(ld, 3
+    adts->channel_configuration = (uint8_t)faad_getbits(ld, 3
         DEBUGVAR(1,125,"adts_fixed_header(): channel_configuration"));
     adts->original = faad_get1bit(ld
         DEBUGVAR(1,126,"adts_fixed_header(): original"));
@@ -977,7 +981,7 @@
         DEBUGVAR(1,127,"adts_fixed_header(): home"));
     if (adts->id == 0)
     {
-        adts->emphasis = faad_getbits(ld, 2
+        adts->emphasis = (uint8_t)faad_getbits(ld, 2
             DEBUGVAR(1,128,"adts_fixed_header(): emphasis"));
     }
 
@@ -991,11 +995,11 @@
         DEBUGVAR(1,129,"adts_variable_header(): copyright_identification_bit"));
     adts->copyright_identification_start = faad_get1bit(ld
         DEBUGVAR(1,130,"adts_variable_header(): copyright_identification_start"));
-    adts->aac_frame_length = faad_getbits(ld, 13
+    adts->aac_frame_length = (uint16_t)faad_getbits(ld, 13
         DEBUGVAR(1,131,"adts_variable_header(): aac_frame_length"));
-    adts->adts_buffer_fullness = faad_getbits(ld, 11
+    adts->adts_buffer_fullness = (uint16_t)faad_getbits(ld, 11
         DEBUGVAR(1,132,"adts_variable_header(): adts_buffer_fullness"));
-    adts->no_raw_data_blocks_in_frame = faad_getbits(ld, 2
+    adts->no_raw_data_blocks_in_frame = (uint8_t)faad_getbits(ld, 2
         DEBUGVAR(1,133,"adts_variable_header(): no_raw_data_blocks_in_frame"));
 }
 
@@ -1004,7 +1008,7 @@
 {
     if (adts->protection_absent == 0)
     {
-        adts->crc_check = faad_getbits(ld, 16
+        adts->crc_check = (uint16_t)faad_getbits(ld, 16
             DEBUGVAR(1,134,"adts_error_check(): crc_check"));
     }
 }
--- a/libfaad/syntax.h
+++ b/libfaad/syntax.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.h,v 1.4 2002/01/25 20:26:33 menno Exp $
+** $Id: syntax.h,v 1.5 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __SYNTAX_H__
@@ -28,10 +28,6 @@
 
 #include "bits.h"
 
-#ifndef min
-#define min(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
 #define MAIN 0
 #define LC   1
 #define SSR  2
@@ -83,70 +79,70 @@
 
 typedef struct
 {
-    int element_instance_tag;
-    int object_type;
-    int sf_index;
-    int num_front_channel_elements;
-    int num_side_channel_elements;
-    int num_back_channel_elements;
-    int num_lfe_channel_elements;
-    int num_assoc_data_elements;
-    int num_valid_cc_elements;
-    int mono_mixdown_present;
-    int mono_mixdown_element_number;
-    int stereo_mixdown_present;
-    int stereo_mixdown_element_number;
-    int matrix_mixdown_idx_present;
-    int pseudo_surround_enable;
-    int matrix_mixdown_idx;
-    int front_element_is_cpe[16];
-    int front_element_tag_select[16];
-    int side_element_is_cpe[16];
-    int side_element_tag_select[16];
-    int back_element_is_cpe[16];
-    int back_element_tag_select[16];
-    int lfe_element_tag_select[16];
-    int assoc_data_element_tag_select[16];
-    int cc_element_is_ind_sw[16];
-    int valid_cc_element_tag_select[16];
+    uint8_t element_instance_tag;
+    uint8_t object_type;
+    uint8_t sf_index;
+    uint8_t num_front_channel_elements;
+    uint8_t num_side_channel_elements;
+    uint8_t num_back_channel_elements;
+    uint8_t num_lfe_channel_elements;
+    uint8_t num_assoc_data_elements;
+    uint8_t num_valid_cc_elements;
+    uint8_t mono_mixdown_present;
+    uint8_t mono_mixdown_element_number;
+    uint8_t stereo_mixdown_present;
+    uint8_t stereo_mixdown_element_number;
+    uint8_t matrix_mixdown_idx_present;
+    uint8_t pseudo_surround_enable;
+    uint8_t matrix_mixdown_idx;
+    uint8_t front_element_is_cpe[16];
+    uint8_t front_element_tag_select[16];
+    uint8_t side_element_is_cpe[16];
+    uint8_t side_element_tag_select[16];
+    uint8_t back_element_is_cpe[16];
+    uint8_t back_element_tag_select[16];
+    uint8_t lfe_element_tag_select[16];
+    uint8_t assoc_data_element_tag_select[16];
+    uint8_t cc_element_is_ind_sw[16];
+    uint8_t valid_cc_element_tag_select[16];
 
-    int channels;
+    uint8_t channels;
 
-    int comment_field_bytes;
-    unsigned char comment_field_data[257];
+    uint8_t comment_field_bytes;
+    uint8_t comment_field_data[257];
 } program_config;
 
 typedef struct
 {
-    int syncword;
-    int id;
-    int layer;
-    int protection_absent;
-    int profile;
-    int sf_index;
-    int private_bit;
-    int channel_configuration;
-    int original;
-    int home;
-    int emphasis;
-    int copyright_identification_bit;
-    int copyright_identification_start;
-    int aac_frame_length;
-    int adts_buffer_fullness;
-    int no_raw_data_blocks_in_frame;
-    int crc_check;
+    uint16_t syncword;
+    uint8_t id;
+    uint8_t layer;
+    uint8_t protection_absent;
+    uint8_t profile;
+    uint8_t sf_index;
+    uint8_t private_bit;
+    uint8_t channel_configuration;
+    uint8_t original;
+    uint8_t home;
+    uint8_t emphasis;
+    uint8_t copyright_identification_bit;
+    uint8_t copyright_identification_start;
+    uint16_t aac_frame_length;
+    uint16_t adts_buffer_fullness;
+    uint8_t no_raw_data_blocks_in_frame;
+    uint16_t crc_check;
 } adts_header;
 
 typedef struct
 {
-    int copyright_id_present;
-    char copyright_id[10];
-    int original_copy;
-    int home;
-    int bitstream_type;
-    int bitrate;
-    int num_program_config_elements;
-    int adif_buffer_fullness;
+    uint8_t copyright_id_present;
+    int8_t copyright_id[10];
+    uint8_t original_copy;
+    uint8_t home;
+    uint8_t bitstream_type;
+    uint32_t bitrate;
+    uint8_t num_program_config_elements;
+    uint32_t adif_buffer_fullness;
 
     program_config pce;
 } adif_header;
@@ -153,91 +149,91 @@
 
 typedef struct
 {
-    int last_band;
-    int data_present;
-    int lag;
-    int coef;
-    int short_used[8];
-    int short_lag_present[8];
-    int short_lag[8];
-    int long_used[51];
+    uint8_t last_band;
+    uint8_t data_present;
+    uint16_t lag;
+    uint8_t coef;
+    uint8_t long_used[51];
+    uint8_t short_used[8];
+    uint8_t short_lag_present[8];
+    uint8_t short_lag[8];
 } ltp_info;
 
 typedef struct
 {
-    int limit;
-    int predictor_reset;
-    int predictor_reset_group_number;
-    int prediction_used[41];
+    uint8_t limit;
+    uint8_t predictor_reset;
+    uint8_t predictor_reset_group_number;
+    uint8_t prediction_used[41];
 } pred_info;
 
 typedef struct
 {
-    int number_pulse;
-    int pulse_start_sfb;
-    int pulse_offset[4];
-    int pulse_amp[4];
+    uint8_t number_pulse;
+    uint8_t pulse_start_sfb;
+    uint8_t pulse_offset[4];
+    uint8_t pulse_amp[4];
 } pulse_info;
 
 typedef struct
 {
-    int n_filt[8];
-    int coef_res[8];
-    int length[8][4];
-    int order[8][4];
-    int direction[8][4];
-    int coef_compress[8][4];
-    int coef[8][4][32];
+    uint8_t n_filt[8];
+    uint8_t coef_res[8];
+    uint8_t length[8][4];
+    uint8_t order[8][4];
+    uint8_t direction[8][4];
+    uint8_t coef_compress[8][4];
+    uint8_t coef[8][4][32];
 } tns_info;
 
 typedef struct
 {
-    float ctrl1;
-    float ctrl2;
+    uint8_t present;
 
-    int present;
+    uint8_t num_bands;
+    uint8_t pce_instance_tag;
+    uint8_t excluded_chns_present;
+    uint8_t band_top[17];
+    uint8_t prog_ref_level;
+    uint8_t dyn_rng_sgn[17];
+    uint8_t dyn_rng_ctl[17];
+    uint8_t exclude_mask[MAX_CHANNELS];
+    uint8_t additional_excluded_chns[MAX_CHANNELS];
 
-    int num_bands;
-    int pce_instance_tag;
-    int excluded_chns_present;
-    int band_top[17];
-    int prog_ref_level;
-    int dyn_rng_sgn[17];
-    int dyn_rng_ctl[17];
-    int exclude_mask[MAX_CHANNELS];
-    int additional_excluded_chns[MAX_CHANNELS];
+    real_t ctrl1;
+    real_t ctrl2;
 } drc_info;
 
 typedef struct
 {
-    int max_sfb;
+    uint8_t max_sfb;
 
-    int num_swb;
-    int num_window_groups;
-    int num_windows;
-    int window_sequence;
-    int window_group_length[8];
-    int window_shape;
-    int scale_factor_grouping;
-    int sect_sfb_offset[8][15*8];
-    int swb_offset[51];
+    uint8_t num_swb;
+    uint8_t num_window_groups;
+    uint8_t num_windows;
+    uint8_t window_sequence;
+    uint8_t window_group_length[8];
+    uint8_t window_shape;
+    uint8_t scale_factor_grouping;
+    uint16_t sect_sfb_offset[8][15*8];
+    uint16_t swb_offset[51];
 
-    int sect_cb[8][15*8];
-    int sect_start[8][15*8];
-    int sect_end[8][15*8];
-    int sfb_cb[8][8*15];
-    int num_sec[8]; /* number of sections in a group */
+    uint8_t sect_cb[8][15*8];
+    uint16_t sect_start[8][15*8];
+    uint16_t sect_end[8][15*8];
+    uint8_t sfb_cb[8][8*15];
+    uint8_t num_sec[8]; /* number of sections in a group */
 
-    int global_gain;
+    uint8_t global_gain;
+    uint16_t scale_factors[8][51];
 
-    int ms_mask_present;
-    int ms_used[MAX_WINDOW_GROUPS][MAX_SFB];
+    uint8_t ms_mask_present;
+    uint8_t ms_used[MAX_WINDOW_GROUPS][MAX_SFB];
 
-    int pulse_data_present;
-    int tns_data_present;
-    int gain_control_data_present;
-    int predictor_data_present;
-    int scale_factors[8][51];
+    uint8_t pulse_data_present;
+    uint8_t tns_data_present;
+    uint8_t gain_control_data_present;
+    uint8_t predictor_data_present;
 
     pulse_info pul;
     tns_info tns;
@@ -248,49 +244,50 @@
 
 typedef struct
 {
-    int ele_id;
+    uint8_t ele_id;
 
-    int channel;
-    int paired_channel;
+    uint8_t channel;
+    uint8_t paired_channel;
 
-    int element_instance_tag;
-    int common_window;
+    uint8_t element_instance_tag;
+    uint8_t common_window;
 
     ic_stream ics1;
     ic_stream ics2;
 } element; /* syntax element (SCE, CPE, LFE) */
 
-int GASpecificConfig(bitfile *ld, unsigned long *channelConfiguration);
-int single_lfe_channel_element(element *sce, bitfile *ld, short *spec_data,
-                               int sf_index, int object_type);
-int channel_pair_element(element *cpe, bitfile *ld, short *spec_data1,
-                         short *spec_data2, int sf_index, int object_type);
-int data_stream_element(bitfile *ld);
-int program_config_element(program_config *pce, bitfile *ld);
-int fill_element(bitfile *ld, drc_info *drc);
-int adts_frame(adts_header *adts, bitfile *ld);
+
+uint8_t GASpecificConfig(bitfile *ld, uint8_t *channelConfiguration);
+uint8_t single_lfe_channel_element(element *sce, bitfile *ld, int16_t *spec_data,
+                               uint8_t sf_index, uint8_t object_type);
+uint8_t channel_pair_element(element *cpe, bitfile *ld, int16_t *spec_data1,
+                         int16_t *spec_data2, uint8_t sf_index, uint8_t object_type);
+uint16_t data_stream_element(bitfile *ld);
+uint8_t program_config_element(program_config *pce, bitfile *ld);
+uint8_t fill_element(bitfile *ld, drc_info *drc);
+uint8_t adts_frame(adts_header *adts, bitfile *ld);
 void get_adif_header(adif_header *adif, bitfile *ld);
 
 
 /* static functions */
-static int individual_channel_stream(element *ele, bitfile *ld,
-                                     ic_stream *ics, int scal_flag,
-                                     short *spec_data, int sf_index,
-                                     int object_type);
-static int ics_info(ic_stream *ics, bitfile *ld,
-                    int common_window, int fs_index, int object_type);
+static uint8_t individual_channel_stream(element *ele, bitfile *ld,
+                                     ic_stream *ics, uint8_t scal_flag,
+                                     int16_t *spec_data, uint8_t sf_index,
+                                     uint8_t object_type);
+static uint8_t ics_info(ic_stream *ics, bitfile *ld,
+                    uint8_t common_window, uint8_t fs_index, uint8_t object_type);
 static void section_data(ic_stream *ics, bitfile *ld);
-static int scale_factor_data(ic_stream *ics, bitfile *ld);
-static int spectral_data(ic_stream *ics, bitfile *ld, short *spectral_data);
-static int extension_payload(bitfile *ld, drc_info *drc, int count);
+static uint8_t scale_factor_data(ic_stream *ics, bitfile *ld);
+static uint8_t spectral_data(ic_stream *ics, bitfile *ld, int16_t *spectral_data);
+static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count);
 static void pulse_data(pulse_info *pul, bitfile *ld);
 static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld);
 static void ltp_data(ic_stream *ics, ltp_info *ltp, bitfile *ld);
-static int adts_fixed_header(adts_header *adts, bitfile *ld);
+static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld);
 static void adts_variable_header(adts_header *adts, bitfile *ld);
 static void adts_error_check(adts_header *adts, bitfile *ld);
-static int dynamic_range_info(bitfile *ld, drc_info *drc);
-static int excluded_channels(bitfile *ld, drc_info *drc);
+static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc);
+static uint8_t excluded_channels(bitfile *ld, drc_info *drc);
 
 
 #ifdef __cplusplus
--- a/libfaad/tns.c
+++ b/libfaad/tns.c
@@ -16,10 +16,12 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: tns.c,v 1.1 2002/01/14 19:15:57 menno Exp $
+** $Id: tns.c,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
-#ifdef __ICL
+#include "common.h"
+
+#ifdef USE_FMATH
 #include <mathf.h>
 #else
 #include <math.h>
@@ -29,12 +31,13 @@
 
 
 /* TNS decoding for one channel and frame */
-void tns_decode_frame(ic_stream *ics, tns_info *tns, int sr_index,
-                      int object_type, float *spec)
+void tns_decode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
+                      uint8_t object_type, real_t *spec)
 {
-    int w, bottom, f, top, start, end, size, inc;
-    int tns_order;
-    float lpc[TNS_MAX_ORDER+1];
+    uint8_t w, f, tns_order;
+    int8_t inc;
+    uint16_t bottom, top, start, end, size;
+    real_t lpc[TNS_MAX_ORDER+1];
 
     if (!ics->tns_data_present)
         return;
@@ -76,12 +79,13 @@
 }
 
 /* TNS encoding for one channel and frame */
-void tns_encode_frame(ic_stream *ics, tns_info *tns, int sr_index,
-                      int object_type, float *spec)
+void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
+                      uint8_t object_type, real_t *spec)
 {
-    int w, bottom, f, top, start, end, size, inc;
-    int tns_order;
-    float lpc[TNS_MAX_ORDER+1];
+    uint8_t w, f, tns_order;
+    int8_t inc;
+    uint16_t bottom, top, start, end, size;
+    real_t lpc[TNS_MAX_ORDER+1];
 
     if (!ics->tns_data_present)
         return;
@@ -123,18 +127,18 @@
 }
 
 /* Decoder transmitted coefficients for one TNS filter */
-static void tns_decode_coef(int order, int coef_res_bits, int coef_compress,
-                            int *coef, float *a)
+static void tns_decode_coef(uint8_t order, uint8_t coef_res_bits, uint8_t coef_compress,
+                            uint8_t *coef, real_t *a)
 {
-    int i, m;
-    int coef_res2, s_mask, n_mask;
-    int tmp[TNS_MAX_ORDER+1];
-    float tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
-    float iqfac, iqfac_m;
+    uint8_t i, m;
+    uint8_t coef_res2, s_mask, n_mask;
+    int8_t tmp[TNS_MAX_ORDER+1];
+    real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
+    real_t iqfac, iqfac_m;
 
     /* Some internal tables */
-    int sgn_mask[] = { 0x2, 0x4, 0x8 };
-    int neg_mask[] = { ~0x3, ~0x7, ~0xf };
+    static uint8_t sgn_mask[] = { 0x2, 0x4, 0x8 };
+    static uint8_t neg_mask[] = { ~0x3, ~0x7, ~0xf };
 
     /* size used for transmission */
     coef_res2 = coef_res_bits - coef_compress;
@@ -150,10 +154,10 @@
     iqfac_m = ((1 << (coef_res_bits-1)) + 0.5f) / (M_PI/2.0f);
 
     for (i = 0; i < order; i++)
-#ifdef __ICL
+#ifdef USE_FMATH
         tmp2[i] = sinf(tmp[i] / ((tmp[i] >= 0) ? iqfac : iqfac_m));
 #else
-        tmp2[i] = (float)sin(tmp[i] / ((tmp[i] >= 0) ? iqfac : iqfac_m));
+        tmp2[i] = (real_t)sin(tmp[i] / ((tmp[i] >= 0) ? iqfac : iqfac_m));
 #endif
 
     /* Conversion to LPC coefficients */
@@ -170,8 +174,8 @@
     }
 }
 
-static void tns_ar_filter(float *spectrum, int size, int inc, float *lpc,
-                          int order)
+static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
+                          uint8_t order)
 {
     /*
      - Simple all-pole filter of order "order" defined by
@@ -182,8 +186,9 @@
        to the next data sample is given by "inc"
     */
 
-    int i, j;
-    float y, state[TNS_MAX_ORDER];
+    uint8_t j;
+    uint16_t i;
+    real_t y, state[TNS_MAX_ORDER];
 
     for (i = 0; i < order; i++)
         state[i] = 0;
@@ -204,8 +209,8 @@
     }
 }
 
-static void tns_ma_filter(float *spectrum, int size, int inc, float *lpc,
-                          int order)
+static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
+                          uint8_t order)
 {
     /*
      - Simple all-zero filter of order "order" defined by
@@ -216,8 +221,9 @@
        to the next data sample is given by "inc"
     */
 
-    int i, j;
-    float y, state[TNS_MAX_ORDER];
+    uint8_t j;
+    uint16_t i;
+    real_t y, state[TNS_MAX_ORDER];
 
     for (i = 0; i < order; i++)
         state[i] = 0;
@@ -238,7 +244,7 @@
     }
 }
 
-static int tns_max_bands_table[12][4] =
+static uint8_t tns_max_bands_table[12][4] =
 {
     /* entry for each sampling rate
      * 1    Main/LC long window
@@ -260,9 +266,9 @@
     { 39, 14, 19, 7 },       /* 8000  */
 };
 
-static int tns_max_bands(ic_stream *ics, int sr_index)
+static uint8_t tns_max_bands(ic_stream *ics, uint8_t sr_index)
 {
-    int i;
+    uint8_t i;
 
     i = (ics->window_sequence == EIGHT_SHORT_SEQUENCE) ? 1 : 0;
 
@@ -269,8 +275,8 @@
     return tns_max_bands_table[sr_index][i];
 }
 
-static int tns_max_order(ic_stream *ics, int sr_index,
-                         int object_type)
+static uint8_t tns_max_order(ic_stream *ics, uint8_t sr_index,
+                         uint8_t object_type)
 {
     /* Correction in 14496-3 Cor. 1
        Works like MPEG2-AAC (13818-7) now
--- a/libfaad/tns.h
+++ b/libfaad/tns.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: tns.h,v 1.1 2002/01/14 19:15:57 menno Exp $
+** $Id: tns.h,v 1.2 2002/02/18 10:01:05 menno Exp $
 **/
 
 #ifndef __TNS_H__
@@ -26,35 +26,24 @@
 extern "C" {
 #endif
 
-#ifndef max
-#define max(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-#ifndef min
-#define min(a, b) (((a) < (b)) ? (a) : (b))
-#endif
 
-#ifndef M_PI
-#define M_PI 3.14159265358979323846f
-#endif
-
-
 #define TNS_MAX_ORDER 20
 
     
-void tns_decode_frame(ic_stream *ics, tns_info *tns, int sr_index,
-                      int object_type, float *spec);
-void tns_encode_frame(ic_stream *ics, tns_info *tns, int sr_index,
-                      int object_type, float *spec);
+void tns_decode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
+                      uint8_t object_type, real_t *spec);
+void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
+                      uint8_t object_type, real_t *spec);
 
-static void tns_decode_coef(int order, int coef_res_bits, int coef_compress,
-                            int *coef, float *a);
-static void tns_ar_filter(float *spectrum, int size, int inc, float *lpc,
-                          int order);
-static void tns_ma_filter(float *spectrum, int size, int inc, float *lpc,
-                          int order);
-static int tns_max_bands(ic_stream *ics, int sr_index);
-static int tns_max_order(ic_stream *ics, int sr_index,
-                         int object_type);
+static void tns_decode_coef(uint8_t order, uint8_t coef_res_bits, uint8_t coef_compress,
+                            uint8_t *coef, real_t *a);
+static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
+                          uint8_t order);
+static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
+                          uint8_t order);
+static uint8_t tns_max_bands(ic_stream *ics, uint8_t sr_index);
+static uint8_t tns_max_order(ic_stream *ics, uint8_t sr_index,
+                         uint8_t object_type);
 
 
 #ifdef __cplusplus
--- a/plugins/in_mp4/in_mp4.c
+++ b/plugins/in_mp4/in_mp4.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: in_mp4.c,v 1.7 2002/01/25 23:20:42 menno Exp $
+** $Id: in_mp4.c,v 1.8 2002/02/18 10:01:05 menno Exp $
 **/
 
 #define WIN32_LEAN_AND_MEAN
@@ -61,7 +61,7 @@
     MP4SampleId numSamples;
     MP4SampleId sampleId;
     int samplerate;
-    int channels;
+    unsigned char channels;
     int decode_pos_ms; // current decoding position, in milliseconds
     int paused; // are we paused?
     int seek_needed; // if != -1, it is the point that the decode thread should seek to, in ms.
@@ -120,12 +120,14 @@
         if (!strcmp(trackType, MP4_AUDIO_TRACK_TYPE))
         {
             unsigned char *buff = NULL;
-            int buff_size = 0, dummy;
+            int buff_size = 0;
+            unsigned char dummy8;
+            unsigned int dummy32;
             MP4GetTrackESConfiguration(infile, trackId, &buff, &buff_size);
 
             if (buff)
             {
-                rc = AudioSpecificConfig(buff, &dummy, &dummy, &dummy, &dummy);
+                rc = AudioSpecificConfig(buff, &dummy32, &dummy8, &dummy8, &dummy8);
                 free(buff);
 
                 if (rc < 0)
@@ -249,7 +251,8 @@
 BOOL CALLBACK info_dialog_proc(HWND hwndDlg, UINT message,
                                WPARAM wParam, LPARAM lParam)
 {
-    int i, width, height, numFrames, ch, sf;
+    int i, width, height, numFrames;
+    unsigned char ch, sf;
     float fps;
     MP4FileHandle file;
     int track;
@@ -323,7 +326,7 @@
     unsigned long msDuration;
     MP4Duration trackDuration;
     unsigned int timeScale, avgBitRate;
-    int type;
+    unsigned char type;
     const char* typeName;
 
     switch (message) {
--- a/plugins/winamp/in_faad.c
+++ b/plugins/winamp/in_faad.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: in_faad.c,v 1.2 2002/01/21 22:58:14 menno Exp $
+** $Id: in_faad.c,v 1.3 2002/02/18 10:01:05 menno Exp $
 **/
 
 #define WIN32_LEAN_AND_MEAN
@@ -334,12 +334,9 @@
 
     memmap_buffer = (char*)LocalAlloc(LPTR, fileread);
     read_buffer_filestream(infile, memmap_buffer, fileread);
-    memmap_index = 0;
 
-    tagsize = id3v2_tag(memmap_buffer);
-
-	/* If we find a tag, run right over it */
-    memmap_index += tagsize;
+    /* skip id3v2 tag */
+    memmap_index = id3v2_tag(memmap_buffer);
 
     hDecoder = faacDecOpen();
 
--- a/plugins/winamp3/cnv_aacpcm.dsp
+++ b/plugins/winamp3/cnv_aacpcm.dsp
@@ -165,6 +165,162 @@
 # Begin Group "wa3sdk_h"
 
 # PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\sdk\studio\api.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\apihelp.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\attribs\attrcb.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\attribs\attribute.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\attribs\attrint.h
+# End Source File
+# Begin Source File
+
+SOURCE="..\..\..\..\..\Program Files\Microsoft Visual Studio\VC98\Include\BASETSD.H"
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\basewnd.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\attribs\cfgitem.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\attribs\cfgitemi.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\chunklist.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\common.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\compdb.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\corecb.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\depend.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\drag.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\guid.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\map.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\mediainfo.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\memblock.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\multimap.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\named.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\nsGUID.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\pair.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\pathparse.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\platform\platform.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\ptrlist.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\rootcomp.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\rootwnd.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\scriptvar.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\services\service.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\services\servicei.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\services\services.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\std.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\services\svc_fileread.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\services\svc_mediaconverter.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\tlist.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\vcputypes.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\common\virtualwnd.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sdk\studio\wac.h
+# End Source File
 # End Group
 # Begin Source File