shithub: aacenc

Download patch

ref: a6c5046f22be23435ab21c679e4bf14631f0e233
parent: 066f3cc7bac1d1a85f5274e0ec90165b3cfcbec6
author: menno <menno>
date: Thu Oct 5 09:04:05 EDT 2000

Big code cleanup

--- a/aac_se_enc.c
+++ b/aac_se_enc.c
@@ -21,12 +21,11 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.12 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.13 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
-#include <stdlib.h>
 #include "aac_se_enc.h"
 #include "quant.h"
 #include "huffman.h"
@@ -244,7 +243,7 @@
   /* this function writes out an individual_channel_stream to the bitstream and */
   /* returns the number of bits written to the bitstream */
   int bit_count = 0;
-//  int output_book_vector[SFB_NUM_MAX*2];
+//  int output_book_vector[MAX_SCFAC_BANDS*2];
   writeFlag = ( writeFlag != 0 );
 
   /* Write the 8-bit global_gain */
--- a/aac_se_enc.h
+++ b/aac_se_enc.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.6 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.7 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -29,13 +29,13 @@
 #ifndef AAC_SE_ENC
 #define AAC_SE_ENC
 
-#include "interface.h"
 #include "bitstream.h"
-#include "all.h"
 #include "quant.h"
 #include "nok_ltp_enc.h"
 
 extern int max_pred_sfb;
+
+
 
 /*****************************************************************************/
 /* Write AAC fill bits to the bitStream                                      */
--- a/aacenc.h
+++ b/aacenc.h
@@ -21,12 +21,11 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.19 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.20 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
-#include <stdio.h>
 #include <sndfile.h>
 
 typedef struct RCBufStruct RCBuf;	/* buffer handle */
--- a/all.h
+++ /dev/null
@@ -1,56 +1,0 @@
-/*
- *	General declarations
- *
- *	Copyright (c) 1999 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, 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; see the file COPYING.  If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/**************************************************************************
-  Version Control Information			Method: CVS
-  Identifiers:
-  $Revision: 1.6 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef	_all_h_
-#define _all_h_
-
-#include "interface.h"
-#include "tns.h"
-#include "bitstream.h"
-
-typedef struct
-{
-    int is_present;  
-    int ms_used[MAXBANDS];
-} MS_Info;
-
-typedef struct
-{
-    int present;	/* channel present */
-    int tag;		/* element tag */
-    int cpe;		/* 0 if single channel or lfe, 1 if channel pair */ 
-    int lfe;            /* 1 if lfe channel */             
-    int	common_window;	/* 1 if common window for cpe */
-    int	ch_is_left;	/* 1 if left channel of cpe */
-    int	paired_ch;	/* index of paired channel in cpe */
-    int widx;		/* window element index for this channel */
-    MS_Info ms_info;    /* MS information */
-} Ch_Info;
-
-#endif	/* _all_h_ */
-
--- a/bitstream.c
+++ b/bitstream.c
@@ -21,14 +21,12 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.4 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.5 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
-#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 #include "bitstream.h"		/* bit stream module */
 
--- a/block.h
+++ /dev/null
@@ -1,100 +1,0 @@
-/*
- *	Function prototypes for block handling
- *
- *	Copyright (c) 1999 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, 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; see the file COPYING.  If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/**************************************************************************
-  Version Control Information			Method: CVS
-  Identifiers:
-  $Revision: 1.5 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef BLOCK_H
-#define BLOCK_H 1
-
-#define IN_DATATYPE  double
-#define OUT_DATATYPE double
-
-#define BLOCK_LEN_LONG	   1024
-#define BLOCK_LEN_SHORT    128
-
-#define NWINLONG	(BLOCK_LEN_LONG)
-#define ALFALONG	4.0
-#define NWINSHORT	(BLOCK_LEN_SHORT)
-#define ALFASHORT	7.0
-
-#define	NWINFLAT	(NWINLONG)					/* flat params */
-#define	NWINADV		(NWINLONG-NWINSHORT)		/* Advanced flat params */
-#define NFLAT		((NWINFLAT-NWINSHORT)/2)
-#define NADV0		((NWINADV-NWINSHORT)/2)
-
-
-typedef enum {
-    WS_SIN, WS_KBD, N_WINDOW_SHAPES
-} 
-Window_shape;
-
-/* YT 970615 for Son_PP  */
-typedef enum {
-	MOVERLAPPED,
-	MNON_OVERLAPPED
-}
-Mdct_in,Imdct_out;
-
-typedef enum {
-    WT_LONG, 
-    WT_SHORT, 
-    WT_FLAT, 
-    WT_ADV,			/* Advanced flat window */
-    N_WINDOW_TYPES
-} 
-WINDOW_TYPE_AAC; 
-
-typedef enum {                  /* ADVanced transform types */
-    LONG_BLOCK,
-    START_BLOCK,
-    SHORT_BLOCK,
-    STOP_BLOCK,
-    START_ADV_BLOCK,
-    STOP_ADV_BLOCK,
-    START_FLAT_BLOCK,
-    STOP_FLAT_BLOCK,
-    N_BLOCK_TYPES
-} 
-BLOCK_TYPE;
-
-typedef enum {  		/* Advanced window sequence (frame) types */
-    ONLY_LONG,
-    LONG_START, 
-    LONG_STOP,
-    SHORT_START, 
-    SHORT_STOP,
-    EIGHT_SHORT, 
-    SHORT_EXT_STOP,
-    NINE_SHORT,
-    OLD_START,
-    OLD_STOP,
-    N_WINDOW_SEQUENCES
-} 
-WINDOW_SEQUENCE;
-
-
-#endif	/*	BLOCK_H	*/
-
--- a/enc.h
+++ b/enc.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.6 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.7 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -29,7 +29,6 @@
 #ifndef _enc_h_
 #define _enc_h_
 
-#include <stdio.h>              /* typedef FILE */
 
 #include "bitstream.h"		/* bit stream module */
 
--- a/enc_tf.c
+++ b/enc_tf.c
@@ -21,25 +21,21 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.62 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.63 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
-#include <math.h>
 #include <stdlib.h>
-#include <memory.h>
+
 #include "aacenc.h"
 #include "bitstream.h"
 #include "interface.h"
 #include "enc.h"
-#include "block.h"
-#include "tf_main.h"
 #include "psych.h"
 #include "mc_enc.h"
 #include "ms.h"
 #include "quant.h"
-#include "all.h"
 #include "aac_se_enc.h"
 #include "nok_ltp_enc.h"
 #include "transfo.h"
@@ -68,8 +64,6 @@
 double *nok_tmp_DTimeSigBuf[MAX_TIME_CHANNELS]; /* temporary fix to the buffer size problem. */
 
 /* variables used by the T/F mapping */
-enum QC_MOD_SELECT qc_select = AAC_QC;                   /* later f(encPara) */
-enum AAC_PROFILE profile = MAIN;
 enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS];
 enum WINDOW_TYPE desired_block_type[MAX_TIME_CHANNELS];
 enum WINDOW_TYPE next_desired_block_type[MAX_TIME_CHANNELS];
@@ -143,14 +137,6 @@
     }
   }
 
-  profile = MAIN;
-  qc_select = AAC_PRED;           /* enable prediction */
-
-  if (as->profile == LOW) {
-    profile = LOW;
-    qc_select = AAC_QC;          /* disable prediction */
-  }
-
   if (as->use_PNS)
     pns_sfb_start = 0;
   else
@@ -187,7 +173,7 @@
 
   /* Init TNS */
   for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
-    TnsInit(as->out_sampling_rate,profile,&tnsInfo[chanNum]);
+    TnsInit(as->out_sampling_rate,as->profile,&tnsInfo[chanNum]);
     quantInfo[chanNum].tnsInfo = &tnsInfo[chanNum];         /* Set pointer to TNS data */
   }
 
--- a/fastfft.h
+++ b/fastfft.h
@@ -21,11 +21,15 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.4 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.5 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
+#ifndef _FASTFFT_H_
+#define _FASTFFT_H_
+
+
 #include "transfo.h"
 
 #define PFFTW(name)  CONCAT(pfftw_, name)
@@ -37,3 +41,4 @@
 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);
 
+#endif
\ No newline at end of file
--- a/huffman.c
+++ b/huffman.c
@@ -21,16 +21,13 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.3 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.4 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
-#include <math.h>
-#include <string.h>
 #include "aacenc.h"
 #include "bitstream.h"
-#include "tf_main.h"
 #include "pulse.h"
 #include "quant.h"
 #include "huffman.h"
@@ -45,7 +42,7 @@
 		  int write_flag)              /* Write flag: 0 count, 1 write */
 {
   /*
-    This function inputs the vector, 'book_vector[]', which is of length SFB_NUM_MAX,
+    This function inputs the vector, 'book_vector[]', which is of length MAX_SCFAC_BANDS,
     and contains the optimal huffman tables of each sfb.  It returns the vector, 'output_book_vector[]', which
     has it's elements formatted for the encoded bit stream.  It's syntax is:
 
@@ -142,12 +139,12 @@
 	return(bit_count);
 }
 
-int bit_search(int quant[NUM_COEFF],  /* Quantized spectral values */
+int bit_search(int quant[BLOCK_LEN_LONG],  /* Quantized spectral values */
                AACQuantInfo* quantInfo)        /* Quantization information */
   /*
   This function inputs a vector of quantized spectral data, quant[][], and returns a vector,
   'book_vector[]' that describes how to group together the scalefactor bands into a smaller
-  number of sections.  There are SFB_NUM_MAX elements in book_vector (equal to 49 in the
+  number of sections.  There are MAX_SCFAC_BANDS elements in book_vector (equal to 49 in the
   case of long blocks and 112 for short blocks), and each element has a huffman codebook 
   number assigned to it.
 
@@ -239,7 +236,7 @@
 }
 
 
-int noiseless_bit_count(int quant[NUM_COEFF],
+int noiseless_bit_count(int quant[BLOCK_LEN_LONG],
 			/*int huff[13][MAXINDEX][NUMINTAB],*/
 			int hop,  // hop is now always 1
 			int min_book_choice[112][3],
@@ -426,7 +423,7 @@
 int output_bits(AACQuantInfo* quantInfo,
 		/*int huff[13][MAXINDEX][NUMINTAB],*/
                 int book,
-		int quant[NUM_COEFF],
+		int quant[BLOCK_LEN_LONG],
                 int offset,
 		int length,
 		int write_flag)
--- a/huffman.h
+++ b/huffman.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.4 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.5 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -31,9 +31,7 @@
 
 #include "pulse.h"
 #include "interface.h"
-#include "tf_main.h"
 #include "tns.h"
-#include "all.h"
 #include "nok_ltp_common.h"
 
 #ifdef __cplusplus
@@ -68,13 +66,13 @@
 /*********************************************************/
 /* bit_search                                            */
 /*********************************************************/
-int bit_search(int quant[NUM_COEFF],  /* Quantized spectral values */
+int bit_search(int quant[BLOCK_LEN_LONG],  /* Quantized spectral values */
                AACQuantInfo* quantInfo);       /* Quantization information */
 
 /*********************************************************/
 /* noiseless_bit_count                                   */
 /*********************************************************/
-int noiseless_bit_count(int quant[NUM_COEFF],
+int noiseless_bit_count(int quant[BLOCK_LEN_LONG],
 			int hop,
 			int min_book_choice[112][3],
 			AACQuantInfo* quantInfo);         /* Quantization information */
@@ -88,7 +86,7 @@
 int output_bits(AACQuantInfo* quantInfo,
 		/*int huff[13][MAXINDEX][NUMINTAB],*/
                 int book,                /* codebook */
-		int quant[NUM_COEFF],		
+		int quant[BLOCK_LEN_LONG],		
 		int offset,
 		int length,
 		int write_flag);
--- a/interface.h
+++ b/interface.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.2 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.3 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -29,191 +29,211 @@
 #ifndef _interface_h_
 #define _interface_h_
 
-/*
- * interface between the encoder and decoder
- */
 
-#define C_LN10		2.30258509299404568402		/* ln(10) */
-#define C_PI		3.14159265358979323846		/* pi */
-#define C_SQRT2		1.41421356237309504880		/* sqrt(2) */
+/* AAC Profile */
+enum AAC_PROFILE { MAIN, LOW, SSR };
 
-#define MINTHR		.5
-#define SF_C1		(13.33333/1.333333)
+#define MAX_SAMPLING_RATES 12
 
-/* prediction */
-#define	PRED_ORDER	2
-#define PRED_ALPHA	0.9
-#define PRED_A		0.95
-#define PRED_B		0.95
+enum WINDOW_TYPE { 
+  ONLY_LONG_WINDOW, 
+  LONG_SHORT_WINDOW, 
+  ONLY_SHORT_WINDOW,
+  SHORT_LONG_WINDOW,
+};    
 
-enum
-{
-    /* 
-     * block switching
-     */
-    LN			= 2048,
-    SN			= 256,
-    LN2			= LN/2,
-    SN2			= SN/2,
-    LN4			= LN/4,
-    SN4			= SN/4,
-    NSHORT		= LN/SN,
-    MAX_SBK		= NSHORT,
+#define NSFB_LONG  51
+#define NSFB_SHORT 15
+#define MAX_SHORT_IN_LONG_BLOCK 8
 
-    NUM_WIN_SEQ,
-    WLONG		= 0, /* ONLY_LONG_WINDOW,  */
-    WSTART, 
-    WSHORT, 
-    WSTOP, 
-    
-    MAXBANDS		= 16*NSHORT,	/* max number of scale factor bands ((NSFB_SHORT+1)*MAX_SHORT_IN_LONG_BLOCK) */
-    MAXFAC		= 121,		/* maximum scale factor */
-    MIDFAC		= (MAXFAC-1)/2,
-    SF_OFFSET		= 100,		/* global gain must be positive */
+#define MAX_SHORT_WINDOWS 8
 
-    /*
-     * specify huffman tables as signed (1) or unsigned (0)
-     */
-    HUF1SGN		= 1, 
-    HUF2SGN		= 1, 
-    HUF3SGN		= 0, 
-    HUF4SGN		= 0, 
-    HUF5SGN		= 1, 
-    HUF6SGN		= 1, 
-    HUF7SGN		= 0, 
-    HUF8SGN		= 0, 
-    HUF9SGN		= 0, 
-    HUF10SGN		= 0, 
-    HUF11SGN		= 0, 
+/* if static memory allocation is used, this value tells the max. nr of
+   audio channels to be supported */
+/*#define MAX_TIME_CHANNELS (MAX_CHANNELS)*/
+#define MAX_TIME_CHANNELS 6
 
-    BY4BOOKS		= 4,
-    ESCBOOK		= 11,
-    NSPECBOOKS		= ESCBOOK + 1,
-    BOOKSCL		= NSPECBOOKS,
-    NBOOKS		= NSPECBOOKS+1,
-    INTENSITY_HCB	= 15,
-    INTENSITY_HCB2	= 14,
-    
-    LONG_SECT_BITS	= 5, 
-    SHORT_SECT_BITS	= 3, 
+/* max. number of scale factor bands */
+#define MAX_SCFAC_BANDS ((NSFB_SHORT+1)*MAX_SHORT_IN_LONG_BLOCK)
 
-    /*
-     * Program Configuration
-     */
-    Main_Profile	= 0, 
-    LC_Profile		= 1, 
-    SRS_Profile		= 2,
+#define IN_DATATYPE  double
+#define OUT_DATATYPE double
 
-    Fs_48		= 3, 
-    Fs_44		= 4, 
-    Fs_32		= 5, 
+#define BLOCK_LEN_LONG	   1024
+#define BLOCK_LEN_SHORT    128
 
-    /*
-     * Misc constants
-     */
-    CC_DOM		= 0,	/* before TNS */ 
-    CC_IND		= 1,  
-     
-    /* 
-     * Raw bitstream constants
-     */
-    LEN_SE_ID		= 3,
-    LEN_TAG		= 4,
-    LEN_GLOB_GAIN       = 8,
-    LEN_COM_WIN		= 1,
-    LEN_ICS_RESERV	= 1, 
-    LEN_WIN_SEQ		= 2,
-    LEN_WIN_SH		= 1,
-    LEN_MAX_SFBL	= 6, 
-    LEN_MAX_SFBS	= 4, 
-    LEN_CB		= 4,
-    LEN_SCL_PCM		= 8,
-    LEN_PRED_PRES	= 1,
-    LEN_PRED_RST	= 1,
-    LEN_PRED_RSTGRP	= 5,
-    LEN_PRED_ENAB	= 1,
-    LEN_MASK_PRES	= 2,
-    LEN_MASK		= 1,
-    LEN_PULSE_PRES	= 1,
-    LEN_TNS_PRES	= 1,
-    LEN_TNS_NFILTL      = 2,
-    LEN_TNS_NFILTS      = 1,
-    LEN_TNS_COEFF_RES   = 1,
-    LEN_TNS_LENGTHL     = 6,
-    LEN_TNS_LENGTHS     = 4,
-    LEN_TNS_ORDERL      = 5,
-    LEN_TNS_ORDERS      = 3,
-    LEN_TNS_DIRECTION   = 1,
-    LEN_TNS_COMPRESS    = 1,
-    LEN_GAIN_PRES	= 1,
+#define NWINLONG	(BLOCK_LEN_LONG)
+#define ALFALONG	4.0
+#define NWINSHORT	(BLOCK_LEN_SHORT)
+#define ALFASHORT	7.0
 
-    LEN_NEC_NPULSE	= 2, 
-    LEN_NEC_ST_SFB	= 6, 
-    LEN_NEC_POFF	= 5, 
-    LEN_NEC_PAMP	= 4, 
-    NUM_NEC_LINES	= 4, 
-    NEC_OFFSET_AMP	= 4, 
+#define	NWINFLAT	(NWINLONG)					/* flat params */
+#define	NWINADV		(NWINLONG-NWINSHORT)		/* Advanced flat params */
+#define NFLAT		((NWINFLAT-NWINSHORT)/2)
+#define NADV0		((NWINADV-NWINSHORT)/2)
 
-    LEN_NCC		= 3,
-    LEN_IS_CPE		= 1, 
-    LEN_CC_LR		= 1,
-    LEN_CC_DOM		= 1,
-    LEN_CC_SGN		= 1,
-    LEN_CCH_GES		= 2,
-    LEN_CCH_CGP		= 1,
 
-    LEN_D_CNT		= 4,
-    LEN_D_ESC		= 12,
-    LEN_F_CNT		= 4,
-    LEN_F_ESC		= 8,
-    LEN_BYTE		= 8,
-    LEN_PAD_DATA	= 8,
+typedef enum {
+    WS_SIN, WS_KBD, N_WINDOW_SHAPES
+} 
+Window_shape;
 
-    LEN_PC_COMM		= 8, 
+/* YT 970615 for Son_PP  */
+typedef enum {
+	MOVERLAPPED,
+	MNON_OVERLAPPED
+}
+Mdct_in,Imdct_out;
 
-    /* sfb 40, coef 672, pred bw of 15.75 kHz */
-    MAX_PRED_SFB	= 48,  // Max = 48, was 40
+typedef enum {
+    WT_LONG, 
+    WT_SHORT, 
+    WT_FLAT, 
+    WT_ADV,			/* Advanced flat window */
+    N_WINDOW_TYPES
+} 
+WINDOW_TYPE_AAC; 
 
-    ID_SCE 		= 0,
-    ID_CPE,
-    ID_CCE,
-    ID_LFE,
-    ID_DSE,
-    ID_PCE,
-    ID_FIL,
-    ID_END,
+typedef enum {                  /* ADVanced transform types */
+    LONG_BLOCK,
+    START_BLOCK,
+    SHORT_BLOCK,
+    STOP_BLOCK,
+    START_ADV_BLOCK,
+    STOP_ADV_BLOCK,
+    START_FLAT_BLOCK,
+    STOP_FLAT_BLOCK,
+    N_BLOCK_TYPES
+} 
+BLOCK_TYPE;
 
-    /* PLL's don't like idle channels! */
-    FILL_VALUE		= 0x55,
+typedef enum {  		/* Advanced window sequence (frame) types */
+    ONLY_LONG,
+    LONG_START, 
+    LONG_STOP,
+    SHORT_START, 
+    SHORT_STOP,
+    EIGHT_SHORT, 
+    SHORT_EXT_STOP,
+    NINE_SHORT,
+    OLD_START,
+    OLD_STOP,
+    N_WINDOW_SEQUENCES
+} 
+WINDOW_SEQUENCE;
 
-    /*
-     * program configuration element
-     */
-    LEN_PROFILE		= 2, 
-    LEN_SAMP_IDX	= 4, 
-    LEN_NUM_ELE		= 4, 
-    LEN_NUM_LFE		= 2, 
-    LEN_NUM_DAT		= 3, 
-    LEN_NUM_CCE		= 4, 
-    LEN_MIX_PRES	= 1, 
-    LEN_ELE_IS_CPE	= 1,
-    LEN_IND_SW_CCE	= 1,  
-    LEN_COMMENT_BYTES	= 8, 
-         
-    /*
-     * audio data interchange format header
-     */
-    LEN_ADIF_ID		= (32/8), 
-    LEN_COPYRT_PRES	= 1, 
-    LEN_COPYRT_ID	= (72/8), 
-    LEN_ORIG		= 1, 
-    LEN_HOME		= 1, 
-    LEN_BS_TYPE		= 1, 
-    LEN_BIT_RATE	= 23, 
-    LEN_NUM_PCE		= 4, 
-    LEN_ADIF_BF		= 20, 
-    XXX
-};
+
+/* 
+ * Raw bitstream constants
+ */
+#define LEN_SE_ID 3
+#define LEN_TAG 4
+#define LEN_GLOB_GAIN 8
+#define LEN_COM_WIN 1
+#define LEN_ICS_RESERV 1
+#define LEN_WIN_SEQ 2
+#define LEN_WIN_SH 1
+#define LEN_MAX_SFBL 6 
+#define LEN_MAX_SFBS 4 
+#define LEN_CB 4
+#define LEN_SCL_PCM 8
+#define LEN_PRED_PRES 1
+#define LEN_PRED_RST 1
+#define LEN_PRED_RSTGRP 5
+#define LEN_PRED_ENAB 1
+#define LEN_MASK_PRES 2
+#define LEN_MASK 1
+#define LEN_PULSE_PRES 1
+
+#define LEN_TNS_PRES 1
+#define LEN_TNS_NFILTL 2
+#define LEN_TNS_NFILTS 1
+#define LEN_TNS_COEFF_RES 1
+#define LEN_TNS_LENGTHL 6
+#define LEN_TNS_LENGTHS 4
+#define LEN_TNS_ORDERL 5
+#define LEN_TNS_ORDERS 3
+#define LEN_TNS_DIRECTION 1
+#define LEN_TNS_COMPRESS 1
+#define LEN_GAIN_PRES 1
+
+#define LEN_NEC_NPULSE 2 
+#define LEN_NEC_ST_SFB 6 
+#define LEN_NEC_POFF 5 
+#define LEN_NEC_PAMP 4 
+#define NUM_NEC_LINES 4 
+#define NEC_OFFSET_AMP 4 
+
+#define LEN_NCC 3
+#define LEN_IS_CPE 1
+#define LEN_CC_LR 1
+#define LEN_CC_DOM 1
+#define LEN_CC_SGN 1
+#define LEN_CCH_GES 2
+#define LEN_CCH_CGP 1
+#define LEN_D_CNT 4
+#define LEN_D_ESC 12
+#define LEN_F_CNT 4
+#define LEN_F_ESC 8
+#define LEN_BYTE 8
+#define LEN_PAD_DATA 8
+
+#define LEN_PC_COMM 8 
+
+#define ID_SCE 0
+#define ID_CPE 1
+#define ID_CCE 2
+#define ID_LFE 3
+#define ID_DSE 4
+#define ID_PCE 5
+#define ID_FIL 6
+#define ID_END 7
+
+/*
+ * program configuration element
+ */
+#define LEN_PROFILE 2
+#define LEN_SAMP_IDX 4
+#define LEN_NUM_ELE 4
+#define LEN_NUM_LFE 2
+#define LEN_NUM_DAT 3
+#define LEN_NUM_CCE 4
+#define LEN_MIX_PRES 1
+#define LEN_ELE_IS_CPE 1
+#define LEN_IND_SW_CCE 1
+#define LEN_COMMENT_BYTES 8
+	
+/*
+ * audio data interchange format header
+ */
+#define LEN_ADIF_ID (32/8)
+#define LEN_COPYRT_PRES 1
+#define LEN_COPYRT_ID (72/8)
+#define LEN_ORIG 1
+#define LEN_HOME 1
+#define LEN_BS_TYPE 1
+#define LEN_BIT_RATE 23
+#define LEN_NUM_PCE 4
+#define LEN_ADIF_BF 20
+
+typedef struct
+{
+    int is_present;  
+    int ms_used[MAX_SCFAC_BANDS];
+} MS_Info;
+
+typedef struct
+{
+    int present;	/* channel present */
+    int tag;		/* element tag */
+    int cpe;		/* 0 if single channel or lfe, 1 if channel pair */ 
+    int lfe;            /* 1 if lfe channel */             
+    int	common_window;	/* 1 if common window for cpe */
+    int	ch_is_left;	/* 1 if left channel of cpe */
+    int	paired_ch;	/* index of paired channel in cpe */
+    int widx;		/* window element index for this channel */
+    MS_Info ms_info;    /* MS information */
+} Ch_Info;
 
 #endif   /* #ifndef _interface_h_ */
 
--- a/mc_enc.h
+++ b/mc_enc.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.4 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.5 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -29,7 +29,7 @@
 #ifndef MC_ENC
 #define MC_ENC
 
-#include "all.h"
+#include "interface.h"
 
 void DetermineChInfo(Ch_Info* chInfo, int numChannels, int lfePresent);
 
--- a/ms.h
+++ b/ms.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.9 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.10 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -29,8 +29,6 @@
 #ifndef MS_ENC
 #define MS_ENC
 
-#include "all.h"
-#include "tf_main.h"
 #include "quant.h"
 
 
--- a/nok_ltp_common.h
+++ b/nok_ltp_common.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.3 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.4 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -34,15 +34,7 @@
   Purpose:	Number of short windows in one long window.
   Explanation:	-  */
 #ifndef MAX_SHORT_WINDOWS
-#define MAX_SHORT_WINDOWS NSHORT
-#endif
-
-/*
-  Macro:	MAX_SCFAC_BANDS
-  Purpose:	Maximum number of scalefactor bands in one frame.
-  Explanation:	-  */
-#ifndef MAX_SCFAC_BANDS
-#define MAX_SCFAC_BANDS MAXBANDS
+#define MAX_SHORT_WINDOWS MAX_SHORT_IN_LONG_BLOCK
 #endif
 
 /*
--- a/nok_ltp_enc.c
+++ b/nok_ltp_enc.c
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.13 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.14 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -35,8 +35,8 @@
 
 /*
   Interface to related modules.  */
-#include "tf_main.h"
 #include "interface.h"
+#include "transfo.h"
 #include "bitstream.h"
 #include "nok_ltp_common.h"
 #include "nok_pitch.h"
@@ -110,7 +110,7 @@
 		lt_status->pred_mdct[i] = 0;
 
 	lt_status->weight_idx = 0;
-	for(i=0; i<NSHORT; i++)
+	for(i=0; i<MAX_SHORT_IN_LONG_BLOCK; i++)
 		lt_status->sbk_prediction_used[i] = lt_status->delay[i] = 0;
 
 	for(i=0; i<MAX_SCFAC_BANDS; i++)
--- a/nok_ltp_enc.h
+++ b/nok_ltp_enc.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.3 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.4 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -29,6 +29,8 @@
 #ifndef _NOK_LTP_ENC_H
 #define _NOK_LTP_ENC_H
 
+#include "interface.h"
+#include "bitstream.h"
 #include "nok_ltp_common.h"
 
 extern void nok_init_lt_pred (NOK_LT_PRED_STATUS * lt_status);
--- a/nok_pitch.c
+++ b/nok_pitch.c
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.8 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.9 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -29,15 +29,9 @@
 /**************************************************************************
   External Objects Needed
   *************************************************************************/
-/*
-  Standard library declarations.  */
-#include <math.h>
-#include <stdio.h>
 
 /*
   Interface to related modules.  */
-#include "tf_main.h"
-#include "block.h"
 #include "interface.h"
 #include "nok_ltp_common.h"
 #include "nok_ltp_enc.h"
--- a/psych.c
+++ b/psych.c
@@ -21,18 +21,14 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.67 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
+  $Revision: 1.68 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
-#include <stdlib.h>
 #include <math.h>
-#include <memory.h>
-#include "tf_main.h"
 #include "psych.h"
 #include "transfo.h"
-#include "all.h"
 
 double sqrt2048, sqrt256;
 
@@ -358,11 +354,11 @@
     }
 
 	for(b = 0; b < part_tbl_long->len; b++) {
-		dyn_long.bmax[b] = pow(10, 1.25*(1-cos(PI*b/part_tbl_long->len))-2.5);
+		dyn_long.bmax[b] = pow(10, 1.25*(1-cos(M_PI*b/part_tbl_long->len))-2.5);
 //		dyn_long.bmax[b] = pow(10, -3*(0.5+0.5*(M_PI*(min(dyn_long.bval[b], 15.5)/15.5))));
 	}
 	for(b = 0; b < part_tbl_short->len; b++) {
-		dyn_short.bmax[b] = pow(10, 1.25*(1-cos(PI*b/part_tbl_short->len))-2.5);
+		dyn_short.bmax[b] = pow(10, 1.25*(1-cos(M_PI*b/part_tbl_short->len))-2.5);
 //		dyn_short.bmax[b] = pow(10, -3*(0.5+0.5*(M_PI*(min(dyn_short.bval[b], 15.5)/15.5))));
 	}
 
@@ -1137,13 +1133,13 @@
     else if( p1 == NPART_LONG ) p2 = 0;
 
     for(b = 0; b < part_tbl_long->len; b++) {
-		temp = psy_min( psy_stvar_long->nb[p1+b], 2.0*psy_stvar_long->nb[p2+b]);
+		temp = min( psy_stvar_long->nb[p1+b], 2.0*psy_stvar_long->nb[p2+b]);
 		if (temp > 0.01)
 			psy_stvar_long->nb[p1+b] = temp;
     }
 
     for(b = 0; b < part_tbl_short->len; b++){
-		temp = psy_min( psy_stvar_short->nb[0][b], 1.0*psy_stvar_short->last7_nb[b]);
+		temp = min( psy_stvar_short->nb[0][b], 1.0*psy_stvar_short->last7_nb[b]);
 		if (temp > 0.01)
 			psy_stvar_short->nb[0][b] = temp;
     }
@@ -1154,7 +1150,7 @@
 
 	for(i = 1;  i < MAX_SHORT_WINDOWS; i++){
 		for(b = 0; b < part_tbl_short->len; b++){
-			temp = psy_min( psy_stvar_short->nb[i][b], 1.0*psy_stvar_short->nb[i - 1][b]);
+			temp = min( psy_stvar_short->nb[i][b], 1.0*psy_stvar_short->nb[i - 1][b]);
 			if (temp > 0.01)
 				psy_stvar_short->nb[i][b] = temp;
 		}
--- a/psych.h
+++ b/psych.h
@@ -21,19 +21,26 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.21 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
+  $Revision: 1.22 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
-#include "all.h"
+#include "interface.h"
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
+#ifndef min
+#define min(a,b) ( (a) < (b) ? (a) : (b) )
+#endif
+#ifndef max
+#define max(a,b) ( (a) > (b) ? (a) : (b) )
+#endif
+
 typedef struct { 
-  long   sampling_rate;                   /* the following entries are for this sampling rate */
+  long   sampling_rate;  /* the following entries are for this sampling rate */
   int    num_cb_long;
   int    num_cb_short;
   int    cb_width_long[NSFB_LONG];
@@ -180,10 +187,6 @@
   CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS]
 );
 
-/* added by T. Okada( 1997.07.10 ) */
-/* Jul 10 */
-#define psy_max(x,y) ((x) > (y) ? (x) : (y))
-#define psy_min(x,y) ((x) < (y) ? (x) : (y))
 #define psy_sqr(x) ((x)*(x))
 
 
--- a/quant.c
+++ b/quant.c
@@ -21,17 +21,15 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.9 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
+  $Revision: 1.10 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
 #include <math.h>
-#include <string.h>
 #include "aacenc.h"
 #include "quant.h"
 #include "bitstream.h"
-#include "tf_main.h"
 #include "pulse.h"
 #include "huffman.h"
 #include "aac_se_enc.h"
@@ -47,7 +45,7 @@
 int pns_sfb_start = 1000;         /* lower border for Perceptual Noise Substitution
                                       (off by default) */
 
-double ATH[SFB_NUM_MAX];
+double ATH[MAX_SCFAC_BANDS];
 
 double ATHformula(double f)
 {
@@ -65,7 +63,7 @@
 }
 
 
-void compute_ath(AACQuantInfo *quantInfo, double ATH[SFB_NUM_MAX])
+void compute_ath(AACQuantInfo *quantInfo, double ATH[MAX_SCFAC_BANDS])
 {
 	int sfb,i,start=0,end=0;
 	double ATH_f;
@@ -347,7 +345,7 @@
 
 int inner_loop(AACQuantInfo *quantInfo,
 			   double *pow_spectrum,
-			   int quant[NUM_COEFF],
+			   int quant[BLOCK_LEN_LONG],
 			   int max_bits)
 {
 	int bits;
@@ -365,7 +363,7 @@
 
 int search_common_scalefac(AACQuantInfo *quantInfo,
 						   double *pow_spectrum,
-						   int quant[NUM_COEFF],
+						   int quant[BLOCK_LEN_LONG],
 						   int desired_rate)
 {
 	int flag_GoneOver = 0;
@@ -410,10 +408,10 @@
 
 int calc_noise(AACQuantInfo *quantInfo,
 				double *p_spectrum,
-				int quant[NUM_COEFF],
-				double requant[NUM_COEFF],
-				double error_energy[SFB_NUM_MAX],
-				double allowed_dist[SFB_NUM_MAX],
+				int quant[BLOCK_LEN_LONG],
+				double requant[BLOCK_LEN_LONG],
+				double error_energy[MAX_SCFAC_BANDS],
+				double allowed_dist[MAX_SCFAC_BANDS],
 				double *over_noise,
 				double *tot_noise,
 				double *max_noise
@@ -519,7 +517,7 @@
 
 
 int count_bits(AACQuantInfo* quantInfo,
-			   int quant[NUM_COEFF]
+			   int quant[BLOCK_LEN_LONG]
 			   )
 {
 	int i, bits = 0;
@@ -594,8 +592,8 @@
 //			   ,int bitRate
                            )
 {
-	int quant[NUM_COEFF];
-	int s_quant[NUM_COEFF];
+	int quant[BLOCK_LEN_LONG];
+	int s_quant[BLOCK_LEN_LONG];
 	int i;
 //	int j=0;
 	int k;
@@ -602,14 +600,14 @@
 	double max_dct_line = 0;
 //	int global_gain;
 	int store_common_scalefac;
-	int best_scale_factor[SFB_NUM_MAX];
-	double pow_spectrum[NUM_COEFF];
-	double requant[NUM_COEFF];
+	int best_scale_factor[MAX_SCFAC_BANDS];
+	double pow_spectrum[BLOCK_LEN_LONG];
+	double requant[BLOCK_LEN_LONG];
 	int sb;
 	int extra_bits;
 //	int max_bits;
-//	int output_book_vector[SFB_NUM_MAX*2];
-	double SigMaskRatio[SFB_NUM_MAX];
+//	int output_book_vector[MAX_SCFAC_BANDS*2];
+	double SigMaskRatio[MAX_SCFAC_BANDS];
 	MS_Info *ms_info;
 	int *ptr_book_vector;
 
@@ -626,7 +624,7 @@
 	double noise_thresh;
 	double sfQuantFac;
 	double over_noise, tot_noise, max_noise;
-	double noise[SFB_NUM_MAX];
+	double noise[MAX_SCFAC_BANDS];
 	double best_max_noise = 0;
 	double best_over_noise = 0;
 	double best_tot_noise = 0;
@@ -633,7 +631,7 @@
 //	static int init = -1;
 
 	/* Set block type in quantization info */
-	quantInfo -> block_type = block_type[MONO_CHAN];
+	quantInfo -> block_type = block_type[0];
 
 #if 0
 	if (init != quantInfo->block_type) {
@@ -650,10 +648,10 @@
 		/* Now compute interleaved sf bands and spectrum */
 		sort_for_grouping(
 			quantInfo,                       /* ptr to quantization information */
-			sfb_width_table[MONO_CHAN],      /* Widths of single window */
+			sfb_width_table[0],      /* Widths of single window */
 			p_spectrum,                      /* Spectral values, noninterleaved */
 			SigMaskRatio,
-			PsySigMaskRatio[MONO_CHAN]
+			PsySigMaskRatio[0]
 			);
 
 		extra_bits = 51;
@@ -668,8 +666,8 @@
 			k=0;
 			for( i=0; i< quantInfo -> nr_of_sfb; i++ ){
 				sfb_offset[i] = k;
-				k +=sfb_width_table[MONO_CHAN][i];
-				SigMaskRatio[i]=PsySigMaskRatio[MONO_CHAN][i];
+				k +=sfb_width_table[0][i];
+				SigMaskRatio[i]=PsySigMaskRatio[0][i];
 			}
 			sfb_offset[i] = k;
 			extra_bits = 100; /* header bits and more ... */
@@ -701,9 +699,9 @@
 				int w;
 				for (w=0;w<numWindowsThisGroup;w++) {
 					int bandNum = (w+windowOffset)*maxBand + b;
-					sum += energy[MONO_CHAN][bandNum];
+					sum += energy[0][bandNum];
 				}
-				energy[MONO_CHAN][sfb_index] = sum/numWindowsThisGroup;
+				energy[0][sfb_index] = sum/numWindowsThisGroup;
 				sfb_index++;
 			}
 			windowOffset += numWindowsThisGroup;
@@ -726,7 +724,7 @@
     for(sb=0; sb < quantInfo->nr_of_sfb; sb++ )
 		quantInfo->pns_sfb_flag[sb] = 0;
 
-//	if (block_type[MONO_CHAN] != ONLY_SHORT_WINDOW) {     /* long blocks only */
+//	if (block_type[0] != ONLY_SHORT_WINDOW) {     /* long blocks only */
 		for(sb = pns_sfb_start; sb < quantInfo->nr_of_sfb; sb++ ) {
 			/* Calc. pseudo scalefactor */
 			if (energy[0][sb] == 0.0) {
@@ -735,7 +733,7 @@
 			}
 
 			if ((ms_info->is_present)&&(!ms_info->ms_used[sb])) {
-				if ((10*log10(energy[MONO_CHAN][sb]*sfb_width_table[0][sb]+1e-60)<70)||(SigMaskRatio[sb] > 1.0)) {
+				if ((10*log10(energy[0][sb]*sfb_width_table[0][sb]+1e-60)<70)||(SigMaskRatio[sb] > 1.0)) {
 					quantInfo->pns_sfb_flag[sb] = 1;
 					quantInfo->pns_sfb_nrg[sb] = (int) (2.0 * log(energy[0][sb]*sfb_width_table[0][sb]+1e-60) / log(2.0) + 0.5) + PNS_SF_OFFSET;
 
@@ -750,10 +748,10 @@
 
 	/* Compute allowed distortion */
 	for(sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-		allowed_dist[MONO_CHAN][sb] = energy[MONO_CHAN][sb] * SigMaskRatio[sb];
-//		if (allowed_dist[MONO_CHAN][sb] < ATH[sb]) {
+		allowed_dist[0][sb] = energy[0][sb] * SigMaskRatio[sb];
+//		if (allowed_dist[0][sb] < ATH[sb]) {
 //			printf("%d Yes\n", sb);
-//			allowed_dist[MONO_CHAN][sb] = ATH[sb];
+//			allowed_dist[0][sb] = ATH[sb];
 //		}
 //		printf("%d\t\t%.3f\n", sb, SigMaskRatio[sb]);
 	}
@@ -760,7 +758,7 @@
 
 	/** find the maximum spectral coefficient **/
 	/* Bug fix, 3/10/98 CL */
-	/* for(i=0; i<NUM_COEFF; i++){ */
+	/* for(i=0; i<BLOCK_LEN_LONG; i++){ */
 	for(i=0; i < sfb_offset[quantInfo->nr_of_sfb]; i++){
 		pow_spectrum[i] = (pow(ABS(p_spectrum[0][i]), 0.75));
 		sign[i] = sgn(p_spectrum[0][i]);
@@ -833,7 +831,7 @@
 				for (sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
 					best_scale_factor[sb] = scale_factor[sb];
 				}
-				memcpy(s_quant, quant, sizeof(int)*NUM_COEFF);
+				memcpy(s_quant, quant, sizeof(int)*BLOCK_LEN_LONG);
 			}
 		}
 
@@ -985,7 +983,7 @@
 		for (k=0; k<*nr_of_sfb; k++) {
 			for (j=0; j < window_group_length[i]; j++) {
 				for (ii=0;ii< sfb_width_table[k];ii++)
-					tmp[index++] = p_spectrum[MONO_CHAN][ii+ sfb_offset[k] + 128*j +group_offset];
+					tmp[index++] = p_spectrum[0][ii+ sfb_offset[k] + 128*j +group_offset];
 			}
 		}
 		group_offset +=  128*window_group_length[i];
@@ -992,7 +990,7 @@
 	}
 
 	for (k=0; k<1024; k++){
-		p_spectrum[MONO_CHAN][k] = tmp[k];
+		p_spectrum[0][k] = tmp[k];
 	}
 
 	/* now calc the new sfb_offset table for the whole p_spectrum vector*/
@@ -1054,8 +1052,8 @@
 
 
 int compute_scalefacs(AACQuantInfo* quantInfo,
-					  int sf[SFB_NUM_MAX],
-					  int scalefac[SFB_NUM_MAX])
+					  int sf[MAX_SCFAC_BANDS],
+					  int scalefac[MAX_SCFAC_BANDS])
 {
 	int sfb;
 	int maxover;
@@ -1187,12 +1185,12 @@
 				  double pow_quant_orig[1024],
 				  double allowed_dist[SFB_NUM_MAX],
 				  int quant[1024], int minbits, int maxbits,
-				  int scalefac[SFB_NUM_MAX])
+				  int scalefac[MAX_SCFAC_BANDS])
 {
 	int start,end,bw,sfb,l, vbrmax;
 	int bits_used;
-	int vbrsf[SFB_NUM_MAX];
-	int save_sf[SFB_NUM_MAX];
+	int vbrsf[MAX_SCFAC_BANDS];
+	int save_sf[MAX_SCFAC_BANDS];
 	int maxover0,maxover1,maxover,mover;
 	int ifqstep;
 	double pow_quant[1024];
@@ -1229,12 +1227,12 @@
 
 
 	/* save a copy of vbrsf, incase we have to recomptue scalefacs */
-	memcpy(&save_sf,&vbrsf,sizeof(int)*SFB_NUM_MAX);
+	memcpy(&save_sf,&vbrsf,sizeof(int)*MAX_SCFAC_BANDS);
 
 
 	do {
 
-		memset(scalefac,0,sizeof(int)*SFB_NUM_MAX);
+		memset(scalefac,0,sizeof(int)*MAX_SCFAC_BANDS);
 
 		maxover0=0;
 		maxover1=0;
@@ -1311,7 +1309,7 @@
 
 
 			--vbrmax;
-			memcpy(&vbrsf,&save_sf,sizeof(int)*SFB_NUM_MAX);
+			memcpy(&vbrsf,&save_sf,sizeof(int)*MAX_SCFAC_BANDS);
 			memcpy(pow_quant, pow_quant_orig, sizeof(pow_quant));
 		}
 
@@ -1365,15 +1363,15 @@
 			   Ch_Info* ch_info
                )
 {
-	int quant[NUM_COEFF];
+	int quant[BLOCK_LEN_LONG];
 	int i;
 	int k;
 	double max_dct_line = 0;
-	double pow_spectrum[NUM_COEFF];
-	double requant[NUM_COEFF];
+	double pow_spectrum[BLOCK_LEN_LONG];
+	double requant[BLOCK_LEN_LONG];
 	int sb;
 	int extra_bits;
-	double SigMaskRatio[SFB_NUM_MAX];
+	double SigMaskRatio[MAX_SCFAC_BANDS];
 	MS_Info *ms_info;
 	int *ptr_book_vector;
 
@@ -1386,7 +1384,7 @@
 	int best_over = 100;
 	double sfQuantFac;
 	double over_noise, tot_noise, max_noise;
-	double noise[SFB_NUM_MAX];
+	double noise[MAX_SCFAC_BANDS];
 	double best_max_noise = 0;
 	double best_over_noise = 0;
 	double best_tot_noise = 0;
@@ -1400,7 +1398,7 @@
 	int used_bits;
 
 	/* Set block type in quantization info */
-	quantInfo -> block_type = block_type[MONO_CHAN];
+	quantInfo -> block_type = block_type[0];
 
 	sfQuantFac = pow(2.0, 0.1875);
 
@@ -1410,10 +1408,10 @@
 		/* Now compute interleaved sf bands and spectrum */
 		sort_for_grouping(
 			quantInfo,                       /* ptr to quantization information */
-			sfb_width_table[MONO_CHAN],      /* Widths of single window */
+			sfb_width_table[0],      /* Widths of single window */
 			p_spectrum,                      /* Spectral values, noninterleaved */
 			SigMaskRatio,
-			PsySigMaskRatio[MONO_CHAN]
+			PsySigMaskRatio[0]
 			);
 
 		extra_bits = 51;
@@ -1428,8 +1426,8 @@
 			k=0;
 			for( i=0; i< quantInfo -> nr_of_sfb; i++ ){
 				sfb_offset[i] = k;
-				k +=sfb_width_table[MONO_CHAN][i];
-				SigMaskRatio[i]=PsySigMaskRatio[MONO_CHAN][i];
+				k +=sfb_width_table[0][i];
+				SigMaskRatio[i]=PsySigMaskRatio[0][i];
 			}
 			sfb_offset[i] = k;
 			extra_bits = 100; /* header bits and more ... */
@@ -1461,9 +1459,9 @@
 				int w;
 				for (w=0;w<numWindowsThisGroup;w++) {
 					int bandNum = (w+windowOffset)*maxBand + b;
-					sum += energy[MONO_CHAN][bandNum];
+					sum += energy[0][bandNum];
 				}
-				energy[MONO_CHAN][sfb_index] = sum/numWindowsThisGroup;
+				energy[0][sfb_index] = sum/numWindowsThisGroup;
 				sfb_index++;
 			}
 			windowOffset += numWindowsThisGroup;
@@ -1494,7 +1492,7 @@
 		}
 
 		if ((ms_info->is_present)&&(!ms_info->ms_used[sb])) {
-			if ((10*log10(energy[MONO_CHAN][sb]*sfb_width_table[0][sb]+1e-60)<70)||(SigMaskRatio[sb] > 1.0)) {
+			if ((10*log10(energy[0][sb]*sfb_width_table[0][sb]+1e-60)<70)||(SigMaskRatio[sb] > 1.0)) {
 				quantInfo->pns_sfb_flag[sb] = 1;
 				quantInfo->pns_sfb_nrg[sb] = (int) (2.0 * log(energy[0][sb]*sfb_width_table[0][sb]+1e-60) / log(2.0) + 0.5) + PNS_SF_OFFSET;
 
@@ -1508,7 +1506,7 @@
 
 	/** find the maximum spectral coefficient **/
 	/* Bug fix, 3/10/98 CL */
-	/* for(i=0; i<NUM_COEFF; i++){ */
+	/* for(i=0; i<BLOCK_LEN_LONG; i++){ */
 	for(i=0; i < sfb_offset[quantInfo->nr_of_sfb]; i++){
 		pow_spectrum[i] = (pow(ABS(p_spectrum[0][i]), 0.75));
 		sign[i] = sgn(p_spectrum[0][i]);
--- a/quant.h
+++ b/quant.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.3 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
+  $Revision: 1.4 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -31,10 +31,9 @@
 
 #include "pulse.h"
 #include "interface.h"
-#include "tf_main.h"
 #include "tns.h"
-#include "all.h"
 #include "nok_ltp_common.h"
+#include "bitstream.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -45,15 +44,20 @@
 
 /* assumptions for the first run of this quantizer */
 #define CHANNEL  1
-#define NUM_COEFF  BLOCK_LEN_LONG       /* now using BLOCK_LEN_LONG of block.h */
 #define MAGIC_NUMBER  0.4054
 #define MAX_QUANT 8192
 #define SF_OFFSET 100
 #define ABS(A) ((A) < 0 ? (-A) : (A))
 #define sgn(A) ((A) > 0 ? (1) : (-1))
-#define SFB_NUM_MAX MAX_SCFAC_BANDS     /* now using MAX_SCFAC_BANDS of tf_main.h */
 
+#define MAXFAC 121   /* maximum scale factor */
+#define MIDFAC (MAXFAC-1)/2
+#define SF_OFFSET 100   /* global gain must be positive */
 
+#define INTENSITY_HCB 15
+#define INTENSITY_HCB2 14
+
+
 extern int pns_sfb_start;                        /* lower border for PNS */
 
 
@@ -65,12 +69,12 @@
   int nr_of_sfb;                        /* Number of scalefactor bands, interleaved */
   int spectralCount;                    /* Number of spectral data coefficients */
   enum WINDOW_TYPE block_type;	        /* Block type */      
-  int scale_factor[SFB_NUM_MAX];        /* Scalefactor data array , interleaved */			
+  int scale_factor[MAX_SCFAC_BANDS];        /* Scalefactor data array , interleaved */			
   int sfb_offset[250];                  /* Scalefactor spectral offset, interleaved */
-  int book_vector[SFB_NUM_MAX];         /* Huffman codebook selected for each sf band */
-  int data[5*NUM_COEFF];                /* Data of spectral bitstream elements, for each spectral pair, 
+  int book_vector[MAX_SCFAC_BANDS];         /* Huffman codebook selected for each sf band */
+  int data[5*BLOCK_LEN_LONG];                /* Data of spectral bitstream elements, for each spectral pair, 
                                            5 elements are required: 1*(esc)+2*(sign)+2*(esc value)=5 */
-  int len[5*NUM_COEFF];                 /* Lengths of spectral bitstream elements */
+  int len[5*BLOCK_LEN_LONG];                 /* Lengths of spectral bitstream elements */
   int num_window_groups;                /* Number of window groups */
   int window_group_length
     [MAX_SHORT_IN_LONG_BLOCK];          /* Length (in windows) of each window group */
@@ -78,13 +82,13 @@
   Window_shape window_shape;            /* Window shape parameter */
   Window_shape prev_window_shape;       /* Previous window shape parameter */
   short pred_global_flag;               /* Global prediction enable flag */
-  int pred_sfb_flag[SFB_NUM_MAX];       /* Prediction enable flag for each scalefactor band */
+  int pred_sfb_flag[MAX_SCFAC_BANDS];       /* Prediction enable flag for each scalefactor band */
   int reset_group_number;               /* Prediction reset group number */
   TNS_INFO* tnsInfo;                    /* Ptr to tns data */
   AACPulseInfo pulseInfo;
   NOK_LT_PRED_STATUS *ltpInfo;          /* Prt to LTP data */
-  int pns_sfb_nrg[SFB_NUM_MAX];
-  int pns_sfb_flag[SFB_NUM_MAX];
+  int pns_sfb_nrg[MAX_SCFAC_BANDS];
+  int pns_sfb_flag[MAX_SCFAC_BANDS];
   int profile;
   int srate_idx;
 } AACQuantInfo;
@@ -92,17 +96,17 @@
 
 void quantize(AACQuantInfo *quantInfo,
 			  double *pow_spectrum,
-			  int quant[NUM_COEFF]
+			  int quant[BLOCK_LEN_LONG]
 			  );
 void dequantize(AACQuantInfo *quantInfo,
 				double *p_spectrum,
-				int quant[NUM_COEFF],
-				double requant[NUM_COEFF],
-				double error_energy[SFB_NUM_MAX]
+				int quant[BLOCK_LEN_LONG],
+				double requant[BLOCK_LEN_LONG],
+				double error_energy[MAX_SCFAC_BANDS]
 				);
 int count_bits(AACQuantInfo* quantInfo,
-			   int quant[NUM_COEFF]
-//			   ,int output_book_vector[SFB_NUM_MAX*2]
+			   int quant[BLOCK_LEN_LONG]
+//			   ,int output_book_vector[MAX_SCFAC_BANDS*2]
                            );
 
 
--- a/tf_main.h
+++ /dev/null
@@ -1,143 +1,0 @@
-/*
- *	Main definitions
- *
- *	Copyright (c) 1999 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, 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; see the file COPYING.  If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/**************************************************************************
-  Version Control Information			Method: CVS
-  Identifiers:
-  $Revision: 1.10 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _TF_MAIN_H_INCLUDED
-#define _TF_MAIN_H_INCLUDED
-
-#include "bitstream.h"
-#include "block.h"
-
-/* AAC Profile */
-enum AAC_PROFILE { MAIN, LOW, SSR };
-
-/* select different pre-/post- processing modules TK */
-enum PP_MOD_SELECT { NONE=0x0, AAC_PP=0x1 };
-
-/* select different T/F modules */
-enum TF_MOD_SELECT { VM_TF_SOURCE=0x1, MDCT_AAC=0x2, MDCT_UER=0x4, QMF_MDCT_SONY=0x8, LOW_DELAY_UNH=0x10 };
-
-/* select different Q&C modules */
-enum QC_MOD_SELECT { VM_QC_SOURCE=0x1, AAC_QC=0x2, MDCT_VALUES_16BIT=0x4, UER_QC=0x8, NTT_VQ=0x10 , AAC_PRED=0x20};
-
-/* name the audio channels */
-enum CHANN_ASS { 
-  MONO_CHAN=0,
-  LEFT_CHAN=0, 
-  RIGHT_CHAN=1,
-  MAX_CHANNELS
-};
-
-/* audio channel configuration coding */
-enum CH_CONFIG { CHC_MONO, CHC_DUAL, CHC_JOINT_DUAL, CHC_5CHAN, CHC_MODES };
-
-/* transport layer type */ /* added "NO_SYNCWORD" by NI (28 Aug. 1996) */
-enum TRANSPORT_STREAM { NO_TSTREAM, AAC_RAWDATA_TSTREAM, LENINFO_TSTREAM,
-		        NO_SYNCWORD};
-
-enum SR_CODING { SR8000, SR11025, SR12000, SR16000, SR22050, SR24000, SR32000, SR44100, SR48000, SR64000, SR88200, SR96000, MAX_SAMPLING_RATES };
-
-enum WINDOW_TYPE { 
-  ONLY_LONG_WINDOW, 
-  LONG_SHORT_WINDOW, 
-  ONLY_SHORT_WINDOW,
-  SHORT_LONG_WINDOW,
-  SHORT_MEDIUM_WINDOW,
-  MEDIUM_LONG_WINDOW,
-  LONG_MEDIUM_WINDOW,
-  MEDIUM_SHORT_WINDOW,
-  ONLY_MEDIUM_WINDOW,
-  
-  LONG_START_WINDOW,
-  EIGHT_SHORT_WINDOW,
-  LONG_STOP_WINDOW
-};    
-
-enum AAC_WINDOW_SEQUENCE { /* TK */
-  ONLY_LONG_SEQUENCE = ONLY_LONG_WINDOW,
-  LONG_START_SEQUENCE = LONG_SHORT_WINDOW,
-  EIGHT_SHORT_SEQUENCE = ONLY_SHORT_WINDOW,
-  LONG_STOP_SEQUENCE = SHORT_LONG_WINDOW
-};
-
-enum WIN_SWITCH_MODE {
-  STATIC_LONG,
-  STATIC_MEDIUM,
-  STATIC_SHORT,
-  LS_STARTSTOP_SEQUENCE,
-  LM_STARTSTOP_SEQUENCE,
-  MS_STARTSTOP_SEQUENCE,
-  LONG_SHORT_SEQUENCE,
-  LONG_MEDIUM_SEQUENCE,
-  MEDIUM_SHORT_SEQUENCE,
-  LONG_MEDIUM_SHORT_SEQUENCE,
-  FFT_PE_WINDOW_SWITCHING
-};
-
-#define NSFB_LONG  51
-#define NSFB_SHORT 15
-#define MAX_SHORT_IN_LONG_BLOCK 8
-
-#define MAX_SHORT_WINDOWS 8
-
-/* if static memory allocation is used, this value tells the max. nr of
-   audio channels to be supported */
-/*#define MAX_TIME_CHANNELS (MAX_CHANNELS)*/
-#define MAX_TIME_CHANNELS 6
-
-/* max. number of scale factor bands */
-#define MAX_SCFAC_BANDS ((NSFB_SHORT+1)*MAX_SHORT_IN_LONG_BLOCK)
-
-void freq2buffer(
-  double           p_in_data[],
-  double           p_out_data[],
-  double           p_overlap[],
-  enum WINDOW_TYPE block_type,
-  Window_shape     wfun_select,      
-  Window_shape     wfun_select_prev,   
-  Mdct_in	   overlap_select
-);
-
-void buffer2freq(                    
-  double           p_in_data[],      
-  double           p_out_mdct[],
-  double           p_overlap[],
-  enum WINDOW_TYPE block_type,
-  Window_shape     wfun_select,      
-  Window_shape     wfun_select_prev,   
-  Mdct_in          overlap_select      
-);
-
-void specFilter (double p_in[],
-		 double p_out[],
-		 int  samp_rate,
-		 int lowpass_freq,
-		 int    specLen
-);
-
-#endif	/* #ifndef _TF_MAIN_H_INCLUDED */
-
--- a/tns.c
+++ b/tns.c
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.11 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
+  $Revision: 1.12 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -131,8 +131,8 @@
 
 	switch( blockType ) {
 	case ONLY_SHORT_WINDOW :
-		numberOfWindows = NSHORT;
-		windowSize = SN2;
+		numberOfWindows = MAX_SHORT_IN_LONG_BLOCK;
+		windowSize = BLOCK_LEN_SHORT;
 		startBand = tnsInfo->tnsMinBandNumberShort;
 		stopBand = numberOfBands; 
 		lengthInBands = stopBand-startBand;
@@ -350,8 +350,8 @@
 	double iqfac,iqfac_m;
 	int i;
 
-	iqfac = ((1<<(coeffRes-1))-0.5)/(PI/2);
-	iqfac_m = ((1<<(coeffRes-1))+0.5)/(PI/2);
+	iqfac = ((1<<(coeffRes-1))-0.5)/(M_PI/2);
+	iqfac_m = ((1<<(coeffRes-1))+0.5)/(M_PI/2);
 
 	/* Quantize and inverse quantize */
 	for (i=1;i<=fOrder;i++) {
--- a/tns.h
+++ b/tns.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.5 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
+  $Revision: 1.6 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
  
@@ -29,9 +29,6 @@
 #ifndef _TNS_H_INCLUDED
 #define _TNS_H_INCLUDED
  
-#include <math.h>
-#include <stdio.h>
-#include "tf_main.h"
 #include "interface.h"
 
 /*************************/
@@ -42,7 +39,9 @@
 #define DEF_TNS_COEFF_THRESH 0.1
 #define DEF_TNS_COEFF_RES 4
 #define DEF_TNS_RES_OFFSET 3
-#define PI C_PI
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
 #ifndef min
 #define min(a,b) ( (a) < (b) ? (a) : (b) )
 #endif
@@ -79,7 +78,7 @@
   int tnsMaxBandsShort;
   int tnsMaxOrderLong;
   int tnsMaxOrderShort;
-  TNS_WINDOW_DATA windowData[NSHORT];	/* TNS data per window */
+  TNS_WINDOW_DATA windowData[MAX_SHORT_IN_LONG_BLOCK];	/* TNS data per window */
 } TNS_INFO;
 
 
--- a/transfo.c
+++ b/transfo.c
@@ -21,14 +21,12 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.17 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
+  $Revision: 1.18 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
 #include <math.h>
-#include <string.h>
-#include "all.h"
 #include "transfo.h"
 #include "shape_win.h"
 
--- a/transfo.h
+++ b/transfo.h
@@ -21,13 +21,44 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.10 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
+  $Revision: 1.11 $
+  $Date: 2000/10/05 13:04:05 $ (check in)
   $Author: menno $
   *************************************************************************/
 
 #ifndef TRANSFORM_H
 #define TRANSFORM_H
+
+#include "interface.h"
+
+
+void freq2buffer(
+  double           p_in_data[],
+  double           p_out_data[],
+  double           p_overlap[],
+  enum WINDOW_TYPE block_type,
+  Window_shape     wfun_select,      
+  Window_shape     wfun_select_prev,   
+  Mdct_in	   overlap_select
+);
+
+void buffer2freq(                    
+  double           p_in_data[],      
+  double           p_out_mdct[],
+  double           p_overlap[],
+  enum WINDOW_TYPE block_type,
+  Window_shape     wfun_select,      
+  Window_shape     wfun_select_prev,   
+  Mdct_in          overlap_select      
+);
+
+void specFilter (double p_in[],
+		 double p_out[],
+		 int  samp_rate,
+		 int lowpass_freq,
+		 int    specLen
+);
+
 
 // Use this for decoder - single precision
 //typedef float fftw_real;