shithub: aacenc

Download patch

ref: f1da21d5b79294f24d55fc5ea8aaa6ff0a076987
parent: 06e2bdb10725e93bfdfae7c8c5744692d5f5b49b
author: menno <menno>
date: Wed Jan 17 06:21:40 EST 2001

no message

diff: cannot open b/frontend//null: file does not exist: 'b/frontend//null' diff: cannot open b/include//null: file does not exist: 'b/include//null' diff: cannot open b/libfaac//null: file does not exist: 'b/libfaac//null'
--- a/Makefile
+++ /dev/null
@@ -1,43 +1,0 @@
-# On X86 machines it is HIGHLY Recomended that if you want to compile with any
-# -O setting you NOT use -O. use -O2 to -O6. -O is broken. Also note that you
-# MUST use -ffast-math with -O2 to -O6. If you do not, it will be SLOWER then
-# using no -O altogether. On a Pentium 3, the fastest optimizations are:
-# -O6 -march=i686 -finline-functions -funroll-loops -fomit-frame-pointer
-# -ffast-math
-#
-prefix = /usr/local
-
-DESTDIR = 
-
-SOURCE=aac_se_enc.c bitstream.c enc_tf.c encoder.c mc_enc.c ms.c psych.c pulse.c tns.c transfo.c fastfft.c ltp_enc.c rateconv.c faac.c quant.c huffman.c
-
-OBJ = $(SOURCE:.c=.o)
-
-CC=gcc
-
-#PROFILE_OPTS = -g -pg -a
-
-CC_OPTS=-DHAS_ULONG $(CFLAGS) $(PROFILE_OPTS)
-LD_OPTS=
-
-TARGETS=faac
-
-all: $(TARGETS)
-
-faac: $(OBJ) Makefile
-	$(CC) $(LD_OPTS) -o faac $(OBJ) -lsndfile -lm $(PROFILE_OPTS)
-
-%.o: %.c
-	$(CC) $(CC_OPTS) -c $< -o $@	
-
-install:
-	@if test -f faac; then \
-	  install -d ${DESTDIR}${prefix}/bin && \
-	  install faac ${DESTDIR}${prefix}/bin; \
-	fi
-
-uninstall:
-	@rm -f ${DESTDIR}${prefix}/bin/faac
-
-clean:
-	@rm -f *.o $(TARGETS)
--- a/aac_se_enc.c
+++ /dev/null
@@ -1,519 +1,0 @@
-/*
- *	Writing/counting AAC syntactic elements
- *
- *	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.15 $
-  $Date: 2000/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include "aac_se_enc.h"
-#include "quant.h"
-#include "huffman.h"
-
-int max_pred_sfb;
-
-/*****************************************************************************/
-/* WriteAACFillBits(...)                                                     */
-/* Write fill_elements to the bitstream.	                             */
-/* Number of bits written is LEN_SE_ID + FIL_COUNT_LEN + a multiple of 8.    */
-/* Return number of bits left over (less than 7 ).                           */
-/*****************************************************************************/
-int WriteAACFillBits(BsBitStream* ptrBs,  /* Pointer to bitstream */
-		     int numBits,         /* Number of bits needed to fill */
-		     int writeFlag)
-{
-  int numberOfBitsLeft=numBits;
-
-  /* Need at least (LEN_SE_ID + LEN_F_CNT) bits for a fill_element */
-  int minNumberOfBits = LEN_SE_ID + LEN_F_CNT;
-  while (numberOfBitsLeft>=minNumberOfBits) {
-    int numberOfBytes;
-    int maxCount;
-
-    if (writeFlag) {
-      BsPutBit(ptrBs,ID_FIL,LEN_SE_ID);	/* Write fill_element ID */
-    }
-    numberOfBitsLeft-=minNumberOfBits;	/* Subtract for ID,count */
-
-    numberOfBytes=(int)(numberOfBitsLeft/LEN_BYTE);
-    maxCount = (1<<LEN_F_CNT) - 1;  /* Max count without escaping */
-
-    /* if we have less than maxCount bytes, write them now */
-    if (numberOfBytes<maxCount) {
-      int i;
-      if (writeFlag) {
-	BsPutBit(ptrBs,numberOfBytes,LEN_F_CNT);
-	for (i=0;i<numberOfBytes;i++) {
-	  BsPutBit(ptrBs,0,LEN_BYTE);
-        }
-      }
-      /* otherwise, we need to write an escape count */
-    }
-    else {
-      int maxEscapeCount,maxNumberOfBytes,escCount;
-      int i;
-      if (writeFlag) {
-	BsPutBit(ptrBs,maxCount,LEN_F_CNT);
-      }
-      maxEscapeCount = (1<<LEN_BYTE) - 1;  /* Max escape count */
-      maxNumberOfBytes = maxCount + maxEscapeCount;
-      numberOfBytes = (numberOfBytes > maxNumberOfBytes ) ? (maxNumberOfBytes) : (numberOfBytes);
-      escCount = numberOfBytes - maxCount;
-      if (writeFlag) {
-	BsPutBit(ptrBs,escCount,LEN_BYTE);
-	for (i=0;i<numberOfBytes-1;i++) {
-	  BsPutBit(ptrBs,0,LEN_BYTE);
-        }
-      }
-    }
-    numberOfBitsLeft -= LEN_BYTE*numberOfBytes;
-  }
-  return numberOfBitsLeft;
-}
-
-int WriteADTSHeader(AACQuantInfo* quantInfo,   /* AACQuantInfo structure */
-		    BsBitStream* fixedStream,  /* Pointer to bitstream */
-		    int used_bits,
-		    int writeFlag)             /* 1 means write, 0 means count only */
-{
-  if (writeFlag) {
-    /* Fixed ADTS header */
-    BsPutBit(fixedStream, 0xFFFF, 12); // 12 bit Syncword
-    BsPutBit(fixedStream, 1, 1); // ID
-    BsPutBit(fixedStream, 0, 2); // layer
-    BsPutBit(fixedStream, 1, 1); // protection absent
-    BsPutBit(fixedStream, quantInfo->profile, 2); // profile
-    BsPutBit(fixedStream, quantInfo->srate_idx, 4); // sampling rate
-    BsPutBit(fixedStream, 0, 1); // private bit
-    BsPutBit(fixedStream, 1, 3); // ch. config (must be > 0)
-    BsPutBit(fixedStream, 0, 1); // original/copy
-    BsPutBit(fixedStream, 0, 1); // home
-    BsPutBit(fixedStream, 0, 2); // emphasis
-
-    /* Variable ADTS header */
-    BsPutBit(fixedStream, 0, 1); // copyr. id. bit
-    BsPutBit(fixedStream, 0, 1); // copyr. id. start
-    BsPutBit(fixedStream, bit2byte(used_bits), 13); // number of bits
-    BsPutBit(fixedStream, 0x7FF, 11); // buffer fullness (0x7FF for VBR)
-    BsPutBit(fixedStream, 0, 2); // raw data blocks (0+1=1)
-  }
-  return 58;
-}
-
-/*****************************************************************************/
-/* WriteSCE(...), write a single-channel element to the bitstream.           */
-/*****************************************************************************/
-int WriteSCE(AACQuantInfo* quantInfo,   /* AACQuantInfo structure */
-	     int tag,
-	     BsBitStream* fixedStream,  /* Pointer to bitstream */
-	     int writeFlag)             /* 1 means write, 0 means count only */
-{
-  int bit_count=0;
-
-  if (writeFlag) {
-    /* write ID_SCE, single_element_channel() identifier */
-    BsPutBit(fixedStream,ID_SCE,LEN_SE_ID);
-
-    /* write the element_identifier_tag */
-    BsPutBit(fixedStream,tag,LEN_TAG);
-  }
-
-  bit_count += LEN_SE_ID;
-  bit_count += LEN_TAG;
-
-  /* Write an individual_channel_stream element */
-  bit_count += WriteICS(quantInfo,0,fixedStream,writeFlag);
-
-  return bit_count;
-}
-
-/*****************************************************************************/
-/* WriteLFE(...), write a lfe-channel element to the bitstream.              */
-/*****************************************************************************/
-int WriteLFE(AACQuantInfo* quantInfo,   /* AACQuantInfo structure */
-	     int tag,
-	     BsBitStream* fixedStream,  /* Pointer to bitstream */
-	     int writeFlag)             /* 1 means write, 0 means count only */
-{
-  int bit_count=0;
-
-  if (writeFlag) {
-    /* write ID_LFE, lfe_element_channel() identifier */
-    BsPutBit(fixedStream,ID_LFE,LEN_SE_ID);
-
-    /* write the element_identifier_tag */
-    BsPutBit(fixedStream,tag,LEN_TAG);
-  }
-
-  bit_count += LEN_SE_ID;
-  bit_count += LEN_TAG;
-
-  /* Write an individual_channel_stream element */
-  bit_count += WriteICS(quantInfo,0,fixedStream,writeFlag);
-
-  return bit_count;
-}
-
-/*****************************************************************************/
-/* WriteCPE(...), write a channel_pair_element to the bitstream.           */
-/*****************************************************************************/
-int WriteCPE(AACQuantInfo* quantInfoL,   /* AACQuantInfo structure, left */
-             AACQuantInfo* quantInfoR,   /* AACQuantInfo structure, right */
-	     int tag,
-	     int commonWindow,          /* common_window flag */
-	     MS_Info* ms_info,          /* MS stereo information */
-	     BsBitStream* fixedStream,  /* Pointer to bitstream */
-	     int writeFlag)             /* 1 means write, 0 means count only */
-{
-  int bit_count=0;
-
-  if (writeFlag) {
-    /* write ID_CPE, single_element_channel() identifier */
-    BsPutBit(fixedStream,ID_CPE,LEN_SE_ID);
-
-    /* write the element_identifier_tag */
-    BsPutBit(fixedStream,tag,LEN_TAG);  /* Currently, this is zero */
-
-    /* common_window? */
-    BsPutBit(fixedStream,commonWindow,LEN_COM_WIN);
-  }
-
-  bit_count += LEN_SE_ID;
-  bit_count += LEN_TAG;
-  bit_count += LEN_COM_WIN;
-
-  /* if common_window, write ics_info */
-  if (commonWindow) {
-    int numWindows,maxSfb;
-    bit_count += WriteICSInfo(quantInfoL,fixedStream,writeFlag);
-    numWindows=quantInfoL->num_window_groups;
-    maxSfb = quantInfoL->max_sfb;
-    if (writeFlag) {
-      BsPutBit(fixedStream,ms_info->is_present,LEN_MASK_PRES);
-      if (ms_info->is_present==1) {
-	int g;
-	int b;
-	for (g=0;g<numWindows;g++) {
-	  for (b=0;b<maxSfb;b++) {
-	    BsPutBit(fixedStream,ms_info->ms_used[g*maxSfb+b],LEN_MASK);
-          }
-        }
-      }
-    }
-    bit_count += LEN_MASK_PRES;
-    if (ms_info->is_present==1)
-      bit_count += (numWindows*maxSfb*LEN_MASK);
-  }
-
-  /* Write individual_channel_stream elements */
-  bit_count += WriteICS(quantInfoL,commonWindow,fixedStream,writeFlag);
-  bit_count += WriteICS(quantInfoR,commonWindow,fixedStream,writeFlag);
-
-  return bit_count;
-}
-
-/*****************************************************************************/
-/* WriteICS(...), write an individual_channel_stream element to the bitstream.*/
-/*****************************************************************************/
-int WriteICS(AACQuantInfo* quantInfo,    /* AACQuantInfo structure */
-	     int commonWindow,           /* Common window flag */
-	     BsBitStream* fixed_stream,  /* Pointer to bitstream */
-	     int writeFlag)              /* 1 means write, 0 means count only */
-{
-  /* 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[MAX_SCFAC_BANDS*2];
-  writeFlag = ( writeFlag != 0 );
-
-  /* Write the 8-bit global_gain */
-  BsPutBit(fixed_stream,quantInfo->common_scalefac,writeFlag*LEN_GLOB_GAIN);
-  bit_count += LEN_GLOB_GAIN;
-
-  /* Write ics information */
-  if (!commonWindow) {
-    bit_count += WriteICSInfo(quantInfo,fixed_stream,writeFlag);
-  }
-
-  /* Write section_data() information to the bitstream */
-//  bit_count += sort_book_numbers(quantInfo,output_book_vector,fixed_stream,writeFlag);
-  bit_count += sort_book_numbers(quantInfo,fixed_stream,writeFlag);
-
-  /* Write scale_factor_data() information */
-  bit_count += write_scalefactor_bitstream(fixed_stream,writeFlag,quantInfo);
-
-  /* Write pulse_data() */
-  bit_count += WritePulseData(quantInfo,fixed_stream,writeFlag);
-
-  /* Write TNS data */
-  bit_count += WriteTNSData(quantInfo,fixed_stream,writeFlag);
-
-  /* Write gain control data */
-  bit_count += WriteGainControlData(fixed_stream,writeFlag);
-
-  /* Write out spectral_data() */
-  bit_count += WriteSpectralData(quantInfo,fixed_stream,writeFlag);
-
-  /* Return number of bits */
-  return(bit_count);
-}
-
-/*****************************************************************************/
-/* WriteICSInfo(...), write individual_channel_stream information            */
-/*  to the bitstream.                                                        */
-/*****************************************************************************/
-int WriteICSInfo(AACQuantInfo* quantInfo,    /* AACQuantInfo structure */
-		 BsBitStream* fixed_stream,  /* Pointer to bitstream */
-		 int writeFlag)              /* 1 means write, 0 means count only */
-{
-  int grouping_bits;
-  int max_sfb;
-  int bit_count = 0;
-
-  /* Compute number of scalefactor bands */
-//  if (quantInfo->max_sfb*quantInfo->num_window_groups != quantInfo->nr_of_sfb)
-    //CommonExit(-1,"Wrong number of scalefactorbands");
-  max_sfb =   quantInfo->max_sfb;
-
-  if (writeFlag) {
-    /* write out ics_info() information */
-    BsPutBit(fixed_stream,0,LEN_ICS_RESERV);  /* reserved Bit*/
-
-    /* Write out window sequence */
-    BsPutBit(fixed_stream,quantInfo->block_type,LEN_WIN_SEQ);  /* short window */
-
-    /* Write out window shape */
-    BsPutBit(fixed_stream,quantInfo->window_shape,LEN_WIN_SH);  /* window shape */
-  }
-
-  bit_count += LEN_ICS_RESERV;
-  bit_count += LEN_WIN_SEQ;
-  bit_count += LEN_WIN_SH;
-
-  /* For short windows, write out max_sfb and scale_factor_grouping */
-  if (quantInfo -> block_type == ONLY_SHORT_WINDOW){
-    if (writeFlag) {
-      BsPutBit(fixed_stream,max_sfb,LEN_MAX_SFBS);
-      grouping_bits = find_grouping_bits(quantInfo->window_group_length,quantInfo->num_window_groups);
-      BsPutBit(fixed_stream,grouping_bits,MAX_SHORT_WINDOWS - 1);  /* the grouping bits */
-    }
-    bit_count += LEN_MAX_SFBS;
-    bit_count += MAX_SHORT_WINDOWS - 1;
-  }
-  /* Otherwise, write out max_sfb and predictor data */
-  else { /* block type is either start, stop, or long */
-    if (writeFlag) {
-      BsPutBit(fixed_stream,max_sfb,LEN_MAX_SFBL);
-    }
-    bit_count += LEN_MAX_SFBL;
-    bit_count += WriteLTP_PredictorData(quantInfo,fixed_stream,writeFlag);
-  }
-
-  return bit_count;
-}
-
-/*****************************************************************************/
-/* WriteLTP_PredictorData(...), write LTP predictor data.                    */
-/*****************************************************************************/
-int WriteLTP_PredictorData(AACQuantInfo* quantInfo,    /* AACQuantInfo structure */
-                           BsBitStream* fixed_stream,  /* Pointer to bitstream */
-                           int writeFlag)              /* 1 means write, 0 means count only */
-{
-  int bit_count = 0;
-
-  bit_count += ltp_encode (quantInfo, fixed_stream, writeFlag);
-
-  return (bit_count);
-}
-
-/*****************************************************************************/
-/* WritePulseData(...), write pulse data.                            */
-/*****************************************************************************/
-int WritePulseData(AACQuantInfo* quantInfo,    /* AACQuantInfo structure */
-		   BsBitStream* fixed_stream,  /* Pointer to bitstream */
-		   int writeFlag)              /* 1 means write, 0 means count only */
-{
-  int i, bit_count = 0;
-
-  if (quantInfo->pulseInfo.pulse_data_present) {
-    if (writeFlag) {
-      BsPutBit(fixed_stream,1,LEN_PULSE_PRES);  /* no pulse_data_present */
-      BsPutBit(fixed_stream,quantInfo->pulseInfo.number_pulse,LEN_NEC_NPULSE);  /* no pulse_data_present */
-      BsPutBit(fixed_stream,quantInfo->pulseInfo.pulse_start_sfb,LEN_NEC_ST_SFB);  /* no pulse_data_present */
-    }
-    bit_count += (LEN_NEC_NPULSE + LEN_NEC_ST_SFB);
-
-    for (i = 0; i < quantInfo->pulseInfo.number_pulse+1; i++) {
-      if (writeFlag) {
-	BsPutBit(fixed_stream,quantInfo->pulseInfo.pulse_offset[i],LEN_NEC_POFF);
-	BsPutBit(fixed_stream,quantInfo->pulseInfo.pulse_amp[i],LEN_NEC_PAMP);
-      }
-      bit_count += (LEN_NEC_POFF + LEN_NEC_PAMP);
-    }
-  }
-  else {
-    if (writeFlag) {
-      BsPutBit(fixed_stream,0,LEN_PULSE_PRES);  /* no pulse_data_present */
-    }
-  }
-  bit_count += LEN_PULSE_PRES;
-  return bit_count;
-}
-
-/*****************************************************************************/
-/* WriteTNSData(...), write TNS data.                            */
-/*****************************************************************************/
-int WriteTNSData(AACQuantInfo* quantInfo,    /* AACQuantInfo structure */
-		 BsBitStream* fixed_stream,  /* Pointer to bitstream */
-		 int writeFlag)              /* 1 means write, 0 means count only */
-{
-  int bit_count = 0;
-  int numWindows;
-  int len_tns_nfilt;
-  int len_tns_length;
-  int len_tns_order;
-  int filtNumber;
-  int resInBits;
-  int bitsToTransmit;
-  unsigned long unsignedIndex;
-  int w;
-
-  TNS_INFO* tnsInfoPtr = &quantInfo->tnsInfo;
-
-  if (writeFlag) {
-    BsPutBit(fixed_stream,tnsInfoPtr->tnsDataPresent,LEN_TNS_PRES);
-  }
-  bit_count += LEN_TNS_PRES;
-
-  /* If TNS is not present, bail */
-  if (!tnsInfoPtr->tnsDataPresent) {
-    return bit_count;
-  }
-
-  /* Set window-dependent TNS parameters */
-  if (quantInfo->block_type == ONLY_SHORT_WINDOW) {
-    numWindows = MAX_SHORT_WINDOWS;
-    len_tns_nfilt = LEN_TNS_NFILTS;
-    len_tns_length = LEN_TNS_LENGTHS;
-    len_tns_order = LEN_TNS_ORDERS;
-  }
-  else {
-    numWindows = 1;
-    len_tns_nfilt = LEN_TNS_NFILTL;
-    len_tns_length = LEN_TNS_LENGTHL;
-    len_tns_order = LEN_TNS_ORDERL;
-  }
-
-  /* Write TNS data */
-  bit_count += (numWindows * len_tns_nfilt);
-  for (w=0;w<numWindows;w++) {
-    TNS_WINDOW_DATA* windowDataPtr = &tnsInfoPtr->windowData[w];
-    int numFilters = windowDataPtr->numFilters;
-    if (writeFlag) {
-      BsPutBit(fixed_stream,numFilters,len_tns_nfilt); /* n_filt[] = 0 */
-    }
-    if (numFilters) {
-      bit_count += LEN_TNS_COEFF_RES;
-      resInBits = windowDataPtr->coefResolution;
-      if (writeFlag) {
-	BsPutBit(fixed_stream,resInBits-DEF_TNS_RES_OFFSET,LEN_TNS_COEFF_RES);
-      }
-      bit_count += numFilters * (len_tns_length+len_tns_order);
-      for (filtNumber=0;filtNumber<numFilters;filtNumber++) {
-	TNS_FILTER_DATA* tnsFilterPtr=&windowDataPtr->tnsFilter[filtNumber];
-	int order = tnsFilterPtr->order;
-	if (writeFlag) {
-	  BsPutBit(fixed_stream,tnsFilterPtr->length,len_tns_length);
-	  BsPutBit(fixed_stream,order,len_tns_order);
-        }
-	if (order) {
-	  bit_count += (LEN_TNS_DIRECTION + LEN_TNS_COMPRESS);
-	  if (writeFlag) {
-	    BsPutBit(fixed_stream,tnsFilterPtr->direction,LEN_TNS_DIRECTION);
-	    BsPutBit(fixed_stream,tnsFilterPtr->coefCompress,LEN_TNS_COMPRESS);
-          }
-	  bitsToTransmit = resInBits - tnsFilterPtr->coefCompress;
-	  bit_count += order * bitsToTransmit;
-	  if (writeFlag) {
-	    int i;
-	    for (i=1;i<=order;i++) {
-	      unsignedIndex = (unsigned long) (tnsFilterPtr->index[i])&(~(~0<<bitsToTransmit));
-	      BsPutBit(fixed_stream,unsignedIndex,bitsToTransmit);
-            }
-          }
-        }
-      }
-    }
-  }
-  return bit_count;
-}
-
-/*****************************************************************************/
-/* WriteGainControlData(...), write gain control data.                       */
-/*****************************************************************************/
-int WriteGainControlData(BsBitStream* fixed_stream,  /* Pointer to bitstream */
-			 int writeFlag)              /* 1 means write, 0 means count only */
-{
-  int bit_count = 0;
-  bit_count += LEN_GAIN_PRES;
-
-  if (writeFlag) {
-    BsPutBit(fixed_stream,0,LEN_GAIN_PRES);
-  }
-  return bit_count;
-}
-/*****************************************************************************/
-/* WriteSpectralData(...), write spectral data.                              */
-/*****************************************************************************/
-int WriteSpectralData(AACQuantInfo* quantInfo,    /* AACQuantInfo structure */
-		      BsBitStream* fixed_stream,  /* Pointer to bitstream */
-		      int writeFlag)              /* 1 means write, 0 means count only */
-{
-  int bit_count = 0;
-  int numSpectral = quantInfo->spectralCount;
-
-  /* set up local pointers to data and len */
-  /* data array contains data to be written */
-  /* len array contains lengths of data words */
-  int* data = quantInfo -> data;
-  int* len = quantInfo -> len;
-
-  if (writeFlag) {
-    int i;
-    for(i=0;i<numSpectral;i++) {
-      if (len[i] > 0) {  /* only send out non-zero codebook data */
-      	BsPutBit(fixed_stream,data[i],len[i]); /* write data */
-	bit_count += len[i];                   /* update bit_count */
-      }
-    }
-  }
-  else {
-    int i;
-    for(i=0;i<numSpectral;i++) {
-      bit_count += len[i];              /* update bit_count */
-    }
-  }
-
-  return bit_count;
-}
-
--- a/aac_se_enc.h
+++ /dev/null
@@ -1,139 +1,0 @@
-/*
- *	Function prototypes for writing/counting AAC syntactic elements
- *
- *	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.8 $
-  $Date: 2000/10/06 14:47:27 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef AAC_SE_ENC
-#define AAC_SE_ENC
-
-#include "bitstream.h"
-#include "quant.h"
-#include "ltp_enc.h"
-
-extern int max_pred_sfb;
-
-
-
-/*****************************************************************************/
-/* Write AAC fill bits to the bitStream                                      */
-/*****************************************************************************/
-int WriteAACFillBits(BsBitStream* ptrBs,  /* Pointer to bit stream */
-		     int numBits,        /* Number of bits neede to fill */
-				int writeFlag);
-
-int WriteADTSHeader(AACQuantInfo* quantInfo,   /* AACQuantInfo structure */
-					BsBitStream* fixedStream,  /* Pointer to bitstream */
-					int used_bits,
-					int writeFlag);            /* 1 means write, 0 means count only */
-
-/*****************************************************************************/
-/* WriteSCE(...), write a single-channel element to the bitstream.           */
-/*****************************************************************************/
-int WriteSCE(AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-	     int tag,
-	     BsBitStream* fixedStream, /* Pointer to bitstream */
-	     int writeFlag);           /* 1 means write, 0 means count only */
-
-/*****************************************************************************/
-/* WriteLFE(...), write a lfe-channel element to the bitstream.              */
-/*****************************************************************************/
-int WriteLFE(AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-	     int tag,
-	     BsBitStream* fixedStream, /* Pointer to bitstream */
-	     int writeFlag);           /* 1 means write, 0 means count only */
-
-/*****************************************************************************/
-/* WriteCPE(...), write a channel_pair_element to the bitstream.           */
-/*****************************************************************************/
-int WriteCPE(AACQuantInfo* quantInfoL,   /* AACQuantInfo structure, left */
-             AACQuantInfo* quantInfoR,   /* AACQuantInfo structure, right */
-	     int tag,
-	     int commonWindow,
-	     MS_Info* ms_info,
-	     BsBitStream* fixedStream,  /* Pointer to bitstream */
-	     int writeFlag);            /* 1 means write, 0 means count only */
-
-/*****************************************************************************/
-/* WriteICS(...), write an individual_channel_stream element to the bitstream.*/
-/*****************************************************************************/
-int WriteICS(AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-	     int commonWindow,
-	     BsBitStream* fixedStream, /* Pointer to bitstream */
-	     int writeFlag);           /* 1 means write, 0 means count only */ 
-
-/*****************************************************************************/
-/* WriteICSInfo(...), write a individual_channel_stream information          */
-/*  to the bitstream.                                                        */
-/*****************************************************************************/
-int WriteICSInfo(AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-		 BsBitStream* fixedStream, /* Pointer to bitstream */
-		 int writeFlag);           /* 1 means write, 0 means count only */
-
-/*****************************************************************************/
-/* WriteLTP_PredictorData(...), write LTP predictor data.                    */
-/*****************************************************************************/
-int WriteLTP_PredictorData(AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-                           BsBitStream* fixedStream, /* Pointer to bitstream */
-                           int writeFlag);           /* 1 means write, 0 means count only */
-
-/*****************************************************************************/
-/* WritePredictorData(...), write predictor data.                            */
-/*****************************************************************************/
-int WritePredictorData(AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-		       BsBitStream* fixedStream, /* Pointer to bitstream */
-		       int writeFlag);           /* 1 means write, 0 means count only */   
-
-/*****************************************************************************/
-/* WritePulseData(...), write pulse data.                            */
-/*****************************************************************************/
-int WritePulseData(AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-		   BsBitStream* fixedStream, /* Pointer to bitstream */
-		   int writeFlag);           /* 1 means write, 0 means count only */ 
-
-/*****************************************************************************/
-/* WriteTNSData(...), write TNS data.                            */
-/*****************************************************************************/
-int WriteTNSData(AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-		 BsBitStream* fixedStream, /* Pointer to bitstream */
-		 int writeFlag);           /* 1 means write, 0 means count only */
-
-/*****************************************************************************/
-/* WriteGainControlData(...), write gain control data.                       */
-/*****************************************************************************/
-int WriteGainControlData(
-//                         AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-			 BsBitStream* fixedStream, /* Pointer to bitstream */
-			 int writeFlag);           /* 1 means write, 0 means count only */
-
-/*****************************************************************************/
-/* WriteSpectralData(...), write spectral data.                              */
-/*****************************************************************************/
-int WriteSpectralData(AACQuantInfo* quantInfo,  /* Pointer to AACQuantInfo structure */
-		      BsBitStream* fixedStream, /* Pointer to bitstream */
-		      int writeFlag);           /* 1 means write, 0 means count only */
-
-#endif
-
--- a/aacenc.h
+++ /dev/null
@@ -1,142 +1,0 @@
-/*
- *	Function prototypes for AAC encoder
- *
- *	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.20 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <sndfile.h>
-
-typedef struct RCBufStruct RCBuf;	/* buffer handle */
-
-#define PROFILE                 1
-#define HEADER_TYPE             2
-#define MS_STEREO               3
-#define IS_STEREO               4
-#define BITRATE                 5
-#define CUT_OFF                 6
-#define OUT_SAMPLING_RATE       7
-#define RAW_AUDIO               8
-#define TNS                     9
-#define LTP                     10
-#define PNS                     11
-#define IN_SAMPLING_RATE        12
-#define NUMBER_OF_CHANNELS      13
-#define LFE_PRESENT             14
-
-#define MAIN_PROFILE 0
-#define LOW_PROFILE 1
-
-#define NO_HEADER	0
-#define ADIF_HEADER     1
-#define ADTS_HEADER     2
-
-#define NO_MS           -1
-#define FORCE_MS        1
-#define SWITCHING_MS    0
-
-#define USE_TNS         1
-#define NO_TNS          0
-
-#define USE_LTP         1
-#define NO_LTP          0
-
-#define USE_LFE         1
-#define NO_LFE          0
-
-#define USE_PNS         1
-#define NO_PNS          0
-
-#define USE_RAW_AUDIO   1
-#define NO_RAW_AUDIO    0
-
-#define FNO_ERROR 0
-#define FERROR 1
-#define F_FINISH 2
-
-
-typedef struct {
-	int DLLMajorVersion; // These 2 values should always be checked, because the DLL
-	int DLLMinorVersion; // interface can change from version to version.
-	int MajorVersion;
-	int MinorVersion;
-	char HomePage[255];
-} faacVersion;
-
-// This structure is for AAC stream object
-typedef struct {
-	long total_bits;
-	long frames;
-	long cur_frame;
-	int is_first_frame;
-	int channels;
-	int out_sampling_rate;
-	int in_sampling_rate;
-	int frame_bits;
-	int available_bits;
-	int header_type;
-	int use_MS;
-	int use_TNS;
-	int use_LTP;
-	int use_PNS;
-	int profile;
-	double **inputBuffer;
-	RCBuf *rc_buf;
-	int rc_needed;
-	int savedSize;
-	float saved[2048];
-	int cut_off;
-	int bit_rate;
-	int raw_audio;
-	SNDFILE *in_file;
-	FILE *out_file;
-	unsigned char *bitBuffer;
-	int bitBufferSize;
-	short *sampleBuffer;
-	int samplesToRead;
-	int lfePresent;
-} faacAACStream;
-
-#ifndef FAAC_DLL
-
-int faac_EncodeInit(faacAACStream *as, char *in_file, char *out_file);
-int faac_EncodeFrame(faacAACStream *as);
-int faac_BlockEncodeFrame(faacAACStream *as, short *input_samples, int Samples);
-void faac_EncodeFree(faacAACStream *as);
-faacVersion *faac_Version(void);
-void faac_InitParams(faacAACStream *as);
-void faac_SetParam(faacAACStream *as, int param, int value);
-
-#else
-
-__declspec(dllexport) int faac_EncodeInit(faacAACStream *as, char *in_file, char *out_file);
-__declspec(dllexport) int faac_EncodeFrame(faacAACStream *as);
-__declspec(dllexport) int faac_BlockEncodeFrame(faacAACStream *as, short *input_samples, int Samples);
-__declspec(dllexport) void faac_EncodeFree(faacAACStream *as);
-__declspec(dllexport) faacVersion *faac_Version(void);
-__declspec(dllexport) void faac_InitParams(faacAACStream *as);
-__declspec(dllexport) void faac_SetParam(faacAACStream *as, int param, int value);
-
-#endif
-
--- a/bitstream.c
+++ /dev/null
@@ -1,121 +1,0 @@
-/*
- *	Bitstream writing
- *
- *	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/06 14:47:27 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <stdlib.h>
-#include <memory.h>
-
-#include "bitstream.h"		/* bit stream module */
-
-
-
-BsBitStream *BsOpenWrite(int size)
-{
-	BsBitStream *bs;
-
-	bs = malloc(sizeof(BsBitStream));
-	bs->size = size;
-	bs->numBit = 0;
-	bs->currentBit = 0;
-	bs->data = malloc(bit2byte(size));
-	memset(bs->data, 0, bit2byte(size));
-
-	return bs;
-}
-
-void BsClose(BsBitStream *bs)
-{
-	free(bs->data);
-	free(bs);
-}
-
-long BsBufferNumBit (BsBitStream *bs)
-{
-	return bs->numBit;
-}
-
-int BsWriteByte (BsBitStream *stream,
-				 unsigned long data,
-				 int numBit)
-{
-	long numUsed,idx;
-
-	idx = (stream->currentBit / BYTE_NUMBIT) % bit2byte(stream->size);
-	numUsed = stream->currentBit % BYTE_NUMBIT;
-	if (numUsed == 0)
-		stream->data[idx] = 0;
-	stream->data[idx] |= (data & ((1<<numBit)-1)) <<
-		(BYTE_NUMBIT-numUsed-numBit);
-	stream->currentBit += numBit;
-	stream->numBit = stream->currentBit;
-
-	return 0;
-}
-
-int BsPutBit (BsBitStream *stream,
-			  unsigned long data,
-			  int numBit)
-{
-	int num,maxNum,curNum;
-	unsigned long bits;
-
-	if (numBit == 0)
-		return 0;
-
-	/* write bits in packets according to buffer byte boundaries */
-	num = 0;
-	maxNum = BYTE_NUMBIT - stream->currentBit % BYTE_NUMBIT;
-	while (num < numBit) {
-		curNum = min(numBit-num,maxNum);
-		bits = data>>(numBit-num-curNum);
-		if (BsWriteByte(stream,bits,curNum)) {
-			return 1;
-		}
-		num += curNum;
-		maxNum = BYTE_NUMBIT;
-	}
-
-	return 0;
-}
-
-int ByteAlign(BsBitStream* ptrBs, int writeFlag)
-{
-	int len, i,j;
-	len = BsBufferNumBit( ptrBs );
-	   
-	j = (8 - (len%8))%8;
-
-	if ((len % 8) == 0) j = 0;
-	if (writeFlag) {
-		for( i=0; i<j; i++ ) {
-			BsPutBit( ptrBs, 0, 1 ); 
-		}
-	}
-	return j;
-}
-
-
--- a/bitstream.h
+++ /dev/null
@@ -1,73 +1,0 @@
-/*
- *	Function prototypes for bitstream writing
- *
- *	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.3 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _bitstream_h_
-#define _bitstream_h_
-
-#ifndef min
-#define min(a,b) ( (a) < (b) ? (a) : (b) )
-#endif
-#ifndef max
-#define max(a,b) ( (a) > (b) ? (a) : (b) )
-#endif
-
-#define BYTE_NUMBIT 8		/* bits in byte (char) */
-#define LONG_NUMBIT 32		/* bits in unsigned long */
-#define bit2byte(a) (((a)+BYTE_NUMBIT-1)/BYTE_NUMBIT)
-#define byte2bit(a) ((a)*BYTE_NUMBIT)
-
-
-typedef struct _bitstream
-{
-  unsigned char *data;		/* data bits */
-  long numBit;			/* number of bits in buffer */
-  long size;			/* buffer size in bits */
-  long currentBit;		/* current bit position in bit stream */
-  long numByte;			/* number of bytes read/written (only file) */
-} BsBitStream;
-
-
-BsBitStream *BsOpenWrite(int size);
-
-void BsClose(BsBitStream *bs);
-
-long BsBufferNumBit (BsBitStream *bs);
-
-int BsWriteByte (BsBitStream *stream,
-				 unsigned long data,
-				 int numBit);
-
-int BsPutBit (BsBitStream *stream,
-			  unsigned long data,
-			  int numBit);
-
-/* ByteAlign(...), used to byte align bitstream */
-int ByteAlign(BsBitStream* ptrBs, int writeFlag);
-
-#endif
-
--- a/enc.h
+++ /dev/null
@@ -1,69 +1,0 @@
-/*
- *	Function prototypes for frame encoding
- *
- *	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.7 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _enc_h_
-#define _enc_h_
-
-
-#include "bitstream.h"		/* bit stream module */
-
-/* ---------- functions ---------- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* EncTfInit() */
-/* Init t/f-based encoder core. */
-
-void EncTfInit (faacAACStream *as);
-
-
-
-/* EncTfFrame() */
-/* Encode one audio frame into one bit stream frame with */
-/* t/f-based encoder core. */
-
-int EncTfFrame (faacAACStream *as, BsBitStream *bitBuf);
-
-
-/* EncTfFree() */
-/* Free memory allocated by t/f-based encoder core. */
-
-void EncTfFree (void);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif	/* #ifndef _enc_h_ */
-
-/* end of enc.h */
-
--- a/enc_tf.c
+++ /dev/null
@@ -1,905 +1,0 @@
-/*
- *	Frame encoding
- *
- *	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.69 $
-  $Date: 2000/11/10 13:27:06 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <stdlib.h>
-#include <memory.h>
-
-#include "aacenc.h"
-#include "bitstream.h"
-#include "interface.h"
-#include "enc.h"
-#include "psych.h"
-#include "mc_enc.h"
-#include "ms.h"
-#include "quant.h"
-#include "aac_se_enc.h"
-#include "ltp_enc.h"
-#include "transfo.h"
-
-
-/* AAC tables */
-
-SR_INFO sr_info_aac[MAX_SAMPLING_RATES+1] =
-{
-	{ 8000, 40, 15,
-		{
-			12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 16, 
-			16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28, 
-			28, 32, 32, 36, 40, 44, 48, 52, 56, 60, 64, 80
-		}, {
-			4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 20
-		}
-	}, { 11025, 43, 15,
-		{
-			8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 
-			12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
-			24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
-		}, {
-			4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
-		}
-	}, { 12000, 43, 15,
-		{
-			8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 
-			12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, 
-			24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
-		}, {
-			4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
-		}
-	}, { 16000, 43, 15,
-		{
-			8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 
-			12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, 
-			24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
-		}, {
-			4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
-		}
-	}, { 22050, 47, 15,
-		{
-			4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8,  8,  8,  8,
-			8,  8,  8,  12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
-			36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
-		}, {
-			4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8, 12, 16, 16, 20
-		}
-	},{ 24000, 47, 15,
-		{
-			4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8,  8,  8,  8,
-			8,  8,  8,  12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
-			36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
-		}, {
-			4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8, 12, 16, 16, 20
-		}
-	}, { 32000, 51, 14,
-		{
-			4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	8,	8,	8,	8,	
-			8,	8,	8,	12,	12,	12,	12,	16,	16,	20,	20,	24,	24,	28,	
-			28,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,
-			32,	32,	32,	32,	32,	32,	32,	32,	32
-		},{
-			4,	4,	4,	4,	4,	8,	8,	8,	12,	12,	12,	16,	16,	16
-		}
-	}, { 44100, 49, 14,
-		{
-			4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8,  8,  8,  8, 
-			12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
-			32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
-		}, {
-			4,  4,  4,  4,  4,  8,  8,  8, 12, 12, 12, 16, 16, 16 
-		}
-	}, { 48000, 49, 14,
-		{
-			4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8,  8,  8,  8, 
-			12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
-			32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
-		}, {
-			4,  4,  4,  4,  4,  8,  8,  8, 12, 12, 12, 16, 16, 16 
-		}
-	}, {64000, 47, 12,
-		{
-			4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
-			8, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 24, 24, 28,
-			36, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
-			40, 40, 40, 40, 40
-		},{
-			4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 32
-		}
-	}, { 88200, 41, 12,
-		{
-			4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
-			8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28, 
-			36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
-		},{
-			4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
-		}
-	}, { 96000, 41, 12,
-		{
-			4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
-			8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28, 
-			36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
-		},{
-			4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
-		}
-	},
-	{ -1 }
-};
-
-/* First attempt at supporting multiple sampling rates   *
- * and bitrates correctly.                               */
-
-/* Tables for maximum nomber of scalefactor bands */
-/* Needs more fine-tuning. Only the values for 44.1kHz have been changed
-   on lower bitrates. */
-int max_sfb_s[] = { 12, 12, 12, 13, 14, 13, 15, 15, 15, 15, 15, 15 };
-int max_sfb_l[] = { 49, 49, 47, 48, 49, 51, 47, 47, 43, 43, 43, 40 };
-
-
-int     max_ch;    /* no of of audio channels */
-double *spectral_line_vector[MAX_TIME_CHANNELS];
-double *reconstructed_spectrum[MAX_TIME_CHANNELS];
-double *overlap_buffer[MAX_TIME_CHANNELS];
-double *DTimeSigBuf[MAX_TIME_CHANNELS];
-double *DTimeSigLookAheadBuf[MAX_TIME_CHANNELS*2];
-double *tmp_DTimeSigBuf[MAX_TIME_CHANNELS]; /* temporary fix to the buffer size problem. */
-
-/* variables used by the T/F mapping */
-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];
-
-AACQuantInfo quantInfo[MAX_TIME_CHANNELS];               /* Info structure for AAC quantization and coding */
-
-
-/* EncTfFree() */
-/* Free memory allocated by t/f-based encoder core. */
-
-void EncTfFree (void)
-{
-  int chanNum;
-
-  for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
-    if (DTimeSigBuf[chanNum]) free(DTimeSigBuf[chanNum]);
-    if (spectral_line_vector[chanNum]) free(spectral_line_vector[chanNum]);
-
-    if (reconstructed_spectrum[chanNum]) free(reconstructed_spectrum[chanNum]);
-    if (overlap_buffer[chanNum]) free(overlap_buffer[chanNum]);
-    if (quantInfo[chanNum].ltpInfo.delay) free(quantInfo[chanNum].ltpInfo.delay);
-    if (tmp_DTimeSigBuf[chanNum]) free(tmp_DTimeSigBuf[chanNum]);
-  }
-  for (chanNum=0;chanNum<MAX_TIME_CHANNELS*2;chanNum++) {
-    if (DTimeSigLookAheadBuf[chanNum]) free(DTimeSigLookAheadBuf[chanNum]);
-  }
-}
-
-/*******************************************************************************
- ***
- *** Function: EncTfInit
- ***
- *** Purpose:  Initialize the T/F-part and the macro blocks of the T/F part of the VM
- ***
- *** Description:
- ***
- ***
- *** Parameters:
- ***
- ***
- *** Return Value:
- ***
- *** **** MPEG-4 VM ****
- ***
- ******************************************************************************/
-
-void EncTfInit (faacAACStream *as)
-{
-  int chanNum, i;
-  int SampleRates[] = { 96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000,0};
-  int srate_idx;
-//	int BitRates[] = {
-//		64000,80000,96000,112000,128000,160000,192000,224000,256000,0
-//	};
-
-  for (i = 0; ; i++) {
-    if (SampleRates[i] == as->out_sampling_rate) {
-      srate_idx = i;
-      break;
-    }
-  }
-
-  if (as->use_PNS)
-    pns_sfb_start = 0;
-  else
-    pns_sfb_start = 60;
-
-  /* set the return values */
-  max_ch = as->channels;
-
-  /* some global initializations */
-  for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
-    DTimeSigBuf[chanNum]            = (double*)malloc(BLOCK_LEN_LONG*sizeof(double));
-    memset(DTimeSigBuf[chanNum],0,BLOCK_LEN_LONG*sizeof(double));
-    spectral_line_vector[chanNum]   = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
-    reconstructed_spectrum[chanNum] = (double*)malloc(BLOCK_LEN_LONG*sizeof(double));
-    memset(reconstructed_spectrum[chanNum], 0, BLOCK_LEN_LONG*sizeof(double));
-    overlap_buffer[chanNum] = (double*)malloc(sizeof(double)*BLOCK_LEN_LONG);
-    memset(overlap_buffer[chanNum],0,(BLOCK_LEN_LONG)*sizeof(double));
-    block_type[chanNum] = ONLY_LONG_WINDOW;
-    quantInfo[chanNum].ltpInfo.delay =  (int*)malloc(MAX_SHORT_WINDOWS*sizeof(int));
-    tmp_DTimeSigBuf[chanNum]  = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
-    memset(tmp_DTimeSigBuf[chanNum],0,(2*BLOCK_LEN_LONG)*sizeof(double));
-  }
-  for (chanNum=0;chanNum<MAX_TIME_CHANNELS*2;chanNum++) {
-    DTimeSigLookAheadBuf[chanNum]   = (double*)malloc((BLOCK_LEN_LONG)*sizeof(double));
-    memset(DTimeSigLookAheadBuf[chanNum],0,(BLOCK_LEN_LONG)*sizeof(double));
-  }
-
-  /* initialize psychoacoustic module */
-  Psy_Init();
-
-  /* initialize spectrum processing */
-  /* initialize quantization and coding */
-  aacQuantizeInit(0);
-
-  /* Init TNS */
-  for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
-    TnsInit(as->out_sampling_rate,as->profile,&quantInfo[chanNum].tnsInfo);
-  }
-
-  /* Init LTP predictor */
-  for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
-    init_lt_pred (&quantInfo[chanNum].ltpInfo);
-    quantInfo[chanNum].window_shape = WS_SIN;
-  }
-
-  for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
-		quantInfo[chanNum].sr_info = &sr_info_aac[0];
-			
-		/* find correct sampling rate depending parameters */
-		while( quantInfo[chanNum].sr_info->sampling_rate != as->out_sampling_rate ) {
-			quantInfo[chanNum].sr_info++;
-		}
-
-    quantInfo[chanNum].srate_idx = srate_idx;
-    quantInfo[chanNum].profile = as->profile;
-  }
-
-  /* Initialisation for FFT & MDCT stuff */
-  make_MDCT_windows();
-  make_FFT_order();
-  initrft();
-}
-
-
-
-/*******************************************************************************
- ***
- *** Function:    EncTfFrame
- ***
- *** Purpose:     processes a block of time signal input samples into a bitstream
- ***              based on T/F encoding
- ***
- *** Description:
- ***
- ***
- *** Parameters:
- ***
- ***
- *** Return Value:  returns the number of used bits
- ***
- *** **** MPEG-4 VM ****
- ***
- ******************************************************************************/
-
-int EncTfFrame (faacAACStream *as, BsBitStream  *fixed_stream)
-{
-  int used_bits;
-  int error;
-
-  /* Energy array (computed before prediction for long windows) */
-  double energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS];
-
-  /* determine the function parameters used earlier */
-  int          average_bits = as->frame_bits;
-  int          available_bitreservoir_bits = as->available_bits-as->frame_bits;
-
-  /* max. allowed amount of bits in the reservoir  (used to avoid padding bits) */
-  long num_bits_available;
-
-  double *p_ratio[MAX_TIME_CHANNELS], allowed_distortion[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS];
-  static double p_ratio_long[2][MAX_TIME_CHANNELS][MAX_SCFAC_BANDS];
-  static double p_ratio_short[2][MAX_TIME_CHANNELS][MAX_SCFAC_BANDS];
-  int    nr_of_sfb[MAX_TIME_CHANNELS], sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS];
-  int sfb_offset_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS+1];
-
-
-  /* structures holding the output of the psychoacoustic model */
-  CH_PSYCH_OUTPUT_LONG chpo_long[MAX_TIME_CHANNELS];
-  CH_PSYCH_OUTPUT_SHORT chpo_short[MAX_TIME_CHANNELS][MAX_SHORT_WINDOWS];
-  static int ps = 1;
-  ps = !ps;
-
-  if (as->header_type==ADTS_HEADER)
-    available_bitreservoir_bits += 58;
-
-  /***********************************************************************/
-  /* Determine channel elements */
-  /***********************************************************************/
-  DetermineChInfo(quantInfo, max_ch, as->lfePresent);
-
-
-  /***********************************************************************/
-  /* Fill buffers  */
-  /* store input data in look ahead buffer which may be necessary */
-  /* for the window switching decision */
-  /***********************************************************************/
-  {
-	  int chanNum;
-	  int i;
-
-	  for (chanNum = 0; chanNum < max_ch; chanNum++) {
-
-		  if (quantInfo[chanNum].channelInfo.present) {
-			  if ((quantInfo[chanNum].channelInfo.cpe) && (quantInfo[chanNum].channelInfo.ch_is_left)) { /* CPE */
-				  int leftChan = chanNum;
-				  int rightChan = quantInfo[chanNum].channelInfo.paired_ch;
-
-				  if (as->use_MS == 1) {
-					  for(i = 0; i < BLOCK_LEN_LONG; i++){
-						  DTimeSigLookAheadBuf[leftChan][i] = (as->inputBuffer[leftChan][i]+as->inputBuffer[rightChan][i])*0.5;
-						  DTimeSigLookAheadBuf[rightChan][i] = (as->inputBuffer[leftChan][i]-as->inputBuffer[rightChan][i])*0.5;
-					  }
-				  }
-			  }
-
-			  if(as->use_LTP) {
-				  for( i=0; i< BLOCK_LEN_LONG; i++ ) {
-					  tmp_DTimeSigBuf[chanNum][i] = DTimeSigBuf[chanNum][i];
-					  tmp_DTimeSigBuf[chanNum][BLOCK_LEN_LONG + i] = DTimeSigLookAheadBuf[chanNum][i];
-				  }
-			  }
-			  for( i=0; i< BLOCK_LEN_LONG; i++ ) {
-				  DTimeSigBuf[chanNum][i] = DTimeSigLookAheadBuf[chanNum][i];
-				  DTimeSigLookAheadBuf[chanNum][i] = as->inputBuffer[chanNum][i];
-			  }
-		  }
-	  }
-  }
-
-
-  if (fixed_stream == NULL) {
-    Psy_FillBuffer(DTimeSigLookAheadBuf, max_ch);
-    return FNO_ERROR; /* quick'n'dirty fix for encoder startup */
-  }
-
-  /* Keep track of number of bits used */
-  used_bits = 0;
-
-  /*****************************************************************************/
-  /* psychoacoustics */
-  /*****************************************************************************/
-  Psy_Calculate(
-	  quantInfo,
-	  as->out_sampling_rate,
-	  max_ch,
-	  DTimeSigLookAheadBuf,
-	  next_desired_block_type,
-	  as->use_MS,
-	  chpo_long,
-	  chpo_short
-	  );
-
-  /*****************************************************************************/
-  /* block_switch processing */
-  /*****************************************************************************/
-  {
-    int chanNum;
-	
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-    /* A few definitions:                                                      */
-    /*   block_type:  Initially, the block_type used in the previous frame.    */
-    /*                Will be set to the block_type to use this frame.         */
-    /*                A block type will be selected to ensure a meaningful     */
-    /*                window transition.                                       */
-    /*   next_desired_block_type:  Block_type (LONG or SHORT) which the psycho */
-    /*                model wants to use next frame.  The psycho model is      */
-    /*                using a look-ahead buffer.                               */
-    /*   desired_block_type:  Block_type (LONG or SHORT) which the psycho      */
-    /*                previously wanted to use.  It is the desired block_type  */
-    /*                for this frame.                                          */
-    if ( (block_type[chanNum]==ONLY_SHORT_WINDOW)||(block_type[chanNum]==LONG_SHORT_WINDOW) ) {
-      if ( (desired_block_type[chanNum]==ONLY_LONG_WINDOW)&&(next_desired_block_type[chanNum]==ONLY_LONG_WINDOW) ) {
-	block_type[chanNum]=SHORT_LONG_WINDOW;
-      }
-      else {
-	block_type[chanNum]=ONLY_SHORT_WINDOW;
-      }
-    }
-    else if (next_desired_block_type[chanNum]==ONLY_SHORT_WINDOW) {
-      block_type[chanNum]=LONG_SHORT_WINDOW;
-      }
-      else {
-	block_type[chanNum]=ONLY_LONG_WINDOW;
-      }
-      desired_block_type[chanNum]=next_desired_block_type[chanNum];
-    }
-  }
-
-//	printf("%d\t\n", block_type[0]);
-//	block_type[0] = ONLY_LONG_WINDOW;
-//	block_type[1] = ONLY_LONG_WINDOW;
-//	block_type[0] = ONLY_SHORT_WINDOW;
-//	block_type[1] = ONLY_SHORT_WINDOW;
-
-  {
-	  int chanNum;
-
-	  for (chanNum = 0; chanNum < max_ch; chanNum++) {
-		  /* Set window shape paremeter in quantInfo */
-		  switch( block_type[chanNum] ) {
-		  case ONLY_SHORT_WINDOW:
-		  case LONG_SHORT_WINDOW:
-			  quantInfo[chanNum].prev_window_shape = quantInfo[chanNum].window_shape;
-			  quantInfo[chanNum].window_shape = WS_SIN;
-			  break;
-		  case ONLY_LONG_WINDOW:
-		  case SHORT_LONG_WINDOW:
-			  quantInfo[chanNum].prev_window_shape = quantInfo[chanNum].window_shape;
-			  quantInfo[chanNum].window_shape = WS_KBD;
-			  break;
-		  }
-	  }
-  }
-
-  {
-    int chanNum;
-
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-      switch( block_type[chanNum] ) {
-        case ONLY_SHORT_WINDOW:
-
-        quantInfo[chanNum].max_sfb = max_sfb_s[quantInfo[chanNum].srate_idx];
-        quantInfo[chanNum].num_window_groups = 8;
-        quantInfo[chanNum].window_group_length[0] = 1;
-        quantInfo[chanNum].window_group_length[1] = 1;
-        quantInfo[chanNum].window_group_length[2] = 1;
-        quantInfo[chanNum].window_group_length[3] = 1;
-        quantInfo[chanNum].window_group_length[4] = 1;
-        quantInfo[chanNum].window_group_length[5] = 1;
-        quantInfo[chanNum].window_group_length[6] = 1;
-        quantInfo[chanNum].window_group_length[7] = 1;
-        break;
-
-        default:
-        quantInfo[chanNum].max_sfb = max_sfb_l[quantInfo[chanNum].srate_idx];
-        quantInfo[chanNum].num_window_groups = 1;
-        quantInfo[chanNum].window_group_length[0]=1;
-        break;
-      }
-    }
-  }
-
-  {
-    int chanNum;
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-      /* Count number of bits used for gain_control_data */
-      used_bits += WriteGainControlData(NULL,0); /* Zero write flag means don't write */
-    }
-  }
-
-
-  /*****************************************************************************
-  * T/F mapping (MDCT)
-  *****************************************************************************/
-  {
-    int chanNum, k;
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-      buffer2freq(
-		  DTimeSigBuf[chanNum],
-		  spectral_line_vector[chanNum],
-		  overlap_buffer[chanNum],
-		  block_type[chanNum],
-		  quantInfo[chanNum].window_shape,
-		  quantInfo[chanNum].prev_window_shape,
-		  MOVERLAPPED
-		  );
-
-      if (block_type[chanNum] == ONLY_SHORT_WINDOW) {
-	for (k = 0; k < 8; k++) {
-	  specFilter(spectral_line_vector[chanNum]+k*BLOCK_LEN_SHORT, spectral_line_vector[chanNum]+k*BLOCK_LEN_SHORT, as->out_sampling_rate, as->cut_off, BLOCK_LEN_SHORT);
-        }
-      }
-      else {
-	specFilter(spectral_line_vector[chanNum], spectral_line_vector[chanNum], as->out_sampling_rate, as->cut_off, BLOCK_LEN_LONG);
-      }
-    }
-  }
-
-  /*****************************************************************************
-  * adapt ratios of psychoacoustic module to codec scale factor bands
-  *****************************************************************************/
-
-  {
-    int chanNum;
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-      switch( block_type[chanNum] ) {
-	case ONLY_LONG_WINDOW:
-	  memcpy( (char*)sfb_width_table[chanNum], (char*)quantInfo[chanNum].sr_info->cb_width_long, (NSFB_LONG+1)*sizeof(int) );
-	  nr_of_sfb[chanNum] = quantInfo[chanNum].sr_info->num_cb_long;
-	  p_ratio[chanNum]   = p_ratio_long[ps][chanNum];
-	  break;
-        case LONG_SHORT_WINDOW:
-	  memcpy( (char*)sfb_width_table[chanNum], (char*)quantInfo[chanNum].sr_info->cb_width_long, (NSFB_LONG+1)*sizeof(int) );
-	  nr_of_sfb[chanNum] = quantInfo[chanNum].sr_info->num_cb_long;
-	  p_ratio[chanNum]   = p_ratio_long[ps][chanNum];
-	  break;
-        case ONLY_SHORT_WINDOW:
-	  memcpy( (char*)sfb_width_table[chanNum], (char*)quantInfo[chanNum].sr_info->cb_width_short, (NSFB_SHORT+1)*sizeof(int) );
-	  nr_of_sfb[chanNum] = quantInfo[chanNum].sr_info->num_cb_short;
-	  p_ratio[chanNum]   = p_ratio_short[ps][chanNum];
-          break;
-        case SHORT_LONG_WINDOW:
-	  memcpy( (char*)sfb_width_table[chanNum], (char*)quantInfo[chanNum].sr_info->cb_width_long, (NSFB_LONG+1)*sizeof(int) );
-	  nr_of_sfb[chanNum] = quantInfo[chanNum].sr_info->num_cb_long;
-	  p_ratio[chanNum]   = p_ratio_long[ps][chanNum];
-          break;
-      }
-    }
-  }
-
-  MSPreprocess(p_ratio_long[!ps], p_ratio_short[!ps], chpo_long, chpo_short,
-		block_type, quantInfo, as->use_MS, max_ch);
-
-  MSEnergy(spectral_line_vector, energy, chpo_long, chpo_short, sfb_width_table,
-		block_type, quantInfo, as->use_MS, max_ch);
-
-  {
-    int chanNum;
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-      /* Construct sf band offset table */
-      int offset=0;
-      int sfb;
-      for (sfb=0;sfb<nr_of_sfb[chanNum];sfb++) {
-	sfb_offset_table[chanNum][sfb] = offset;
-	offset+=sfb_width_table[chanNum][sfb];
-      }
-      sfb_offset_table[chanNum][nr_of_sfb[chanNum]]=offset;
-    }
-  }
-
-
-  /************************************************************************
-   Set upper spectral coefficients to zero for LFE
-   ************************************************************************/
-  {
-    int chanNum;
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-      if (quantInfo[chanNum].channelInfo.lfe) {
-        int i;
-        for (i = sfb_offset_table[chanNum][10];
-			i < sfb_offset_table[chanNum][nr_of_sfb[chanNum]]; i++)
-          spectral_line_vector[chanNum][i] = 0;
-      }
-    }
-  }
-
-  /*****************************************************************************
-  * quantization and coding
-  *****************************************************************************/
-  {
-//  int padding_limit = max_bitreservoir_bits;
-    int maxNumBitsByteAligned;
-    int chanNum;
-    int numFillBits;
-    int bitsLeftAfterFill;
-    int orig_used_bits;
-
-    /* bit budget */
-    num_bits_available = (long)(average_bits + available_bitreservoir_bits - used_bits);
-
-    /* find the largest byte-aligned section with fewer bits than num_bits_available */
-    maxNumBitsByteAligned = ((num_bits_available >> 3) << 3);
-
-    /* Compute how many reservoir bits can be used and still be able to byte */
-    /* align without exceeding num_bits_available, and have room for an ID_END marker   */
-    available_bitreservoir_bits = maxNumBitsByteAligned - LEN_SE_ID - average_bits;
-
-    /******************************************/
-    /* Perform TNS analysis and filtering     */
-    /******************************************/
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-		if (!quantInfo[chanNum].channelInfo.lfe) {
-			error = TnsEncode(&quantInfo[chanNum],
-				nr_of_sfb[chanNum],            /* Number of bands per window */
-				block_type[chanNum],
-				sfb_offset_table[chanNum],
-				spectral_line_vector[chanNum],
-				as->use_TNS);
-			if (error == FERROR)
-				return FERROR;
-		} else {
-			quantInfo[chanNum].tnsInfo.tnsDataPresent=0;      /* TNS not used for LFE */
-		}
-    }
-
-    /*******************************************************************************/
-    /* If LTP prediction is used, compute LTP predictor info and residual spectrum */
-    /*******************************************************************************/
-    for(chanNum=0;chanNum<max_ch;chanNum++) {
-      if(as->use_LTP && quantInfo[chanNum].channelInfo.present &&
-		  (!quantInfo[chanNum].channelInfo.lfe) && (block_type[chanNum] != ONLY_SHORT_WINDOW)) {
-        if(quantInfo[chanNum].channelInfo.cpe) {
-    	  if(quantInfo[chanNum].channelInfo.ch_is_left) {
-	    int i;
-	    int leftChan=chanNum;
-	    int rightChan=quantInfo[chanNum].channelInfo.paired_ch;
-
-  	    ltp_enc(spectral_line_vector[leftChan],
-		        tmp_DTimeSigBuf[leftChan],
-		        block_type[leftChan],
-		        WS_SIN,
-		        &sfb_offset_table[leftChan][0],
-		        nr_of_sfb[leftChan],
-		        &quantInfo[leftChan].ltpInfo);
-
-            quantInfo[rightChan].ltpInfo.global_pred_flag = quantInfo[leftChan].ltpInfo.global_pred_flag;
-  	    for(i = 0; i < BLOCK_LEN_LONG; i++)
-    	      quantInfo[rightChan].ltpInfo.pred_mdct[i] = quantInfo[leftChan].ltpInfo.pred_mdct[i];
-  	    for(i = 0; i < MAX_SCFAC_BANDS; i++)
-  	      quantInfo[rightChan].ltpInfo.sfb_prediction_used[i] = quantInfo[leftChan].ltpInfo.sfb_prediction_used[i];
-  	    quantInfo[rightChan].ltpInfo.weight = quantInfo[leftChan].ltpInfo.weight;
-	    quantInfo[rightChan].ltpInfo.delay[0] = quantInfo[leftChan].ltpInfo.delay[0];
-
-	    if (!quantInfo[leftChan].channelInfo.common_window) {
-	      ltp_enc(spectral_line_vector[rightChan],
-			  tmp_DTimeSigBuf[rightChan],
-			  block_type[rightChan],
-			  WS_SIN,
-			  &sfb_offset_table[rightChan][0],
-			  nr_of_sfb[rightChan],
-			  &quantInfo[rightChan].ltpInfo);
-            }
-          } /* if(channelInfo[chanNum].ch_is_left) */
-        } /* if(channelInfo[chanNum].cpe) */
-        else
-	  ltp_enc(spectral_line_vector[chanNum],
-		      tmp_DTimeSigBuf[chanNum],
-		      block_type[chanNum],
-		      WS_SIN,
-		      &sfb_offset_table[chanNum][0],
-		      nr_of_sfb[chanNum],
-		      &quantInfo[chanNum].ltpInfo);
-      } /* if(channelInfo[chanNum].present... */
-      else
-        quantInfo[chanNum].ltpInfo.global_pred_flag = 0;
-    } /* for(chanNum... */
-
-    /******************************************/
-    /* Apply MS stereo                        */
-    /******************************************/
-    if (as->use_MS == 1) {
-      MSEncode(spectral_line_vector,
-	       sfb_offset_table,
-	       block_type,
-	       quantInfo,
-	       max_ch);
-    }
-    else if (as->use_MS == 0) {
-      MSEncodeSwitch(spectral_line_vector,
-		     sfb_offset_table,
-		     quantInfo,
-		     max_ch
-			 );
-    }
-
-    /************************************************/
-    /* Call the AAC quantization and coding module. */
-    /************************************************/
-    for (chanNum = 0; chanNum < max_ch; chanNum++) {
-      int bitsToUse;
-	  if (!as->lfePresent) {
-		  bitsToUse = (int)((average_bits - used_bits)/max_ch);
-		  bitsToUse += (int)(0.2*available_bitreservoir_bits/max_ch);
-	  } else {
-		  /* Calculation of reduced bitrate for LFE */
-		  double lfeBitRatio = 0.14;       /* ratio of LFE bits to bits of one SCE */
-		  int lfeBits = max(200,(int)((average_bits - used_bits) * lfeBitRatio / (max_ch - 1))); /* number of bits for LFE */ 
-		  
-		  if (quantInfo[chanNum].channelInfo.lfe) {
-			  bitsToUse = lfeBits;
-			  bitsToUse += (int)(0.2*available_bitreservoir_bits 
-				  * lfeBitRatio / (max_ch - 1));
-		  } else {
-			  bitsToUse = (int)((average_bits - used_bits - lfeBits) / (max_ch - 1));
-			  bitsToUse += (int)(0.2*available_bitreservoir_bits 
-				  * (1 - lfeBitRatio / (max_ch - 1)) / (max_ch - 1));
-		  }
-	  }
-
-      error = aacQuantize(&quantInfo[chanNum],
-		  &spectral_line_vector[chanNum],
-		  &p_ratio[chanNum],
-		  &allowed_distortion[chanNum],
-		  &energy[chanNum],
-		  &block_type[chanNum],
-		  &sfb_width_table[chanNum],
-		  bitsToUse,
-		  fixed_stream,
-		  &reconstructed_spectrum[chanNum]		  
-		  );
-      if (error == FERROR)
-        return error;
-    }
-
-    /**********************************************************/
-    /* Reconstruct MS Stereo bands for prediction            */
-    /**********************************************************/
-    if (as->use_MS != -1) {
-      MSReconstruct(reconstructed_spectrum,
-		    sfb_offset_table,
-//		    block_type,
-		    quantInfo,
-		    max_ch);
-    }
-
-    /**********************************************************/
-    /* Update LTP history buffer                              */
-    /**********************************************************/
-    if(as->use_LTP)
-      for (chanNum=0;chanNum<max_ch;chanNum++) {
-		  if (!quantInfo[chanNum].channelInfo.lfe) {  /* no reconstruction needed for LFE channel*/
-			  ltp_reconstruct(reconstructed_spectrum[chanNum],
-				  block_type[chanNum],
-				  WS_SIN,
-				  &sfb_offset_table[chanNum][0],
-				  nr_of_sfb[chanNum],
-				  &quantInfo[chanNum].ltpInfo);
-		  }
-      }
-
-
-    /**********************************/
-    /* Write out all encoded channels */
-    /**********************************/
-    used_bits = 0;
-    if (as->header_type==ADTS_HEADER)
-      used_bits += WriteADTSHeader(&quantInfo[0], fixed_stream, used_bits, 0);
-
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-      if (quantInfo[chanNum].channelInfo.present) {
-        /* Write out a single_channel_element */
-        if (!quantInfo[chanNum].channelInfo.cpe) {
-           if (quantInfo[chanNum].channelInfo.lfe) {
-			   /* Write out lfe */ 
-			   used_bits += WriteLFE(&quantInfo[chanNum],   /* Quantization information */
-				   quantInfo[chanNum].channelInfo.tag,
-				   fixed_stream,           /* Bitstream */
-				   0);                     /* Write flag, 1 means write */
-           } else {
-			   /* Write out sce */
-			   used_bits += WriteSCE(&quantInfo[chanNum],   /* Quantization information */
-				   quantInfo[chanNum].channelInfo.tag,
-				   fixed_stream,           /* Bitstream */
-				   0);                     /* Write flag, 1 means write */
-		   }
-        }
-        else {
-	  if (quantInfo[chanNum].channelInfo.ch_is_left) {
-	    /* Write out cpe */
-	    used_bits += WriteCPE(&quantInfo[chanNum],   /* Quantization information,left */
-				  &quantInfo[quantInfo[chanNum].channelInfo.paired_ch],   /* Right */
-				  quantInfo[chanNum].channelInfo.tag,
-				  quantInfo[chanNum].channelInfo.common_window,    /* common window */
-				  &(quantInfo[chanNum].channelInfo.ms_info),
-				  fixed_stream,           /* Bitstream */
-				  0);                     /* Write flag, 1 means write */
-          }
-        }  /* if (!channelInfo[chanNum].cpe)  else */
-      } /* if (chann...*/
-    } /* for (chanNum...*/
-
-    orig_used_bits = used_bits;
-
-    /* Compute how many fill bits are needed to avoid overflowing bit reservoir */
-    /* Save room for ID_END terminator */
-    if (used_bits < (8 - LEN_SE_ID) ) {
-      numFillBits = 8 - LEN_SE_ID - used_bits;
-    }
-    else {
-      numFillBits = 0;
-    }
-
-    /* Write AAC fill_elements, smallest fill element is 7 bits. */
-    /* Function may leave up to 6 bits left after fill, so tell it to fill a few extra */
-    numFillBits += 6;
-    bitsLeftAfterFill=WriteAACFillBits(fixed_stream,numFillBits, 0);
-    used_bits += (numFillBits - bitsLeftAfterFill);
-
-    /* Write ID_END terminator */
-    used_bits += LEN_SE_ID;
-
-    /* Now byte align the bitstream */
-    used_bits += ByteAlign(fixed_stream, 0);
-
-    if (as->header_type==ADTS_HEADER)
-      WriteADTSHeader(&quantInfo[0], fixed_stream, used_bits, 1);
-
-    for (chanNum=0;chanNum<max_ch;chanNum++) {
-      if (quantInfo[chanNum].channelInfo.present) {
-        /* Write out a single_channel_element */
-        if (!quantInfo[chanNum].channelInfo.cpe) {
-           if (quantInfo[chanNum].channelInfo.lfe) {
-			   /* Write out lfe */ 
-			   WriteLFE(&quantInfo[chanNum],   /* Quantization information */
-				   quantInfo[chanNum].channelInfo.tag,
-				   fixed_stream,           /* Bitstream */
-				   1);                     /* Write flag, 1 means write */
-           } else {
-			   /* Write out sce */
-			   WriteSCE(&quantInfo[chanNum],   /* Quantization information */
-				   quantInfo[chanNum].channelInfo.tag,
-				   fixed_stream,           /* Bitstream */
-				   1);                     /* Write flag, 1 means write */
-		   }
-        }
-        else {
-       	  if (quantInfo[chanNum].channelInfo.ch_is_left) {
-	    /* Write out cpe */
-	    WriteCPE(&quantInfo[chanNum],   /* Quantization information,left */
-		     &quantInfo[quantInfo[chanNum].channelInfo.paired_ch],   /* Right */
-		     quantInfo[chanNum].channelInfo.tag,
-		     quantInfo[chanNum].channelInfo.common_window,    /* common window */
-		     &(quantInfo[chanNum].channelInfo.ms_info),
-		     fixed_stream,           /* Bitstream */
-		     1);                     /* Write flag, 1 means write */
-          }
-        }  /* if (!channelInfo[chanNum].cpe)  else */
-      } /* if (chann...*/
-    } /* for (chanNum...*/
-
-    /* Compute how many fill bits are needed to avoid overflowing bit reservoir */
-    /* Save room for ID_END terminator */
-    if (orig_used_bits < (8 - LEN_SE_ID) ) {
-    numFillBits = 8 - LEN_SE_ID - used_bits;
-    }
-    else {
-      numFillBits = 0;
-    }
-
-    /* Write AAC fill_elements, smallest fill element is 7 bits. */
-    /* Function may leave up to 6 bits left after fill, so tell it to fill a few extra */
-    numFillBits += 6;
-    bitsLeftAfterFill=WriteAACFillBits(fixed_stream,numFillBits, 1);
-
-    /* Write ID_END terminator */
-    BsPutBit(fixed_stream,ID_END,LEN_SE_ID);
-
-    /* Now byte align the bitstream */
-    ByteAlign(fixed_stream, 1);
-
-  } /* End of quantization and coding */
-  return FNO_ERROR;
-}
-
--- a/encoder.c
+++ /dev/null
@@ -1,470 +1,0 @@
-/*
- *	Bitstream encoding
- *
- *	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.43 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifdef _WIN32
-#include <windows.h>
-#endif
-
-#include "aacenc.h"
-#include "enc.h"
-#include "rateconv.h"
-
-////////////////////////////////////////////////////////////////////////////////
-int write_ADIF_header(faacAACStream *as)
-{
-  BsBitStream *bitHeader;
-  unsigned char headerBuf[20];
-  float seconds;
-  int i, bits, bytes;
-  static int SampleRates[] = {96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000,0};
-
-  seconds = (float)as->out_sampling_rate/(float)1024;
-  seconds = (float)as->cur_frame/seconds;
-
-  as->total_bits += 17 * 8;
-  bitHeader = BsOpenWrite(200);
-
-  for (i = 0; ; i++){
-    if (SampleRates[i] == as->out_sampling_rate)
-      break;
-    else if (SampleRates[i] == 0)
-      return FERROR;
-  }
-
-  // ADIF_Header
-  BsPutBit(bitHeader,'A',8);
-  BsPutBit(bitHeader,'D',8);
-  BsPutBit(bitHeader,'I',8);
-  BsPutBit(bitHeader,'F',8);
-  BsPutBit(bitHeader,0,1);   // Copyright present
-  BsPutBit(bitHeader,0,1);   // Original
-  BsPutBit(bitHeader,0,1);   // Home
-  BsPutBit(bitHeader,0,1);   // Bitstream type
-  BsPutBit(bitHeader,(int)(as->total_bits/seconds),23);  // Bitrate
-  BsPutBit(bitHeader, 0, 4);   // num program config elements
-
-  // ADIF_buffer_fulness
-  BsPutBit(bitHeader, 0, 20);
-
-  // program_config_element
-  BsPutBit(bitHeader,0,4);
-  BsPutBit(bitHeader,as->profile,2);
-  BsPutBit(bitHeader,i,4);
-  BsPutBit(bitHeader,1,4);
-  BsPutBit(bitHeader,0,4);
-  BsPutBit(bitHeader,0,4);
-  BsPutBit(bitHeader,0,2);
-  BsPutBit(bitHeader,0,3);
-  BsPutBit(bitHeader,0,4);
-  BsPutBit(bitHeader,0,1);
-  BsPutBit(bitHeader,0,1);
-  BsPutBit(bitHeader,0,1);
-  // element_list
-  BsPutBit(bitHeader,(as->channels == 2),1);
-  BsPutBit(bitHeader,0,4);
-
-  ByteAlign(bitHeader, 1);
-  // Comment
-  BsPutBit(bitHeader,0,8);
-
-  bits = BsBufferNumBit(bitHeader);
-
-  // Copy bitBuf into bitBuffer here
-  bytes = (int)((bits+7)/8);
-  for (i = 0; i < bytes; i++)
-    headerBuf[i] = bitHeader->data[i];
-  BsClose(bitHeader);
-  // Write header to a file
-  fseek(as->out_file, 0, SEEK_SET);
-  fwrite(headerBuf, 1, 17, as->out_file);
-  return FNO_ERROR;
-}
-////////////////////////////////////////////////////////////////////////////////
-int faac_EncodeInit(faacAACStream *as, char *in_file, char *out_file)
-{
-  int frameNumSample,delayNumSample;
-  int ch, frames, startupNumFrame;
-
-  if ( strcmp(in_file,"") ) {
-    SF_INFO sf_info;
-
-    as->in_file = sf_open_read(in_file, &sf_info);
-    if (as->in_file == NULL)
-      return -1;
-    if (as->raw_audio) {
-      sf_info.format =  SF_FORMAT_RAW;
-      sf_info.format |= SF_FORMAT_PCM_BE;
-      sf_info.channels = 2;
-      sf_info.pcmbitwidth = 16;
-      sf_info.samplerate = 44100;
-    }
-    frames = (int)(sf_info.samples/1024+0.5);
-    as->channels = sf_info.channels;
-    as->in_sampling_rate = sf_info.samplerate;
-    as->out_sampling_rate = (as->out_sampling_rate) ? (as->out_sampling_rate) : (sf_info.samplerate);
-  }
-  else {
-    as->in_file = NULL;
-    frames = 0;
-    as->out_sampling_rate = (as->out_sampling_rate) ? (as->out_sampling_rate) : (as->in_sampling_rate);
-  }
-  as->cut_off = (as->cut_off) ? (as->cut_off) : ((as->out_sampling_rate)>>1);
-
-  as->out_file = fopen(out_file, "wb");
-  if (as->out_file == NULL)
-    return -2;
-
-  if ((as->inputBuffer = (double**)malloc( as->channels*sizeof(double*))) == NULL)
-    return -3;
-  for (ch=0; ch < as->channels; ch++){
-    if ((as->inputBuffer[ch]=(double*)malloc( 1024*sizeof(double))) == NULL)
-      return -4;
-  }
-
-  if((as->bit_rate % 1000)||(as->bit_rate < 8000))
-    return -5;
-  if (as->channels != 2)
-      if(as->channels == 1)
-        as->use_MS=-1;
-//      else
-//        return -6;
-  if ((as->profile != MAIN_PROFILE)&&(as->profile != LOW_PROFILE))
-    return -7;
-
-  as->total_bits = 0;
-  as->frames = 0;
-  as->cur_frame = 0;
-  as->is_first_frame = 1;
-
-  if (as->in_sampling_rate != as->out_sampling_rate)
-    as->rc_needed = 1;
-  else
-    as->rc_needed = 0;
-
-  EncTfInit(as);
-
-  frameNumSample = 1024;
-  delayNumSample = 2*frameNumSample;
-
-  as->samplesToRead = frameNumSample * as->channels;
-
-  as->frame_bits = (int)((as->bit_rate*as->channels)*frameNumSample/as->out_sampling_rate+0.5);
-  as->bitBufferSize = (int)(((as->frame_bits * 5) + 7)/8);
-
-
-  /* num frames to start up encoder due to delay compensation */
-  startupNumFrame = (delayNumSample+frameNumSample-1)/frameNumSample;
-
-  /* process audio file frame by frame */
-  as->cur_frame = -startupNumFrame;
-  as->available_bits = 8184;
-
-  if (as->rc_needed) {
-    as->rc_buf = RateConvInit (0,		/* in: debug level */
-		(double)as->out_sampling_rate/(double)as->in_sampling_rate, /* in: outputRate / inputRate */
-		as->channels,		/* in: number of channels */
-		-1,			/* in: num taps */
-		-1,			/* in: alpha for Kaiser window */
-		-1,			/* in: 6dB cutoff freq / input bandwidth */
-		-1,			/* in: 100dB cutoff freq / input bandwidth */
-		&as->samplesToRead);        /* out: num input samples / frame */
-  }
-  else
-    as->samplesToRead = 1024*as->channels;
-
-  as->savedSize = 0;
-
-  if (as->header_type == ADIF_HEADER) {
-    char tmp[17];
-    memset(tmp, 0, 17*sizeof(char));
-    fwrite(tmp, 1, 17, as->out_file);
-  }
-  as->sampleBuffer = (short*) malloc(as->samplesToRead*sizeof(short));
-  as->bitBuffer = (unsigned char*) malloc((as->bitBufferSize+100)*sizeof(char));
-
-  return frames;
-}
-////////////////////////////////////////////////////////////////////////////////
-int faac_EncodeFrameCore(faacAACStream *as, int Samples)
-{
-  int i, j, error;
-  int usedNumBit, usedBytes;
-  int samplesOut, curSample = 0;
-  BsBitStream *bitBuf;
-  float *dataOut;
-  float *data = NULL;
-  int totalBytes = 0;
-
-  // Is this the last (incomplete) frame
-  if ((Samples < as->samplesToRead)&&(Samples > 0)) {
-    // Padd with zeros
-    memset(as->sampleBuffer + Samples, 0, (as->samplesToRead-Samples)*sizeof(short));
-  }
-
-  if (as->rc_needed && (Samples > 0)) {
-    samplesOut = as->savedSize + RateConv (
-                 as->rc_buf,			/* in: buffer (handle) */
-                 as->sampleBuffer,		/* in: input data[] */
-	         as->samplesToRead,		/* in: number of input samples */
-	         &dataOut);
-
-    data = (float*) malloc((samplesOut)*sizeof(float));
-    for (i = 0; i < as->savedSize; i++)
-      data[i] = as->saved[i];
-    for (j = 0; i < samplesOut; i++, j++)
-      data[i] = dataOut[j];
-  }
-  else if (Samples > 0) {
-    samplesOut = 1024*as->channels;
-    data = (float*) malloc((samplesOut)*sizeof(float));
-    for (i = 0; i < samplesOut; i++)
-      data[i] = as->sampleBuffer[i];
-  }
-  else
-    samplesOut = 1024*as->channels;
-
-  while(samplesOut >= 1024*as->channels) {
-    // Process Buffer
-    if (as->sampleBuffer) {
-//      if (as->channels == 2) {
-        if (Samples > 0)
-          for (i = 0; i < 1024; i++) {
-//	    as->inputBuffer[0][i] = data[curSample+(i*as->channels)];
-			  for (j = 0; j < as->channels; j++)
-				  as->inputBuffer[j][i] = data[curSample+(i*as->channels)+j];
-	  }
-        else // (Samples == 0) when called by faacEncodeFinish
-          for (i = 0; i < 1024; i++) {
-	    as->inputBuffer[0][i] = 0;
-            as->inputBuffer[1][i] = 0;
-	  }
-//        }
-//      else {
-        // No mono supported yet (basically only a problem with decoder
-        // the encoder in fact supports it).
-//        return FERROR;
-//      }
-    }
-
-  if (as->is_first_frame) {
-    EncTfFrame(as, (BsBitStream*)NULL);
-    as->is_first_frame = 0;
-    as->cur_frame++;
-
-    as->bitBufferSize = 0;
-
-    samplesOut -= (as->channels*1024);
-    curSample  += (as->channels*1024);
-
-    continue;
-  }
-
-  bitBuf = BsOpenWrite(as->frame_bits * 10);
-
-  /* compute available number of bits */
-  /* frameAvailNumBit contains number of bits in reservoir */
-  /* variable bit rate: don't exceed bit reservoir size */
-  if (as->available_bits > 8184)
-    as->available_bits = 8184;
-
-  /* Add to frameAvailNumBit the number of bits for this frame */
-  as->available_bits += as->frame_bits;
-
-  /* Encode frame */
-  error = EncTfFrame(as, bitBuf);
-
-  if (error == FERROR)
-    return FERROR;
-
-  usedNumBit = BsBufferNumBit(bitBuf);
-  as->total_bits += usedNumBit;
-
-  // Copy bitBuf into bitBuffer here
-  usedBytes = (int)((usedNumBit+7)/8);
-  for (i = 0; i < usedBytes; i++)
-    as->bitBuffer[i+totalBytes] = bitBuf->data[i];
-  totalBytes += usedBytes;
-  BsClose(bitBuf);
-
-  /* Adjust available bit counts */
-  as->available_bits -= usedNumBit;    /* Subtract bits used */
-
-  as->cur_frame++;
-
-  samplesOut -= (as->channels*1024);
-  curSample  += (as->channels*1024);
-  }
-
-  as->bitBufferSize = totalBytes;
-
-  as->savedSize = samplesOut;
-  for (i = 0; i < samplesOut; i++)
-    as->saved[i] = data[curSample+i];
-  if (data)
-    free(data);
-
-  fwrite(as->bitBuffer, 1, as->bitBufferSize, as->out_file);
-  return FNO_ERROR;
-}
-////////////////////////////////////////////////////////////////////////////////
-int faac_EncodeFrame(faacAACStream *as)
-{
-  int Samples;
-
-  Samples = sf_read_short(as->in_file, as->sampleBuffer, as->samplesToRead);
-  if ( Samples > 0 )
-    if ( faac_EncodeFrameCore(as, Samples) == FERROR)
-      return FERROR;
-  if (Samples < as->samplesToRead) {
-    if(as->sampleBuffer){
-      free(as->sampleBuffer);
-      as->sampleBuffer = NULL;
-    }
-    faac_EncodeFrameCore(as,0);
-    faac_EncodeFrameCore(as,0);
-    return F_FINISH;
-    }
-  return FNO_ERROR;
-}
-////////////////////////////////////////////////////////////////////////////////
-int faac_BlockEncodeFrame(faacAACStream *as, short *input_samples, int Samples)
-{
-  memcpy(as->sampleBuffer,input_samples,sizeof(short)*Samples);
-  if (Samples < as->samplesToRead) {
-    faac_EncodeFrameCore(as,Samples);
-    if(as->sampleBuffer){
-      free(as->sampleBuffer);
-      as->sampleBuffer = NULL;
-    }
-    faac_EncodeFrameCore(as,0);
-    faac_EncodeFrameCore(as,0);
-    return F_FINISH;
-    }
-  else
-    return faac_EncodeFrameCore(as,Samples);
-}
-////////////////////////////////////////////////////////////////////////////////
-void faac_EncodeFree(faacAACStream *as)
-{
-  int ch;
-
-  /* free encoder memory */
-  EncTfFree();
-  if (as->rc_needed)
-    RateConvFree (as->rc_buf);
-
-  for(ch=0; ch < as->channels; ch++)
-    if(as->inputBuffer[ch])
-      free(as->inputBuffer[ch]);
-  if(as->inputBuffer)
-    free(as->inputBuffer);
-
-  if (as->header_type == ADIF_HEADER)
-    write_ADIF_header(as);
-
-  if ( as->in_file != NULL )
-    sf_close(as->in_file);
-  fclose(as->out_file);
-
-  if (as->bitBuffer)
-    free(as->bitBuffer);
-}
-////////////////////////////////////////////////////////////////////////////////
-faacVersion *faac_Version(void)
-{
-  faacVersion *faacv = malloc(sizeof(faacVersion));
-
-  faacv->DLLMajorVersion = 2;
-  faacv->DLLMinorVersion = 30;
-  faacv->MajorVersion = 0;
-  faacv->MinorVersion = 70;
-  strcpy(faacv->HomePage, "http://www.audiocoding.com/");
-
-  return faacv;
-}
-////////////////////////////////////////////////////////////////////////////////
-void faac_InitParams(faacAACStream *as)
-{
-  as->profile = MAIN_PROFILE;
-  as->header_type = ADTS_HEADER;
-  as->use_MS = 0;
-  as->use_TNS = 1;
-  as->use_LTP = 1;
-  as->use_PNS = 0;
-  as->lfePresent = 0;
-  as->cut_off = 0;
-  as->bit_rate = 64000;
-  as->out_sampling_rate = 0;
-  as->raw_audio = 0;
-}
-////////////////////////////////////////////////////////////////////////////////
-void faac_SetParam(faacAACStream *as, int param, int value)
-{
-  switch (param){
-    case PROFILE:
-      as->profile = value;
-      break;
-    case HEADER_TYPE:
-      as->header_type = value;
-      break;
-    case MS_STEREO:
-      as->use_MS = value;
-      break;
-    case BITRATE:
-      as->bit_rate = value*1000;
-      break;
-    case CUT_OFF:
-      as->cut_off = value;
-      break;
-    case OUT_SAMPLING_RATE:
-      as->out_sampling_rate = value;
-      break;
-    case RAW_AUDIO:
-      as->raw_audio = value;
-      break;
-    case TNS:
-      as->use_TNS = value;
-      break;
-    case LTP:
-      as->use_LTP = value;
-      break;
-    case PNS:
-      as->use_PNS = value;
-      break;
-	case LFE_PRESENT:
-		as->lfePresent = value;
-		break;
-    case IN_SAMPLING_RATE:
-      as->in_sampling_rate = value;
-      break;
-    case NUMBER_OF_CHANNELS:
-      as->channels = value;
-      break;
-  }
-}
-////////////////////////////////////////////////////////////////////////////////
--- a/faac.c
+++ /dev/null
@@ -1,378 +1,0 @@
-/*
- *	FAAC main
- *
- *	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.17 $
-  $Date: 2000/12/04 20:03:47 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifdef _WIN32
-#include <windows.h>
-#else
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#endif
-#ifdef LINUX
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <unistd.h>
-#endif
-
-#include "aacenc.h"
-#include "bitstream.h"
-
-#ifdef FAAC_DLL
-
-BOOL APIENTRY DllMain(HANDLE hModule,
-                      DWORD  ul_reason_for_call,
-                      LPVOID lpReserved)
-{
-  return TRUE;
-}
-
-#else  // Not dll
-
-char *get_filename(char *pPath)
-{
-  char *pT;
-
-  for (pT = pPath; *pPath; pPath++) {
-   if ((pPath[0] == '\\' || pPath[0] == ':') && pPath[1] && (pPath[1] != '\\'))
-     pT = pPath + 1;
-  }
-
-  return pT;
-}
-
-void combine_path(char *path, char *dir, char *file)
-{
-  /* Should be a bit more sophisticated
-    This code assumes that the path exists */
-
-  /* Assume dir is allocated big enough */
-  if (dir[strlen(dir)-1] != '\\')
-    strcat(dir, "\\");
-  strcat(dir, get_filename(file));
-  strcpy(path, dir);
-}
-
-void usage(char* argv0ptr)
-{
-  printf("Usage:\n");
-  printf("%s -options file ...\n", argv0ptr);
-  printf("Options:\n");
-  printf(" -?    Shows this help screen.\n");
-  printf(" -pX   AAC profile (X can be LOW, or MAIN (default).\n");
-  printf(" -bX   Bitrate in kbps/channel (in steps of 1kbps, min. 16kbps)\n");
-  printf(" -pns  Use PNS (Perceptual Noise Substitution).\n");
-  printf(" -nt   Don't use TNS (Temporal Noise Shaping).\n");
-  printf(" -ms   Use mid/side stereo coding.\n");
-  printf(" -nm   Don't use mid/side stereo coding.\n");
-  printf("       The default for MS is intelligent switching.\n");
-  printf(" -np   Don't use LTP (Long Term Prediction).\n");
-  printf(" -lfe  Use LFE (Low Frequency Enhancement) channel.\n");
-  printf(" -oX   Set output directory.\n");
-  printf(" -sX   Set output sampling rate.\n");
-  printf(" -cX   Set cut-off frequency.\n");
-  printf(" -r    Use raw data input file.\n");
-  printf(" -hN   No header will be written to the AAC file.\n");
-  printf(" -hS   ADTS headers will be written to the AAC file(default).\n");
-  printf(" -hI   ADIF header will be written to the AAC file.\n");
-  printf(" file  Multiple files can be given as well as wild cards.\n");
-  printf("       Can be any of the filetypes supported by libsndfile\n");
-  printf("       (http://www.zip.com.au/~erikd/libsndfile/).\n");
-  printf("Example:\n");
-  printf("       %s -b96 -oc:\\aac\\ *.wav\n", argv0ptr);
-  return;
-}
-
-int parse_arg(int argc, char *argv[],faacAACStream *as, char *InFileNames[100], char *OutFileNames[100])
-{
-  int i, out_dir_set=0, FileCount=0;
-  char *argp, *fnp, out_dir[255];
-
-  faac_InitParams(as);
-  if (argc == 1) {
-    usage(argv[0]);
-    return -1;
-  }
-
-  for (i = 1; i < argc; i++) {
-    if ((argv[i][0] != '-')&&(argv[i][0] != '/')) {
-      if (strchr("-/", argv[i][0]))
-      	argp = &argv[i][1];
-      else
-        argp = argv[i];
-
-      if (!strchr(argp, '*') && !strchr(argp, '?')) {
-	InFileNames[FileCount] = (char*) malloc((strlen(argv[i])+1)*sizeof(char));
-	OutFileNames[FileCount] = (char*) malloc((strlen(argv[i])+1)*sizeof(char));
-	strcpy(InFileNames[FileCount], argv[i]);
-	FileCount++;
-      }
-      else {
-#ifdef _WIN32
-	HANDLE hFindFile;
-	WIN32_FIND_DATA fd;
-
-        char path[255], *p;
-
-        if (NULL == (p = strrchr(argp, '\\')))
-	  p = strrchr(argp, '/');
-        if (p) {
-	  char ch = *p;
-
-	  *p = 0;
-	  strcat(strcpy(path, argp), "\\");
-	  *p = ch;
-        }
-	else
-	  *path = 0;
-
-	  if (INVALID_HANDLE_VALUE != (hFindFile = FindFirstFile(argp, &fd))) {
-	     do {
-	       InFileNames[FileCount] = (char*) malloc((strlen(fd.cFileName) + strlen(path) + 2)*sizeof(char));
-	       OutFileNames[FileCount] = (char*) malloc((strlen(fd.cFileName) + strlen(path) + 2)*sizeof(char));
-               strcat(strcpy(InFileNames[FileCount], path), fd.cFileName);
-	       FileCount++;
-             }
-             while (FindNextFile(hFindFile, &fd));
-	  FindClose(hFindFile);
-        }
-#else
-	printf("Wildcards not yet supported on systems other than WIN32\n");
-#endif
-      }
-    }
-    else {
-      switch(argv[i][1]) {
-      	case 'p': case 'P':
-	  if ((argv[i][2] == 'n') || (argv[i][2] == 'N'))
-	    faac_SetParam(as,PNS,USE_PNS);
-          else if ((argv[i][2] == 'l') || (argv[i][2] == 'L'))
-            faac_SetParam(as,PROFILE,LOW_PROFILE);
-	  else if ((argv[i][2] == 'm') || (argv[i][2] == 'M'))
-	    faac_SetParam(as,PROFILE,MAIN_PROFILE);
-          else {
-            printf("Unknown option: %s\n", argv[i]);
-            return 0;
-          }
-          break;
-        case 'n': case 'N':
-	  if ((argv[i][2] == 'm') || (argv[i][2] == 'M'))
-	    faac_SetParam(as,MS_STEREO,NO_MS);
-          else if ((argv[i][2] == 'p') || (argv[i][2] == 'P'))
-	    faac_SetParam(as,LTP,NO_LTP);
-          else if ((argv[i][2] == 't') || (argv[i][2] == 'T'))
-	  faac_SetParam(as,TNS,NO_TNS);
-          else {
-            printf("Unknown option: %s\n", argv[i]);
-            return 0;
-          }
-	  break;
-        case 'h': case 'H':
-          if ((argv[i][2] == 'i') || (argv[i][2] == 'I'))
-	    faac_SetParam(as,HEADER_TYPE,ADIF_HEADER);
-          else if ((argv[i][2] == 's') || (argv[i][2] == 'S'))
-	    faac_SetParam(as,HEADER_TYPE,ADTS_HEADER);
-          else if ((argv[i][2] == 'n') || (argv[i][2] == 'N'))
-	    faac_SetParam(as,HEADER_TYPE,NO_HEADER);
-          else {
-            printf("Unknown option: %s\n", argv[i]);
-            return 0;
-          }
-	  break;
-        case 'm': case 'M':
-	  faac_SetParam(as,MS_STEREO,FORCE_MS);
-	  break;
-	case 'r': case 'R':
-	  faac_SetParam(as,RAW_AUDIO,USE_RAW_AUDIO);
-	  break;
-	case 'b': case 'B':
-	  faac_SetParam(as,BITRATE,atoi(&argv[i][2]));
-	  break;
-	case 's': case 'S':
-	  faac_SetParam(as,OUT_SAMPLING_RATE,atoi(&argv[i][2]));
-	  break;
-        case 'c': case 'C':
-	  faac_SetParam(as,CUT_OFF,atoi(&argv[i][2]));
-	  break;
-        case 'l': case 'L':
-	  faac_SetParam(as,LFE_PRESENT,USE_LFE);
-	  break;
-        case 'o': case 'O':
-	  out_dir_set = 1;
-	  strcpy(out_dir, &argv[i][2]);
-	  break;
-	case '?':
-	  usage(argv[0]);
-	  return 0;
-        default:
-          printf("Unknown option: %s\n", argv[i]);
-          return 0;
-      }
-    }   // else  of:  if ((argv[i][0] != '-')&&(argv[i][0] != '/')) {
-  } //   for (i = 1; i < argc; i++) {
-
-  if (FileCount == 0)
-    return -1;
-  else {
-    for (i = 0; i < FileCount; i++){
-      if (out_dir_set)
-        combine_path(OutFileNames[i], out_dir, InFileNames[i]);
-      else
-        strcpy(OutFileNames[i], InFileNames[i]);
-      fnp = strrchr(OutFileNames[i],'.');
-      fnp[0] = '\0';
-      strcat(OutFileNames[i],".aac");
-    }
-  }
-  return FileCount;
-}
-
-void printVersion(void)
-{
-  faacVersion *faacv;
-  faacv = faac_Version();
-  printf("FAAC cl (Freeware AAC Encoder)\n");
-  printf("FAAC homepage: %s\n", faacv->HomePage);
-  printf("Encoder engine version: %d.%d\n\n",
-	 faacv->MajorVersion, faacv->MinorVersion);
-  if (faacv)
-    free(faacv);
-}
-
-void printConf(faacAACStream *as)
-{
-  printf("AAC configuration:\n");
-  printf("----------------------------------------------\n");
-  printf("AAC profile: %s.\n", (as->profile==MAIN_PROFILE)?"MAIN":"LOW");
-  printf("Bitrate: %dkbps/ch.\n", as->bit_rate/1000);
-  printf("Mid/Side (MS) stereo coding: %s.\n",
- 	(as->use_MS==1)?"Always (If CPE)":((as->use_MS==0)?"Switching (If CPE)":"Off"));
-  printf("Temporal Noise Shaping: %s.\n", as->use_TNS?"On":"Off");
-  printf("Long Term Prediction: %s.\n", as->use_LTP?"On":"Off");
-  printf("Perceptual Noise Substitution: %s.\n", as->use_PNS?"On":"Off");
-  if (as->out_sampling_rate)
-    printf("Output sampling rate: %dHz.\n", as->out_sampling_rate);
-  if (as->cut_off)
-    printf("Cut-off frequency: %dHz.\n", as->cut_off);
-  if (as->header_type == ADIF_HEADER)
-    printf("Header info: ADIF header (seeking disabled)\n");
-  else if (as->header_type == ADTS_HEADER)
-    printf("Header info: ADTS headers (seeking enabled)\n");
-  else
-    printf("Header info: no headers (seeking disabled)\n");
-  printf("----------------------------------------------\n");
-}
-
-int main(int argc, char *argv[])
-{
-#ifdef LINUX
-    struct rusage *usage;
-#endif
-  int i, frames, currentFrame, result, FileCount;
-  char *InFileNames[100], *OutFileNames[100];
-  faacAACStream *as;
-
-	/* System dependant types */
-#ifdef _WIN32
-  long	begin, end;
-  int nTotSecs, nSecs;
-  int nMins;
-#else
-  float	totalSecs;
-  int mins;
-#endif
-
-  /* create main aacstream object */
-  as =(faacAACStream *) malloc(sizeof(faacAACStream));
-
-  /* Print version of FAAC */
-  printVersion();
-
-  /* Process command line params */
-  if ((FileCount=parse_arg(argc, argv, as, InFileNames, OutFileNames)) < 1) return 0;
-
-  /* Print configuration */
-  printConf(as);
-
-  /* Process input files */
-  for (i = 0; i < FileCount; i++) {
-    printf("0%\tBusy encoding %s.\r", InFileNames[i]);
-#ifdef _WIN32
-    begin = GetTickCount();
-#endif
-
-    /* Init encoder core and retrieve number of frames */
-    if ((frames=faac_EncodeInit(as, InFileNames[i], OutFileNames[i])) < 0) {
-      printf("Error %d while encoding %s.\n",-frames,InFileNames[i]);
-      continue;
-    }
-    currentFrame = 0;
-    // Keep encoding frames until the end of the audio file
-    do {
-      currentFrame++;
-      result = faac_EncodeFrame(as);
-      if (result == FERROR) {
-        printf("Error while encoding %s.\n", InFileNames[i]);
-	break;
-      }
-      printf("%.2f%%\tBusy encoding %s.\r", min((double)(currentFrame*100)/frames,100),InFileNames[i]);
-
-    } while (result != F_FINISH);
-
-    /* destroying internal data */
-    faac_EncodeFree(as);
-#ifdef _WIN32
-    end = GetTickCount();
-    nTotSecs = (end-begin)/1000;
-    nMins = nTotSecs / 60;
-    nSecs = nTotSecs - (60*nMins);
-    printf("Encoding %s took:\t%d:%.2d\t\n", InFileNames[i], nMins, nSecs);
-#else
-#ifdef LINUX
-    usage=malloc(sizeof(struct rusage*));
-    getrusage(RUSAGE_SELF,usage);
-    totalSecs=usage->ru_utime.tv_sec;
-    free(usage);
-    mins = totalSecs/60;
-    printf("Encoding %s took: %i min, %.2f sec. of cpu-time\n", InFileNames[i], mins, totalSecs - (60 * mins));
-#else
-    totalSecs = (float)(clock())/(float)CLOCKS_PER_SEC;
-    mins = totalSecs/60;
-    printf("Encoding %s took: %i min, %.2f sec.\n", InFileNames[i], mins, totalSecs - (60 * mins));
-#endif
-#endif
-    if(InFileNames[i]) free(InFileNames[i]);
-    if(OutFileNames[i]) free(OutFileNames[i]);
-  }
-  if (as) free (as);
-//  exit(FNO_ERROR); // Uncomment to use profiling on *nix systems
-  return FNO_ERROR;
-}
-
-#endif // end of not dll
-
-
--- a/faac.dsp
+++ /dev/null
@@ -1,155 +1,0 @@
-# Microsoft Developer Studio Project File - Name="faac" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=faac - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE 
-!MESSAGE NMAKE /f "faac.mak".
-!MESSAGE 
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE 
-!MESSAGE NMAKE /f "faac.mak" CFG="faac - Win32 Debug"
-!MESSAGE 
-!MESSAGE Possible choices for configuration are:
-!MESSAGE 
-!MESSAGE "faac - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "faac - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE 
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "faac - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "ReleaseFAAC"
-# PROP BASE Intermediate_Dir "ReleaseFAAC"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "ReleaseFAAC"
-# PROP Intermediate_Dir "ReleaseFAAC"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x413 /d "NDEBUG"
-# ADD RSC /l 0x413 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.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 libsndfile.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
-# SUBTRACT LINK32 /nodefaultlib
-
-!ELSEIF  "$(CFG)" == "faac - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "DebugFAAC"
-# PROP BASE Intermediate_Dir "DebugFAAC"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "DebugFAAC"
-# PROP Intermediate_Dir "DebugFAAC"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD BASE RSC /l 0x413 /d "_DEBUG"
-# ADD RSC /l 0x413 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.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 libsndfile.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 /debug /machine:I386
-
-!ENDIF 
-
-# Begin Target
-
-# Name "faac - Win32 Release"
-# Name "faac - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\aac_se_enc.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\bitstream.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\enc_tf.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\encoder.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\faac.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\fastfft.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\huffman.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ltp_enc.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\mc_enc.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ms.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\psych.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\pulse.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\quant.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\rateconv.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\tns.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\transfo.c
-# End Source File
-# End Group
-# End Target
-# End Project
--- a/faac.dsw
+++ /dev/null
@@ -1,41 +1,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "faac"=.\faac.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "faac_dll"=.\faac_dll.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
--- a/faac_dll.dsp
+++ /dev/null
@@ -1,163 +1,0 @@
-# Microsoft Developer Studio Project File - Name="faac_dll" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=faac_dll - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE 
-!MESSAGE NMAKE /f "faac_dll.mak".
-!MESSAGE 
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE 
-!MESSAGE NMAKE /f "faac_dll.mak" CFG="faac_dll - Win32 Debug"
-!MESSAGE 
-!MESSAGE Possible choices for configuration are:
-!MESSAGE 
-!MESSAGE "faac_dll - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "faac_dll - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE 
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "faac_dll - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "ReleaseDLL"
-# PROP BASE Intermediate_Dir "ReleaseDLL"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "ReleaseDLL"
-# PROP Intermediate_Dir "ReleaseDLL"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FAAC_DLL_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MT /O2 /D "NDEBUG" /D "FAAC_DLL" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FAAC_DLL_EXPORTS" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x413 /d "NDEBUG"
-# ADD RSC /l 0x413 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.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 /nologo /dll /machine:I386
-# ADD LINK32 libsndfile.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 /dll /machine:I386 /out:"ReleaseDLL/faac.dll"
-
-!ELSEIF  "$(CFG)" == "faac_dll - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "DebugDLL"
-# PROP BASE Intermediate_Dir "DebugDLL"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "DebugDLL"
-# PROP Intermediate_Dir "DebugDLL"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FAAC_DLL_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "FAAC_DLL" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FAAC_DLL_EXPORTS" /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x413 /d "_DEBUG"
-# ADD RSC /l 0x413 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.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 /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 libsndfile.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 /dll /debug /machine:I386 /out:"Debug/faac.dll" /pdbtype:sept
-
-!ENDIF 
-
-# Begin Target
-
-# Name "faac_dll - Win32 Release"
-# Name "faac_dll - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\aac_se_enc.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\bitstream.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\enc_tf.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\encoder.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\faac.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\fastfft.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\huffman.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ltp_enc.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\mc_enc.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ms.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\psych.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\pulse.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\quant.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\rateconv.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\tns.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\transfo.c
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
--- a/fastfft.c
+++ /dev/null
@@ -1,3618 +1,0 @@
-/*
- *	Fast FFT routines
- *
- *	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.8 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include "fastfft.h"
-
-int unscambled64[64];
-int unscambled128[128];
-int unscambled512[512];
-int unscambled1024[1024];
-fftw_complex FFTarray[1024];    /* the array for in-place FFT */
-
-fftw_real K980785280[1] =
-{FFTW_KONST(+0.980785280403230449126182236134239036973933731)};
-fftw_real K195090322[1] =
-{FFTW_KONST(+0.195090322016128267848284868477022240927691618)};
-fftw_real K555570233[1] =
-{FFTW_KONST(+0.555570233019602224742830813948532874374937191)};
-fftw_real K831469612[1] =
-{FFTW_KONST(+0.831469612302545237078788377617905756738560812)};
-fftw_real K923879532[1] =
-{FFTW_KONST(+0.923879532511286756128183189396788286822416626)};
-fftw_real K382683432[1] =
-{FFTW_KONST(+0.382683432365089771728459984030398866761344562)};
-fftw_real K707106781[1] =
-{FFTW_KONST(+0.707106781186547524400844362104849039284835938)};
-
-fftw_complex PFFTW(W_64)[30] = {
-{ 0.995184726672197, 0.0980171403295606 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.956940335732209, 0.290284677254462 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 0.881921264348355, 0.471396736825998 },
-{ 0.555570233019602, 0.831469612302545 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.38268343236509, 0.923879532511287 },
-{ 0.773010453362737, 0.634393284163645 },
-{ 0.195090322016128, 0.98078528040323 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 6.12303176911189e-17, 1 },
-{ 0.634393284163645, 0.773010453362737 },
-{ -0.195090322016128, 0.98078528040323 },
-{ 0.555570233019602, 0.831469612302545 },
-{ -0.38268343236509, 0.923879532511287 },
-{ 0.471396736825998, 0.881921264348355 },
-{ -0.555570233019602, 0.831469612302545 },
-{ 0.38268343236509, 0.923879532511287 },
-{ -0.707106781186547, 0.707106781186548 },
-{ 0.290284677254462, 0.956940335732209 },
-{ -0.831469612302545, 0.555570233019602 },
-{ 0.195090322016128, 0.98078528040323 },
-{ -0.923879532511287, 0.38268343236509 },
-{ 0.0980171403295608, 0.995184726672197 },
-{ -0.98078528040323, 0.195090322016129 },
-};
-
-fftw_complex PFFTW(W_128)[62] = {
-{ 0.998795456205172, 0.049067674327418 },
-{ 0.995184726672197, 0.0980171403295606 },
-{ 0.995184726672197, 0.0980171403295606 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.989176509964781, 0.146730474455362 },
-{ 0.956940335732209, 0.290284677254462 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.970031253194544, 0.242980179903264 },
-{ 0.881921264348355, 0.471396736825998 },
-{ 0.956940335732209, 0.290284677254462 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.941544065183021, 0.33688985339222 },
-{ 0.773010453362737, 0.634393284163645 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 0.903989293123443, 0.427555093430282 },
-{ 0.634393284163645, 0.773010453362737 },
-{ 0.881921264348355, 0.471396736825998 },
-{ 0.555570233019602, 0.831469612302545 },
-{ 0.857728610000272, 0.514102744193222 },
-{ 0.471396736825998, 0.881921264348355 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.38268343236509, 0.923879532511287 },
-{ 0.803207531480645, 0.595699304492433 },
-{ 0.290284677254462, 0.956940335732209 },
-{ 0.773010453362737, 0.634393284163645 },
-{ 0.195090322016128, 0.98078528040323 },
-{ 0.740951125354959, 0.671558954847018 },
-{ 0.0980171403295608, 0.995184726672197 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 6.12303176911189e-17, 1 },
-{ 0.671558954847018, 0.740951125354959 },
-{ -0.0980171403295606, 0.995184726672197 },
-{ 0.634393284163645, 0.773010453362737 },
-{ -0.195090322016128, 0.98078528040323 },
-{ 0.595699304492433, 0.803207531480645 },
-{ -0.290284677254462, 0.956940335732209 },
-{ 0.555570233019602, 0.831469612302545 },
-{ -0.38268343236509, 0.923879532511287 },
-{ 0.514102744193222, 0.857728610000272 },
-{ -0.471396736825998, 0.881921264348355 },
-{ 0.471396736825998, 0.881921264348355 },
-{ -0.555570233019602, 0.831469612302545 },
-{ 0.427555093430282, 0.903989293123443 },
-{ -0.634393284163645, 0.773010453362737 },
-{ 0.38268343236509, 0.923879532511287 },
-{ -0.707106781186547, 0.707106781186548 },
-{ 0.33688985339222, 0.941544065183021 },
-{ -0.773010453362737, 0.634393284163645 },
-{ 0.290284677254462, 0.956940335732209 },
-{ -0.831469612302545, 0.555570233019602 },
-{ 0.242980179903264, 0.970031253194544 },
-{ -0.881921264348355, 0.471396736825998 },
-{ 0.195090322016128, 0.98078528040323 },
-{ -0.923879532511287, 0.38268343236509 },
-{ 0.146730474455362, 0.989176509964781 },
-{ -0.956940335732209, 0.290284677254462 },
-{ 0.0980171403295608, 0.995184726672197 },
-{ -0.98078528040323, 0.195090322016129 },
-{ 0.0490676743274181, 0.998795456205172 },
-{ -0.995184726672197, 0.0980171403295608 },
-};
-
-fftw_complex PFFTW(W_256)[126] = {
-{ 0.999698818696204, 0.0245412285229123 },
-{ 0.998795456205172, 0.049067674327418 },
-{ 0.998795456205172, 0.049067674327418 },
-{ 0.995184726672197, 0.0980171403295606 },
-{ 0.99729045667869, 0.0735645635996674 },
-{ 0.989176509964781, 0.146730474455362 },
-{ 0.995184726672197, 0.0980171403295606 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.99247953459871, 0.122410675199216 },
-{ 0.970031253194544, 0.242980179903264 },
-{ 0.989176509964781, 0.146730474455362 },
-{ 0.956940335732209, 0.290284677254462 },
-{ 0.985277642388941, 0.170961888760301 },
-{ 0.941544065183021, 0.33688985339222 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.975702130038529, 0.21910124015687 },
-{ 0.903989293123443, 0.427555093430282 },
-{ 0.970031253194544, 0.242980179903264 },
-{ 0.881921264348355, 0.471396736825998 },
-{ 0.96377606579544, 0.266712757474898 },
-{ 0.857728610000272, 0.514102744193222 },
-{ 0.956940335732209, 0.290284677254462 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.949528180593037, 0.313681740398892 },
-{ 0.803207531480645, 0.595699304492433 },
-{ 0.941544065183021, 0.33688985339222 },
-{ 0.773010453362737, 0.634393284163645 },
-{ 0.932992798834739, 0.359895036534988 },
-{ 0.740951125354959, 0.671558954847018 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 0.914209755703531, 0.40524131400499 },
-{ 0.671558954847018, 0.740951125354959 },
-{ 0.903989293123443, 0.427555093430282 },
-{ 0.634393284163645, 0.773010453362737 },
-{ 0.893224301195515, 0.449611329654607 },
-{ 0.595699304492433, 0.803207531480645 },
-{ 0.881921264348355, 0.471396736825998 },
-{ 0.555570233019602, 0.831469612302545 },
-{ 0.870086991108711, 0.492898192229784 },
-{ 0.514102744193222, 0.857728610000272 },
-{ 0.857728610000272, 0.514102744193222 },
-{ 0.471396736825998, 0.881921264348355 },
-{ 0.844853565249707, 0.534997619887097 },
-{ 0.427555093430282, 0.903989293123443 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.38268343236509, 0.923879532511287 },
-{ 0.817584813151584, 0.575808191417845 },
-{ 0.33688985339222, 0.941544065183021 },
-{ 0.803207531480645, 0.595699304492433 },
-{ 0.290284677254462, 0.956940335732209 },
-{ 0.788346427626606, 0.615231590580627 },
-{ 0.242980179903264, 0.970031253194544 },
-{ 0.773010453362737, 0.634393284163645 },
-{ 0.195090322016128, 0.98078528040323 },
-{ 0.757208846506485, 0.653172842953777 },
-{ 0.146730474455362, 0.989176509964781 },
-{ 0.740951125354959, 0.671558954847018 },
-{ 0.0980171403295608, 0.995184726672197 },
-{ 0.724247082951467, 0.689540544737067 },
-{ 0.0490676743274181, 0.998795456205172 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 6.12303176911189e-17, 1 },
-{ 0.689540544737067, 0.724247082951467 },
-{ -0.049067674327418, 0.998795456205172 },
-{ 0.671558954847018, 0.740951125354959 },
-{ -0.0980171403295606, 0.995184726672197 },
-{ 0.653172842953777, 0.757208846506484 },
-{ -0.146730474455362, 0.989176509964781 },
-{ 0.634393284163645, 0.773010453362737 },
-{ -0.195090322016128, 0.98078528040323 },
-{ 0.615231590580627, 0.788346427626606 },
-{ -0.242980179903264, 0.970031253194544 },
-{ 0.595699304492433, 0.803207531480645 },
-{ -0.290284677254462, 0.956940335732209 },
-{ 0.575808191417845, 0.817584813151584 },
-{ -0.33688985339222, 0.941544065183021 },
-{ 0.555570233019602, 0.831469612302545 },
-{ -0.38268343236509, 0.923879532511287 },
-{ 0.534997619887097, 0.844853565249707 },
-{ -0.427555093430282, 0.903989293123443 },
-{ 0.514102744193222, 0.857728610000272 },
-{ -0.471396736825998, 0.881921264348355 },
-{ 0.492898192229784, 0.870086991108711 },
-{ -0.514102744193222, 0.857728610000272 },
-{ 0.471396736825998, 0.881921264348355 },
-{ -0.555570233019602, 0.831469612302545 },
-{ 0.449611329654607, 0.893224301195515 },
-{ -0.595699304492433, 0.803207531480645 },
-{ 0.427555093430282, 0.903989293123443 },
-{ -0.634393284163645, 0.773010453362737 },
-{ 0.40524131400499, 0.914209755703531 },
-{ -0.671558954847018, 0.740951125354959 },
-{ 0.38268343236509, 0.923879532511287 },
-{ -0.707106781186547, 0.707106781186548 },
-{ 0.359895036534988, 0.932992798834739 },
-{ -0.740951125354959, 0.671558954847019 },
-{ 0.33688985339222, 0.941544065183021 },
-{ -0.773010453362737, 0.634393284163645 },
-{ 0.313681740398892, 0.949528180593037 },
-{ -0.803207531480645, 0.595699304492433 },
-{ 0.290284677254462, 0.956940335732209 },
-{ -0.831469612302545, 0.555570233019602 },
-{ 0.266712757474898, 0.96377606579544 },
-{ -0.857728610000272, 0.514102744193222 },
-{ 0.242980179903264, 0.970031253194544 },
-{ -0.881921264348355, 0.471396736825998 },
-{ 0.21910124015687, 0.975702130038529 },
-{ -0.903989293123443, 0.427555093430282 },
-{ 0.195090322016128, 0.98078528040323 },
-{ -0.923879532511287, 0.38268343236509 },
-{ 0.170961888760301, 0.985277642388941 },
-{ -0.941544065183021, 0.33688985339222 },
-{ 0.146730474455362, 0.989176509964781 },
-{ -0.956940335732209, 0.290284677254462 },
-{ 0.122410675199216, 0.99247953459871 },
-{ -0.970031253194544, 0.242980179903264 },
-{ 0.0980171403295608, 0.995184726672197 },
-{ -0.98078528040323, 0.195090322016129 },
-{ 0.0735645635996675, 0.99729045667869 },
-{ -0.989176509964781, 0.146730474455362 },
-{ 0.0490676743274181, 0.998795456205172 },
-{ -0.995184726672197, 0.0980171403295608 },
-{ 0.0245412285229123, 0.999698818696204 },
-{ -0.998795456205172, 0.049067674327418 },
-};
-
-fftw_complex PFFTW(W_512)[254] = {
-{ 0.999924701839145, 0.0122715382857199 },
-{ 0.999698818696204, 0.0245412285229123 },
-{ 0.999698818696204, 0.0245412285229123 },
-{ 0.998795456205172, 0.049067674327418 },
-{ 0.99932238458835, 0.0368072229413588 },
-{ 0.99729045667869, 0.0735645635996674 },
-{ 0.998795456205172, 0.049067674327418 },
-{ 0.995184726672197, 0.0980171403295606 },
-{ 0.998118112900149, 0.0613207363022086 },
-{ 0.99247953459871, 0.122410675199216 },
-{ 0.99729045667869, 0.0735645635996674 },
-{ 0.989176509964781, 0.146730474455362 },
-{ 0.996312612182778, 0.0857973123444399 },
-{ 0.985277642388941, 0.170961888760301 },
-{ 0.995184726672197, 0.0980171403295606 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.993906970002356, 0.110222207293883 },
-{ 0.975702130038529, 0.21910124015687 },
-{ 0.99247953459871, 0.122410675199216 },
-{ 0.970031253194544, 0.242980179903264 },
-{ 0.99090263542778, 0.134580708507126 },
-{ 0.96377606579544, 0.266712757474898 },
-{ 0.989176509964781, 0.146730474455362 },
-{ 0.956940335732209, 0.290284677254462 },
-{ 0.987301418157858, 0.158858143333861 },
-{ 0.949528180593037, 0.313681740398892 },
-{ 0.985277642388941, 0.170961888760301 },
-{ 0.941544065183021, 0.33688985339222 },
-{ 0.983105487431216, 0.183039887955141 },
-{ 0.932992798834739, 0.359895036534988 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.978317370719628, 0.207111376192219 },
-{ 0.914209755703531, 0.40524131400499 },
-{ 0.975702130038529, 0.21910124015687 },
-{ 0.903989293123443, 0.427555093430282 },
-{ 0.97293995220556, 0.231058108280671 },
-{ 0.893224301195515, 0.449611329654607 },
-{ 0.970031253194544, 0.242980179903264 },
-{ 0.881921264348355, 0.471396736825998 },
-{ 0.966976471044852, 0.254865659604515 },
-{ 0.870086991108711, 0.492898192229784 },
-{ 0.96377606579544, 0.266712757474898 },
-{ 0.857728610000272, 0.514102744193222 },
-{ 0.960430519415566, 0.278519689385053 },
-{ 0.844853565249707, 0.534997619887097 },
-{ 0.956940335732209, 0.290284677254462 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.953306040354194, 0.302005949319228 },
-{ 0.817584813151584, 0.575808191417845 },
-{ 0.949528180593037, 0.313681740398892 },
-{ 0.803207531480645, 0.595699304492433 },
-{ 0.945607325380521, 0.325310292162263 },
-{ 0.788346427626606, 0.615231590580627 },
-{ 0.941544065183021, 0.33688985339222 },
-{ 0.773010453362737, 0.634393284163645 },
-{ 0.937339011912575, 0.348418680249435 },
-{ 0.757208846506485, 0.653172842953777 },
-{ 0.932992798834739, 0.359895036534988 },
-{ 0.740951125354959, 0.671558954847018 },
-{ 0.928506080473216, 0.371317193951838 },
-{ 0.724247082951467, 0.689540544737067 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 0.919113851690058, 0.393992040061048 },
-{ 0.689540544737067, 0.724247082951467 },
-{ 0.914209755703531, 0.40524131400499 },
-{ 0.671558954847018, 0.740951125354959 },
-{ 0.909167983090522, 0.416429560097637 },
-{ 0.653172842953777, 0.757208846506484 },
-{ 0.903989293123443, 0.427555093430282 },
-{ 0.634393284163645, 0.773010453362737 },
-{ 0.898674465693954, 0.438616238538528 },
-{ 0.615231590580627, 0.788346427626606 },
-{ 0.893224301195515, 0.449611329654607 },
-{ 0.595699304492433, 0.803207531480645 },
-{ 0.887639620402854, 0.46053871095824 },
-{ 0.575808191417845, 0.817584813151584 },
-{ 0.881921264348355, 0.471396736825998 },
-{ 0.555570233019602, 0.831469612302545 },
-{ 0.876070094195407, 0.482183772079123 },
-{ 0.534997619887097, 0.844853565249707 },
-{ 0.870086991108711, 0.492898192229784 },
-{ 0.514102744193222, 0.857728610000272 },
-{ 0.863972856121587, 0.503538383725718 },
-{ 0.492898192229784, 0.870086991108711 },
-{ 0.857728610000272, 0.514102744193222 },
-{ 0.471396736825998, 0.881921264348355 },
-{ 0.851355193105265, 0.524589682678469 },
-{ 0.449611329654607, 0.893224301195515 },
-{ 0.844853565249707, 0.534997619887097 },
-{ 0.427555093430282, 0.903989293123443 },
-{ 0.838224705554838, 0.545324988422046 },
-{ 0.40524131400499, 0.914209755703531 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.38268343236509, 0.923879532511287 },
-{ 0.824589302785025, 0.565731810783613 },
-{ 0.359895036534988, 0.932992798834739 },
-{ 0.817584813151584, 0.575808191417845 },
-{ 0.33688985339222, 0.941544065183021 },
-{ 0.810457198252595, 0.585797857456439 },
-{ 0.313681740398892, 0.949528180593037 },
-{ 0.803207531480645, 0.595699304492433 },
-{ 0.290284677254462, 0.956940335732209 },
-{ 0.795836904608884, 0.605511041404326 },
-{ 0.266712757474898, 0.96377606579544 },
-{ 0.788346427626606, 0.615231590580627 },
-{ 0.242980179903264, 0.970031253194544 },
-{ 0.780737228572094, 0.624859488142386 },
-{ 0.21910124015687, 0.975702130038529 },
-{ 0.773010453362737, 0.634393284163645 },
-{ 0.195090322016128, 0.98078528040323 },
-{ 0.765167265622459, 0.643831542889791 },
-{ 0.170961888760301, 0.985277642388941 },
-{ 0.757208846506485, 0.653172842953777 },
-{ 0.146730474455362, 0.989176509964781 },
-{ 0.749136394523459, 0.662415777590172 },
-{ 0.122410675199216, 0.99247953459871 },
-{ 0.740951125354959, 0.671558954847018 },
-{ 0.0980171403295608, 0.995184726672197 },
-{ 0.732654271672413, 0.680600997795453 },
-{ 0.0735645635996675, 0.99729045667869 },
-{ 0.724247082951467, 0.689540544737067 },
-{ 0.0490676743274181, 0.998795456205172 },
-{ 0.715730825283819, 0.698376249408973 },
-{ 0.0245412285229123, 0.999698818696204 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 6.12303176911189e-17, 1 },
-{ 0.698376249408973, 0.715730825283819 },
-{ -0.0245412285229121, 0.999698818696204 },
-{ 0.689540544737067, 0.724247082951467 },
-{ -0.049067674327418, 0.998795456205172 },
-{ 0.680600997795453, 0.732654271672413 },
-{ -0.0735645635996673, 0.99729045667869 },
-{ 0.671558954847018, 0.740951125354959 },
-{ -0.0980171403295606, 0.995184726672197 },
-{ 0.662415777590172, 0.749136394523459 },
-{ -0.122410675199216, 0.99247953459871 },
-{ 0.653172842953777, 0.757208846506484 },
-{ -0.146730474455362, 0.989176509964781 },
-{ 0.643831542889791, 0.765167265622459 },
-{ -0.170961888760301, 0.985277642388941 },
-{ 0.634393284163645, 0.773010453362737 },
-{ -0.195090322016128, 0.98078528040323 },
-{ 0.624859488142386, 0.780737228572094 },
-{ -0.21910124015687, 0.975702130038529 },
-{ 0.615231590580627, 0.788346427626606 },
-{ -0.242980179903264, 0.970031253194544 },
-{ 0.605511041404326, 0.795836904608883 },
-{ -0.266712757474898, 0.96377606579544 },
-{ 0.595699304492433, 0.803207531480645 },
-{ -0.290284677254462, 0.956940335732209 },
-{ 0.585797857456439, 0.810457198252595 },
-{ -0.313681740398891, 0.949528180593037 },
-{ 0.575808191417845, 0.817584813151584 },
-{ -0.33688985339222, 0.941544065183021 },
-{ 0.565731810783613, 0.824589302785025 },
-{ -0.359895036534988, 0.932992798834739 },
-{ 0.555570233019602, 0.831469612302545 },
-{ -0.38268343236509, 0.923879532511287 },
-{ 0.545324988422046, 0.838224705554838 },
-{ -0.40524131400499, 0.914209755703531 },
-{ 0.534997619887097, 0.844853565249707 },
-{ -0.427555093430282, 0.903989293123443 },
-{ 0.524589682678469, 0.851355193105265 },
-{ -0.449611329654607, 0.893224301195515 },
-{ 0.514102744193222, 0.857728610000272 },
-{ -0.471396736825998, 0.881921264348355 },
-{ 0.503538383725718, 0.863972856121587 },
-{ -0.492898192229784, 0.870086991108711 },
-{ 0.492898192229784, 0.870086991108711 },
-{ -0.514102744193222, 0.857728610000272 },
-{ 0.482183772079123, 0.876070094195407 },
-{ -0.534997619887097, 0.844853565249707 },
-{ 0.471396736825998, 0.881921264348355 },
-{ -0.555570233019602, 0.831469612302545 },
-{ 0.46053871095824, 0.887639620402854 },
-{ -0.575808191417845, 0.817584813151584 },
-{ 0.449611329654607, 0.893224301195515 },
-{ -0.595699304492433, 0.803207531480645 },
-{ 0.438616238538528, 0.898674465693954 },
-{ -0.615231590580627, 0.788346427626606 },
-{ 0.427555093430282, 0.903989293123443 },
-{ -0.634393284163645, 0.773010453362737 },
-{ 0.416429560097637, 0.909167983090522 },
-{ -0.653172842953777, 0.757208846506485 },
-{ 0.40524131400499, 0.914209755703531 },
-{ -0.671558954847018, 0.740951125354959 },
-{ 0.393992040061048, 0.919113851690058 },
-{ -0.689540544737067, 0.724247082951467 },
-{ 0.38268343236509, 0.923879532511287 },
-{ -0.707106781186547, 0.707106781186548 },
-{ 0.371317193951838, 0.928506080473215 },
-{ -0.724247082951467, 0.689540544737067 },
-{ 0.359895036534988, 0.932992798834739 },
-{ -0.740951125354959, 0.671558954847019 },
-{ 0.348418680249435, 0.937339011912575 },
-{ -0.757208846506485, 0.653172842953777 },
-{ 0.33688985339222, 0.941544065183021 },
-{ -0.773010453362737, 0.634393284163645 },
-{ 0.325310292162263, 0.945607325380521 },
-{ -0.788346427626606, 0.615231590580627 },
-{ 0.313681740398892, 0.949528180593037 },
-{ -0.803207531480645, 0.595699304492433 },
-{ 0.302005949319228, 0.953306040354194 },
-{ -0.817584813151584, 0.575808191417845 },
-{ 0.290284677254462, 0.956940335732209 },
-{ -0.831469612302545, 0.555570233019602 },
-{ 0.278519689385053, 0.960430519415566 },
-{ -0.844853565249707, 0.534997619887097 },
-{ 0.266712757474898, 0.96377606579544 },
-{ -0.857728610000272, 0.514102744193222 },
-{ 0.254865659604515, 0.966976471044852 },
-{ -0.870086991108711, 0.492898192229784 },
-{ 0.242980179903264, 0.970031253194544 },
-{ -0.881921264348355, 0.471396736825998 },
-{ 0.231058108280671, 0.97293995220556 },
-{ -0.893224301195515, 0.449611329654607 },
-{ 0.21910124015687, 0.975702130038529 },
-{ -0.903989293123443, 0.427555093430282 },
-{ 0.207111376192219, 0.978317370719628 },
-{ -0.914209755703531, 0.40524131400499 },
-{ 0.195090322016128, 0.98078528040323 },
-{ -0.923879532511287, 0.38268343236509 },
-{ 0.183039887955141, 0.983105487431216 },
-{ -0.932992798834739, 0.359895036534988 },
-{ 0.170961888760301, 0.985277642388941 },
-{ -0.941544065183021, 0.33688985339222 },
-{ 0.158858143333861, 0.987301418157858 },
-{ -0.949528180593037, 0.313681740398891 },
-{ 0.146730474455362, 0.989176509964781 },
-{ -0.956940335732209, 0.290284677254462 },
-{ 0.134580708507126, 0.99090263542778 },
-{ -0.96377606579544, 0.266712757474898 },
-{ 0.122410675199216, 0.99247953459871 },
-{ -0.970031253194544, 0.242980179903264 },
-{ 0.110222207293883, 0.993906970002356 },
-{ -0.975702130038528, 0.21910124015687 },
-{ 0.0980171403295608, 0.995184726672197 },
-{ -0.98078528040323, 0.195090322016129 },
-{ 0.0857973123444399, 0.996312612182778 },
-{ -0.985277642388941, 0.170961888760301 },
-{ 0.0735645635996675, 0.99729045667869 },
-{ -0.989176509964781, 0.146730474455362 },
-{ 0.0613207363022086, 0.998118112900149 },
-{ -0.99247953459871, 0.122410675199216 },
-{ 0.0490676743274181, 0.998795456205172 },
-{ -0.995184726672197, 0.0980171403295608 },
-{ 0.036807222941359, 0.99932238458835 },
-{ -0.99729045667869, 0.0735645635996677 },
-{ 0.0245412285229123, 0.999698818696204 },
-{ -0.998795456205172, 0.049067674327418 },
-{ 0.0122715382857199, 0.999924701839145 },
-{ -0.999698818696204, 0.0245412285229123 },
-};
-
-fftw_complex PFFTW(W_1024)[510] = {
-{ 0.999981175282601, 0.00613588464915448 },
-{ 0.999924701839145, 0.0122715382857199 },
-{ 0.999924701839145, 0.0122715382857199 },
-{ 0.999698818696204, 0.0245412285229123 },
-{ 0.999830581795823, 0.0184067299058048 },
-{ 0.99932238458835, 0.0368072229413588 },
-{ 0.999698818696204, 0.0245412285229123 },
-{ 0.998795456205172, 0.049067674327418 },
-{ 0.999529417501093, 0.0306748031766366 },
-{ 0.998118112900149, 0.0613207363022086 },
-{ 0.99932238458835, 0.0368072229413588 },
-{ 0.99729045667869, 0.0735645635996674 },
-{ 0.999077727752645, 0.0429382569349408 },
-{ 0.996312612182778, 0.0857973123444399 },
-{ 0.998795456205172, 0.049067674327418 },
-{ 0.995184726672197, 0.0980171403295606 },
-{ 0.998475580573295, 0.0551952443496899 },
-{ 0.993906970002356, 0.110222207293883 },
-{ 0.998118112900149, 0.0613207363022086 },
-{ 0.99247953459871, 0.122410675199216 },
-{ 0.997723066644192, 0.0674439195636641 },
-{ 0.99090263542778, 0.134580708507126 },
-{ 0.99729045667869, 0.0735645635996674 },
-{ 0.989176509964781, 0.146730474455362 },
-{ 0.996820299291166, 0.0796824379714301 },
-{ 0.987301418157858, 0.158858143333861 },
-{ 0.996312612182778, 0.0857973123444399 },
-{ 0.985277642388941, 0.170961888760301 },
-{ 0.99576741446766, 0.0919089564971327 },
-{ 0.983105487431216, 0.183039887955141 },
-{ 0.995184726672197, 0.0980171403295606 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.994564570734255, 0.104121633872055 },
-{ 0.978317370719628, 0.207111376192219 },
-{ 0.993906970002356, 0.110222207293883 },
-{ 0.975702130038529, 0.21910124015687 },
-{ 0.993211949234795, 0.116318630911905 },
-{ 0.97293995220556, 0.231058108280671 },
-{ 0.99247953459871, 0.122410675199216 },
-{ 0.970031253194544, 0.242980179903264 },
-{ 0.9917097536691, 0.128498110793793 },
-{ 0.966976471044852, 0.254865659604515 },
-{ 0.99090263542778, 0.134580708507126 },
-{ 0.96377606579544, 0.266712757474898 },
-{ 0.990058210262297, 0.140658239332849 },
-{ 0.960430519415566, 0.278519689385053 },
-{ 0.989176509964781, 0.146730474455362 },
-{ 0.956940335732209, 0.290284677254462 },
-{ 0.988257567730749, 0.152797185258443 },
-{ 0.953306040354194, 0.302005949319228 },
-{ 0.987301418157858, 0.158858143333861 },
-{ 0.949528180593037, 0.313681740398892 },
-{ 0.986308097244599, 0.16491312048997 },
-{ 0.945607325380521, 0.325310292162263 },
-{ 0.985277642388941, 0.170961888760301 },
-{ 0.941544065183021, 0.33688985339222 },
-{ 0.984210092386929, 0.177004220412149 },
-{ 0.937339011912575, 0.348418680249435 },
-{ 0.983105487431216, 0.183039887955141 },
-{ 0.932992798834739, 0.359895036534988 },
-{ 0.981963869109555, 0.189068664149806 },
-{ 0.928506080473216, 0.371317193951838 },
-{ 0.98078528040323, 0.195090322016128 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.979569765685441, 0.201104634842092 },
-{ 0.919113851690058, 0.393992040061048 },
-{ 0.978317370719628, 0.207111376192219 },
-{ 0.914209755703531, 0.40524131400499 },
-{ 0.977028142657754, 0.213110319916091 },
-{ 0.909167983090522, 0.416429560097637 },
-{ 0.975702130038529, 0.21910124015687 },
-{ 0.903989293123443, 0.427555093430282 },
-{ 0.974339382785576, 0.225083911359793 },
-{ 0.898674465693954, 0.438616238538528 },
-{ 0.97293995220556, 0.231058108280671 },
-{ 0.893224301195515, 0.449611329654607 },
-{ 0.971503890986252, 0.237023605994367 },
-{ 0.887639620402854, 0.46053871095824 },
-{ 0.970031253194544, 0.242980179903264 },
-{ 0.881921264348355, 0.471396736825998 },
-{ 0.968522094274417, 0.24892760574572 },
-{ 0.876070094195407, 0.482183772079123 },
-{ 0.966976471044852, 0.254865659604515 },
-{ 0.870086991108711, 0.492898192229784 },
-{ 0.965394441697689, 0.260794117915276 },
-{ 0.863972856121587, 0.503538383725718 },
-{ 0.96377606579544, 0.266712757474898 },
-{ 0.857728610000272, 0.514102744193222 },
-{ 0.962121404269042, 0.272621355449949 },
-{ 0.851355193105265, 0.524589682678469 },
-{ 0.960430519415566, 0.278519689385053 },
-{ 0.844853565249707, 0.534997619887097 },
-{ 0.958703474895872, 0.284407537211272 },
-{ 0.838224705554838, 0.545324988422046 },
-{ 0.956940335732209, 0.290284677254462 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.955141168305771, 0.296150888243624 },
-{ 0.824589302785025, 0.565731810783613 },
-{ 0.953306040354194, 0.302005949319228 },
-{ 0.817584813151584, 0.575808191417845 },
-{ 0.951435020969008, 0.307849640041535 },
-{ 0.810457198252595, 0.585797857456439 },
-{ 0.949528180593037, 0.313681740398892 },
-{ 0.803207531480645, 0.595699304492433 },
-{ 0.947585591017741, 0.319502030816016 },
-{ 0.795836904608884, 0.605511041404326 },
-{ 0.945607325380521, 0.325310292162263 },
-{ 0.788346427626606, 0.615231590580627 },
-{ 0.94359345816196, 0.331106305759876 },
-{ 0.780737228572094, 0.624859488142386 },
-{ 0.941544065183021, 0.33688985339222 },
-{ 0.773010453362737, 0.634393284163645 },
-{ 0.93945922360219, 0.342660717311994 },
-{ 0.765167265622459, 0.643831542889791 },
-{ 0.937339011912575, 0.348418680249435 },
-{ 0.757208846506485, 0.653172842953777 },
-{ 0.935183509938948, 0.35416352542049 },
-{ 0.749136394523459, 0.662415777590172 },
-{ 0.932992798834739, 0.359895036534988 },
-{ 0.740951125354959, 0.671558954847018 },
-{ 0.930766961078984, 0.365612997804774 },
-{ 0.732654271672413, 0.680600997795453 },
-{ 0.928506080473216, 0.371317193951838 },
-{ 0.724247082951467, 0.689540544737067 },
-{ 0.926210242138311, 0.377007410216418 },
-{ 0.715730825283819, 0.698376249408973 },
-{ 0.923879532511287, 0.38268343236509 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 0.921514039342042, 0.388345046698826 },
-{ 0.698376249408973, 0.715730825283819 },
-{ 0.919113851690058, 0.393992040061048 },
-{ 0.689540544737067, 0.724247082951467 },
-{ 0.916679059921043, 0.399624199845647 },
-{ 0.680600997795453, 0.732654271672413 },
-{ 0.914209755703531, 0.40524131400499 },
-{ 0.671558954847018, 0.740951125354959 },
-{ 0.91170603200543, 0.410843171057904 },
-{ 0.662415777590172, 0.749136394523459 },
-{ 0.909167983090522, 0.416429560097637 },
-{ 0.653172842953777, 0.757208846506484 },
-{ 0.906595704514915, 0.4220002707998 },
-{ 0.643831542889791, 0.765167265622459 },
-{ 0.903989293123443, 0.427555093430282 },
-{ 0.634393284163645, 0.773010453362737 },
-{ 0.901348847046022, 0.433093818853152 },
-{ 0.624859488142386, 0.780737228572094 },
-{ 0.898674465693954, 0.438616238538528 },
-{ 0.615231590580627, 0.788346427626606 },
-{ 0.895966249756185, 0.444122144570429 },
-{ 0.605511041404326, 0.795836904608883 },
-{ 0.893224301195515, 0.449611329654607 },
-{ 0.595699304492433, 0.803207531480645 },
-{ 0.890448723244758, 0.455083587126344 },
-{ 0.585797857456439, 0.810457198252595 },
-{ 0.887639620402854, 0.46053871095824 },
-{ 0.575808191417845, 0.817584813151584 },
-{ 0.884797098430938, 0.465976495767966 },
-{ 0.565731810783613, 0.824589302785025 },
-{ 0.881921264348355, 0.471396736825998 },
-{ 0.555570233019602, 0.831469612302545 },
-{ 0.879012226428634, 0.476799230063322 },
-{ 0.545324988422046, 0.838224705554838 },
-{ 0.876070094195407, 0.482183772079123 },
-{ 0.534997619887097, 0.844853565249707 },
-{ 0.87309497841829, 0.487550160148436 },
-{ 0.524589682678469, 0.851355193105265 },
-{ 0.870086991108711, 0.492898192229784 },
-{ 0.514102744193222, 0.857728610000272 },
-{ 0.867046245515693, 0.498227666972782 },
-{ 0.503538383725718, 0.863972856121587 },
-{ 0.863972856121587, 0.503538383725718 },
-{ 0.492898192229784, 0.870086991108711 },
-{ 0.860866938637767, 0.508830142543107 },
-{ 0.482183772079123, 0.876070094195407 },
-{ 0.857728610000272, 0.514102744193222 },
-{ 0.471396736825998, 0.881921264348355 },
-{ 0.854557988365401, 0.51935599016559 },
-{ 0.46053871095824, 0.887639620402854 },
-{ 0.851355193105265, 0.524589682678469 },
-{ 0.449611329654607, 0.893224301195515 },
-{ 0.848120344803297, 0.529803624686295 },
-{ 0.438616238538528, 0.898674465693954 },
-{ 0.844853565249707, 0.534997619887097 },
-{ 0.427555093430282, 0.903989293123443 },
-{ 0.841554977436898, 0.540171472729893 },
-{ 0.416429560097637, 0.909167983090522 },
-{ 0.838224705554838, 0.545324988422046 },
-{ 0.40524131400499, 0.914209755703531 },
-{ 0.83486287498638, 0.550457972936605 },
-{ 0.393992040061048, 0.919113851690058 },
-{ 0.831469612302545, 0.555570233019602 },
-{ 0.38268343236509, 0.923879532511287 },
-{ 0.828045045257756, 0.560661576197336 },
-{ 0.371317193951838, 0.928506080473215 },
-{ 0.824589302785025, 0.565731810783613 },
-{ 0.359895036534988, 0.932992798834739 },
-{ 0.821102514991105, 0.570780745886967 },
-{ 0.348418680249435, 0.937339011912575 },
-{ 0.817584813151584, 0.575808191417845 },
-{ 0.33688985339222, 0.941544065183021 },
-{ 0.814036329705948, 0.580813958095765 },
-{ 0.325310292162263, 0.945607325380521 },
-{ 0.810457198252595, 0.585797857456439 },
-{ 0.313681740398892, 0.949528180593037 },
-{ 0.806847553543799, 0.590759701858874 },
-{ 0.302005949319228, 0.953306040354194 },
-{ 0.803207531480645, 0.595699304492433 },
-{ 0.290284677254462, 0.956940335732209 },
-{ 0.799537269107905, 0.600616479383869 },
-{ 0.278519689385053, 0.960430519415566 },
-{ 0.795836904608884, 0.605511041404326 },
-{ 0.266712757474898, 0.96377606579544 },
-{ 0.792106577300212, 0.610382806276309 },
-{ 0.254865659604515, 0.966976471044852 },
-{ 0.788346427626606, 0.615231590580627 },
-{ 0.242980179903264, 0.970031253194544 },
-{ 0.784556597155575, 0.620057211763289 },
-{ 0.231058108280671, 0.97293995220556 },
-{ 0.780737228572094, 0.624859488142386 },
-{ 0.21910124015687, 0.975702130038529 },
-{ 0.776888465673232, 0.629638238914927 },
-{ 0.207111376192219, 0.978317370719628 },
-{ 0.773010453362737, 0.634393284163645 },
-{ 0.195090322016128, 0.98078528040323 },
-{ 0.76910333764558, 0.639124444863776 },
-{ 0.183039887955141, 0.983105487431216 },
-{ 0.765167265622459, 0.643831542889791 },
-{ 0.170961888760301, 0.985277642388941 },
-{ 0.761202385484262, 0.648514401022112 },
-{ 0.158858143333861, 0.987301418157858 },
-{ 0.757208846506485, 0.653172842953777 },
-{ 0.146730474455362, 0.989176509964781 },
-{ 0.753186799043613, 0.657806693297079 },
-{ 0.134580708507126, 0.99090263542778 },
-{ 0.749136394523459, 0.662415777590172 },
-{ 0.122410675199216, 0.99247953459871 },
-{ 0.745057785441466, 0.666999922303637 },
-{ 0.110222207293883, 0.993906970002356 },
-{ 0.740951125354959, 0.671558954847018 },
-{ 0.0980171403295608, 0.995184726672197 },
-{ 0.73681656887737, 0.676092703575316 },
-{ 0.0857973123444399, 0.996312612182778 },
-{ 0.732654271672413, 0.680600997795453 },
-{ 0.0735645635996675, 0.99729045667869 },
-{ 0.728464390448225, 0.6850836677727 },
-{ 0.0613207363022086, 0.998118112900149 },
-{ 0.724247082951467, 0.689540544737067 },
-{ 0.0490676743274181, 0.998795456205172 },
-{ 0.720002507961382, 0.693971460889654 },
-{ 0.036807222941359, 0.99932238458835 },
-{ 0.715730825283819, 0.698376249408973 },
-{ 0.0245412285229123, 0.999698818696204 },
-{ 0.711432195745216, 0.702754744457225 },
-{ 0.0122715382857199, 0.999924701839145 },
-{ 0.707106781186548, 0.707106781186547 },
-{ 6.12303176911189e-17, 1 },
-{ 0.702754744457225, 0.711432195745216 },
-{ -0.0122715382857198, 0.999924701839145 },
-{ 0.698376249408973, 0.715730825283819 },
-{ -0.0245412285229121, 0.999698818696204 },
-{ 0.693971460889654, 0.720002507961382 },
-{ -0.0368072229413589, 0.99932238458835 },
-{ 0.689540544737067, 0.724247082951467 },
-{ -0.049067674327418, 0.998795456205172 },
-{ 0.6850836677727, 0.728464390448225 },
-{ -0.0613207363022085, 0.998118112900149 },
-{ 0.680600997795453, 0.732654271672413 },
-{ -0.0735645635996673, 0.99729045667869 },
-{ 0.676092703575316, 0.73681656887737 },
-{ -0.0857973123444398, 0.996312612182778 },
-{ 0.671558954847018, 0.740951125354959 },
-{ -0.0980171403295606, 0.995184726672197 },
-{ 0.666999922303637, 0.745057785441466 },
-{ -0.110222207293883, 0.993906970002356 },
-{ 0.662415777590172, 0.749136394523459 },
-{ -0.122410675199216, 0.99247953459871 },
-{ 0.657806693297079, 0.753186799043612 },
-{ -0.134580708507126, 0.99090263542778 },
-{ 0.653172842953777, 0.757208846506484 },
-{ -0.146730474455362, 0.989176509964781 },
-{ 0.648514401022113, 0.761202385484262 },
-{ -0.158858143333861, 0.987301418157858 },
-{ 0.643831542889791, 0.765167265622459 },
-{ -0.170961888760301, 0.985277642388941 },
-{ 0.639124444863776, 0.76910333764558 },
-{ -0.183039887955141, 0.983105487431216 },
-{ 0.634393284163645, 0.773010453362737 },
-{ -0.195090322016128, 0.98078528040323 },
-{ 0.629638238914927, 0.776888465673232 },
-{ -0.207111376192218, 0.978317370719628 },
-{ 0.624859488142386, 0.780737228572094 },
-{ -0.21910124015687, 0.975702130038529 },
-{ 0.620057211763289, 0.784556597155575 },
-{ -0.231058108280671, 0.97293995220556 },
-{ 0.615231590580627, 0.788346427626606 },
-{ -0.242980179903264, 0.970031253194544 },
-{ 0.610382806276309, 0.792106577300212 },
-{ -0.254865659604515, 0.966976471044852 },
-{ 0.605511041404326, 0.795836904608883 },
-{ -0.266712757474898, 0.96377606579544 },
-{ 0.600616479383869, 0.799537269107905 },
-{ -0.278519689385053, 0.960430519415566 },
-{ 0.595699304492433, 0.803207531480645 },
-{ -0.290284677254462, 0.956940335732209 },
-{ 0.590759701858874, 0.806847553543799 },
-{ -0.302005949319228, 0.953306040354194 },
-{ 0.585797857456439, 0.810457198252595 },
-{ -0.313681740398891, 0.949528180593037 },
-{ 0.580813958095765, 0.814036329705948 },
-{ -0.325310292162263, 0.945607325380521 },
-{ 0.575808191417845, 0.817584813151584 },
-{ -0.33688985339222, 0.941544065183021 },
-{ 0.570780745886967, 0.821102514991105 },
-{ -0.348418680249434, 0.937339011912575 },
-{ 0.565731810783613, 0.824589302785025 },
-{ -0.359895036534988, 0.932992798834739 },
-{ 0.560661576197336, 0.828045045257756 },
-{ -0.371317193951837, 0.928506080473216 },
-{ 0.555570233019602, 0.831469612302545 },
-{ -0.38268343236509, 0.923879532511287 },
-{ 0.550457972936605, 0.83486287498638 },
-{ -0.393992040061048, 0.919113851690058 },
-{ 0.545324988422046, 0.838224705554838 },
-{ -0.40524131400499, 0.914209755703531 },
-{ 0.540171472729893, 0.841554977436898 },
-{ -0.416429560097637, 0.909167983090522 },
-{ 0.534997619887097, 0.844853565249707 },
-{ -0.427555093430282, 0.903989293123443 },
-{ 0.529803624686295, 0.848120344803297 },
-{ -0.438616238538527, 0.898674465693954 },
-{ 0.524589682678469, 0.851355193105265 },
-{ -0.449611329654607, 0.893224301195515 },
-{ 0.51935599016559, 0.854557988365401 },
-{ -0.46053871095824, 0.887639620402854 },
-{ 0.514102744193222, 0.857728610000272 },
-{ -0.471396736825998, 0.881921264348355 },
-{ 0.508830142543107, 0.860866938637767 },
-{ -0.482183772079123, 0.876070094195407 },
-{ 0.503538383725718, 0.863972856121587 },
-{ -0.492898192229784, 0.870086991108711 },
-{ 0.498227666972782, 0.867046245515693 },
-{ -0.503538383725717, 0.863972856121587 },
-{ 0.492898192229784, 0.870086991108711 },
-{ -0.514102744193222, 0.857728610000272 },
-{ 0.487550160148436, 0.87309497841829 },
-{ -0.524589682678469, 0.851355193105265 },
-{ 0.482183772079123, 0.876070094195407 },
-{ -0.534997619887097, 0.844853565249707 },
-{ 0.476799230063322, 0.879012226428633 },
-{ -0.545324988422046, 0.838224705554838 },
-{ 0.471396736825998, 0.881921264348355 },
-{ -0.555570233019602, 0.831469612302545 },
-{ 0.465976495767966, 0.884797098430938 },
-{ -0.565731810783613, 0.824589302785025 },
-{ 0.46053871095824, 0.887639620402854 },
-{ -0.575808191417845, 0.817584813151584 },
-{ 0.455083587126344, 0.890448723244758 },
-{ -0.585797857456439, 0.810457198252595 },
-{ 0.449611329654607, 0.893224301195515 },
-{ -0.595699304492433, 0.803207531480645 },
-{ 0.444122144570429, 0.895966249756185 },
-{ -0.605511041404325, 0.795836904608884 },
-{ 0.438616238538528, 0.898674465693954 },
-{ -0.615231590580627, 0.788346427626606 },
-{ 0.433093818853152, 0.901348847046022 },
-{ -0.624859488142386, 0.780737228572095 },
-{ 0.427555093430282, 0.903989293123443 },
-{ -0.634393284163645, 0.773010453362737 },
-{ 0.4220002707998, 0.906595704514915 },
-{ -0.643831542889791, 0.765167265622459 },
-{ 0.416429560097637, 0.909167983090522 },
-{ -0.653172842953777, 0.757208846506485 },
-{ 0.410843171057904, 0.91170603200543 },
-{ -0.662415777590172, 0.749136394523459 },
-{ 0.40524131400499, 0.914209755703531 },
-{ -0.671558954847018, 0.740951125354959 },
-{ 0.399624199845647, 0.916679059921043 },
-{ -0.680600997795453, 0.732654271672413 },
-{ 0.393992040061048, 0.919113851690058 },
-{ -0.689540544737067, 0.724247082951467 },
-{ 0.388345046698826, 0.921514039342042 },
-{ -0.698376249408973, 0.715730825283819 },
-{ 0.38268343236509, 0.923879532511287 },
-{ -0.707106781186547, 0.707106781186548 },
-{ 0.377007410216418, 0.926210242138311 },
-{ -0.715730825283819, 0.698376249408973 },
-{ 0.371317193951838, 0.928506080473215 },
-{ -0.724247082951467, 0.689540544737067 },
-{ 0.365612997804774, 0.930766961078984 },
-{ -0.732654271672413, 0.680600997795453 },
-{ 0.359895036534988, 0.932992798834739 },
-{ -0.740951125354959, 0.671558954847019 },
-{ 0.354163525420491, 0.935183509938947 },
-{ -0.749136394523459, 0.662415777590172 },
-{ 0.348418680249435, 0.937339011912575 },
-{ -0.757208846506485, 0.653172842953777 },
-{ 0.342660717311994, 0.93945922360219 },
-{ -0.765167265622459, 0.643831542889791 },
-{ 0.33688985339222, 0.941544065183021 },
-{ -0.773010453362737, 0.634393284163645 },
-{ 0.331106305759876, 0.94359345816196 },
-{ -0.780737228572094, 0.624859488142386 },
-{ 0.325310292162263, 0.945607325380521 },
-{ -0.788346427626606, 0.615231590580627 },
-{ 0.319502030816016, 0.947585591017741 },
-{ -0.795836904608883, 0.605511041404326 },
-{ 0.313681740398892, 0.949528180593037 },
-{ -0.803207531480645, 0.595699304492433 },
-{ 0.307849640041535, 0.951435020969008 },
-{ -0.810457198252595, 0.585797857456439 },
-{ 0.302005949319228, 0.953306040354194 },
-{ -0.817584813151584, 0.575808191417845 },
-{ 0.296150888243624, 0.955141168305771 },
-{ -0.824589302785025, 0.565731810783613 },
-{ 0.290284677254462, 0.956940335732209 },
-{ -0.831469612302545, 0.555570233019602 },
-{ 0.284407537211272, 0.958703474895872 },
-{ -0.838224705554838, 0.545324988422046 },
-{ 0.278519689385053, 0.960430519415566 },
-{ -0.844853565249707, 0.534997619887097 },
-{ 0.272621355449949, 0.962121404269042 },
-{ -0.851355193105265, 0.524589682678469 },
-{ 0.266712757474898, 0.96377606579544 },
-{ -0.857728610000272, 0.514102744193222 },
-{ 0.260794117915276, 0.965394441697689 },
-{ -0.863972856121587, 0.503538383725718 },
-{ 0.254865659604515, 0.966976471044852 },
-{ -0.870086991108711, 0.492898192229784 },
-{ 0.24892760574572, 0.968522094274417 },
-{ -0.876070094195406, 0.482183772079123 },
-{ 0.242980179903264, 0.970031253194544 },
-{ -0.881921264348355, 0.471396736825998 },
-{ 0.237023605994367, 0.971503890986252 },
-{ -0.887639620402854, 0.46053871095824 },
-{ 0.231058108280671, 0.97293995220556 },
-{ -0.893224301195515, 0.449611329654607 },
-{ 0.225083911359793, 0.974339382785576 },
-{ -0.898674465693954, 0.438616238538528 },
-{ 0.21910124015687, 0.975702130038529 },
-{ -0.903989293123443, 0.427555093430282 },
-{ 0.213110319916091, 0.977028142657754 },
-{ -0.909167983090522, 0.416429560097637 },
-{ 0.207111376192219, 0.978317370719628 },
-{ -0.914209755703531, 0.40524131400499 },
-{ 0.201104634842092, 0.979569765685441 },
-{ -0.919113851690058, 0.393992040061048 },
-{ 0.195090322016128, 0.98078528040323 },
-{ -0.923879532511287, 0.38268343236509 },
-{ 0.189068664149806, 0.981963869109555 },
-{ -0.928506080473215, 0.371317193951838 },
-{ 0.183039887955141, 0.983105487431216 },
-{ -0.932992798834739, 0.359895036534988 },
-{ 0.177004220412149, 0.984210092386929 },
-{ -0.937339011912575, 0.348418680249435 },
-{ 0.170961888760301, 0.985277642388941 },
-{ -0.941544065183021, 0.33688985339222 },
-{ 0.16491312048997, 0.986308097244599 },
-{ -0.945607325380521, 0.325310292162263 },
-{ 0.158858143333861, 0.987301418157858 },
-{ -0.949528180593037, 0.313681740398891 },
-{ 0.152797185258443, 0.988257567730749 },
-{ -0.953306040354194, 0.302005949319228 },
-{ 0.146730474455362, 0.989176509964781 },
-{ -0.956940335732209, 0.290284677254462 },
-{ 0.140658239332849, 0.990058210262297 },
-{ -0.960430519415566, 0.278519689385053 },
-{ 0.134580708507126, 0.99090263542778 },
-{ -0.96377606579544, 0.266712757474898 },
-{ 0.128498110793793, 0.9917097536691 },
-{ -0.966976471044852, 0.254865659604515 },
-{ 0.122410675199216, 0.99247953459871 },
-{ -0.970031253194544, 0.242980179903264 },
-{ 0.116318630911905, 0.993211949234795 },
-{ -0.97293995220556, 0.231058108280671 },
-{ 0.110222207293883, 0.993906970002356 },
-{ -0.975702130038528, 0.21910124015687 },
-{ 0.104121633872055, 0.994564570734255 },
-{ -0.978317370719628, 0.207111376192219 },
-{ 0.0980171403295608, 0.995184726672197 },
-{ -0.98078528040323, 0.195090322016129 },
-{ 0.0919089564971327, 0.99576741446766 },
-{ -0.983105487431216, 0.183039887955141 },
-{ 0.0857973123444399, 0.996312612182778 },
-{ -0.985277642388941, 0.170961888760301 },
-{ 0.0796824379714301, 0.996820299291166 },
-{ -0.987301418157858, 0.158858143333861 },
-{ 0.0735645635996675, 0.99729045667869 },
-{ -0.989176509964781, 0.146730474455362 },
-{ 0.0674439195636641, 0.997723066644192 },
-{ -0.99090263542778, 0.134580708507126 },
-{ 0.0613207363022086, 0.998118112900149 },
-{ -0.99247953459871, 0.122410675199216 },
-{ 0.05519524434969, 0.998475580573295 },
-{ -0.993906970002356, 0.110222207293883 },
-{ 0.0490676743274181, 0.998795456205172 },
-{ -0.995184726672197, 0.0980171403295608 },
-{ 0.042938256934941, 0.999077727752645 },
-{ -0.996312612182778, 0.0857973123444402 },
-{ 0.036807222941359, 0.99932238458835 },
-{ -0.99729045667869, 0.0735645635996677 },
-{ 0.0306748031766366, 0.999529417501093 },
-{ -0.998118112900149, 0.0613207363022085 },
-{ 0.0245412285229123, 0.999698818696204 },
-{ -0.998795456205172, 0.049067674327418 },
-{ 0.0184067299058048, 0.999830581795823 },
-{ -0.99932238458835, 0.0368072229413588 },
-{ 0.0122715382857199, 0.999924701839145 },
-{ -0.999698818696204, 0.0245412285229123 },
-{ 0.00613588464915452, 0.999981175282601 },
-{ -0.999924701839145, 0.01227153828572 },
-};
-///////////////////////////////////////////////////////////////
-
-
-void PFFTW(16) (fftw_complex * input) {
-     fftw_real tmp332;
-     fftw_real tmp331;
-     fftw_real tmp330;
-     fftw_real tmp329;
-     fftw_real tmp328;
-     fftw_real tmp327;
-     fftw_real tmp326;
-     fftw_real tmp325;
-     fftw_real tmp324;
-     fftw_real tmp323;
-     fftw_real tmp322;
-     fftw_real tmp321;
-     fftw_real tmp320;
-     fftw_real tmp319;
-     fftw_real tmp318;
-     fftw_real tmp317;
-     fftw_real tmp316;
-     fftw_real tmp315;
-     fftw_real tmp314;
-     fftw_real tmp313;
-     fftw_real tmp312;
-     fftw_real tmp311;
-     fftw_real tmp310;
-     fftw_real tmp309;
-     fftw_real tmp308;
-     fftw_real tmp307;
-     fftw_real tmp306;
-     fftw_real tmp305;
-     fftw_real tmp304;
-     fftw_real tmp303;
-     fftw_real tmp302;
-     fftw_real tmp301;
-     fftw_real st1;
-     fftw_real st2;
-     fftw_real st3;
-     fftw_real st4;
-     fftw_real st5;
-     fftw_real st6;
-     fftw_real st7;
-     fftw_real st8;
-     st8 = c_re(input[0]);
-     st8 = st8 - c_re(input[8]);
-     st7 = c_im(input[4]);
-     st7 = st7 - c_im(input[12]);
-     st6 = c_re(input[4]);
-     st5 = st8 - st7;
-     st8 = st8 + st7;
-     st6 = st6 - c_re(input[12]);
-     st4 = c_im(input[0]);
-     st4 = st4 - c_im(input[8]);
-     st3 = c_re(input[0]);
-     st2 = st6 + st4;
-     st4 = st4 - st6;
-     st3 = st3 + c_re(input[8]);
-     st1 = c_re(input[4]);
-     st1 = st1 + c_re(input[12]);
-     st7 = c_im(input[0]);
-     st6 = st3 + st1;
-     st3 = st3 - st1;
-     st7 = st7 + c_im(input[8]);
-     st1 = c_im(input[4]);
-     st1 = st1 + c_im(input[12]);
-     tmp301 = st4;
-     st4 = c_re(input[2]);
-     tmp302 = st8;
-     st8 = st7 + st1;
-     st7 = st7 - st1;
-     st4 = st4 + c_re(input[10]);
-     st1 = c_re(input[6]);
-     st1 = st1 + c_re(input[14]);
-     tmp303 = st2;
-     st2 = c_im(input[2]);
-     tmp304 = st5;
-     st5 = st4 + st1;
-     st4 = st4 - st1;
-     st2 = st2 + c_im(input[10]);
-     st1 = st6 + st5;
-     st6 = st6 - st5;
-     st5 = st4 + st7;
-     st7 = st7 - st4;
-     st4 = c_im(input[6]);
-     st4 = st4 + c_im(input[14]);
-     tmp305 = st5;
-     st5 = c_re(input[6]);
-     tmp306 = st7;
-     st7 = st2 + st4;
-     st2 = st2 - st4;
-     st4 = st8 - st7;
-     st8 = st8 + st7;
-     st7 = st3 - st2;
-     st3 = st3 + st2;
-     st5 = st5 - c_re(input[14]);
-     st2 = c_im(input[2]);
-     st2 = st2 - c_im(input[10]);
-     tmp307 = st3;
-     st3 = c_re(input[2]);
-     tmp308 = st6;
-     st6 = st5 + st2;
-     st2 = st2 - st5;
-     st3 = st3 - c_re(input[10]);
-     st5 = c_im(input[6]);
-     st5 = st5 - c_im(input[14]);
-     tmp309 = st7;
-     st7 = c_re(input[5]);
-     tmp310 = st8;
-     st8 = st3 - st5;
-     st3 = st3 + st5;
-     st5 = st6 - st8;
-     st6 = st6 + st8;
-     st5 = st5 * K707106781[0];
-     st8 = st2 + st3;
-     st6 = st6 * K707106781[0];
-     st2 = st2 - st3;
-     st8 = st8 * K707106781[0];
-     st7 = st7 - c_re(input[13]);
-     st2 = st2 * K707106781[0];
-     st3 = tmp304 + st5;
-     tmp311 = st4;
-     st4 = tmp303 + st6;
-     st6 = tmp303 - st6;
-     st5 = tmp304 - st5;
-     tmp312 = st1;
-     st1 = tmp302 - st8;
-     st8 = tmp302 + st8;
-     tmp313 = st8;
-     st8 = tmp301 + st2;
-     st2 = tmp301 - st2;
-     tmp314 = st2;
-     st2 = c_im(input[1]);
-     st2 = st2 - c_im(input[9]);
-     tmp315 = st8;
-     st8 = c_re(input[1]);
-     tmp316 = st1;
-     st1 = st7 + st2;
-     st2 = st2 - st7;
-     st7 = st1 * K923879532[0];
-     st8 = st8 - c_re(input[9]);
-     st1 = st1 * K382683432[0];
-     tmp317 = st5;
-     st5 = c_im(input[5]);
-     tmp318 = st6;
-     st6 = st2 * K923879532[0];
-     st5 = st5 - c_im(input[13]);
-     st2 = st2 * K382683432[0];
-     tmp319 = st4;
-     st4 = st8 - st5;
-     st8 = st8 + st5;
-     st5 = st4 * K382683432[0];
-     tmp320 = st3;
-     st3 = c_re(input[7]);
-     st4 = st4 * K923879532[0];
-     st7 = st7 + st5;
-     st5 = st8 * K382683432[0];
-     st1 = st1 - st4;
-     st8 = st8 * K923879532[0];
-     st6 = st6 - st5;
-     st2 = st2 + st8;
-     st3 = st3 - c_re(input[15]);
-     st4 = c_im(input[3]);
-     st4 = st4 - c_im(input[11]);
-     st5 = c_re(input[3]);
-     st8 = st3 + st4;
-     st4 = st4 - st3;
-     st3 = st8 * K382683432[0];
-     st5 = st5 - c_re(input[11]);
-     st8 = st8 * K923879532[0];
-     tmp321 = st2;
-     st2 = c_im(input[7]);
-     tmp322 = st6;
-     st6 = st4 * K382683432[0];
-     st2 = st2 - c_im(input[15]);
-     st4 = st4 * K923879532[0];
-     tmp323 = st1;
-     st1 = st5 - st2;
-     st5 = st5 + st2;
-     st2 = st1 * K923879532[0];
-     tmp324 = st7;
-     st7 = c_re(input[1]);
-     st1 = st1 * K382683432[0];
-     st3 = st3 + st2;
-     st2 = st5 * K923879532[0];
-     st1 = st1 - st8;
-     st5 = st5 * K382683432[0];
-     st6 = st6 - st2;
-     st4 = st4 + st5;
-     st7 = st7 + c_re(input[9]);
-     st8 = tmp324 - st3;
-     st3 = tmp324 + st3;
-     st2 = tmp320 - st8;
-     st8 = tmp320 + st8;
-     st5 = tmp319 - st3;
-     st3 = tmp319 + st3;
-     tmp325 = st3;
-     st3 = tmp323 + st1;
-     st1 = tmp323 - st1;
-     tmp326 = st5;
-     st5 = tmp318 - st3;
-     st3 = tmp318 + st3;
-     tmp327 = st5;
-     st5 = tmp317 - st1;
-     st1 = tmp317 + st1;
-     tmp328 = st3;
-     st3 = tmp322 - st6;
-     tmp329 = st5;
-     st5 = tmp321 + st4;
-     tmp330 = st1;
-     st1 = tmp316 - st3;
-     st3 = tmp316 + st3;
-     tmp331 = st2;
-     st2 = tmp313 - st5;
-     st5 = tmp313 + st5;
-     st6 = tmp322 + st6;
-     c_re(input[9]) = st2;
-     c_re(input[1]) = st5;
-     st2 = tmp315 - st6;
-     st6 = tmp315 + st6;
-     st4 = tmp321 - st4;
-     st5 = c_re(input[5]);
-     c_re(input[5]) = st3;
-     st5 = st5 + c_re(input[13]);
-     c_re(input[13]) = st1;
-     st1 = st7 + st5;
-     st7 = st7 - st5;
-     st3 = tmp314 - st4;
-     st4 = tmp314 + st4;
-     st5 = c_im(input[1]);
-     c_im(input[1]) = st6;
-     st5 = st5 + c_im(input[9]);
-     c_im(input[9]) = st2;
-     st2 = c_im(input[5]);
-     c_im(input[5]) = st3;
-     st2 = st2 + c_im(input[13]);
-     c_im(input[13]) = st4;
-     st6 = st5 - st2;
-     st5 = st5 + st2;
-     st3 = c_re(input[3]);
-     c_re(input[3]) = st8;
-     st3 = st3 + c_re(input[11]);
-     c_re(input[11]) = tmp331;
-     st8 = c_re(input[7]);
-     c_re(input[7]) = tmp330;
-     st8 = st8 + c_re(input[15]);
-     c_re(input[15]) = tmp329;
-     st4 = st3 + st8;
-     st3 = st3 - st8;
-     st2 = st1 + st4;
-     st1 = st1 - st4;
-     st8 = st3 + st6;
-     st6 = st6 - st3;
-     st4 = tmp312 - st2;
-     st2 = tmp312 + st2;
-     st3 = tmp311 - st1;
-     c_re(input[8]) = st4;
-     c_re(input[0]) = st2;
-     c_im(input[4]) = st3;
-     st1 = st1 + tmp311;
-     st4 = c_im(input[3]);
-     c_im(input[3]) = tmp328;
-     c_im(input[12]) = st1;
-     st4 = st4 + c_im(input[11]);
-     c_im(input[11]) = tmp327;
-     st2 = c_im(input[7]);
-     c_im(input[7]) = tmp326;
-     st2 = st2 + c_im(input[15]);
-     c_im(input[15]) = tmp325;
-     st3 = st4 - st2;
-     st4 = st4 + st2;
-     st1 = st7 - st3;
-     st2 = st5 - st4;
-     tmp332 = st2;
-     st2 = st8 - st1;
-     st8 = st8 + st1;
-     st2 = st2 * K707106781[0];
-     st5 = st5 + st4;
-     st8 = st8 * K707106781[0];
-     st7 = st7 + st3;
-     st3 = tmp310 + st5;
-     st4 = st6 - st7;
-     st6 = st6 + st7;
-     c_im(input[0]) = st3;
-     st4 = st4 * K707106781[0];
-     st5 = tmp310 - st5;
-     st6 = st6 * K707106781[0];
-     st1 = tmp309 - st2;
-     c_im(input[8]) = st5;
-     c_re(input[14]) = st1;
-     st2 = tmp309 + st2;
-     st7 = tmp308 + tmp332;
-     st3 = tmp308 - tmp332;
-     c_re(input[6]) = st2;
-     c_re(input[4]) = st7;
-     c_re(input[12]) = st3;
-     st5 = tmp306 - st4;
-     st4 = tmp306 + st4;
-     st1 = tmp307 - st6;
-     c_im(input[10]) = st5;
-     c_im(input[2]) = st4;
-     c_re(input[10]) = st1;
-     st6 = tmp307 + st6;
-     st2 = tmp305 - st8;
-     st8 = tmp305 + st8;
-     c_re(input[2]) = st6;
-     c_im(input[6]) = st2;
-     c_im(input[14]) = st8;
-}
-
-void PFFTW(32) (fftw_complex * input) {
-     fftw_real tmp714;
-     fftw_real tmp713;
-     fftw_real tmp712;
-     fftw_real tmp711;
-     fftw_real tmp710;
-     fftw_real tmp709;
-     fftw_real tmp708;
-     fftw_real tmp707;
-     fftw_real tmp706;
-     fftw_real tmp705;
-     fftw_real tmp704;
-     fftw_real tmp703;
-     fftw_real tmp702;
-     fftw_real tmp701;
-     fftw_real tmp700;
-     fftw_real tmp699;
-     fftw_real tmp698;
-     fftw_real tmp697;
-     fftw_real tmp696;
-     fftw_real tmp695;
-     fftw_real tmp694;
-     fftw_real tmp693;
-     fftw_real tmp692;
-     fftw_real tmp691;
-     fftw_real tmp690;
-     fftw_real tmp689;
-     fftw_real tmp688;
-     fftw_real tmp687;
-     fftw_real tmp686;
-     fftw_real tmp685;
-     fftw_real tmp684;
-     fftw_real tmp683;
-     fftw_real tmp682;
-     fftw_real tmp681;
-     fftw_real tmp680;
-     fftw_real tmp679;
-     fftw_real tmp678;
-     fftw_real tmp677;
-     fftw_real tmp676;
-     fftw_real tmp675;
-     fftw_real tmp674;
-     fftw_real tmp673;
-     fftw_real tmp672;
-     fftw_real tmp671;
-     fftw_real tmp670;
-     fftw_real tmp669;
-     fftw_real tmp668;
-     fftw_real tmp667;
-     fftw_real tmp666;
-     fftw_real tmp665;
-     fftw_real tmp664;
-     fftw_real tmp663;
-     fftw_real tmp662;
-     fftw_real tmp661;
-     fftw_real tmp660;
-     fftw_real tmp659;
-     fftw_real tmp658;
-     fftw_real tmp657;
-     fftw_real tmp656;
-     fftw_real tmp655;
-     fftw_real tmp654;
-     fftw_real tmp653;
-     fftw_real tmp652;
-     fftw_real tmp651;
-     fftw_real tmp650;
-     fftw_real tmp649;
-     fftw_real tmp648;
-     fftw_real tmp647;
-     fftw_real tmp646;
-     fftw_real tmp645;
-     fftw_real tmp644;
-     fftw_real tmp643;
-     fftw_real tmp642;
-     fftw_real tmp641;
-     fftw_real tmp640;
-     fftw_real tmp639;
-     fftw_real tmp638;
-     fftw_real tmp637;
-     fftw_real tmp636;
-     fftw_real tmp635;
-     fftw_real tmp634;
-     fftw_real tmp633;
-     fftw_real tmp632;
-     fftw_real tmp631;
-     fftw_real tmp630;
-     fftw_real tmp629;
-     fftw_real tmp628;
-     fftw_real tmp627;
-     fftw_real tmp626;
-     fftw_real tmp625;
-     fftw_real tmp624;
-     fftw_real tmp623;
-     fftw_real tmp622;
-     fftw_real tmp621;
-     fftw_real st1;
-     fftw_real st2;
-     fftw_real st3;
-     fftw_real st4;
-     fftw_real st5;
-     fftw_real st6;
-     fftw_real st7;
-     fftw_real st8;
-     st8 = c_re(input[0]);
-     st8 = st8 - c_re(input[16]);
-     st7 = c_im(input[8]);
-     st7 = st7 - c_im(input[24]);
-     st6 = st8 - st7;
-     st8 = st8 + st7;
-     st5 = c_re(input[0]);
-     st5 = st5 + c_re(input[16]);
-     st4 = c_re(input[8]);
-     st4 = st4 + c_re(input[24]);
-     st3 = st5 + st4;
-     st5 = st5 - st4;
-     st2 = c_im(input[0]);
-     st2 = st2 + c_im(input[16]);
-     st1 = c_im(input[8]);
-     st1 = st1 + c_im(input[24]);
-     st7 = st2 + st1;
-     st2 = st2 - st1;
-     st4 = c_re(input[4]);
-     st4 = st4 + c_re(input[20]);
-     st1 = c_re(input[28]);
-     st1 = st1 + c_re(input[12]);
-     tmp621 = st6;
-     st6 = st4 + st1;
-     st1 = st1 - st4;
-     st4 = st3 + st6;
-     st3 = st3 - st6;
-     st6 = st2 - st1;
-     st1 = st1 + st2;
-     st2 = c_im(input[4]);
-     st2 = st2 + c_im(input[20]);
-     tmp622 = st1;
-     st1 = c_im(input[28]);
-     st1 = st1 + c_im(input[12]);
-     tmp623 = st6;
-     st6 = st2 + st1;
-     st2 = st2 - st1;
-     st1 = st7 + st6;
-     st7 = st7 - st6;
-     st6 = st5 - st2;
-     st5 = st5 + st2;
-     st2 = c_re(input[8]);
-     st2 = st2 - c_re(input[24]);
-     tmp624 = st5;
-     st5 = c_im(input[0]);
-     st5 = st5 - c_im(input[16]);
-     tmp625 = st6;
-     st6 = st2 + st5;
-     st5 = st5 - st2;
-     st2 = c_im(input[4]);
-     st2 = st2 - c_im(input[20]);
-     tmp626 = st3;
-     st3 = c_re(input[4]);
-     st3 = st3 - c_re(input[20]);
-     tmp627 = st1;
-     st1 = st2 - st3;
-     st3 = st3 + st2;
-     st2 = c_re(input[28]);
-     st2 = st2 - c_re(input[12]);
-     tmp628 = st7;
-     st7 = c_im(input[28]);
-     st7 = st7 - c_im(input[12]);
-     tmp629 = st4;
-     st4 = st2 + st7;
-     st2 = st2 - st7;
-     st7 = st1 - st4;
-     st7 = st7 * K707106781[0];
-     st1 = st1 + st4;
-     st1 = st1 * K707106781[0];
-     st4 = st2 - st3;
-     st4 = st4 * K707106781[0];
-     st3 = st3 + st2;
-     st3 = st3 * K707106781[0];
-     st2 = st8 - st3;
-     tmp630 = st2;
-     st2 = st5 - st1;
-     tmp631 = st2;
-     st2 = tmp621 - st7;
-     tmp632 = st2;
-     st2 = st6 - st4;
-     st7 = tmp621 + st7;
-     st6 = st6 + st4;
-     st8 = st8 + st3;
-     st5 = st5 + st1;
-     st1 = c_re(input[2]);
-     st1 = st1 + c_re(input[18]);
-     st4 = c_re(input[10]);
-     st4 = st4 + c_re(input[26]);
-     st3 = st1 + st4;
-     st1 = st1 - st4;
-     st4 = c_im(input[2]);
-     st4 = st4 + c_im(input[18]);
-     tmp633 = st5;
-     st5 = c_im(input[10]);
-     st5 = st5 + c_im(input[26]);
-     tmp634 = st8;
-     st8 = st4 + st5;
-     st4 = st4 - st5;
-     st5 = st1 + st4;
-     st4 = st4 - st1;
-     st1 = c_re(input[30]);
-     st1 = st1 + c_re(input[14]);
-     tmp635 = st6;
-     st6 = c_re(input[6]);
-     st6 = st6 + c_re(input[22]);
-     tmp636 = st7;
-     st7 = st1 + st6;
-     st1 = st1 - st6;
-     st6 = st3 + st7;
-     st7 = st7 - st3;
-     st3 = tmp629 + st6;
-     st6 = tmp629 - st6;
-     tmp637 = st6;
-     st6 = st7 + tmp628;
-     st7 = tmp628 - st7;
-     tmp638 = st7;
-     st7 = c_im(input[30]);
-     st7 = st7 + c_im(input[14]);
-     tmp639 = st6;
-     st6 = c_im(input[6]);
-     st6 = st6 + c_im(input[22]);
-     tmp640 = st3;
-     st3 = st7 + st6;
-     st7 = st7 - st6;
-     st6 = st8 + st3;
-     st8 = st8 - st3;
-     st3 = st1 - st7;
-     tmp641 = st2;
-     st2 = st3 - st5;
-     st2 = st2 * K707106781[0];
-     st5 = st5 + st3;
-     st5 = st5 * K707106781[0];
-     st1 = st1 + st7;
-     st7 = st4 - st1;
-     st7 = st7 * K707106781[0];
-     st4 = st4 + st1;
-     st4 = st4 * K707106781[0];
-     st3 = tmp627 - st6;
-     st6 = tmp627 + st6;
-     st1 = tmp626 - st8;
-     st8 = tmp626 + st8;
-     tmp642 = st8;
-     st8 = tmp625 + st7;
-     st7 = tmp625 - st7;
-     tmp643 = st7;
-     st7 = tmp623 - st2;
-     st2 = tmp623 + st2;
-     tmp644 = st2;
-     st2 = tmp624 + st5;
-     st5 = tmp624 - st5;
-     tmp645 = st5;
-     st5 = tmp622 - st4;
-     st4 = tmp622 + st4;
-     tmp646 = st4;
-     st4 = c_re(input[6]);
-     st4 = st4 - c_re(input[22]);
-     tmp647 = st5;
-     st5 = c_im(input[30]);
-     st5 = st5 - c_im(input[14]);
-     tmp648 = st2;
-     st2 = st4 + st5;
-     tmp649 = st7;
-     st7 = st2 * K382683432[0];
-     st5 = st5 - st4;
-     st2 = st2 * K923879532[0];
-     st4 = c_re(input[30]);
-     tmp650 = st8;
-     st8 = st5 * K923879532[0];
-     st4 = st4 - c_re(input[14]);
-     st5 = st5 * K382683432[0];
-     tmp651 = st1;
-     st1 = c_im(input[6]);
-     st1 = st1 - c_im(input[22]);
-     tmp652 = st6;
-     st6 = st4 - st1;
-     tmp653 = st3;
-     st3 = st6 * K923879532[0];
-     st4 = st4 + st1;
-     st6 = st6 * K382683432[0];
-     st7 = st7 + st3;
-     st1 = st4 * K382683432[0];
-     st6 = st6 - st2;
-     st4 = st4 * K923879532[0];
-     st8 = st8 + st1;
-     st4 = st4 - st5;
-     st2 = c_re(input[10]);
-     st2 = st2 - c_re(input[26]);
-     st5 = c_im(input[2]);
-     st5 = st5 - c_im(input[18]);
-     st3 = st2 + st5;
-     st1 = st3 * K382683432[0];
-     st5 = st5 - st2;
-     st3 = st3 * K923879532[0];
-     st2 = c_re(input[2]);
-     tmp654 = st6;
-     st6 = st5 * K923879532[0];
-     st2 = st2 - c_re(input[18]);
-     st5 = st5 * K382683432[0];
-     tmp655 = st7;
-     st7 = c_im(input[10]);
-     st7 = st7 - c_im(input[26]);
-     tmp656 = st4;
-     st4 = st2 - st7;
-     tmp657 = st8;
-     st8 = st4 * K923879532[0];
-     st2 = st2 + st7;
-     st4 = st4 * K382683432[0];
-     st1 = st1 - st8;
-     st7 = st2 * K382683432[0];
-     st3 = st3 + st4;
-     st2 = st2 * K923879532[0];
-     st6 = st6 - st7;
-     st5 = st5 + st2;
-     st8 = st6 - tmp657;
-     st4 = tmp630 + st8;
-     st8 = tmp630 - st8;
-     st7 = tmp656 - st5;
-     st2 = tmp631 - st7;
-     st7 = tmp631 + st7;
-     tmp658 = st7;
-     st7 = st1 - tmp655;
-     tmp659 = st8;
-     st8 = tmp632 + st7;
-     st7 = tmp632 - st7;
-     tmp660 = st7;
-     st7 = tmp654 - st3;
-     tmp661 = st8;
-     st8 = tmp641 - st7;
-     st7 = tmp641 + st7;
-     st3 = st3 + tmp654;
-     tmp662 = st7;
-     st7 = tmp636 + st3;
-     st3 = tmp636 - st3;
-     st1 = st1 + tmp655;
-     tmp663 = st3;
-     st3 = tmp635 - st1;
-     st1 = tmp635 + st1;
-     st5 = st5 + tmp656;
-     tmp664 = st1;
-     st1 = tmp634 + st5;
-     st5 = tmp634 - st5;
-     st6 = st6 + tmp657;
-     tmp665 = st5;
-     st5 = tmp633 - st6;
-     st6 = tmp633 + st6;
-     tmp666 = st6;
-     st6 = c_re(input[1]);
-     st6 = st6 + c_re(input[17]);
-     tmp667 = st5;
-     st5 = c_re(input[9]);
-     st5 = st5 + c_re(input[25]);
-     tmp668 = st1;
-     st1 = st6 + st5;
-     st6 = st6 - st5;
-     st5 = c_im(input[1]);
-     st5 = st5 + c_im(input[17]);
-     tmp669 = st3;
-     st3 = c_im(input[9]);
-     st3 = st3 + c_im(input[25]);
-     tmp670 = st7;
-     st7 = st5 - st3;
-     st5 = st5 + st3;
-     st3 = c_re(input[5]);
-     st3 = st3 + c_re(input[21]);
-     tmp671 = st8;
-     st8 = c_re(input[29]);
-     st8 = st8 + c_re(input[13]);
-     tmp672 = st2;
-     st2 = st3 + st8;
-     st8 = st8 - st3;
-     st3 = st1 + st2;
-     st1 = st1 - st2;
-     st2 = st8 + st7;
-     tmp673 = st4;
-     st4 = st2 * K382683432[0];
-     st7 = st7 - st8;
-     st2 = st2 * K923879532[0];
-     st8 = c_im(input[5]);
-     tmp674 = st3;
-     st3 = st7 * K923879532[0];
-     st8 = st8 + c_im(input[21]);
-     st7 = st7 * K382683432[0];
-     tmp675 = st4;
-     st4 = c_im(input[29]);
-     st4 = st4 + c_im(input[13]);
-     tmp676 = st7;
-     st7 = st8 - st4;
-     st8 = st8 + st4;
-     st4 = st5 + st8;
-     st5 = st5 - st8;
-     st8 = st1 + st5;
-     st5 = st5 - st1;
-     st1 = st6 + st7;
-     tmp677 = st8;
-     st8 = st1 * K923879532[0];
-     st6 = st6 - st7;
-     st1 = st1 * K382683432[0];
-     st2 = st2 - st1;
-     st7 = st6 * K382683432[0];
-     st3 = st3 + st7;
-     st6 = st6 * K923879532[0];
-     st6 = tmp676 - st6;
-     st8 = tmp675 + st8;
-     st1 = c_re(input[31]);
-     st1 = st1 + c_re(input[15]);
-     st7 = c_re(input[7]);
-     st7 = st7 + c_re(input[23]);
-     tmp678 = st8;
-     st8 = st1 + st7;
-     st1 = st1 - st7;
-     st7 = c_im(input[31]);
-     st7 = st7 + c_im(input[15]);
-     tmp679 = st2;
-     st2 = c_im(input[7]);
-     st2 = st2 + c_im(input[23]);
-     tmp680 = st3;
-     st3 = st7 - st2;
-     st7 = st7 + st2;
-     st2 = c_re(input[3]);
-     st2 = st2 + c_re(input[19]);
-     tmp681 = st6;
-     st6 = c_re(input[27]);
-     st6 = st6 + c_re(input[11]);
-     tmp682 = st5;
-     st5 = st2 + st6;
-     st6 = st6 - st2;
-     st2 = st8 + st5;
-     st8 = st8 - st5;
-     st5 = st6 + st3;
-     tmp683 = st4;
-     st4 = st5 * K382683432[0];
-     st3 = st3 - st6;
-     st5 = st5 * K923879532[0];
-     st6 = tmp674 + st2;
-     tmp684 = st4;
-     st4 = st3 * K923879532[0];
-     tmp685 = st5;
-     st5 = tmp640 - st6;
-     st3 = st3 * K382683432[0];
-     st6 = tmp640 + st6;
-     st2 = st2 - tmp674;
-     c_re(input[16]) = st5;
-     st5 = st2 + tmp653;
-     st2 = tmp653 - st2;
-     c_re(input[0]) = st6;
-     st6 = c_im(input[3]);
-     st6 = st6 + c_im(input[19]);
-     c_im(input[8]) = st5;
-     st5 = c_im(input[27]);
-     st5 = st5 + c_im(input[11]);
-     c_im(input[24]) = st2;
-     st2 = st6 - st5;
-     st6 = st6 + st5;
-     st5 = st7 + st6;
-     st7 = st7 - st6;
-     st6 = st8 - st7;
-     st8 = st8 + st7;
-     st7 = st1 + st2;
-     tmp686 = st4;
-     st4 = st7 * K923879532[0];
-     st1 = st1 - st2;
-     st7 = st7 * K382683432[0];
-     st2 = tmp683 + st5;
-     tmp687 = st4;
-     st4 = st1 * K382683432[0];
-     tmp688 = st7;
-     st7 = tmp652 - st2;
-     st1 = st1 * K923879532[0];
-     st2 = tmp652 + st2;
-     st5 = tmp683 - st5;
-     c_im(input[16]) = st7;
-     st7 = tmp637 - st5;
-     st5 = tmp637 + st5;
-     c_im(input[0]) = st2;
-     st2 = tmp682 + st8;
-     st2 = st2 * K707106781[0];
-     c_re(input[24]) = st7;
-     st7 = tmp639 - st2;
-     st2 = tmp639 + st2;
-     st8 = tmp682 - st8;
-     st8 = st8 * K707106781[0];
-     c_re(input[8]) = st5;
-     st5 = tmp651 - st8;
-     st8 = tmp651 + st8;
-     c_im(input[20]) = st7;
-     st7 = tmp677 + st6;
-     st7 = st7 * K707106781[0];
-     c_im(input[4]) = st2;
-     st2 = tmp642 - st7;
-     st7 = tmp642 + st7;
-     st6 = st6 - tmp677;
-     st6 = st6 * K707106781[0];
-     c_re(input[28]) = st5;
-     st5 = tmp638 - st6;
-     st6 = tmp638 + st6;
-     st3 = st3 + st1;
-     st1 = tmp681 - st3;
-     st3 = tmp681 + st3;
-     st4 = st4 - tmp686;
-     c_re(input[12]) = st8;
-     st8 = tmp680 + st4;
-     st4 = st4 - tmp680;
-     c_re(input[20]) = st2;
-     st2 = tmp650 - st8;
-     st8 = tmp650 + st8;
-     c_re(input[4]) = st7;
-     st7 = tmp649 - st4;
-     st4 = tmp649 + st4;
-     c_im(input[28]) = st5;
-     st5 = tmp643 - st1;
-     st1 = tmp643 + st1;
-     c_im(input[12]) = st6;
-     st6 = tmp644 - st3;
-     st3 = tmp644 + st3;
-     c_re(input[22]) = st2;
-     st2 = tmp685 + tmp688;
-     c_re(input[6]) = st8;
-     st8 = tmp679 - st2;
-     st2 = tmp679 + st2;
-     c_im(input[30]) = st7;
-     st7 = tmp687 - tmp684;
-     c_im(input[14]) = st4;
-     st4 = tmp678 + st7;
-     st7 = st7 - tmp678;
-     c_re(input[30]) = st5;
-     st5 = tmp648 - st4;
-     st4 = tmp648 + st4;
-     c_re(input[14]) = st1;
-     st1 = tmp647 - st7;
-     st7 = tmp647 + st7;
-     c_im(input[22]) = st6;
-     st6 = tmp645 - st8;
-     st8 = tmp645 + st8;
-     c_im(input[6]) = st3;
-     st3 = tmp646 - st2;
-     st2 = tmp646 + st2;
-     c_re(input[18]) = st5;
-     st5 = c_re(input[31]);
-     st5 = st5 - c_re(input[15]);
-     c_re(input[2]) = st4;
-     st4 = c_im(input[7]);
-     st4 = st4 - c_im(input[23]);
-     c_im(input[26]) = st1;
-     st1 = st5 - st4;
-     st5 = st5 + st4;
-     c_im(input[10]) = st7;
-     st7 = c_re(input[7]);
-     st7 = st7 - c_re(input[23]);
-     c_re(input[26]) = st6;
-     st6 = c_im(input[31]);
-     st6 = st6 - c_im(input[15]);
-     c_re(input[10]) = st8;
-     st8 = st7 + st6;
-     st6 = st6 - st7;
-     c_im(input[18]) = st3;
-     st3 = c_im(input[3]);
-     st3 = st3 - c_im(input[19]);
-     c_im(input[2]) = st2;
-     st2 = c_re(input[3]);
-     st2 = st2 - c_re(input[19]);
-     st4 = st3 - st2;
-     st2 = st2 + st3;
-     st7 = c_re(input[27]);
-     st7 = st7 - c_re(input[11]);
-     st3 = c_im(input[27]);
-     st3 = st3 - c_im(input[11]);
-     tmp689 = st5;
-     st5 = st7 + st3;
-     st7 = st7 - st3;
-     st3 = st4 - st5;
-     st3 = st3 * K707106781[0];
-     st4 = st4 + st5;
-     st4 = st4 * K707106781[0];
-     st5 = st7 - st2;
-     st5 = st5 * K707106781[0];
-     st2 = st2 + st7;
-     st2 = st2 * K707106781[0];
-     st7 = st1 - st3;
-     tmp690 = st2;
-     st2 = st7 * K980785280[0];
-     st1 = st1 + st3;
-     st7 = st7 * K195090322[0];
-     st3 = st6 - st4;
-     tmp691 = st7;
-     st7 = st3 * K555570233[0];
-     st6 = st6 + st4;
-     st3 = st3 * K831469612[0];
-     st4 = st8 - st5;
-     tmp692 = st6;
-     st6 = st4 * K195090322[0];
-     st8 = st8 + st5;
-     st4 = st4 * K980785280[0];
-     st5 = tmp689 - tmp690;
-     tmp693 = st4;
-     st4 = st5 * K831469612[0];
-     tmp694 = st2;
-     st2 = tmp689 + tmp690;
-     st5 = st5 * K555570233[0];
-     st4 = st4 + st7;
-     st7 = st8 * K831469612[0];
-     st5 = st5 - st3;
-     st3 = st1 * K555570233[0];
-     st6 = st6 + tmp694;
-     st1 = st1 * K831469612[0];
-     tmp695 = st6;
-     st6 = tmp691 - tmp693;
-     st8 = st8 * K555570233[0];
-     st7 = st7 + st3;
-     st3 = st2 * K195090322[0];
-     st1 = st1 - st8;
-     st8 = tmp692 * K980785280[0];
-     st3 = st3 + st8;
-     st2 = st2 * K980785280[0];
-     st8 = c_re(input[9]);
-     tmp696 = st3;
-     st3 = tmp692 * K195090322[0];
-     st8 = st8 - c_re(input[25]);
-     st2 = st2 - st3;
-     st3 = c_im(input[1]);
-     st3 = st3 - c_im(input[17]);
-     tmp697 = st2;
-     st2 = st8 + st3;
-     st3 = st3 - st8;
-     st8 = c_re(input[1]);
-     st8 = st8 - c_re(input[17]);
-     tmp698 = st1;
-     st1 = c_im(input[9]);
-     st1 = st1 - c_im(input[25]);
-     tmp699 = st7;
-     st7 = st8 - st1;
-     st8 = st8 + st1;
-     st1 = c_re(input[29]);
-     st1 = st1 - c_re(input[13]);
-     tmp700 = st6;
-     st6 = c_im(input[29]);
-     st6 = st6 - c_im(input[13]);
-     tmp701 = st5;
-     st5 = st1 - st6;
-     st1 = st1 + st6;
-     st6 = c_re(input[5]);
-     st6 = st6 - c_re(input[21]);
-     tmp702 = st4;
-     st4 = c_im(input[5]);
-     st4 = st4 - c_im(input[21]);
-     tmp703 = st8;
-     st8 = st6 + st4;
-     st4 = st4 - st6;
-     st6 = st5 - st8;
-     st6 = st6 * K707106781[0];
-     st8 = st8 + st5;
-     st8 = st8 * K707106781[0];
-     st5 = st4 - st1;
-     st5 = st5 * K707106781[0];
-     st4 = st4 + st1;
-     st4 = st4 * K707106781[0];
-     st1 = st2 - st6;
-     tmp704 = st8;
-     st8 = st1 * K195090322[0];
-     st2 = st2 + st6;
-     st1 = st1 * K980785280[0];
-     st6 = st3 - st4;
-     tmp705 = st1;
-     st1 = st6 * K555570233[0];
-     st3 = st3 + st4;
-     st6 = st6 * K831469612[0];
-     st4 = st7 - st5;
-     tmp706 = st8;
-     st8 = st4 * K980785280[0];
-     st7 = st7 + st5;
-     st4 = st4 * K195090322[0];
-     st5 = tmp703 - tmp704;
-     tmp707 = st4;
-     st4 = st5 * K831469612[0];
-     tmp708 = st8;
-     st8 = tmp703 + tmp704;
-     st5 = st5 * K555570233[0];
-     st1 = st1 - st4;
-     st4 = st2 * K831469612[0];
-     tmp709 = st4;
-     st4 = st1 - tmp702;
-     tmp710 = st4;
-     st4 = st7 * K555570233[0];
-     st1 = st1 + tmp702;
-     st2 = st2 * K555570233[0];
-     st5 = st5 + st6;
-     st7 = st7 * K831469612[0];
-     st6 = st5 + tmp701;
-     tmp711 = st2;
-     st2 = st3 * K980785280[0];
-     st5 = tmp701 - st5;
-     tmp712 = st2;
-     st2 = st8 * K195090322[0];
-     tmp713 = st2;
-     st2 = tmp673 - st6;
-     st8 = st8 * K980785280[0];
-     st3 = st3 * K195090322[0];
-     st6 = tmp673 + st6;
-     c_re(input[21]) = st2;
-     st2 = tmp672 - st5;
-     st5 = tmp672 + st5;
-     c_re(input[5]) = st6;
-     st6 = tmp659 - tmp710;
-     c_im(input[29]) = st2;
-     st2 = tmp659 + tmp710;
-     c_im(input[13]) = st5;
-     st5 = tmp658 - st1;
-     st1 = tmp658 + st1;
-     c_re(input[29]) = st6;
-     st6 = tmp706 - tmp708;
-     c_re(input[13]) = st2;
-     st2 = st6 - tmp695;
-     st6 = st6 + tmp695;
-     c_im(input[21]) = st5;
-     st5 = tmp705 + tmp707;
-     c_im(input[5]) = st1;
-     st1 = st5 + tmp700;
-     st5 = tmp700 - st5;
-     tmp714 = st8;
-     st8 = tmp661 - st1;
-     st1 = tmp661 + st1;
-     c_re(input[23]) = st8;
-     st8 = tmp671 - st5;
-     st5 = tmp671 + st5;
-     c_re(input[7]) = st1;
-     st1 = tmp660 - st2;
-     st2 = tmp660 + st2;
-     c_im(input[31]) = st8;
-     st8 = tmp662 - st6;
-     st6 = tmp662 + st6;
-     st4 = tmp709 - st4;
-     c_im(input[15]) = st5;
-     st5 = st4 - tmp699;
-     st4 = st4 + tmp699;
-     st7 = tmp711 + st7;
-     c_re(input[31]) = st1;
-     st1 = st7 + tmp698;
-     st7 = tmp698 - st7;
-     c_re(input[15]) = st2;
-     st2 = tmp670 - st1;
-     st1 = tmp670 + st1;
-     c_im(input[23]) = st8;
-     st8 = tmp669 - st7;
-     st7 = tmp669 + st7;
-     c_im(input[7]) = st6;
-     st6 = tmp663 - st5;
-     st5 = tmp663 + st5;
-     c_re(input[19]) = st2;
-     st2 = tmp664 - st4;
-     st4 = tmp664 + st4;
-     c_re(input[3]) = st1;
-     st1 = tmp712 - tmp713;
-     c_im(input[27]) = st8;
-     st8 = st1 - tmp696;
-     st1 = st1 + tmp696;
-     st3 = tmp714 + st3;
-     c_im(input[11]) = st7;
-     st7 = st3 + tmp697;
-     st3 = tmp697 - st3;
-     c_re(input[27]) = st6;
-     st6 = tmp668 - st7;
-     st7 = tmp668 + st7;
-     c_re(input[11]) = st5;
-     st5 = tmp667 - st3;
-     st3 = tmp667 + st3;
-     c_im(input[19]) = st2;
-     st2 = tmp665 - st8;
-     st8 = tmp665 + st8;
-     c_im(input[3]) = st4;
-     st4 = tmp666 - st1;
-     st1 = tmp666 + st1;
-     c_re(input[17]) = st6;
-     c_re(input[1]) = st7;
-     c_im(input[25]) = st5;
-     c_im(input[9]) = st3;
-     c_re(input[25]) = st2;
-     c_re(input[9]) = st8;
-     c_im(input[17]) = st4;
-     c_im(input[1]) = st1;
-}
-
-void  PFFTW(64)(fftw_complex *input)
-{
-     PFFTW(twiddle_4)(input, PFFTW(W_64), 16);
-     PFFTW(16)(input );
-     PFFTW(16)(input + 16);
-     PFFTW(16)(input + 32);
-     PFFTW(16)(input + 48);
-}
-
-void PFFTW(128)(fftw_complex *input)
-{
-     PFFTW(twiddle_4)(input, PFFTW(W_128), 32);
-     PFFTW(32)(input );
-     PFFTW(32)(input + 32);
-     PFFTW(32)(input + 64);
-     PFFTW(32)(input + 96);
-}
-
-void PFFTW(256)(fftw_complex *input)
-{
-     PFFTW(twiddle_4)(input, PFFTW(W_256), 64);
-     PFFTW(64)(input );
-     PFFTW(64)(input + 64);
-     PFFTW(64)(input + 128);
-     PFFTW(64)(input + 192);
-}
-
-void PFFTW(512)(fftw_complex *input)
-{
-     PFFTW(twiddle_4)(input, PFFTW(W_512), 128);
-     PFFTW(128)(input );
-     PFFTW(128)(input + 128);
-     PFFTW(128)(input + 256);
-     PFFTW(128)(input + 384);
-}
-
-void PFFTW(1024)(fftw_complex *input)
-{
-     extern fftw_complex PFFTW(W_1024)[];
-     PFFTW(twiddle_4)(input, PFFTW(W_1024), 256);
-     PFFTW(256)(input );
-     PFFTW(256)(input + 256);
-     PFFTW(256)(input + 512);
-     PFFTW(256)(input + 768);
-}
-
-///////////////////////////////////////////////////////////////
-void PFFTWI(16) (fftw_complex * input) {
-     fftw_real tmp333;
-     fftw_real tmp332;
-     fftw_real tmp331;
-     fftw_real tmp330;
-     fftw_real tmp329;
-     fftw_real tmp328;
-     fftw_real tmp327;
-     fftw_real tmp326;
-     fftw_real tmp325;
-     fftw_real tmp324;
-     fftw_real tmp323;
-     fftw_real tmp322;
-     fftw_real tmp321;
-     fftw_real tmp320;
-     fftw_real tmp319;
-     fftw_real tmp318;
-     fftw_real tmp317;
-     fftw_real tmp316;
-     fftw_real tmp315;
-     fftw_real tmp314;
-     fftw_real tmp313;
-     fftw_real tmp312;
-     fftw_real tmp311;
-     fftw_real tmp310;
-     fftw_real tmp309;
-     fftw_real tmp308;
-     fftw_real tmp307;
-     fftw_real tmp306;
-     fftw_real tmp305;
-     fftw_real tmp304;
-     fftw_real tmp303;
-     fftw_real tmp302;
-     fftw_real tmp301;
-     fftw_real st1;
-     fftw_real st2;
-     fftw_real st3;
-     fftw_real st4;
-     fftw_real st5;
-     fftw_real st6;
-     fftw_real st7;
-     fftw_real st8;
-     st8 = c_re(input[4]);
-     st8 = st8 - c_re(input[12]);
-     st7 = c_im(input[0]);
-     st7 = st7 - c_im(input[8]);
-     st6 = c_re(input[0]);
-     st6 = st6 - c_re(input[8]);
-     st5 = st8 + st7;
-     st7 = st7 - st8;
-     st4 = c_im(input[4]);
-     st4 = st4 - c_im(input[12]);
-     st3 = c_re(input[0]);
-     st3 = st3 + c_re(input[8]);
-     st2 = st6 - st4;
-     st6 = st6 + st4;
-     st1 = c_re(input[4]);
-     st1 = st1 + c_re(input[12]);
-     st8 = c_im(input[0]);
-     st8 = st8 + c_im(input[8]);
-     st4 = st3 + st1;
-     st3 = st3 - st1;
-     st1 = c_im(input[4]);
-     st1 = st1 + c_im(input[12]);
-     tmp301 = st6;
-     st6 = c_re(input[2]);
-     st6 = st6 + c_re(input[10]);
-     tmp302 = st7;
-     st7 = st8 + st1;
-     st8 = st8 - st1;
-     st1 = c_re(input[6]);
-     st1 = st1 + c_re(input[14]);
-     tmp303 = st2;
-     st2 = c_im(input[2]);
-     st2 = st2 + c_im(input[10]);
-     tmp304 = st5;
-     st5 = st6 + st1;
-     st6 = st6 - st1;
-     st1 = c_im(input[6]);
-     st1 = st1 + c_im(input[14]);
-     tmp305 = st3;
-     st3 = st4 + st5;
-     st4 = st4 - st5;
-     st5 = st2 + st1;
-     st2 = st2 - st1;
-     st1 = st6 + st8;
-     tmp306 = st1;
-     st1 = st7 - st5;
-     st7 = st7 + st5;
-     st5 = tmp305 - st2;
-     st2 = tmp305 + st2;
-     st8 = st8 - st6;
-     st6 = c_re(input[6]);
-     st6 = st6 - c_re(input[14]);
-     tmp307 = st8;
-     st8 = c_im(input[2]);
-     st8 = st8 - c_im(input[10]);
-     tmp308 = st2;
-     st2 = c_re(input[2]);
-     st2 = st2 - c_re(input[10]);
-     tmp309 = st4;
-     st4 = st6 + st8;
-     st8 = st8 - st6;
-     st6 = c_im(input[6]);
-     st6 = st6 - c_im(input[14]);
-     tmp310 = st5;
-     st5 = c_re(input[1]);
-     st5 = st5 - c_re(input[9]);
-     tmp311 = st7;
-     st7 = st2 - st6;
-     st2 = st2 + st6;
-     st6 = c_im(input[5]);
-     tmp312 = st1;
-     st1 = st4 + st7;
-     st7 = st7 - st4;
-     st4 = st2 - st8;
-     st1 = st1 * K707106781[0];
-     st8 = st8 + st2;
-     st7 = st7 * K707106781[0];
-     st6 = st6 - c_im(input[13]);
-     st4 = st4 * K707106781[0];
-     st2 = tmp304 - st1;
-     st8 = st8 * K707106781[0];
-     tmp313 = st3;
-     st3 = st5 - st6;
-     st5 = st5 + st6;
-     st6 = tmp303 + st7;
-     tmp314 = st6;
-     st6 = st3 * K923879532[0];
-     st7 = tmp303 - st7;
-     st3 = st3 * K382683432[0];
-     st1 = tmp304 + st1;
-     tmp315 = st1;
-     st1 = st5 * K382683432[0];
-     tmp316 = st7;
-     st7 = tmp302 - st4;
-     st5 = st5 * K923879532[0];
-     st4 = tmp302 + st4;
-     tmp317 = st4;
-     st4 = tmp301 - st8;
-     st8 = tmp301 + st8;
-     tmp318 = st8;
-     st8 = c_re(input[5]);
-     st8 = st8 - c_re(input[13]);
-     tmp319 = st4;
-     st4 = c_im(input[1]);
-     st4 = st4 - c_im(input[9]);
-     tmp320 = st7;
-     st7 = c_re(input[3]);
-     st7 = st7 - c_re(input[11]);
-     tmp321 = st2;
-     st2 = st8 + st4;
-     st4 = st4 - st8;
-     st8 = c_im(input[7]);
-     tmp322 = st5;
-     st5 = st2 * K382683432[0];
-     st8 = st8 - c_im(input[15]);
-     st2 = st2 * K923879532[0];
-     st6 = st6 - st5;
-     st5 = st4 * K923879532[0];
-     st2 = st2 + st3;
-     st4 = st4 * K382683432[0];
-     st1 = st1 - st5;
-     st3 = st7 - st8;
-     st4 = st4 + tmp322;
-     st7 = st7 + st8;
-     st8 = st3 * K382683432[0];
-     st5 = c_re(input[7]);
-     st3 = st3 * K923879532[0];
-     st5 = st5 - c_re(input[15]);
-     tmp323 = st4;
-     st4 = st7 * K923879532[0];
-     tmp324 = st1;
-     st1 = c_im(input[3]);
-     st7 = st7 * K382683432[0];
-     st1 = st1 - c_im(input[11]);
-     tmp325 = st2;
-     st2 = c_re(input[1]);
-     st2 = st2 + c_re(input[9]);
-     tmp326 = st6;
-     st6 = st5 + st1;
-     st1 = st1 - st5;
-     st5 = c_re(input[5]);
-     tmp327 = st7;
-     st7 = st6 * K923879532[0];
-     st5 = st5 + c_re(input[13]);
-     st6 = st6 * K382683432[0];
-     st8 = st8 - st7;
-     st7 = st1 * K382683432[0];
-     st6 = st6 + st3;
-     st1 = st1 * K923879532[0];
-     st7 = st7 - st4;
-     st3 = st2 + st5;
-     st1 = st1 + tmp327;
-     st2 = st2 - st5;
-     st4 = tmp326 - st8;
-     st8 = tmp326 + st8;
-     st5 = tmp325 - st6;
-     tmp328 = st2;
-     st2 = tmp321 - st4;
-     st4 = tmp321 + st4;
-     tmp329 = st3;
-     st3 = tmp314 - st8;
-     st8 = tmp314 + st8;
-     tmp330 = st2;
-     st2 = tmp316 - st5;
-     st5 = tmp316 + st5;
-     c_re(input[9]) = st3;
-     c_re(input[1]) = st8;
-     c_re(input[5]) = st2;
-     c_re(input[13]) = st5;
-     st6 = tmp325 + st6;
-     st3 = tmp324 - st7;
-     st8 = tmp323 - st1;
-     st2 = tmp315 - st6;
-     st6 = tmp315 + st6;
-     st5 = tmp320 - st3;
-     st3 = tmp320 + st3;
-     tmp331 = st5;
-     st5 = tmp317 - st8;
-     st8 = tmp317 + st8;
-     st7 = tmp324 + st7;
-     st1 = tmp323 + st1;
-     tmp332 = st3;
-     st3 = c_im(input[1]);
-     c_im(input[1]) = st6;
-     st3 = st3 + c_im(input[9]);
-     c_im(input[9]) = st2;
-     st2 = tmp319 - st7;
-     st7 = tmp319 + st7;
-     st6 = tmp318 - st1;
-     st1 = tmp318 + st1;
-     tmp333 = st5;
-     st5 = c_im(input[5]);
-     c_im(input[5]) = st4;
-     st5 = st5 + c_im(input[13]);
-     c_im(input[13]) = tmp330;
-     st4 = st3 - st5;
-     st3 = st3 + st5;
-     st5 = c_re(input[3]);
-     c_re(input[3]) = st7;
-     st5 = st5 + c_re(input[11]);
-     c_re(input[11]) = st2;
-     st2 = c_re(input[7]);
-     c_re(input[7]) = st6;
-     st2 = st2 + c_re(input[15]);
-     c_re(input[15]) = st1;
-     st7 = st5 + st2;
-     st5 = st5 - st2;
-     st6 = c_im(input[3]);
-     c_im(input[3]) = st8;
-     st6 = st6 + c_im(input[11]);
-     c_im(input[11]) = tmp333;
-     st8 = tmp329 + st7;
-     st7 = tmp329 - st7;
-     st1 = st5 + st4;
-     st4 = st4 - st5;
-     st2 = tmp313 - st8;
-     st8 = tmp313 + st8;
-     st5 = st7 + tmp312;
-     st7 = tmp312 - st7;
-     c_re(input[8]) = st2;
-     c_re(input[0]) = st8;
-     c_im(input[4]) = st5;
-     c_im(input[12]) = st7;
-     st2 = c_im(input[7]);
-     c_im(input[7]) = tmp332;
-     st2 = st2 + c_im(input[15]);
-     c_im(input[15]) = tmp331;
-     st8 = st6 - st2;
-     st6 = st6 + st2;
-     st5 = tmp328 - st8;
-     st8 = tmp328 + st8;
-     st7 = st3 - st6;
-     st2 = st5 - st1;
-     st1 = st1 + st5;
-     st3 = st3 + st6;
-     st2 = st2 * K707106781[0];
-     st6 = st4 + st8;
-     st1 = st1 * K707106781[0];
-     st8 = st8 - st4;
-     st6 = st6 * K707106781[0];
-     st4 = tmp311 + st3;
-     st8 = st8 * K707106781[0];
-     st3 = tmp311 - st3;
-     st5 = tmp310 - st2;
-     c_im(input[0]) = st4;
-     c_im(input[8]) = st3;
-     c_re(input[10]) = st5;
-     st2 = tmp310 + st2;
-     st4 = tmp309 + st7;
-     st7 = tmp309 - st7;
-     st3 = tmp308 - st6;
-     c_re(input[2]) = st2;
-     c_re(input[12]) = st4;
-     c_re(input[4]) = st7;
-     c_re(input[6]) = st3;
-     st6 = tmp308 + st6;
-     st5 = tmp307 - st8;
-     st8 = tmp307 + st8;
-     st2 = tmp306 - st1;
-     c_re(input[14]) = st6;
-     c_im(input[14]) = st5;
-     c_im(input[6]) = st8;
-     c_im(input[10]) = st2;
-     st1 = tmp306 + st1;
-     c_im(input[2]) = st1;
-}
-
-void PFFTWI(32) (fftw_complex * input) {
-     fftw_real tmp714;
-     fftw_real tmp713;
-     fftw_real tmp712;
-     fftw_real tmp711;
-     fftw_real tmp710;
-     fftw_real tmp709;
-     fftw_real tmp708;
-     fftw_real tmp707;
-     fftw_real tmp706;
-     fftw_real tmp705;
-     fftw_real tmp704;
-     fftw_real tmp703;
-     fftw_real tmp702;
-     fftw_real tmp701;
-     fftw_real tmp700;
-     fftw_real tmp699;
-     fftw_real tmp698;
-     fftw_real tmp697;
-     fftw_real tmp696;
-     fftw_real tmp695;
-     fftw_real tmp694;
-     fftw_real tmp693;
-     fftw_real tmp692;
-     fftw_real tmp691;
-     fftw_real tmp690;
-     fftw_real tmp689;
-     fftw_real tmp688;
-     fftw_real tmp687;
-     fftw_real tmp686;
-     fftw_real tmp685;
-     fftw_real tmp684;
-     fftw_real tmp683;
-     fftw_real tmp682;
-     fftw_real tmp681;
-     fftw_real tmp680;
-     fftw_real tmp679;
-     fftw_real tmp678;
-     fftw_real tmp677;
-     fftw_real tmp676;
-     fftw_real tmp675;
-     fftw_real tmp674;
-     fftw_real tmp673;
-     fftw_real tmp672;
-     fftw_real tmp671;
-     fftw_real tmp670;
-     fftw_real tmp669;
-     fftw_real tmp668;
-     fftw_real tmp667;
-     fftw_real tmp666;
-     fftw_real tmp665;
-     fftw_real tmp664;
-     fftw_real tmp663;
-     fftw_real tmp662;
-     fftw_real tmp661;
-     fftw_real tmp660;
-     fftw_real tmp659;
-     fftw_real tmp658;
-     fftw_real tmp657;
-     fftw_real tmp656;
-     fftw_real tmp655;
-     fftw_real tmp654;
-     fftw_real tmp653;
-     fftw_real tmp652;
-     fftw_real tmp651;
-     fftw_real tmp650;
-     fftw_real tmp649;
-     fftw_real tmp648;
-     fftw_real tmp647;
-     fftw_real tmp646;
-     fftw_real tmp645;
-     fftw_real tmp644;
-     fftw_real tmp643;
-     fftw_real tmp642;
-     fftw_real tmp641;
-     fftw_real tmp640;
-     fftw_real tmp639;
-     fftw_real tmp638;
-     fftw_real tmp637;
-     fftw_real tmp636;
-     fftw_real tmp635;
-     fftw_real tmp634;
-     fftw_real tmp633;
-     fftw_real tmp632;
-     fftw_real tmp631;
-     fftw_real tmp630;
-     fftw_real tmp629;
-     fftw_real tmp628;
-     fftw_real tmp627;
-     fftw_real tmp626;
-     fftw_real tmp625;
-     fftw_real tmp624;
-     fftw_real tmp623;
-     fftw_real tmp622;
-     fftw_real tmp621;
-     fftw_real st1;
-     fftw_real st2;
-     fftw_real st3;
-     fftw_real st4;
-     fftw_real st5;
-     fftw_real st6;
-     fftw_real st7;
-     fftw_real st8;
-     st8 = c_re(input[8]);
-     st8 = st8 - c_re(input[24]);
-     st7 = c_im(input[0]);
-     st7 = st7 - c_im(input[16]);
-     st6 = st8 + st7;
-     st7 = st7 - st8;
-     st5 = c_re(input[0]);
-     st5 = st5 + c_re(input[16]);
-     st4 = c_re(input[8]);
-     st4 = st4 + c_re(input[24]);
-     st3 = st5 + st4;
-     st5 = st5 - st4;
-     st2 = c_im(input[0]);
-     st2 = st2 + c_im(input[16]);
-     st1 = c_im(input[8]);
-     st1 = st1 + c_im(input[24]);
-     st8 = st2 + st1;
-     st2 = st2 - st1;
-     st4 = c_re(input[4]);
-     st4 = st4 + c_re(input[20]);
-     st1 = c_re(input[28]);
-     st1 = st1 + c_re(input[12]);
-     tmp621 = st6;
-     st6 = st4 + st1;
-     st4 = st4 - st1;
-     st1 = st3 + st6;
-     st3 = st3 - st6;
-     st6 = st2 - st4;
-     st4 = st4 + st2;
-     st2 = c_im(input[4]);
-     st2 = st2 + c_im(input[20]);
-     tmp622 = st4;
-     st4 = c_im(input[28]);
-     st4 = st4 + c_im(input[12]);
-     tmp623 = st6;
-     st6 = st2 + st4;
-     st4 = st4 - st2;
-     st2 = st8 + st6;
-     st8 = st8 - st6;
-     st6 = st5 - st4;
-     st5 = st5 + st4;
-     st4 = c_re(input[0]);
-     st4 = st4 - c_re(input[16]);
-     tmp624 = st5;
-     st5 = c_im(input[8]);
-     st5 = st5 - c_im(input[24]);
-     tmp625 = st6;
-     st6 = st4 - st5;
-     st4 = st4 + st5;
-     st5 = c_re(input[4]);
-     st5 = st5 - c_re(input[20]);
-     tmp626 = st3;
-     st3 = c_im(input[4]);
-     st3 = st3 - c_im(input[20]);
-     tmp627 = st2;
-     st2 = st5 + st3;
-     st5 = st5 - st3;
-     st3 = c_im(input[28]);
-     st3 = st3 - c_im(input[12]);
-     tmp628 = st8;
-     st8 = c_re(input[28]);
-     st8 = st8 - c_re(input[12]);
-     tmp629 = st1;
-     st1 = st3 - st8;
-     st8 = st8 + st3;
-     st3 = st2 + st1;
-     st3 = st3 * K707106781[0];
-     st1 = st1 - st2;
-     st1 = st1 * K707106781[0];
-     st2 = st5 + st8;
-     st2 = st2 * K707106781[0];
-     st5 = st5 - st8;
-     st5 = st5 * K707106781[0];
-     st8 = st7 - st5;
-     tmp630 = st8;
-     st8 = st4 - st1;
-     tmp631 = st8;
-     st8 = tmp621 - st3;
-     tmp632 = st8;
-     st8 = st6 - st2;
-     st3 = tmp621 + st3;
-     st6 = st6 + st2;
-     st7 = st7 + st5;
-     st4 = st4 + st1;
-     st1 = c_re(input[2]);
-     st1 = st1 + c_re(input[18]);
-     st2 = c_re(input[10]);
-     st2 = st2 + c_re(input[26]);
-     st5 = st1 + st2;
-     st1 = st1 - st2;
-     st2 = c_im(input[2]);
-     st2 = st2 + c_im(input[18]);
-     tmp633 = st4;
-     st4 = c_im(input[10]);
-     st4 = st4 + c_im(input[26]);
-     tmp634 = st7;
-     st7 = st2 + st4;
-     st2 = st2 - st4;
-     st4 = st1 + st2;
-     st1 = st1 - st2;
-     st2 = c_re(input[30]);
-     st2 = st2 + c_re(input[14]);
-     tmp635 = st6;
-     st6 = c_re(input[6]);
-     st6 = st6 + c_re(input[22]);
-     tmp636 = st3;
-     st3 = st2 + st6;
-     st2 = st2 - st6;
-     st6 = st5 + st3;
-     st5 = st5 - st3;
-     st3 = tmp629 + st6;
-     st6 = tmp629 - st6;
-     tmp637 = st6;
-     st6 = tmp628 - st5;
-     st5 = st5 + tmp628;
-     tmp638 = st5;
-     st5 = c_im(input[30]);
-     st5 = st5 + c_im(input[14]);
-     tmp639 = st6;
-     st6 = c_im(input[6]);
-     st6 = st6 + c_im(input[22]);
-     tmp640 = st3;
-     st3 = st5 + st6;
-     st5 = st5 - st6;
-     st6 = st7 + st3;
-     st3 = st3 - st7;
-     st7 = st5 - st2;
-     tmp641 = st8;
-     st8 = st7 - st4;
-     st8 = st8 * K707106781[0];
-     st4 = st4 + st7;
-     st4 = st4 * K707106781[0];
-     st2 = st2 + st5;
-     st5 = st1 - st2;
-     st5 = st5 * K707106781[0];
-     st1 = st1 + st2;
-     st1 = st1 * K707106781[0];
-     st7 = tmp627 - st6;
-     st6 = tmp627 + st6;
-     st2 = tmp626 + st3;
-     st3 = tmp626 - st3;
-     tmp642 = st3;
-     st3 = tmp623 + st5;
-     st5 = tmp623 - st5;
-     tmp643 = st5;
-     st5 = tmp625 - st8;
-     st8 = tmp625 + st8;
-     tmp644 = st8;
-     st8 = tmp622 + st4;
-     st4 = tmp622 - st4;
-     tmp645 = st4;
-     st4 = tmp624 - st1;
-     st1 = tmp624 + st1;
-     tmp646 = st1;
-     st1 = c_re(input[6]);
-     st1 = st1 - c_re(input[22]);
-     tmp647 = st4;
-     st4 = c_im(input[30]);
-     st4 = st4 - c_im(input[14]);
-     tmp648 = st8;
-     st8 = st1 + st4;
-     tmp649 = st5;
-     st5 = st8 * K382683432[0];
-     st4 = st4 - st1;
-     st8 = st8 * K923879532[0];
-     st1 = c_re(input[30]);
-     tmp650 = st3;
-     st3 = st4 * K923879532[0];
-     st1 = st1 - c_re(input[14]);
-     st4 = st4 * K382683432[0];
-     tmp651 = st2;
-     st2 = c_im(input[6]);
-     st2 = st2 - c_im(input[22]);
-     tmp652 = st6;
-     st6 = st1 - st2;
-     tmp653 = st7;
-     st7 = st6 * K923879532[0];
-     st1 = st1 + st2;
-     st6 = st6 * K382683432[0];
-     st5 = st5 + st7;
-     st2 = st1 * K382683432[0];
-     st8 = st8 - st6;
-     st1 = st1 * K923879532[0];
-     st3 = st3 + st2;
-     st4 = st4 - st1;
-     st7 = c_re(input[2]);
-     st7 = st7 - c_re(input[18]);
-     st6 = c_im(input[10]);
-     st6 = st6 - c_im(input[26]);
-     st2 = st7 - st6;
-     st1 = st2 * K923879532[0];
-     st7 = st7 + st6;
-     st2 = st2 * K382683432[0];
-     st6 = c_re(input[10]);
-     tmp654 = st8;
-     st8 = st7 * K382683432[0];
-     st6 = st6 - c_re(input[26]);
-     st7 = st7 * K923879532[0];
-     tmp655 = st5;
-     st5 = c_im(input[2]);
-     st5 = st5 - c_im(input[18]);
-     tmp656 = st4;
-     st4 = st6 + st5;
-     tmp657 = st3;
-     st3 = st4 * K382683432[0];
-     st5 = st5 - st6;
-     st4 = st4 * K923879532[0];
-     st1 = st1 - st3;
-     st6 = st5 * K923879532[0];
-     st4 = st4 + st2;
-     st5 = st5 * K382683432[0];
-     st8 = st8 - st6;
-     st5 = st5 + st7;
-     st2 = st8 - tmp657;
-     st7 = tmp630 + st2;
-     st2 = tmp630 - st2;
-     st3 = tmp656 - st5;
-     st6 = tmp631 - st3;
-     st3 = tmp631 + st3;
-     tmp658 = st3;
-     st3 = st1 - tmp655;
-     tmp659 = st2;
-     st2 = tmp632 - st3;
-     st3 = tmp632 + st3;
-     tmp660 = st3;
-     st3 = tmp654 - st4;
-     tmp661 = st2;
-     st2 = tmp641 + st3;
-     st3 = tmp641 - st3;
-     st4 = st4 + tmp654;
-     tmp662 = st3;
-     st3 = tmp636 - st4;
-     st4 = tmp636 + st4;
-     st1 = st1 + tmp655;
-     tmp663 = st4;
-     st4 = tmp635 + st1;
-     st1 = tmp635 - st1;
-     st5 = st5 + tmp656;
-     tmp664 = st1;
-     st1 = tmp634 + st5;
-     st5 = tmp634 - st5;
-     st8 = st8 + tmp657;
-     tmp665 = st5;
-     st5 = tmp633 - st8;
-     st8 = tmp633 + st8;
-     tmp666 = st8;
-     st8 = c_re(input[1]);
-     st8 = st8 + c_re(input[17]);
-     tmp667 = st5;
-     st5 = c_re(input[9]);
-     st5 = st5 + c_re(input[25]);
-     tmp668 = st1;
-     st1 = st8 + st5;
-     st8 = st8 - st5;
-     st5 = c_im(input[1]);
-     st5 = st5 + c_im(input[17]);
-     tmp669 = st4;
-     st4 = c_im(input[9]);
-     st4 = st4 + c_im(input[25]);
-     tmp670 = st3;
-     st3 = st5 + st4;
-     st5 = st5 - st4;
-     st4 = c_re(input[5]);
-     st4 = st4 + c_re(input[21]);
-     tmp671 = st2;
-     st2 = c_re(input[29]);
-     st2 = st2 + c_re(input[13]);
-     tmp672 = st6;
-     st6 = st4 + st2;
-     st4 = st4 - st2;
-     st2 = st1 + st6;
-     st1 = st1 - st6;
-     st6 = st4 + st5;
-     tmp673 = st7;
-     st7 = st6 * K923879532[0];
-     st5 = st5 - st4;
-     st6 = st6 * K382683432[0];
-     st4 = c_im(input[5]);
-     tmp674 = st2;
-     st2 = st5 * K382683432[0];
-     st4 = st4 + c_im(input[21]);
-     st5 = st5 * K923879532[0];
-     tmp675 = st7;
-     st7 = c_im(input[29]);
-     st7 = st7 + c_im(input[13]);
-     tmp676 = st5;
-     st5 = st4 + st7;
-     st7 = st7 - st4;
-     st4 = st3 + st5;
-     st3 = st3 - st5;
-     st5 = st1 - st3;
-     st1 = st1 + st3;
-     st3 = st8 + st7;
-     tmp677 = st1;
-     st1 = st3 * K382683432[0];
-     st8 = st8 - st7;
-     st3 = st3 * K923879532[0];
-     st3 = st3 - st6;
-     st6 = st8 * K923879532[0];
-     st2 = st2 + st6;
-     st8 = st8 * K382683432[0];
-     st8 = st8 - tmp676;
-     st1 = tmp675 + st1;
-     st7 = c_re(input[31]);
-     st7 = st7 + c_re(input[15]);
-     st6 = c_re(input[7]);
-     st6 = st6 + c_re(input[23]);
-     tmp678 = st1;
-     st1 = st7 + st6;
-     st7 = st7 - st6;
-     st6 = c_im(input[31]);
-     st6 = st6 + c_im(input[15]);
-     tmp679 = st3;
-     st3 = c_im(input[7]);
-     st3 = st3 + c_im(input[23]);
-     tmp680 = st2;
-     st2 = st6 + st3;
-     st6 = st6 - st3;
-     st3 = c_re(input[3]);
-     st3 = st3 + c_re(input[19]);
-     tmp681 = st8;
-     st8 = c_re(input[27]);
-     st8 = st8 + c_re(input[11]);
-     tmp682 = st5;
-     st5 = st3 + st8;
-     st3 = st3 - st8;
-     st8 = st1 + st5;
-     st1 = st1 - st5;
-     st5 = st3 + st6;
-     tmp683 = st4;
-     st4 = st5 * K923879532[0];
-     st6 = st6 - st3;
-     st5 = st5 * K382683432[0];
-     st3 = tmp674 + st8;
-     tmp684 = st4;
-     st4 = st6 * K382683432[0];
-     tmp685 = st5;
-     st5 = tmp640 - st3;
-     st6 = st6 * K923879532[0];
-     st3 = tmp640 + st3;
-     st8 = tmp674 - st8;
-     c_re(input[16]) = st5;
-     st5 = st8 + tmp653;
-     st8 = tmp653 - st8;
-     c_re(input[0]) = st3;
-     st3 = c_im(input[3]);
-     st3 = st3 + c_im(input[19]);
-     c_im(input[8]) = st5;
-     st5 = c_im(input[27]);
-     st5 = st5 + c_im(input[11]);
-     c_im(input[24]) = st8;
-     st8 = st3 + st5;
-     st5 = st5 - st3;
-     st3 = st2 + st8;
-     st2 = st2 - st8;
-     st8 = st1 + st2;
-     st2 = st2 - st1;
-     st1 = st7 + st5;
-     tmp686 = st4;
-     st4 = st1 * K382683432[0];
-     st7 = st7 - st5;
-     st1 = st1 * K923879532[0];
-     st5 = tmp683 + st3;
-     tmp687 = st4;
-     st4 = st7 * K923879532[0];
-     tmp688 = st1;
-     st1 = tmp652 - st5;
-     st7 = st7 * K382683432[0];
-     st5 = tmp652 + st5;
-     st3 = st3 - tmp683;
-     c_im(input[16]) = st1;
-     st1 = tmp637 - st3;
-     st3 = tmp637 + st3;
-     c_im(input[0]) = st5;
-     st5 = tmp682 - st8;
-     st5 = st5 * K707106781[0];
-     c_re(input[24]) = st1;
-     st1 = tmp639 - st5;
-     st5 = tmp639 + st5;
-     st8 = tmp682 + st8;
-     st8 = st8 * K707106781[0];
-     c_re(input[8]) = st3;
-     st3 = tmp651 - st8;
-     st8 = tmp651 + st8;
-     c_im(input[28]) = st1;
-     st1 = st2 - tmp677;
-     st1 = st1 * K707106781[0];
-     c_im(input[12]) = st5;
-     st5 = tmp642 - st1;
-     st1 = tmp642 + st1;
-     st2 = tmp677 + st2;
-     st2 = st2 * K707106781[0];
-     c_re(input[20]) = st3;
-     st3 = tmp638 - st2;
-     st2 = tmp638 + st2;
-     st6 = st6 + st7;
-     st7 = tmp681 - st6;
-     st6 = tmp681 + st6;
-     st4 = tmp686 - st4;
-     c_re(input[4]) = st8;
-     st8 = tmp680 + st4;
-     st4 = st4 - tmp680;
-     c_re(input[28]) = st5;
-     st5 = tmp650 - st8;
-     st8 = tmp650 + st8;
-     c_re(input[12]) = st1;
-     st1 = tmp649 - st4;
-     st4 = tmp649 + st4;
-     c_im(input[20]) = st3;
-     st3 = tmp643 - st7;
-     st7 = tmp643 + st7;
-     c_im(input[4]) = st2;
-     st2 = tmp644 - st6;
-     st6 = tmp644 + st6;
-     c_im(input[22]) = st5;
-     st5 = tmp685 + tmp688;
-     c_im(input[6]) = st8;
-     st8 = tmp679 - st5;
-     st5 = tmp679 + st5;
-     c_re(input[30]) = st1;
-     st1 = tmp684 - tmp687;
-     c_re(input[14]) = st4;
-     st4 = tmp678 + st1;
-     st1 = st1 - tmp678;
-     c_im(input[30]) = st3;
-     st3 = tmp648 - st4;
-     st4 = tmp648 + st4;
-     c_im(input[14]) = st7;
-     st7 = tmp647 - st1;
-     st1 = tmp647 + st1;
-     c_re(input[22]) = st2;
-     st2 = tmp645 - st8;
-     st8 = tmp645 + st8;
-     c_re(input[6]) = st6;
-     st6 = tmp646 - st5;
-     st5 = tmp646 + st5;
-     c_im(input[18]) = st3;
-     st3 = c_re(input[31]);
-     st3 = st3 - c_re(input[15]);
-     c_im(input[2]) = st4;
-     st4 = c_im(input[7]);
-     st4 = st4 - c_im(input[23]);
-     c_re(input[26]) = st7;
-     st7 = st3 - st4;
-     st3 = st3 + st4;
-     c_re(input[10]) = st1;
-     st1 = c_re(input[7]);
-     st1 = st1 - c_re(input[23]);
-     c_im(input[26]) = st2;
-     st2 = c_im(input[31]);
-     st2 = st2 - c_im(input[15]);
-     c_im(input[10]) = st8;
-     st8 = st1 + st2;
-     st2 = st2 - st1;
-     c_re(input[18]) = st6;
-     st6 = c_re(input[3]);
-     st6 = st6 - c_re(input[19]);
-     c_re(input[2]) = st5;
-     st5 = c_im(input[3]);
-     st5 = st5 - c_im(input[19]);
-     st4 = st6 - st5;
-     st6 = st6 + st5;
-     st1 = c_re(input[27]);
-     st1 = st1 - c_re(input[11]);
-     st5 = c_im(input[27]);
-     st5 = st5 - c_im(input[11]);
-     tmp689 = st2;
-     st2 = st1 + st5;
-     st5 = st5 - st1;
-     st1 = st4 + st2;
-     st1 = st1 * K707106781[0];
-     st4 = st4 - st2;
-     st4 = st4 * K707106781[0];
-     st2 = st6 + st5;
-     st2 = st2 * K707106781[0];
-     st5 = st5 - st6;
-     st5 = st5 * K707106781[0];
-     st6 = st7 - st1;
-     tmp690 = st4;
-     st4 = st6 * K831469612[0];
-     st7 = st7 + st1;
-     st6 = st6 * K555570233[0];
-     st1 = st3 - st5;
-     tmp691 = st6;
-     st6 = st1 * K195090322[0];
-     st3 = st3 + st5;
-     st1 = st1 * K980785280[0];
-     st5 = st8 - st2;
-     tmp692 = st3;
-     st3 = st5 * K555570233[0];
-     st8 = st8 + st2;
-     st5 = st5 * K831469612[0];
-     st2 = tmp689 - tmp690;
-     tmp693 = st5;
-     st5 = st2 * K980785280[0];
-     tmp694 = st4;
-     st4 = tmp689 + tmp690;
-     st2 = st2 * K195090322[0];
-     st5 = st5 + st6;
-     st6 = st8 * K980785280[0];
-     st2 = st2 - st1;
-     st1 = st7 * K195090322[0];
-     st3 = st3 - tmp694;
-     st7 = st7 * K980785280[0];
-     tmp695 = st3;
-     st3 = tmp691 + tmp693;
-     st8 = st8 * K195090322[0];
-     st6 = st6 - st1;
-     st1 = st4 * K555570233[0];
-     st7 = st7 + st8;
-     st8 = tmp692 * K831469612[0];
-     st1 = st1 + st8;
-     st4 = st4 * K831469612[0];
-     st8 = c_re(input[1]);
-     tmp696 = st1;
-     st1 = tmp692 * K555570233[0];
-     st8 = st8 - c_re(input[17]);
-     st4 = st4 - st1;
-     st1 = c_im(input[9]);
-     st1 = st1 - c_im(input[25]);
-     tmp697 = st4;
-     st4 = st8 - st1;
-     st8 = st8 + st1;
-     st1 = c_re(input[9]);
-     st1 = st1 - c_re(input[25]);
-     tmp698 = st7;
-     st7 = c_im(input[1]);
-     st7 = st7 - c_im(input[17]);
-     tmp699 = st6;
-     st6 = st1 + st7;
-     st7 = st7 - st1;
-     st1 = c_re(input[5]);
-     st1 = st1 - c_re(input[21]);
-     tmp700 = st3;
-     st3 = c_im(input[5]);
-     st3 = st3 - c_im(input[21]);
-     tmp701 = st2;
-     st2 = st1 - st3;
-     st1 = st1 + st3;
-     st3 = c_re(input[29]);
-     st3 = st3 - c_re(input[13]);
-     tmp702 = st5;
-     st5 = c_im(input[29]);
-     st5 = st5 - c_im(input[13]);
-     tmp703 = st7;
-     st7 = st3 + st5;
-     st5 = st5 - st3;
-     st3 = st2 + st7;
-     st3 = st3 * K707106781[0];
-     st2 = st2 - st7;
-     st2 = st2 * K707106781[0];
-     st7 = st1 + st5;
-     st7 = st7 * K707106781[0];
-     st5 = st5 - st1;
-     st5 = st5 * K707106781[0];
-     st1 = st4 - st3;
-     tmp704 = st2;
-     st2 = st1 * K831469612[0];
-     st4 = st4 + st3;
-     st1 = st1 * K555570233[0];
-     st3 = st8 - st5;
-     tmp705 = st1;
-     st1 = st3 * K195090322[0];
-     st8 = st8 + st5;
-     st3 = st3 * K980785280[0];
-     st5 = st6 - st7;
-     tmp706 = st2;
-     st2 = st5 * K555570233[0];
-     st6 = st6 + st7;
-     st5 = st5 * K831469612[0];
-     st7 = tmp703 - tmp704;
-     tmp707 = st5;
-     st5 = st7 * K980785280[0];
-     tmp708 = st2;
-     st2 = tmp703 + tmp704;
-     st7 = st7 * K195090322[0];
-     st1 = st1 - st5;
-     st5 = st4 * K195090322[0];
-     tmp709 = st5;
-     st5 = st1 - tmp702;
-     tmp710 = st5;
-     st5 = st6 * K980785280[0];
-     st1 = st1 + tmp702;
-     st4 = st4 * K980785280[0];
-     st7 = st7 + st3;
-     st6 = st6 * K195090322[0];
-     st3 = st7 + tmp701;
-     tmp711 = st4;
-     st4 = st8 * K831469612[0];
-     st7 = tmp701 - st7;
-     tmp712 = st4;
-     st4 = st2 * K555570233[0];
-     tmp713 = st4;
-     st4 = tmp673 - st3;
-     st2 = st2 * K831469612[0];
-     st8 = st8 * K555570233[0];
-     st3 = tmp673 + st3;
-     c_im(input[23]) = st4;
-     st4 = tmp672 - st7;
-     st7 = tmp672 + st7;
-     c_im(input[7]) = st3;
-     st3 = tmp659 - tmp710;
-     c_re(input[31]) = st4;
-     st4 = tmp659 + tmp710;
-     c_re(input[15]) = st7;
-     st7 = tmp658 - st1;
-     st1 = tmp658 + st1;
-     c_im(input[31]) = st3;
-     st3 = tmp706 + tmp708;
-     c_im(input[15]) = st4;
-     st4 = st3 + tmp695;
-     st3 = tmp695 - st3;
-     c_re(input[23]) = st7;
-     st7 = tmp705 - tmp707;
-     c_re(input[7]) = st1;
-     st1 = st7 - tmp700;
-     st7 = st7 + tmp700;
-     tmp714 = st2;
-     st2 = tmp661 - st1;
-     st1 = tmp661 + st1;
-     c_im(input[29]) = st2;
-     st2 = tmp671 - st7;
-     st7 = tmp671 + st7;
-     c_im(input[13]) = st1;
-     st1 = tmp660 - st4;
-     st4 = tmp660 + st4;
-     c_re(input[21]) = st2;
-     st2 = tmp662 - st3;
-     st3 = tmp662 + st3;
-     st5 = tmp709 + st5;
-     c_re(input[5]) = st7;
-     st7 = st5 + tmp699;
-     st5 = tmp699 - st5;
-     st6 = tmp711 - st6;
-     c_im(input[21]) = st1;
-     st1 = st6 - tmp698;
-     st6 = st6 + tmp698;
-     c_im(input[5]) = st4;
-     st4 = tmp670 - st1;
-     st1 = tmp670 + st1;
-     c_re(input[29]) = st2;
-     st2 = tmp669 - st6;
-     st6 = tmp669 + st6;
-     c_re(input[13]) = st3;
-     st3 = tmp663 - st7;
-     st7 = tmp663 + st7;
-     c_im(input[25]) = st4;
-     st4 = tmp664 - st5;
-     st5 = tmp664 + st5;
-     c_im(input[9]) = st1;
-     st1 = tmp712 - tmp713;
-     c_re(input[17]) = st2;
-     st2 = st1 - tmp696;
-     st1 = st1 + tmp696;
-     st8 = tmp714 + st8;
-     c_re(input[1]) = st6;
-     st6 = st8 + tmp697;
-     st8 = tmp697 - st8;
-     c_im(input[17]) = st3;
-     st3 = tmp668 - st6;
-     st6 = tmp668 + st6;
-     c_im(input[1]) = st7;
-     st7 = tmp667 - st8;
-     st8 = tmp667 + st8;
-     c_re(input[25]) = st4;
-     st4 = tmp665 - st2;
-     st2 = tmp665 + st2;
-     c_re(input[9]) = st5;
-     st5 = tmp666 - st1;
-     st1 = tmp666 + st1;
-     c_im(input[19]) = st3;
-     c_im(input[3]) = st6;
-     c_re(input[27]) = st7;
-     c_re(input[11]) = st8;
-     c_im(input[27]) = st4;
-     c_im(input[11]) = st2;
-     c_re(input[19]) = st5;
-     c_re(input[3]) = st1;
-}
-
-void PFFTWI(64)(fftw_complex *input) 
-{
-     PFFTWI(16)(input );
-     PFFTWI(16)(input + 16);
-     PFFTWI(16)(input + 32);
-     PFFTWI(16)(input + 48);
-     PFFTWI(twiddle_4)(input, PFFTW(W_64), 16);
-}
-
-void PFFTWI(128)(fftw_complex *input) 
-{
-     PFFTWI(32)(input );
-     PFFTWI(32)(input + 32);
-     PFFTWI(32)(input + 64);
-     PFFTWI(32)(input + 96);
-     PFFTWI(twiddle_4)(input, PFFTW(W_128), 32);
-}
-
-void PFFTWI(256)(fftw_complex *input)
-{
-     PFFTWI(64)(input );
-     PFFTWI(64)(input + 64);
-     PFFTWI(64)(input + 128);
-     PFFTWI(64)(input + 192);
-     PFFTWI(twiddle_4)(input, PFFTW(W_256), 64);
-}
-
-void PFFTWI(512)(fftw_complex *input)
-{
-     PFFTWI(128)(input );
-     PFFTWI(128)(input + 128);
-     PFFTWI(128)(input + 256);
-     PFFTWI(128)(input + 384);
-     PFFTWI(twiddle_4)(input, PFFTW(W_512), 128);
-}
-
-void PFFTWI(1024)(fftw_complex *input)
-{
-     extern fftw_complex PFFTW(W_1024)[];
-     PFFTWI(256)(input );
-     PFFTWI(256)(input + 256);
-     PFFTWI(256)(input + 512);
-     PFFTWI(256)(input + 768);
-     PFFTWI(twiddle_4)(input, PFFTW(W_1024), 256);
-}
-
-///////////////////////////////////////////////////////////////////////////
-void  PFFTW(twiddle_4) (fftw_complex * A, const fftw_complex * W, int iostride) {
-     int i;
-     fftw_complex *inout;
-     inout = A;
-     {
-	  fftw_real st1;
-	  fftw_real st2;
-	  fftw_real st3;
-	  fftw_real st4;
-	  fftw_real st5;
-	  fftw_real st6;
-	  fftw_real st7;
-	  fftw_real st8;
-	  st8 = c_re(inout[0]);
-	  st8 = st8 + c_re(inout[2 * iostride]);
-	  st7 = c_re(inout[iostride]);
-	  st7 = st7 + c_re(inout[3 * iostride]);
-	  st6 = st8 - st7;
-	  st8 = st8 + st7;
-	  st5 = c_im(inout[0]);
-	  st5 = st5 + c_im(inout[2 * iostride]);
-	  st4 = c_im(inout[iostride]);
-	  st4 = st4 + c_im(inout[3 * iostride]);
-	  st3 = st5 - st4;
-	  st5 = st5 + st4;
-	  st2 = c_im(inout[0]);
-	  st2 = st2 - c_im(inout[2 * iostride]);
-	  st1 = c_re(inout[iostride]);
-	  st1 = st1 - c_re(inout[3 * iostride]);
-	  st7 = st2 - st1;
-	  st1 = st1 + st2;
-	  st4 = c_re(inout[0]);
-	  st4 = st4 - c_re(inout[2 * iostride]);
-	  c_re(inout[2 * iostride]) = st6;
-	  st6 = c_im(inout[iostride]);
-	  st6 = st6 - c_im(inout[3 * iostride]);
-	  c_re(inout[0]) = st8;
-	  st8 = st4 - st6;
-	  st4 = st4 + st6;
-	  c_im(inout[0]) = st5;
-	  c_im(inout[2 * iostride]) = st3;
-	  c_im(inout[iostride]) = st7;
-	  c_im(inout[3 * iostride]) = st1;
-	  c_re(inout[3 * iostride]) = st8;
-	  c_re(inout[iostride]) = st4;
-     }
-     inout = inout + 1;
-     i = iostride - 1;
-     do {
-	  {
-	       fftw_real st1;
-	       fftw_real st2;
-	       fftw_real st3;
-	       fftw_real st4;
-	       fftw_real st5;
-	       fftw_real st6;
-	       fftw_real st7;
-	       fftw_real st8;
-	       st8 = c_re(inout[0]);
-	       st8 = st8 + c_re(inout[2 * iostride]);
-	       st7 = c_re(inout[iostride]);
-	       st7 = st7 + c_re(inout[3 * iostride]);
-	       st6 = st8 - st7;
-	       st5 = st6 * c_im(W[1]);
-	       st8 = st8 + st7;
-	       st6 = st6 * c_re(W[1]);
-	       st4 = c_im(inout[0]);
-	       st4 = st4 + c_im(inout[2 * iostride]);
-	       st3 = c_im(inout[iostride]);
-	       st3 = st3 + c_im(inout[3 * iostride]);
-	       st2 = st4 - st3;
-	       st1 = st2 * c_im(W[1]);
-	       st4 = st4 + st3;
-	       st2 = st2 * c_re(W[1]);
-	       st2 = st2 - st5;
-	       st6 = st6 + st1;
-	       st7 = c_re(inout[0]);
-	       st7 = st7 - c_re(inout[2 * iostride]);
-	       st5 = c_im(inout[iostride]);
-	       st5 = st5 - c_im(inout[3 * iostride]);
-	       c_re(inout[0]) = st8;
-	       st8 = st7 - st5;
-	       st3 = st8 * c_re(W[0]);
-	       st7 = st7 + st5;
-	       st8 = st8 * c_im(W[0]);
-	       st1 = c_re(inout[iostride]);
-	       c_re(inout[2 * iostride]) = st6;
-	       st6 = st7 * c_im(W[0]);
-	       st1 = st1 - c_re(inout[3 * iostride]);
-	       st7 = st7 * c_re(W[0]);
-	       st5 = c_im(inout[0]);
-	       st5 = st5 - c_im(inout[2 * iostride]);
-	       c_im(inout[0]) = st4;
-	       st4 = st1 + st5;
-	       c_im(inout[2 * iostride]) = st2;
-	       st2 = st4 * c_im(W[0]);
-	       st5 = st5 - st1;
-	       st4 = st4 * c_re(W[0]);
-	       st3 = st3 - st2;
-	       st1 = st5 * c_re(W[0]);
-	       st5 = st5 * c_im(W[0]);
-	       st4 = st4 + st8;
-	       st5 = st5 + st7;
-	       st1 = st1 - st6;
-	       c_re(inout[3 * iostride]) = st3;
-	       c_im(inout[3 * iostride]) = st4;
-	       c_re(inout[iostride]) = st5;
-	       c_im(inout[iostride]) = st1;
-	  }
-	  i = i - 1, inout = inout + 1, W = W + 2;
-     } while (i > 0);
-}
-
-void PFFTWI(twiddle_4) (fftw_complex * A, const fftw_complex * W, int iostride) {
-     int i;
-     fftw_complex *inout;
-     inout = A;
-     {
-	  fftw_real st1;
-	  fftw_real st2;
-	  fftw_real st3;
-	  fftw_real st4;
-	  fftw_real st5;
-	  fftw_real st6;
-	  fftw_real st7;
-	  fftw_real st8;
-	  st8 = c_re(inout[0]);
-	  st8 = st8 + c_re(inout[2 * iostride]);
-	  st7 = c_re(inout[iostride]);
-	  st7 = st7 + c_re(inout[3 * iostride]);
-	  st6 = st8 - st7;
-	  st8 = st8 + st7;
-	  st5 = c_im(inout[0]);
-	  st5 = st5 + c_im(inout[2 * iostride]);
-	  st4 = c_im(inout[iostride]);
-	  st4 = st4 + c_im(inout[3 * iostride]);
-	  st3 = st5 - st4;
-	  st5 = st5 + st4;
-	  st2 = c_re(inout[iostride]);
-	  st2 = st2 - c_re(inout[3 * iostride]);
-	  st1 = c_im(inout[0]);
-	  st1 = st1 - c_im(inout[2 * iostride]);
-	  st7 = st2 + st1;
-	  st1 = st1 - st2;
-	  st4 = c_re(inout[0]);
-	  st4 = st4 - c_re(inout[2 * iostride]);
-	  c_re(inout[2 * iostride]) = st6;
-	  st6 = c_im(inout[iostride]);
-	  st6 = st6 - c_im(inout[3 * iostride]);
-	  c_re(inout[0]) = st8;
-	  st8 = st4 - st6;
-	  st4 = st4 + st6;
-	  c_im(inout[0]) = st5;
-	  c_im(inout[2 * iostride]) = st3;
-	  c_im(inout[iostride]) = st7;
-	  c_im(inout[3 * iostride]) = st1;
-	  c_re(inout[iostride]) = st8;
-	  c_re(inout[3 * iostride]) = st4;
-     }
-     inout = inout + 1;
-     i = iostride - 1;
-     do {
-	  {
-	       fftw_real st1;
-	       fftw_real st2;
-	       fftw_real st3;
-	       fftw_real st4;
-	       fftw_real st5;
-	       fftw_real st6;
-	       fftw_real st7;
-	       fftw_real st8;
-	       st8 = c_re(inout[2 * iostride]);
-	       st8 = st8 * c_re(W[1]);
-	       st7 = c_im(inout[2 * iostride]);
-	       st7 = st7 * c_im(W[1]);
-	       st8 = st8 - st7;
-	       st6 = st8 + c_re(inout[0]);
-	       st8 = c_re(inout[0]) - st8;
-	       st5 = c_re(inout[2 * iostride]);
-	       st5 = st5 * c_im(W[1]);
-	       st4 = c_im(inout[2 * iostride]);
-	       st4 = st4 * c_re(W[1]);
-	       st5 = st5 + st4;
-	       st3 = st5 + c_im(inout[0]);
-	       st5 = c_im(inout[0]) - st5;
-	       st2 = c_re(inout[iostride]);
-	       st2 = st2 * c_re(W[0]);
-	       st1 = c_im(inout[iostride]);
-	       st1 = st1 * c_im(W[0]);
-	       st2 = st2 - st1;
-	       st7 = c_re(inout[3 * iostride]);
-	       st7 = st7 * c_re(W[0]);
-	       st4 = c_im(inout[3 * iostride]);
-	       st4 = st4 * c_im(W[0]);
-	       st7 = st7 + st4;
-	       st1 = st2 + st7;
-	       st2 = st2 - st7;
-	       st4 = st6 - st1;
-	       st6 = st6 + st1;
-	       st7 = st2 + st5;
-	       st5 = st5 - st2;
-	       st1 = c_re(inout[iostride]);
-	       st1 = st1 * c_im(W[0]);
-	       st2 = c_im(inout[iostride]);
-	       st2 = st2 * c_re(W[0]);
-	       st1 = st1 + st2;
-	       c_re(inout[2 * iostride]) = st4;
-	       st4 = c_im(inout[3 * iostride]);
-	       st4 = st4 * c_re(W[0]);
-	       c_re(inout[0]) = st6;
-	       st6 = c_re(inout[3 * iostride]);
-	       st6 = st6 * c_im(W[0]);
-	       st4 = st4 - st6;
-	       c_im(inout[iostride]) = st7;
-	       st7 = st1 - st4;
-	       st1 = st1 + st4;
-	       c_im(inout[3 * iostride]) = st5;
-	       st5 = st8 - st7;
-	       st8 = st8 + st7;
-	       st2 = st1 + st3;
-	       st3 = st3 - st1;
-	       c_re(inout[iostride]) = st5;
-	       c_re(inout[3 * iostride]) = st8;
-	       c_im(inout[0]) = st2;
-	       c_im(inout[2 * iostride]) = st3;
-	  }
-	  i = i - 1, inout = inout + 1, W = W + 2;
-     } while (i > 0);
-}
-//////////////////////////////////////////////////////////////////////
-int PFFTW(permutation_64)(int i)
-{
-    int i1 = i % 4;
-    int i2 = i / 4;
-    if (i1 <= 2)
-       return (i1 * 16 + i2);
-    else
-       return (i1 * 16 + ((i2 + 1) % 16));
-}
-
-int PFFTW(permutation_128)(int i)
-{
-    int i1 = i % 4;
-    int i2 = i / 4;
-    if (i1 <= 2)
-       return (i1 * 32 + i2);
-    else
-       return (i1 * 32 + ((i2 + 1) % 32));
-}
-
-int PFFTW(permutation_256)(int i)
-{
-    int i1 = i % 4;
-    int i2 = i / 4;
-    if (i1 <= 2)
-       return (i1 * 64 + PFFTW(permutation_64)(i2));
-    else
-       return (i1 * 64 + PFFTW(permutation_64)((i2 + 1) % 64));
-}
-
-int PFFTW(permutation_512)(int i)
-{
-    int i1 = i % 4;
-    int i2 = i / 4;
-    if (i1 <= 2)
-       return (i1 * 128 + PFFTW(permutation_128)(i2));
-    else
-       return (i1 * 128 + PFFTW(permutation_128)((i2 + 1) % 128));
-}
-
-int PFFTW(permutation_1024)(int i)
-{
-    int i1 = i % 4;
-    int i2 = i / 4;
-    if (i1 <= (4 / 2))
-       return (i1 * 256 + PFFTW(permutation_256)(i2));
-    else
-       return (i1 * 256 + PFFTW(permutation_256)((i2 + 1) % 256));
-}
-
-/////////////////////////////////////////////////////////////////
-void make_FFT_order(void)
-{
-int i;
-for (i=0 ; i < 1024 ; i++){
-     if (i < 64) unscambled64[i] = PFFTW(permutation_64)(i);
-     if (i < 128) unscambled128[i] = PFFTW(permutation_128)(i);
-     if (i < 512) unscambled512[i] = PFFTW(permutation_512)(i);
-     unscambled1024[i] = PFFTW(permutation_1024)(i);
-     }
-}
-
--- a/fastfft.h
+++ /dev/null
@@ -1,44 +1,0 @@
-/*
- *	Function prototypes for fast FFT routines
- *
- *	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 13:04:05 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _FASTFFT_H_
-#define _FASTFFT_H_
-
-
-#include "transfo.h"
-
-#define PFFTW(name)  CONCAT(pfftw_, name)
-#define PFFTWI(name)  CONCAT(pfftwi_, name)
-#define CONCAT_AUX(a, b) a ## b
-#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);
-
-#endif
\ No newline at end of file
--- /dev/null
+++ b/frontend/faac.dsp
@@ -1,0 +1,106 @@
+# Microsoft Developer Studio Project File - Name="faac" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=faac - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "faac.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "faac.mak" CFG="faac - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "faac - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "faac - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "faac - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x413 /d "NDEBUG"
+# ADD RSC /l 0x413 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.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 libsndfile.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
+
+!ELSEIF  "$(CFG)" == "faac - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x413 /d "_DEBUG"
+# ADD RSC /l 0x413 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.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 libsndfile.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 
+
+# Begin Target
+
+# Name "faac - Win32 Release"
+# Name "faac - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\include\faac.h
+# End Source File
+# Begin Source File
+
+SOURCE="E:\Program Files\Microsoft Visual Studio\VC98\Include\sndfile.h"
+# End Source File
+# End Group
+# End Target
+# End Project
--- /dev/null
+++ b/frontend/faac.dsw
@@ -1,0 +1,44 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "faac"=.\faac.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+    Begin Project Dependency
+    Project_Dep_Name libfaac
+    End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "libfaac"=..\LIBFAAC\libfaac.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
--- /dev/null
+++ b/frontend/main.c
@@ -1,0 +1,209 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: main.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <sndfile.h>
+
+#include "faac.h"
+
+
+#define PCMBUFSIZE 1024
+#define BITBUFSIZE 8192
+
+int main(int argc, char *argv[])
+{
+	int i, frames, currentFrame;
+	faacEncHandle hEncoder;
+	SNDFILE *infile;
+	SF_INFO sfinfo;
+
+	unsigned int sr, chan;
+
+	short *pcmbuf;
+
+	unsigned char *bitbuf;
+	int bytesInput = 0;
+
+	FILE *outfile;
+
+#ifdef LINUX
+	struct rusage *usage;
+#endif
+#ifdef _WIN32
+	long begin, end;
+	int nTotSecs, nSecs;
+	int nMins;
+#else
+	float totalSecs;
+	int mins;
+#endif
+
+	printf("FAAC - command line demo\n");
+	printf("Uses FAACLIB version: %.1f %s\n\n", FAACENC_VERSION, (FAACENC_VERSIONB)?"beta":"");
+
+	if (argc < 3)
+	{
+		printf("USAGE: %s -options infile outfile\n", argv[0]);
+		printf("Options:\n");
+		printf("  -nm   Don\'t use mid/side coding\n");
+		printf("  -brX  Set the bitrate per channel, X in bps\n\n");
+		return 1;
+	}
+
+	/* open the audio input file */
+	infile = sf_open_read(argv[argc-2], &sfinfo);
+	if (infile == NULL)
+	{
+		printf("couldn't open input file %s\n", argv [argc-2]);
+		return 1;
+	}
+
+	/* open the aac output file */
+	outfile = fopen(argv[argc-1], "wb");
+	if (!outfile)
+	{
+		printf("couldn't create output file %s\n", argv [argc-1]);
+		return 1;
+	}
+
+	/* determine input file parameters */
+	sr = sfinfo.samplerate;
+	chan = sfinfo.channels;
+
+	pcmbuf = (short*)malloc(PCMBUFSIZE*chan*sizeof(short));
+	bitbuf = (unsigned char*)malloc(BITBUFSIZE*sizeof(unsigned char));
+
+	/* open the encoder library */
+	hEncoder = faacEncOpen(sr, chan);
+
+	/* set other options */
+	if (argc > 3)
+	{
+		faacEncConfigurationPtr myFormat;
+		myFormat = faacEncGetCurrentConfiguration(hEncoder);
+
+		for (i = 1; i < argc-2; i++) {
+			if ((argv[i][0] == '-') || (argv[i][0] == '/')) {
+				switch(argv[i][1]) {
+				case 'n': case 'N':
+					if ((argv[i][2] == 'm') || (argv[i][2] == 'M'))
+						myFormat->allowMidside = 0;
+				break;
+				case 'b': case 'B':
+					if ((argv[i][2] == 'r') || (argv[i][2] == 'R'))
+					{
+						unsigned int bitrate = atol(&argv[i][3]);
+						if (bitrate)
+						{
+							myFormat->bitRate = bitrate;
+						}
+					}
+				break;
+				}
+			}
+		}
+
+		if (!faacEncSetConfiguration(hEncoder, myFormat))
+			fprintf(stderr, "unsupported output format!\n");
+	}
+
+	if (outfile)
+	{
+#ifdef _WIN32
+		begin = GetTickCount();
+#endif
+		frames = (int)(sfinfo.samples/1024+0.5);
+		currentFrame = 0;
+
+		/* encoding loop */
+		for ( ;; )
+		{
+			int bytesWritten;
+
+			currentFrame++;
+
+			bytesInput = sf_read_short(infile, pcmbuf, chan*PCMBUFSIZE) * sizeof(short);
+
+			/* call the actual encoding routine */
+			bytesWritten = faacEncEncode(hEncoder,
+				pcmbuf,
+				bytesInput/2,
+				bitbuf,
+				BITBUFSIZE);
+
+#ifndef _DEBUG
+			printf("%.2f%%\tBusy encoding %s.\r",
+				min((double)(currentFrame*100)/frames,100), argv[argc-2]);
+#endif
+
+			/* all done, bail out */
+			if (!bytesInput && !bytesWritten)
+				break ;
+
+			if (bytesWritten < 0)
+			{
+				fprintf(stderr, "faacEncEncode() failed\n");
+				break ;
+			}
+
+			/* write bitstream to aac file */
+			fwrite(bitbuf, 1, bytesWritten, outfile);
+		}
+
+		/* clean up */
+		fclose(outfile);
+
+#ifdef _WIN32
+		end = GetTickCount();
+		nTotSecs = (end-begin)/1000;
+		nMins = nTotSecs / 60;
+		nSecs = nTotSecs - (60*nMins);
+		printf("Encoding %s took:\t%d:%.2d\t\n", argv[argc-2], nMins, nSecs);
+#else
+#ifdef LINUX
+		usage=malloc(sizeof(struct rusage*));
+		getrusage(RUSAGE_SELF,usage);
+		totalSecs=usage->ru_utime.tv_sec;
+		free(usage);
+		mins = totalSecs/60;
+		printf("Encoding %s took: %i min, %.2f sec. of cpu-time\n", argv[argc-2], mins, totalSecs - (60 * mins));
+#else
+		totalSecs = (float)(clock())/(float)CLOCKS_PER_SEC;
+		mins = totalSecs/60;
+		printf("Encoding %s took: %i min, %.2f sec.\n", argv[argc-2], mins, totalSecs - (60 * mins));
+#endif
+#endif
+	}
+
+	faacEncClose(hEncoder);
+
+	sf_close(infile);
+
+	if (pcmbuf) free(pcmbuf);
+	if (bitbuf) free(bitbuf);
+
+	return 0;
+}
--- /dev/null
+++ b/frontend/usage.txt
@@ -1,0 +1,10 @@
+Using the command line tool is quite simple.
+
+FAAC -options infile outfile
+
+infile can be any of the filetypes supported by
+libsndfile (http://www.zip.com.au/~erikd/libsndfile/)
+
+options:
+-nm   Don't use mid/side coding
+-brX  Use bitrate X, this is in bps/channel
--- a/huffman.c
+++ /dev/null
@@ -1,835 +1,0 @@
-/*
- *	AAC Huffman coding
- *
- *	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/06 14:47:27 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <math.h>
-
-#include "aacenc.h"
-#include "bitstream.h"
-#include "pulse.h"
-#include "quant.h"
-#include "huffman.h"
-#include "aac_se_enc.h"
-
-#include "hufftab5.h"
-
-
-sort_book_numbers(AACQuantInfo* quantInfo,     /* Quantization information */
-//		  int output_book_vector[],    /* Output codebook vector, formatted for bitstream */
-		  BsBitStream* fixed_stream,   /* Bitstream */
-		  int write_flag)              /* Write flag: 0 count, 1 write */
-{
-  /*
-    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:
-
-    {sect_cb[0], length_segment[0], ... ,sect_cb[num_of_sections], length_segment[num_of_sections]}
-
-    The above syntax is true, unless there is an escape sequence.  An
-    escape sequence occurs when a section is longer than 2 ^ (bit_len)
-    long in units of scalefactor bands.  Also, the integer returned from
-    this function is the number of bits written in the bitstream,
-    'bit_count'.
-
-    This function supports both long and short blocks.
-    */
-
-	int i;
-	int repeat_counter;
-	int bit_count = 0;
-	int previous;
-	int max, bit_len/*,sfbs*/;
-	int max_sfb,g,band;
-
-	/* Set local pointers to quantInfo elements */
-	int* book_vector = quantInfo -> book_vector;
-//	int nr_of_sfb = quantInfo -> nr_of_sfb;
-
-	if (quantInfo->block_type == ONLY_SHORT_WINDOW){
-		max = 7;
-		bit_len = 3;
-	} else {  /* the block_type is a long,start, or stop window */
-		max = 31;
-		bit_len = 5;
-	}
-
-	/* Compute number of scalefactor bands */
-	max_sfb = quantInfo->nr_of_sfb/quantInfo->num_window_groups;
-
-
-	for (g=0;g<quantInfo->num_window_groups;g++) {
-		band=g*max_sfb;
-
-		repeat_counter=1;
-
-		previous = book_vector[band];
-		if (write_flag) {
-			BsPutBit(fixed_stream,book_vector[band],4);
-		}
-		bit_count += 4;
-
-		for (i=band+1;i<band+max_sfb;i++) {
-			if( (book_vector[i] != previous)) {
-				if (write_flag) {
-					BsPutBit(fixed_stream,repeat_counter,bit_len);
-				}
-				bit_count += bit_len;
-
-				if (repeat_counter == max){  /* in case you need to terminate an escape sequence */
-					if (write_flag) BsPutBit(fixed_stream,0,bit_len);
-					bit_count += bit_len;
-				}
-
-				if (write_flag) BsPutBit(fixed_stream,book_vector[i],4);
-				bit_count += 4;
-				previous = book_vector[i];
-				repeat_counter=1;
-
-			}
-			/* if the length of the section is longer than the amount of bits available in */
-			/* the bitsream, "max", then start up an escape sequence */
-			else if ((book_vector[i] == previous) && (repeat_counter == max)) {
-				if (write_flag) {
-					BsPutBit(fixed_stream,repeat_counter,bit_len);
-				}
-				bit_count += bit_len;
-				repeat_counter = 1;
-			}
-			else {
-				repeat_counter++;
-			}
-		}
-
-		if (write_flag) {
-			BsPutBit(fixed_stream,repeat_counter,bit_len);
-		}
-		bit_count += bit_len;
-		if (repeat_counter == max) {  /* special case if the last section length is an */
-			/* escape sequence */
-			if (write_flag) BsPutBit(fixed_stream,0,bit_len);
-			bit_count += bit_len;
-		}
-
-
-	}  /* Bottom of group iteration */
-
-	return(bit_count);
-}
-
-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 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.
-
-  For a quick and simple algorithm, this function performs a binary
-  search across the sfb's (scale factor bands).  On the first approach, it calculates the 
-  needed amount of bits if every sfb were its own section and transmitted its own huffman 
-  codebook value side information (equal to 9 bits for a long block, 7 for a short).  The 
-  next iteration combines adjacent sfb's, and calculates the bit rate for length two sfb 
-  sections.  If any wider two-sfb section requires fewer bits than the sum of the two 
-  single-sfb sections (below it in the binary tree), then the wider section will be chosen.
-  This process occurs until the sections are split into three uniform parts, each with an
-  equal amount of sfb's contained.  
-
-  The binary tree is stored as a two-dimensional array.  Since this tree is not full, (there
-  are only 49 nodes, not 2^6 = 64), the numbering is a little complicated.  If the tree were
-  full, the top node would be 1.  It's children would be 2 and 3.  But, since this tree
-  is not full, the top row of three nodes are numbered {4,5,6}.  The row below it is
-  {8,9,10,11,12,13}, and so on.  
-
-  The binary tree is called bit_stats[112][3].  There are 112 total nodes (some are not
-  used since it's not full).  bit_stats[x][0] holds the bit totals needed for the sfb sectioning
-  strategy represented by the node x in the tree.  bit_stats[x][1] holds the optimal huffman
-  codebook table that minimizes the bit rate, given the sectioning boundaries dictated by node x.
-*/
-
-{
-	int i,j,k,n;
-	int hop;
-	int min_book_choice[112][3];
-	int bit_stats[240][3];
-//	int total_bits;
-	int total_bit_count;
-	int levels;
-	double fraction;
-
-	/* Set local pointer to quantInfo book_vector */
-	int* book_vector = quantInfo -> book_vector;
-
-	levels = (int) ((log((double)quantInfo->nr_of_sfb)/log((double)2.0))+1);
-	fraction = (pow(2,levels)+quantInfo->nr_of_sfb)/(double)(pow(2,levels));
-
-//#define SLOW
-#ifdef SLOW
-	for(i=0;i<5;i++){
-		hop = 1 << i;
-#else
-		hop = 1;
-		i = 0;
-#endif
-//		total_bits = noiseless_bit_count(quant, hop, min_book_choice, quantInfo);
-		noiseless_bit_count(quant, hop, min_book_choice, quantInfo);
-
-		/* load up the (not-full) binary search tree with the min_book_choice values */
-		k=0;
-//		m=0;
-		total_bit_count = 0;
-
-		for (j=(int)(pow(2,levels-i)); j<(int)(fraction*pow(2,levels-i)); j++)
-		{
-			bit_stats[j][0] = min_book_choice[k][0]; /* the minimum bit cost for this section */
-			bit_stats[j][1] = min_book_choice[k][1]; /* used with this huffman book number */
-
-			if (i>0){  /* not on the lowest level, grouping more than one signle scalefactor band per section*/
-				if  (bit_stats[j][0] < bit_stats[2*j][0] + bit_stats[2*j+1][0]){
-
-					/* it is cheaper to combine surrounding sfb secionts into one larger huffman book section */
-					for(n=k;n<k+hop;n++) { /* write the optimal huffman book value for the new larger section */
-						if ( (book_vector[n]!=INTENSITY_HCB)&&(book_vector[n]!=INTENSITY_HCB2) ) { /* Don't merge with IS bands */
-							book_vector[n] = bit_stats[j][1];
-						}
-					}
-				} else {  /* it was cheaper to transmit the smaller huffman table sections */
-					bit_stats[j][0] = bit_stats[2*j][0] + bit_stats[2*j+1][0];
-				}
-			} else {  /* during the first stage of the iteration, all sfb's are individual sections */
-				if ( (book_vector[k]!=INTENSITY_HCB)&&(book_vector[k]!=INTENSITY_HCB2) ) {
-					book_vector[k] = bit_stats[j][1];  /* initially, set all sfb's to their own optimal section table values */
-				}
-			}
-			total_bit_count = total_bit_count +  bit_stats[j][0];
-			k=k+hop;
-//			m++;
-		}
-#ifdef SLOW
-	}
-#endif
-	/*   book_vector[k] = book_vector[k-1]; */
-	return(total_bit_count);
-}
-
-
-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],
-			AACQuantInfo* quantInfo)         /* Quantization information */
-{
-  int i,j,k;
-
-  /*
-     This function inputs:
-     - the quantized spectral data, 'quant[][]';
-     - all of the huffman codebooks, 'huff[][]';
-     - the size of the sections, in scalefactor bands (SFB's), 'hop';
-     - an empty matrix, min_book_choice[][] passed to it;
-
-     This function outputs:
-     - the matrix, min_book_choice.  It is a two dimensional matrix, with its
-     rows corresponding to spectral sections.  The 0th column corresponds to
-     the bits needed to code a section with 'hop' scalefactors bands wide, all using
-     the same huffman codebook.  The 1st column contains the huffman codebook number
-     that allows the minimum number of bits to be used.
-
-     Other notes:
-     - Initally, the dynamic range is calculated for each spectral section.  The section
-     can only be entropy coded with books that have an equal or greater dynamic range
-     than the section's spectral data.  The exception to this is for the 11th ESC codebook.
-     If the dynamic range is larger than 16, then an escape code is appended after the
-     table 11 codeword which encodes the larger value explicity in a pseudo-non-uniform
-     quantization method.
-
-     */
-
-	int max_sb_coeff;
-	int book_choice[12][2];
-	int total_bits_cost = 0;
-	int offset, length, end;
-	int q;
-	int write_flag = 0;
-
-	/* set local pointer to sfb_offset */
-	int* sfb_offset = quantInfo->sfb_offset;
-	int nr_of_sfb = quantInfo->nr_of_sfb;
-
-	/* each section is 'hop' scalefactor bands wide */
-	for (i=0; i < nr_of_sfb; i=i+hop){ 
-		if ((i+hop) > nr_of_sfb)
-			q = nr_of_sfb;
-		else
-			q = i+hop;
-
-		{
-			
-			/* find the maximum absolute value in the current spectral section, to see what tables are available to use */
-			max_sb_coeff = 0;
-			for (j=sfb_offset[i]; j<sfb_offset[q]; j++){  /* snl */
-				if (ABS(quant[j]) > max_sb_coeff)
-					max_sb_coeff = ABS(quant[j]);
-			}
-
-			j = 0;
-			offset = sfb_offset[i];
-			if ((i+hop) > nr_of_sfb){
-				end = sfb_offset[nr_of_sfb];
-			}
-			else
-				end = sfb_offset[q];
-			length = end - offset;
-
-			/* all spectral coefficients in this section are zero */
-			if (max_sb_coeff == 0) { 
-				book_choice[j][0] = output_bits(quantInfo,0,quant,offset,length,write_flag);
-				book_choice[j++][1] = 0;
-
-			}
-			else {  /* if the section does have non-zero coefficients */
-				if(max_sb_coeff < 2){
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,1,quant,offset,length,write_flag);
-					book_choice[j++][1] = 1;
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,2,quant,offset,length,write_flag);
-					book_choice[j++][1] = 2;
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,3,quant,offset,length,write_flag);
-					book_choice[j++][1] = 3;
-				}
-				else if (max_sb_coeff < 3){
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,3,quant,offset,length,write_flag);
-					book_choice[j++][1] = 3;
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,4,quant,offset,length,write_flag);
-					book_choice[j++][1] = 4;
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,5,quant,offset,length,write_flag);
-					book_choice[j++][1] = 5;
-				}
-				else if (max_sb_coeff < 5){
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,5,quant,offset,length,write_flag);
-					book_choice[j++][1] = 5;
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,6,quant,offset,length,write_flag);
-					book_choice[j++][1] = 6;
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,7,quant,offset,length,write_flag);
-					book_choice[j++][1] = 7;
-				}
-				else if (max_sb_coeff < 8){
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,7,quant,offset,length,write_flag);
-					book_choice[j++][1] = 7;
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,8,quant,offset,length,write_flag);
-					book_choice[j++][1] = 8;
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,9,quant,offset,length,write_flag);
-					book_choice[j++][1] = 9;
-				}
-				else if (max_sb_coeff < 13){
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,9,quant,offset,length,write_flag);
-					book_choice[j++][1] = 9;
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,10,quant,offset,length,write_flag);
-					book_choice[j++][1] = 10;
-				}
-				/* (max_sb_coeff >= 13), choose table 11 */
-				else {
-					quantInfo->spectralCount = 0; /* just for debugging : using data and len vectors */
-					book_choice[j][0] = output_bits(quantInfo,11,quant,offset,length,write_flag);
-					book_choice[j++][1] = 11;
-				}
-			}
-
-			/* find the minimum bit cost and table number for huffman coding this scalefactor section */
-			min_book_choice[i][0] = 100000;  
-			for(k=0;k<j;k++){
-				if (book_choice[k][0] < min_book_choice[i][0]){
-					min_book_choice[i][1] = book_choice[k][1];
-					min_book_choice[i][0] = book_choice[k][0];
-				}
-			}
-			total_bits_cost += min_book_choice[i][0];
-		}
-	}
-	return(total_bits_cost);
-}
-
-
-
-int calculate_esc_sequence(int input,
-						   int *len_esc_sequence
-						   )
-/* 
-   This function takes an element that is larger than 16 and generates the base10 value of the
-   equivalent escape sequence.  It returns the escape sequence in the variable, 'output'.  It
-   also passed the length of the escape sequence through the parameter, 'len_esc_sequence'.
-*/
-
-{
-	float x,y;
-	int output;
-	int N;
-
-	N = -1;
-	y = (float)ABS(input);
-	x = y / 16;
-
-	while (x >= 1) {
-		N++;
-		x = x/2;
-	}
-
-	*len_esc_sequence = 2*N + 5;  /* the length of the escape sequence in bits */
-
-	output = (int)((pow(2,N) - 1)*pow(2,N+5) + y - pow(2,N+4));
-	return(output);
-}
-
-
-#ifndef __BORLANDC__
-__inline
-#endif
-int output_bits(AACQuantInfo* quantInfo,
-		/*int huff[13][MAXINDEX][NUMINTAB],*/
-                int book,
-		int quant[BLOCK_LEN_LONG],
-                int offset,
-		int length,
-		int write_flag)
-{
-  /* 
-     This function inputs 
-     - all the huffman codebooks, 'huff[]' 
-     - a specific codebook number, 'book'
-     - the quantized spectral data, 'quant[][]'
-     - the offset into the spectral data to begin scanning, 'offset'
-     - the 'length' of the segment to huffman code
-     -> therefore, the segment quant[CHANNEL][offset] to quant[CHANNEL][offset+length-1]
-     is huffman coded.
-     - a flag, 'write_flag' to determine whether the codebooks and lengths need to be written
-     to file.  If write_flag=0, then this function is being used only in the quantization
-     rate loop, and does not need to spend time writing the codebooks and lengths to file.
-     If write_flag=1, then it is being called by the function output_bits(), which is 
-     sending the bitsteam out of the encoder.  
-
-     This function outputs 
-     - the number of bits required, 'bits'  using the prescribed codebook, book applied to 
-     the given segment of spectral data.
-
-     There are three parameters that are passed back and forth into this function.  data[]
-     and len[] are one-dimensional arrays that store the codebook values and their respective
-     bit lengths.  These are used when packing the data for the bitstream in output_bits().  The
-     index into these arrays is 'quantInfo->spectralCount''.  It gets incremented internally in this
-     function as counter, then passed to the outside through outside_counter.  The next time
-     output_bits() is called, counter starts at the value it left off from the previous call.
-
-   */
- 
-	int esc_sequence;
-	int len_esc;
-	int index;
-	int bits=0;
-	int tmp;
-	int codebook,i,j;
-	int counter;
-
-	/* Set up local pointers to quantInfo elements data and len */
-	int* data= quantInfo -> data;
-	int* len=  quantInfo -> len;
-
-	counter = quantInfo->spectralCount;
-
-	/* This case also applies to intensity stereo encoding */
-	/*if (book == 0) { */ /* if using the zero codebook, data of zero length is sent */
-	if ((book == 0)||(book==INTENSITY_HCB2)||(book==INTENSITY_HCB)) {  /* if using the zero codebook, 
-		data of zero length is sent */
-		
-		if (write_flag) {
-			quantInfo->data[counter] = 0;
-			quantInfo->len[counter++] = 0;
-		}
-	}
-
-	if ((book == 1) || (book == 2)) {
-		for(i=offset;i<offset+length;i=i+4){
-			index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
-			if (book == 1) {
-				codebook = huff1[index][LASTINTAB];
-				tmp = huff1[index][FIRSTINTAB];
-			} else {
-				codebook = huff2[index][LASTINTAB];
-				tmp = huff2[index][FIRSTINTAB];
-			}
-			bits += tmp;
-			if (write_flag) {
-				data[counter] = codebook;
-				len[counter++] = tmp;
-			}
-		}
-	}
-
-	if ((book == 3) || (book == 4)) {
-		for(i=offset;i<offset+length;i=i+4){
-			index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
-			if (book == 3) {
-				codebook = huff3[index][LASTINTAB];
-				tmp = huff3[index][FIRSTINTAB];
-			} else {
-				codebook = huff4[index][LASTINTAB];
-				tmp = huff4[index][FIRSTINTAB];
-			}
-			bits = bits + tmp;
-			for(j=0;j<4;j++){
-				if(ABS(quant[i+j]) > 0) bits += 1; /* only for non-zero spectral coefficients */
-			}
-			if (write_flag) {
-				data[counter] = codebook;
-				len[counter++] = tmp;
-				for(j=0;j<4;j++){
-					if(quant[i+j] > 0) {  /* send out '0' if a positive value */
-						data[counter] = 0;
-						len[counter++] = 1;
-					}
-					if(quant[i+j] < 0) {  /* send out '1' if a negative value */
-						data[counter] = 1;
-						len[counter++] = 1;
-					}
-				}
-			}
-		}
-	}
-
-	if ((book == 5) || (book == 6)) {
-		for(i=offset;i<offset+length;i=i+2){
-			index = 9*(quant[i]) + (quant[i+1]) + 40;
-			if (book == 5) {
-				codebook = huff5[index][LASTINTAB];
-				tmp = huff5[index][FIRSTINTAB];
-			} else {
-				codebook = huff6[index][LASTINTAB];
-				tmp = huff6[index][FIRSTINTAB];
-			}
-			bits = bits + tmp;
-			if (write_flag) {
-				data[counter] = codebook;
-				len[counter++] = tmp;
-			}
-		}
-	}
-
-	if ((book == 7) || (book == 8)) {
-		for(i=offset;i<offset+length;i=i+2){
-			index = 8*ABS(quant[i]) + ABS(quant[i+1]);
-			if (book == 7) {
-				codebook = huff7[index][LASTINTAB];
-				tmp = huff7[index][FIRSTINTAB];
-			} else {
-				codebook = huff8[index][LASTINTAB];
-				tmp = huff8[index][FIRSTINTAB];
-			}
-			bits = bits + tmp;
-			for(j=0;j<2;j++){
-				if(ABS(quant[i+j]) > 0) bits += 1; /* only for non-zero spectral coefficients */
-			}
-			if (write_flag) {
-				data[counter] = codebook;
-				len[counter++] = tmp;
-				for(j=0;j<2;j++){
-					if(quant[i+j] > 0) {  /* send out '0' if a positive value */
-						data[counter] = 0;
-						len[counter++] = 1;
-					}
-					if(quant[i+j] < 0) {  /* send out '1' if a negative value */
-						data[counter] = 1;
-						len[counter++] = 1;
-					}
-				}
-			}
-		}
-	}
-
-	if ((book == 9) || (book == 10)) {
-		for(i=offset;i<offset+length;i=i+2){
-			index = 13*ABS(quant[i]) + ABS(quant[i+1]);
-			if (book == 9) {
-				codebook = huff9[index][LASTINTAB];
-				tmp = huff9[index][FIRSTINTAB];
-			} else {
-				codebook = huff10[index][LASTINTAB];
-				tmp = huff10[index][FIRSTINTAB];
-			}
-			bits = bits + tmp;
-			for(j=0;j<2;j++){
-				if(ABS(quant[i+j]) > 0) bits += 1; /* only for non-zero spectral coefficients */
-			}
-			if (write_flag) {
-				
-				data[counter] = codebook;
-				len[counter++] = tmp;
-
-				for(j=0;j<2;j++){
-					if(quant[i+j] > 0) {  /* send out '0' if a positive value */
-						data[counter] = 0;
-						len[counter++] = 1;
-					}
-					if(quant[i+j] < 0) {  /* send out '1' if a negative value */
-						data[counter] = 1;
-						len[counter++] = 1;
-					}
-				}
-			}
-		}
-	}
-
-	if ((book == 11)){
-		/* First, calculate the indecies into the huffman tables */
-
-		for(i=offset;i<offset+length;i=i+2){
-			if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) {  /* both codewords were above 16 */
-				/* first, code the orignal pair, with the larger value saturated to +/- 16 */
-				index = 17*16 + 16;
-			}
-			else if (ABS(quant[i]) >= 16) {  /* the first codeword was above 16, not the second one */
-				/* first, code the orignal pair, with the larger value saturated to +/- 16 */
-				index = 17*16 + ABS(quant[i+1]);
-			}
-			else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
-				index = 17*ABS(quant[i]) + 16;
-			}
-			else {  /* there were no values above 16, so no escape sequences */
-				index = 17*ABS(quant[i]) + ABS(quant[i+1]);
-			}
-
-			/* write out the codewords */
-
-			tmp = huff11[index][FIRSTINTAB];
-			codebook = huff11[index][LASTINTAB];
-			bits += tmp;
-			if (write_flag) {
-				/*	printf("[book %d] {%d %d} \n",book,quant[i],quant[i+1]);*/
-				data[counter] = codebook;
-				len[counter++] = tmp;
-			}
-			
-			/* Take care of the sign bits */
-
-			for(j=0;j<2;j++){
-				if(ABS(quant[i+j]) > 0) bits += 1; /* only for non-zero spectral coefficients */
-			}
-			if (write_flag) {
-				for(j=0;j<2;j++){
-					if(quant[i+j] > 0) {  /* send out '0' if a positive value */
-						data[counter] = 0;
-						len[counter++] = 1;
-					}
-					if(quant[i+j] < 0) {  /* send out '1' if a negative value */
-						data[counter] = 1;
-						len[counter++] = 1;
-					}
-				}
-			}
-
-			/* write out the escape sequences */
-
-			if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) {  /* both codewords were above 16 */
-				/* code and transmit the first escape_sequence */
-				esc_sequence = calculate_esc_sequence(quant[i],&len_esc); 
-				bits += len_esc;
-				if (write_flag) {
-					data[counter] = esc_sequence;
-					len[counter++] = len_esc;
-				}
-
-				/* then code and transmit the second escape_sequence */
-				esc_sequence = calculate_esc_sequence(quant[i+1],&len_esc);
-				bits += len_esc;
-				if (write_flag) {
-					data[counter] = esc_sequence;
-					len[counter++] = len_esc;
-				}
-			}
-
-			else if (ABS(quant[i]) >= 16) {  /* the first codeword was above 16, not the second one */
-				/* code and transmit the escape_sequence */
-				esc_sequence = calculate_esc_sequence(quant[i],&len_esc); 
-				bits += len_esc;
-				if (write_flag) {
-					data[counter] = esc_sequence;
-					len[counter++] = len_esc;
-				}
-			}
-
-			else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
-				/* code and transmit the escape_sequence */
-				esc_sequence = calculate_esc_sequence(quant[i+1],&len_esc); 
-				bits += len_esc;
-				if (write_flag) {
-					data[counter] = esc_sequence;
-					len[counter++] = len_esc;
-				}
-			} 
-		}
-	}
-
-	quantInfo -> spectralCount = counter;  /* send the current count back to the outside world */
-
-	return(bits);
-}
-
-
-int find_grouping_bits(int window_group_length[],
-					   int num_window_groups
-					   )
-{
-
-  /* This function inputs the grouping information and outputs the seven bit 
-	'grouping_bits' field that the NBC decoder expects.  */
-
-
-	int grouping_bits = 0;
-	int tmp[8];
-	int i,j;
-	int index=0;
-
-	for(i=0; i<num_window_groups; i++){
-		for (j=0; j<window_group_length[i];j++){
-			tmp[index++] = i;
-		}
-	}
-
-	for(i=1; i<8; i++){
-		grouping_bits = grouping_bits << 1;
-		if(tmp[i] == tmp[i-1]) {
-			grouping_bits++;
-		}
-	}
-	
-	return(grouping_bits);
-}
-
-
-
-int write_scalefactor_bitstream(BsBitStream* fixed_stream,             /* Bitstream */  
-				int write_flag,                        /* Write flag */
-				AACQuantInfo* quantInfo)               /* Quantization information */
-{
-	/* this function takes care of counting the number of bits necessary */
-	/* to encode the scalefactors.  In addition, if the write_flag == 1, */
-	/* then the scalefactors are written out the fixed_stream output bit */
-	/* stream.  it returns k, the number of bits written to the bitstream*/
-
-	int i,j,bit_count=0;
-	int diff,length,codeword;
-	int previous_scale_factor;
-	int previous_is_factor;       /* Intensity stereo */
-	int index = 0;
-//	int count = 0;
-//	int group_offset = 0;
-	int nr_of_sfb_per_group;
-
-	int pns_pcm_flag = 1;
-	int previous_noise_nrg = quantInfo->common_scalefac ;
-
-	/* set local pointer to quantInfo elements */
-	int* scale_factors = quantInfo->scale_factor;
-
-	if (quantInfo->block_type == ONLY_SHORT_WINDOW) { /* short windows */
-		nr_of_sfb_per_group = quantInfo->nr_of_sfb/quantInfo->num_window_groups;
-	}
-	else {
-		nr_of_sfb_per_group = quantInfo->nr_of_sfb;
-		quantInfo->num_window_groups = 1;
-		quantInfo->window_group_length[0] = 1;
-	}
-
-	previous_scale_factor = quantInfo->common_scalefac;
-	previous_is_factor = 0;
-    
-	for(j=0; j<quantInfo->num_window_groups; j++){
-		for(i=0;i<nr_of_sfb_per_group;i++) {  
-			/* test to see if any codebooks in a group are zero */
-			if ( (quantInfo->book_vector[index]==INTENSITY_HCB) ||
-				(quantInfo->book_vector[index]==INTENSITY_HCB2) ) {
-				/* only send scalefactors if using non-zero codebooks */
-				diff = scale_factors[index] - previous_is_factor;
-				if ((diff < 60)&&(diff >= -60))
-					length = huff12[diff+60][FIRSTINTAB];
-				else length = 0;
-				bit_count+=length;
-				previous_is_factor = scale_factors[index];
-				if (write_flag == 1 ) {   
-					codeword = huff12[diff+60][LASTINTAB];
-					BsPutBit(fixed_stream,codeword,length); 
-				}
-			} else if (quantInfo-> book_vector[index] == PNS_HCB){
-				diff = quantInfo->pns_sfb_nrg[index] - previous_noise_nrg;
-				if (pns_pcm_flag) {
-					pns_pcm_flag = 0;
-					length = PNS_PCM_BITS;
-					codeword = diff + PNS_PCM_OFFSET;
-				} else {
-					if (diff<-60  ||  diff>60) {
-						length = 0;
-						codeword = 0;
-					} else {
-						length = huff12[diff+60][FIRSTINTAB];
-						codeword = huff12[diff+60][LASTINTAB];
-					}
-				}
-				bit_count += length;
-				previous_noise_nrg = quantInfo->pns_sfb_nrg[index];
-				if (write_flag == 1 ) {   
-					BsPutBit(fixed_stream,codeword,length); 
-				}
-			} else if (quantInfo->book_vector[index]) {
-				/* only send scalefactors if using non-zero codebooks */
-				diff = scale_factors[index] - previous_scale_factor;
-				if ((diff < 60)&&(diff >= -60))
-					length = huff12[diff+60][FIRSTINTAB];
-				else length = 0;
-				bit_count+=length;
-				previous_scale_factor = scale_factors[index];
-				if (write_flag == 1 ) {   
-					codeword = huff12[diff+60][LASTINTAB];
-					BsPutBit(fixed_stream,codeword,length); 
-				}
-			}
-			index++;
-		}
-	}
-	return(bit_count);
-}
-
--- a/huffman.h
+++ /dev/null
@@ -1,113 +1,0 @@
-/*
- *	Function prototypes for AAC Huffman coding
- *
- *	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/06 14:47:27 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef HUFFMAN_H
-#define HUFFMAN_H
-
-#include "pulse.h"
-#include "interface.h"
-#include "tns.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define PNS_HCB 13                               /* reserved codebook for flagging PNS */
-#define PNS_PCM_BITS 9                           /* size of first (PCM) PNS energy */
-#define PNS_PCM_OFFSET (1 << (PNS_PCM_BITS-1))   /* corresponding PCM transmission offset */
-#define PNS_SF_OFFSET 90                         /* transmission offset for PNS energies */
-
-// Huffman tables
-#define MAXINDEX 289
-#define NUMINTAB 2
-#define FIRSTINTAB 0
-#define LASTINTAB 1
-
-
-void PulseCoder(AACQuantInfo *quantInfo, int *quant);
-void PulseDecoder(AACQuantInfo *quantInfo, int *quant);
-
-/*********************************************************/
-/* sort_book_numbers                                     */
-/*********************************************************/
-int sort_book_numbers(AACQuantInfo* quantInfo,     /* Quantization information */
-//		  int output_book_vector[],    /* Output codebook vector, formatted for bitstream */
-		  BsBitStream* fixed_stream,   /* Bitstream */
-		  int write_flag);             /* Write flag: 0 count, 1 write */
-
-
-/*********************************************************/
-/* bit_search                                            */
-/*********************************************************/
-int bit_search(int quant[BLOCK_LEN_LONG],  /* Quantized spectral values */
-               AACQuantInfo* quantInfo);       /* Quantization information */
-
-/*********************************************************/
-/* noiseless_bit_count                                   */
-/*********************************************************/
-int noiseless_bit_count(int quant[BLOCK_LEN_LONG],
-			int hop,
-			int min_book_choice[112][3],
-			AACQuantInfo* quantInfo);         /* Quantization information */
-
-/*********************************************************/
-/* output_bits                                           */
-/*********************************************************/
-#ifndef __BORLANDC__
-__inline
-#endif
-int output_bits(AACQuantInfo* quantInfo,
-		/*int huff[13][MAXINDEX][NUMINTAB],*/
-                int book,                /* codebook */
-		int quant[BLOCK_LEN_LONG],		
-		int offset,
-		int length,
-		int write_flag);
-
-
-/*********************************************************/
-/* find_grouping_bits                                    */
-/*********************************************************/
-int find_grouping_bits(int window_group_length[],
-		       int num_window_groups
-		       );
-
-/*********************************************************/
-/* write_scalefactor_bitstream                           */
-/*********************************************************/
-int write_scalefactor_bitstream(BsBitStream* fixed_stream,             /* Bitstream */  
-				int write_flag,                        /* Write flag */
-				AACQuantInfo* quantInfo);              /* Quantization information */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--- a/hufftab5.h
+++ /dev/null
@@ -1,338 +1,0 @@
-/*
- *	Huffman Tables
- *
- *	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.2 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-int huff1[][2] = {
-		{ 11,  2040},
-		{ 9,  497},{ 11,  2045},{ 10,  1013},{ 7,  104},{ 10,  1008},
-		{ 11,  2039},{ 9,  492},{ 11,  2037},{ 10,  1009},{ 7,  114},
-		{ 10,  1012},{ 7,  116},{ 5,  17},{ 7,  118},{ 9,  491},
-		{ 7,  108},{ 10,  1014},{ 11,  2044},{ 9,  481},{ 11,  2033},
-		{ 9,  496},{ 7,  97},{ 9,  502},{ 11,  2034},{ 9,  490},
-		{ 11,  2043},{ 9,  498},{ 7,  105},{ 9,  493},{ 7,  119},
-		{ 5,  23},{ 7,  111},{ 9,  486},{ 7,  100},{ 9,  485},
-		{ 7,  103},{ 5,  21},{ 7,  98},{ 5,  18},{ 1,  0},
-		{ 5,  20},{ 7,  101},{ 5,  22},{ 7,  109},{ 9,  489},
-		{ 7,  99},{ 9,  484},{ 7,  107},{ 5,  19},{ 7,  113},
-		{ 9,  483},{ 7,  112},{ 9,  499},{ 11,  2046},{ 9,  487},
-		{ 11,  2035},{ 9,  495},{ 7,  96},{ 9,  494},{ 11,  2032},
-		{ 9,  482},{ 11,  2042},{ 10,  1011},{ 7,  106},{ 9,  488},
-		{ 7,  117},{ 5,  16},{ 7,  115},{ 9,  500},{ 7,  110},
-		{ 10,  1015},{ 11,  2038},{ 9,  480},{ 11,  2041},{ 10,  1010},
-		{ 7,  102},{ 9,  501},{ 11,  2047},{ 9,  503},{ 11,  2036}
-	};
-int huff2[][2] = {
-	{ 9,  499},
-		{ 7,  111},{ 9,  509},{ 8,  235},{ 6,  35},{ 8,  234},
-		{ 9,  503},{ 8,  232},{ 9,  506},{ 8,  242},{ 6,  45},
-		{ 7,  112},{ 6,  32},{ 5,  6},{ 6,  43},{ 7,  110},
-		{ 6,  40},{ 8,  233},{ 9,  505},{ 7,  102},{ 8,  248},
-		{ 8,  231},{ 6,  27},{ 8,  241},{ 9,  500},{ 7,  107},
-		{ 9,  501},{ 8,  236},{ 6,  42},{ 7,  108},{ 6,  44},
-		{ 5,  10},{ 6,  39},{ 7,  103},{ 6,  26},{ 8,  245},
-		{ 6,  36},{ 5,  8},{ 6,  31},{ 5,  9},{ 3,  0},
-		{ 5,  7},{ 6,  29},{ 5,  11},{ 6,  48},{ 8,  239},
-		{ 6,  28},{ 7,  100},{ 6,  30},{ 5,  12},{ 6,  41},
-		{ 8,  243},{ 6,  47},{ 8,  240},{ 9,  508},{ 7,  113},
-		{ 9,  498},{ 8,  244},{ 6,  33},{ 8,  230},{ 8,  247},
-		{ 7,  104},{ 9,  504},{ 8,  238},{ 6,  34},{ 7,  101},
-		{ 6,  49},{ 4,  2},{ 6,  38},{ 8,  237},{ 6,  37},
-		{ 7,  106},{ 9,  507},{ 7,  114},{ 9,  510},{ 7,  105},
-		{ 6,  46},{ 8,  246},{ 9,  511},{ 7,  109},{ 9,  502}
-	};
-int huff3[][2] = {
-		{ 1,  0},
-		{ 4,  9},{ 8,  239},{ 4,  11},{ 5,  25},{ 8,  240},
-		{ 9,  491},{ 9,  486},{ 10,  1010},{ 4,  10},{ 6,  53},
-		{ 9,  495},{ 6,  52},{ 6,  55},{ 9,  489},{ 9,  493},
-		{ 9,  487},{ 10,  1011},{ 9,  494},{ 10,  1005},{ 13,  8186},
-		{ 9,  492},{ 9,  498},{ 11,  2041},{ 11,  2040},{ 10,  1016},
-		{ 12,  4088},{ 4,  8},{ 6,  56},{ 10,  1014},{ 6,  54},
-		{ 7,  117},{ 10,  1009},{ 10,  1003},{ 10,  1004},{ 12,  4084},
-		{ 5,  24},{ 7,  118},{ 11,  2036},{ 6,  57},{ 7,  116},
-		{ 10,  1007},{ 9,  499},{ 9,  500},{ 11,  2038},{ 9,  488},
-		{ 10,  1002},{ 13,  8188},{ 8,  242},{ 9,  497},{ 12,  4091},
-		{ 10,  1013},{ 11,  2035},{ 12,  4092},{ 8,  238},{ 10,  1015},
-		{ 15,  32766},{ 9,  496},{ 11,  2037},{ 15,  32765},{ 13,  8187},
-		{ 14,  16378},{ 16,  65535},{ 8,  241},{ 10,  1008},{ 14,  16380},
-		{ 9,  490},{ 10,  1006},{ 14,  16379},{ 12,  4086},{ 12,  4090},
-		{ 15,  32764},{ 11,  2034},{ 12,  4085},{ 16,  65534},{ 10,  1012},
-		{ 11,  2039},{ 15,  32763},{ 12,  4087},{ 12,  4089},{ 15,  32762}
-	};
-int huff4[][2] = {
-		{ 4,  7},
-		{ 5,  22},{ 8,  246},{ 5,  24},{ 4,  8},{ 8,  239},
-		{ 9,  495},{ 8,  243},{ 11,  2040},{ 5,  25},{ 5,  23},
-		{ 8,  237},{ 5,  21},{ 4,  1},{ 8,  226},{ 8,  240},
-		{ 7,  112},{ 10,  1008},{ 9,  494},{ 8,  241},{ 11,  2042},
-		{ 8,  238},{ 8,  228},{ 10,  1010},{ 11,  2038},{ 10,  1007},
-		{ 11,  2045},{ 4,  5},{ 5,  20},{ 8,  242},{ 4,  9},
-		{ 4,  4},{ 8,  229},{ 8,  244},{ 8,  232},{ 10,  1012},
-		{ 4,  6},{ 4,  2},{ 8,  231},{ 4,  3},{ 4,  0},
-		{ 7,  107},{ 8,  227},{ 7,  105},{ 9,  499},{ 8,  235},
-		{ 8,  230},{ 10,  1014},{ 7,  110},{ 7,  106},{ 9,  500},
-		{ 10,  1004},{ 9,  496},{ 10,  1017},{ 8,  245},{ 8,  236},
-		{ 11,  2043},{ 8,  234},{ 7,  111},{ 10,  1015},{ 11,  2041},
-		{ 10,  1011},{ 12,  4095},{ 8,  233},{ 7,  109},{ 10,  1016},
-		{ 7,  108},{ 7,  104},{ 9,  501},{ 10,  1006},{ 9,  498},
-		{ 11,  2036},{ 11,  2039},{ 10,  1009},{ 12,  4094},{ 10,  1005},
-		{ 9,  497},{ 11,  2037},{ 11,  2046},{ 10,  1013},{ 11,  2044}
-	};
-int huff5[][2] = {
-		{ 13,  8191},
-		{ 12,  4087},{ 11,  2036},{ 11,  2024},{ 10,  1009},{ 11,  2030},
-		{ 11,  2041},{ 12,  4088},{ 13,  8189},{ 12,  4093},{ 11,  2033},
-		{ 10,  1000},{ 9,  488},{ 8,  240},{ 9,  492},{ 10,  1006},
-		{ 11,  2034},{ 12,  4090},{ 12,  4084},{ 10,  1007},{ 9,  498},
-		{ 8,  232},{ 7,  112},{ 8,  236},{ 9,  496},{ 10,  1002},
-		{ 11,  2035},{ 11,  2027},{ 9,  491},{ 8,  234},{ 5,  26},
-		{ 4,  8},{ 5,  25},{ 8,  238},{ 9,  495},{ 11,  2029},
-		{ 10,  1008},{ 8,  242},{ 7,  115},{ 4,  11},{ 1,  0},
-		{ 4,  10},{ 7,  113},{ 8,  243},{ 11,  2025},{ 11,  2031},
-		{ 9,  494},{ 8,  239},{ 5,  24},{ 4,  9},{ 5,  27},
-		{ 8,  235},{ 9,  489},{ 11,  2028},{ 11,  2038},{ 10,  1003},
-		{ 9,  499},{ 8,  237},{ 7,  114},{ 8,  233},{ 9,  497},
-		{ 10,  1005},{ 11,  2039},{ 12,  4086},{ 11,  2032},{ 10,  1001},
-		{ 9,  493},{ 8,  241},{ 9,  490},{ 10,  1004},{ 11,  2040},
-		{ 12,  4089},{ 13,  8188},{ 12,  4092},{ 12,  4085},{ 11,  2026},
-		{ 10,  1011},{ 10,  1010},{ 11,  2037},{ 12,  4091},{ 13,  8190}
-	};
-int huff6[][2] = {
-		{ 11,  2046},
-		{ 10,  1021},{ 9,  497},{ 9,  491},{ 9,  500},{ 9,  490},
-		{ 9,  496},{ 10,  1020},{ 11,  2045},{ 10,  1014},{ 9,  485},
-		{ 8,  234},{ 7,  108},{ 7,  113},{ 7,  104},{ 8,  240},
-		{ 9,  486},{ 10,  1015},{ 9,  499},{ 8,  239},{ 6,  50},
-		{ 6,  39},{ 6,  40},{ 6,  38},{ 6,  49},{ 8,  235},
-		{ 9,  503},{ 9,  488},{ 7,  111},{ 6,  46},{ 4,  8},
-		{ 4,  4},{ 4,  6},{ 6,  41},{ 7,  107},{ 9,  494},
-		{ 9,  495},{ 7,  114},{ 6,  45},{ 4,  2},{ 4,  0},
-		{ 4,  3},{ 6,  47},{ 7,  115},{ 9,  506},{ 9,  487},
-		{ 7,  110},{ 6,  43},{ 4,  7},{ 4,  1},{ 4,  5},
-		{ 6,  44},{ 7,  109},{ 9,  492},{ 9,  505},{ 8,  238},
-		{ 6,  48},{ 6,  36},{ 6,  42},{ 6,  37},{ 6,  51},
-		{ 8,  236},{ 9,  498},{ 10,  1016},{ 9,  484},{ 8,  237},
-		{ 7,  106},{ 7,  112},{ 7,  105},{ 7,  116},{ 8,  241},
-		{ 10,  1018},{ 11,  2047},{ 10,  1017},{ 9,  502},{ 9,  493},
-		{ 9,  504},{ 9,  489},{ 9,  501},{ 10,  1019},{ 11,  2044}
-	};
-int huff7[][2] = {
-		{ 1,  0},
-		{ 3,  5},{ 6,  55},{ 7,  116},{ 8,  242},{ 9,  491},
-		{ 10,  1005},{ 11,  2039},{ 3,  4},{ 4,  12},{ 6,  53},
-		{ 7,  113},{ 8,  236},{ 8,  238},{ 9,  494},{ 9,  501},
-		{ 6,  54},{ 6,  52},{ 7,  114},{ 8,  234},{ 8,  241},
-		{ 9,  489},{ 9,  499},{ 10,  1013},{ 7,  115},{ 7,  112},
-		{ 8,  235},{ 8,  240},{ 9,  497},{ 9,  496},{ 10,  1004},
-		{ 10,  1018},{ 8,  243},{ 8,  237},{ 9,  488},{ 9,  495},
-		{ 10,  1007},{ 10,  1009},{ 10,  1017},{ 11,  2043},{ 9,  493},
-		{ 8,  239},{ 9,  490},{ 9,  498},{ 10,  1011},{ 10,  1016},
-		{ 11,  2041},{ 11,  2044},{ 10,  1006},{ 9,  492},{ 9,  500},
-		{ 10,  1012},{ 10,  1015},{ 11,  2040},{ 12,  4093},{ 12,  4094},
-		{ 11,  2038},{ 10,  1008},{ 10,  1010},{ 10,  1014},{ 11,  2042},
-		{ 11,  2045},{ 12,  4092},{ 12,  4095}
-	};
-int huff8[][2] = {
-		{ 5,  14},
-		{ 4,  5},{ 5,  16},{ 6,  48},{ 7,  111},{ 8,  241},
-		{ 9,  506},{ 10,  1022},{ 4,  3},{ 3,  0},{ 4,  4},
-		{ 5,  18},{ 6,  44},{ 7,  106},{ 7,  117},{ 8,  248},
-		{ 5,  15},{ 4,  2},{ 4,  6},{ 5,  20},{ 6,  46},
-		{ 7,  105},{ 7,  114},{ 8,  245},{ 6,  47},{ 5,  17},
-		{ 5,  19},{ 6,  42},{ 6,  50},{ 7,  108},{ 8,  236},
-		{ 8,  250},{ 7,  113},{ 6,  43},{ 6,  45},{ 6,  49},
-		{ 7,  109},{ 7,  112},{ 8,  242},{ 9,  505},{ 8,  239},
-		{ 7,  104},{ 6,  51},{ 7,  107},{ 7,  110},{ 8,  238},
-		{ 8,  249},{ 10,  1020},{ 9,  504},{ 7,  116},{ 7,  115},
-		{ 8,  237},{ 8,  240},{ 8,  246},{ 9,  502},{ 9,  509},
-		{ 10,  1021},{ 8,  243},{ 8,  244},{ 8,  247},{ 9,  503},
-		{ 9,  507},{ 9,  508},{ 10,  1023}
-	};
-int huff9[][2] = {
-		{ 1,  0},
-		{ 3,  5},{ 6,  55},{ 8,  231},{ 9,  478},{ 10,  974},
-		{ 10,  985},{ 11,  1992},{ 11,  1997},{ 12,  4040},{ 12,  4061},
-		{ 13,  8164},{ 13,  8172},{ 3,  4},{ 4,  12},{ 6,  53},
-		{ 7,  114},{ 8,  234},{ 8,  237},{ 9,  482},{ 10,  977},
-		{ 10,  979},{ 10,  992},{ 11,  2008},{ 12,  4047},{ 12,  4053},
-		{ 6,  54},{ 6,  52},{ 7,  113},{ 8,  232},{ 8,  236},
-		{ 9,  481},{ 10,  975},{ 10,  989},{ 10,  987},{ 11,  2000},
-		{ 12,  4039},{ 12,  4052},{ 12,  4068},{ 8,  230},{ 7,  112},
-		{ 8,  233},{ 9,  477},{ 9,  483},{ 10,  978},{ 10,  988},
-		{ 11,  1996},{ 11,  1994},{ 11,  2014},{ 12,  4056},{ 12,  4074},
-		{ 13,  8155},{ 9,  479},{ 8,  235},{ 9,  476},{ 9,  486},
-		{ 10,  981},{ 10,  990},{ 11,  1995},{ 11,  2013},{ 11,  2012},
-		{ 12,  4045},{ 12,  4066},{ 12,  4071},{ 13,  8161},{ 10,  976},
-		{ 9,  480},{ 9,  484},{ 10,  982},{ 11,  1989},{ 11,  2001},
-		{ 11,  2011},{ 12,  4050},{ 11,  2016},{ 12,  4057},{ 12,  4075},
-		{ 13,  8163},{ 13,  8169},{ 11,  1988},{ 9,  485},{ 10,  983},
-		{ 11,  1990},{ 11,  1999},{ 11,  2010},{ 12,  4043},{ 12,  4058},
-		{ 12,  4067},{ 12,  4073},{ 13,  8166},{ 13,  8179},{ 13,  8183},
-		{ 11,  2003},{ 10,  984},{ 10,  993},{ 11,  2004},{ 11,  2009},
-		{ 12,  4051},{ 12,  4062},{ 13,  8157},{ 13,  8153},{ 13,  8162},
-		{ 13,  8170},{ 13,  8177},{ 13,  8182},{ 11,  2002},{ 10,  980},
-		{ 10,  986},{ 11,  1991},{ 11,  2007},{ 11,  2018},{ 12,  4046},
-		{ 12,  4059},{ 13,  8152},{ 13,  8174},{ 14,  16368},{ 13,  8180},
-		{ 14,  16370},{ 11,  2017},{ 10,  991},{ 11,  1993},{ 11,  2006},
-		{ 12,  4042},{ 12,  4048},{ 12,  4069},{ 12,  4070},{ 13,  8171},
-		{ 13,  8175},{ 14,  16371},{ 14,  16372},{ 14,  16373},{ 12,  4064},
-		{ 11,  1998},{ 11,  2005},{ 12,  4038},{ 12,  4049},{ 12,  4065},
-		{ 13,  8160},{ 13,  8168},{ 13,  8176},{ 14,  16369},{ 14,  16376},
-		{ 14,  16374},{ 15,  32764},{ 12,  4072},{ 11,  2015},{ 12,  4041},
-		{ 12,  4055},{ 12,  4060},{ 13,  8156},{ 13,  8159},{ 13,  8173},
-		{ 13,  8181},{ 14,  16377},{ 14,  16379},{ 15,  32765},{ 15,  32766},
-		{ 13,  8167},{ 12,  4044},{ 12,  4054},{ 12,  4063},{ 13,  8158},
-		{ 13,  8154},{ 13,  8165},{ 13,  8178},{ 14,  16378},{ 14,  16375},
-		{ 14,  16380},{ 14,  16381},{ 15,  32767}
-	};
-int huff10[][2] = {
-		{ 6,  34},
-		{ 5,  8},{ 6,  29},{ 6,  38},{ 7,  95},{ 8,  211},
-		{ 9,  463},{ 10,  976},{ 10,  983},{ 10,  1005},{ 11,  2032},
-		{ 11,  2038},{ 12,  4093},{ 5,  7},{ 4,  0},{ 4,  1},
-		{ 5,  9},{ 6,  32},{ 7,  84},{ 7,  96},{ 8,  213},
-		{ 8,  220},{ 9,  468},{ 10,  973},{ 10,  990},{ 11,  2023},
-		{ 6,  28},{ 4,  2},{ 5,  6},{ 5,  12},{ 6,  30},
-		{ 6,  40},{ 7,  91},{ 8,  205},{ 8,  217},{ 9,  462},
-		{ 9,  476},{ 10,  985},{ 10,  1009},{ 6,  37},{ 5,  11},
-		{ 5,  10},{ 5,  13},{ 6,  36},{ 7,  87},{ 7,  97},
-		{ 8,  204},{ 8,  221},{ 9,  460},{ 9,  478},{ 10,  979},
-		{ 10,  999},{ 7,  93},{ 6,  33},{ 6,  31},{ 6,  35},
-		{ 6,  39},{ 7,  89},{ 7,  100},{ 8,  216},{ 8,  223},
-		{ 9,  466},{ 9,  482},{ 10,  989},{ 10,  1006},{ 8,  209},
-		{ 7,  85},{ 6,  41},{ 7,  86},{ 7,  88},{ 7,  98},
-		{ 8,  206},{ 8,  224},{ 8,  226},{ 9,  474},{ 10,  980},
-		{ 10,  995},{ 11,  2027},{ 9,  457},{ 7,  94},{ 7,  90},
-		{ 7,  92},{ 7,  99},{ 8,  202},{ 8,  218},{ 9,  455},
-		{ 9,  458},{ 9,  480},{ 10,  987},{ 10,  1000},{ 11,  2028},
-		{ 9,  483},{ 8,  210},{ 8,  203},{ 8,  208},{ 8,  215},
-		{ 8,  219},{ 9,  454},{ 9,  469},{ 9,  472},{ 10,  970},
-		{ 10,  986},{ 11,  2026},{ 11,  2033},{ 9,  481},{ 8,  212},
-		{ 8,  207},{ 8,  214},{ 8,  222},{ 8,  225},{ 9,  464},
-		{ 9,  470},{ 10,  977},{ 10,  981},{ 10,  1010},{ 11,  2030},
-		{ 11,  2043},{ 10,  1001},{ 9,  461},{ 9,  456},{ 9,  459},
-		{ 9,  465},{ 9,  471},{ 9,  479},{ 10,  975},{ 10,  992},
-		{ 10,  1007},{ 11,  2022},{ 11,  2040},{ 12,  4090},{ 10,  1003},
-		{ 9,  477},{ 9,  467},{ 9,  473},{ 9,  475},{ 10,  978},
-		{ 10,  972},{ 10,  988},{ 10,  1002},{ 11,  2029},{ 11,  2035},
-		{ 11,  2041},{ 12,  4089},{ 11,  2034},{ 10,  974},{ 9,  484},
-		{ 10,  971},{ 10,  984},{ 10,  982},{ 10,  994},{ 10,  997},
-		{ 11,  2024},{ 11,  2036},{ 11,  2037},{ 11,  2039},{ 12,  4091},
-		{ 11,  2042},{ 10,  1004},{ 10,  991},{ 10,  993},{ 10,  996},
-		{ 10,  998},{ 10,  1008},{ 11,  2025},{ 11,  2031},{ 12,  4088},
-		{ 12,  4094},{ 12,  4092},{ 12,  4095}
-	};
-int huff11[][2] = {
-		{ 4,  0},
-		{ 5,  6},{ 6,  25},{ 7,  61},{ 8,  156},{ 8,  198},
-		{ 9,  423},{ 10,  912},{ 10,  962},{ 10,  991},{ 11,  2022},
-		{ 11,  2035},{ 12,  4091},{ 11,  2028},{ 12,  4090},{ 12,  4094},
-		{ 10,  910},{ 5,  5},{ 4,  1},{ 5,  8},{ 6,  20},
-		{ 7,  55},{ 7,  66},{ 8,  146},{ 8,  175},{ 9,  401},
-		{ 9,  421},{ 9,  437},{ 10,  926},{ 10,  960},{ 10,  930},
-		{ 10,  973},{ 11,  2006},{ 8,  174},{ 6,  23},{ 5,  7},
-		{ 5,  9},{ 6,  24},{ 7,  57},{ 7,  64},{ 8,  142},
-		{ 8,  163},{ 8,  184},{ 9,  409},{ 9,  428},{ 9,  449},
-		{ 10,  945},{ 10,  918},{ 10,  958},{ 10,  970},{ 8,  157},
-		{ 7,  60},{ 6,  21},{ 6,  22},{ 6,  26},{ 7,  59},
-		{ 7,  68},{ 8,  145},{ 8,  165},{ 8,  190},{ 9,  406},
-		{ 9,  430},{ 9,  441},{ 10,  929},{ 10,  913},{ 10,  933},
-		{ 10,  981},{ 8,  148},{ 8,  154},{ 7,  54},{ 7,  56},
-		{ 7,  58},{ 7,  65},{ 8,  140},{ 8,  155},{ 8,  176},
-		{ 8,  195},{ 9,  414},{ 9,  427},{ 9,  444},{ 10,  927},
-		{ 10,  911},{ 10,  937},{ 10,  975},{ 8,  147},{ 8,  191},
-		{ 7,  62},{ 7,  63},{ 7,  67},{ 7,  69},{ 8,  158},
-		{ 8,  167},{ 8,  185},{ 9,  404},{ 9,  418},{ 9,  442},
-		{ 9,  451},{ 10,  934},{ 10,  935},{ 10,  955},{ 10,  980},
-		{ 8,  159},{ 9,  416},{ 8,  143},{ 8,  141},{ 8,  144},
-		{ 8,  152},{ 8,  166},{ 8,  182},{ 8,  196},{ 9,  415},
-		{ 9,  431},{ 9,  447},{ 10,  921},{ 10,  959},{ 10,  948},
-		{ 10,  969},{ 10,  999},{ 8,  168},{ 9,  438},{ 8,  171},
-		{ 8,  164},{ 8,  170},{ 8,  178},{ 8,  194},{ 8,  197},
-		{ 9,  408},{ 9,  420},{ 9,  440},{ 10,  908},{ 10,  932},
-		{ 10,  964},{ 10,  966},{ 10,  989},{ 10,  1000},{ 8,  173},
-		{ 10,  943},{ 9,  402},{ 8,  189},{ 8,  188},{ 9,  398},
-		{ 9,  407},{ 9,  410},{ 9,  419},{ 9,  433},{ 10,  909},
-		{ 10,  920},{ 10,  951},{ 10,  979},{ 10,  977},{ 10,  987},
-		{ 11,  2013},{ 8,  180},{ 10,  990},{ 9,  425},{ 9,  411},
-		{ 9,  412},{ 9,  417},{ 9,  426},{ 9,  429},{ 9,  435},
-		{ 10,  907},{ 10,  946},{ 10,  952},{ 10,  974},{ 10,  993},
-		{ 10,  992},{ 11,  2002},{ 11,  2021},{ 8,  183},{ 11,  2019},
-		{ 9,  443},{ 9,  424},{ 9,  422},{ 9,  432},{ 9,  434},
-		{ 9,  439},{ 10,  923},{ 10,  922},{ 10,  954},{ 10,  949},
-		{ 10,  982},{ 11,  2007},{ 10,  996},{ 11,  2008},{ 11,  2026},
-		{ 8,  186},{ 11,  2024},{ 10,  928},{ 9,  445},{ 9,  436},
-		{ 10,  906},{ 9,  452},{ 10,  914},{ 10,  938},{ 10,  944},
-		{ 10,  956},{ 10,  983},{ 11,  2004},{ 11,  2012},{ 11,  2011},
-		{ 11,  2005},{ 11,  2032},{ 8,  193},{ 11,  2043},{ 10,  968},
-		{ 10,  931},{ 10,  917},{ 10,  925},{ 10,  940},{ 10,  942},
-		{ 10,  965},{ 10,  984},{ 10,  994},{ 10,  998},{ 11,  2020},
-		{ 11,  2023},{ 11,  2016},{ 11,  2025},{ 11,  2039},{ 9,  400},
-		{ 11,  2034},{ 10,  915},{ 9,  446},{ 9,  448},{ 10,  916},
-		{ 10,  919},{ 10,  941},{ 10,  963},{ 10,  961},{ 10,  978},
-		{ 11,  2010},{ 11,  2009},{ 11,  2015},{ 11,  2027},{ 11,  2036},
-		{ 11,  2042},{ 9,  405},{ 11,  2040},{ 10,  957},{ 10,  924},
-		{ 10,  939},{ 10,  936},{ 10,  947},{ 10,  953},{ 10,  976},
-		{ 10,  995},{ 10,  997},{ 11,  2018},{ 11,  2014},{ 11,  2029},
-		{ 11,  2033},{ 11,  2041},{ 11,  2044},{ 9,  403},{ 12,  4093},
-		{ 10,  988},{ 10,  950},{ 10,  967},{ 10,  972},{ 10,  971},
-		{ 10,  985},{ 10,  986},{ 11,  2003},{ 11,  2017},{ 11,  2030},
-		{ 11,  2031},{ 11,  2037},{ 11,  2038},{ 12,  4092},{ 12,  4095},
-		{ 9,  413},{ 9,  450},{ 8,  181},{ 8,  161},{ 8,  150},
-		{ 8,  151},{ 8,  149},{ 8,  153},{ 8,  160},{ 8,  162},
-		{ 8,  172},{ 8,  169},{ 8,  177},{ 8,  179},{ 8,  187},
-		{ 8,  192},{ 9,  399},{ 5,  4}
-	};
-int huff12[][2] = {
-		{ 18,  262120},
-		{ 18,  262118},{ 18,  262119},{ 18,  262117},{ 19,  524277},{ 19,  524273},
-		{ 19,  524269},{ 19,  524278},{ 19,  524270},{ 19,  524271},{ 19,  524272},
-		{ 19,  524284},{ 19,  524285},{ 19,  524287},{ 19,  524286},{ 19,  524279},
-		{ 19,  524280},{ 19,  524283},{ 19,  524281},{ 18,  262116},{ 19,  524282},
-		{ 18,  262115},{ 17,  131055},{ 17,  131056},{ 16,  65525},{ 17,  131054},
-		{ 16,  65522},{ 16,  65523},{ 16,  65524},{ 16,  65521},{ 15,  32758},
-		{ 15,  32759},{ 14,  16377},{ 14,  16373},{ 14,  16375},{ 14,  16371},
-		{ 14,  16374},{ 14,  16370},{ 13,  8183},{ 13,  8181},{ 12,  4089},
-		{ 12,  4087},{ 12,  4086},{ 11,  2041},{ 12,  4084},{ 11,  2040},
-		{ 10,  1017},{ 10,  1015},{ 10,  1013},{ 9,  504},{ 9,  503},
-		{ 8,  250},{ 8,  248},{ 8,  246},{ 7,  121},{ 6,  58},
-		{ 6,  56},{ 5,  26},{ 4,  11},{ 3,  4},{ 1,  0},
-		{ 4,  10},{ 4,  12},{ 5,  27},{ 6,  57},{ 6,  59},
-		{ 7,  120},{ 7,  122},{ 8,  247},{ 8,  249},{ 9,  502},
-		{ 9,  505},{ 10,  1012},{ 10,  1014},{ 10,  1016},{ 11,  2037},
-		{ 11,  2036},{ 11,  2038},{ 11,  2039},{ 12,  4085},{ 12,  4088},
-		{ 13,  8180},{ 13,  8182},{ 13,  8184},{ 14,  16376},{ 14,  16372},
-		{ 16,  65520},{ 15,  32756},{ 16,  65526},{ 15,  32757},{ 18,  262114},
-		{ 19,  524249},{ 19,  524250},{ 19,  524251},{ 19,  524252},{ 19,  524253},
-		{ 19,  524254},{ 19,  524248},{ 19,  524242},{ 19,  524243},{ 19,  524244},
-		{ 19,  524245},{ 19,  524246},{ 19,  524274},{ 19,  524255},{ 19,  524263},
-		{ 19,  524264},{ 19,  524265},{ 19,  524266},{ 19,  524267},{ 19,  524262},
-		{ 19,  524256},{ 19,  524257},{ 19,  524258},{ 19,  524259},{ 19,  524260},
-		{ 19,  524261},{ 19,  524247},{ 19,  524268},{ 19,  524276},{ 19,  524275}
-	};
-
-
--- /dev/null
+++ b/include/faac.h
@@ -1,0 +1,83 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: faac.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef FAACLIB_H
+#define FAACLIB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifdef WIN32
+  #pragma pack(push, 8)
+  #ifndef FAACAPI
+    #define FAACAPI __stdcall
+  #endif
+#else
+  #ifndef FAACAPI
+    #define FAACAPI
+  #endif
+#endif
+
+#define FAACENC_VERSION 1.0
+#define FAACENC_VERSIONB 1 /* If 1 this version is still in beta */
+
+typedef struct faacEncConfiguration
+{
+
+	/* Allow mid/side coding */
+	unsigned int allowMidside;
+	/* Use one of the channels as LFE channel */
+	unsigned int useLfe;
+
+	/* bitrate / channel of AAC file */
+	unsigned long bitRate;
+
+} faacEncConfiguration, *faacEncConfigurationPtr;
+
+typedef void *faacEncHandle;
+
+
+faacEncConfigurationPtr FAACAPI faacEncGetCurrentConfiguration(faacEncHandle hEncoder);
+int FAACAPI faacEncSetConfiguration (faacEncHandle hEncoder, faacEncConfigurationPtr config);
+
+faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
+								  unsigned int numChannels);
+
+int FAACAPI faacEncEncode(faacEncHandle hEncoder,
+						  short *inputBuffer,
+						  unsigned int samplesInput,
+						  void *outputBuffer,
+						  unsigned int bufferSize
+						  );
+
+int FAACAPI faacEncClose(faacEncHandle hEncoder);
+
+
+#ifdef WIN32
+  #pragma pack(pop)
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* FAACLIB_H */
\ No newline at end of file
--- a/interface.h
+++ /dev/null
@@ -1,193 +1,0 @@
-/*
- *	Definitions of Bitstream elements
- *
- *	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/31 14:48:41 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _interface_h_
-#define _interface_h_
-
-
-/* AAC Profile */
-enum AAC_PROFILE { MAIN, LOW, SSR };
-
-#define MAX_SAMPLING_RATES 12
-
-enum WINDOW_TYPE { 
-  ONLY_LONG_WINDOW, 
-  LONG_SHORT_WINDOW, 
-  ONLY_SHORT_WINDOW,
-  SHORT_LONG_WINDOW,
-};    
-
-#define NSFB_LONG  51
-#define NSFB_SHORT 15
-
-#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 6
-
-/* max. number of scale factor bands */
-#define MAX_SCFAC_BANDS ((NSFB_SHORT+1)*MAX_SHORT_WINDOWS)
-
-#define BLOCK_LEN_LONG	   1024
-#define BLOCK_LEN_SHORT    128
-
-
-typedef enum {
-    WS_SIN, WS_KBD, N_WINDOW_SHAPES
-} Window_shape;
-
-typedef enum {
-	MOVERLAPPED,
-	MNON_OVERLAPPED
-} Mdct_in,Imdct_out;
-
-
-
-/* 
- * 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 { 
-  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];
-  int    cb_width_short[NSFB_SHORT];
-} SR_INFO;
-
-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_ */
-
--- /dev/null
+++ b/libfaac/aacquant.c
@@ -1,0 +1,702 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: aacquant.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#include <math.h>
+#include <stdlib.h>
+#include <memory.h>
+
+#include "aacquant.h"
+#include "coder.h"
+#include "huffman.h"
+#include "psych.h"
+
+
+
+#define XRPOW_FTOI(src,dest) ((dest) = (int)(src))
+#define QUANTFAC(rx)  adj43[rx]
+#define ROUNDFAC 0.4054
+
+
+double *pow43;
+double *adj43;
+double *adj43asm;
+
+
+void AACQuantizeInit(CoderInfo *coderInfo, unsigned int numChannels)
+{
+	unsigned int channel, i;
+
+	pow43 = (double*)malloc(PRECALC_SIZE*sizeof(double));
+	adj43 = (double*)malloc(PRECALC_SIZE*sizeof(double));
+	adj43asm = (double*)malloc(PRECALC_SIZE*sizeof(double));
+
+	pow43[0] = 0.0;
+	for(i=1;i<PRECALC_SIZE;i++)
+		pow43[i] = pow((double)i, 4.0/3.0);
+
+	adj43asm[0] = 0.0;
+	for (i = 1; i < PRECALC_SIZE; i++)
+		adj43asm[i] = i - 0.5 - pow(0.5 * (pow43[i - 1] + pow43[i]),0.75);
+	for (i = 0; i < PRECALC_SIZE-1; i++)
+		adj43[i] = (i + 1) - pow(0.5 * (pow43[i] + pow43[i + 1]), 0.75);
+	adj43[i] = 0.5;
+
+	for (channel = 0; channel < numChannels; channel++) {
+		coderInfo[channel].old_value = 0;
+		coderInfo[channel].CurrentStep = 4;
+	}
+}
+
+void AACQuantizeEnd()
+{
+	if (pow43) free(pow43);
+	if (adj43) free(adj43);
+	if (adj43asm) free(adj43asm);
+}
+
+int AACQuantize(CoderInfo *coderInfo,
+				PsyInfo *psyInfo,
+				ChannelInfo *channelInfo,
+				int *cb_width,
+				int num_cb,
+				double *xr,
+				int desired_rate)
+{
+	int sb, i, do_q = 0;
+	int bits, sign;
+	double *xr_pow, *xmin;
+	int *xi;
+
+	/* Use local copy's */
+	int *scale_factor = coderInfo->scale_factor;
+
+
+	xr_pow = (double*)malloc(FRAME_LEN*sizeof(double));
+	xmin = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+	xi = (int*)malloc(FRAME_LEN*sizeof(int));
+
+
+	if (coderInfo->block_type == ONLY_SHORT_WINDOW) {
+		SortForGrouping(coderInfo, psyInfo, channelInfo, cb_width, xr);
+	} else {
+		for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
+			if (channelInfo->msInfo.is_present && channelInfo->msInfo.ms_used[sb]) {
+				psyInfo->maskThr[sb] = psyInfo->maskThrMS[sb];
+				psyInfo->maskEn[sb] = psyInfo->maskEnMS[sb];
+			}
+		}
+	}
+
+
+	/* Set all scalefactors to 0 */
+	coderInfo->global_gain = 0;
+	for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
+		scale_factor[sb] = 0;
+
+	/* Compute xr_pow */
+	for (i = 0; i < FRAME_LEN; i++) {
+        double temp = fabs(xr[i]);
+        xr_pow[i] = sqrt(temp * sqrt(temp));
+        do_q += (temp > 1E-20);
+    }
+
+	if (do_q) {
+		bits = SearchStepSize(coderInfo, desired_rate, xr_pow, xi);
+		coderInfo->old_value = coderInfo->global_gain;
+
+		CalcAllowedDist(psyInfo, cb_width, num_cb, xr, xmin);
+		OuterLoop(coderInfo, xr, xr_pow, xi, xmin, desired_rate);
+
+		for ( i = 0; i < FRAME_LEN; i++ )  {
+			sign = (xr[i] < 0) ? -1 : 1;
+			xi[i] *= sign;
+		}
+	} else {
+		coderInfo->global_gain = 0;
+		memset(xi, 0, FRAME_LEN*sizeof(int));
+	}
+
+	CountBitsLong(coderInfo, xi);
+
+	/* offset the difference of common_scalefac and scalefactors by SF_OFFSET  */
+	for (i = 0; i < coderInfo->nr_of_sfb; i++) {
+		if ((coderInfo->book_vector[i]!=INTENSITY_HCB)&&(coderInfo->book_vector[i]!=INTENSITY_HCB2)) {
+			scale_factor[i] = coderInfo->global_gain - scale_factor[i] + SF_OFFSET;
+		}
+	}
+	coderInfo->global_gain = scale_factor[0];
+
+	/* place the codewords and their respective lengths in arrays data[] and len[] respectively */
+	/* there are 'counter' elements in each array, and these are variable length arrays depending on the input */
+	coderInfo->spectral_count = 0;
+	for(i = 0; i < coderInfo->nr_of_sfb; i++) {
+		OutputBits(
+			coderInfo,
+			coderInfo->book_vector[i],
+			xi,
+			coderInfo->sfb_offset[i],
+			coderInfo->sfb_offset[i+1]-coderInfo->sfb_offset[i],
+			1);
+	}
+
+
+	if (xmin) free(xmin);
+	if (xr_pow) free(xr_pow);
+	if (xi) free(xi);
+
+	return bits;
+}
+
+static int SearchStepSize(CoderInfo *coderInfo,
+						  const int desired_rate,
+						  const double *xr,
+						  int *xi)
+{
+	int flag_GoneOver = 0;
+	int CurrentStep = coderInfo->CurrentStep;
+	int nBits;
+	int StepSize = coderInfo->old_value;
+	int Direction = 0;
+
+	do
+	{
+		coderInfo->global_gain = StepSize;
+		nBits = CountBits(coderInfo, xi, xr);
+
+		if (CurrentStep == 1 ) {
+			break; /* nothing to adjust anymore */
+		}
+		if (flag_GoneOver) {
+			CurrentStep /= 2;
+		}
+		if (nBits > desired_rate) { /* increase Quantize_StepSize */
+			if (Direction == -1 && !flag_GoneOver) {
+				flag_GoneOver = 1;
+				CurrentStep /= 2; /* late adjust */
+			}
+			Direction = 1;
+			StepSize += CurrentStep;
+		} else if (nBits < desired_rate) {
+			if (Direction == 1 && !flag_GoneOver) {
+				flag_GoneOver = 1;
+				CurrentStep /= 2; /* late adjust */
+			}
+			Direction = -1;
+			StepSize -= CurrentStep;
+		} else break;
+	} while (1);
+
+	CurrentStep = coderInfo->old_value - StepSize;
+
+	coderInfo->CurrentStep = CurrentStep/4 != 0 ? 4 : 2;
+	coderInfo->old_value = coderInfo->global_gain;
+
+	return nBits;
+}
+
+#if 1 // TAKEHIRO_IEEE754_HACK
+
+#pragma warning( disable : 4244 4307 )
+
+typedef union {
+    float f;
+    int i;
+} fi_union;
+
+#define MAGIC_FLOAT (65536*(128))
+#define MAGIC_INT 0x4b000000
+
+static void Quantize(const double *xp, int *pi, double istep)
+{
+	int j;
+	fi_union *fi;
+
+	fi = (fi_union *)pi;
+	for (j = FRAME_LEN/4 - 1; j >= 0; --j) {
+		double x0 = istep * xp[0];
+		double x1 = istep * xp[1];
+		double x2 = istep * xp[2];
+		double x3 = istep * xp[3];
+
+		x0 += MAGIC_FLOAT; fi[0].f = x0;
+		x1 += MAGIC_FLOAT; fi[1].f = x1;
+		x2 += MAGIC_FLOAT; fi[2].f = x2;
+		x3 += MAGIC_FLOAT; fi[3].f = x3;
+
+		fi[0].f = x0 + (adj43asm - MAGIC_INT)[fi[0].i];
+		fi[1].f = x1 + (adj43asm - MAGIC_INT)[fi[1].i];
+		fi[2].f = x2 + (adj43asm - MAGIC_INT)[fi[2].i];
+		fi[3].f = x3 + (adj43asm - MAGIC_INT)[fi[3].i];
+
+		fi[0].i -= MAGIC_INT;
+		fi[1].i -= MAGIC_INT;
+		fi[2].i -= MAGIC_INT;
+		fi[3].i -= MAGIC_INT;
+		fi += 4;
+		xp += 4;
+	}
+}
+#else
+static void Quantize(const double *xr, int *ix, double istep)
+{
+	int j;
+
+    for (j = FRAME_LEN/8; j > 0; --j) {
+		double x1, x2, x3, x4, x5, x6, x7, x8;
+		int rx1, rx2, rx3, rx4, rx5, rx6, rx7, rx8;
+
+		x1 = *xr++ * istep;
+		x2 = *xr++ * istep;
+		XRPOW_FTOI(x1, rx1);
+		x3 = *xr++ * istep;
+		XRPOW_FTOI(x2, rx2);
+		x4 = *xr++ * istep;
+		XRPOW_FTOI(x3, rx3);
+		x5 = *xr++ * istep;
+		XRPOW_FTOI(x4, rx4);
+		x6 = *xr++ * istep;
+		XRPOW_FTOI(x5, rx5);
+		x7 = *xr++ * istep;
+		XRPOW_FTOI(x6, rx6);
+		x8 = *xr++ * istep;
+		XRPOW_FTOI(x7, rx7);
+		x1 += QUANTFAC(rx1);
+		XRPOW_FTOI(x8, rx8);
+		x2 += QUANTFAC(rx2);
+		XRPOW_FTOI(x1,*ix++);
+		x3 += QUANTFAC(rx3);
+		XRPOW_FTOI(x2,*ix++);
+		x4 += QUANTFAC(rx4);
+		XRPOW_FTOI(x3,*ix++);
+		x5 += QUANTFAC(rx5);
+		XRPOW_FTOI(x4,*ix++);
+		x6 += QUANTFAC(rx6);
+		XRPOW_FTOI(x5,*ix++);
+		x7 += QUANTFAC(rx7);
+		XRPOW_FTOI(x6,*ix++);
+		x8 += QUANTFAC(rx8);
+		XRPOW_FTOI(x7,*ix++);
+		XRPOW_FTOI(x8,*ix++);
+    }
+}
+#endif
+
+static int CountBitsLong(CoderInfo *coderInfo, int *xi)
+{
+	int i, bits = 0;
+
+	/* find a good method to section the scalefactor bands into huffman codebook sections */
+	BitSearch(coderInfo, xi);
+
+	/* calculate the amount of bits needed for encoding the huffman codebook numbers */
+	bits += SortBookNumbers(coderInfo, NULL, 0);
+
+	/* calculate the amount of bits needed for the spectral values */
+	coderInfo->spectral_count = 0;
+	for(i = 0; i < coderInfo->nr_of_sfb; i++) {  
+		bits += OutputBits(coderInfo,
+			coderInfo->book_vector[i],
+			xi,
+			coderInfo->sfb_offset[i], 
+			coderInfo->sfb_offset[i+1] - coderInfo->sfb_offset[i],
+			0);
+	}
+
+	/* the number of bits for the scalefactors */
+	bits += WriteScalefactors(coderInfo, NULL, 0);
+
+	/* the total amount of bits required */
+	return bits;
+}
+
+static int CountBits(CoderInfo *coderInfo, int *ix, const double *xr)
+{
+	int bits = 0, i;
+
+	/* since quantize uses table lookup, we need to check this first: */
+	double w = (IXMAX_VAL) / IPOW20(coderInfo->global_gain);
+	for ( i = 0; i < FRAME_LEN; i++ )  {
+		if (xr[i] > w)
+			return LARGE_BITS;
+	}
+
+	Quantize(xr, ix, IPOW20(coderInfo->global_gain));
+
+	bits = CountBitsLong(coderInfo, ix);
+
+	return bits;
+}
+
+static int InnerLoop(CoderInfo *coderInfo,
+					 double *xr_pow,
+					 int *xi,
+					 int max_bits)
+{
+	int bits;
+
+	/*  count bits */
+	bits = CountBits(coderInfo, xi, xr_pow);
+
+	/*  increase quantizer stepsize until needed bits are below maximum */
+	while (bits > max_bits) {
+		coderInfo->global_gain += 1;
+		bits = CountBits(coderInfo, xi, xr_pow);
+	}
+
+	return bits;
+}
+
+static void CalcAllowedDist(PsyInfo *psyInfo, int *cb_width, int num_cb,
+							double *xr, double *xmin)
+{
+	int sfb, start, end, i;
+	double en0, xmin0;
+
+	end = 0;
+	for (sfb = 0; sfb < num_cb; sfb++)
+	{
+		start = end;
+		end += cb_width[sfb];
+
+		for (en0 = 0.0, i = start; i < end; i++)
+		{
+			en0 += xr[i] * xr[i];
+		}
+		en0 /= cb_width[sfb];
+
+		xmin0 = psyInfo->maskEn[sfb];
+		if (xmin0 > 0.0)
+			xmin0 = en0 * psyInfo->maskThr[sfb] / xmin0;
+		xmin[sfb] = xmin0;
+	}
+}
+
+static int OuterLoop(CoderInfo *coderInfo,
+					 double *xr,
+					 double *xr_pow,
+					 int *xi,
+					 double *xmin,
+					 int target_bits)
+{
+	int sb, i;
+	int notdone, over, better;
+	int store_global_gain, outer_loop_count;
+	int best_global_gain, age;
+
+    calcNoiseResult noiseInfo;
+    calcNoiseResult bestNoiseInfo;
+
+	double sfQuantFac = pow(2.0, 0.1875);
+	int *scale_factor = coderInfo->scale_factor;
+
+	int *best_scale_factor;
+	double *requant_xr;
+	int *save_xi;
+	double *distort;
+
+	distort = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+	best_scale_factor = (int*)malloc(MAX_SCFAC_BANDS*sizeof(int));
+
+	requant_xr = (double*)malloc(FRAME_LEN*sizeof(double));
+	save_xi = (int*)malloc(FRAME_LEN*sizeof(int));
+
+	notdone = 1;
+	outer_loop_count = 0;
+
+	do { /* outer iteration loop */
+
+		over = 0;
+		outer_loop_count++;
+
+		InnerLoop(coderInfo, xr_pow, xi, target_bits);
+
+		store_global_gain = coderInfo->global_gain;
+
+		over = CalcNoise(coderInfo, xr, xi, requant_xr, distort, xmin, &noiseInfo);
+
+		if (outer_loop_count == 1)
+			better = 1;
+		else
+			better = QuantCompare(&bestNoiseInfo, &noiseInfo);
+
+		if (better) {
+			bestNoiseInfo = noiseInfo;
+			best_global_gain = store_global_gain;
+
+			for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
+				best_scale_factor[sb] = scale_factor[sb];
+			}
+			memcpy(save_xi, xi, sizeof(int)*BLOCK_LEN_LONG);
+			age = 0;
+		} else
+			age++;
+
+        if (age > 3 && bestNoiseInfo.over_count == 0) 
+            break;
+
+        notdone = BalanceNoise(coderInfo, distort, xr_pow);
+
+		for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
+			if (scale_factor[sb] > 30)
+				notdone = 0;
+
+		if (notdone == 0) 
+            break;
+
+	} while (1);
+
+	coderInfo->global_gain = best_global_gain;
+	for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
+		scale_factor[sb] = best_scale_factor[sb];
+	}
+	for (i = 0; i < 1024; i++)
+		xi[i] = save_xi[i];
+
+
+	if (requant_xr) free(requant_xr);
+	if (best_scale_factor) free(best_scale_factor);
+	if (save_xi) free(save_xi);
+	if (distort) free(distort);
+
+	return 0;
+}
+
+static int CalcNoise(CoderInfo *coderInfo,
+					 double *xr,
+					 int *xi,
+					 double *requant_xr,
+					 double *error_energy,
+					 double *xmin,
+					 calcNoiseResult *res
+					 )
+{
+	int i, sb, sbw;
+	int over = 0, count = 0;
+	double invQuantFac;
+	double linediff, noise;
+
+	double over_noise = 1;
+	double tot_noise = 1;
+	double max_noise = 1E-20;
+
+	for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
+
+		sbw = coderInfo->sfb_offset[sb+1] - coderInfo->sfb_offset[sb];
+
+		invQuantFac = pow(2.0, -0.25*(coderInfo->scale_factor[sb] - coderInfo->global_gain));
+
+		error_energy[sb] = 0.0;
+
+		for (i = coderInfo->sfb_offset[sb]; i < coderInfo->sfb_offset[sb+1]; i++){
+			requant_xr[i] =  pow43[min(ABS(xi[i]),8999)] * invQuantFac; 
+
+			/* measure the distortion in each scalefactor band */
+			linediff = (double)(ABS(xr[i]) - ABS(requant_xr[i]));
+			linediff *= linediff;
+			error_energy[sb] += linediff;
+		}
+		error_energy[sb] = error_energy[sb] / sbw;		
+		
+		noise = error_energy[sb] / xmin[sb];
+
+		/* multiplying here is adding in dB */
+		tot_noise *= max(noise, 1E-20);
+		if (noise>1) {
+			over++;
+			/* multiplying here is adding in dB */
+			over_noise *= noise;
+		}
+		max_noise = max(max_noise,noise);
+		error_energy[sb] = noise;
+		count++;
+  	}
+
+	res->tot_count  = count;
+	res->over_count = over;
+	res->tot_noise   = 10.*log10(max(1e-20,tot_noise )); 
+	res->over_noise  = 10.*log10(max(1e+00,over_noise)); 
+	res->max_noise   = 10.*log10(max(1e-20,max_noise ));
+
+	return over;
+}
+
+
+static int QuantCompare(calcNoiseResult *best,
+						calcNoiseResult *calc)
+{
+	int better;
+
+	better = calc->over_count  < best->over_count
+		||  ( calc->over_count == best->over_count  &&
+		calc->over_noise  < best->over_noise )
+		||  ( calc->over_count == best->over_count  &&
+		calc->over_noise == best->over_noise  &&
+		calc->tot_noise   < best->tot_noise  ); 
+
+	return better;
+}
+
+static int BalanceNoise(CoderInfo *coderInfo,
+						double *distort,
+						double *xrpow)
+{
+	int status = 0, sb;
+
+	AmpScalefacBands(coderInfo, distort, xrpow);
+
+	for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
+		if (coderInfo->scale_factor[sb] == 0)
+			status = 1;
+
+	return status;
+}
+
+static void AmpScalefacBands(CoderInfo *coderInfo,
+							 double *distort,
+							 double *xr_pow)
+{
+	int start, end, l, sfb;
+	double ifqstep, distort_thresh;
+
+	ifqstep = pow(2.0, 0.1875);
+
+	distort_thresh = -900;
+	for (sfb = 0; sfb < coderInfo->nr_of_sfb; sfb++) {
+		distort_thresh = max(distort[sfb], distort_thresh);
+	}
+
+	if (distort_thresh>1.0)
+		distort_thresh=1.0;
+	else
+		distort_thresh *= .95;
+
+    for ( sfb = 0; sfb < coderInfo->nr_of_sfb; sfb++ ) {
+		if (distort[sfb] > distort_thresh) {
+			coderInfo->scale_factor[sfb]++;
+			start = coderInfo->sfb_offset[sfb];
+			end   = coderInfo->sfb_offset[sfb+1];
+			for ( l = start; l < end; l++ ) {
+				xr_pow[l] *= ifqstep;
+			}
+		}
+    }
+}
+
+
+static int SortForGrouping(CoderInfo* coderInfo,
+						   PsyInfo *psyInfo,
+						   ChannelInfo *channelInfo,
+						   int *sfb_width_table,
+						   double *xr)
+{
+	int i,j,ii;
+	int index = 0;
+	double xr_tmp[1024];
+	double thr_tmp[150];
+	double en_tmp[150];
+	int book=1;
+	int group_offset=0;
+	int k=0;
+	int windowOffset = 0;
+
+
+	/* set up local variables for used quantInfo elements */
+	int* sfb_offset = coderInfo->sfb_offset;
+	int* nr_of_sfb = &(coderInfo->nr_of_sfb);
+	int* window_group_length;
+	int num_window_groups;
+	*nr_of_sfb = coderInfo->max_sfb;              /* Init to max_sfb */
+	window_group_length = coderInfo->window_group_length;
+	num_window_groups = coderInfo->num_window_groups;
+
+	/* calc org sfb_offset just for shortblock */
+	sfb_offset[k]=0;
+	for (k=1 ; k <*nr_of_sfb+1; k++) {
+		sfb_offset[k] = sfb_offset[k-1] + sfb_width_table[k-1];
+	}
+
+	/* sort the input spectral coefficients */
+	index = 0;
+	group_offset=0;
+	for (i=0; i< num_window_groups; i++) {
+		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++)
+					xr_tmp[index++] = xr[ii+ sfb_offset[k] + 128*j +group_offset];
+			}
+		}
+		group_offset +=  128*window_group_length[i];     
+	}
+
+	for (k=0; k<1024; k++){
+		xr[k] = xr_tmp[k];
+	}
+
+
+	/* now calc the new sfb_offset table for the whole p_spectrum vector*/
+	index = 0;
+	sfb_offset[index++] = 0;
+	windowOffset = 0;
+	for (i=0; i < num_window_groups; i++) {
+		for (k=0 ; k <*nr_of_sfb; k++) {
+			int w;
+			double worstTHR;
+			double worstEN;
+
+			/* for this window group and this band, find worst case inverse sig-mask-ratio */
+			if (channelInfo->msInfo.is_present && channelInfo->msInfo.ms_usedS[windowOffset][k]) {
+				worstTHR = psyInfo->maskThrSMS[windowOffset][k];
+				worstEN = psyInfo->maskEnSMS[windowOffset][k];
+			} else {
+				worstTHR = psyInfo->maskThrS[windowOffset][k];
+				worstEN = psyInfo->maskEnS[windowOffset][k];
+			}
+
+			for (w=1;w<window_group_length[i];w++) {
+				if (channelInfo->msInfo.is_present && channelInfo->msInfo.ms_usedS[w+windowOffset][k]) {
+					if (psyInfo->maskThrSMS[w+windowOffset][k] < worstTHR) {
+						worstTHR = psyInfo->maskThrSMS[w+windowOffset][k];
+						worstEN = psyInfo->maskEnSMS[w+windowOffset][k];
+					}
+				} else {
+					if (psyInfo->maskThrS[w+windowOffset][k] < worstTHR) {
+						worstTHR = psyInfo->maskThrS[w+windowOffset][k];
+						worstEN = psyInfo->maskEnS[w+windowOffset][k];
+					}
+				}
+			}
+			thr_tmp[k+ i* *nr_of_sfb] = worstTHR;
+			en_tmp[k+ i* *nr_of_sfb] = worstEN;
+			sfb_offset[index] = sfb_offset[index-1] + sfb_width_table[k]*window_group_length[i] ;
+			index++;
+		}
+		windowOffset += window_group_length[i];
+	}
+
+	*nr_of_sfb = *nr_of_sfb * num_window_groups;  /* Number interleaved bands. */
+
+	for (k = 0; k < *nr_of_sfb; k++){
+		psyInfo->maskThr[k] = thr_tmp[k];
+		psyInfo->maskEn[k] = en_tmp[k];
+	}
+
+	return 0;
+}
--- /dev/null
+++ b/libfaac/aacquant.h
@@ -1,0 +1,97 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: aacquant.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef AACQUANT_H
+#define AACQUANT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "coder.h"
+#include "psych.h"
+
+#define IXMAX_VAL 8191
+#define PRECALC_SIZE (IXMAX_VAL+2)
+#define LARGE_BITS 100000
+#define SF_OFFSET 100
+
+#define POW20(x)  pow(2.0,((double)x)*.25)
+#define IPOW20(x)  pow(2.0,-((double)x)*.1875)
+
+
+typedef struct {
+    int     over_count;      /* number of quantization noise > masking */
+    int     tot_count;       /* all */
+    double  over_noise;      /* sum of quantization noise > masking */
+    double  tot_noise;       /* sum of all quantization noise */
+    double  max_noise;       /* max quantization noise */
+} calcNoiseResult;
+
+void AACQuantizeInit(CoderInfo *coderInfo, unsigned int numChannels);
+void AACQuantizeEnd();
+
+int AACQuantize(CoderInfo *coderInfo,
+				PsyInfo *psyInfo,
+				ChannelInfo *channelInfo,
+				int *cb_width,
+				int num_cb,
+				double *xr,
+				int desired_rate);
+
+static int SearchStepSize(CoderInfo *coderInfo,
+						  const int desired_rate,
+						  const double *xr,
+						  int *xi);
+
+static void Quantize(const double *xr, int *ix, double istep);
+
+static int SortForGrouping(CoderInfo* coderInfo, PsyInfo *psyInfo,
+						   ChannelInfo *channelInfo, int *sfb_width_table,
+						   double *xr);
+
+static int CountBitsLong(CoderInfo *coderInfo, int *xi);
+
+static int CountBits(CoderInfo *coderInfo, int *ix, const double *xr);
+
+static int InnerLoop(CoderInfo *coderInfo, double *xr_pow, int *xi, int max_bits);
+
+static void CalcAllowedDist(PsyInfo *psyInfo, int *cb_width, int num_cb,
+							double *xr, double *xmin);
+
+static int CalcNoise(CoderInfo *coderInfo, double *xr, int *xi, double *requant_xr,
+					 double *error_energy, double *xmin, calcNoiseResult *res);
+
+static int OuterLoop(CoderInfo *coderInfo, double *xr, double *xr_pow, int *xi,
+					 double *xmin, int target_bits);
+
+static int QuantCompare(calcNoiseResult *best,
+						calcNoiseResult *calc);
+
+static int BalanceNoise(CoderInfo *coderInfo, double *distort, double *xrpow);
+
+static void AmpScalefacBands(CoderInfo *coderInfo, double *distort, double *xr_pow);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* AACQUANT_H */
--- /dev/null
+++ b/libfaac/bitstream.c
@@ -1,0 +1,600 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: bitstream.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#include <stdlib.h>
+#include <memory.h>
+
+#include "coder.h"
+#include "channels.h"
+#include "huffman.h"
+#include "bitstream.h"
+
+
+int WriteBitstream(CoderInfo *coderInfo,
+				   ChannelInfo *channelInfo,
+				   BitStream *bitStream,
+				   int numChannel)
+{
+	int channel;
+	int bits = 0;
+	int bitsLeftAfterFill, numFillBits;
+
+	for (channel = 0; channel < numChannel; channel++) {
+
+		if (channelInfo[channel].present) {
+
+			/* Write out a single_channel_element */
+			if (!channelInfo[channel].cpe) {
+
+				if (channelInfo[channel].lfe) {
+					/* Write out lfe */ 
+					bits += WriteLFE(&coderInfo[channel],
+						&channelInfo[channel],
+						bitStream,
+						1);
+				} else {
+					/* Write out sce */
+					bits += WriteSCE(&coderInfo[channel],
+						&channelInfo[channel],
+						bitStream,
+						1);
+				}
+
+			} else {
+
+				if (channelInfo[channel].ch_is_left) {
+					/* Write out cpe */
+					bits += WriteCPE(&coderInfo[channel],
+						&coderInfo[channelInfo[channel].paired_ch],
+						&channelInfo[channel],
+						bitStream,
+						1);
+				}
+			}
+		}
+	}
+
+	/* Compute how many fill bits are needed to avoid overflowing bit reservoir */
+	/* Save room for ID_END terminator */
+	if (bits < (8 - LEN_SE_ID) ) {
+		numFillBits = 8 - LEN_SE_ID - bits;
+	} else {
+		numFillBits = 0;
+	}
+
+	/* Write AAC fill_elements, smallest fill element is 7 bits. */
+	/* Function may leave up to 6 bits left after fill, so tell it to fill a few extra */
+	numFillBits += 6;
+	bitsLeftAfterFill = WriteAACFillBits(bitStream, numFillBits, 1);
+	bits += (numFillBits - bitsLeftAfterFill);
+
+	/* Write ID_END terminator */
+	bits += LEN_SE_ID;
+    PutBit(bitStream, ID_END, LEN_SE_ID);
+
+	/* Now byte align the bitstream */
+	bits += ByteAlign(bitStream, 1);
+
+	return bits;
+}
+
+int CountBitstream(CoderInfo *coderInfo,
+				   ChannelInfo *channelInfo,
+				   BitStream *bitStream,
+				   int numChannel)
+{
+	int channel;
+	int bits = 0;
+	int bitsLeftAfterFill, numFillBits;
+
+	for (channel = 0; channel < numChannel; channel++) {
+
+		if (channelInfo[channel].present) {
+
+			/* Write out a single_channel_element */
+			if (!channelInfo[channel].cpe) {
+
+				if (channelInfo[channel].lfe) {
+					/* Write out lfe */ 
+					bits += WriteLFE(&coderInfo[channel],
+						&channelInfo[channel],
+						bitStream,
+						0);
+				} else {
+					/* Write out sce */
+					bits += WriteSCE(&coderInfo[channel],
+						&channelInfo[channel],
+						bitStream,
+						0);
+				}
+
+			} else {
+
+				if (channelInfo[channel].ch_is_left) {
+					/* Write out cpe */
+					bits += WriteCPE(&coderInfo[channel],
+						&coderInfo[channelInfo[channel].paired_ch],
+						&channelInfo[channel],
+						bitStream,
+						0);
+				}
+			}
+		}
+	}
+
+	/* Compute how many fill bits are needed to avoid overflowing bit reservoir */
+	/* Save room for ID_END terminator */
+	if (bits < (8 - LEN_SE_ID) ) {
+		numFillBits = 8 - LEN_SE_ID - bits;
+	} else {
+		numFillBits = 0;
+	}
+
+	/* Write AAC fill_elements, smallest fill element is 7 bits. */
+	/* Function may leave up to 6 bits left after fill, so tell it to fill a few extra */
+	numFillBits += 6;
+	bitsLeftAfterFill = WriteAACFillBits(bitStream, numFillBits, 0);
+	bits += (numFillBits - bitsLeftAfterFill);
+
+	/* Write ID_END terminator */
+	bits += LEN_SE_ID;
+
+	/* Now byte align the bitstream */
+	bits += ByteAlign(bitStream, 0);
+
+	return bits;
+}
+
+static int WriteCPE(CoderInfo *coderInfoL,
+					CoderInfo *coderInfoR,
+					ChannelInfo *channelInfo,
+					BitStream* bitStream,
+					int writeFlag)
+{
+	int bits = 0;
+
+	if (writeFlag) {
+		/* write ID_CPE, single_element_channel() identifier */
+		PutBit(bitStream, ID_CPE, LEN_SE_ID);
+
+		/* write the element_identifier_tag */
+		PutBit(bitStream, channelInfo->tag, LEN_TAG);
+
+		/* common_window? */
+		PutBit(bitStream, channelInfo->common_window, LEN_COM_WIN);
+	}
+
+	bits += LEN_SE_ID;
+	bits += LEN_TAG;
+	bits += LEN_COM_WIN;
+
+	/* if common_window, write ics_info */
+	if (channelInfo->common_window) {
+		int numWindows, maxSfb;
+
+		bits += WriteICSInfo(coderInfoL, bitStream, writeFlag);
+		numWindows = coderInfoL->num_window_groups;
+		maxSfb = coderInfoL->max_sfb;
+
+		if (writeFlag) {
+			PutBit(bitStream, channelInfo->msInfo.is_present, LEN_MASK_PRES);
+			if (channelInfo->msInfo.is_present == 1) {
+				int g;
+				int b;
+				for (g=0;g<numWindows;g++) {
+					for (b=0;b<maxSfb;b++) {
+						PutBit(bitStream, channelInfo->msInfo.ms_used[g*maxSfb+b], LEN_MASK);
+					}
+				}
+			}
+		}
+		bits += LEN_MASK_PRES;
+		if (channelInfo->msInfo.is_present == 1)
+			bits += (numWindows*maxSfb*LEN_MASK);
+	}
+
+	/* Write individual_channel_stream elements */
+	bits += WriteICS(coderInfoL, bitStream, channelInfo->common_window, writeFlag);
+	bits += WriteICS(coderInfoR, bitStream, channelInfo->common_window, writeFlag);
+
+	return bits;
+}
+
+static int WriteSCE(CoderInfo *coderInfo,
+					ChannelInfo *channelInfo,
+					BitStream *bitStream,
+					int writeFlag)
+{
+	int bits = 0;
+
+	if (writeFlag) {
+		/* write Single Element Channel (SCE) identifier */
+		PutBit(bitStream, ID_SCE, LEN_SE_ID);
+
+		/* write the element identifier tag */
+		PutBit(bitStream, channelInfo->tag, LEN_TAG);
+	}
+
+	bits += LEN_SE_ID;
+	bits += LEN_TAG;
+
+	/* Write an Individual Channel Stream element */
+	bits += WriteICS(coderInfo, bitStream, 0, writeFlag);
+
+	return bits;
+}
+
+static int WriteLFE(CoderInfo *coderInfo,
+					ChannelInfo *channelInfo,
+					BitStream *bitStream,
+					int writeFlag)
+{
+	int bits = 0;
+
+	if (writeFlag) {
+		/* write ID_LFE, lfe_element_channel() identifier */
+		PutBit(bitStream, ID_LFE, LEN_SE_ID);
+
+		/* write the element_identifier_tag */
+		PutBit(bitStream, channelInfo->tag, LEN_TAG);
+	}
+
+	bits += LEN_SE_ID;
+	bits += LEN_TAG;
+
+	/* Write an individual_channel_stream element */
+	bits += WriteICS(coderInfo, bitStream, 0, writeFlag);
+
+	return bits;
+}
+
+static int WriteICSInfo(CoderInfo *coderInfo,
+						BitStream *bitStream,
+						int writeFlag)
+{
+	int grouping_bits;
+	int bits = 0;
+
+	if (writeFlag) {
+		/* write out ics_info() information */
+		PutBit(bitStream, 0, LEN_ICS_RESERV);  /* reserved Bit*/
+
+		/* Write out window sequence */
+		PutBit(bitStream, coderInfo->block_type, LEN_WIN_SEQ);  /* block type */
+
+		/* Write out window shape */
+		PutBit(bitStream, coderInfo->window_shape, LEN_WIN_SH);  /* window shape */
+	}
+
+	bits += LEN_ICS_RESERV;
+	bits += LEN_WIN_SEQ;
+	bits += LEN_WIN_SH;
+
+	/* For short windows, write out max_sfb and scale_factor_grouping */
+	if (coderInfo->block_type == ONLY_SHORT_WINDOW){
+		if (writeFlag) {
+			PutBit(bitStream, coderInfo->max_sfb, LEN_MAX_SFBS);
+			grouping_bits = FindGroupingBits(coderInfo);
+			PutBit(bitStream, grouping_bits, MAX_SHORT_WINDOWS - 1);  /* the grouping bits */
+		}
+		bits += LEN_MAX_SFBS;
+		bits += MAX_SHORT_WINDOWS - 1;
+	} else { /* Otherwise, write out max_sfb and predictor data */
+		if (writeFlag) {
+			PutBit(bitStream, coderInfo->max_sfb, LEN_MAX_SFBL);
+		}
+		bits += LEN_MAX_SFBL;
+		bits += WriteLTPPredictorData(coderInfo, bitStream, writeFlag);
+		/* bits += WritePredictorData(coderInfo, bitStream, writeFlag); */
+	}
+
+	return bits;
+}
+
+static int WriteICS(CoderInfo *coderInfo,
+					BitStream *bitStream,
+					int commonWindow,
+					int writeFlag)
+{
+	/* this function writes out an individual_channel_stream to the bitstream and */
+	/* returns the number of bits written to the bitstream */
+	int bits = 0;
+
+	/* Write the 8-bit global_gain */
+	if (writeFlag)
+		PutBit(bitStream, coderInfo->global_gain, LEN_GLOB_GAIN);
+	bits += LEN_GLOB_GAIN;
+
+	/* Write ics information */
+	if (!commonWindow) {
+		bits += WriteICSInfo(coderInfo, bitStream, writeFlag);
+	}
+
+	bits += SortBookNumbers(coderInfo, bitStream, writeFlag);
+	bits += WriteScalefactors(coderInfo, bitStream, writeFlag);
+	bits += WritePulseData(coderInfo, bitStream, writeFlag);
+	bits += WriteTNSData(coderInfo, bitStream, writeFlag);
+	bits += WriteGainControlData(coderInfo, bitStream, writeFlag);
+	bits += WriteSpectralData(coderInfo, bitStream, writeFlag);
+
+	/* Return number of bits */
+	return bits;
+}
+
+static int WriteLTPPredictorData(CoderInfo *coderInfo,
+								 BitStream *bitStream,
+								 int writeFlag)
+{
+	int bits = 0;
+
+	if(writeFlag)
+		PutBit (bitStream, 0, 1);  /* LTP not used */
+
+	bits += 1;
+
+	return bits;
+}
+
+static int WritePulseData(CoderInfo *coderInfo,
+						  BitStream *bitStream,
+						  int writeFlag)
+{
+	int bits = 0;
+
+	if (writeFlag) {
+		PutBit(bitStream, 0, LEN_PULSE_PRES);  /* no pulse_data_present */
+	}
+
+	bits += LEN_PULSE_PRES;
+
+	return bits;
+}
+
+static int WriteTNSData(CoderInfo *coderInfo,
+						BitStream *bitStream,
+						int writeFlag)
+{
+	int bits = 0;
+
+	if (writeFlag) {
+		PutBit(bitStream, 0, LEN_TNS_PRES);
+	}
+
+	bits += LEN_TNS_PRES;
+
+	return bits;
+}
+
+static int WriteGainControlData(CoderInfo *coderInfo,
+								BitStream *bitStream,
+								int writeFlag)
+{
+	int bits = 0;
+
+	if (writeFlag) {
+		PutBit(bitStream, 0, LEN_GAIN_PRES);
+	}
+
+	bits += LEN_GAIN_PRES;
+
+	return bits;
+}
+
+static int WriteSpectralData(CoderInfo *coderInfo,
+							 BitStream *bitStream,
+							 int writeFlag)
+{
+	int i, bits = 0;
+
+	/* set up local pointers to data and len */
+	/* data array contains data to be written */
+	/* len array contains lengths of data words */
+	int* data = coderInfo->data;
+	int* len  = coderInfo->len;
+
+	if (writeFlag) {
+		for(i = 0; i < coderInfo->spectral_count; i++) {
+			if (len[i] > 0) {  /* only send out non-zero codebook data */
+				PutBit(bitStream, data[i], len[i]); /* write data */
+				bits += len[i];
+			}
+		}
+	} else {
+		for(i = 0; i < coderInfo->spectral_count; i++) {
+			bits += len[i];
+		}
+	}
+
+	return bits;
+}
+
+static int WriteAACFillBits(BitStream* bitStream,
+							int numBits,
+							int writeFlag)
+{
+	int numberOfBitsLeft = numBits;
+
+	/* Need at least (LEN_SE_ID + LEN_F_CNT) bits for a fill_element */
+	int minNumberOfBits = LEN_SE_ID + LEN_F_CNT;
+
+	while (numberOfBitsLeft >= minNumberOfBits)
+	{
+		int numberOfBytes;
+		int maxCount;
+
+		if (writeFlag) {
+			PutBit(bitStream, ID_FIL, LEN_SE_ID);	/* Write fill_element ID */
+		}
+		numberOfBitsLeft -= minNumberOfBits;	/* Subtract for ID,count */
+
+		numberOfBytes = (int)(numberOfBitsLeft/LEN_BYTE);
+		maxCount = (1<<LEN_F_CNT) - 1;  /* Max count without escaping */
+
+		/* if we have less than maxCount bytes, write them now */
+		if (numberOfBytes < maxCount) {
+			int i;
+			if (writeFlag) {
+				PutBit(bitStream, numberOfBytes, LEN_F_CNT);
+				for (i = 0; i < numberOfBytes; i++) {
+					PutBit(bitStream, 0, LEN_BYTE);
+				}
+			}
+			/* otherwise, we need to write an escape count */
+		}
+		else {
+			int maxEscapeCount, maxNumberOfBytes, escCount;
+			int i;
+			if (writeFlag) {
+				PutBit(bitStream, maxCount, LEN_F_CNT);
+			}
+			maxEscapeCount = (1<<LEN_BYTE) - 1;  /* Max escape count */
+			maxNumberOfBytes = maxCount + maxEscapeCount;
+			numberOfBytes = (numberOfBytes > maxNumberOfBytes ) ? (maxNumberOfBytes) : (numberOfBytes);
+			escCount = numberOfBytes - maxCount;
+			if (writeFlag) {
+				PutBit(bitStream, escCount, LEN_BYTE);
+				for (i = 0; i < numberOfBytes-1; i++) {
+					PutBit(bitStream, 0, LEN_BYTE);
+				}
+			}
+		}
+		numberOfBitsLeft -= LEN_BYTE*numberOfBytes;
+	}
+
+	return numberOfBitsLeft;
+}
+
+static int FindGroupingBits(CoderInfo *coderInfo)
+{
+	/* This function inputs the grouping information and outputs the seven bit 
+	'grouping_bits' field that the AAC decoder expects.  */
+
+	int grouping_bits = 0;
+	int tmp[8];
+	int i, j;
+	int index = 0;
+
+	for(i = 0; i < coderInfo->num_window_groups; i++){
+		for (j = 0; j < coderInfo->window_group_length[i]; j++){
+			tmp[index++] = i;
+		}
+	}
+
+	for(i = 1; i < 8; i++){
+		grouping_bits = grouping_bits << 1;
+		if(tmp[i] == tmp[i-1]) {
+			grouping_bits++;
+		}
+	}
+	
+	return grouping_bits;
+}
+
+/* size in bytes! */
+BitStream *OpenBitStream(int size, unsigned char *buffer)
+{
+	BitStream *bitStream;
+
+	bitStream = malloc(sizeof(BitStream));
+	bitStream->size = size;
+	bitStream->numBit = 0;
+	bitStream->currentBit = 0;
+	bitStream->data = buffer;
+	memset(bitStream->data, 0, size);
+
+	return bitStream;
+}
+
+int CloseBitStream(BitStream *bitStream)
+{
+	int bytes = bit2byte(bitStream->numBit);
+
+	free(bitStream);
+
+	return bytes;
+}
+
+static long BufferNumBit(BitStream *bitStream)
+{
+	return bitStream->numBit;
+}
+
+static int WriteByte(BitStream *bitStream,
+					 unsigned long data,
+					 int numBit)
+{
+	long numUsed,idx;
+
+	idx = (bitStream->currentBit / BYTE_NUMBIT) % bitStream->size;
+	numUsed = bitStream->currentBit % BYTE_NUMBIT;
+	if (numUsed == 0)
+		bitStream->data[idx] = 0;
+	bitStream->data[idx] |= (data & ((1<<numBit)-1)) <<
+		(BYTE_NUMBIT-numUsed-numBit);
+	bitStream->currentBit += numBit;
+	bitStream->numBit = bitStream->currentBit;
+
+	return 0;
+}
+
+int PutBit(BitStream *bitStream,
+		   unsigned long data,
+		   int numBit)
+{
+	int num,maxNum,curNum;
+	unsigned long bits;
+
+	if (numBit == 0)
+		return 0;
+
+	/* write bits in packets according to buffer byte boundaries */
+	num = 0;
+	maxNum = BYTE_NUMBIT - bitStream->currentBit % BYTE_NUMBIT;
+	while (num < numBit) {
+		curNum = min(numBit-num,maxNum);
+		bits = data>>(numBit-num-curNum);
+		if (WriteByte(bitStream, bits, curNum)) {
+			return 1;
+		}
+		num += curNum;
+		maxNum = BYTE_NUMBIT;
+	}
+
+	return 0;
+}
+
+static int ByteAlign(BitStream *bitStream, int writeFlag)
+{
+	int len, i,j;
+
+	len = BufferNumBit(bitStream);
+	   
+	j = (8 - (len%8))%8;
+
+	if ((len % 8) == 0) j = 0;
+	if (writeFlag) {
+		for( i=0; i<j; i++ ) {
+			PutBit(bitStream, 0, 1);
+		}
+	}
+	return j;
+}
+
--- /dev/null
+++ b/libfaac/bitstream.h
@@ -1,0 +1,199 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: bitstream.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef BITSTREAM_H
+#define BITSTREAM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "coder.h"
+#include "channels.h"
+
+/* 
+ * 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
+
+
+
+#define BYTE_NUMBIT 8		/* bits in byte (char) */
+#define LONG_NUMBIT 32		/* bits in unsigned long */
+#define bit2byte(a) (((a)+BYTE_NUMBIT-1)/BYTE_NUMBIT)
+
+
+typedef struct
+{
+  unsigned char *data;		/* data bits */
+  long numBit;			/* number of bits in buffer */
+  long size;			/* buffer size in bytes */
+  long currentBit;		/* current bit position in bit stream */
+  long numByte;			/* number of bytes read/written (only file) */
+} BitStream;
+
+
+
+int WriteBitstream(CoderInfo *coderInfo,
+				   ChannelInfo *channelInfo,
+				   BitStream *bitStream,
+				   int numChannels);
+
+int CountBitstream(CoderInfo *coderInfo,
+				   ChannelInfo *channelInfo,
+				   BitStream *bitStream,
+				   int numChannels);
+
+static int WriteCPE(CoderInfo *coderInfoL,
+					CoderInfo *coderInfoR,
+					ChannelInfo *channelInfo,
+					BitStream* bitStream,
+					int writeFlag);
+
+static int WriteSCE(CoderInfo *coderInfo,
+					ChannelInfo *channelInfo,
+					BitStream *bitStream,
+					int writeFlag);
+
+static int WriteLFE(CoderInfo *coderInfo,
+					ChannelInfo *channelInfo,
+					BitStream *bitStream,
+					int writeFlag);
+
+static int WriteICSInfo(CoderInfo *coderInfo,
+						BitStream *bitStream,
+						int writeFlag);
+
+static int WriteICS(CoderInfo *coderInfo,
+					BitStream *bitStream,
+					int commonWindow,
+					int writeFlag);
+
+static int WriteLTPPredictorData(CoderInfo *coderInfo,
+								 BitStream *bitStream,
+								 int writeFlag);
+
+static int WritePulseData(CoderInfo *coderInfo,
+						  BitStream *bitStream,
+						  int writeFlag);
+
+static int WriteTNSData(CoderInfo *coderInfo,
+						BitStream *bitStream,
+						int writeFlag);
+
+static int WriteGainControlData(CoderInfo *coderInfo,
+								BitStream *bitStream,
+								int writeFlag);
+
+static int WriteSpectralData(CoderInfo *coderInfo,
+							 BitStream *bitStream,
+							 int writeFlag);
+
+static int WriteAACFillBits(BitStream* bitStream,
+							int numBits,
+							int writeFlag);
+
+static int FindGroupingBits(CoderInfo *coderInfo);
+
+BitStream *OpenBitStream(int size, unsigned char *buffer);
+
+int CloseBitStream(BitStream *bitStream);
+
+static long BufferNumBit(BitStream *bitStream);
+
+static int WriteByte(BitStream *bitStream,
+					 unsigned long data,
+					 int numBit);
+
+int PutBit(BitStream *bitStream,
+		   unsigned long data,
+		   int numBit);
+
+static int ByteAlign(BitStream* bitStream,
+					 int writeFlag);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* BITSTREAM_H */
+
--- /dev/null
+++ b/libfaac/channels.c
@@ -1,0 +1,105 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: channels.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#include "channels.h"
+#include "coder.h"
+
+
+/* If LFE present                                                       */
+/*  Num channels       # of SCE's       # of CPE's       #of LFE's      */ 
+/*  ============       ==========       ==========       =========      */
+/*      1                  1                0               0           */
+/*      2                  0                1               0           */
+/*      3                  1                1               0           */
+/*      4                  1                1               1           */
+/*      5                  1                2               0           */
+/* For more than 5 channels, use the following elements:                */
+/*      2*N                1                2*(N-1)         1           */
+/*      2*N+1              1                2*N             0           */
+/*                                                                      */
+/* Else:                                                                */
+/*                                                                      */  
+/*  Num channels       # of SCE's       # of CPE's       #of LFE's      */
+/*  ============       ==========       ==========       =========      */
+/*      1                  1                0               0           */
+/*      2                  0                1               0           */
+/*      3                  1                1               0           */
+/*      4                  2                1               0           */
+/*      5                  1                2               0           */
+/* For more than 5 channels, use the following elements:                */
+/*      2*N                2                2*(N-1)         0           */
+/*      2*N+1              1                2*N             0           */
+
+void GetChannelInfo(ChannelInfo *channelInfo, int numChannels, int useLfe)
+{
+	int sceTag = 0;
+	int lfeTag = 0;
+	int cpeTag = 0;
+	int numChannelsLeft = numChannels;
+
+	
+	/* First element is sce, except for 2 channel case */
+	if (numChannelsLeft != 2) {
+		channelInfo[numChannels-numChannelsLeft].present = 1;
+		channelInfo[numChannels-numChannelsLeft].tag = sceTag++;
+		channelInfo[numChannels-numChannelsLeft].cpe = 0;
+		channelInfo[numChannels-numChannelsLeft].lfe = 0;    
+		numChannelsLeft--;
+	}
+
+	/* Next elements are cpe's */
+	while (numChannelsLeft > 1) {
+		/* Left channel info */
+		channelInfo[numChannels-numChannelsLeft].present = 1;
+		channelInfo[numChannels-numChannelsLeft].tag = cpeTag++;
+		channelInfo[numChannels-numChannelsLeft].cpe = 1;
+		channelInfo[numChannels-numChannelsLeft].common_window = 0;
+		channelInfo[numChannels-numChannelsLeft].ch_is_left = 1;
+		channelInfo[numChannels-numChannelsLeft].paired_ch = numChannels-numChannelsLeft+1;
+		channelInfo[numChannels-numChannelsLeft].lfe = 0;    
+		numChannelsLeft--;
+		
+		/* Right channel info */
+		channelInfo[numChannels-numChannelsLeft].present = 1;
+		channelInfo[numChannels-numChannelsLeft].cpe = 1;
+		channelInfo[numChannels-numChannelsLeft].common_window = 0;
+		channelInfo[numChannels-numChannelsLeft].ch_is_left = 0;
+		channelInfo[numChannels-numChannelsLeft].paired_ch = numChannels-numChannelsLeft-1;
+		channelInfo[numChannels-numChannelsLeft].lfe = 0;
+		numChannelsLeft--;
+	}
+
+	/* Is there another channel left ? */
+	if (numChannelsLeft) {
+		if (useLfe) { 
+			channelInfo[numChannels-numChannelsLeft].present = 1;
+			channelInfo[numChannels-numChannelsLeft].tag = lfeTag++;
+			channelInfo[numChannels-numChannelsLeft].cpe = 0;
+			channelInfo[numChannels-numChannelsLeft].lfe = 1; 
+		} else {
+			channelInfo[numChannels-numChannelsLeft].present = 1;
+			channelInfo[numChannels-numChannelsLeft].tag = sceTag++;
+			channelInfo[numChannels-numChannelsLeft].cpe = 0;
+			channelInfo[numChannels-numChannelsLeft].lfe = 0;
+		}
+		numChannelsLeft--;
+	}
+}
--- /dev/null
+++ b/libfaac/channels.h
@@ -1,0 +1,55 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: channels.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef CHANNEL_H
+#define CHANNEL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "coder.h"
+
+typedef struct {
+    int is_present;  
+    int ms_used[MAX_SCFAC_BANDS];
+    int ms_usedS[8][MAX_SCFAC_BANDS];
+} MSInfo;
+
+typedef struct {
+	int tag;
+	int present;
+	int ch_is_left;
+	int paired_ch;
+	int common_window;
+	int cpe;
+	int sce;
+	int lfe;
+	MSInfo msInfo;
+} ChannelInfo;
+
+void GetChannelInfo(ChannelInfo *channelInfo, int numChannels, int useLfe);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CHANNEL_H */
\ No newline at end of file
--- /dev/null
+++ b/libfaac/coder.h
@@ -1,0 +1,90 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: coder.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef CODER_H
+#define CODER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+#define MAX_CHANNELS 64
+#define FRAME_LEN 1024
+
+#define NSFB_LONG  51
+#define NSFB_SHORT 15
+#define MAX_SHORT_WINDOWS 8
+#define BLOCK_LEN_LONG 1024
+#define BLOCK_LEN_SHORT 128
+#define MAX_SCFAC_BANDS ((NSFB_SHORT+1)*MAX_SHORT_WINDOWS)
+
+enum WINDOW_TYPE {
+	ONLY_LONG_WINDOW, 
+	LONG_SHORT_WINDOW, 
+	ONLY_SHORT_WINDOW,
+	SHORT_LONG_WINDOW,
+};
+
+typedef struct {
+	int window_shape;
+	int prev_window_shape;
+	int block_type;
+	int desired_block_type;
+
+	int global_gain;
+	int old_value;
+	int CurrentStep;
+	int scale_factor[MAX_SCFAC_BANDS];
+
+	int num_window_groups;
+	int window_group_length[8];
+	int max_sfb;
+	int nr_of_sfb;
+	int sfb_offset[250];
+
+	int spectral_count;
+
+	/* Huffman codebook selected for each sf band */
+	int book_vector[MAX_SCFAC_BANDS];
+
+	/* Data of spectral bitstream elements, for each spectral pair,
+	   5 elements are required: 1*(esc)+2*(sign)+2*(esc value)=5 */
+	int *data;
+
+	/* Lengths of spectral bitstream elements */
+	int *len;
+
+} CoderInfo;
+
+typedef struct { 
+  unsigned 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];
+  int cb_width_short[NSFB_SHORT];
+} SR_INFO;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CODER_H */
\ No newline at end of file
--- /dev/null
+++ b/libfaac/fft.c
@@ -1,0 +1,423 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: fft.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#include <math.h>
+#include <stdlib.h>
+
+#include "fft.h"
+
+
+#define  MAXLOGM     11    /* max FFT length = 2^MAXLOGM */
+#define  TWOPI       6.28318530717958647692
+#define  SQHALF      0.707106781186547524401
+
+static   double    *tabr[MAXLOGM]; /* tables of butterfly angles */
+
+static void build_table(int logm)
+{
+   static   int      m, m2, m4, m8, nel, n;
+   static   double    *cn, *spcn, *smcn;
+   static   double    ang, c, s;
+ 
+   /* Compute a few constants */
+   m = 1 << logm; m2 = m / 2; m4 = m2 / 2; m8 = m4 /2;
+ 
+   /* Allocate memory for tables */
+   nel = m4 - 2;
+   tabr[logm-4] = (double *) calloc(3 * nel, sizeof(double));
+//   if ((tab[logm-4] = (double *) calloc(3 * nel, sizeof(double))) == NULL) {
+//      printf("Error : RSFFT : not enough memory for cosine tables.\n");
+//      error_exit();
+//   }
+ 
+   /* Initialize pointers */
+   cn  = tabr[logm-4]; spcn  = cn + nel;  smcn  = spcn + nel;
+ 
+   /* Compute tables */
+   for (n = 1; n < m4; n++) {
+      if (n == m8) continue;
+      ang = n * TWOPI / m;
+      c = cos(ang); s = sin(ang);
+      *cn++ = c; *spcn++ = - (s + c); *smcn++ = s - c;
+   }
+}
+ 
+/*--------------------------------------------------------------------*
+ *    Recursive part of the RSFFT algorithm.  Not externally          *
+ *    callable.                                                       *
+ *--------------------------------------------------------------------*/
+ 
+static void rsrec(double *x, int logm)
+{
+   static   int      m, m2, m4, m8, nel, n;
+   static   double    *xr1, *xr2, *xi1;
+   static   double    *cn, *spcn, *smcn;
+   static   double    tmp1, tmp2;
+ 
+   /* Compute trivial cases */
+   if (logm < 2) {
+      if (logm == 1) {   /* length m = 2 */
+         xr2  = x + 1;
+         tmp1 = *x + *xr2;
+         *xr2 = *x - *xr2;
+         *x   = tmp1;
+         return;
+      }
+      else if (logm == 0) return;   /* length m = 1 */
+   }
+ 
+   /* Compute a few constants */
+   m = 1 << logm; m2 = m / 2; m4 = m2 / 2; m8 = m4 /2;
+ 
+   /* Build tables of butterfly coefficients, if necessary */
+   if ((logm >= 4) && (tabr[logm-4] == NULL))
+      build_table(logm);
+ 
+   /* Step 1 */
+   xr1 = x; xr2 = xr1 + m2;
+   for (n = 0; n < m2; n++) {
+      tmp1 = *xr1 + *xr2;
+      *xr2 = *xr1 - *xr2;
+      *xr1 = tmp1;
+      xr1++; xr2++;
+   }
+ 
+   /* Step 2 */
+   xr1 = x + m2 + m4;
+   for (n = 0; n < m4; n++) {
+      *xr1 = - *xr1;
+      xr1++;
+   }
+ 
+   /* Step 3: multiplication by W_M^n */
+   xr1 = x + m2; xi1 = xr1 + m4;
+   if (logm >= 4) {
+      nel = m4 - 2;
+      cn  = tabr[logm-4]; spcn  = cn + nel;  smcn  = spcn + nel;
+   }
+   xr1++; xi1++;
+   for (n = 1; n < m4; n++) {
+      if (n == m8) {
+         tmp1 =  SQHALF * (*xr1 + *xi1);
+         *xi1 =  SQHALF * (*xi1 - *xr1);
+         *xr1 =  tmp1;
+      } else {
+         tmp2 = *cn++ * (*xr1 + *xi1);
+         tmp1 = *spcn++ * *xr1 + tmp2;
+         *xr1 = *smcn++ * *xi1 + tmp2;
+         *xi1 = tmp1;
+      }
+      xr1++; xi1++;
+   }
+ 
+   /* Call rsrec again with half DFT length */
+   rsrec(x, logm-1);
+ 
+   /* Step 4: Call complex DFT routine, with quarter DFT length.
+      Constants have to be recomputed, because they are static! */
+   m = 1 << logm; m2 = m / 2; m4 = 3 * (m / 4);
+   srrec(x + m2, x + m4, logm-2);
+ 
+   /* Step 5: sign change & data reordering */
+   m = 1 << logm; m2 = m / 2; m4 = m2 / 2; m8 = m4 / 2;
+   xr1 = x + m2 + m4;
+   xr2 = x + m - 1;
+   for (n = 0; n < m8; n++) {
+      tmp1   =    *xr1;
+      *xr1++ =  - *xr2;
+      *xr2-- =  - tmp1;
+   }
+   xr1 = x + m2 + 1;
+   xr2 = x + m - 2;
+   for (n = 0; n < m8; n++) {
+      tmp1   =    *xr1;
+      *xr1++ =  - *xr2;
+      *xr2-- =    tmp1;
+      xr1++;
+      xr2--;
+   }
+   if (logm == 2) x[3] = -x[3];
+}
+ 
+/*--------------------------------------------------------------------*
+ *    Direct transform for real inputs                                *
+ *--------------------------------------------------------------------*/
+ 
+/*--------------------------------------------------------------------*
+ *    Data unshuffling according to bit-reversed indexing.            *
+ *                                                                    *
+ *    Bit reversal is done using Evan's algorithm (Ref: D. M. W.      *
+ *    Evans, "An improved digit-reversal permutation algorithm ...",  *
+ *    IEEE Trans. ASSP, Aug. 1987, pp. 1120-1125).                    *
+ *--------------------------------------------------------------------*/
+static   int   brseed[256];   /* Evans' seed table */
+static   int   brsflg;        /* flag for table building */
+ 
+static void BR_permute(double *x, int logm)
+{
+   int      i, j, imax, lg2, n;
+   int      off, fj, gno, *brp;
+   double    tmp, *xp, *xq;
+ 
+   lg2 = logm >> 1;
+   n = 1 << lg2;
+   if (logm & 1) lg2++;
+ 
+   /* Create seed table if not yet built */
+   if (brsflg != logm) {
+      brsflg = logm;
+      brseed[0] = 0;
+      brseed[1] = 1;
+      for (j = 2; j <= lg2; j++) {
+         imax = 1 << (j - 1);
+         for (i = 0; i < imax; i++) {
+            brseed[i] <<= 1;
+            brseed[i + imax] = brseed[i] + 1;
+         }
+      }
+   }
+ 
+   /* Unshuffling loop */
+   for (off = 1; off < n; off++) {
+      fj = n * brseed[off]; i = off; j = fj;
+      tmp = x[i]; x[i] = x[j]; x[j] = tmp;
+      xp = &x[i];
+      brp = &brseed[1];
+      for (gno = 1; gno < brseed[off]; gno++) {
+         xp += n;
+         j = fj + *brp++;
+         xq = x + j;
+         tmp = *xp; *xp = *xq; *xq = tmp;
+      }
+   }
+}
+ 
+/*--------------------------------------------------------------------*
+ *    Recursive part of the SRFFT algorithm.                          *
+ *--------------------------------------------------------------------*/
+ 
+static void srrec(double *xr, double *xi, int logm)
+{
+   static   int      m, m2, m4, m8, nel, n;
+   static   double    *xr1, *xr2, *xi1, *xi2;
+   static   double    *cn, *spcn, *smcn, *c3n, *spc3n, *smc3n;
+   static   double    tmp1, tmp2, ang, c, s;
+   static   double    *tab[MAXLOGM];
+ 
+   /* Compute trivial cases */
+   if (logm < 3) {
+      if (logm == 2) {  /* length m = 4 */
+         xr2  = xr + 2;
+         xi2  = xi + 2;
+         tmp1 = *xr + *xr2;
+         *xr2 = *xr - *xr2;
+         *xr  = tmp1;
+         tmp1 = *xi + *xi2;
+         *xi2 = *xi - *xi2;
+         *xi  = tmp1;
+         xr1  = xr + 1;
+         xi1  = xi + 1;
+         xr2++;
+         xi2++;
+         tmp1 = *xr1 + *xr2;
+         *xr2 = *xr1 - *xr2;
+         *xr1 = tmp1;
+         tmp1 = *xi1 + *xi2;
+         *xi2 = *xi1 - *xi2;
+         *xi1 = tmp1;
+         xr2  = xr + 1;
+         xi2  = xi + 1;
+         tmp1 = *xr + *xr2;
+         *xr2 = *xr - *xr2;
+         *xr  = tmp1;
+         tmp1 = *xi + *xi2;
+         *xi2 = *xi - *xi2;
+         *xi  = tmp1;
+         xr1  = xr + 2;
+         xi1  = xi + 2;
+         xr2  = xr + 3;
+         xi2  = xi + 3;
+         tmp1 = *xr1 + *xi2;
+         tmp2 = *xi1 + *xr2;
+         *xi1 = *xi1 - *xr2;
+         *xr2 = *xr1 - *xi2;
+         *xr1 = tmp1;
+         *xi2 = tmp2;
+         return;
+      }
+      else if (logm == 1) {   /* length m = 2 */
+         xr2  = xr + 1;
+         xi2  = xi + 1;
+         tmp1 = *xr + *xr2;
+         *xr2 = *xr - *xr2;
+         *xr  = tmp1;
+         tmp1 = *xi + *xi2;
+         *xi2 = *xi - *xi2;
+         *xi  = tmp1;
+         return;
+      }
+      else if (logm == 0) return;   /* length m = 1 */
+   }
+ 
+   /* Compute a few constants */
+   m = 1 << logm; m2 = m / 2; m4 = m2 / 2; m8 = m4 /2;
+ 
+   /* Build tables of butterfly coefficients, if necessary */
+   if ((logm >= 4) && (tab[logm-4] == NULL)) {
+ 
+      /* Allocate memory for tables */
+      nel = m4 - 2;
+	  tab[logm-4] = (double *) calloc(6 * nel, sizeof(double));
+//      if ((tab[logm-4] = (double *) calloc(6 * nel, sizeof(double))) == NULL) {
+//         error_exit();
+//      }
+ 
+      /* Initialize pointers */
+      cn  = tab[logm-4]; spcn  = cn + nel;  smcn  = spcn + nel;
+      c3n = smcn + nel;  spc3n = c3n + nel; smc3n = spc3n + nel;
+ 
+      /* Compute tables */
+      for (n = 1; n < m4; n++) {
+         if (n == m8) continue;
+         ang = n * TWOPI / m;
+         c = cos(ang); s = sin(ang);
+         *cn++ = c; *spcn++ = - (s + c); *smcn++ = s - c;
+         ang = 3 * n * TWOPI / m;
+         c = cos(ang); s = sin(ang);
+         *c3n++ = c; *spc3n++ = - (s + c); *smc3n++ = s - c;
+      }
+   }
+ 
+   /* Step 1 */
+   xr1 = xr; xr2 = xr1 + m2;
+   xi1 = xi; xi2 = xi1 + m2;
+   for (n = 0; n < m2; n++) {
+      tmp1 = *xr1 + *xr2;
+      *xr2 = *xr1 - *xr2;
+      *xr1 = tmp1;
+      tmp2 = *xi1 + *xi2;
+      *xi2 = *xi1 - *xi2;
+      *xi1 = tmp2;
+      xr1++; xr2++; xi1++; xi2++;
+   }
+ 
+   /* Step 2 */
+   xr1 = xr + m2; xr2 = xr1 + m4;
+   xi1 = xi + m2; xi2 = xi1 + m4;
+   for (n = 0; n < m4; n++) {
+      tmp1 = *xr1 + *xi2;
+      tmp2 = *xi1 + *xr2;
+      *xi1 = *xi1 - *xr2;
+      *xr2 = *xr1 - *xi2;
+      *xr1 = tmp1;
+      *xi2 = tmp2;
+      xr1++; xr2++; xi1++; xi2++;
+   }
+ 
+   /* Steps 3 & 4 */
+   xr1 = xr + m2; xr2 = xr1 + m4;
+   xi1 = xi + m2; xi2 = xi1 + m4;
+   if (logm >= 4) {
+      nel = m4 - 2;
+      cn  = tab[logm-4]; spcn  = cn + nel;  smcn  = spcn + nel;
+      c3n = smcn + nel;  spc3n = c3n + nel; smc3n = spc3n + nel;
+   }
+   xr1++; xr2++; xi1++; xi2++;
+   for (n = 1; n < m4; n++) {
+      if (n == m8) {
+         tmp1 =  SQHALF * (*xr1 + *xi1);
+         *xi1 =  SQHALF * (*xi1 - *xr1);
+         *xr1 =  tmp1;
+         tmp2 =  SQHALF * (*xi2 - *xr2);
+         *xi2 = -SQHALF * (*xr2 + *xi2);
+         *xr2 =  tmp2;
+      } else {
+         tmp2 = *cn++ * (*xr1 + *xi1);
+         tmp1 = *spcn++ * *xr1 + tmp2;
+         *xr1 = *smcn++ * *xi1 + tmp2;
+         *xi1 = tmp1;
+         tmp2 = *c3n++ * (*xr2 + *xi2);
+         tmp1 = *spc3n++ * *xr2 + tmp2;
+         *xr2 = *smc3n++ * *xi2 + tmp2;
+         *xi2 = tmp1;
+      }
+      xr1++; xr2++; xi1++; xi2++;
+   }
+ 
+   /* Call ssrec again with half DFT length */
+   srrec(xr, xi, logm-1);
+ 
+   /* Call ssrec again twice with one quarter DFT length.
+      Constants have to be recomputed, because they are static! */
+   m = 1 << logm; m2 = m / 2;
+   srrec(xr + m2, xi + m2, logm-2);
+   m = 1 << logm; m4 = 3 * (m / 4);
+   srrec(xr + m4, xi + m4, logm-2);
+}
+ 
+/*--------------------------------------------------------------------*
+ *    Direct transform                                                *
+ *--------------------------------------------------------------------*/
+void  srfft(double *xr, double *xi, int logm)
+{
+   /* Call recursive routine */
+   srrec(xr, xi, logm);
+ 
+   /* Output array unshuffling using bit-reversed indices */
+   if (logm > 1) {
+      BR_permute(xr, logm);
+      BR_permute(xi, logm);
+   }
+}
+ 
+/*--------------------------------------------------------------------*
+ *    Inverse transform.  Uses Duhamel's trick (Ref: P. Duhamel       *
+ *    et. al., "On computing the inverse DFT", IEEE Trans. ASSP,      *
+ *    Feb. 1988, pp. 285-286).                                        *
+ *--------------------------------------------------------------------*/
+void srifft(double *xr, double *xi, int logm)
+{
+   int      i, m;
+   double    fac, *xrp, *xip;
+ 
+   /* Call direct FFT, swapping real & imaginary addresses */
+   srfft(xi, xr, logm);
+ 
+   /* Normalization */
+   m = 1 << logm;
+   fac = 1.0 / m;
+   xrp = xr; xip = xi;
+   for (i = 0; i < m; i++) {
+      *xrp++ *= fac;
+      *xip++ *= fac;
+   }
+}
+
+void rsfft(double *x, int logm)
+{
+   /* Call recursive routine */
+   rsrec(x, logm);
+ 
+   /* Output array unshuffling using bit-reversed indices */
+   if (logm > 1) {
+      BR_permute(x, logm);
+   }
+}
--- /dev/null
+++ b/libfaac/fft.h
@@ -1,0 +1,44 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: fft.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef FFT_H
+#define FFT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+
+
+static void build_table(int logm);
+static void rsrec(double *x, int logm);
+static void srrec(double *xr, double *xi, int logm);
+void rsfft(double *x, int logm);
+void srfft(double *xr, double *xi, int logm);
+void srifft(double *xr, double *xi, int logm);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* FFT_H */
--- /dev/null
+++ b/libfaac/filtbank.c
@@ -1,0 +1,248 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: filtbank.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+
+#include "coder.h"
+#include "filtbank.h"
+#include "frame.h"
+#include "fft.h"
+
+#include "kbd_win.h"
+
+#define  TWOPI       6.28318530717958647692
+
+void FilterBankInit(faacEncHandle hEncoder)
+{
+	unsigned int i, channel;
+
+	for (channel = 0; channel < hEncoder->numChannels; channel++) {
+		hEncoder->freqBuff[channel] = (double*)malloc(2*FRAME_LEN*sizeof(double));
+		hEncoder->overlapBuff[channel] = (double*)malloc(FRAME_LEN*sizeof(double));
+		memset(hEncoder->overlapBuff[channel], 0, FRAME_LEN*sizeof(double));
+	}
+
+	hEncoder->sin_window_long = (double*)malloc(BLOCK_LEN_LONG*sizeof(double));
+	hEncoder->sin_window_short = (double*)malloc(BLOCK_LEN_SHORT*sizeof(double));
+	hEncoder->kbd_window_long = kbd_window_long;
+	hEncoder->kbd_window_short = kbd_window_short;
+
+	for( i=0; i<BLOCK_LEN_LONG; i++ )
+		hEncoder->sin_window_long[i] = sin((M_PI/(2*BLOCK_LEN_LONG)) * (i + 0.5));
+	for( i=0; i<BLOCK_LEN_SHORT; i++ )
+		hEncoder->sin_window_short[i] = sin((M_PI/(2*BLOCK_LEN_SHORT)) * (i + 0.5));
+}
+
+void FilterBankEnd(faacEncHandle hEncoder)
+{
+	unsigned int channel;
+
+	for (channel = 0; channel < hEncoder->numChannels; channel++) {
+		if (hEncoder->freqBuff[channel]) free(hEncoder->freqBuff[channel]);
+		if (hEncoder->overlapBuff[channel]) free(hEncoder->overlapBuff[channel]);
+	}
+
+	if (hEncoder->sin_window_long) free(hEncoder->sin_window_long);
+	if (hEncoder->sin_window_short) free(hEncoder->sin_window_short);
+}
+
+void FilterBank(faacEncHandle hEncoder,
+				CoderInfo *coderInfo,
+				double *p_in_data,
+				double *p_out_mdct,
+				double *p_overlap)
+{
+	double *transf_buf;
+	double *p_o_buf, *first_window, *second_window;
+	int k, i;
+	int block_type = coderInfo->block_type;
+
+	transf_buf = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
+
+	/* create / shift old values */
+	/* We use p_overlap here as buffer holding the last frame time signal*/
+	memcpy(transf_buf, p_overlap, FRAME_LEN*sizeof(double));
+	memcpy(transf_buf+BLOCK_LEN_LONG, p_in_data, FRAME_LEN*sizeof(double));
+	memcpy(p_overlap, p_in_data, FRAME_LEN*sizeof(double));
+
+	/*  Window shape processing */
+	switch (coderInfo->prev_window_shape){
+    case SINE_WINDOW:
+		if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+			first_window = hEncoder->sin_window_long;
+		else
+			first_window = hEncoder->sin_window_short;
+		break;
+    case KBD_WINDOW:
+		if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+			first_window = hEncoder->kbd_window_long;
+		else
+			first_window = hEncoder->kbd_window_short;
+		break;
+	}
+
+	switch (coderInfo->window_shape){
+    case SINE_WINDOW:
+		if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+			second_window = hEncoder->sin_window_long;
+		else
+			second_window = hEncoder->sin_window_short;
+		break;
+    case KBD_WINDOW:
+		if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+			second_window = hEncoder->kbd_window_long;
+		else
+			second_window = hEncoder->kbd_window_short;
+		break;
+	}
+
+	/* Set ptr to transf-Buffer */
+	p_o_buf = transf_buf;
+
+	/* Separate action for each Block Type */
+	switch( block_type ) {
+    case ONLY_LONG_WINDOW :
+		for ( i = 0 ; i < BLOCK_LEN_LONG ; i++){
+			p_out_mdct[i] = p_o_buf[i] * first_window[i];
+			p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+		}
+		MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+		break;
+
+    case LONG_SHORT_WINDOW :
+		for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+			p_out_mdct[i] = p_o_buf[i] * first_window[i];
+		memcpy(p_out_mdct+BLOCK_LEN_LONG,p_o_buf+BLOCK_LEN_LONG,NFLAT_LS*sizeof(double));
+		for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+			p_out_mdct[i+BLOCK_LEN_LONG+NFLAT_LS] = p_o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
+		memset(p_out_mdct+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
+		MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+		break;
+
+    case SHORT_LONG_WINDOW :
+		memset(p_out_mdct,0,NFLAT_LS*sizeof(double));
+		for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+			p_out_mdct[i+NFLAT_LS] = p_o_buf[i+NFLAT_LS] * first_window[i];
+		memcpy(p_out_mdct+NFLAT_LS+BLOCK_LEN_SHORT,p_o_buf+NFLAT_LS+BLOCK_LEN_SHORT,NFLAT_LS*sizeof(double));
+		for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+			p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+		MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+		break;
+
+    case ONLY_SHORT_WINDOW :
+		p_o_buf += NFLAT_LS;
+		for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
+			for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++ ){
+				p_out_mdct[i] = p_o_buf[i] * first_window[i];
+				p_out_mdct[i+BLOCK_LEN_SHORT] = p_o_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
+			}
+			MDCT( p_out_mdct, 2*BLOCK_LEN_SHORT );
+			p_out_mdct += BLOCK_LEN_SHORT;
+			p_o_buf += BLOCK_LEN_SHORT;
+			first_window = second_window;
+		}
+		break;
+	}
+
+	if (transf_buf) free(transf_buf);
+}
+
+static void MDCT(double *data, int N)
+{
+	double *xi, *xr;
+	double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
+	double freq = TWOPI / N;
+	double cosfreq8, sinfreq8;
+	int i, n;
+
+	xi = (double*)malloc((N >> 2)*sizeof(double));
+	xr = (double*)malloc((N >> 2)*sizeof(double));
+
+	/* prepare for recurrence relation in pre-twiddle */
+	cfreq = cos (freq);
+	sfreq = sin (freq);
+	cosfreq8 = cos (freq * 0.125);
+	sinfreq8 = sin (freq * 0.125);
+	c = cosfreq8;
+	s = sinfreq8;
+
+	for (i = 0; i < (N >> 2); i++) {
+		/* calculate real and imaginary parts of g(n) or G(p) */
+		n = (N >> 1) - 1 - 2 * i;
+
+		if (i < (N >> 3))
+			tempr = data [(N >> 2) + n] + data [N + (N >> 2) - 1 - n]; /* use second form of e(n) for n = N / 2 - 1 - 2i */
+		else
+			tempr = data [(N >> 2) + n] - data [(N >> 2) - 1 - n]; /* use first form of e(n) for n = N / 2 - 1 - 2i */
+
+		n = 2 * i;
+		if (i < (N >> 3))
+			tempi = data [(N >> 2) + n] - data [(N >> 2) - 1 - n]; /* use first form of e(n) for n=2i */
+		else
+			tempi = data [(N >> 2) + n] + data [N + (N >> 2) - 1 - n]; /* use second form of e(n) for n=2i*/
+
+		/* calculate pre-twiddled FFT input */
+		xr[i] = tempr * c + tempi * s;
+		xi[i] = tempi * c - tempr * s;
+
+		/* use recurrence to prepare cosine and sine for next value of i */
+		cold = c;
+		c = c * cfreq - s * sfreq;
+		s = s * cfreq + cold * sfreq;
+	}
+
+	/* Perform in-place complex FFT of length N/4 */
+	switch (N) {
+    case 256:
+		srfft(xr, xi, 6);
+		break;
+    case 2048:
+		srfft(xr, xi, 9);
+	}
+
+	/* prepare for recurrence relations in post-twiddle */
+	c = cosfreq8;
+	s = sinfreq8;
+
+	/* post-twiddle FFT output and then get output data */
+	for (i = 0; i < (N >> 2); i++) {
+		/* get post-twiddled FFT output  */
+		tempr = 2. * (xr[i] * c + xi[i] * s);
+		tempi = 2. * (xi[i] * c - xr[i] * s);
+
+		/* fill in output values */
+		data [2 * i] = -tempr;   /* first half even */
+		data [(N >> 1) - 1 - 2 * i] = tempi;  /* first half odd */
+		data [(N >> 1) + 2 * i] = -tempi;  /* second half even */
+		data [N - 1 - 2 * i] = tempr;  /* second half odd */
+
+		/* use recurrence to prepare cosine and sine for next value of i */
+		cold = c;
+		c = c * cfreq - s * sfreq;
+		s = s * cfreq + cold * sfreq;
+	}
+
+	if (xr) free(xr);
+	if (xi) free(xi);
+}
--- /dev/null
+++ b/libfaac/filtbank.h
@@ -1,0 +1,63 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: filtbank.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef FILTBANK_H
+#define FILTBANK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "frame.h"
+
+#define NFLAT_LS 448
+
+#ifndef M_PI
+#define M_PI        3.14159265358979323846
+#endif
+
+#ifndef M_PI_2
+#define M_PI_2      1.57079632679489661923
+#endif
+
+
+#define SINE_WINDOW 0
+#define KBD_WINDOW  1
+
+void FilterBankInit(faacEncHandle hEncoder);
+
+void FilterBankEnd(faacEncHandle hEncoder);
+
+void FilterBank(faacEncHandle hEncoder,
+				CoderInfo *coderInfo,
+				double *p_in_data,
+				double *p_out_mdct,
+				double *p_overlap);
+
+static void MDCT(double *data, int N);
+static void IMDCT(double *data, int N);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* FILTBANK_H */
\ No newline at end of file
--- /dev/null
+++ b/libfaac/frame.c
@@ -1,0 +1,379 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: frame.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+
+#include "frame.h"
+#include "coder.h"
+#include "joint.h"
+#include "channels.h"
+#include "bitstream.h"
+#include "filtbank.h"
+#include "aacquant.h"
+#include "util.h"
+#include "huffman.h"
+#include "psych.h"
+
+
+faacEncConfigurationPtr FAACAPI faacEncGetCurrentConfiguration(faacEncHandle hEncoder)
+{
+	faacEncConfigurationPtr config = &(hEncoder->config);
+
+	return config;
+}
+
+int FAACAPI faacEncSetConfiguration(faacEncHandle hEncoder,
+									faacEncConfigurationPtr config)
+{
+	hEncoder->config.allowMidside = config->allowMidside;
+	hEncoder->config.useLfe = config->useLfe;
+	hEncoder->config.bitRate = config->bitRate;
+
+	return 1;
+}
+
+faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
+								  unsigned int numChannels)
+{
+	unsigned int channel;
+	faacEncHandle hEncoder;
+
+	hEncoder = (faacEncStruct*)malloc(sizeof(faacEncStruct));
+	memset(hEncoder, 0, sizeof(faacEncStruct));
+
+	hEncoder->numChannels = numChannels;
+	hEncoder->sampleRate = sampleRate;
+	hEncoder->sampleRateIdx = GetSRIndex(sampleRate);
+
+	/* Initialize variables to default values */
+	hEncoder->frameNum = 0;
+	hEncoder->flushFrame = 0;
+	hEncoder->config.allowMidside = 1;
+	hEncoder->config.useLfe = 0;
+	hEncoder->config.bitRate = 64000; /* default bitrate / channel */
+
+	/* find correct sampling rate depending parameters */
+	hEncoder->srInfo = &srInfo[hEncoder->sampleRateIdx];
+
+	for (channel = 0; channel < numChannels; channel++) {
+		hEncoder->coderInfo[channel].prev_window_shape = SINE_WINDOW;
+		hEncoder->coderInfo[channel].window_shape = SINE_WINDOW;
+		hEncoder->coderInfo[channel].block_type = ONLY_LONG_WINDOW;
+		hEncoder->coderInfo[channel].num_window_groups = 1;
+		hEncoder->coderInfo[channel].window_group_length[0] = 1;
+
+		hEncoder->sampleBuff[channel] = NULL;
+		hEncoder->nextSampleBuff[channel] = NULL;
+		hEncoder->next2SampleBuff[channel] = NULL;
+	}
+
+	/* Initialize coder functions */
+	PsyInit(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels,
+		hEncoder->sampleRate, hEncoder->srInfo->cb_width_long,
+		hEncoder->srInfo->num_cb_long, hEncoder->srInfo->cb_width_short,
+		hEncoder->srInfo->num_cb_short);
+
+	FilterBankInit(hEncoder);
+
+	AACQuantizeInit(hEncoder->coderInfo, hEncoder->numChannels);
+
+	HuffmanInit(hEncoder->coderInfo, hEncoder->numChannels);
+
+	/* Return handle */
+	return hEncoder;
+}
+
+int FAACAPI faacEncClose(faacEncHandle hEncoder)
+{
+	/* Deinitialize coder functions */
+	PsyEnd(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels);
+
+	FilterBankEnd(hEncoder);
+
+	AACQuantizeEnd();
+
+	HuffmanEnd(hEncoder->coderInfo, hEncoder->numChannels);
+
+	/* Free handle */
+	if (hEncoder) free(hEncoder);
+
+	return 0;
+}
+
+int FAACAPI faacEncEncode(faacEncHandle hEncoder,
+						  short *inputBuffer,
+						  unsigned int samplesInput,
+						  unsigned char *outputBuffer,
+						  unsigned int bufferSize
+						  )
+{
+	unsigned int channel, i;
+	int sb, frameBytes;
+	unsigned int bitsToUse, offset;
+	BitStream *bitStream; /* bitstream used for writing the frame to */
+
+	/* local copy's of parameters */
+	ChannelInfo *channelInfo = hEncoder->channelInfo;
+	CoderInfo *coderInfo = hEncoder->coderInfo;
+	unsigned int numChannels = hEncoder->numChannels;
+	unsigned int sampleRate = hEncoder->sampleRate;
+	unsigned int useLfe = hEncoder->config.useLfe;
+	unsigned int allowMidside = hEncoder->config.allowMidside;
+	unsigned int bitRate = hEncoder->config.bitRate;
+
+	/* Increase frame number */
+	hEncoder->frameNum++;
+
+	if (samplesInput == 0)
+		hEncoder->flushFrame++;
+
+	/* After 4 flush frames all samples have been encoded,
+	   return 0 bytes written */
+	if (hEncoder->flushFrame == 4)
+		return 0;
+
+	/* Determine the channel configuration */
+	GetChannelInfo(channelInfo, numChannels, useLfe);
+
+	/* Update current sample buffers */
+	for (channel = 0; channel < numChannels; channel++) {
+		if (hEncoder->sampleBuff[channel])
+			free(hEncoder->sampleBuff[channel]);
+		hEncoder->sampleBuff[channel] = hEncoder->nextSampleBuff[channel];
+		hEncoder->nextSampleBuff[channel] = hEncoder->next2SampleBuff[channel];
+		hEncoder->next2SampleBuff[channel] = hEncoder->next3SampleBuff[channel];
+		hEncoder->next3SampleBuff[channel] = (double*)malloc(FRAME_LEN*sizeof(double));
+
+		if (samplesInput == 0) { /* start flushing*/
+			for (i = 0; i < FRAME_LEN; i++)
+				hEncoder->next3SampleBuff[channel][i] = 0.0;
+		} else {
+			for (i = 0; i < (int)(samplesInput/numChannels); i++)
+				hEncoder->next3SampleBuff[channel][i] = 
+					(double)inputBuffer[(i*numChannels)+channel];
+			for (i = (int)(samplesInput/numChannels); i < FRAME_LEN; i++)
+				hEncoder->next3SampleBuff[channel][i] = 0.0;
+		}
+
+		/* Psychoacoustics */
+		/* Update buffers and run FFT on new samples */
+		PsyBufferUpdate(&hEncoder->gpsyInfo, &hEncoder->psyInfo[channel],
+			hEncoder->next3SampleBuff[channel]);
+	}
+
+	if (hEncoder->frameNum <= 3) /* Still filling up the buffers */
+		return 0;
+
+	/* Excitation pattern based psychoacoustic model */
+	PsyCalculate(channelInfo, &hEncoder->gpsyInfo, hEncoder->psyInfo,
+		hEncoder->srInfo->cb_width_long, hEncoder->srInfo->num_cb_long,
+		hEncoder->srInfo->cb_width_short,
+		hEncoder->srInfo->num_cb_short, numChannels);
+
+	BlockSwitch(coderInfo, hEncoder->psyInfo, numChannels);
+
+	/* AAC Filterbank, MDCT with overlap and add */
+	for (channel = 0; channel < numChannels; channel++) {
+		FilterBank(hEncoder,
+			&coderInfo[channel],
+			hEncoder->sampleBuff[channel],
+			hEncoder->freqBuff[channel],
+			hEncoder->overlapBuff[channel]);
+	}
+
+	/* TMP: Build sfb offset table and other stuff */
+	for (channel = 0; channel < numChannels; channel++) {
+		channelInfo[channel].msInfo.is_present = 0;
+
+		if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
+			coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_short;
+			coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_short;
+
+			coderInfo[channel].num_window_groups = 1;
+			coderInfo[channel].window_group_length[0] = 8;
+			coderInfo[channel].window_group_length[1] = 0;
+			coderInfo[channel].window_group_length[2] = 0;
+			coderInfo[channel].window_group_length[3] = 0;
+			coderInfo[channel].window_group_length[4] = 0;
+			coderInfo[channel].window_group_length[5] = 0;
+			coderInfo[channel].window_group_length[6] = 0;
+			coderInfo[channel].window_group_length[7] = 0;
+
+			offset = 0;
+			for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
+				coderInfo[channel].sfb_offset[sb] = offset;
+				offset += hEncoder->srInfo->cb_width_short[sb];
+			}
+			coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
+		} else {
+			coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_long;
+			coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_long;
+
+			coderInfo[channel].num_window_groups = 1;
+			coderInfo[channel].window_group_length[0] = 1;
+
+			offset = 0;
+			for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
+				coderInfo[channel].sfb_offset[sb] = offset;
+				offset += hEncoder->srInfo->cb_width_long[sb];
+			}
+			coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
+		}
+	}
+
+	MSEncode(coderInfo, channelInfo, hEncoder->freqBuff, numChannels, allowMidside);
+
+	/* Quantize and code the signal */
+	bitsToUse = (int)((bitRate)*FRAME_LEN/sampleRate+0.5);
+	for (channel = 0; channel < numChannels; channel++) {
+		if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
+			AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
+				&channelInfo[channel], hEncoder->srInfo->cb_width_short,
+				hEncoder->srInfo->num_cb_short,	hEncoder->freqBuff[channel], bitsToUse);
+		} else {
+			AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
+				&channelInfo[channel], hEncoder->srInfo->cb_width_long,
+				hEncoder->srInfo->num_cb_long, hEncoder->freqBuff[channel], bitsToUse);
+		}
+	}
+
+	/* Write the AAC bitstream */
+	bitStream = OpenBitStream(bufferSize, outputBuffer);
+
+	WriteBitstream(coderInfo, channelInfo, bitStream, numChannels);
+
+	/* Close the bitstream and return the number of bytes written */
+	frameBytes = CloseBitStream(bitStream);
+
+#ifdef _DEBUG
+	printf("%d\t%d\n", hEncoder->frameNum-3, frameBytes);
+#endif
+
+	return frameBytes;
+}
+
+
+/* Scalefactorband data table */
+static SR_INFO srInfo[12+1] =
+{
+	{ 96000, 41, 12,
+		{
+			4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
+			8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28, 
+			36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
+		},{
+			4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
+		}
+	}, { 88200, 41, 12,
+		{
+			4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
+			8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28, 
+			36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
+		},{
+			4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
+		}
+	}, { 64000, 47, 12,
+		{
+			4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+			8, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 24, 24, 28,
+			36, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
+			40, 40, 40, 40, 40
+		},{
+			4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 32
+		}
+	}, { 48000, 49, 14,
+		{
+			4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8,  8,  8,  8, 
+			12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
+			32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
+		}, {
+			4,  4,  4,  4,  4,  8,  8,  8, 12, 12, 12, 16, 16, 16 
+		}
+	}, { 44100, 49, 14,
+		{
+			4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8,  8,  8,  8, 
+			12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
+			32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
+		}, {
+			4,  4,  4,  4,  4,  8,  8,  8, 12, 12, 12, 16, 16, 16 
+		}
+	}, { 32000, 51, 14,
+		{
+			4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	8,	8,	8,	8,	
+			8,	8,	8,	12,	12,	12,	12,	16,	16,	20,	20,	24,	24,	28,	
+			28,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,
+			32,	32,	32,	32,	32,	32,	32,	32,	32
+		},{
+			4,	4,	4,	4,	4,	8,	8,	8,	12,	12,	12,	16,	16,	16
+		}
+	}, { 24000, 47, 15,
+		{
+			4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8,  8,  8,  8,
+			8,  8,  8,  12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
+			36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
+		}, {
+			4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8, 12, 16, 16, 20
+		}
+	}, { 22050, 47, 15,
+		{
+			4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8,  8,  8,  8,
+			8,  8,  8,  12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
+			36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
+		}, {
+			4,  4,  4,  4,  4,  4,  4,  8,  8,  8,  8, 12, 16, 16, 20
+		}
+	}, { 16000, 43, 15,
+		{
+			8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 
+			12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, 
+			24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
+		}, {
+			4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
+		}
+	}, { 12000, 43, 15,
+		{
+			8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 
+			12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, 
+			24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
+		}, {
+			4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
+		}
+	}, { 11025, 43, 15,
+		{
+			8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 
+			12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
+			24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
+		}, {
+			4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
+		}
+	}, { 8000, 40, 15,
+		{
+			12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 16, 
+			16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28, 
+			28, 32, 32, 36, 40, 44, 48, 52, 56, 60, 64, 80
+		}, {
+			4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 20
+		}
+	},
+	{ -1 }
+};
--- /dev/null
+++ b/libfaac/frame.h
@@ -1,0 +1,125 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: frame.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef FRAME_H
+#define FRAME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "coder.h"
+#include "channels.h"
+#include "psych.h"
+
+#ifdef WIN32
+  #pragma pack(push, 8)
+  #ifndef FAACAPI
+    #define FAACAPI __stdcall
+  #endif
+#else
+  #ifndef FAACAPI
+    #define FAACAPI
+  #endif
+#endif
+
+static SR_INFO srInfo[12+1];
+
+typedef struct faacEncConfiguration
+{
+
+	/* Allow mid/side coding */
+	unsigned int allowMidside;
+	/* Use one of the channels as LFE channel */
+	unsigned int useLfe;
+
+	/* bitrate / channel of AAC file */
+	unsigned long bitRate;
+
+} faacEncConfiguration, *faacEncConfigurationPtr;
+
+typedef struct {
+	/* number of channels in AAC file */
+	unsigned int numChannels;
+
+	/* samplerate of AAC file */
+	unsigned long sampleRate;
+	unsigned int sampleRateIdx;
+
+	/* frame number */
+	unsigned int frameNum;
+	unsigned int flushFrame;
+
+	/* Scalefactorband data */
+	SR_INFO *srInfo;
+
+	/* sample buffers of current next and next next frame*/
+	double *sampleBuff[MAX_CHANNELS];
+	double *nextSampleBuff[MAX_CHANNELS];
+	double *next2SampleBuff[MAX_CHANNELS];
+	double *next3SampleBuff[MAX_CHANNELS];
+
+	/* Filterbank buffers */
+	double *sin_window_long;
+	double *sin_window_short;
+	double *kbd_window_long;
+	double *kbd_window_short;
+	double *freqBuff[MAX_CHANNELS];
+	double *overlapBuff[MAX_CHANNELS];
+
+	/* Channel and Coder data for all channels */
+	CoderInfo coderInfo[MAX_CHANNELS];
+	ChannelInfo channelInfo[MAX_CHANNELS];
+
+	/* Psychoacoustics data */
+	PsyInfo psyInfo[MAX_CHANNELS];
+	GlobalPsyInfo gpsyInfo;
+
+	/* Configuration data */
+	faacEncConfiguration config;
+
+} faacEncStruct, *faacEncHandle;
+
+faacEncConfigurationPtr FAACAPI faacEncGetCurrentConfiguration(faacEncHandle hEncoder);
+int FAACAPI faacEncSetConfiguration (faacEncHandle hEncoder, faacEncConfigurationPtr config);
+
+faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
+								  unsigned int numChannels);
+
+int FAACAPI faacEncEncode(faacEncHandle hEncoder,
+						  short *inputBuffer,
+						  unsigned int samplesInput,
+						  void *outputBuffer,
+						  unsigned int bufferSize
+						  );
+
+int FAACAPI faacEncClose(faacEncHandle hEncoder);
+
+
+#ifdef WIN32
+  #pragma pack(pop)
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* FRAME_H */
\ No newline at end of file
--- /dev/null
+++ b/libfaac/huffman.c
@@ -1,0 +1,778 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: huffman.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#include <math.h>
+#include <stdlib.h>
+
+#include "huffman.h"
+#include "coder.h"
+#include "bitstream.h"
+
+#include "hufftab.h"
+
+void HuffmanInit(CoderInfo *coderInfo, unsigned int numChannels)
+{
+	unsigned int channel;
+
+	for (channel = 0; channel < numChannels; channel++) {
+		coderInfo[channel].data = (int*)malloc(5*FRAME_LEN*sizeof(int));
+		coderInfo[channel].len = (int*)malloc(5*FRAME_LEN*sizeof(int));
+	}
+}
+
+void HuffmanEnd(CoderInfo *coderInfo, unsigned int numChannels)
+{
+	unsigned int channel;
+
+	for (channel = 0; channel < numChannels; channel++) {
+		if (coderInfo[channel].data) free(coderInfo[channel].data);
+		if (coderInfo[channel].len) free(coderInfo[channel].len);
+	}
+}
+
+int BitSearch(CoderInfo *coderInfo,
+			  int *quant)  /* Quantized spectral values */
+  /*
+  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 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.
+
+  For a quick and simple algorithm, this function performs a binary
+  search across the sfb's (scale factor bands).  On the first approach, it calculates the 
+  needed amount of bits if every sfb were its own section and transmitted its own huffman 
+  codebook value side information (equal to 9 bits for a long block, 7 for a short).  The 
+  next iteration combines adjacent sfb's, and calculates the bit rate for length two sfb 
+  sections.  If any wider two-sfb section requires fewer bits than the sum of the two 
+  single-sfb sections (below it in the binary tree), then the wider section will be chosen.
+  This process occurs until the sections are split into three uniform parts, each with an
+  equal amount of sfb's contained.  
+
+  The binary tree is stored as a two-dimensional array.  Since this tree is not full, (there
+  are only 49 nodes, not 2^6 = 64), the numbering is a little complicated.  If the tree were
+  full, the top node would be 1.  It's children would be 2 and 3.  But, since this tree
+  is not full, the top row of three nodes are numbered {4,5,6}.  The row below it is
+  {8,9,10,11,12,13}, and so on.  
+
+  The binary tree is called bit_stats[112][3].  There are 112 total nodes (some are not
+  used since it's not full).  bit_stats[x][0] holds the bit totals needed for the sfb sectioning
+  strategy represented by the node x in the tree.  bit_stats[x][1] holds the optimal huffman
+  codebook table that minimizes the bit rate, given the sectioning boundaries dictated by node x.
+*/
+
+{
+	int i,j,k,n;
+	int hop;
+	int min_book_choice[112][3];
+	int bit_stats[240][3];
+//	int total_bits;
+	int total_bit_count;
+	int levels;
+	double fraction;
+
+	/* Set local pointer to coderInfo book_vector */
+	int* book_vector = coderInfo -> book_vector;
+
+	levels = (int) ((log((double)coderInfo->nr_of_sfb)/log((double)2.0))+1);
+	fraction = (pow(2,levels)+coderInfo->nr_of_sfb)/(double)(pow(2,levels));
+
+//#define SLOW
+#ifdef SLOW
+	for(i=0;i<5;i++){
+		hop = 1 << i;
+#else
+		hop = 1;
+		i = 0;
+#endif
+		NoiselessBitCount(coderInfo, quant, hop, min_book_choice);
+
+		/* load up the (not-full) binary search tree with the min_book_choice values */
+		k=0;
+//		m=0;
+		total_bit_count = 0;
+
+		for (j=(int)(pow(2,levels-i)); j<(int)(fraction*pow(2,levels-i)); j++)
+		{
+			bit_stats[j][0] = min_book_choice[k][0]; /* the minimum bit cost for this section */
+			bit_stats[j][1] = min_book_choice[k][1]; /* used with this huffman book number */
+
+			if (i>0){  /* not on the lowest level, grouping more than one signle scalefactor band per section*/
+				if  (bit_stats[j][0] < bit_stats[2*j][0] + bit_stats[2*j+1][0]){
+
+					/* it is cheaper to combine surrounding sfb secionts into one larger huffman book section */
+					for(n=k;n<k+hop;n++) { /* write the optimal huffman book value for the new larger section */
+						if ( (book_vector[n]!=INTENSITY_HCB)&&(book_vector[n]!=INTENSITY_HCB2) ) { /* Don't merge with IS bands */
+							book_vector[n] = bit_stats[j][1];
+						}
+					}
+				} else {  /* it was cheaper to transmit the smaller huffman table sections */
+					bit_stats[j][0] = bit_stats[2*j][0] + bit_stats[2*j+1][0];
+				}
+			} else {  /* during the first stage of the iteration, all sfb's are individual sections */
+				if ( (book_vector[k]!=INTENSITY_HCB)&&(book_vector[k]!=INTENSITY_HCB2) ) {
+					book_vector[k] = bit_stats[j][1];  /* initially, set all sfb's to their own optimal section table values */
+				}
+			}
+			total_bit_count = total_bit_count +  bit_stats[j][0];
+			k=k+hop;
+//			m++;
+		}
+#ifdef SLOW
+	}
+#endif
+	/*   book_vector[k] = book_vector[k-1]; */
+	return(total_bit_count);
+}
+
+
+int NoiselessBitCount(CoderInfo *coderInfo,
+					  int *quant,
+					  int hop,
+					  int min_book_choice[112][3])
+{
+  int i,j,k;
+
+  /*
+     This function inputs:
+     - the quantized spectral data, 'quant[][]';
+     - all of the huffman codebooks, 'huff[][]';
+     - the size of the sections, in scalefactor bands (SFB's), 'hop';
+     - an empty matrix, min_book_choice[][] passed to it;
+
+     This function outputs:
+     - the matrix, min_book_choice.  It is a two dimensional matrix, with its
+     rows corresponding to spectral sections.  The 0th column corresponds to
+     the bits needed to code a section with 'hop' scalefactors bands wide, all using
+     the same huffman codebook.  The 1st column contains the huffman codebook number
+     that allows the minimum number of bits to be used.
+
+     Other notes:
+     - Initally, the dynamic range is calculated for each spectral section.  The section
+     can only be entropy coded with books that have an equal or greater dynamic range
+     than the section's spectral data.  The exception to this is for the 11th ESC codebook.
+     If the dynamic range is larger than 16, then an escape code is appended after the
+     table 11 codeword which encodes the larger value explicity in a pseudo-non-uniform
+     quantization method.
+
+     */
+
+	int max_sb_coeff;
+	int book_choice[12][2];
+	int total_bits_cost = 0;
+	int offset, length, end;
+	int q;
+	int write_flag = 0;
+
+	/* set local pointer to sfb_offset */
+	int* sfb_offset = coderInfo->sfb_offset;
+	int nr_of_sfb = coderInfo->nr_of_sfb;
+
+	/* each section is 'hop' scalefactor bands wide */
+	for (i=0; i < nr_of_sfb; i=i+hop){ 
+		if ((i+hop) > nr_of_sfb)
+			q = nr_of_sfb;
+		else
+			q = i+hop;
+
+		{
+			
+			/* find the maximum absolute value in the current spectral section, to see what tables are available to use */
+			max_sb_coeff = 0;
+			for (j=sfb_offset[i]; j<sfb_offset[q]; j++){  /* snl */
+				if (ABS(quant[j]) > max_sb_coeff)
+					max_sb_coeff = ABS(quant[j]);
+			}
+
+			j = 0;
+			offset = sfb_offset[i];
+			if ((i+hop) > nr_of_sfb){
+				end = sfb_offset[nr_of_sfb];
+			}
+			else
+				end = sfb_offset[q];
+			length = end - offset;
+
+			/* all spectral coefficients in this section are zero */
+			if (max_sb_coeff == 0) { 
+				book_choice[j][0] = OutputBits(coderInfo,0,quant,offset,length,write_flag);
+				book_choice[j++][1] = 0;
+
+			}
+			else {  /* if the section does have non-zero coefficients */
+				if(max_sb_coeff < 2){
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,1,quant,offset,length,write_flag);
+					book_choice[j++][1] = 1;
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,2,quant,offset,length,write_flag);
+					book_choice[j++][1] = 2;
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,3,quant,offset,length,write_flag);
+					book_choice[j++][1] = 3;
+				}
+				else if (max_sb_coeff < 3){
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,3,quant,offset,length,write_flag);
+					book_choice[j++][1] = 3;
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,4,quant,offset,length,write_flag);
+					book_choice[j++][1] = 4;
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,5,quant,offset,length,write_flag);
+					book_choice[j++][1] = 5;
+				}
+				else if (max_sb_coeff < 5){
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,5,quant,offset,length,write_flag);
+					book_choice[j++][1] = 5;
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,6,quant,offset,length,write_flag);
+					book_choice[j++][1] = 6;
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,7,quant,offset,length,write_flag);
+					book_choice[j++][1] = 7;
+				}
+				else if (max_sb_coeff < 8){
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,7,quant,offset,length,write_flag);
+					book_choice[j++][1] = 7;
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,8,quant,offset,length,write_flag);
+					book_choice[j++][1] = 8;
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,9,quant,offset,length,write_flag);
+					book_choice[j++][1] = 9;
+				}
+				else if (max_sb_coeff < 13){
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,9,quant,offset,length,write_flag);
+					book_choice[j++][1] = 9;
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,10,quant,offset,length,write_flag);
+					book_choice[j++][1] = 10;
+				}
+				/* (max_sb_coeff >= 13), choose table 11 */
+				else {
+					coderInfo->spectral_count = 0; /* just for debugging : using data and len vectors */
+					book_choice[j][0] = OutputBits(coderInfo,11,quant,offset,length,write_flag);
+					book_choice[j++][1] = 11;
+				}
+			}
+
+			/* find the minimum bit cost and table number for huffman coding this scalefactor section */
+			min_book_choice[i][0] = 100000;  
+			for(k=0;k<j;k++){
+				if (book_choice[k][0] < min_book_choice[i][0]){
+					min_book_choice[i][1] = book_choice[k][1];
+					min_book_choice[i][0] = book_choice[k][0];
+				}
+			}
+			total_bits_cost += min_book_choice[i][0];
+		}
+	}
+	return(total_bits_cost);
+}
+
+
+
+static int CalculateEscSequence(int input, int *len_esc_sequence)
+/* 
+   This function takes an element that is larger than 16 and generates the base10 value of the
+   equivalent escape sequence.  It returns the escape sequence in the variable, 'output'.  It
+   also passed the length of the escape sequence through the parameter, 'len_esc_sequence'.
+*/
+
+{
+	float x,y;
+	int output;
+	int N;
+
+	N = -1;
+	y = (float)ABS(input);
+	x = y / 16;
+
+	while (x >= 1) {
+		N++;
+		x = x/2;
+	}
+
+	*len_esc_sequence = 2*N + 5;  /* the length of the escape sequence in bits */
+
+	output = (int)((pow(2,N) - 1)*pow(2,N+5) + y - pow(2,N+4));
+	return(output);
+}
+
+int OutputBits(CoderInfo *coderInfo,
+			   int book,
+			   int *quant,
+			   int offset,
+			   int length,
+			   int write_flag)
+{
+  /* 
+     This function inputs 
+     - all the huffman codebooks, 'huff[]' 
+     - a specific codebook number, 'book'
+     - the quantized spectral data, 'quant[][]'
+     - the offset into the spectral data to begin scanning, 'offset'
+     - the 'length' of the segment to huffman code
+     -> therefore, the segment quant[CHANNEL][offset] to quant[CHANNEL][offset+length-1]
+     is huffman coded.
+     - a flag, 'write_flag' to determine whether the codebooks and lengths need to be written
+     to file.  If write_flag=0, then this function is being used only in the quantization
+     rate loop, and does not need to spend time writing the codebooks and lengths to file.
+     If write_flag=1, then it is being called by the function OutputBits(), which is 
+     sending the bitsteam out of the encoder.  
+
+     This function outputs 
+     - the number of bits required, 'bits'  using the prescribed codebook, book applied to 
+     the given segment of spectral data.
+
+     There are three parameters that are passed back and forth into this function.  data[]
+     and len[] are one-dimensional arrays that store the codebook values and their respective
+     bit lengths.  These are used when packing the data for the bitstream in OutputBits().  The
+     index into these arrays is 'coderInfo->spectral_count''.  It gets incremented internally in this
+     function as counter, then passed to the outside through outside_counter.  The next time
+     OutputBits() is called, counter starts at the value it left off from the previous call.
+
+   */
+ 
+	int esc_sequence;
+	int len_esc;
+	int index;
+	int bits=0;
+	int tmp;
+	int codebook,i,j;
+	int counter;
+
+	/* Set up local pointers to coderInfo elements data and len */
+	int* data= coderInfo -> data;
+	int* len=  coderInfo -> len;
+
+	counter = coderInfo->spectral_count;
+
+	/* This case also applies to intensity stereo encoding */
+	/*if (book == 0) { */ /* if using the zero codebook, data of zero length is sent */
+	if ((book == 0)||(book==INTENSITY_HCB2)||(book==INTENSITY_HCB)) {  /* if using the zero codebook, 
+		data of zero length is sent */
+		
+		if (write_flag) {
+			coderInfo->data[counter] = 0;
+			coderInfo->len[counter++] = 0;
+		}
+	}
+
+	if ((book == 1) || (book == 2)) {
+		for(i=offset;i<offset+length;i=i+4){
+			index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
+			if (book == 1) {
+				codebook = huff1[index][LASTINTAB];
+				tmp = huff1[index][FIRSTINTAB];
+			} else {
+				codebook = huff2[index][LASTINTAB];
+				tmp = huff2[index][FIRSTINTAB];
+			}
+			bits += tmp;
+			if (write_flag) {
+				data[counter] = codebook;
+				len[counter++] = tmp;
+			}
+		}
+	}
+
+	if ((book == 3) || (book == 4)) {
+		for(i=offset;i<offset+length;i=i+4){
+			index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
+			if (book == 3) {
+				codebook = huff3[index][LASTINTAB];
+				tmp = huff3[index][FIRSTINTAB];
+			} else {
+				codebook = huff4[index][LASTINTAB];
+				tmp = huff4[index][FIRSTINTAB];
+			}
+			bits = bits + tmp;
+			for(j=0;j<4;j++){
+				if(ABS(quant[i+j]) > 0) bits += 1; /* only for non-zero spectral coefficients */
+			}
+			if (write_flag) {
+				data[counter] = codebook;
+				len[counter++] = tmp;
+				for(j=0;j<4;j++){
+					if(quant[i+j] > 0) {  /* send out '0' if a positive value */
+						data[counter] = 0;
+						len[counter++] = 1;
+					}
+					if(quant[i+j] < 0) {  /* send out '1' if a negative value */
+						data[counter] = 1;
+						len[counter++] = 1;
+					}
+				}
+			}
+		}
+	}
+
+	if ((book == 5) || (book == 6)) {
+		for(i=offset;i<offset+length;i=i+2){
+			index = 9*(quant[i]) + (quant[i+1]) + 40;
+			if (book == 5) {
+				codebook = huff5[index][LASTINTAB];
+				tmp = huff5[index][FIRSTINTAB];
+			} else {
+				codebook = huff6[index][LASTINTAB];
+				tmp = huff6[index][FIRSTINTAB];
+			}
+			bits = bits + tmp;
+			if (write_flag) {
+				data[counter] = codebook;
+				len[counter++] = tmp;
+			}
+		}
+	}
+
+	if ((book == 7) || (book == 8)) {
+		for(i=offset;i<offset+length;i=i+2){
+			index = 8*ABS(quant[i]) + ABS(quant[i+1]);
+			if (book == 7) {
+				codebook = huff7[index][LASTINTAB];
+				tmp = huff7[index][FIRSTINTAB];
+			} else {
+				codebook = huff8[index][LASTINTAB];
+				tmp = huff8[index][FIRSTINTAB];
+			}
+			bits = bits + tmp;
+			for(j=0;j<2;j++){
+				if(ABS(quant[i+j]) > 0) bits += 1; /* only for non-zero spectral coefficients */
+			}
+			if (write_flag) {
+				data[counter] = codebook;
+				len[counter++] = tmp;
+				for(j=0;j<2;j++){
+					if(quant[i+j] > 0) {  /* send out '0' if a positive value */
+						data[counter] = 0;
+						len[counter++] = 1;
+					}
+					if(quant[i+j] < 0) {  /* send out '1' if a negative value */
+						data[counter] = 1;
+						len[counter++] = 1;
+					}
+				}
+			}
+		}
+	}
+
+	if ((book == 9) || (book == 10)) {
+		for(i=offset;i<offset+length;i=i+2){
+			index = 13*ABS(quant[i]) + ABS(quant[i+1]);
+			if (book == 9) {
+				codebook = huff9[index][LASTINTAB];
+				tmp = huff9[index][FIRSTINTAB];
+			} else {
+				codebook = huff10[index][LASTINTAB];
+				tmp = huff10[index][FIRSTINTAB];
+			}
+			bits = bits + tmp;
+			for(j=0;j<2;j++){
+				if(ABS(quant[i+j]) > 0) bits += 1; /* only for non-zero spectral coefficients */
+			}
+			if (write_flag) {
+				
+				data[counter] = codebook;
+				len[counter++] = tmp;
+
+				for(j=0;j<2;j++){
+					if(quant[i+j] > 0) {  /* send out '0' if a positive value */
+						data[counter] = 0;
+						len[counter++] = 1;
+					}
+					if(quant[i+j] < 0) {  /* send out '1' if a negative value */
+						data[counter] = 1;
+						len[counter++] = 1;
+					}
+				}
+			}
+		}
+	}
+
+	if ((book == 11)){
+		/* First, calculate the indecies into the huffman tables */
+
+		for(i=offset;i<offset+length;i=i+2){
+			if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) {  /* both codewords were above 16 */
+				/* first, code the orignal pair, with the larger value saturated to +/- 16 */
+				index = 17*16 + 16;
+			}
+			else if (ABS(quant[i]) >= 16) {  /* the first codeword was above 16, not the second one */
+				/* first, code the orignal pair, with the larger value saturated to +/- 16 */
+				index = 17*16 + ABS(quant[i+1]);
+			}
+			else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
+				index = 17*ABS(quant[i]) + 16;
+			}
+			else {  /* there were no values above 16, so no escape sequences */
+				index = 17*ABS(quant[i]) + ABS(quant[i+1]);
+			}
+
+			/* write out the codewords */
+
+			tmp = huff11[index][FIRSTINTAB];
+			codebook = huff11[index][LASTINTAB];
+			bits += tmp;
+			if (write_flag) {
+				data[counter] = codebook;
+				len[counter++] = tmp;
+			}
+			
+			/* Take care of the sign bits */
+
+			for(j=0;j<2;j++){
+				if(ABS(quant[i+j]) > 0) bits += 1; /* only for non-zero spectral coefficients */
+			}
+			if (write_flag) {
+				for(j=0;j<2;j++){
+					if(quant[i+j] > 0) {  /* send out '0' if a positive value */
+						data[counter] = 0;
+						len[counter++] = 1;
+					}
+					if(quant[i+j] < 0) {  /* send out '1' if a negative value */
+						data[counter] = 1;
+						len[counter++] = 1;
+					}
+				}
+			}
+
+			/* write out the escape sequences */
+
+			if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) {  /* both codewords were above 16 */
+				/* code and transmit the first escape_sequence */
+				esc_sequence = CalculateEscSequence(quant[i],&len_esc); 
+				bits += len_esc;
+				if (write_flag) {
+					data[counter] = esc_sequence;
+					len[counter++] = len_esc;
+				}
+
+				/* then code and transmit the second escape_sequence */
+				esc_sequence = CalculateEscSequence(quant[i+1],&len_esc);
+				bits += len_esc;
+				if (write_flag) {
+					data[counter] = esc_sequence;
+					len[counter++] = len_esc;
+				}
+			}
+
+			else if (ABS(quant[i]) >= 16) {  /* the first codeword was above 16, not the second one */
+				/* code and transmit the escape_sequence */
+				esc_sequence = CalculateEscSequence(quant[i],&len_esc); 
+				bits += len_esc;
+				if (write_flag) {
+					data[counter] = esc_sequence;
+					len[counter++] = len_esc;
+				}
+			}
+
+			else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
+				/* code and transmit the escape_sequence */
+				esc_sequence = CalculateEscSequence(quant[i+1],&len_esc); 
+				bits += len_esc;
+				if (write_flag) {
+					data[counter] = esc_sequence;
+					len[counter++] = len_esc;
+				}
+			} 
+		}
+	}
+
+	coderInfo -> spectral_count = counter;  /* send the current count back to the outside world */
+
+	return(bits);
+}
+
+int SortBookNumbers(CoderInfo *coderInfo,
+					BitStream *bitStream,
+					int writeFlag)
+{
+  /*
+    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:
+
+    {sect_cb[0], length_segment[0], ... ,sect_cb[num_of_sections], length_segment[num_of_sections]}
+
+    The above syntax is true, unless there is an escape sequence.  An
+    escape sequence occurs when a section is longer than 2 ^ (bit_len)
+    long in units of scalefactor bands.  Also, the integer returned from
+    this function is the number of bits written in the bitstream,
+    'bit_count'.
+
+    This function supports both long and short blocks.
+    */
+
+	int i;
+	int repeat_counter;
+	int bit_count = 0;
+	int previous;
+	int max, bit_len/*,sfbs*/;
+	int max_sfb,g,band;
+
+	/* Set local pointers to coderInfo elements */
+	int* book_vector = coderInfo->book_vector;
+
+	if (coderInfo->block_type == ONLY_SHORT_WINDOW){
+		max = 7;
+		bit_len = 3;
+	} else {  /* the block_type is a long,start, or stop window */
+		max = 31;
+		bit_len = 5;
+	}
+
+	/* Compute number of scalefactor bands */
+	max_sfb = coderInfo->nr_of_sfb / coderInfo->num_window_groups;
+
+
+	for (g = 0; g < coderInfo->num_window_groups; g++) {
+		band=g*max_sfb;
+
+		repeat_counter=1;
+
+		previous = book_vector[band];
+		if (writeFlag) {
+			PutBit(bitStream,book_vector[band],4);
+		}
+		bit_count += 4;
+
+		for (i=band+1;i<band+max_sfb;i++) {
+			if( (book_vector[i] != previous)) {
+				if (writeFlag) {
+					PutBit(bitStream,repeat_counter,bit_len);
+				}
+				bit_count += bit_len;
+
+				if (repeat_counter == max){  /* in case you need to terminate an escape sequence */
+					if (writeFlag)
+						PutBit(bitStream,0,bit_len);
+					bit_count += bit_len;
+				}
+
+				if (writeFlag)
+					PutBit(bitStream,book_vector[i],4);
+				bit_count += 4;
+				previous = book_vector[i];
+				repeat_counter=1;
+
+			}
+			/* if the length of the section is longer than the amount of bits available in */
+			/* the bitsream, "max", then start up an escape sequence */
+			else if ((book_vector[i] == previous) && (repeat_counter == max)) {
+				if (writeFlag) {
+					PutBit(bitStream,repeat_counter,bit_len);
+				}
+				bit_count += bit_len;
+				repeat_counter = 1;
+			}
+			else {
+				repeat_counter++;
+			}
+		}
+
+		if (writeFlag)
+			PutBit(bitStream,repeat_counter,bit_len);
+		bit_count += bit_len;
+
+		if (repeat_counter == max) {  /* special case if the last section length is an */
+			/* escape sequence */
+			if (writeFlag)
+				PutBit(bitStream,0,bit_len);
+			bit_count += bit_len;
+		}
+
+
+	}  /* Bottom of group iteration */
+
+	return bit_count;
+}
+
+int WriteScalefactors(CoderInfo *coderInfo,
+					  BitStream *bitStream,
+					  int writeFlag)
+							 
+{
+	/* this function takes care of counting the number of bits necessary */
+	/* to encode the scalefactors.  In addition, if the writeFlag == 1, */
+	/* then the scalefactors are written out the bitStream output bit */
+	/* stream.  it returns k, the number of bits written to the bitstream*/
+
+	int i,j,bit_count=0;
+	int diff,length,codeword;
+	int previous_scale_factor;
+	int previous_is_factor;       /* Intensity stereo */
+	int index = 0;
+	int nr_of_sfb_per_group;
+
+	/* set local pointer to coderInfo elements */
+	int* scale_factors = coderInfo->scale_factor;
+
+	if (coderInfo->block_type == ONLY_SHORT_WINDOW) { /* short windows */
+		nr_of_sfb_per_group = coderInfo->nr_of_sfb/coderInfo->num_window_groups;
+	} else {
+		nr_of_sfb_per_group = coderInfo->nr_of_sfb;
+		coderInfo->num_window_groups = 1;
+		coderInfo->window_group_length[0] = 1;
+	}
+
+	previous_scale_factor = coderInfo->global_gain;
+	previous_is_factor = 0;
+    
+	for(j=0; j<coderInfo->num_window_groups; j++){
+		for(i=0;i<nr_of_sfb_per_group;i++) {  
+			/* test to see if any codebooks in a group are zero */
+			if ( (coderInfo->book_vector[index]==INTENSITY_HCB) ||
+				(coderInfo->book_vector[index]==INTENSITY_HCB2) ) {
+				/* only send scalefactors if using non-zero codebooks */
+				diff = scale_factors[index] - previous_is_factor;
+				if ((diff < 60)&&(diff >= -60))
+					length = huff12[diff+60][FIRSTINTAB];
+				else length = 0;
+				bit_count+=length;
+				previous_is_factor = scale_factors[index];
+				if (writeFlag == 1 ) {   
+					codeword = huff12[diff+60][LASTINTAB];
+					PutBit(bitStream,codeword,length); 
+				}
+			} else if (coderInfo->book_vector[index]) {
+				/* only send scalefactors if using non-zero codebooks */
+				diff = scale_factors[index] - previous_scale_factor;
+				if ((diff < 60)&&(diff >= -60))
+					length = huff12[diff+60][FIRSTINTAB];
+				else length = 0;
+				bit_count+=length;
+				previous_scale_factor = scale_factors[index];
+				if (writeFlag == 1 ) {   
+					codeword = huff12[diff+60][LASTINTAB];
+					PutBit(bitStream,codeword,length); 
+				}
+			}
+			index++;
+		}
+	}
+	return bit_count;
+}
+
--- /dev/null
+++ b/libfaac/huffman.h
@@ -1,0 +1,78 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: huffman.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef HUFFMAN_H
+#define HUFFMAN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "bitstream.h"
+#include "coder.h"
+
+/* Huffman tables */
+#define MAXINDEX 289
+#define NUMINTAB 2
+#define FIRSTINTAB 0
+#define LASTINTAB 1
+
+#define INTENSITY_HCB 15
+#define INTENSITY_HCB2 14
+
+
+#define ABS(A) ((A) < 0 ? (-A) : (A))
+
+#include "frame.h"
+
+void HuffmanInit(CoderInfo *coderInfo, unsigned int numChannels);
+void HuffmanEnd(CoderInfo *coderInfo, unsigned int numChannels);
+
+int BitSearch(CoderInfo *coderInfo,
+			  int *quant);
+
+int NoiselessBitCount(CoderInfo *coderInfo,
+					  int *quant,
+					  int hop,
+					  int min_book_choice[112][3]);
+
+static int CalculateEscSequence(int input, int *len_esc_sequence);
+
+int OutputBits(CoderInfo *coderInfo,
+			   int book,
+			   int *quant,
+			   int offset,
+			   int length,
+			   int write_flag);
+
+int SortBookNumbers(CoderInfo *coderInfo,
+					BitStream *bitStream,
+					int writeFlag);
+
+int WriteScalefactors(CoderInfo *coderInfo,
+					  BitStream *bitStream,
+					  int writeFlag);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* HUFFMAN_H */
--- /dev/null
+++ b/libfaac/hufftab.h
@@ -1,0 +1,331 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: hufftab.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+unsigned short huff1[][2] = {
+		{ 11,  2040},
+		{ 9,  497},{ 11,  2045},{ 10,  1013},{ 7,  104},{ 10,  1008},
+		{ 11,  2039},{ 9,  492},{ 11,  2037},{ 10,  1009},{ 7,  114},
+		{ 10,  1012},{ 7,  116},{ 5,  17},{ 7,  118},{ 9,  491},
+		{ 7,  108},{ 10,  1014},{ 11,  2044},{ 9,  481},{ 11,  2033},
+		{ 9,  496},{ 7,  97},{ 9,  502},{ 11,  2034},{ 9,  490},
+		{ 11,  2043},{ 9,  498},{ 7,  105},{ 9,  493},{ 7,  119},
+		{ 5,  23},{ 7,  111},{ 9,  486},{ 7,  100},{ 9,  485},
+		{ 7,  103},{ 5,  21},{ 7,  98},{ 5,  18},{ 1,  0},
+		{ 5,  20},{ 7,  101},{ 5,  22},{ 7,  109},{ 9,  489},
+		{ 7,  99},{ 9,  484},{ 7,  107},{ 5,  19},{ 7,  113},
+		{ 9,  483},{ 7,  112},{ 9,  499},{ 11,  2046},{ 9,  487},
+		{ 11,  2035},{ 9,  495},{ 7,  96},{ 9,  494},{ 11,  2032},
+		{ 9,  482},{ 11,  2042},{ 10,  1011},{ 7,  106},{ 9,  488},
+		{ 7,  117},{ 5,  16},{ 7,  115},{ 9,  500},{ 7,  110},
+		{ 10,  1015},{ 11,  2038},{ 9,  480},{ 11,  2041},{ 10,  1010},
+		{ 7,  102},{ 9,  501},{ 11,  2047},{ 9,  503},{ 11,  2036}
+	};
+unsigned short huff2[][2] = {
+	{ 9,  499},
+		{ 7,  111},{ 9,  509},{ 8,  235},{ 6,  35},{ 8,  234},
+		{ 9,  503},{ 8,  232},{ 9,  506},{ 8,  242},{ 6,  45},
+		{ 7,  112},{ 6,  32},{ 5,  6},{ 6,  43},{ 7,  110},
+		{ 6,  40},{ 8,  233},{ 9,  505},{ 7,  102},{ 8,  248},
+		{ 8,  231},{ 6,  27},{ 8,  241},{ 9,  500},{ 7,  107},
+		{ 9,  501},{ 8,  236},{ 6,  42},{ 7,  108},{ 6,  44},
+		{ 5,  10},{ 6,  39},{ 7,  103},{ 6,  26},{ 8,  245},
+		{ 6,  36},{ 5,  8},{ 6,  31},{ 5,  9},{ 3,  0},
+		{ 5,  7},{ 6,  29},{ 5,  11},{ 6,  48},{ 8,  239},
+		{ 6,  28},{ 7,  100},{ 6,  30},{ 5,  12},{ 6,  41},
+		{ 8,  243},{ 6,  47},{ 8,  240},{ 9,  508},{ 7,  113},
+		{ 9,  498},{ 8,  244},{ 6,  33},{ 8,  230},{ 8,  247},
+		{ 7,  104},{ 9,  504},{ 8,  238},{ 6,  34},{ 7,  101},
+		{ 6,  49},{ 4,  2},{ 6,  38},{ 8,  237},{ 6,  37},
+		{ 7,  106},{ 9,  507},{ 7,  114},{ 9,  510},{ 7,  105},
+		{ 6,  46},{ 8,  246},{ 9,  511},{ 7,  109},{ 9,  502}
+	};
+unsigned short huff3[][2] = {
+		{ 1,  0},
+		{ 4,  9},{ 8,  239},{ 4,  11},{ 5,  25},{ 8,  240},
+		{ 9,  491},{ 9,  486},{ 10,  1010},{ 4,  10},{ 6,  53},
+		{ 9,  495},{ 6,  52},{ 6,  55},{ 9,  489},{ 9,  493},
+		{ 9,  487},{ 10,  1011},{ 9,  494},{ 10,  1005},{ 13,  8186},
+		{ 9,  492},{ 9,  498},{ 11,  2041},{ 11,  2040},{ 10,  1016},
+		{ 12,  4088},{ 4,  8},{ 6,  56},{ 10,  1014},{ 6,  54},
+		{ 7,  117},{ 10,  1009},{ 10,  1003},{ 10,  1004},{ 12,  4084},
+		{ 5,  24},{ 7,  118},{ 11,  2036},{ 6,  57},{ 7,  116},
+		{ 10,  1007},{ 9,  499},{ 9,  500},{ 11,  2038},{ 9,  488},
+		{ 10,  1002},{ 13,  8188},{ 8,  242},{ 9,  497},{ 12,  4091},
+		{ 10,  1013},{ 11,  2035},{ 12,  4092},{ 8,  238},{ 10,  1015},
+		{ 15,  32766},{ 9,  496},{ 11,  2037},{ 15,  32765},{ 13,  8187},
+		{ 14,  16378},{ 16,  65535},{ 8,  241},{ 10,  1008},{ 14,  16380},
+		{ 9,  490},{ 10,  1006},{ 14,  16379},{ 12,  4086},{ 12,  4090},
+		{ 15,  32764},{ 11,  2034},{ 12,  4085},{ 16,  65534},{ 10,  1012},
+		{ 11,  2039},{ 15,  32763},{ 12,  4087},{ 12,  4089},{ 15,  32762}
+	};
+unsigned short huff4[][2] = {
+		{ 4,  7},
+		{ 5,  22},{ 8,  246},{ 5,  24},{ 4,  8},{ 8,  239},
+		{ 9,  495},{ 8,  243},{ 11,  2040},{ 5,  25},{ 5,  23},
+		{ 8,  237},{ 5,  21},{ 4,  1},{ 8,  226},{ 8,  240},
+		{ 7,  112},{ 10,  1008},{ 9,  494},{ 8,  241},{ 11,  2042},
+		{ 8,  238},{ 8,  228},{ 10,  1010},{ 11,  2038},{ 10,  1007},
+		{ 11,  2045},{ 4,  5},{ 5,  20},{ 8,  242},{ 4,  9},
+		{ 4,  4},{ 8,  229},{ 8,  244},{ 8,  232},{ 10,  1012},
+		{ 4,  6},{ 4,  2},{ 8,  231},{ 4,  3},{ 4,  0},
+		{ 7,  107},{ 8,  227},{ 7,  105},{ 9,  499},{ 8,  235},
+		{ 8,  230},{ 10,  1014},{ 7,  110},{ 7,  106},{ 9,  500},
+		{ 10,  1004},{ 9,  496},{ 10,  1017},{ 8,  245},{ 8,  236},
+		{ 11,  2043},{ 8,  234},{ 7,  111},{ 10,  1015},{ 11,  2041},
+		{ 10,  1011},{ 12,  4095},{ 8,  233},{ 7,  109},{ 10,  1016},
+		{ 7,  108},{ 7,  104},{ 9,  501},{ 10,  1006},{ 9,  498},
+		{ 11,  2036},{ 11,  2039},{ 10,  1009},{ 12,  4094},{ 10,  1005},
+		{ 9,  497},{ 11,  2037},{ 11,  2046},{ 10,  1013},{ 11,  2044}
+	};
+unsigned short huff5[][2] = {
+		{ 13,  8191},
+		{ 12,  4087},{ 11,  2036},{ 11,  2024},{ 10,  1009},{ 11,  2030},
+		{ 11,  2041},{ 12,  4088},{ 13,  8189},{ 12,  4093},{ 11,  2033},
+		{ 10,  1000},{ 9,  488},{ 8,  240},{ 9,  492},{ 10,  1006},
+		{ 11,  2034},{ 12,  4090},{ 12,  4084},{ 10,  1007},{ 9,  498},
+		{ 8,  232},{ 7,  112},{ 8,  236},{ 9,  496},{ 10,  1002},
+		{ 11,  2035},{ 11,  2027},{ 9,  491},{ 8,  234},{ 5,  26},
+		{ 4,  8},{ 5,  25},{ 8,  238},{ 9,  495},{ 11,  2029},
+		{ 10,  1008},{ 8,  242},{ 7,  115},{ 4,  11},{ 1,  0},
+		{ 4,  10},{ 7,  113},{ 8,  243},{ 11,  2025},{ 11,  2031},
+		{ 9,  494},{ 8,  239},{ 5,  24},{ 4,  9},{ 5,  27},
+		{ 8,  235},{ 9,  489},{ 11,  2028},{ 11,  2038},{ 10,  1003},
+		{ 9,  499},{ 8,  237},{ 7,  114},{ 8,  233},{ 9,  497},
+		{ 10,  1005},{ 11,  2039},{ 12,  4086},{ 11,  2032},{ 10,  1001},
+		{ 9,  493},{ 8,  241},{ 9,  490},{ 10,  1004},{ 11,  2040},
+		{ 12,  4089},{ 13,  8188},{ 12,  4092},{ 12,  4085},{ 11,  2026},
+		{ 10,  1011},{ 10,  1010},{ 11,  2037},{ 12,  4091},{ 13,  8190}
+	};
+unsigned short huff6[][2] = {
+		{ 11,  2046},
+		{ 10,  1021},{ 9,  497},{ 9,  491},{ 9,  500},{ 9,  490},
+		{ 9,  496},{ 10,  1020},{ 11,  2045},{ 10,  1014},{ 9,  485},
+		{ 8,  234},{ 7,  108},{ 7,  113},{ 7,  104},{ 8,  240},
+		{ 9,  486},{ 10,  1015},{ 9,  499},{ 8,  239},{ 6,  50},
+		{ 6,  39},{ 6,  40},{ 6,  38},{ 6,  49},{ 8,  235},
+		{ 9,  503},{ 9,  488},{ 7,  111},{ 6,  46},{ 4,  8},
+		{ 4,  4},{ 4,  6},{ 6,  41},{ 7,  107},{ 9,  494},
+		{ 9,  495},{ 7,  114},{ 6,  45},{ 4,  2},{ 4,  0},
+		{ 4,  3},{ 6,  47},{ 7,  115},{ 9,  506},{ 9,  487},
+		{ 7,  110},{ 6,  43},{ 4,  7},{ 4,  1},{ 4,  5},
+		{ 6,  44},{ 7,  109},{ 9,  492},{ 9,  505},{ 8,  238},
+		{ 6,  48},{ 6,  36},{ 6,  42},{ 6,  37},{ 6,  51},
+		{ 8,  236},{ 9,  498},{ 10,  1016},{ 9,  484},{ 8,  237},
+		{ 7,  106},{ 7,  112},{ 7,  105},{ 7,  116},{ 8,  241},
+		{ 10,  1018},{ 11,  2047},{ 10,  1017},{ 9,  502},{ 9,  493},
+		{ 9,  504},{ 9,  489},{ 9,  501},{ 10,  1019},{ 11,  2044}
+	};
+unsigned short huff7[][2] = {
+		{ 1,  0},
+		{ 3,  5},{ 6,  55},{ 7,  116},{ 8,  242},{ 9,  491},
+		{ 10,  1005},{ 11,  2039},{ 3,  4},{ 4,  12},{ 6,  53},
+		{ 7,  113},{ 8,  236},{ 8,  238},{ 9,  494},{ 9,  501},
+		{ 6,  54},{ 6,  52},{ 7,  114},{ 8,  234},{ 8,  241},
+		{ 9,  489},{ 9,  499},{ 10,  1013},{ 7,  115},{ 7,  112},
+		{ 8,  235},{ 8,  240},{ 9,  497},{ 9,  496},{ 10,  1004},
+		{ 10,  1018},{ 8,  243},{ 8,  237},{ 9,  488},{ 9,  495},
+		{ 10,  1007},{ 10,  1009},{ 10,  1017},{ 11,  2043},{ 9,  493},
+		{ 8,  239},{ 9,  490},{ 9,  498},{ 10,  1011},{ 10,  1016},
+		{ 11,  2041},{ 11,  2044},{ 10,  1006},{ 9,  492},{ 9,  500},
+		{ 10,  1012},{ 10,  1015},{ 11,  2040},{ 12,  4093},{ 12,  4094},
+		{ 11,  2038},{ 10,  1008},{ 10,  1010},{ 10,  1014},{ 11,  2042},
+		{ 11,  2045},{ 12,  4092},{ 12,  4095}
+	};
+unsigned short huff8[][2] = {
+		{ 5,  14},
+		{ 4,  5},{ 5,  16},{ 6,  48},{ 7,  111},{ 8,  241},
+		{ 9,  506},{ 10,  1022},{ 4,  3},{ 3,  0},{ 4,  4},
+		{ 5,  18},{ 6,  44},{ 7,  106},{ 7,  117},{ 8,  248},
+		{ 5,  15},{ 4,  2},{ 4,  6},{ 5,  20},{ 6,  46},
+		{ 7,  105},{ 7,  114},{ 8,  245},{ 6,  47},{ 5,  17},
+		{ 5,  19},{ 6,  42},{ 6,  50},{ 7,  108},{ 8,  236},
+		{ 8,  250},{ 7,  113},{ 6,  43},{ 6,  45},{ 6,  49},
+		{ 7,  109},{ 7,  112},{ 8,  242},{ 9,  505},{ 8,  239},
+		{ 7,  104},{ 6,  51},{ 7,  107},{ 7,  110},{ 8,  238},
+		{ 8,  249},{ 10,  1020},{ 9,  504},{ 7,  116},{ 7,  115},
+		{ 8,  237},{ 8,  240},{ 8,  246},{ 9,  502},{ 9,  509},
+		{ 10,  1021},{ 8,  243},{ 8,  244},{ 8,  247},{ 9,  503},
+		{ 9,  507},{ 9,  508},{ 10,  1023}
+	};
+unsigned short huff9[][2] = {
+		{ 1,  0},
+		{ 3,  5},{ 6,  55},{ 8,  231},{ 9,  478},{ 10,  974},
+		{ 10,  985},{ 11,  1992},{ 11,  1997},{ 12,  4040},{ 12,  4061},
+		{ 13,  8164},{ 13,  8172},{ 3,  4},{ 4,  12},{ 6,  53},
+		{ 7,  114},{ 8,  234},{ 8,  237},{ 9,  482},{ 10,  977},
+		{ 10,  979},{ 10,  992},{ 11,  2008},{ 12,  4047},{ 12,  4053},
+		{ 6,  54},{ 6,  52},{ 7,  113},{ 8,  232},{ 8,  236},
+		{ 9,  481},{ 10,  975},{ 10,  989},{ 10,  987},{ 11,  2000},
+		{ 12,  4039},{ 12,  4052},{ 12,  4068},{ 8,  230},{ 7,  112},
+		{ 8,  233},{ 9,  477},{ 9,  483},{ 10,  978},{ 10,  988},
+		{ 11,  1996},{ 11,  1994},{ 11,  2014},{ 12,  4056},{ 12,  4074},
+		{ 13,  8155},{ 9,  479},{ 8,  235},{ 9,  476},{ 9,  486},
+		{ 10,  981},{ 10,  990},{ 11,  1995},{ 11,  2013},{ 11,  2012},
+		{ 12,  4045},{ 12,  4066},{ 12,  4071},{ 13,  8161},{ 10,  976},
+		{ 9,  480},{ 9,  484},{ 10,  982},{ 11,  1989},{ 11,  2001},
+		{ 11,  2011},{ 12,  4050},{ 11,  2016},{ 12,  4057},{ 12,  4075},
+		{ 13,  8163},{ 13,  8169},{ 11,  1988},{ 9,  485},{ 10,  983},
+		{ 11,  1990},{ 11,  1999},{ 11,  2010},{ 12,  4043},{ 12,  4058},
+		{ 12,  4067},{ 12,  4073},{ 13,  8166},{ 13,  8179},{ 13,  8183},
+		{ 11,  2003},{ 10,  984},{ 10,  993},{ 11,  2004},{ 11,  2009},
+		{ 12,  4051},{ 12,  4062},{ 13,  8157},{ 13,  8153},{ 13,  8162},
+		{ 13,  8170},{ 13,  8177},{ 13,  8182},{ 11,  2002},{ 10,  980},
+		{ 10,  986},{ 11,  1991},{ 11,  2007},{ 11,  2018},{ 12,  4046},
+		{ 12,  4059},{ 13,  8152},{ 13,  8174},{ 14,  16368},{ 13,  8180},
+		{ 14,  16370},{ 11,  2017},{ 10,  991},{ 11,  1993},{ 11,  2006},
+		{ 12,  4042},{ 12,  4048},{ 12,  4069},{ 12,  4070},{ 13,  8171},
+		{ 13,  8175},{ 14,  16371},{ 14,  16372},{ 14,  16373},{ 12,  4064},
+		{ 11,  1998},{ 11,  2005},{ 12,  4038},{ 12,  4049},{ 12,  4065},
+		{ 13,  8160},{ 13,  8168},{ 13,  8176},{ 14,  16369},{ 14,  16376},
+		{ 14,  16374},{ 15,  32764},{ 12,  4072},{ 11,  2015},{ 12,  4041},
+		{ 12,  4055},{ 12,  4060},{ 13,  8156},{ 13,  8159},{ 13,  8173},
+		{ 13,  8181},{ 14,  16377},{ 14,  16379},{ 15,  32765},{ 15,  32766},
+		{ 13,  8167},{ 12,  4044},{ 12,  4054},{ 12,  4063},{ 13,  8158},
+		{ 13,  8154},{ 13,  8165},{ 13,  8178},{ 14,  16378},{ 14,  16375},
+		{ 14,  16380},{ 14,  16381},{ 15,  32767}
+	};
+unsigned short huff10[][2] = {
+		{ 6,  34},
+		{ 5,  8},{ 6,  29},{ 6,  38},{ 7,  95},{ 8,  211},
+		{ 9,  463},{ 10,  976},{ 10,  983},{ 10,  1005},{ 11,  2032},
+		{ 11,  2038},{ 12,  4093},{ 5,  7},{ 4,  0},{ 4,  1},
+		{ 5,  9},{ 6,  32},{ 7,  84},{ 7,  96},{ 8,  213},
+		{ 8,  220},{ 9,  468},{ 10,  973},{ 10,  990},{ 11,  2023},
+		{ 6,  28},{ 4,  2},{ 5,  6},{ 5,  12},{ 6,  30},
+		{ 6,  40},{ 7,  91},{ 8,  205},{ 8,  217},{ 9,  462},
+		{ 9,  476},{ 10,  985},{ 10,  1009},{ 6,  37},{ 5,  11},
+		{ 5,  10},{ 5,  13},{ 6,  36},{ 7,  87},{ 7,  97},
+		{ 8,  204},{ 8,  221},{ 9,  460},{ 9,  478},{ 10,  979},
+		{ 10,  999},{ 7,  93},{ 6,  33},{ 6,  31},{ 6,  35},
+		{ 6,  39},{ 7,  89},{ 7,  100},{ 8,  216},{ 8,  223},
+		{ 9,  466},{ 9,  482},{ 10,  989},{ 10,  1006},{ 8,  209},
+		{ 7,  85},{ 6,  41},{ 7,  86},{ 7,  88},{ 7,  98},
+		{ 8,  206},{ 8,  224},{ 8,  226},{ 9,  474},{ 10,  980},
+		{ 10,  995},{ 11,  2027},{ 9,  457},{ 7,  94},{ 7,  90},
+		{ 7,  92},{ 7,  99},{ 8,  202},{ 8,  218},{ 9,  455},
+		{ 9,  458},{ 9,  480},{ 10,  987},{ 10,  1000},{ 11,  2028},
+		{ 9,  483},{ 8,  210},{ 8,  203},{ 8,  208},{ 8,  215},
+		{ 8,  219},{ 9,  454},{ 9,  469},{ 9,  472},{ 10,  970},
+		{ 10,  986},{ 11,  2026},{ 11,  2033},{ 9,  481},{ 8,  212},
+		{ 8,  207},{ 8,  214},{ 8,  222},{ 8,  225},{ 9,  464},
+		{ 9,  470},{ 10,  977},{ 10,  981},{ 10,  1010},{ 11,  2030},
+		{ 11,  2043},{ 10,  1001},{ 9,  461},{ 9,  456},{ 9,  459},
+		{ 9,  465},{ 9,  471},{ 9,  479},{ 10,  975},{ 10,  992},
+		{ 10,  1007},{ 11,  2022},{ 11,  2040},{ 12,  4090},{ 10,  1003},
+		{ 9,  477},{ 9,  467},{ 9,  473},{ 9,  475},{ 10,  978},
+		{ 10,  972},{ 10,  988},{ 10,  1002},{ 11,  2029},{ 11,  2035},
+		{ 11,  2041},{ 12,  4089},{ 11,  2034},{ 10,  974},{ 9,  484},
+		{ 10,  971},{ 10,  984},{ 10,  982},{ 10,  994},{ 10,  997},
+		{ 11,  2024},{ 11,  2036},{ 11,  2037},{ 11,  2039},{ 12,  4091},
+		{ 11,  2042},{ 10,  1004},{ 10,  991},{ 10,  993},{ 10,  996},
+		{ 10,  998},{ 10,  1008},{ 11,  2025},{ 11,  2031},{ 12,  4088},
+		{ 12,  4094},{ 12,  4092},{ 12,  4095}
+	};
+unsigned short huff11[][2] = {
+		{ 4,  0},
+		{ 5,  6},{ 6,  25},{ 7,  61},{ 8,  156},{ 8,  198},
+		{ 9,  423},{ 10,  912},{ 10,  962},{ 10,  991},{ 11,  2022},
+		{ 11,  2035},{ 12,  4091},{ 11,  2028},{ 12,  4090},{ 12,  4094},
+		{ 10,  910},{ 5,  5},{ 4,  1},{ 5,  8},{ 6,  20},
+		{ 7,  55},{ 7,  66},{ 8,  146},{ 8,  175},{ 9,  401},
+		{ 9,  421},{ 9,  437},{ 10,  926},{ 10,  960},{ 10,  930},
+		{ 10,  973},{ 11,  2006},{ 8,  174},{ 6,  23},{ 5,  7},
+		{ 5,  9},{ 6,  24},{ 7,  57},{ 7,  64},{ 8,  142},
+		{ 8,  163},{ 8,  184},{ 9,  409},{ 9,  428},{ 9,  449},
+		{ 10,  945},{ 10,  918},{ 10,  958},{ 10,  970},{ 8,  157},
+		{ 7,  60},{ 6,  21},{ 6,  22},{ 6,  26},{ 7,  59},
+		{ 7,  68},{ 8,  145},{ 8,  165},{ 8,  190},{ 9,  406},
+		{ 9,  430},{ 9,  441},{ 10,  929},{ 10,  913},{ 10,  933},
+		{ 10,  981},{ 8,  148},{ 8,  154},{ 7,  54},{ 7,  56},
+		{ 7,  58},{ 7,  65},{ 8,  140},{ 8,  155},{ 8,  176},
+		{ 8,  195},{ 9,  414},{ 9,  427},{ 9,  444},{ 10,  927},
+		{ 10,  911},{ 10,  937},{ 10,  975},{ 8,  147},{ 8,  191},
+		{ 7,  62},{ 7,  63},{ 7,  67},{ 7,  69},{ 8,  158},
+		{ 8,  167},{ 8,  185},{ 9,  404},{ 9,  418},{ 9,  442},
+		{ 9,  451},{ 10,  934},{ 10,  935},{ 10,  955},{ 10,  980},
+		{ 8,  159},{ 9,  416},{ 8,  143},{ 8,  141},{ 8,  144},
+		{ 8,  152},{ 8,  166},{ 8,  182},{ 8,  196},{ 9,  415},
+		{ 9,  431},{ 9,  447},{ 10,  921},{ 10,  959},{ 10,  948},
+		{ 10,  969},{ 10,  999},{ 8,  168},{ 9,  438},{ 8,  171},
+		{ 8,  164},{ 8,  170},{ 8,  178},{ 8,  194},{ 8,  197},
+		{ 9,  408},{ 9,  420},{ 9,  440},{ 10,  908},{ 10,  932},
+		{ 10,  964},{ 10,  966},{ 10,  989},{ 10,  1000},{ 8,  173},
+		{ 10,  943},{ 9,  402},{ 8,  189},{ 8,  188},{ 9,  398},
+		{ 9,  407},{ 9,  410},{ 9,  419},{ 9,  433},{ 10,  909},
+		{ 10,  920},{ 10,  951},{ 10,  979},{ 10,  977},{ 10,  987},
+		{ 11,  2013},{ 8,  180},{ 10,  990},{ 9,  425},{ 9,  411},
+		{ 9,  412},{ 9,  417},{ 9,  426},{ 9,  429},{ 9,  435},
+		{ 10,  907},{ 10,  946},{ 10,  952},{ 10,  974},{ 10,  993},
+		{ 10,  992},{ 11,  2002},{ 11,  2021},{ 8,  183},{ 11,  2019},
+		{ 9,  443},{ 9,  424},{ 9,  422},{ 9,  432},{ 9,  434},
+		{ 9,  439},{ 10,  923},{ 10,  922},{ 10,  954},{ 10,  949},
+		{ 10,  982},{ 11,  2007},{ 10,  996},{ 11,  2008},{ 11,  2026},
+		{ 8,  186},{ 11,  2024},{ 10,  928},{ 9,  445},{ 9,  436},
+		{ 10,  906},{ 9,  452},{ 10,  914},{ 10,  938},{ 10,  944},
+		{ 10,  956},{ 10,  983},{ 11,  2004},{ 11,  2012},{ 11,  2011},
+		{ 11,  2005},{ 11,  2032},{ 8,  193},{ 11,  2043},{ 10,  968},
+		{ 10,  931},{ 10,  917},{ 10,  925},{ 10,  940},{ 10,  942},
+		{ 10,  965},{ 10,  984},{ 10,  994},{ 10,  998},{ 11,  2020},
+		{ 11,  2023},{ 11,  2016},{ 11,  2025},{ 11,  2039},{ 9,  400},
+		{ 11,  2034},{ 10,  915},{ 9,  446},{ 9,  448},{ 10,  916},
+		{ 10,  919},{ 10,  941},{ 10,  963},{ 10,  961},{ 10,  978},
+		{ 11,  2010},{ 11,  2009},{ 11,  2015},{ 11,  2027},{ 11,  2036},
+		{ 11,  2042},{ 9,  405},{ 11,  2040},{ 10,  957},{ 10,  924},
+		{ 10,  939},{ 10,  936},{ 10,  947},{ 10,  953},{ 10,  976},
+		{ 10,  995},{ 10,  997},{ 11,  2018},{ 11,  2014},{ 11,  2029},
+		{ 11,  2033},{ 11,  2041},{ 11,  2044},{ 9,  403},{ 12,  4093},
+		{ 10,  988},{ 10,  950},{ 10,  967},{ 10,  972},{ 10,  971},
+		{ 10,  985},{ 10,  986},{ 11,  2003},{ 11,  2017},{ 11,  2030},
+		{ 11,  2031},{ 11,  2037},{ 11,  2038},{ 12,  4092},{ 12,  4095},
+		{ 9,  413},{ 9,  450},{ 8,  181},{ 8,  161},{ 8,  150},
+		{ 8,  151},{ 8,  149},{ 8,  153},{ 8,  160},{ 8,  162},
+		{ 8,  172},{ 8,  169},{ 8,  177},{ 8,  179},{ 8,  187},
+		{ 8,  192},{ 9,  399},{ 5,  4}
+	};
+unsigned int huff12[][2] = {
+		{ 18,  262120},
+		{ 18,  262118},{ 18,  262119},{ 18,  262117},{ 19,  524277},{ 19,  524273},
+		{ 19,  524269},{ 19,  524278},{ 19,  524270},{ 19,  524271},{ 19,  524272},
+		{ 19,  524284},{ 19,  524285},{ 19,  524287},{ 19,  524286},{ 19,  524279},
+		{ 19,  524280},{ 19,  524283},{ 19,  524281},{ 18,  262116},{ 19,  524282},
+		{ 18,  262115},{ 17,  131055},{ 17,  131056},{ 16,  65525},{ 17,  131054},
+		{ 16,  65522},{ 16,  65523},{ 16,  65524},{ 16,  65521},{ 15,  32758},
+		{ 15,  32759},{ 14,  16377},{ 14,  16373},{ 14,  16375},{ 14,  16371},
+		{ 14,  16374},{ 14,  16370},{ 13,  8183},{ 13,  8181},{ 12,  4089},
+		{ 12,  4087},{ 12,  4086},{ 11,  2041},{ 12,  4084},{ 11,  2040},
+		{ 10,  1017},{ 10,  1015},{ 10,  1013},{ 9,  504},{ 9,  503},
+		{ 8,  250},{ 8,  248},{ 8,  246},{ 7,  121},{ 6,  58},
+		{ 6,  56},{ 5,  26},{ 4,  11},{ 3,  4},{ 1,  0},
+		{ 4,  10},{ 4,  12},{ 5,  27},{ 6,  57},{ 6,  59},
+		{ 7,  120},{ 7,  122},{ 8,  247},{ 8,  249},{ 9,  502},
+		{ 9,  505},{ 10,  1012},{ 10,  1014},{ 10,  1016},{ 11,  2037},
+		{ 11,  2036},{ 11,  2038},{ 11,  2039},{ 12,  4085},{ 12,  4088},
+		{ 13,  8180},{ 13,  8182},{ 13,  8184},{ 14,  16376},{ 14,  16372},
+		{ 16,  65520},{ 15,  32756},{ 16,  65526},{ 15,  32757},{ 18,  262114},
+		{ 19,  524249},{ 19,  524250},{ 19,  524251},{ 19,  524252},{ 19,  524253},
+		{ 19,  524254},{ 19,  524248},{ 19,  524242},{ 19,  524243},{ 19,  524244},
+		{ 19,  524245},{ 19,  524246},{ 19,  524274},{ 19,  524255},{ 19,  524263},
+		{ 19,  524264},{ 19,  524265},{ 19,  524266},{ 19,  524267},{ 19,  524262},
+		{ 19,  524256},{ 19,  524257},{ 19,  524258},{ 19,  524259},{ 19,  524260},
+		{ 19,  524261},{ 19,  524247},{ 19,  524268},{ 19,  524276},{ 19,  524275}
+	};
+
+
--- /dev/null
+++ b/libfaac/joint.c
@@ -1,0 +1,126 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: joint.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#include <stdlib.h> /* for max() define */
+#include "channels.h"
+
+void MSEncode(CoderInfo *coderInfo,
+			  ChannelInfo *channelInfo,
+			  double *spectrum[MAX_CHANNELS],
+			  int numberOfChannels,
+			  short msenable)
+{
+	int chanNum;
+	int sfbNum;
+	int lineNum;
+	double sum,diff;
+
+	/* Look for channel_pair_elements */
+	for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+		if (channelInfo[chanNum].present) {
+			if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
+				int leftChan=chanNum;
+				int rightChan = channelInfo[chanNum].paired_ch;
+				channelInfo[leftChan].msInfo.is_present = 0;
+				channelInfo[rightChan].msInfo.is_present = 0;
+
+				/* Perform MS if block_types are the same */
+				if ((coderInfo[leftChan].block_type==coderInfo[rightChan].block_type)&&(msenable)) { 
+					int numGroups;
+					int maxSfb;
+					int g,w,line_offset;
+					int startWindow,stopWindow;
+					MSInfo *msInfoL;
+					MSInfo *msInfoR;
+
+					channelInfo[leftChan].common_window = 1;  /* Use common window */
+					channelInfo[leftChan].msInfo.is_present = 1;
+					channelInfo[rightChan].msInfo.is_present = 1;
+
+					numGroups = coderInfo[leftChan].num_window_groups;
+					maxSfb = coderInfo[leftChan].max_sfb;
+					w=0;
+
+					/* Determine which bands should be enabled */
+					msInfoL = &(channelInfo[leftChan].msInfo);
+					msInfoR = &(channelInfo[rightChan].msInfo);
+					
+					/* Perform sum and differencing on bands in which ms_used flag */
+					/* has been set. */
+					if (coderInfo[leftChan].block_type == ONLY_SHORT_WINDOW) {
+						line_offset=0;
+						startWindow = 0;
+						for (g=0;g<numGroups;g++) {
+							int numWindows = coderInfo[leftChan].window_group_length[g];
+							stopWindow = startWindow + numWindows;
+							for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+								/* Enable MS mask */
+								int use_ms = 1;
+								for (w=startWindow;w<stopWindow;w++) {
+									use_ms = min(use_ms, msInfoL->ms_usedS[w][sfbNum]);
+								}
+								msInfoL->ms_used[g*maxSfb+sfbNum] = use_ms; /* write this to bitstream */
+								msInfoR->ms_used[g*maxSfb+sfbNum] = use_ms;
+								for (w=startWindow;w<stopWindow;w++) {
+									msInfoL->ms_usedS[w][sfbNum] = use_ms;
+									msInfoR->ms_usedS[w][sfbNum] = use_ms;
+								}
+								for (w=startWindow;w<stopWindow;w++) {
+									if (msInfoL->ms_usedS[w][sfbNum]) {
+										for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
+										lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
+										lineNum++)
+										{
+											line_offset = w*BLOCK_LEN_SHORT;
+											sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
+											diff=spectrum[leftChan][line_offset+lineNum]-spectrum[rightChan][line_offset+lineNum];
+											spectrum[leftChan][line_offset+lineNum] = 0.5 * sum;
+											spectrum[rightChan][line_offset+lineNum] = 0.5 * diff;
+										}
+									}
+								}
+							}
+							startWindow = stopWindow;
+						}
+					} else {
+						for (sfbNum = 0;sfbNum < maxSfb; sfbNum++) {
+							msInfoR->ms_used[sfbNum] = msInfoL->ms_used[sfbNum];
+
+							/* Enable MS mask */
+							if (msInfoL->ms_used[sfbNum]) {
+								for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
+								lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
+								lineNum++)
+								{
+									sum=spectrum[leftChan][lineNum]+spectrum[rightChan][lineNum];
+									diff=spectrum[leftChan][lineNum]-spectrum[rightChan][lineNum];
+									spectrum[leftChan][lineNum] = 0.5 * sum;
+									spectrum[rightChan][lineNum] = 0.5 * diff;
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+}
+
--- /dev/null
+++ b/libfaac/joint.h
@@ -1,0 +1,39 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: joint.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef JOINT_H
+#define JOINT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "coder.h"
+
+
+void MSEncode(CoderInfo *coderInfo, ChannelInfo *channelInfo, double *spectrum[MAX_CHANNELS],
+			  int numberOfChannels, short msenable);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* JOINT_H */
--- /dev/null
+++ b/libfaac/kbd_win.h
@@ -1,0 +1,1185 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: kbd_win.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef _SHAPE_WIN_H_
+#define _SHAPE_WIN_H_
+
+double kbd_window_long[BLOCK_LEN_LONG] = {
+  0.00029256153896361,
+  0.00042998567353047,
+  0.00054674074589540,
+  0.00065482304299792,
+  0.00075870195068747,
+  0.00086059331713336,
+  0.00096177541439010,
+  0.0010630609410878,
+  0.0011650036308132,
+  0.0012680012194148,
+  0.0013723517232956,
+  0.0014782864109136,
+  0.0015859901976719,
+  0.0016956148252373,
+  0.0018072876903517,
+  0.0019211179405514,
+  0.0020372007924215,
+  0.0021556206591754,
+  0.0022764534599614,
+  0.0023997683540995,
+  0.0025256290631156,
+  0.0026540948920831,
+  0.0027852215281403,
+  0.0029190616715331,
+  0.0030556655443223,
+  0.0031950812943391,
+  0.0033373553240392,
+  0.0034825325586930,
+  0.0036306566699199,
+  0.0037817702604646,
+  0.0039359150179719,
+  0.0040931318437260,
+  0.0042534609610026,
+  0.0044169420066964,
+  0.0045836141091341,
+  0.0047535159544086,
+  0.0049266858431214,
+  0.0051031617390698,
+  0.0052829813111335,
+  0.0054661819693975,
+  0.0056528008963682,
+  0.0058428750739943,
+  0.0060364413070882,
+  0.0062335362436492,
+  0.0064341963925079,
+  0.0066384581386503,
+  0.0068463577565218,
+  0.0070579314215715,
+  0.0072732152202559,
+  0.0074922451586909,
+  0.0077150571701162,
+  0.0079416871213115,
+  0.0081721708180857,
+  0.0084065440099458,
+  0.0086448423940363,
+  0.0088871016184291,
+  0.0091333572848345,
+  0.0093836449507939,
+  0.0096380001314086,
+  0.0098964583006517,
+  0.010159054892306,
+  0.010425825300561,
+  0.010696804880310,
+  0.010972028947167,
+  0.011251532777236,
+  0.011535351606646,
+  0.011823520630897,
+  0.012116075003993,
+  0.012413049837429,
+  0.012714480198999,
+  0.013020401111478,
+  0.013330847551161,
+  0.013645854446288,
+  0.013965456675352,
+  0.014289689065314,
+  0.014618586389712,
+  0.014952183366697,
+  0.015290514656976,
+  0.015633614861688,
+  0.015981518520214,
+  0.016334260107915,
+  0.016691874033817,
+  0.017054394638241,
+  0.017421856190380,
+  0.017794292885832,
+  0.018171738844085,
+  0.018554228105962,
+  0.018941794631032,
+  0.019334472294980,
+  0.019732294886947,
+  0.020135296106839,
+  0.020543509562604,
+  0.020956968767488,
+  0.021375707137257,
+  0.021799757987407,
+  0.022229154530343,
+  0.022663929872540,
+  0.023104117011689,
+  0.023549748833816,
+  0.024000858110398,
+  0.024457477495451,
+  0.024919639522613,
+  0.025387376602207,
+  0.025860721018295,
+  0.026339704925726,
+  0.026824360347160,
+  0.027314719170100,
+  0.027810813143900,
+  0.028312673876775,
+  0.028820332832801,
+  0.029333821328905,
+  0.029853170531859,
+  0.030378411455255,
+  0.030909574956490,
+  0.031446691733739,
+  0.031989792322926,
+  0.032538907094693,
+  0.033094066251369,
+  0.033655299823935,
+  0.034222637668991,
+  0.034796109465717,
+  0.035375744712844,
+  0.035961572725616,
+  0.036553622632758,
+  0.037151923373446,
+  0.037756503694277,
+  0.038367392146243,
+  0.038984617081711,
+  0.039608206651398,
+  0.040238188801359,
+  0.040874591269976,
+  0.041517441584950,
+  0.042166767060301,
+  0.042822594793376,
+  0.043484951661852,
+  0.044153864320760,
+  0.044829359199509,
+  0.045511462498913,
+  0.046200200188234,
+  0.046895598002228,
+  0.047597681438201,
+  0.048306475753074,
+  0.049022005960455,
+  0.049744296827725,
+  0.050473372873129,
+  0.051209258362879,
+  0.051951977308273,
+  0.052701553462813,
+  0.053458010319350,
+  0.054221371107223,
+  0.054991658789428,
+  0.055768896059787,
+  0.056553105340134,
+  0.057344308777513,
+  0.058142528241393,
+  0.058947785320893,
+  0.059760101322019,
+  0.060579497264926,
+  0.061405993881180,
+  0.062239611611049,
+  0.063080370600799,
+  0.063928290700012,
+  0.064783391458919,
+  0.065645692125747,
+  0.066515211644086,
+  0.067391968650269,
+  0.068275981470777,
+  0.069167268119652,
+  0.070065846295935,
+  0.070971733381121,
+  0.071884946436630,
+  0.072805502201299,
+  0.073733417088896,
+  0.074668707185649,
+  0.075611388247794,
+  0.076561475699152,
+  0.077518984628715,
+  0.078483929788261,
+  0.079456325589986,
+  0.080436186104162,
+  0.081423525056808,
+  0.082418355827392,
+  0.083420691446553,
+  0.084430544593841,
+  0.085447927595483,
+  0.086472852422178,
+  0.087505330686900,
+  0.088545373642744,
+  0.089592992180780,
+  0.090648196827937,
+  0.091710997744919,
+  0.092781404724131,
+  0.093859427187640,
+  0.094945074185163,
+  0.096038354392069,
+  0.097139276107423,
+  0.098247847252041,
+  0.099364075366580,
+  0.10048796760965,
+  0.10161953075597,
+  0.10275877119451,
+  0.10390569492671,
+  0.10506030756469,
+  0.10622261432949,
+  0.10739262004941,
+  0.10857032915821,
+  0.10975574569357,
+  0.11094887329534,
+  0.11214971520402,
+  0.11335827425914,
+  0.11457455289772,
+  0.11579855315274,
+  0.11703027665170,
+  0.11826972461510,
+  0.11951689785504,
+  0.12077179677383,
+  0.12203442136263,
+  0.12330477120008,
+  0.12458284545102,
+  0.12586864286523,
+  0.12716216177615,
+  0.12846340009971,
+  0.12977235533312,
+  0.13108902455375,
+  0.13241340441801,
+  0.13374549116025,
+  0.13508528059173,
+  0.13643276809961,
+  0.13778794864595,
+  0.13915081676677,
+  0.14052136657114,
+  0.14189959174027,
+  0.14328548552671,
+  0.14467904075349,
+  0.14608024981336,
+  0.14748910466804,
+  0.14890559684750,
+  0.15032971744929,
+  0.15176145713790,
+  0.15320080614414,
+  0.15464775426459,
+  0.15610229086100,
+  0.15756440485987,
+  0.15903408475193,
+  0.16051131859170,
+  0.16199609399712,
+  0.16348839814917,
+  0.16498821779156,
+  0.16649553923042,
+  0.16801034833404,
+  0.16953263053270,
+  0.17106237081842,
+  0.17259955374484,
+  0.17414416342714,
+  0.17569618354193,
+  0.17725559732720,
+  0.17882238758238,
+  0.18039653666830,
+  0.18197802650733,
+  0.18356683858343,
+  0.18516295394233,
+  0.18676635319174,
+  0.18837701650148,
+  0.18999492360384,
+  0.19162005379380,
+  0.19325238592940,
+  0.19489189843209,
+  0.19653856928714,
+  0.19819237604409,
+  0.19985329581721,
+  0.20152130528605,
+  0.20319638069594,
+  0.20487849785865,
+  0.20656763215298,
+  0.20826375852540,
+  0.20996685149083,
+  0.21167688513330,
+  0.21339383310678,
+  0.21511766863598,
+  0.21684836451719,
+  0.21858589311922,
+  0.22033022638425,
+  0.22208133582887,
+  0.22383919254503,
+  0.22560376720111,
+  0.22737503004300,
+  0.22915295089517,
+  0.23093749916189,
+  0.23272864382838,
+  0.23452635346201,
+  0.23633059621364,
+  0.23814133981883,
+  0.23995855159925,
+  0.24178219846403,
+  0.24361224691114,
+  0.24544866302890,
+  0.24729141249740,
+  0.24914046059007,
+  0.25099577217522,
+  0.25285731171763,
+  0.25472504328019,
+  0.25659893052556,
+  0.25847893671788,
+  0.26036502472451,
+  0.26225715701781,
+  0.26415529567692,
+  0.26605940238966,
+  0.26796943845439,
+  0.26988536478190,
+  0.27180714189742,
+  0.27373472994256,
+  0.27566808867736,
+  0.27760717748238,
+  0.27955195536071,
+  0.28150238094021,
+  0.28345841247557,
+  0.28542000785059,
+  0.28738712458038,
+  0.28935971981364,
+  0.29133775033492,
+  0.29332117256704,
+  0.29530994257338,
+  0.29730401606034,
+  0.29930334837974,
+  0.30130789453132,
+  0.30331760916521,
+  0.30533244658452,
+  0.30735236074785,
+  0.30937730527195,
+  0.31140723343430,
+  0.31344209817583,
+  0.31548185210356,
+  0.31752644749341,
+  0.31957583629288,
+  0.32162997012390,
+  0.32368880028565,
+  0.32575227775738,
+  0.32782035320134,
+  0.32989297696566,
+  0.33197009908736,
+  0.33405166929523,
+  0.33613763701295,
+  0.33822795136203,
+  0.34032256116495,
+  0.34242141494820,
+  0.34452446094547,
+  0.34663164710072,
+  0.34874292107143,
+  0.35085823023181,
+  0.35297752167598,
+  0.35510074222129,
+  0.35722783841160,
+  0.35935875652060,
+  0.36149344255514,
+  0.36363184225864,
+  0.36577390111444,
+  0.36791956434930,
+  0.37006877693676,
+  0.37222148360070,
+  0.37437762881878,
+  0.37653715682603,
+  0.37870001161834,
+  0.38086613695607,
+  0.38303547636766,
+  0.38520797315322,
+  0.38738357038821,
+  0.38956221092708,
+  0.39174383740701,
+  0.39392839225157,
+  0.39611581767449,
+  0.39830605568342,
+  0.40049904808370,
+  0.40269473648218,
+  0.40489306229101,
+  0.40709396673153,
+  0.40929739083810,
+  0.41150327546197,
+  0.41371156127524,
+  0.41592218877472,
+  0.41813509828594,
+  0.42035022996702,
+  0.42256752381274,
+  0.42478691965848,
+  0.42700835718423,
+  0.42923177591866,
+  0.43145711524314,
+  0.43368431439580,
+  0.43591331247564,
+  0.43814404844658,
+  0.44037646114161,
+  0.44261048926688,
+  0.44484607140589,
+  0.44708314602359,
+  0.44932165147057,
+  0.45156152598727,
+  0.45380270770813,
+  0.45604513466581,
+  0.45828874479543,
+  0.46053347593880,
+  0.46277926584861,
+  0.46502605219277,
+  0.46727377255861,
+  0.46952236445718,
+  0.47177176532752,
+  0.47402191254100,
+  0.47627274340557,
+  0.47852419517009,
+  0.48077620502869,
+  0.48302871012505,
+  0.48528164755674,
+  0.48753495437962,
+  0.48978856761212,
+  0.49204242423966,
+  0.49429646121898,
+  0.49655061548250,
+  0.49880482394273,
+  0.50105902349665,
+  0.50331315103004,
+  0.50556714342194,
+  0.50782093754901,
+  0.51007447028990,
+  0.51232767852971,
+  0.51458049916433,
+  0.51683286910489,
+  0.51908472528213,
+  0.52133600465083,
+  0.52358664419420,
+  0.52583658092832,
+  0.52808575190648,
+  0.53033409422367,
+  0.53258154502092,
+  0.53482804148974,
+  0.53707352087652,
+  0.53931792048690,
+  0.54156117769021,
+  0.54380322992385,
+  0.54604401469766,
+  0.54828346959835,
+  0.55052153229384,
+  0.55275814053768,
+  0.55499323217338,
+  0.55722674513883,
+  0.55945861747062,
+  0.56168878730842,
+  0.56391719289930,
+  0.56614377260214,
+  0.56836846489188,
+  0.57059120836390,
+  0.57281194173835,
+  0.57503060386439,
+  0.57724713372458,
+  0.57946147043912,
+  0.58167355327012,
+  0.58388332162591,
+  0.58609071506528,
+  0.58829567330173,
+  0.59049813620770,
+  0.59269804381879,
+  0.59489533633802,
+  0.59708995413996,
+  0.59928183777495,
+  0.60147092797329,
+  0.60365716564937,
+  0.60584049190582,
+  0.60802084803764,
+  0.61019817553632,
+  0.61237241609393,
+  0.61454351160718,
+  0.61671140418155,
+  0.61887603613527,
+  0.62103735000336,
+  0.62319528854167,
+  0.62534979473088,
+  0.62750081178042,
+  0.62964828313250,
+  0.63179215246597,
+  0.63393236370030,
+  0.63606886099946,
+  0.63820158877577,
+  0.64033049169379,
+  0.64245551467413,
+  0.64457660289729,
+  0.64669370180740,
+  0.64880675711607,
+  0.65091571480603,
+  0.65302052113494,
+  0.65512112263906,
+  0.65721746613689,
+  0.65930949873289,
+  0.66139716782102,
+  0.66348042108842,
+  0.66555920651892,
+  0.66763347239664,
+  0.66970316730947,
+  0.67176824015260,
+  0.67382864013196,
+  0.67588431676768,
+  0.67793521989751,
+  0.67998129968017,
+  0.68202250659876,
+  0.68405879146403,
+  0.68609010541774,
+  0.68811639993588,
+  0.69013762683195,
+  0.69215373826012,
+  0.69416468671849,
+  0.69617042505214,
+  0.69817090645634,
+  0.70016608447958,
+  0.70215591302664,
+  0.70414034636163,
+  0.70611933911096,
+  0.70809284626630,
+  0.71006082318751,
+  0.71202322560554,
+  0.71398000962530,
+  0.71593113172842,
+  0.71787654877613,
+  0.71981621801195,
+  0.72175009706445,
+  0.72367814394990,
+  0.72560031707496,
+  0.72751657523927,
+  0.72942687763803,
+  0.73133118386457,
+  0.73322945391280,
+  0.73512164817975,
+  0.73700772746796,
+  0.73888765298787,
+  0.74076138636020,
+  0.74262888961827,
+  0.74449012521027,
+  0.74634505600152,
+  0.74819364527663,
+  0.75003585674175,
+  0.75187165452661,
+  0.75370100318668,
+  0.75552386770515,
+  0.75734021349500,
+  0.75915000640095,
+  0.76095321270137,
+  0.76274979911019,
+  0.76453973277875,
+  0.76632298129757,
+  0.76809951269819,
+  0.76986929545481,
+  0.77163229848604,
+  0.77338849115651,
+  0.77513784327849,
+  0.77688032511340,
+  0.77861590737340,
+  0.78034456122283,
+  0.78206625827961,
+  0.78378097061667,
+  0.78548867076330,
+  0.78718933170643,
+  0.78888292689189,
+  0.79056943022564,
+  0.79224881607494,
+  0.79392105926949,
+  0.79558613510249,
+  0.79724401933170,
+  0.79889468818046,
+  0.80053811833858,
+  0.80217428696334,
+  0.80380317168028,
+  0.80542475058405,
+  0.80703900223920,
+  0.80864590568089,
+  0.81024544041560,
+  0.81183758642175,
+  0.81342232415032,
+  0.81499963452540,
+  0.81656949894467,
+  0.81813189927991,
+  0.81968681787738,
+  0.82123423755821,
+  0.82277414161874,
+  0.82430651383076,
+  0.82583133844180,
+  0.82734860017528,
+  0.82885828423070,
+  0.83036037628369,
+  0.83185486248609,
+  0.83334172946597,
+  0.83482096432759,
+  0.83629255465130,
+  0.83775648849344,
+  0.83921275438615,
+  0.84066134133716,
+  0.84210223882952,
+  0.84353543682130,
+  0.84496092574524,
+  0.84637869650833,
+  0.84778874049138,
+  0.84919104954855,
+  0.85058561600677,
+  0.85197243266520,
+  0.85335149279457,
+  0.85472279013653,
+  0.85608631890295,
+  0.85744207377513,
+  0.85879004990298,
+  0.86013024290422,
+  0.86146264886346,
+  0.86278726433124,
+  0.86410408632306,
+  0.86541311231838,
+  0.86671434025950,
+  0.86800776855046,
+  0.86929339605590,
+  0.87057122209981,
+  0.87184124646433,
+  0.87310346938840,
+  0.87435789156650,
+  0.87560451414719,
+  0.87684333873173,
+  0.87807436737261,
+  0.87929760257204,
+  0.88051304728038,
+  0.88172070489456,
+  0.88292057925645,
+  0.88411267465117,
+  0.88529699580537,
+  0.88647354788545,
+  0.88764233649580,
+  0.88880336767692,
+  0.88995664790351,
+  0.89110218408260,
+  0.89223998355154,
+  0.89337005407600,
+  0.89449240384793,
+  0.89560704148345,
+  0.89671397602074,
+  0.89781321691786,
+  0.89890477405053,
+  0.89998865770993,
+  0.90106487860034,
+  0.90213344783689,
+  0.90319437694315,
+  0.90424767784873,
+  0.90529336288690,
+  0.90633144479201,
+  0.90736193669708,
+  0.90838485213119,
+  0.90940020501694,
+  0.91040800966776,
+  0.91140828078533,
+  0.91240103345685,
+  0.91338628315231,
+  0.91436404572173,
+  0.91533433739238,
+  0.91629717476594,
+  0.91725257481564,
+  0.91820055488334,
+  0.91914113267664,
+  0.92007432626589,
+  0.92100015408120,
+  0.92191863490944,
+  0.92282978789113,
+  0.92373363251740,
+  0.92463018862687,
+  0.92551947640245,
+  0.92640151636824,
+  0.92727632938624,
+  0.92814393665320,
+  0.92900435969727,
+  0.92985762037477,
+  0.93070374086684,
+  0.93154274367610,
+  0.93237465162328,
+  0.93319948784382,
+  0.93401727578443,
+  0.93482803919967,
+  0.93563180214841,
+  0.93642858899043,
+  0.93721842438279,
+  0.93800133327637,
+  0.93877734091223,
+  0.93954647281807,
+  0.94030875480458,
+  0.94106421296182,
+  0.94181287365556,
+  0.94255476352362,
+  0.94328990947213,
+  0.94401833867184,
+  0.94474007855439,
+  0.94545515680855,
+  0.94616360137644,
+  0.94686544044975,
+  0.94756070246592,
+  0.94824941610434,
+  0.94893161028248,
+  0.94960731415209,
+  0.95027655709525,
+  0.95093936872056,
+  0.95159577885924,
+  0.95224581756115,
+  0.95288951509097,
+  0.95352690192417,
+  0.95415800874314,
+  0.95478286643320,
+  0.95540150607863,
+  0.95601395895871,
+  0.95662025654373,
+  0.95722043049100,
+  0.95781451264084,
+  0.95840253501260,
+  0.95898452980058,
+  0.95956052937008,
+  0.96013056625336,
+  0.96069467314557,
+  0.96125288290073,
+  0.96180522852773,
+  0.96235174318622,
+  0.96289246018262,
+  0.96342741296604,
+  0.96395663512424,
+  0.96448016037959,
+  0.96499802258499,
+  0.96551025571985,
+  0.96601689388602,
+  0.96651797130376,
+  0.96701352230768,
+  0.96750358134269,
+  0.96798818295998,
+  0.96846736181297,
+  0.96894115265327,
+  0.96940959032667,
+  0.96987270976912,
+  0.97033054600270,
+  0.97078313413161,
+  0.97123050933818,
+  0.97167270687887,
+  0.97210976208030,
+  0.97254171033525,
+  0.97296858709871,
+  0.97339042788392,
+  0.97380726825843,
+  0.97421914384017,
+  0.97462609029350,
+  0.97502814332534,
+  0.97542533868127,
+  0.97581771214160,
+  0.97620529951759,
+  0.97658813664749,
+  0.97696625939282,
+  0.97733970363445,
+  0.97770850526884,
+  0.97807270020427,
+  0.97843232435704,
+  0.97878741364771,
+  0.97913800399743,
+  0.97948413132414,
+  0.97982583153895,
+  0.98016314054243,
+  0.98049609422096,
+  0.98082472844313,
+  0.98114907905608,
+  0.98146918188197,
+  0.98178507271438,
+  0.98209678731477,
+  0.98240436140902,
+  0.98270783068385,
+  0.98300723078342,
+  0.98330259730589,
+  0.98359396579995,
+  0.98388137176152,
+  0.98416485063031,
+  0.98444443778651,
+  0.98472016854752,
+  0.98499207816463,
+  0.98526020181980,
+  0.98552457462240,
+  0.98578523160609,
+  0.98604220772560,
+  0.98629553785362,
+  0.98654525677772,
+  0.98679139919726,
+  0.98703399972035,
+  0.98727309286089,
+  0.98750871303556,
+  0.98774089456089,
+  0.98796967165036,
+  0.98819507841154,
+  0.98841714884323,
+  0.98863591683269,
+  0.98885141615285,
+  0.98906368045957,
+  0.98927274328896,
+  0.98947863805473,
+  0.98968139804554,
+  0.98988105642241,
+  0.99007764621618,
+  0.99027120032501,
+  0.99046175151186,
+  0.99064933240208,
+  0.99083397548099,
+  0.99101571309153,
+  0.99119457743191,
+  0.99137060055337,
+  0.99154381435784,
+  0.99171425059582,
+  0.99188194086414,
+  0.99204691660388,
+  0.99220920909823,
+  0.99236884947045,
+  0.99252586868186,
+  0.99268029752989,
+  0.99283216664606,
+  0.99298150649419,
+  0.99312834736847,
+  0.99327271939167,
+  0.99341465251338,
+  0.99355417650825,
+  0.99369132097430,
+  0.99382611533130,
+  0.99395858881910,
+  0.99408877049612,
+  0.99421668923778,
+  0.99434237373503,
+  0.99446585249289,
+  0.99458715382906,
+  0.99470630587254,
+  0.99482333656229,
+  0.99493827364600,
+  0.99505114467878,
+  0.99516197702200,
+  0.99527079784214,
+  0.99537763410962,
+  0.99548251259777,
+  0.99558545988178,
+  0.99568650233767,
+  0.99578566614138,
+  0.99588297726783,
+  0.99597846149005,
+  0.99607214437834,
+  0.99616405129947,
+  0.99625420741595,
+  0.99634263768527,
+  0.99642936685928,
+  0.99651441948352,
+  0.99659781989663,
+  0.99667959222978,
+  0.99675976040620,
+  0.99683834814063,
+  0.99691537893895,
+  0.99699087609774,
+  0.99706486270391,
+  0.99713736163442,
+  0.99720839555593,
+  0.99727798692461,
+  0.99734615798589,
+  0.99741293077431,
+  0.99747832711337,
+  0.99754236861541,
+  0.99760507668158,
+  0.99766647250181,
+  0.99772657705478,
+  0.99778541110799,
+  0.99784299521785,
+  0.99789934972976,
+  0.99795449477828,
+  0.99800845028730,
+  0.99806123597027,
+  0.99811287133042,
+  0.99816337566108,
+  0.99821276804596,
+  0.99826106735952,
+  0.99830829226732,
+  0.99835446122649,
+  0.99839959248609,
+  0.99844370408765,
+  0.99848681386566,
+  0.99852893944805,
+  0.99857009825685,
+  0.99861030750869,
+  0.99864958421549,
+  0.99868794518504,
+  0.99872540702178,
+  0.99876198612738,
+  0.99879769870160,
+  0.99883256074295,
+  0.99886658804953,
+  0.99889979621983,
+  0.99893220065356,
+  0.99896381655254,
+  0.99899465892154,
+  0.99902474256924,
+  0.99905408210916,
+  0.99908269196056,
+  0.99911058634952,
+  0.99913777930986,
+  0.99916428468421,
+  0.99919011612505,
+  0.99921528709576,
+  0.99923981087174,
+  0.99926370054150,
+  0.99928696900779,
+  0.99930962898876,
+  0.99933169301910,
+  0.99935317345126,
+  0.99937408245662,
+  0.99939443202674,
+  0.99941423397457,
+  0.99943349993572,
+  0.99945224136972,
+  0.99947046956130,
+  0.99948819562171,
+  0.99950543049000,
+  0.99952218493439,
+  0.99953846955355,
+  0.99955429477803,
+  0.99956967087154,
+  0.99958460793242,
+  0.99959911589494,
+  0.99961320453077,
+  0.99962688345035,
+  0.99964016210433,
+  0.99965304978499,
+  0.99966555562769,
+  0.99967768861231,
+  0.99968945756473,
+  0.99970087115825,
+  0.99971193791510,
+  0.99972266620792,
+  0.99973306426121,
+  0.99974314015288,
+  0.99975290181568,
+  0.99976235703876,
+  0.99977151346914,
+  0.99978037861326,
+  0.99978895983845,
+  0.99979726437448,
+  0.99980529931507,
+  0.99981307161943,
+  0.99982058811377,
+  0.99982785549283,
+  0.99983488032144,
+  0.99984166903600,
+  0.99984822794606,
+  0.99985456323584,
+  0.99986068096572,
+  0.99986658707386,
+  0.99987228737764,
+  0.99987778757524,
+  0.99988309324717,
+  0.99988820985777,
+  0.99989314275675,
+  0.99989789718072,
+  0.99990247825468,
+  0.99990689099357,
+  0.99991114030376,
+  0.99991523098456,
+  0.99991916772971,
+  0.99992295512891,
+  0.99992659766930,
+  0.99993009973692,
+  0.99993346561824,
+  0.99993669950161,
+  0.99993980547870,
+  0.99994278754604,
+  0.99994564960642,
+  0.99994839547033,
+  0.99995102885747,
+  0.99995355339809,
+  0.99995597263451,
+  0.99995829002249,
+  0.99996050893264,
+  0.99996263265183,
+  0.99996466438460,
+  0.99996660725452,
+  0.99996846430558,
+  0.99997023850356,
+  0.99997193273736,
+  0.99997354982037,
+  0.99997509249183,
+  0.99997656341810,
+  0.99997796519400,
+  0.99997930034415,
+  0.99998057132421,
+  0.99998178052220,
+  0.99998293025975,
+  0.99998402279338,
+  0.99998506031574,
+  0.99998604495686,
+  0.99998697878536,
+  0.99998786380966,
+  0.99998870197921,
+  0.99998949518567,
+  0.99999024526408,
+  0.99999095399401,
+  0.99999162310077,
+  0.99999225425649,
+  0.99999284908128,
+  0.99999340914435,
+  0.99999393596510,
+  0.99999443101421,
+  0.99999489571473,
+  0.99999533144314,
+  0.99999573953040,
+  0.99999612126300,
+  0.99999647788395,
+  0.99999681059383,
+  0.99999712055178,
+  0.99999740887647,
+  0.99999767664709,
+  0.99999792490431,
+  0.99999815465123,
+  0.99999836685427,
+  0.99999856244415,
+  0.99999874231676,
+  0.99999890733405,
+  0.99999905832493,
+  0.99999919608613,
+  0.99999932138304,
+  0.99999943495056,
+  0.99999953749392,
+  0.99999962968950,
+  0.99999971218563,
+  0.99999978560337,
+  0.99999985053727,
+  0.99999990755616,
+  0.99999995720387
+};
+
+
+double kbd_window_short[BLOCK_LEN_SHORT] = {
+4.3795702929468881e-005,
+0.00011867384265436617,
+0.0002307165763996192,
+0.00038947282760568383,
+0.00060581272288302553,
+0.00089199695169487453,
+0.0012617254423430522,
+0.0017301724373162003,
+0.0023140071937421476,
+0.0030313989666022221,
+0.0039020049735530842,
+0.0049469401815512024,
+0.0061887279335368318,
+0.0076512306364647726,
+0.0093595599562652423,
+0.011339966208377799,
+0.013619706891715299,
+0.016226894586323766,
+0.019190324717288168,
+0.022539283975960878,
+0.026303340480472455,
+0.030512117046644357,
+0.03519504922365594,
+0.040381130021856941,
+0.046098643518702249,
+0.052374889768730587,
+0.059235903660769147,
+0.066706170556282418,
+0.074808341703430481,
+0.083562952548726227,
+0.092988147159339674,
+0.1030994120216919,
+0.11390932249409955,
+0.12542730516149531,
+0.13765941926783826,
+0.15060816028651081,
+0.16427228853114245,
+0.17864668550988483,
+0.19372224048676889,
+0.20948576943658073,
+0.22591996826744942,
+0.24300340184133981,
+0.26071052995068139,
+0.27901177101369551,
+0.29787360383626599,
+0.3172587073594233,
+0.33712613787396362,
+0.35743154274286698,
+0.37812740923363009,
+0.39916334663203618,
+0.42048639939189658,
+0.4420413886774246,
+0.4637712792815169,
+0.4856175685594023,
+0.50752069370766872,
+0.52942045344797806,
+0.55125643994680196,
+0.57296847662071559,
+0.59449705734411495,
+0.61578378249506627,
+0.63677178724712891,
+0.65740615754163356,
+0.67763432925662526,
+0.69740646622548552,
+0.71667581294953808,
+0.73539901809352737,
+0.75353642514900732,
+0.77105232699609816,
+0.78791518148597028,
+0.80409778560147072,
+0.81957740622770781,
+0.83433586607383625,
+0.84835958382689225,
+0.86163956818294229,
+0.87417136598406997,
+0.88595496528524853,
+0.89699465477567619,
+0.90729884157670959,
+0.91687983002436779,
+0.92575356460899649,
+0.93393934077779084,
+0.94145948779657318,
+0.94833902830402828,
+0.95460531956280026,
+0.96028768170574896,
+0.96541701848104766,
+0.97002543610646474,
+0.97414586584250062,
+0.97781169577969584,
+0.98105641710392333,
+0.98391328975491177,
+0.98641503193166202,
+0.98859353733226141,
+0.99047962335771556,
+0.9921028127769449,
+0.99349115056397752,
+0.99467105680259038,
+0.9956672157341897,
+0.99650250022834352,
+0.99719793020823266,
+0.99777266288955657,
+0.99824401211201486,
+0.99862749357391212,
+0.99893689243401962,
+0.99918434952623147,
+0.99938046234161726,
+0.99953439696357238,
+0.99965400728430465,
+0.99974595807027455,
+0.99981584876278362,
+0.99986833527824281,
+0.99990724749057802,
+0.99993570051598468,
+0.99995619835942084,
+0.99997072890647543,
+0.9999808496399144,
+0.99998776381655818,
+0.99999238714961569,
+0.99999540529959718,
+0.99999732268176988,
+0.99999850325054862,
+0.99999920402413744,
+0.9999996021706401,
+0.99999981649545566,
+0.99999992415545547,
+0.99999997338493041,
+0.99999999295825959,
+0.99999999904096815
+};
+
+#endif
+
--- /dev/null
+++ b/libfaac/libfaac.dsp
@@ -1,0 +1,184 @@
+# Microsoft Developer Studio Project File - Name="libfaac" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=libfaac - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "libfaac.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "libfaac.mak" CFG="libfaac - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "libfaac - Win32 Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "libfaac - Win32 Debug" (based on "Win32 (x86) Static Library")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "libfaac - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD BASE RSC /l 0x413 /d "NDEBUG"
+# ADD RSC /l 0x413 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF  "$(CFG)" == "libfaac - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ  /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ  /c
+# ADD BASE RSC /l 0x413 /d "_DEBUG"
+# ADD RSC /l 0x413 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ENDIF 
+
+# Begin Target
+
+# Name "libfaac - Win32 Release"
+# Name "libfaac - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\aacquant.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\bitstream.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\channels.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\fft.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\filtbank.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\frame.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\huffman.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\joint.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\psych.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\util.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\aacquant.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\bitstream.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\channels.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\coder.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\fft.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\filtbank.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\frame.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\huffman.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\hufftab.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\joint.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\kbd_win.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\psych.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\util.h
+# End Source File
+# End Group
+# End Target
+# End Project
--- /dev/null
+++ b/libfaac/psych.c
@@ -1,0 +1,1224 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: psych.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#include <stdlib.h>
+#include <memory.h>
+#include <math.h>
+
+#include "psych.h"
+#include "coder.h"
+#include "fft.h"
+
+
+void PsyInit(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, unsigned int numChannels,
+			 unsigned int sampleRate, int *cb_width_long, int num_cb_long,
+			 int *cb_width_short, int num_cb_short)
+{
+	unsigned int channel;
+	int i, j, b, bb, high, low, size;
+	double tmpx,tmpy,tmp,x,b1,b2;
+	double bval[MAX_SCFAC_BANDS];
+
+	gpsyInfo->ath = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+	gpsyInfo->athS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+	gpsyInfo->rnorm = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+	gpsyInfo->rnormS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+	gpsyInfo->mld = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+	gpsyInfo->mldS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+	gpsyInfo->hannWindow = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
+	gpsyInfo->hannWindowS = (double*)malloc(2*BLOCK_LEN_SHORT*sizeof(double));
+
+	for(i = 0; i < BLOCK_LEN_LONG*2; i++)
+		gpsyInfo->hannWindow[i] = 0.5 * (1-cos(2.0*M_PI*(i+0.5)/(BLOCK_LEN_LONG*2)));
+	for(i = 0; i < BLOCK_LEN_SHORT*2; i++)
+		gpsyInfo->hannWindowS[i] = 0.5 * (1-cos(2.0*M_PI*(i+0.5)/(BLOCK_LEN_SHORT*2)));
+	gpsyInfo->sampleRate = (double)sampleRate;
+
+	size = BLOCK_LEN_LONG;
+	for (channel = 0; channel < numChannels; channel++) {
+		psyInfo[channel].size = size;
+
+		psyInfo[channel].lastPe = 0.0;
+		psyInfo[channel].lastEnr = 0.0;
+		psyInfo[channel].threeInARow = 0;
+		psyInfo[channel].cw = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].maskThr = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskEn = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskThrNext = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskEnNext = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskThrMS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskEnMS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskThrNextMS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskEnNextMS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].prevSamples = (double*)malloc(size*sizeof(double));
+		memset(psyInfo[channel].prevSamples, 0, size*sizeof(double));
+
+		psyInfo[channel].lastNb = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].lastNbMS = (double*)malloc(size*sizeof(double));
+		for (j = 0; j < size; j++) {
+			psyInfo[channel].lastNb[j] = 2.;
+			psyInfo[channel].lastNbMS[j] = 2.;
+		}
+
+		psyInfo[channel].fftMagPlus2 = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].fftMagPlus1 = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].fftMag = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].fftMagMin1 = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].fftMagMin2 = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].fftPhPlus2 = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].fftPhPlus1 = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].fftPh = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].fftPhMin1 = (double*)malloc(size*sizeof(double));
+		psyInfo[channel].fftPhMin2 = (double*)malloc(size*sizeof(double));
+	}
+
+	size = BLOCK_LEN_SHORT;
+	for (channel = 0; channel < numChannels; channel++) {
+		psyInfo[channel].sizeS = size;
+
+		psyInfo[channel].prevSamplesS = (double*)malloc(size*sizeof(double));
+		memset(psyInfo[channel].prevSamplesS, 0, size*sizeof(double));
+
+		for (j = 0; j < 8; j++) {
+			psyInfo[channel].cwS[j] = (double*)malloc(size*sizeof(double));
+			psyInfo[channel].maskThrS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskEnS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskThrNextS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskEnNextS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskThrSMS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskEnSMS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskThrNextSMS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskEnNextSMS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+
+			psyInfo[channel].fftMagPlus2S[j] = (double*)malloc(size*sizeof(double));
+			psyInfo[channel].fftMagPlus1S[j] = (double*)malloc(size*sizeof(double));
+			psyInfo[channel].fftMagS[j] = (double*)malloc(size*sizeof(double));
+			psyInfo[channel].fftMagMin1S[j] = (double*)malloc(size*sizeof(double));
+			psyInfo[channel].fftPhPlus2S[j] = (double*)malloc(size*sizeof(double));
+			psyInfo[channel].fftPhPlus1S[j] = (double*)malloc(size*sizeof(double));
+			psyInfo[channel].fftPhS[j] = (double*)malloc(size*sizeof(double));
+			psyInfo[channel].fftPhMin1S[j] = (double*)malloc(size*sizeof(double));
+		}
+	}
+
+	size = BLOCK_LEN_LONG;
+	high = 0;
+	for(b = 0; b < num_cb_long; b++) {
+		low = high;
+		high += cb_width_long[b];
+
+		bval[b] = 0.5 * (freq2bark(gpsyInfo->sampleRate*low/(2*size)) + 
+			freq2bark(gpsyInfo->sampleRate*(high-1)/(2*size)));
+	}
+
+	for(b = 0; b < num_cb_long; b++) {
+		b2 = bval[b];
+		for(bb = 0; bb < num_cb_long; bb++) {
+			b1 = bval[bb];
+
+			if (b>=bb) tmpx = (b2 - b1)*3.0;
+			else tmpx = (b2 - b1)*1.5;
+
+			if(tmpx>=0.5 && tmpx<=2.5)
+			{
+				tmp = tmpx - 0.5;
+				x = 8.0 * (tmp*tmp - 2.0 * tmp);
+			}
+			else x = 0.0;
+			tmpx += 0.474;
+			tmpy = 15.811389 + 7.5*tmpx - 17.5*sqrt(1.0+tmpx*tmpx);
+
+			if (tmpy <= -100.0) gpsyInfo->spreading[b][bb] = 0.0;
+			else gpsyInfo->spreading[b][bb] = exp((x + tmpy)*0.2302585093);
+		}
+	}
+
+    for( b = 0; b < num_cb_long; b++){
+		tmp = 0.0;
+		for( bb = 0; bb < num_cb_long; bb++)
+			tmp += gpsyInfo->spreading[bb][b];
+		gpsyInfo->rnorm[b] = 1.0/tmp;
+    }
+
+	j = 0;
+    for( b = 0; b < num_cb_long; b++){
+		gpsyInfo->ath[b] = 1.e37;
+
+		for (bb = 0; bb < cb_width_long[b]; bb++, j++) {
+			double freq = gpsyInfo->sampleRate*j/(1000.0*2*size);
+			double level;
+			level = ATHformula(freq*1000) - 20;
+			level = pow(10., 0.1*level);
+			level *= cb_width_long[b];
+			if (level < gpsyInfo->ath[b])
+				gpsyInfo->ath[b] = level;
+		}
+    }
+
+	low = 0;
+	for (b = 0; b < num_cb_long; b++) {
+		tmp = freq2bark(gpsyInfo->sampleRate*low/(2*size));
+		tmp = (min(tmp, 15.5)/15.5);
+
+		gpsyInfo->mld[b] = pow(10.0, 1.25*(1-cos(M_PI*tmp))-2.5);
+		low += cb_width_long[b];
+	}
+
+
+	size = BLOCK_LEN_SHORT;
+	high = 0;
+	for(b = 0; b < num_cb_short; b++) {
+		low = high;
+		high += cb_width_short[b];
+
+		bval[b] = 0.5 * (freq2bark(gpsyInfo->sampleRate*low/(2*size)) + 
+			freq2bark(gpsyInfo->sampleRate*(high-1)/(2*size)));
+	}
+
+	for(b = 0; b < num_cb_short; b++) {
+		b2 = bval[b];
+		for(bb = 0; bb < num_cb_short; bb++) {
+			b1 = bval[bb];
+
+			if (b>=bb) tmpx = (b2 - b1)*3.0;
+			else tmpx = (b2 - b1)*1.5;
+
+			if(tmpx>=0.5 && tmpx<=2.5)
+			{
+				tmp = tmpx - 0.5;
+				x = 8.0 * (tmp*tmp - 2.0 * tmp);
+			}
+			else x = 0.0;
+			tmpx += 0.474;
+			tmpy = 15.811389 + 7.5*tmpx - 17.5*sqrt(1.0+tmpx*tmpx);
+
+			if (tmpy <= -100.0) gpsyInfo->spreadingS[b][bb] = 0.0;
+			else gpsyInfo->spreadingS[b][bb] = exp((x + tmpy)*0.2302585093);
+		}
+	}
+
+	j = 0;
+    for( b = 0; b < num_cb_short; b++){
+		gpsyInfo->athS[b] = 1.e37;
+
+		for (bb = 0; bb < cb_width_short[b]; bb++, j++) {
+			double freq = gpsyInfo->sampleRate*j/(1000.0*2*size);
+			double level;
+			level = ATHformula(freq*1000) - 20;
+			level = pow(10., 0.1*level);
+			level *= cb_width_short[b];
+			if (level < gpsyInfo->athS[b])
+				gpsyInfo->athS[b] = level;
+		}
+    }
+
+    for( b = 0; b < num_cb_short; b++){
+		tmp = 0.0;
+		for( bb = 0; bb < num_cb_short; bb++)
+			tmp += gpsyInfo->spreadingS[bb][b];
+		gpsyInfo->rnormS[b] = 1.0/tmp;
+    }
+
+	low = 0;
+	for (b = 0; b < num_cb_short; b++) {
+		tmp = freq2bark(gpsyInfo->sampleRate*low/(2*size));
+		tmp = (min(tmp, 15.5)/15.5);
+
+		gpsyInfo->mldS[b] = pow(10.0, 1.25*(1-cos(M_PI*tmp))-2.5);
+		low += cb_width_short[b];
+	}
+}
+
+void PsyEnd(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, unsigned int numChannels)
+{
+	unsigned int channel;
+	int j;
+
+	if (gpsyInfo->ath) free(gpsyInfo->ath);
+	if (gpsyInfo->athS) free(gpsyInfo->athS);
+	if (gpsyInfo->rnorm) free(gpsyInfo->rnorm);
+	if (gpsyInfo->rnormS) free(gpsyInfo->rnormS);
+	if (gpsyInfo->mld) free(gpsyInfo->mld);
+	if (gpsyInfo->mldS) free(gpsyInfo->mldS);
+	if (gpsyInfo->hannWindow) free(gpsyInfo->hannWindow);
+	if (gpsyInfo->hannWindowS) free(gpsyInfo->hannWindowS);
+
+	for (channel = 0; channel < numChannels; channel++) {
+		if (psyInfo[channel].prevSamples) free(psyInfo[channel].prevSamples);
+		if (psyInfo[channel].cw) free(psyInfo[channel].cw);
+		if (psyInfo[channel].maskThr) free(psyInfo[channel].maskThr);
+		if (psyInfo[channel].maskEn) free(psyInfo[channel].maskEn);
+		if (psyInfo[channel].maskThrNext) free(psyInfo[channel].maskThrNext);
+		if (psyInfo[channel].maskEnNext) free(psyInfo[channel].maskEnNext);
+		if (psyInfo[channel].maskThrMS) free(psyInfo[channel].maskThrMS);
+		if (psyInfo[channel].maskEnMS) free(psyInfo[channel].maskEnMS);
+		if (psyInfo[channel].maskThrNextMS) free(psyInfo[channel].maskThrNextMS);
+		if (psyInfo[channel].maskEnNextMS) free(psyInfo[channel].maskEnNextMS);
+		
+		if (psyInfo[channel].lastNb) free(psyInfo[channel].lastNb);
+		if (psyInfo[channel].lastNbMS) free(psyInfo[channel].lastNbMS);
+
+		if (psyInfo[channel].fftMagPlus2) free(psyInfo[channel].fftMagPlus2);
+		if (psyInfo[channel].fftMagPlus1) free(psyInfo[channel].fftMagPlus1);
+		if (psyInfo[channel].fftMag) free(psyInfo[channel].fftMag);
+		if (psyInfo[channel].fftMagMin1) free(psyInfo[channel].fftMagMin1);
+		if (psyInfo[channel].fftMagMin2) free(psyInfo[channel].fftMagMin2);
+		if (psyInfo[channel].fftPhPlus2) free(psyInfo[channel].fftPhPlus2);
+		if (psyInfo[channel].fftPhPlus1) free(psyInfo[channel].fftPhPlus1);
+		if (psyInfo[channel].fftPh) free(psyInfo[channel].fftPh);
+		if (psyInfo[channel].fftPhMin1) free(psyInfo[channel].fftPhMin1);
+		if (psyInfo[channel].fftPhMin2) free(psyInfo[channel].fftPhMin2);
+	}
+
+	for (channel = 0; channel < numChannels; channel++) {
+		if(psyInfo[channel].prevSamplesS) free(psyInfo[channel].prevSamplesS);
+		for (j = 0; j < 8; j++) {
+			if (psyInfo[channel].cwS[j]) free(psyInfo[channel].cwS[j]);
+			if (psyInfo[channel].maskThrS[j]) free(psyInfo[channel].maskThrS[j]);
+			if (psyInfo[channel].maskEnS[j]) free(psyInfo[channel].maskEnS[j]);
+			if (psyInfo[channel].maskThrNextS[j]) free(psyInfo[channel].maskThrNextS[j]);
+			if (psyInfo[channel].maskEnNextS[j]) free(psyInfo[channel].maskEnNextS[j]);
+			if (psyInfo[channel].maskThrSMS[j]) free(psyInfo[channel].maskThrSMS[j]);
+			if (psyInfo[channel].maskEnSMS[j]) free(psyInfo[channel].maskEnSMS[j]);
+			if (psyInfo[channel].maskThrNextSMS[j]) free(psyInfo[channel].maskThrNextSMS[j]);
+			if (psyInfo[channel].maskEnNextSMS[j]) free(psyInfo[channel].maskEnNextSMS[j]);
+
+			if (psyInfo[channel].fftMagPlus2S[j]) free(psyInfo[channel].fftMagPlus2S[j]);
+			if (psyInfo[channel].fftMagPlus1S[j]) free(psyInfo[channel].fftMagPlus1S[j]);
+			if (psyInfo[channel].fftMagS[j]) free(psyInfo[channel].fftMagS[j]);
+			if (psyInfo[channel].fftMagMin1S[j]) free(psyInfo[channel].fftMagMin1S[j]);
+			if (psyInfo[channel].fftPhPlus2S[j]) free(psyInfo[channel].fftPhPlus2S[j]);
+			if (psyInfo[channel].fftPhPlus1S[j]) free(psyInfo[channel].fftPhPlus1S[j]);
+			if (psyInfo[channel].fftPhS[j]) free(psyInfo[channel].fftPhS[j]);
+			if (psyInfo[channel].fftPhMin1S[j]) free(psyInfo[channel].fftPhMin1S[j]);
+		}
+	}
+}
+
+/* Do psychoacoustical analysis */
+void PsyCalculate(ChannelInfo *channelInfo, GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo,
+				  int *cb_width_long, int num_cb_long, int *cb_width_short,
+				  int num_cb_short, unsigned int numChannels)
+{
+	unsigned int channel;
+
+	for (channel = 0; channel < numChannels; channel++) {
+		if (channelInfo[channel].present) {
+
+			if (channelInfo[channel].cpe &&
+				channelInfo[channel].ch_is_left) { /* CPE */
+
+				int leftChan = channel;
+				int rightChan = channelInfo[channel].paired_ch;
+
+				/* Calculate the unpredictability */
+				PsyUnpredictability(&psyInfo[leftChan]);
+				PsyUnpredictability(&psyInfo[rightChan]);
+
+				/* Calculate the threshold */
+				PsyThreshold(gpsyInfo, &psyInfo[leftChan], cb_width_long, num_cb_long,
+					cb_width_short, num_cb_short);
+				PsyThreshold(gpsyInfo, &psyInfo[rightChan], cb_width_long, num_cb_long,
+					cb_width_short, num_cb_short);
+
+				/* And for MS */
+				PsyThresholdMS(&channelInfo[leftChan], gpsyInfo, &psyInfo[leftChan],
+					&psyInfo[rightChan], cb_width_long, num_cb_long, cb_width_short,
+					num_cb_short);
+
+			} else if (!channelInfo[channel].cpe &&
+				channelInfo[channel].lfe) { /* LFE */
+
+				/* NOT FINISHED */
+
+			} else if (!channelInfo[channel].cpe) { /* SCE */
+
+				/* Calculate the unpredictability */
+				PsyUnpredictability(&psyInfo[channel]);
+
+				/* Calculate the threshold */
+				PsyThreshold(gpsyInfo, &psyInfo[channel], cb_width_long, num_cb_long,
+					cb_width_short, num_cb_short);
+			}
+		}
+	}
+}
+
+static void Hann(GlobalPsyInfo *gpsyInfo, double *inSamples, int size)
+{
+	int i;
+
+	/* Applying Hann window */
+	if (size == BLOCK_LEN_LONG*2) {
+		for(i = 0; i < size; i++)
+			inSamples[i] *= gpsyInfo->hannWindow[i];
+	} else {
+		for(i = 0; i < size; i++)
+			inSamples[i] *= gpsyInfo->hannWindowS[i];
+	}
+}
+
+void PsyBufferUpdate(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, double *newSamples)
+{
+	int i, j;
+	double a, b;
+	double *transBuff, *transBuffS, *tmp;
+
+	transBuff = (double*)malloc(2*psyInfo->size*sizeof(double));
+
+	memcpy(transBuff, psyInfo->prevSamples, psyInfo->size*sizeof(double));
+	memcpy(transBuff + psyInfo->size, newSamples, psyInfo->size*sizeof(double));
+
+
+	/* In 2 frames this will be the frequencies where
+	   the psychoacoustics are calculated for */
+	Hann(gpsyInfo, transBuff, 2*psyInfo->size);
+	rsfft(transBuff, 11);
+
+
+	/* shift all buffers 1 frame ahead */
+	tmp = psyInfo->fftMagMin2;
+	psyInfo->fftMagMin2 = psyInfo->fftMagMin1;
+	psyInfo->fftMagMin1 = psyInfo->fftMag;
+	psyInfo->fftMag = psyInfo->fftMagPlus1;
+	psyInfo->fftMagPlus1 = psyInfo->fftMagPlus2;
+	psyInfo->fftMagPlus2 = tmp;
+
+	tmp = psyInfo->fftPhMin2;
+	psyInfo->fftPhMin2 = psyInfo->fftPhMin1;
+	psyInfo->fftPhMin1 = psyInfo->fftPh;
+	psyInfo->fftPh = psyInfo->fftPhPlus1;
+	psyInfo->fftPhPlus1 = psyInfo->fftPhPlus2;
+	psyInfo->fftPhPlus2 = tmp;
+
+
+	/* Calculate magnitude and phase of new data */
+	for (i = 0; i < psyInfo->size; i++) {
+		a = transBuff[i];
+		b = transBuff[i + psyInfo->size];
+		psyInfo->fftMagPlus2[i] = sqrt(a*a + b*b);
+
+		if(a > 0.0){
+			if(b >= 0.0)
+				psyInfo->fftPhPlus2[i] = atan2(b, a);
+			else
+				psyInfo->fftPhPlus2[i] = atan2(b, a) + M_PI * 2.0;
+		} else if(a < 0.0) {
+			psyInfo->fftPhPlus2[i] = atan2(b, a) + M_PI;
+		} else {
+			if(b > 0.0)
+				psyInfo->fftPhPlus2[i] = M_PI * 0.5;
+			else if( b < 0.0 )
+				psyInfo->fftPhPlus2[i] = M_PI * 1.5;
+			else
+				psyInfo->fftPhPlus2[i] = 0.0;
+		}
+	}
+
+	transBuffS = (double*)malloc(2*psyInfo->sizeS*sizeof(double));
+
+	memcpy(transBuff, psyInfo->prevSamples, psyInfo->size*sizeof(double));
+	memcpy(transBuff + psyInfo->size, newSamples, psyInfo->size*sizeof(double));
+
+	for (j = 0; j < 8; j++) {
+
+		memcpy(transBuffS, transBuff+(j*128)+(1024-128), 2*psyInfo->sizeS*sizeof(double));
+
+		/* In 2 frames this will be the frequencies where
+		   the psychoacoustics are calculated for */
+		Hann(gpsyInfo, transBuffS, 2*psyInfo->sizeS);
+		rsfft(transBuff, 8);
+
+
+		/* shift all buffers 1 frame ahead */
+		tmp = psyInfo->fftMagMin1S[j];
+		psyInfo->fftMagMin1S[j] = psyInfo->fftMagS[j];
+		psyInfo->fftMagS[j] = psyInfo->fftMagPlus1S[j];
+		psyInfo->fftMagPlus1S[j] = psyInfo->fftMagPlus2S[j];
+		psyInfo->fftMagPlus2S[j] = tmp;
+
+		tmp = psyInfo->fftPhMin1S[j];
+		psyInfo->fftPhMin1S[j] = psyInfo->fftPhS[j];
+		psyInfo->fftPhS[j] = psyInfo->fftPhPlus1S[j];
+		psyInfo->fftPhPlus1S[j] = psyInfo->fftPhPlus2S[j];
+		psyInfo->fftPhPlus2S[j] = tmp;
+
+
+		/* Calculate magnitude and phase of new data */
+		for (i = 0; i < psyInfo->sizeS; i++) {
+			a = transBuffS[i];
+			b = transBuffS[i + psyInfo->sizeS];
+			psyInfo->fftMagPlus2S[j][i] = sqrt(a*a + b*b);
+
+			if(a > 0.0){
+				if(b >= 0.0)
+					psyInfo->fftPhPlus2S[j][i] = atan2(b, a);
+				else
+					psyInfo->fftPhPlus2S[j][i] = atan2(b, a) + M_PI * 2.0;
+			} else if(a < 0.0) {
+				psyInfo->fftPhPlus2S[j][i] = atan2(b, a) + M_PI;
+			} else {
+				if(b > 0.0)
+					psyInfo->fftPhPlus2S[j][i] = M_PI * 0.5;
+				else if( b < 0.0 )
+					psyInfo->fftPhPlus2S[j][i] = M_PI * 1.5;
+				else
+					psyInfo->fftPhPlus2S[j][i] = 0.0;
+			}
+		}
+	}
+
+	memcpy(psyInfo->prevSamples, newSamples, psyInfo->size*sizeof(double));
+
+	if (transBuff) free(transBuff);
+	if (transBuffS) free(transBuffS);
+}
+
+static void PsyUnpredictability(PsyInfo *psyInfo)
+{
+	int i, j;
+	double predMagMin, predMagPlus, predMag, mag;
+	double predPhMin, predPhPlus, predPh, ph;
+
+	for (i = 0; i < psyInfo->size; i++)
+	{
+		predMagMin = 2.0 * psyInfo->fftMagMin1[i] - psyInfo->fftMagMin2[i];
+		predMagPlus = 2.0 * psyInfo->fftMagPlus1[i] - psyInfo->fftMagPlus2[i];
+		predPhMin = 2.0 * psyInfo->fftPhMin1[i] - psyInfo->fftPhMin2[i];
+		predPhPlus = 2.0 * psyInfo->fftPhPlus1[i] - psyInfo->fftPhPlus2[i];
+		if ((predMagMin != 0.0) && (predMagPlus != 0.0)) {
+			if ((psyInfo->fftMag[i] - predMagMin) < (psyInfo->fftMag[i] - predMagPlus)) {
+				predMag = predMagMin;
+				predPh = predPhMin;
+			} else {
+				predMag = predMagPlus;
+				predPh = predPhPlus;
+			}
+		} else if (predMagMin == 0.0) {
+			predMag = predMagPlus;
+			predPh = predPhPlus;
+		} else { /* predMagPlus == 0.0 */
+			predMag = predMagMin;
+			predPh = predPhMin;
+		}
+
+		mag = psyInfo->fftMag[i];
+		ph = psyInfo->fftPh[i];
+
+		/* unpredictability */
+		psyInfo->cw[i] =
+			sqrt(mag*mag+predMag*predMag-2*mag*predMag*cos(ph+predPh))/(mag+fabs(predMag));
+	}
+
+	for (i = 0; i < psyInfo->sizeS; i++)
+	{
+		predMagMin = 2.0 * psyInfo->fftMagMin1S[7][i] - psyInfo->fftMagMin1S[6][i];
+		predMagPlus = 2.0 * psyInfo->fftMagS[1][i] - psyInfo->fftMagS[2][i];
+		predPhMin = 2.0 * psyInfo->fftPhMin1S[7][i] - psyInfo->fftPhMin1S[6][i];
+		predPhPlus = 2.0 * psyInfo->fftPhS[1][i] - psyInfo->fftPhS[2][i];
+		if ((predMagMin != 0.0) && (predMagPlus != 0.0)) {
+			if ((psyInfo->fftMagS[0][i] - predMagMin) < (psyInfo->fftMagS[0][i] - predMagPlus)) {
+				predMag = predMagMin;
+				predPh = predPhMin;
+			} else {
+				predMag = predMagPlus;
+				predPh = predPhPlus;
+			}
+		} else if (predMagMin == 0.0) {
+			predMag = predMagPlus;
+			predPh = predPhPlus;
+		} else { /* predMagPlus == 0.0 */
+			predMag = predMagMin;
+			predPh = predPhMin;
+		}
+
+		mag = psyInfo->fftMagS[0][i];
+		ph = psyInfo->fftPhS[0][i];
+
+		/* unpredictability */
+		psyInfo->cwS[0][i] =
+			sqrt(mag*mag+predMag*predMag-2*mag*predMag*cos(ph+predPh))/(mag+fabs(predMag));
+	}
+	for (i = 0; i < psyInfo->sizeS; i++)
+	{
+		predMagMin = 2.0 * psyInfo->fftMagS[0][i] - psyInfo->fftMagMin1S[7][i];
+		predMagPlus = 2.0 * psyInfo->fftMagS[2][i] - psyInfo->fftMagS[3][i];
+		predPhMin = 2.0 * psyInfo->fftPhS[0][i] - psyInfo->fftPhMin1S[7][i];
+		predPhPlus = 2.0 * psyInfo->fftPhS[2][i] - psyInfo->fftPhS[3][i];
+		if ((predMagMin != 0.0) && (predMagPlus != 0.0)) {
+			if ((psyInfo->fftMagS[1][i] - predMagMin) < (psyInfo->fftMagS[1][i] - predMagPlus)) {
+				predMag = predMagMin;
+				predPh = predPhMin;
+			} else {
+				predMag = predMagPlus;
+				predPh = predPhPlus;
+			}
+		} else if (predMagMin == 0.0) {
+			predMag = predMagPlus;
+			predPh = predPhPlus;
+		} else { /* predMagPlus == 0.0 */
+			predMag = predMagMin;
+			predPh = predPhMin;
+		}
+
+		mag = psyInfo->fftMagS[1][i];
+		ph = psyInfo->fftPhS[1][i];
+
+		/* unpredictability */
+		psyInfo->cwS[1][i] =
+			sqrt(mag*mag+predMag*predMag-2*mag*predMag*cos(ph+predPh))/(mag+fabs(predMag));
+	}
+
+	for (j = 2; j < 6; j++) {
+		for (i = 0; i < psyInfo->sizeS; i++)
+		{
+			predMagMin = 2.0 * psyInfo->fftMagS[j-1][i] - psyInfo->fftMagS[j-2][i];
+			predMagPlus = 2.0 * psyInfo->fftMagS[j+1][i] - psyInfo->fftMagS[j+2][i];
+			predPhMin = 2.0 * psyInfo->fftPhS[j-1][i] - psyInfo->fftPhS[j-2][i];
+			predPhPlus = 2.0 * psyInfo->fftPhS[j+1][i] - psyInfo->fftPhS[j+2][i];
+			if ((predMagMin != 0.0) && (predMagPlus != 0.0)) {
+				if ((psyInfo->fftMagS[j][i] - predMagMin) < (psyInfo->fftMagS[j][i] - predMagPlus)) {
+					predMag = predMagMin;
+					predPh = predPhMin;
+				} else {
+					predMag = predMagPlus;
+					predPh = predPhPlus;
+				}
+			} else if (predMagMin == 0.0) {
+				predMag = predMagPlus;
+				predPh = predPhPlus;
+			} else { /* predMagPlus == 0.0 */
+				predMag = predMagMin;
+				predPh = predPhMin;
+			}
+
+			mag = psyInfo->fftMagS[j][i];
+			ph = psyInfo->fftPhS[j][i];
+
+			/* unpredictability */
+			psyInfo->cwS[j][i] =
+				sqrt(mag*mag+predMag*predMag-2*mag*predMag*cos(ph+predPh))/(mag+fabs(predMag));
+		}
+	}
+
+	for (i = 0; i < psyInfo->sizeS; i++)
+	{
+		predMagMin = 2.0 * psyInfo->fftMagS[5][i] - psyInfo->fftMagS[4][i];
+		predMagPlus = 2.0 * psyInfo->fftMagS[7][i] - psyInfo->fftMagPlus1S[0][i];
+		predPhMin = 2.0 * psyInfo->fftPhS[5][i] - psyInfo->fftPhS[4][i];
+		predPhPlus = 2.0 * psyInfo->fftPhS[7][i] - psyInfo->fftPhPlus1S[0][i];
+		if ((predMagMin != 0.0) && (predMagPlus != 0.0)) {
+			if ((psyInfo->fftMagS[6][i] - predMagMin) < (psyInfo->fftMagS[6][i] - predMagPlus)) {
+				predMag = predMagMin;
+				predPh = predPhMin;
+			} else {
+				predMag = predMagPlus;
+				predPh = predPhPlus;
+			}
+		} else if (predMagMin == 0.0) {
+			predMag = predMagPlus;
+			predPh = predPhPlus;
+		} else { /* predMagPlus == 0.0 */
+			predMag = predMagMin;
+			predPh = predPhMin;
+		}
+
+		mag = psyInfo->fftMagS[6][i];
+		ph = psyInfo->fftPhS[6][i];
+
+		/* unpredictability */
+		psyInfo->cwS[6][i] =
+			sqrt(mag*mag+predMag*predMag-2*mag*predMag*cos(ph+predPh))/(mag+fabs(predMag));
+	}
+	for (i = 0; i < psyInfo->sizeS; i++)
+	{
+		predMagMin = 2.0 * psyInfo->fftMagS[6][i] - psyInfo->fftMagMin1S[5][i];
+		predMagPlus = 2.0 * psyInfo->fftMagPlus1S[0][i] - psyInfo->fftMagPlus1S[1][i];
+		predPhMin = 2.0 * psyInfo->fftPhS[6][i] - psyInfo->fftPhS[5][i];
+		predPhPlus = 2.0 * psyInfo->fftPhPlus1S[0][i] - psyInfo->fftPhPlus1S[1][i];
+		if ((predMagMin != 0.0) && (predMagPlus != 0.0)) {
+			if ((psyInfo->fftMagS[7][i] - predMagMin) < (psyInfo->fftMagS[7][i] - predMagPlus)) {
+				predMag = predMagMin;
+				predPh = predPhMin;
+			} else {
+				predMag = predMagPlus;
+				predPh = predPhPlus;
+			}
+		} else if (predMagMin == 0.0) {
+			predMag = predMagPlus;
+			predPh = predPhPlus;
+		} else { /* predMagPlus == 0.0 */
+			predMag = predMagMin;
+			predPh = predPhMin;
+		}
+
+		mag = psyInfo->fftMagS[7][i];
+		ph = psyInfo->fftPhS[7][i];
+
+		/* unpredictability */
+		psyInfo->cwS[7][i] =
+			sqrt(mag*mag+predMag*predMag-2*mag*predMag*cos(ph+predPh))/(mag+fabs(predMag));
+	}
+}
+
+static void PsyThreshold(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, int *cb_width_long,
+						 int num_cb_long, int *cb_width_short, int num_cb_short)
+{
+	int b, bb, w, low, high, j;
+	double tmp, ct, ecb, cb;
+	double tb, snr, bc, en, nb;
+
+	double e[MAX_SCFAC_BANDS];
+	double c[MAX_SCFAC_BANDS];
+
+	double tot, mx, estot[8];
+	double pe = 0.0;
+
+	/* Energy in each partition and weighted unpredictability */
+	high = 0;
+	for (b = 0; b < num_cb_long; b++)
+	{
+		low = high;
+		high += cb_width_long[b];
+
+		e[b] = 0.0;
+		c[b] = 0.0;
+
+		for (w = low; w < high; w++)
+		{
+			tmp = psyInfo->fftMag[w];
+			tmp *= tmp;
+			e[b] += tmp;
+			c[b] += tmp * psyInfo->cw[w];
+		}
+	}
+
+	/* Convolve the partitioned energy and unpredictability
+	   with the spreading function */
+	for (b = 0; b < num_cb_long; b++)
+	{
+		ecb = 0.0;
+		ct = 0.0;
+
+		for (bb = 0; bb < num_cb_long; bb++)
+		{
+			ecb += e[bb] * gpsyInfo->spreading[bb][b];
+			ct += c[bb] * gpsyInfo->spreading[bb][b];
+		}
+		if (ecb != 0.0) cb = ct / ecb;
+		else cb = 0.0;
+		en = ecb * gpsyInfo->rnorm[b];
+		
+		/* Get the tonality index */
+		tb = -0.299 - 0.43*log(cb);
+		tb = max(min(tb,1),0);
+
+		/* Calculate the required SNR in each partition */
+		snr = tb * 18.0 + (1-tb) * 6.0;
+
+		/* Power ratio */
+		bc = pow(10.0, 0.1*(-snr));
+
+		/* Actual energy threshold */
+		nb = en * bc;
+		nb = max(min(nb, psyInfo->lastNb[b]*2), gpsyInfo->ath[b]);
+		psyInfo->lastNb[b] = en * bc;
+
+		/* Perceptual entropy */
+		tmp = cb_width_long[b]
+			* log((nb + 0.0000000001)
+			/ (e[b] + 0.0000000001));
+		tmp = min(0,tmp);
+
+		pe -= tmp;
+
+		psyInfo->maskThr[b] = psyInfo->maskThrNext[b];
+		psyInfo->maskEn[b] = psyInfo->maskEnNext[b];
+		psyInfo->maskThrNext[b] = nb;
+		psyInfo->maskEnNext[b] = en;
+	}
+
+	/* Short windows */
+	for (j = 0; j < 8; j++)
+	{
+		/* Energy in each partition and weighted unpredictability */
+		high = 0;
+		for (b = 0; b < num_cb_short; b++)
+		{
+			low = high;
+			high += cb_width_short[b];
+
+			e[b] = 0.0;
+			c[b] = 0.0;
+
+			for (w = low; w < high; w++)
+			{
+				tmp = psyInfo->fftMagS[j][w];
+				tmp *= tmp;
+				e[b] += tmp;
+				c[b] += tmp * psyInfo->cwS[j][w];
+			}
+		}
+
+		estot[j] = 0.0;
+
+		/* Convolve the partitioned energy and unpredictability
+		with the spreading function */
+		for (b = 0; b < num_cb_short; b++)
+		{
+			ecb = 0.0;
+			ct = 0.0;
+
+			for (bb = 0; bb < num_cb_short; bb++)
+			{
+				ecb += e[bb] * gpsyInfo->spreadingS[bb][b];
+				ct += c[bb] * gpsyInfo->spreadingS[bb][b];
+			}
+			if (ecb != 0.0) cb = ct / ecb;
+			else cb = 0.0;
+			en = ecb * gpsyInfo->rnormS[b];
+			
+			/* Get the tonality index */
+			tb = -0.299 - 0.43*log(cb);
+			tb = max(min(tb,1),0);
+
+			/* Calculate the required SNR in each partition */
+			snr = tb * 18.0 + (1-tb) * 6.0;
+
+			/* Power ratio */
+			bc = pow(10.0, 0.1*(-snr));
+
+			/* Actual energy threshold */
+			nb = en * bc;
+			nb = max(nb, gpsyInfo->athS[b]);
+
+			estot[j] += e[b];
+
+			psyInfo->maskThrS[j][b] = psyInfo->maskThrNextS[j][b];
+			psyInfo->maskEnS[j][b] = psyInfo->maskEnNextS[j][b];
+			psyInfo->maskThrNextS[j][b] = nb;
+			psyInfo->maskEnNextS[j][b] = en;
+		}
+
+		if (estot[j] != 0.0)
+			estot[j] /= num_cb_short;
+	}
+
+	tot = mx = estot[0];
+	for (j = 1; j < 8; j++) {
+		tot += estot[j];
+		mx = max(mx, estot[j]);
+	}
+
+	tot = max(tot, 1.e-12);
+	if (((mx/tot) > 0.25) && (pe > 1100.0) || ((mx/tot) > 0.5)) {
+		psyInfo->block_type = ONLY_SHORT_WINDOW;
+		psyInfo->threeInARow++;
+	} else if ((psyInfo->lastEnr > 0.35) && (psyInfo->lastPe > 1000.0)) {
+		psyInfo->block_type = ONLY_SHORT_WINDOW;
+		psyInfo->threeInARow++;
+	} else if (psyInfo->threeInARow >= 3) {
+		psyInfo->block_type = ONLY_SHORT_WINDOW;
+		psyInfo->threeInARow = 0;
+	} else
+		psyInfo->block_type = ONLY_LONG_WINDOW;
+
+ 	psyInfo->lastEnr = mx/tot;
+	psyInfo->lastPe = pe;
+}
+
+static void PsyThresholdMS(ChannelInfo *channelInfoL, GlobalPsyInfo *gpsyInfo,
+						   PsyInfo *psyInfoL, PsyInfo *psyInfoR,
+						   int *cb_width_long, int num_cb_long, int *cb_width_short,
+						   int num_cb_short)
+{
+	int b, bb, w, low, high, j;
+	double tmp, ct, ecb, cb;
+	double tb, snr, bc, enM, enS, nbM, nbS;
+
+	double eM[MAX_SCFAC_BANDS];
+	double eS[MAX_SCFAC_BANDS];
+	double cM[MAX_SCFAC_BANDS];
+	double cS[MAX_SCFAC_BANDS];
+
+	double x1, x2, db, mld;
+
+#ifdef _DEBUG
+	int ms_used = 0;
+	int ms_usedS = 0;
+#endif
+
+	/* Energy in each partition and weighted unpredictability */
+	high = 0;
+	for (b = 0; b < num_cb_long; b++)
+	{
+		low = high;
+		high += cb_width_long[b];
+
+		eM[b] = 0.0;
+		cM[b] = 0.0;
+		eS[b] = 0.0;
+		cS[b] = 0.0;
+
+		for (w = low; w < high; w++)
+		{
+			tmp = (psyInfoL->fftMag[w] + psyInfoR->fftMag[w]) * 0.5;
+			tmp *= tmp;
+			eM[b] += tmp;
+			cM[b] += tmp * min(psyInfoL->cw[w], psyInfoR->cw[w]);
+
+			tmp = (psyInfoL->fftMag[w] - psyInfoR->fftMag[w]) * 0.5;
+			tmp *= tmp;
+			eS[b] += tmp;
+			cS[b] += tmp * min(psyInfoL->cw[w], psyInfoR->cw[w]);
+		}
+	}
+
+	/* Convolve the partitioned energy and unpredictability
+	   with the spreading function */
+	for (b = 0; b < num_cb_long; b++)
+	{
+		/* Mid channel */
+		ecb = 0.0;
+		ct = 0.0;
+
+		for (bb = 0; bb < num_cb_long; bb++)
+		{
+			ecb += eM[bb] * gpsyInfo->spreading[bb][b];
+			ct += cM[bb] * gpsyInfo->spreading[bb][b];
+		}
+		if (ecb != 0.0) cb = ct / ecb;
+		else cb = 0.0;
+		enM = ecb * gpsyInfo->rnorm[b];
+		
+		/* Get the tonality index */
+		tb = -0.299 - 0.43*log(cb);
+		tb = max(min(tb,1),0);
+
+		/* Calculate the required SNR in each partition */
+		snr = tb * 18.0 + (1-tb) * 6.0;
+
+		/* Power ratio */
+		bc = pow(10.0, 0.1*(-snr));
+
+		/* Actual energy threshold */
+		nbM = enM * bc;
+		nbM = max(min(nbM, psyInfoL->lastNbMS[b]*2), gpsyInfo->ath[b]);
+		psyInfoL->lastNbMS[b] = enM * bc;
+
+
+		/* Side channel */
+		ecb = 0.0;
+		ct = 0.0;
+
+		for (bb = 0; bb < num_cb_long; bb++)
+		{
+			ecb += eS[bb] * gpsyInfo->spreading[bb][b];
+			ct += cS[bb] * gpsyInfo->spreading[bb][b];
+		}
+		if (ecb != 0.0) cb = ct / ecb;
+		else cb = 0.0;
+		enS = ecb * gpsyInfo->rnorm[b];
+		
+		/* Get the tonality index */
+		tb = -0.299 - 0.43*log(cb);
+		tb = max(min(tb,1),0);
+
+		/* Calculate the required SNR in each partition */
+		snr = tb * 18.0 + (1-tb) * 6.0;
+
+		/* Power ratio */
+		bc = pow(10.0, 0.1*(-snr));
+
+		/* Actual energy threshold */
+		nbS = enS * bc;
+		nbS = max(min(nbS, psyInfoR->lastNbMS[b]*2), gpsyInfo->ath[b]);
+		psyInfoR->lastNbMS[b] = enS * bc;
+
+
+		psyInfoL->maskThrMS[b] = psyInfoL->maskThrNextMS[b];
+		psyInfoR->maskThrMS[b] = psyInfoR->maskThrNextMS[b];
+		psyInfoL->maskEnMS[b] = psyInfoL->maskEnNextMS[b];
+		psyInfoR->maskEnMS[b] = psyInfoR->maskEnNextMS[b];
+		psyInfoL->maskThrNextMS[b] = nbM;
+		psyInfoR->maskThrNextMS[b] = nbS;
+		psyInfoL->maskEnNextMS[b] = enM;
+		psyInfoR->maskEnNextMS[b] = enS;
+
+		if (psyInfoL->maskThr[b] <= 1.58*psyInfoR->maskThr[b]
+			&& psyInfoR->maskThr[b] <= 1.58*psyInfoL->maskThr[b]) {
+
+			mld = gpsyInfo->mld[b]*enM;
+			psyInfoL->maskThrMS[b] = max(psyInfoL->maskThrMS[b],
+				min(psyInfoR->maskThrMS[b],mld));
+
+			mld = gpsyInfo->mld[b]*enS;
+			psyInfoR->maskThrMS[b] = max(psyInfoR->maskThrMS[b],
+				min(psyInfoL->maskThrMS[b],mld));
+		}
+
+		x1 = min(psyInfoL->maskThr[b], psyInfoR->maskThr[b]);
+		x2 = max(psyInfoL->maskThr[b], psyInfoR->maskThr[b]);
+		/* thresholds difference in db */
+		if (x2 >= 1000*x1) db=3;
+		else db = log10(x2/x1);  
+		if (db < 0.25) {
+#ifdef _DEBUG
+			ms_used++;
+#endif
+			channelInfoL->msInfo.ms_used[b] = 1;
+		} else {
+			channelInfoL->msInfo.ms_used[b] = 0;
+		}
+	}
+
+#ifdef _DEBUG
+	printf("%d\t", ms_used);
+#endif
+
+	/* Short windows */
+	for (j = 0; j < 8; j++)
+	{
+		/* Energy in each partition and weighted unpredictability */
+		high = 0;
+		for (b = 0; b < num_cb_short; b++)
+		{
+			low = high;
+			high += cb_width_short[b];
+
+			eM[b] = 0.0;
+			eS[b] = 0.0;
+			cM[b] = 0.0;
+			cS[b] = 0.0;
+
+			for (w = low; w < high; w++)
+			{
+				tmp = (psyInfoL->fftMagS[j][w] + psyInfoR->fftMagS[j][w]) * 0.5;
+				tmp *= tmp;
+				eM[b] += tmp;
+				cM[b] += tmp * min(psyInfoL->cwS[j][w], psyInfoR->cwS[j][w]);
+
+				tmp = (psyInfoL->fftMagS[j][w] - psyInfoR->fftMagS[j][w]) * 0.5;
+				tmp *= tmp;
+				eS[b] += tmp;
+				cS[b] += tmp * min(psyInfoL->cwS[j][w], psyInfoR->cwS[j][w]);
+
+			}
+		}
+
+		/* Convolve the partitioned energy and unpredictability
+		with the spreading function */
+		for (b = 0; b < num_cb_short; b++)
+		{
+			/* Mid channel */
+			ecb = 0.0;
+			ct = 0.0;
+
+			for (bb = 0; bb < num_cb_short; bb++)
+			{
+				ecb += eM[bb] * gpsyInfo->spreadingS[bb][b];
+				ct += cM[bb] * gpsyInfo->spreadingS[bb][b];
+			}
+			if (ecb != 0.0) cb = ct / ecb;
+			else cb = 0.0;
+			enM = ecb * gpsyInfo->rnormS[b];
+			
+			/* Get the tonality index */
+			tb = -0.299 - 0.43*log(cb);
+			tb = max(min(tb,1),0);
+
+			/* Calculate the required SNR in each partition */
+			snr = tb * 18.0 + (1-tb) * 6.0;
+
+			/* Power ratio */
+			bc = pow(10.0, 0.1*(-snr));
+
+			/* Actual energy threshold */
+			nbM = enM * bc;
+			nbM = max(nbM, gpsyInfo->athS[b]);
+
+
+			/* Side channel */
+			ecb = 0.0;
+			ct = 0.0;
+
+			for (bb = 0; bb < num_cb_short; bb++)
+			{
+				ecb += eS[bb] * gpsyInfo->spreadingS[bb][b];
+				ct += cS[bb] * gpsyInfo->spreadingS[bb][b];
+			}
+			if (ecb != 0.0) cb = ct / ecb;
+			else cb = 0.0;
+			enS = ecb * gpsyInfo->rnormS[b];
+			
+			/* Get the tonality index */
+			tb = -0.299 - 0.43*log(cb);
+			tb = max(min(tb,1),0);
+
+			/* Calculate the required SNR in each partition */
+			snr = tb * 18.0 + (1-tb) * 6.0;
+
+			/* Power ratio */
+			bc = pow(10.0, 0.1*(-snr));
+
+			/* Actual energy threshold */
+			nbS = enS * bc;
+			nbS = max(nbS, gpsyInfo->athS[b]);
+
+
+			psyInfoL->maskThrSMS[j][b] = psyInfoL->maskThrNextSMS[j][b];
+			psyInfoR->maskThrSMS[j][b] = psyInfoR->maskThrNextSMS[j][b];
+			psyInfoL->maskEnSMS[j][b] = psyInfoL->maskEnNextSMS[j][b];
+			psyInfoR->maskEnSMS[j][b] = psyInfoR->maskEnNextSMS[j][b];
+			psyInfoL->maskThrNextSMS[j][b] = nbM;
+			psyInfoR->maskThrNextSMS[j][b] = nbS;
+			psyInfoL->maskEnNextSMS[j][b] = enM;
+			psyInfoR->maskEnNextSMS[j][b] = enS;
+
+			if (psyInfoL->maskThrS[j][b] <= 1.58*psyInfoR->maskThrS[j][b]
+				&& psyInfoR->maskThrS[j][b] <= 1.58*psyInfoL->maskThrS[j][b]) {
+
+				mld = gpsyInfo->mldS[b]*enM;
+				psyInfoL->maskThrSMS[j][b] = max(psyInfoL->maskThrSMS[j][b],
+					min(psyInfoR->maskThrSMS[j][b],mld));
+
+				mld = gpsyInfo->mldS[b]*enS;
+				psyInfoR->maskThrSMS[j][b] = max(psyInfoR->maskThrSMS[j][b],
+					min(psyInfoL->maskThrSMS[j][b],mld));
+			}
+
+			x1 = min(psyInfoL->maskThrS[j][b], psyInfoR->maskThrS[j][b]);
+			x2 = max(psyInfoL->maskThrS[j][b], psyInfoR->maskThrS[j][b]);
+			/* thresholds difference in db */
+			if (x2 >= 1000*x1) db = 3;
+			else db = log10(x2/x1);
+			if (db < 0.25) {
+#ifdef _DEBUG
+				ms_usedS++;
+#endif
+				channelInfoL->msInfo.ms_usedS[j][b] = 1;
+			} else {
+				channelInfoL->msInfo.ms_usedS[j][b] = 0;
+			}
+		}
+	}
+
+#ifdef _DEBUG
+	printf("%d\t", ms_usedS);
+#endif
+}
+
+void BlockSwitch(CoderInfo *coderInfo, PsyInfo *psyInfo, unsigned int numChannels)
+{
+	unsigned int channel;
+	int desire = ONLY_LONG_WINDOW;
+
+	/* Use the same block type for all channels
+	   If there is 1 channel that wants a short block,
+	   use a short block on all channels.
+	*/
+	for (channel = 0; channel < numChannels; channel++)
+	{
+		if (psyInfo[channel].block_type == ONLY_SHORT_WINDOW)
+			desire = ONLY_SHORT_WINDOW;
+	}
+
+	for (channel = 0; channel < numChannels; channel++)
+	{
+		if ((coderInfo[channel].block_type == ONLY_SHORT_WINDOW) ||
+			(coderInfo[channel].block_type == LONG_SHORT_WINDOW) ) {
+			if ((coderInfo[channel].desired_block_type==ONLY_LONG_WINDOW) &&
+				(desire == ONLY_LONG_WINDOW) ) {
+				coderInfo[channel].block_type = SHORT_LONG_WINDOW;
+			} else {
+				coderInfo[channel].block_type = ONLY_SHORT_WINDOW;
+			}
+		} else if (desire == ONLY_SHORT_WINDOW) {
+			coderInfo[channel].block_type = LONG_SHORT_WINDOW;
+		} else {
+			coderInfo[channel].block_type = ONLY_LONG_WINDOW;
+		}
+		coderInfo[channel].desired_block_type = desire;
+	}
+}
+
+static double freq2bark(double freq)
+{
+    double bark;
+
+    if(freq > 200.0)
+		bark = 26.81 / (1 + (1960 / freq)) - 0.53; 
+    else
+		bark = freq / 102.9;
+
+    return (bark);
+}
+
+static double ATHformula(double freq)
+{
+	/* short [MilliBel] is also sufficient */
+	static double tab [] = {
+		/*    10.0 */  96.69, 96.69, 96.26, 95.12,
+		/*    12.6 */  93.53, 91.13, 88.82, 86.76,
+		/*    15.8 */  84.69, 82.43, 79.97, 77.48,
+		/*    20.0 */  74.92, 72.39, 70.00, 67.62,
+		/*    25.1 */  65.29, 63.02, 60.84, 59.00,
+		/*    31.6 */  57.17, 55.34, 53.51, 51.67,
+		/*    39.8 */  50.04, 48.12, 46.38, 44.66,
+		/*    50.1 */  43.10, 41.73, 40.50, 39.22,
+		/*    63.1 */  37.23, 35.77, 34.51, 32.81,
+		/*    79.4 */  31.32, 30.36, 29.02, 27.60,
+		/*   100.0 */  26.58, 25.91, 24.41, 23.01,
+		/*   125.9 */  22.12, 21.25, 20.18, 19.00,
+		/*   158.5 */  17.70, 16.82, 15.94, 15.12,
+		/*   199.5 */  14.30, 13.41, 12.60, 11.98,
+		/*   251.2 */  11.36, 10.57,  9.98,  9.43,
+		/*   316.2 */   8.87,  8.46,  7.44,  7.12,
+		/*   398.1 */   6.93,  6.68,  6.37,  6.06,
+		/*   501.2 */   5.80,  5.55,  5.29,  5.02,
+		/*   631.0 */   4.75,  4.48,  4.22,  3.98,
+		/*   794.3 */   3.75,  3.51,  3.27,  3.22,
+		/*  1000.0 */   3.12,  3.01,  2.91,  2.68,
+		/*  1258.9 */   2.46,  2.15,  1.82,  1.46,
+		/*  1584.9 */   1.07,  0.61,  0.13, -0.35,
+		/*  1995.3 */  -0.96, -1.56, -1.79, -2.35,
+		/*  2511.9 */  -2.95, -3.50, -4.01, -4.21,
+		/*  3162.3 */  -4.46, -4.99, -5.32, -5.35,
+		/*  3981.1 */  -5.13, -4.76, -4.31, -3.13,
+		/*  5011.9 */  -1.79,  0.08,  2.03,  4.03,
+		/*  6309.6 */   5.80,  7.36,  8.81, 10.22,
+		/*  7943.3 */  11.54, 12.51, 13.48, 14.21,
+		/* 10000.0 */  14.79, 13.99, 12.85, 11.93,
+		/* 12589.3 */  12.87, 15.19, 19.14, 23.69,
+		/* 15848.9 */  33.52, 48.65, 59.42, 61.77,
+		/* 19952.6 */  63.85, 66.04, 68.33, 70.09,
+		/* 25118.9 */  70.66, 71.27, 71.91, 72.60,
+	};
+	double    freq_log;
+	unsigned  index;
+
+	if ( freq <    10. ) freq =    10.;
+	if ( freq > 25000. ) freq = 25000.;
+
+	freq_log = 40. * log10 (0.1 * freq);   /* 4 steps per third, starting at 10 Hz */
+	index    = (unsigned) freq_log;
+	return tab [index] * (1 + index - freq_log) + tab [index+1] * (freq_log - index);
+}
--- /dev/null
+++ b/libfaac/psych.h
@@ -1,0 +1,148 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: psych.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef PSYCH_H
+#define PSYCH_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifndef M_PI
+#define M_PI        3.14159265358979323846
+#endif
+
+#include "coder.h"
+#include "channels.h"
+
+typedef struct {
+	int size;
+	int sizeS;
+
+	/* Previous input samples */
+	double *prevSamples;
+	double *prevSamplesS;
+
+	/* FFT data */
+
+	/* Magnitude */
+	double *fftMagPlus2;
+	double *fftMagPlus1;
+	double *fftMag;
+	double *fftMagMin1;
+	double *fftMagMin2;
+
+	double *fftMagPlus2S[8];
+	double *fftMagPlus1S[8];
+	double *fftMagS[8];
+	double *fftMagMin1S[8];
+
+	/* Phase */
+	double *fftPhPlus2;
+	double *fftPhPlus1;
+	double *fftPh;
+	double *fftPhMin1;
+	double *fftPhMin2;
+
+	double *fftPhPlus2S[8];
+	double *fftPhPlus1S[8];
+	double *fftPhS[8];
+	double *fftPhMin1S[8];
+
+	/* Unpredictability */
+	double *cw;
+	double *cwS[8];
+
+	double lastPe;
+	double lastEnr;
+	int threeInARow;
+	int block_type;
+
+	/* Final threshold values */
+	double *maskThr;
+	double *maskEn;
+	double *maskThrS[8];
+	double *maskEnS[8];
+	double *maskThrNext;
+	double *maskEnNext;
+	double *maskThrNextS[8];
+	double *maskEnNextS[8];
+
+	double *lastNb;
+	double *lastNbMS;
+
+	double *maskThrMS;
+	double *maskEnMS;
+	double *maskThrSMS[8];
+	double *maskEnSMS[8];
+	double *maskThrNextMS;
+	double *maskEnNextMS;
+	double *maskThrNextSMS[8];
+	double *maskEnNextSMS[8];
+} PsyInfo;
+
+typedef struct {
+	double sampleRate;
+
+	/* Hann window */
+	double *hannWindow;
+	double *hannWindowS;
+
+	/* Stereo demasking thresholds */
+	double *mld;
+	double *mldS;
+
+	/* Spreading functions */
+	double spreading[MAX_SCFAC_BANDS][MAX_SCFAC_BANDS];
+	double spreadingS[MAX_SCFAC_BANDS][MAX_SCFAC_BANDS];
+	double *rnorm;
+	double *rnormS;
+
+	/* Absolute threshold of hearing */
+	double *ath;
+	double *athS;
+} GlobalPsyInfo;
+
+void PsyInit(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, unsigned int numChannels,
+			 unsigned int sampleRate, int *cb_width_long, int num_cb_long,
+			 int *cb_width_short, int num_cb_short);
+void PsyEnd(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, unsigned int numChannels);
+void PsyCalculate(ChannelInfo *channelInfo, GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo,
+				  int *cb_width_long, int num_cb_long, int *cb_width_short,
+				  int num_cb_short, unsigned int numChannels);
+void PsyBufferUpdate(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, double *newSamples);
+void BlockSwitch(CoderInfo *coderInfo, PsyInfo *psyInfo, unsigned int numChannels);
+
+static void Hann(GlobalPsyInfo *gpsyInfo, double *inSamples, int N);
+static void PsyUnpredictability(PsyInfo *psyInfo);
+static void PsyThreshold(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, int *cb_width_long,
+						 int num_cb_long, int *cb_width_short, int num_cb_short);
+static void PsyThresholdMS(ChannelInfo *channelInfoL, GlobalPsyInfo *gpsyInfo,
+						   PsyInfo *psyInfoL, PsyInfo *psyInfoR, int *cb_width_long,
+						   int num_cb_long, int *cb_width_short, int num_cb_short);
+static double freq2bark(double freq);
+static double ATHformula(double f);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* PSYCH_H */
\ No newline at end of file
--- /dev/null
+++ b/libfaac/util.c
@@ -1,0 +1,38 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: util.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+/* Returns the sample rate index */
+int GetSRIndex(unsigned int sampleRate)
+{
+	if (92017 <= sampleRate) return 0;
+	if (75132 <= sampleRate) return 1;
+	if (55426 <= sampleRate) return 2;
+	if (46009 <= sampleRate) return 3;
+	if (37566 <= sampleRate) return 4;
+	if (27713 <= sampleRate) return 5;
+	if (23004 <= sampleRate) return 6;
+	if (18783 <= sampleRate) return 7;
+	if (13856 <= sampleRate) return 8;
+	if (11502 <= sampleRate) return 9;
+	if (9391 <= sampleRate) return 10;
+
+	return 11;
+}
\ No newline at end of file
--- /dev/null
+++ b/libfaac/util.h
@@ -1,0 +1,38 @@
+/*
+ * FAAC - Freeware Advanced Audio Coder
+ * Copyright (C) 2001 Menno 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: util.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ */
+
+#ifndef UTIL_H
+#define UTIL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+
+int GetSRIndex(unsigned int sampleRate);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* UTIL_H */
--- a/ltp_enc.c
+++ /dev/null
@@ -1,901 +1,0 @@
-/*
- *	Long Term Prediction
- *
- *	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.2 $
-  $Date: 2000/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <stdio.h>
-#include <math.h>
-
-#include "quant.h"
-#include "interface.h"
-#include "transfo.h"
-#include "bitstream.h"
-#include "ltp_enc.h"
-
-
-/* short double_to_int (double sig_in); */
-#define double_to_int(sig_in) \
-  ((sig_in) > 32767 ? 32767 : (\
-    (sig_in) < -32768 ? -32768 : (\
-      (sig_in) > 0.0 ? (sig_in)+0.5 : (\
-        (sig_in) <= 0.0 ? (sig_in)-0.5 : 0))))
-
-
-void lnqgj (double (*a)[LPC + 1]);
-
-void w_quantize (double *freq, int *ltp_idx);
-
-/*  Purpose:	Codebook for LTP weight coefficients.  */
-double codebook[CODESIZE] =
-{
-  0.570829,
-  0.696616,
-  0.813004,
-  0.911304,
-  0.984900,
-  1.067894,
-  1.194601,
-  1.369533
-};
-
-/**************************************************************************
-  Title:	snr_pred
-
-  Purpose:	Determines is it feasible to employ long term prediction in 
-                the encoder.
-
-  Usage:        y = snr_pred(mdct_in, mdct_pred, sfb_flag, sfb_offset, 
-                             block_type, side_info, num_of_sfb)
-
-  Input:        mdct_in     -  spectral coefficients
-                mdct_pred   -  predicted spectral coefficients
-                sfb_flag    -  an array of flags indicating whether LTP is 
-                               switched on (1) /off (0). One bit is reseved 
-                               for each sfb.
-                sfb_offset  -  scalefactor boundaries
-                block_type  -  window sequence type
-		side_info   -  LTP side information
-		num_of_sfb  -  number of scalefactor bands
-
-  Output:	y - number of bits saved by using long term prediction     
-
-  References:	-
-
-  Explanation:	-
-
-  Author(s):	Juha Ojanpera, Lin Yin
-  *************************************************************************/
-
-double
-snr_pred (double *mdct_in,
-	  double *mdct_pred,
-	  int *sfb_flag,
-	  int *sfb_offset,
-	  enum WINDOW_TYPE block_type,
-	  int side_info,
-	  int num_of_sfb
-)
-{
-	int i, j, flen;
-	double snr_limit;
-	double num_bit, snr[NSFB_LONG];
-	double temp1, temp2;
-	double energy[BLOCK_LEN_LONG], snr_p[BLOCK_LEN_LONG];
-
-
-	if (block_type != ONLY_SHORT_WINDOW)
-    {
-		flen = BLOCK_LEN_LONG;
-		snr_limit = 1.e-30;
-    }
-	else
-    {
-		flen = BLOCK_LEN_SHORT;
-		snr_limit = 1.e-20;
-    }
-
-	for (i = 0; i < flen; i++)
-    {
-		energy[i] = mdct_in[i] * mdct_in[i];
-		snr_p[i] = (mdct_in[i] - mdct_pred[i]) * (mdct_in[i] - mdct_pred[i]);
-    }
-
-	num_bit = 0.0;
-
-	for (i = 0; i < num_of_sfb; i++)
-    {
-		temp1 = 0.0;
-		temp2 = 0.0;
-		for (j = sfb_offset[i]; j < sfb_offset[i + 1]; j++)
-		{
-			temp1 += energy[j];
-			temp2 += snr_p[j];
-		}
-
-		if (temp2 < snr_limit)
-			temp2 = snr_limit;
-
-		if (temp1 > /*1.e-20*/0.0)
-			snr[i] = -10. * log10 (temp2 / temp1);
-		else
-			snr[i] = 0.0;
-
-		sfb_flag[i] = 1;
-
-		if (block_type != ONLY_SHORT_WINDOW)
-		{
-			if (snr[i] <= 0.0)
-			{
-				sfb_flag[i] = 0;
-				for (j = sfb_offset[i]; j < sfb_offset[i + 1]; j++)
-					mdct_pred[j] = 0.0;
-			} else {
-				num_bit += snr[i] / 6. * (sfb_offset[i + 1] - sfb_offset[i]);
-			}
-		}
-    }
-
-	if (num_bit < side_info)
-    {
-		num_bit = 0.0;
-		for (j = 0; j < flen; j++)
-			mdct_pred[j] = 0.0;
-		for (i = 0; i < num_of_sfb; i++)
-			sfb_flag[i] = 0;
-    }
-	else
-		num_bit -= side_info;
-
-	return (num_bit);
-}
-
-
-/**************************************************************************
-  Title:	prediction
-
-  Purpose:	Predicts current frame from the past output samples.
-
-  Usage:        prediction(buffer, predicted_samples, weight, delay, flen)
-
-  Input:	buffer	          - past reconstructed output samples
-                weight            - LTP gain (scaling factor)
-		delay             - LTP lag (optimal delay)
-                flen              - length of the frame
-
-  Output:	predicted_samples - predicted samples
-
-  References:	-
-
-  Explanation:  -
-
-  Author(s):	Juha Ojanpera, Lin Yin
-  *************************************************************************/
-
-void
-prediction (short *buffer,
-	    double *predicted_samples,
-	    double *weight,
-	    int delay,
-	    int flen
-)
-{
-
-  int i, j;
-  int offset;
-
-  for (i = 0; i < flen; i++)
-    {
-      offset = LT_BLEN - flen - delay + i - (LPC - 1) / 2;
-      predicted_samples[i] = 0.0;
-      for (j = 0; j < LPC; j++)
-	predicted_samples[i] += weight[j] * buffer[offset + j];
-    }
-
-}
-
-
-/**************************************************************************
-  Title:	estimate_delay
-
-  Purpose:      Estimates optimal delay between current frame and past
-                reconstructed output samples. The lag between 0...DELAY-1 
-                with the maximum correlation becomes the LTP lag (or delay).
-
-  Usage:        y = estimate_delay(sb_samples, x_buffer, flen)
-
-  Input:	sb_samples - current frame
-                x_buffer   - past reconstructed output samples
-                flen       - length of the frame
-
-  Output:	y  - LTP lag
-
-  References:	-
-
-  Explanation:	-
-
-  Author(s):	Juha Ojanpera, Lin Yin
-  *************************************************************************/
-
-int estimate_delay (double *sb_samples,
-		    short *x_buffer
-//		    ,int flen
-		    )
-{
-	int i, j;
-	int delay;
-	double corr[DELAY],corrtmp;
-	double p_max, energy;
-
-	p_max = 0.0;
-	delay = 0;
-		energy = 0.0;
-		corr[0] = 0.0;
-		for (j = 1; j < 2049; j++)
-		{
-			corr[0] += x_buffer[LT_BLEN - j] * sb_samples[2048 - j];
-			energy += x_buffer[LT_BLEN - j] * x_buffer[LT_BLEN - j];
-		}
-		corrtmp=corr[0];
-		if (energy != 0.0)
-			corr[0] = corr[0] / sqrt(energy);
-		else
-			corr[0] = 0.0;
-
-		if (p_max < corr[0])
-		{
-			p_max = corr[0];
-			delay = 0;
-		}
-
-	/* Used to look like this:
-	   for (i = 1; i < DELAY; i+=16)
-	   Because the new code by Oxygene2000 is so fast, we can now look for the
-	   delay in steps of 1, instead of 16. Thus giving a more accurate delay estimation
-	*/
-	for (i = 1; i < DELAY; i++)
-	{
-		energy -= x_buffer[LT_BLEN - i] * x_buffer[LT_BLEN - i];
-		energy += x_buffer[LT_BLEN - i - 2048] * x_buffer[LT_BLEN - i - 2048]; //2048=j_max
-		corr[i] = corrtmp;
-		corr[i] -= x_buffer[LT_BLEN - i] * sb_samples[2047];
-		corr[i] += x_buffer[LT_BLEN - i - 2048] * sb_samples[0];
-		corrtmp=corr[i];
-//flen=2048
-//		for (j = 1; j < 2049; j++) //2049=flen+1
-//		{
-//			corr[i] += x_buffer[LT_BLEN - i - j] * sb_samples[2048 - j];
-//			energy += x_buffer[LT_BLEN - i - j] * x_buffer[LT_BLEN - i - j];
-//		}
-		if (energy != 0.0)
-			corr[i] = corr[i] / sqrt(energy);
-		else
-			corr[i] = 0.0;
-
-		if (p_max < corr[i])
-		{
-			p_max = corr[i];
-			delay = i;
-		}
-	}
-
-//	if (delay < (LPC - 1) / 2)
-//		delay = (LPC - 1) / 2;
-	if (delay<0) delay=0; //for LPC=1
-
-	/*
-	fprintf(stdout, "delay : %d ... ", delay);
-	*/
-
-	return delay;
-}
-
-
-/**************************************************************************
-  Title:	pitch
-
-  Purpose:	Calculates LTP gains, quantizes them and finally scales
-                the past output samples (from 'delay' to 'delay'+'flen') 
-                to get the predicted frame.
-
-  Usage:	pitch(sb_samples, sb_samples_pred, x_buffer, ltp_coef, 
-                      delay, flen)
-
-  Input:        sb_samples      - current frame
-                x_buffer        - past reconstructed output samples
-                delay           - LTP lag
-                flen            - length of the frame
-
-  Output:	sb_samples_pred - predicted frame
-                ltp_coef        - indices of the LTP gains
-
-  References:	1.)  lnqgj
-                2.)  w_quantize
-                3.)  prediction
-
-  Explanation:	-
-
-  Author(s):	Juha Ojanpera, Lin Yin
-  *************************************************************************/
-
-void
-pitch (double *sb_samples,
-       double *sb_samples_pred,
-       short *x_buffer,
-       int *ltp_coef,
-       int delay,
-       int flen
-)
-{
-	int i, k, j;
-	int offset1, offset2;
-	double weight[LPC];
-	double r[LPC][LPC + 1];
-
-
-	for (i = 0; i < LPC; i++)
-		for (j = 0; j < LPC; j++)
-		{
-			offset1 = LT_BLEN - flen - delay + i - (LPC - 1) / 2;
-			offset2 = LT_BLEN - flen - delay + j - (LPC - 1) / 2;
-			r[i][j] = 0.0;
-			for (k = 0; k < flen; k++)
-				r[i][j] += x_buffer[offset1 + k] * x_buffer[offset2 + k];
-		}
-	for (i = 0; i < LPC; i++)
-		r[i][i] = 1.010 * r[i][i];
-
-	for (i = 0; i < LPC; i++)
-    {
-		offset1 = LT_BLEN - flen - delay + i - (LPC - 1) / 2; 
-		r[i][LPC] = 0.0;
-		for (k = 0; k < flen; k++)
-			r[i][LPC] += x_buffer[offset1 + k] * sb_samples[k];
-    }
-
-	for (i = 0; i < LPC; i++)
-		weight[i] = 0.0;
-
-	if (r[(LPC - 1) / 2][(LPC - 1) / 2] != 0.0)
-		weight[(LPC - 1) / 2] = r[(LPC - 1) / 2][LPC] / r[(LPC - 1) / 2][(LPC - 1) / 2];
-
-	lnqgj (r);
-
-	for (i = 0; i < LPC; i++)
-		weight[i] = r[i][LPC];
-
-	/* 
-	fprintf(stdout, "unquantized weight : %f ... ", weight[0]);
-	*/
-
-	w_quantize (weight, ltp_coef);
-
-	/*
-	fprintf(stdout, "quantized weight : %f\n", weight[0]);    
-	*/
-
-	prediction (x_buffer, sb_samples_pred, weight, delay, flen);
-}
-
-
-/**************************************************************************
-  Title:	lnqgj
-
-  Purpose:	Calculates LTP gains.
-
-  Usage:	lnqgj(a)
-
-  Input:	a - auto-correlation matrix
-
-  Output:	a - LTP gains (in the last column)   
-
-  References:	-
-
-  Explanation:	-
-
-  Author(s):	Juha Ojanpera, Lin Yin
-  *************************************************************************/
-
-void
-lnqgj (double (*a)[LPC + 1])
-{
-	int nn, nnpls1, ip, i, j;
-	double p, w;
-
-	for (nn = 0; nn < LPC; nn++)
-    {
-		p = 0.0;
-		nnpls1 = nn + 1;
-		for (i = nn; i < LPC; i++)
-			if (p - fabs (a[i][nn]) < 0)
-			{
-				p = fabs (a[i][nn]);
-				ip = i;
-			}
-
-		if (p - 1.e-10 <= 0)
-			return;
-
-		if (p - 1.e-10 > 0)
-		{
-			for (j = nn; j <= LPC; j++)
-			{
-				w = a[nn][j];
-				a[nn][j] = a[ip][j];
-				a[ip][j] = w;
-			}
-
-			for (j = nnpls1; j <= LPC; j++)
-				a[nn][j] = a[nn][j] / a[nn][nn];
-
-			for (i = 0; i < LPC; i++)
-				if ((i - nn) != 0)
-					for (j = nnpls1; j <= LPC; j++)
-						a[i][j] = a[i][j] - a[i][nn] * a[nn][j];
-		}
-    }
-}
-
-
-/**************************************************************************
-  Title:	w_quantize
-
-  Purpose:	Quantizes LTP gain(s).
-
-  Usage:	w_quantize(freq, ltp_idx)
-
-  Input:	freq    - original LTP gain(s)
-
-  Output:	freq    - LTP gain(s) selected from the codebook
-                ltp_idx - corresponding indices of the LTP gain(s)
-
-  References:	-
-
-  Explanation:	The closest value from the codebook is selected to be the
-                quantized LTP gain.
-
-  Author(s):	Juha Ojanpera, Lin Yin
-  *************************************************************************/
-
-void
-w_quantize (double *freq, int *ltp_idx)
-{
-	int i, j;
-	double dist, low;
-
-
-	low = 1.0e+10;
-	for (i = 0; i < LPC; i++)
-    {
-//		dist = 0.0;
-		for (j = 0; j < CODESIZE; j++)
-		{
-			dist = (freq[i] - codebook[j]) * (freq[i] - codebook[j]);
-			if (dist < low)
-			{
-				low = dist;
-				ltp_idx[i] = j;
-			}
-		}
-    }
-
-	for (j = 0; j < LPC; j++)
-		freq[j] = codebook[ltp_idx[j]];
-}
-
-
-/**************************************************************************
-  Title:	init_lt_pred
-
-  Purpose:	Initialize the history buffer for long term prediction
-
-  Usage:        init_lt_pred (lt_status)
-
-  Input:	lt_status
-  			- buffer: history buffer
-                        - pred_mdct: prediction transformed to frequency 
-                          domain
-                        - weight_idx : 
-                          3 bit number indicating the LTP coefficient in 
-                          the codebook 
-                        - sbk_prediction_used:
-                          1 bit for each subblock indicating wheather
-                          LTP is used in that subblock 
-                        - sfb_prediction_used:
-                          1 bit for each scalefactor band (sfb) where LTP 
-                          can be used indicating whether LTP is switched 
-                          on (1) /off (0) in that sfb.
-                        - delay: LTP lag
-                        - side_info: LTP side information
-
-  Output:	lt_status
-  			- buffer: filled with 0
-                        - pred_mdct: filled with 0
-                        - weight_idx : filled with 0
-                        - sbk_prediction_used: filled with 0
-                        - sfb_prediction_used: filled with 0
-                        - delay: filled with 0
-                        - side_info: filled with 1
-
-  References:	-
-
-  Explanation:	-
-
-  Author(s):	Mikko Suonio
-  *************************************************************************/
-void
-init_lt_pred(LT_PRED_STATUS *lt_status)
-{
-	int i;
-
-	for (i = 0; i < LT_BLEN; i++)
-		lt_status->buffer[i] = 0;
-
-	for (i = 0; i < BLOCK_LEN_LONG; i++)
-		lt_status->pred_mdct[i] = 0;
-
-	lt_status->weight_idx = 0;
-	for(i=0; i < MAX_SHORT_WINDOWS; i++)
-		lt_status->sbk_prediction_used[i] = lt_status->delay[i] = 0;
-
-	for(i=0; i<MAX_SCFAC_BANDS; i++)
-		lt_status->sfb_prediction_used[i] = 0;
-
-	lt_status->side_info = LEN_LTP_DATA_PRESENT;
-}
-
-
-/**************************************************************************
-  Title:	ltp_enc
-
-  Purpose:      Performs long term prediction.
-
-  Usage:	ltp_enc(p_spectrum, p_time_signal, win_type, win_shape, 
-                            sfb_offset, num_of_sfb, lt_status, buffer_update)
-
-  Input:        p_spectrum    - spectral coefficients
-                p_time_signal - time domain input samples
-                win_type      - window sequence (frame, block) type
-                win_shape     - shape of the mdct window
-                sfb_offset    - scalefactor band boundaries
-                num_of_sfb    - number of scalefactor bands in each block
-
-  Output:	p_spectrum    - residual spectrum
-                lt_status     - buffer: history buffer
-                              - pred_mdct:prediction transformed to frequency domain
-                                for subsequent use
-                              - weight_idx : 
-                                3 bit number indicating the LTP coefficient in 
-                                the codebook 
-                              - sbk_prediction_used: 
-                                1 bit for each subblock indicating wheather
-                                LTP is used in that subblock 
-                              - sfb_prediction_used:
-                                1 bit for each scalefactor band (sfb) where LTP 
-                                can be used indicating whether LTP is switched 
-                                on (1) /off (0) in that sfb.
-                              - delay: LTP lag
-                              - side_info: LTP side information
-                        
-  References:	1.) estimate_delay in pitch.c
-                2.) pitch in pitch.c
-                3.) buffer2freq
-                4.) snr_pred in pitch.c
-                5.) freq2buffer
-                6.) double_to_int
-
-  Explanation:  -
-
-  Author(s):	Juha Ojanpera
-  *************************************************************************/
-
-int
-ltp_enc(double *p_spectrum, double *p_time_signal, enum WINDOW_TYPE win_type,
-            Window_shape win_shape, int *sfb_offset, int num_of_sfb,
-            LT_PRED_STATUS *lt_status)
-{
-    int i;
-    int last_band;
-    double num_bit[MAX_SHORT_WINDOWS];
-    double predicted_samples[2 * BLOCK_LEN_LONG];
-
-    lt_status->global_pred_flag = 0;
-    lt_status->side_info = 1;
-
-    switch(win_type)
-    {
-	case ONLY_LONG_WINDOW:
-	case LONG_SHORT_WINDOW:
-	case SHORT_LONG_WINDOW:
-		last_band = (num_of_sfb < MAX_LT_PRED_LONG_SFB) ? num_of_sfb : MAX_LT_PRED_LONG_SFB;
-
-//		lt_status->delay[0] = estimate_delay (p_time_signal, lt_status->buffer, 2 * BLOCK_LEN_LONG);
-		lt_status->delay[0] = estimate_delay (p_time_signal, lt_status->buffer);
-
-//		fprintf(stderr, "(LTP) lag : %i ", lt_status->delay[0]);
-
-		pitch (p_time_signal, predicted_samples, lt_status->buffer,
-			&lt_status->weight_idx, lt_status->delay[0], 2 * BLOCK_LEN_LONG);
-
-		/* Transform prediction to frequency domain and save it for subsequent use. */
-		buffer2freq (predicted_samples, lt_status->pred_mdct, NULL, win_type, WS_SIN, WS_SIN, MNON_OVERLAPPED);
-
-		lt_status->side_info = LEN_LTP_DATA_PRESENT + last_band + LEN_LTP_LAG + LEN_LTP_COEF;
-
-		num_bit[0] = snr_pred (p_spectrum, lt_status->pred_mdct,
-			lt_status->sfb_prediction_used, sfb_offset,
-			win_type, lt_status->side_info, last_band);
-
-//		if (num_bit[0] > 0) {
-//			fprintf(stderr, "(LTP) lag : %i ", lt_status->delay[0]);
-//			fprintf(stderr, " bit gain : %f\n", num_bit[0]);
-//		}
-
-		lt_status->global_pred_flag = (num_bit[0] == 0.0) ? 0 : 1;
-
-		if(lt_status->global_pred_flag)
-			for (i = 0; i < sfb_offset[last_band]; i++)
-				p_spectrum[i] -= lt_status->pred_mdct[i];
-		else
-			lt_status->side_info = 1;
-        break;
-
-	case ONLY_SHORT_WINDOW:
-		break;
-    }
-
-    return (lt_status->global_pred_flag);
-}
-
-
-/**************************************************************************
-  Title:	ltp_reconstruct
-
-  Purpose:      Updates LTP history buffer.
-
-  Usage:	ltp_reconstruct(p_spectrum, win_type,  win_shape, 
-                                    block_size_long, block_size_medium,
-                                    block_size_short, sfb_offset, 
-                                    num_of_sfb, lt_status)
-
-  Input:        p_spectrum    - reconstructed spectrum
-                win_type      - window sequence (frame, block) type
-                win_shape     - shape of the mdct window
-                sfb_offset    - scalefactor band boundaries
-                num_of_sfb    - number of scalefactor bands in each block
-
-  Output:	p_spectrum    - reconstructed spectrum
-                lt_status     - buffer: history buffer
-
-  References:	1.) buffer2freq
-                2.) freq2buffer
-                3.) double_to_int
-
-  Explanation:  -
-
-  Author(s):	Juha Ojanpera
-  *************************************************************************/
-
-void
-ltp_reconstruct(double *p_spectrum, enum WINDOW_TYPE win_type, 
-                Window_shape win_shape, int *sfb_offset, int num_of_sfb,
-                LT_PRED_STATUS *lt_status)
-{
-	int i, j, last_band;
-	double predicted_samples[2 * BLOCK_LEN_LONG];
-	double overlap_buffer[2 * BLOCK_LEN_LONG];
-
-    
-	switch(win_type)
-	{
-	case ONLY_LONG_WINDOW:
-	case LONG_SHORT_WINDOW:
-	case SHORT_LONG_WINDOW:
-		last_band = (num_of_sfb < MAX_LT_PRED_LONG_SFB) ? num_of_sfb : MAX_LT_PRED_LONG_SFB;
-
-		if(lt_status->global_pred_flag)
-			for (i = 0; i < sfb_offset[last_band]; i++)
-				p_spectrum[i] += lt_status->pred_mdct[i];
-
-		/* Finally update the time domain history buffer. */
-		freq2buffer (p_spectrum, predicted_samples, overlap_buffer, win_type, WS_SIN, WS_SIN, MNON_OVERLAPPED);
-
-		for (i = 0; i < LT_BLEN - BLOCK_LEN_LONG; i++)
-			lt_status->buffer[i] = lt_status->buffer[i + BLOCK_LEN_LONG];
-
-		j = LT_BLEN - 2 * BLOCK_LEN_LONG;
-		for (i = 0; i < BLOCK_LEN_LONG; i++)
-		{
-			lt_status->buffer[i + j] =
-				(short)double_to_int (predicted_samples[i] + lt_status->buffer[i + j]);
-			lt_status->buffer[LT_BLEN - BLOCK_LEN_LONG + i] =
-				(short)double_to_int (predicted_samples[i + BLOCK_LEN_LONG]);
-		}
-		break;
-
-    case ONLY_SHORT_WINDOW:
-#if 0
-		for (i = 0; i < LT_BLEN - block_size_long; i++)
-			lt_status->buffer[i] = lt_status->buffer[i + block_size_long];
-
-		for (i = LT_BLEN - block_size_long; i < LT_BLEN; i++)
-			lt_status->buffer[i] = 0;
-
-		for (i = 0; i < block_size_long; i++)
-			overlap_buffer[i] = 0;
-
-		/* Finally update the time domain history buffer. */
-		freq2buffer (p_spectrum, predicted_samples, overlap_buffer, win_type, block_size_long,
-			block_size_medium, block_size_short, win_shape, MNON_OVERLAPPED);
-
-		for(sw = 0; sw < MAX_SHORT_WINDOWS; sw++)
-		{
-			i = LT_BLEN - 2 * block_size_long + SHORT_SQ_OFFSET + sw * block_size_short;
-			for (j = 0; j < 2 * block_size_short; j++)
-				lt_status->buffer[i + j] = double_to_int (predicted_samples[sw * block_size_short * 2 + j] + 
-				lt_status->buffer[i + j]);
-		}
-#endif
-		break;
-	}
-
-	return;
-}                      
-
-
-/**************************************************************************
-  Title:	ltp_encode
-
-  Purpose:      Writes LTP parameters to the bit stream.
-
-  Usage:	ltp_encode (bs, win_type, num_of_sfb, lt_status)
-
-  Input:        bs         - bit stream
-                win_type   - window sequence (frame, block) type
-                num_of_sfb - number of scalefactor bands
-                lt_status  - side_info:
-			     1, if prediction not used in this frame
-			     >1 otherwise
-                           - weight_idx : 
-                             3 bit number indicating the LTP coefficient in 
-                             the codebook
-                           - sfb_prediction_used:
-                             1 bit for each scalefactor band (sfb) where LTP 
-                             can be used indicating whether LTP is switched 
-                             on (1) /off (0) in that sfb.
-                           - delay: LTP lag
-
-  Output:	-
-
-  References:	1.) BsPutBit
-
-  Explanation:  -
-
-  Author(s):	Juha Ojanpera
-  *************************************************************************/
-
-int
-ltp_encode (AACQuantInfo *quantInfo, BsBitStream *bs, int write_flag)
-{
-	int i, last_band;
-//	int first_subblock;
-//	int prev_subblock;
-	int bit_count = 0;
-
-
-	bit_count += 1;
-	
-	if (quantInfo->ltpInfo.side_info > 1)
-	{
-		if(write_flag)
-			BsPutBit (bs, 1, 1);    	/* LTP used */
-
-		switch(quantInfo->block_type)
-		{
-		case ONLY_LONG_WINDOW:
-		case LONG_SHORT_WINDOW:
-		case SHORT_LONG_WINDOW:
-			bit_count += LEN_LTP_LAG;
-			bit_count += LEN_LTP_COEF;
-			if(write_flag)
-			{
-				BsPutBit (bs, quantInfo->ltpInfo.delay[0], LEN_LTP_LAG);
-				BsPutBit (bs, quantInfo->ltpInfo.weight_idx,  LEN_LTP_COEF);
-			}
-
-			last_band = (quantInfo->nr_of_sfb < MAX_LT_PRED_LONG_SFB) ? quantInfo->nr_of_sfb : MAX_LT_PRED_LONG_SFB;
-			bit_count += last_band;
-			if(write_flag)
-			{
-				for (i = 0; i < last_band; i++)
-					BsPutBit (bs, quantInfo->ltpInfo.sfb_prediction_used[i], LEN_LTP_LONG_USED);
-			}
-			break;
-			
-		case ONLY_SHORT_WINDOW:
-#if 0
-			for(i=0; i < MAX_SHORT_WINDOWS; i++)
-			{
-				if(lt_status->sbk_prediction_used[i])
-				{
-					first_subblock = i;
-					break;
-				}
-			}
-			bit_count += LEN_LTP_LAG;
-			bit_count += LEN_LTP_COEF;
-			
-			if(write_flag)
-			{
-				BsPutBit (bs, lt_status->delay[first_subblock], LEN_LTP_LAG);
-				BsPutBit (bs, lt_status->weight_idx,  LEN_LTP_COEF);
-			}
-
-			prev_subblock = first_subblock;
-			for(i = 0; i < MAX_SHORT_WINDOWS; i++)
-			{
-				bit_count += LEN_LTP_SHORT_USED;
-				if(write_flag)
-					BsPutBit (bs, lt_status->sbk_prediction_used[i], LEN_LTP_SHORT_USED);
-
-				if(lt_status->sbk_prediction_used[i])
-				{
-					if(i > first_subblock)
-					{
-						int diff;
-						
-						diff = lt_status->delay[prev_subblock] - lt_status->delay[i];
-						if(diff)
-						{
-							bit_count += 1;
-							bit_count += LEN_LTP_SHORT_LAG;
-							if(write_flag)
-							{
-								BsPutBit (bs, 1, 1);
-								BsPutBit (bs, diff + LTP_LAG_OFFSET, LEN_LTP_SHORT_LAG);
-							}
-						}
-						else
-						{
-							bit_count += 1;
-							if(write_flag)
-								BsPutBit (bs, 0, 1);
-						}
-					}
-				}
-			}
-			break;
-#endif
-		default:
-			//        CommonExit(1, "ltp_encode : unsupported window sequence %i", win_type);
-			break;
-		}
-	}
-	else
-		if(write_flag)
-			BsPutBit (bs, 0, 1);    	/* LTP not used */
-
-	return (bit_count);
-}
--- a/ltp_enc.h
+++ /dev/null
@@ -1,124 +1,0 @@
-/*
- *	Function prototypes for LTP
- *
- *	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.2 $
-  $Date: 2000/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _LTP_ENC_H
-#define _LTP_ENC_H
-
-#include "interface.h"
-#include "bitstream.h"
-#include "quant.h"
-
-/*
-  Macro:	LT_BLEN
-  Purpose:	Length of the history buffer.
-  Explanation:	Has to hold two long windows of time domain data.  */
-#ifndef	LT_BLEN
-#define LT_BLEN (4 * BLOCK_LEN_LONG)
-#endif
-
-/*  Purpose:      Number of LTP coefficients. */
-#define LPC 1
-/*  Purpose:      Maximum LTP lag.  */
-#define DELAY 2048
-/*  Purpose:	Length of the bitstream element ltp_data_present.  */
-#define	LEN_LTP_DATA_PRESENT 1
-/*  Purpose:	Length of the bitstream element ltp_lag.  */
-#define	LEN_LTP_LAG 11
-/*  Purpose:	Length of the bitstream element ltp_coef.  */
-#define	LEN_LTP_COEF 3
-/*  Purpose:	Length of the bitstream element ltp_short_used.  */
-#define	LEN_LTP_SHORT_USED 1
-/*  Purpose:	Length of the bitstream element ltp_short_lag_present.  */
-#define	LEN_LTP_SHORT_LAG_PRESENT 1
-/*  Purpose:	Length of the bitstream element ltp_short_lag.  */
-#define	LEN_LTP_SHORT_LAG 5
-/*  Purpose:	Offset of the lags written in the bitstream.  */
-#define	LTP_LAG_OFFSET 16
-/*  Purpose:	Length of the bitstream element ltp_long_used.  */
-#define	LEN_LTP_LONG_USED 1
-/* Purpose:	Upper limit for the number of scalefactor bands
-    		which can use lt prediction with long windows.
-   Explanation:	Bands 0..MAX_LT_PRED_SFB-1 can use lt prediction.  */
-#define	MAX_LT_PRED_LONG_SFB 40
-/* Purpose:	Upper limit for the number of scalefactor bands
-    		which can use lt prediction with short windows.
-   Explanation:	Bands 0..MAX_LT_PRED_SFB-1 can use lt prediction.  */
-#define	MAX_LT_PRED_SHORT_SFB 13
-/* Purpose:      Buffer offset to maintain block alignment.
-   Explanation:  This is only used for a short window sequence.  */
-#define SHORT_SQ_OFFSET (BLOCK_LEN_LONG-(BLOCK_LEN_SHORT*4+BLOCK_LEN_SHORT/2))
-/*  Purpose:	Number of codes for LTP weight. */
-#define CODESIZE 8
-/* Purpose:      Float type for external data
-   Explanation:  - */
-typedef double float_ext;
-
-/* Type:		LT_PRED_STATUS
-   Purpose:	Type of the struct holding the LTP encoding parameters.
-   Explanation:	-  */
-typedef struct _LT_PRED_STATUS
-{
-    short buffer[LT_BLEN];
-    double pred_mdct[2 * BLOCK_LEN_LONG];
-    int weight_idx;
-    double weight;
-    int sbk_prediction_used[MAX_SHORT_WINDOWS];
-    int sfb_prediction_used[MAX_SCFAC_BANDS];
-    int *delay;
-    int global_pred_flag;
-    int side_info;
-} LT_PRED_STATUS;
-
-double snr_pred (double *mdct_in, double *mdct_pred, int *sfb_flag,
-                        int *sfb_offset, enum WINDOW_TYPE block_type, int side_info,
-                        int num_of_sfb);
-
-void prediction (short *buffer, double *predicted_samples, double *weight,
-                        int delay, int flen);
-
-int estimate_delay (double *sb_samples, short *x_buffer);
-
-void pitch (double *sb_samples, double *sb_samples_pred, short *x_buffer,
-                   int *ltp_coef, int delay, int flen);
-
-void init_lt_pred(LT_PRED_STATUS * lt_status);
-
-int ltp_enc(double *p_spectrum, double *p_time_signal,
-		       enum WINDOW_TYPE win_type, Window_shape win_shape,
-		       int *sfb_offset, int num_of_sfb,
-		       LT_PRED_STATUS *lt_status);
-
-void ltp_reconstruct(double *p_spectrum, enum WINDOW_TYPE win_type, 
-                            Window_shape win_shape, 
-                            int *sfb_offset, int num_of_sfb,
-                            LT_PRED_STATUS *lt_status);
-
-int ltp_encode (struct _AACQuantInfo *quantInfo, BsBitStream *bs, int write_flag);
-
-#endif /* not defined _LTP_ENC_H */
-
--- a/mc_enc.c
+++ /dev/null
@@ -1,113 +1,0 @@
-/*
- *	Multichannel configuration
- *
- *	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/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include "mc_enc.h"
-#include "quant.h"
-
-void DetermineChInfo(AACQuantInfo *quantInfo, int numChannels, int lfePresent) {
-   
-  /* If LFE present                                                       */
-  /*  Num channels       # of SCE's       # of CPE's       #of LFE's      */ 
-  /*  ============       ==========       ==========       =========      */
-  /*      1                  1                0               0           */
-  /*      2                  0                1               0           */
-  /*      3                  1                1               0           */
-  /*      4                  1                1               1           */
-  /*      5                  1                2               0           */
-  /* For more than 5 channels, use the following elements:                */
-  /*      2*N                1                2*(N-1)         1           */
-  /*      2*N+1              1                2*N             0           */
-  /*                                                                      */
-  /* Else:                                                                */
-  /*                                                                      */  
-  /*  Num channels       # of SCE's       # of CPE's       #of LFE's      */
-  /*  ============       ==========       ==========       =========      */
-  /*      1                  1                0               0           */
-  /*      2                  0                1               0           */
-  /*      3                  1                1               0           */
-  /*      4                  2                1               0           */
-  /*      5                  1                2               0           */
-  /* For more than 5 channels, use the following elements:                */
-  /*      2*N                2                2*(N-1)         0           */
-  /*      2*N+1              1                2*N             0           */
-
-	int sceTag=0;
-	int lfeTag=0;
-	int cpeTag=0;
-	int numChannelsLeft=numChannels;
-
-	
-	/* First element is sce, except for 2 channel case */
-	if (numChannelsLeft!=2) {
-		quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.tag=sceTag++;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=0;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=0;    
-		numChannelsLeft--;
-	}
-
-	/* Next elements are cpe's */
-	while (numChannelsLeft>1) {
-		/* Left channel info */
-		quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.tag=cpeTag++;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=1;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.common_window=0;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.ch_is_left=1;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.paired_ch=numChannels-numChannelsLeft+1;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=0;    
-		numChannelsLeft--;
-		
-		/* Right channel info */
-		quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=1;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.common_window=0;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.ch_is_left=0;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.paired_ch=numChannels-numChannelsLeft-1;
-		quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=0;
-		numChannelsLeft--;
-	}
-
-	/* Is there another channel left ? */
-	if (numChannelsLeft) {
-		if (lfePresent) { 
-			quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
-			quantInfo[numChannels-numChannelsLeft].channelInfo.tag=lfeTag++;
-			quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=0;
-			quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=1; 
-		} else {
-			quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
-			quantInfo[numChannels-numChannelsLeft].channelInfo.tag=sceTag++;
-			quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=0;
-			quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=0;
-		}
-		numChannelsLeft--;
-	}
-}
-
-
--- a/mc_enc.h
+++ /dev/null
@@ -1,39 +1,0 @@
-/*
- *	Function prototypes for multichannel configuration
- *
- *	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/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef MC_ENC
-#define MC_ENC
-
-#include "interface.h"
-
-void DetermineChInfo(struct _AACQuantInfo *quantInfo, int numChannels, int lfePresent);
-
-
-#endif
-
-
--- a/ms.c
+++ /dev/null
@@ -1,541 +1,0 @@
-/*
- *	MS stereo coding
- *
- *	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.15 $
-  $Date: 2000/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include "psych.h"
-#include "ms.h"
-
-void MSPreprocess(double p_ratio_long[][MAX_SCFAC_BANDS],
-		  double p_ratio_short[][MAX_SCFAC_BANDS],
-		  CH_PSYCH_OUTPUT_LONG p_chpo_long[],
-		  CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
-		  enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
-		  AACQuantInfo* quantInfo,               /* Quant info */
-		  int use_ms,
-		   int numberOfChannels
-		  )
-{
-	int chanNum;
-	int sfbNum;
-
-	int used = 0, notused = 0;
-	int realyused = 0;
-
-	/* Look for channel_pair_elements */
-	for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
-		if (quantInfo[chanNum].channelInfo.present) {
-			if ((quantInfo[chanNum].channelInfo.cpe)&&(quantInfo[chanNum].channelInfo.ch_is_left)) {
-				int leftChan=chanNum;
-				int rightChan=quantInfo[chanNum].channelInfo.paired_ch;
-				quantInfo[leftChan].channelInfo.ms_info.is_present=0;
-				quantInfo[leftChan].channelInfo.common_window = 0;
-
-				/* Perform MS if block_types are the same */
-				if ((block_type[leftChan]==block_type[rightChan])&&(use_ms==0)) {
-					int numGroups;
-					int groupIndex = 0;
-					int maxSfb, isBand;
-					int g,b,j;
-					int use_ms_short;
-					MS_Info *msInfo;
-
-					numGroups = quantInfo[leftChan].num_window_groups;
-					maxSfb = quantInfo[leftChan].max_sfb;
-
-					/* Determine which bands should be enabled */
-					msInfo = &(quantInfo[leftChan].channelInfo.ms_info);
-					isBand = maxSfb;
-
-					for (g=0;g<numGroups;g++) {
-						for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
-							use_ms_short = 1;
-							b = g*maxSfb+sfbNum;
-
-							if (block_type[leftChan] == ONLY_SHORT_WINDOW) {
-								for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
-									use_ms_short = min(use_ms_short, p_chpo_short[rightChan][j].use_ms[sfbNum]);
-								}
-								if (sfbNum < isBand) {
-									msInfo->ms_used[b] = use_ms_short;
-								}
-								else {
-									msInfo->ms_used[b] = 0;
-									use_ms_short = 0;
-								}
-
-								if (msInfo->ms_used[b]) {
-									realyused = 1;
-									used++;
-									for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
-										p_ratio_short[leftChan][(g*maxSfb)+sfbNum] = p_chpo_short[leftChan][j].p_ratio[sfbNum];
-										p_ratio_short[rightChan][(g*maxSfb)+sfbNum] = p_chpo_short[rightChan][j].p_ratio[sfbNum];
-										p_chpo_short[rightChan][j].use_ms[sfbNum] = use_ms_short;
-									}
-								}
-								else {
-									notused++;
-									for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
-										p_ratio_short[leftChan][(g*maxSfb)+sfbNum] = p_chpo_short[leftChan][j].p_ratio[sfbNum];
-										p_ratio_short[rightChan][(g*maxSfb)+sfbNum] = p_chpo_short[rightChan][j].p_ratio[sfbNum];
-										p_chpo_short[rightChan][j].use_ms[sfbNum] = use_ms_short;
-									}
-								}
-							}
-							else {
-								if (sfbNum < isBand) {
-									msInfo->ms_used[b] = p_chpo_long[rightChan].use_ms[sfbNum];
-								}
-								else {
-									msInfo->ms_used[b] = 0;
-									p_chpo_long[rightChan].use_ms[sfbNum] = 0;
-								}
-								if (msInfo->ms_used[b]) {
-									realyused = 1;
-									used++;
-									p_ratio_long[leftChan][sfbNum] = p_chpo_long[leftChan].p_ratio[sfbNum];
-									p_ratio_long[rightChan][sfbNum] = p_chpo_long[rightChan].p_ratio[sfbNum];
-								}
-								else {
-									notused++;
-									p_ratio_long[leftChan][sfbNum] = p_chpo_long[leftChan].p_ratio[sfbNum];
-									p_ratio_long[rightChan][sfbNum] = p_chpo_long[rightChan].p_ratio[sfbNum];
-								}
-							}
-						}
-						groupIndex+=quantInfo[leftChan].window_group_length[g];
-					}
-
-					if (realyused) {
-						quantInfo[leftChan].channelInfo.common_window = 1;  /* Use common window */
-						quantInfo[leftChan].channelInfo.ms_info.is_present=1;
-						quantInfo[rightChan].channelInfo.common_window = 1;  /* Use common window */
-						quantInfo[rightChan].channelInfo.ms_info.is_present=1;
-					}
-				}
-				else if ((block_type[leftChan]==block_type[rightChan])&&(use_ms == 1)) {
-					int chan;
-					int numGroups;
-					int groupIndex;
-					int maxSfb;
-					int g,b,j;
-					MS_Info *msInfo;
-
-					quantInfo[leftChan].channelInfo.ms_info.is_present = 1;
-					quantInfo[leftChan].channelInfo.common_window = 1;
-					quantInfo[rightChan].channelInfo.ms_info.is_present = 1;
-					quantInfo[rightChan].channelInfo.common_window = 1;
-
-					for (chan = 0; chan < 2; chan++) {
-						int chan2;
-						if (chan == 0) chan2 = leftChan;
-						else chan2 = rightChan;
-
-						maxSfb = quantInfo[chan].max_sfb;
-
-						/* Determine which bands should be enabled */
-						msInfo = &(quantInfo[leftChan].channelInfo.ms_info);
-						numGroups = quantInfo[chan2].num_window_groups;
-
-						for (g=0;g<numGroups;g++) {
-							for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
-								b = g*maxSfb+sfbNum;
-								groupIndex = 0;
-
-								if (block_type[chan2] == ONLY_SHORT_WINDOW) {
-									msInfo->ms_used[b] = 1;
-									for (j = groupIndex; j < quantInfo[chan2].window_group_length[g]+groupIndex; j++) {
-										p_ratio_short[chan2][(g*maxSfb)+sfbNum] = p_chpo_short[chan2][j].p_ratio[sfbNum];
-										p_chpo_short[rightChan][j].use_ms[sfbNum] = 1;
-									}
-								}
-								else {
-									msInfo->ms_used[b] = 1;
-									p_ratio_long[chan2][sfbNum] = p_chpo_long[chan2].p_ratio[sfbNum];
-									p_chpo_long[rightChan].use_ms[sfbNum] = 1;
-								}
-							}
-//							groupIndex+=quantInfo[chan2].window_group_length[g];
-						}
-					}
-				}
-				else {
-					int chan;
-					int numGroups;
-					int groupIndex;
-					int maxSfb;
-					int g,b,j;
-					MS_Info *msInfo;
-
-					for (chan = 0; chan < 2; chan++) {
-						int chan2;
-						if (chan == 0) chan2 = leftChan;
-						else chan2 = rightChan;
-
-						maxSfb = quantInfo[chan].max_sfb;
-
-						/* Determine which bands should be enabled */
-						msInfo = &(quantInfo[leftChan].channelInfo.ms_info);
-						numGroups = quantInfo[chan2].num_window_groups;
-
-						for (g=0;g<numGroups;g++) {
-							for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
-								b = g*maxSfb+sfbNum;
-								groupIndex = 0;
-
-								if (block_type[chan2] == ONLY_SHORT_WINDOW) {
-									msInfo->ms_used[b] = 0;
-									for (j = groupIndex; j < quantInfo[chan].window_group_length[g]+groupIndex; j++) {
-										p_ratio_short[chan2][(g*maxSfb)+sfbNum] = p_chpo_short[chan2][j].p_ratio[sfbNum];
-										p_chpo_short[rightChan][j].use_ms[sfbNum] = 0;
-									}
-								}
-								else {
-									msInfo->ms_used[b] = 0;
-									p_ratio_long[chan2][sfbNum] = p_chpo_long[chan2].p_ratio[sfbNum];
-									p_chpo_long[rightChan].use_ms[sfbNum] = 0;
-								}
-							}
-//							groupIndex+=quantInfo[chan2].window_group_length[g];
-						}
-					}
-				}
-			}
-		}
-	}
-}
-
-void MSEnergy(double *spectral_line_vector[MAX_TIME_CHANNELS],
-	      double energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-	      CH_PSYCH_OUTPUT_LONG p_chpo_long[],
-	      CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
-	      int sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-	      enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
-	      AACQuantInfo* quantInfo,               /* Quant info */
-	      int use_ms,
-	      int numberOfChannels
-	      )
-{
-	int chanNum, numWindows, bandNumber;
-	int windowLength, w, j;
-	int *p_use_ms;
-	double dtmp;
-
-	for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
-		if (quantInfo[chanNum].channelInfo.present) {
-			if ((quantInfo[chanNum].channelInfo.cpe)&&(quantInfo[chanNum].channelInfo.ch_is_left)) {
-				int leftChan = chanNum;
-				int rightChan = quantInfo[chanNum].channelInfo.paired_ch;
-
-				/* Compute energy in each scalefactor band of each window */
-				numWindows = (block_type[chanNum]==ONLY_SHORT_WINDOW) ?	8 : 1;
-				windowLength = 1024/8;
-				bandNumber=0;
-				for (w=0;w<numWindows;w++) {
-					int offset=0;
-					int sfb;
-
-					if (block_type[chanNum] == ONLY_SHORT_WINDOW) {
-						p_use_ms = p_chpo_short[rightChan][w].use_ms;
-					}
-					else {
-						p_use_ms = p_chpo_long[rightChan].use_ms;
-					}
-
-					j = w*windowLength;
-
-					/* Only compute energy up to max_sfb */
-					for(sfb=0; sfb< quantInfo[chanNum].max_sfb; sfb++ ) {
-						/* calculate scale factor band energy */
-						int width,i;
-						energy[leftChan][bandNumber] = 0.0;
-						energy[rightChan][bandNumber] = 0.0;
-						width=sfb_width_table[chanNum][sfb];
-						for(i=offset; i<(offset+width); i++ ) {
-							if ((p_use_ms[sfb]||(use_ms==1))&&(use_ms!=-1)) {
-								dtmp = (spectral_line_vector[leftChan][j]+spectral_line_vector[rightChan][j])*0.5;
-								energy[leftChan][bandNumber] += dtmp*dtmp;
-								dtmp = (spectral_line_vector[leftChan][j]-spectral_line_vector[rightChan][j])*0.5;
-								energy[rightChan][bandNumber] += dtmp*dtmp;
-							} else {
-								dtmp = spectral_line_vector[leftChan][j];
-								energy[leftChan][bandNumber] += dtmp*dtmp;
-								dtmp = spectral_line_vector[rightChan][j];
-								energy[rightChan][bandNumber] += dtmp*dtmp;
-							}
-							j++;
-						}
-						energy[leftChan][bandNumber] = energy[leftChan][bandNumber] / width;
-						energy[rightChan][bandNumber] = energy[rightChan][bandNumber] / width;
-						bandNumber++;
-						offset+=width;
-					}
-				}
-			} else { /* SCE or LFE */
-
-				/* Compute energy in each scalefactor band of each window */
-				numWindows = (block_type[chanNum]==ONLY_SHORT_WINDOW) ?	8 : 1;
-				windowLength = 1024/8;
-				bandNumber=0;
-				for (w=0;w<numWindows;w++) {
-					int offset=0;
-					int sfb;
-
-					j = w*windowLength;
-
-					/* Only compute energy up to max_sfb */
-					for(sfb = 0; sfb < quantInfo[chanNum].max_sfb; sfb++ ) {
-						/* calculate scale factor band energy */
-						int width, i;
-						energy[chanNum][bandNumber] = 0.0;
-						width=sfb_width_table[chanNum][sfb];
-						for(i=offset; i<(offset+width); i++ ) {
-							dtmp = spectral_line_vector[chanNum][j];
-							energy[chanNum][bandNumber] += dtmp*dtmp;
-							j++;
-						}
-						energy[chanNum][bandNumber] = energy[chanNum][bandNumber] / width;
-						bandNumber++;
-						offset+=width;
-					}
-				}
-			}
-		}
-	}  /* for (chanNum... */
-}
-
-/* Perform MS encoding.  Spectrum is non-interleaved.  */
-/* This would be a lot simpler on interleaved spectral data */
-void MSEncode(double *spectrum[MAX_TIME_CHANNELS],   /* array of pointers to spectral data */
-	      int sfb_offset_table[][MAX_SCFAC_BANDS+1],
-	      enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
-	      AACQuantInfo* quantInfo,               /* Quant info */
-	      int numberOfChannels)                  /* Number of channels */
-{
-	int chanNum;
-	int sfbNum;
-	int lineNum;
-	double sum,diff;
-	Ch_Info *channelInfo;
-
-	/* Look for channel_pair_elements */
-	for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
-		channelInfo = &quantInfo[chanNum].channelInfo;
-
-		if (channelInfo[chanNum].present) {
-			if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
-				int leftChan=chanNum;
-				int rightChan=channelInfo[chanNum].paired_ch;
-				channelInfo[leftChan].ms_info.is_present=0;
-
-				/* Perform MS if block_types are the same */
-				if (block_type[leftChan]==block_type[rightChan]) {
-					int numGroups;
-					int maxSfb;
-					int g,b,w,line_offset;
-					int startWindow,stopWindow;
-					MS_Info *msInfo;
-
-					channelInfo[leftChan].common_window = 1;  /* Use common window */
-					channelInfo[leftChan].ms_info.is_present=1;
-					channelInfo[rightChan].common_window = 1;  /* Use common window */
-					channelInfo[rightChan].ms_info.is_present=1;
-
-					numGroups = quantInfo[leftChan].num_window_groups;
-					maxSfb = quantInfo[leftChan].max_sfb;
-
-					/* Determine which bands should be enabled */
-					/* Right now, simply enable bands which do not use intensity stereo */
-					msInfo = &(channelInfo[leftChan].ms_info);
-					for (g=0;g<numGroups;g++) {
-						for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
-							b = g*maxSfb+sfbNum;
-							msInfo->ms_used[b] = 1;
-						}
-					}
-
-					/* Perform sum and differencing on bands in which ms_used flag */
-					/* has been set. */
-					startWindow = 0;
-					for (g=0;g<numGroups;g++) {
-						int numWindows = quantInfo[leftChan].window_group_length[g];
-						stopWindow = startWindow + numWindows;
-						for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
-							/* Enable MS mask */
-							if (msInfo->ms_used[g*maxSfb+sfbNum]) {
-								for (w=startWindow;w<stopWindow;w++) {
-									for (lineNum=sfb_offset_table[leftChan][sfbNum]; lineNum<sfb_offset_table[leftChan][sfbNum+1]; lineNum++) {
-										line_offset = w*BLOCK_LEN_SHORT;
-										sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
-										diff=spectrum[leftChan][line_offset+lineNum]-spectrum[rightChan][line_offset+lineNum];
-										spectrum[leftChan][line_offset+lineNum] = 0.5 * sum;
-										spectrum[rightChan][line_offset+lineNum] = 0.5 * diff;
-									}  /* for (lineNum... */
-								}  /* for (w=... */
-							}
-						}  /* for (sfbNum... */
-						startWindow = stopWindow;
-					} /* for (g... */
-				}  /* if (block_type... */
-			}
-		}  /* if (channelInfo[chanNum].present */
-	}  /* for (chanNum... */
-}
-
-/* Perform MS encoding.  Spectrum is non-interleaved.  */
-/* This would be a lot simpler on interleaved spectral data */
-void MSEncodeSwitch(double *spectrum[MAX_TIME_CHANNELS],   /* array of pointers to spectral data */
-	      int sfb_offset_table[][MAX_SCFAC_BANDS+1],
-	      AACQuantInfo* quantInfo,               /* Quant info */
-	      int numberOfChannels                 /* Number of channels */
-              )
-{
-	int chanNum;
-	int sfbNum;
-	int lineNum;
-	double sum,diff;
-	Ch_Info *channelInfo;
-
-	/* Look for channel_pair_elements */
-	for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
-		channelInfo = &quantInfo[chanNum].channelInfo;
-
-		if (channelInfo[0].ms_info.is_present) {
-			if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
-				int leftChan=chanNum;
-				int rightChan=channelInfo[chanNum].paired_ch;
-				int numGroups;
-				int maxSfb;
-				int g,/*b,*/w,line_offset;
-				int startWindow,stopWindow;
-				MS_Info *msInfo;
-
-				channelInfo[leftChan].common_window = 1;  /* Use common window */
-				channelInfo[leftChan].ms_info.is_present=1;
-				channelInfo[rightChan].common_window = 1;  /* Use common window */
-				channelInfo[rightChan].ms_info.is_present=1;
-
-				numGroups = quantInfo[leftChan].num_window_groups;
-				maxSfb = quantInfo[leftChan].max_sfb;
-
-				/* Determine which bands should be enabled */
-				/* Right now, simply enable bands which do not use intensity stereo */
-				msInfo = &(channelInfo[leftChan].ms_info);
-#if 0
-				for (g=0;g<numGroups;g++) {
-					for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
-						b = g*maxSfb+sfbNum;
-						msInfo->ms_used[b] = msInfo->ms_used[b];
-					}
-				}
-#endif
-				/* Perform sum and differencing on bands in which ms_used flag */
-				/* has been set. */
-				startWindow = 0;
-				for (g=0;g<numGroups;g++) {
-					int numWindows = quantInfo[leftChan].window_group_length[g];
-					stopWindow = startWindow + numWindows;
-					for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
-						/* Enable MS mask */
-						if (msInfo->ms_used[g*maxSfb+sfbNum]) {
-							for (w=startWindow;w<stopWindow;w++) {
-								for (lineNum=sfb_offset_table[leftChan][sfbNum];lineNum<sfb_offset_table[leftChan][sfbNum+1];lineNum++) {
-									line_offset = w*BLOCK_LEN_SHORT;
-									sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
-									diff=spectrum[leftChan][line_offset+lineNum]-spectrum[rightChan][line_offset+lineNum];
-									spectrum[leftChan][line_offset+lineNum] = 0.5 * sum;
-									spectrum[rightChan][line_offset+lineNum] = 0.5 * diff;
-								}  /* for (lineNum... */
-							}  /* for (w=... */
-						}
-					}  /* for (sfbNum... */
-					startWindow = stopWindow;
-				} /* for (g... */
-			}
-		}
-	}  /* for (chanNum... */
-}
-
-
-void MSReconstruct(double *spectrum[MAX_TIME_CHANNELS],   /* array of pointers to spectral data */
-		   int sfb_offset_table[][MAX_SCFAC_BANDS+1],
-//		   enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
-		   AACQuantInfo* quantInfo,               /* Quant info */
-		   int numberOfChannels)                 /* Number of channels */
-{
-  int chanNum;
-  int sfbNum;
-  int lineNum;
-  double sum,diff;
-  Ch_Info *channelInfo;
-
-  /* Look for channel_pair_elements */
-  for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
-	  channelInfo = &quantInfo[chanNum].channelInfo;
-
-    if (channelInfo[chanNum].present) {
-      if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
-	int leftChan=chanNum;
-	int rightChan=channelInfo[chanNum].paired_ch;
-
-	MS_Info *msInfo;
-	msInfo = &(channelInfo[leftChan].ms_info);
-	if (msInfo->is_present) {
-	  int numGroups = quantInfo[leftChan].num_window_groups;
-	  int maxSfb = quantInfo[leftChan].max_sfb;
-	  int g,w,line_offset;
-	  int startWindow,stopWindow;
-//	  w=0;
-
-	  /* Perform sum and differencing on bands in which ms_used flag */
-	  /* has been set. */
-//					line_offset=0;
-	  startWindow = 0;
-	  for (g=0;g<numGroups;g++) {
-	    int numWindows = quantInfo[leftChan].window_group_length[g];
-	    stopWindow = startWindow + numWindows;
-	    for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
-	      /* Enable MS mask */
-	      if ((msInfo->ms_used[g*maxSfb+sfbNum]) || (msInfo->is_present==2)) {
-	      	for (w=startWindow;w<stopWindow;w++) {
-		  line_offset = w*BLOCK_LEN_SHORT;
-		  for (lineNum=sfb_offset_table[leftChan][sfbNum];lineNum<sfb_offset_table[leftChan][sfbNum+1];lineNum++) {
-		    sum=spectrum[leftChan][line_offset+lineNum];
-		    diff=spectrum[rightChan][line_offset+lineNum];
-		    spectrum[leftChan][line_offset+lineNum] = (sum+diff);
-		    spectrum[rightChan][line_offset+lineNum] = (sum-diff);
-                  }  /* for (lineNum... */
-                }  /* for (w=start... */
-              }  /* if (msInfo... */
-            }  /* for (sfbNum... */
-	    startWindow = stopWindow;
-          } /* for (g... */
-        }  /* if (ms_info.is_present... */
-      }  /* if (channelInfo... */
-    }  /* if (channelInfo[chanNum].present */
-  }  /* for (chanNum... */
-}
-
--- a/ms.h
+++ /dev/null
@@ -1,75 +1,0 @@
-/*
- *	Function prototypes for MS stereo coding
- *
- *	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.11 $
-  $Date: 2000/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef MS_ENC
-#define MS_ENC
-
-#include "quant.h"
-
-
-void MSPreprocess(double p_ratio_long[][MAX_SCFAC_BANDS],
-				  double p_ratio_short[][MAX_SCFAC_BANDS],
-				  CH_PSYCH_OUTPUT_LONG p_chpo_long[],
-				  CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
-				  enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
-				  AACQuantInfo* quantInfo,               /* Quant info */
-				  int use_ms,
-				  int numberOfChannels
-				  );
-
-void MSEnergy(double *spectral_line_vector[MAX_TIME_CHANNELS],
-			  double energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			  CH_PSYCH_OUTPUT_LONG p_chpo_long[],
-			  CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
-			  int sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			  enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
-			  AACQuantInfo* quantInfo,               /* Quant info */
-			  int use_ms,
-			  int numberOfChannels
-			  );
-			  
-void MSEncodeSwitch(double *spectrum[MAX_TIME_CHANNELS],   /* array of pointers to spectral data */
-	      int sfb_offset_table[][MAX_SCFAC_BANDS+1],
-	      AACQuantInfo* quantInfo,
-	      int numberOfChannels
-              );                 /* Number of channels */
-
-void MSEncode(double *spectrum[MAX_TIME_CHANNELS],   /* array of pointers to spectral data */
-	      int sfb_offset_table[][MAX_SCFAC_BANDS+1],
-	      enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
-	      AACQuantInfo* quantInfo,
-	      int numberOfChannels);                 /* Number of channels */
-
-void MSReconstruct(double *spectrum[MAX_TIME_CHANNELS],   /* array of pointers to spectral data */
-		   int sfb_offset_table[][MAX_SCFAC_BANDS+1],
-//		   enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
-		   AACQuantInfo* quantInfo,               /* Quant info */
-		   int numberOfChannels);                 /* Number of channels */
-
-#endif
-
--- a/profiling.txt
+++ /dev/null
@@ -1,196 +1,0 @@
-PROFILING RESULTS
------------------
-
-This is an attempt to cronolog all the profiles done to the code, and the speed at which teh code runs after steps have been taken to optimize it. Think of it  as a diary.
-
-NOTE: After ever optmiztion and code change, md5sum MUST be run on the output   files to determine that they are exact matches of teh pre-optimized code.       PLEASE remember to do this, it'll save alot of heartache in the future.
-Also please dont include any Flat data that is less than 1% of the total time.
-
-Also NOTE: All tests are run at the DEFAULT encoder settings, ie, faac track.wav
-
-Format:
-*Person profiling
-*Version/cvs date
-*gcc flags
-*runtime
-*data track used
-*notes
-*FLAT gprof profile. We may include the Call graph at a later date if we need   to.
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 11:04:16 CST 2000
--O6 -march=i686 -funroll-loops -finline-functions -fomit-frame-pointer
-10 min, 47.88 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-This is the default fully optimized non profiled compile on my box.
-NO PROFILE DATA
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 11:04:16 CST 2000
--O6 -march=i686 -funroll-loops -finline-functions -g -pg -a
-11 min, 12.98 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-This is the default fully optimized, profiled compile on my box.
-Each sample counts as 0.01 seconds.
-  %   cumulative   self              self     total           
- time   seconds   seconds    calls  us/call  us/call  name    
- 58.80    385.25   385.25    41048  9385.35  9385.35  psy_step6
-  3.92    410.93    25.68    41048   625.61   625.61  psy_step14
-  3.91    436.53    25.60    41048   623.66   623.66  psy_step11andahalf
-  3.72    460.87    24.34    20524  1185.93  1787.90  psy_step2
-  3.01    480.59    19.72    20524   960.83  2928.46  tf_encode_spectrum_aac
-  2.53    497.14    16.55    41048   403.19 13119.15  EncTf_psycho_acoustic
-  2.17    511.39    14.25    19506   730.54   730.54  estimate_delay
-  2.13    525.32    13.93    20524   678.72   678.72  psy_step4
-  2.02    538.53    13.21 22839582     0.58     0.61  output_bits
-  1.40    547.73     9.20    41104   223.82   223.98  calc_noise
-  1.17    555.37     7.64    41048   186.12   186.12  psy_step9
-  1.09    562.53     7.16 42029056     0.17     0.17  double_to_int
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 13:00:03 CST 2000
--O6 -march=i686 -funroll-loops -finline-functions -fomit-frame-pointer
-10 min, 44.19 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-New fully Optimized non profile with a macroized double_to_int.
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 13:00:03 CST 2000
--O6 -march=i686 -funroll-loops -finline-functions -g -pg -a
-11 min, 5.36 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-Fully optimized, Profiled with macroized double_to_int. Notice no double_to_int in the top 1% of the flat profile.
-Each sample counts as 0.01 seconds.
-  %   cumulative   self              self     total           
- time   seconds   seconds    calls  us/call  us/call  name    
- 58.99    385.02   385.02    41048  9379.75  9379.75  psy_step6
-  3.94    410.71    25.69    41048   625.85   625.85  psy_step11andahalf
-  3.91    436.24    25.53    20524  1243.91  1822.18  psy_step2
-  3.83    461.23    24.99    41048   608.80   608.80  psy_step14
-  3.06    481.23    20.00    20524   974.47  2941.86  tf_encode_spectrum_aac
-  2.47    497.37    16.14    41048   393.20 13116.31  EncTf_psycho_acoustic
-  2.19    511.64    14.27    20524   695.28   695.28  psy_step4
-  2.10    525.36    13.72    19506   703.37   703.37  estimate_delay
-  2.06    538.82    13.46 22839582     0.59     0.62  output_bits
-  1.35    547.63     8.81    41104   214.33   215.15  calc_noise
-  1.19    555.37     7.74    41048   188.56   188.56  psy_step9
-  1.04    562.15     6.78    20524   330.34   597.84  nok_ltp_reconstruct
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 19:18:25 CST 2000
--finline-functions 
-5 min, 38.96 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-Ok, this is wierd. It jsut dawned on me that since the x86 isnt a risc box with a ton of registers (like im used to) it might be register starved. That seems to be the case. With no optimization except inlining, we are running with a 200% speed increase. Time to pin this down.
-NO PROFILE
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 19:18:25 CST 2000
--O -finline-function
-11 min, 6.09 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-Looks like -O is still starving registers.
-NO PROFILE
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 19:18:25 CST 2000
-No Optimization
-5 min, 39.84 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-a bit slower than the non inlined version.
-NO PROFILE
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 19:18:25 CST 2000
--march=i686 -finline-functions
-5 min, 38.25 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-Still Not getting anywhere.
-NO PROFILE
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 19:18:25 CST 2000
--march=i686 -finline-functions -funroll-loops
-5 min, 37.04 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-More Nothing.
-NO PROFILE
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 19:18:25 CST 2000
--march=i686 -finline-functions -funroll-loops -fomit-frame-pointer
-5 min, 39.46 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-Still Nothing.
-NO PROFILE
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 19:18:25 CST 2000
- -march=i686 -finline-functions -funroll-loops -fomit-frame-pointer -fthread-jumps
-5 min, 41.00 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-Still Nothing.
-NO PROFILE
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 19:18:25 CST 2000
--march=i686 -finline-functions -funroll-loops -fomit-frame-pointer -fthread-jumps -fdefer-pop
-5 min, 42.24 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-Still Nothing.
-NO PROFILE
-
-------------------------------------------------------------------------------
-thebard
-CVS Tue Feb 22 19:18:25 CST 2000
--O6 -march=i686 -finline-functions -funroll-loops -fomit-frame-pointer -ffast-math
-3 min, 12.13 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-Bingo! Got it. -O core dumps, and -O2 to -O6 are slower than thuer non optimized counterparts, unless you add -ffast-math. then things are speedy. The assembly it produces still has room for speed. Still more work to do.
-
-------------------------------------------------------------------------------
-thebard
-CVS Wed Feb 23 20:30:01 CST 2000
--O6 -march=i686 -finline-functions -funroll-loops -ffast-math -g -pg -a
-3 min, 44.97 sec.
-The Outfield Bangin': track 2: Bangin' On My Heart
-This is the profiled fully optimized version. As you can see, there isnt a whole lot letf to optimize...
-Each sample counts as 0.01 seconds.
-  %   cumulative   self              self     total           
- time   seconds   seconds    calls  us/call  us/call  name    
-  9.76     20.63    20.63 32619291     0.63     0.66  output_bits
-  9.18     40.05    19.42    20524   946.21  3941.14  tf_encode_spectrum_aac
-  7.83     56.60    16.55    20524   806.37  1361.39  psy_step2
-  7.72     72.93    16.33    41048   397.83  2266.16  EncTf_psycho_acoustic
-  6.20     86.05    13.12   102792   127.64   128.13  calc_noise
-  5.14     96.91    10.86    20524   529.14   529.14  psy_step4
-  4.51    106.44     9.53    41048   232.17   232.17  psy_step6
-  3.33    113.48     7.04    41048   171.51   171.51  psy_step9
-  3.22    120.30     6.82   223693    30.49    96.05  noiseless_bit_count
-  3.22    127.11     6.81   188315    36.16    36.16  PulseCoder
-  3.16    133.79     6.68    41048   162.74   162.74  psy_step14
-  3.03    140.20     6.41   203169    31.55    31.55  quantize
-  2.62    145.75     5.55     7931   699.79   699.79  estimate_delay
-  2.55    151.14     5.39    20524   262.62   463.36  nok_ltp_reconstruct
-  2.50    156.42     5.28   751457     7.03     7.03  pfftw_twiddle_4
-  2.38    161.46     5.04    41048   122.78   122.78  psy_step5
-  2.03    165.76     4.30   223693    19.22   115.27  bit_search
-  1.89    169.75     3.99    61089    65.31   102.13  MDCT
-  1.62    173.18     3.43    10263   334.21 20456.01  EncTfFrame
-  1.44    176.23     3.05  9744296     0.31     0.31  BsPutBit
-  1.32    179.03     2.80    20524   136.43   339.21  realft2048
-  1.28    181.74     2.71  1037456     2.61     2.61  pfftw_32
-  1.05    183.96     2.22    28455    78.02   297.27  buffer2freq
-
--- a/psych.c
+++ /dev/null
@@ -1,1334 +1,0 @@
-/*
- *	Psychoacoustics
- *
- *	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.73 $
-  $Date: 2000/11/10 13:27:06 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <math.h>
-#include <memory.h>
-
-#include "psych.h"
-#include "transfo.h"
-#include "quant.h"
-
-double sqrt2048, sqrt256;
-
-
-double          sample[MAX_TIME_CHANNELS*2][BLOCK_LEN_LONG*2];
-                               /* sample value */
-
-FFT_TABLE_LONG    fft_tbl_long;  /* table for long fft */
-FFT_TABLE_SHORT    fft_tbl_short;  /* table for short fft */
-PARTITION_TABLE_LONG    part_tbl_long;  
-PARTITION_TABLE_SHORT    part_tbl_short;
-DYN_PART_TABLE_LONG     dyn_long;  
-DYN_PART_TABLE_SHORT    dyn_short;
-PSY_STATVARIABLE_LONG    psy_stvar_long[MAX_TIME_CHANNELS*2];
-                               /* variables for long block */
-PSY_STATVARIABLE_SHORT    psy_stvar_short[MAX_TIME_CHANNELS*2];
-                               /* variables for short block */
-
-
-void Psy_Init( void )
-{
-	int chanNum;
-
-	psy_fft_table_init(&fft_tbl_long, &fft_tbl_short);
-	/* initializing fft table */
-	for (chanNum=0;chanNum<MAX_TIME_CHANNELS*2;chanNum++) {
-		psy_calc_init(&sample[chanNum], &psy_stvar_long[chanNum], &psy_stvar_short[chanNum]);
-		/* initializing static variables */
-	}
-}
-
-void psy_fft_table_init(FFT_TABLE_LONG *fft_tbl_long,
-			FFT_TABLE_SHORT *fft_tbl_short
-			)
-{
-	int i;
-
-	/* generating Hann window */
-	for(i = 0; i < BLOCK_LEN_LONG*2; i++)
-		fft_tbl_long->hw[i] = 0.5 * (1-cos(2.0*M_PI*(i+0.5)/(BLOCK_LEN_LONG*2)));
-	for(i = 0; i < BLOCK_LEN_SHORT*2; i++)
-		fft_tbl_short->hw[i] = 0.5 * (1-cos(2.0*M_PI*(i+0.5)/(BLOCK_LEN_SHORT*2)));
-
-}
-
-/*
- * This Function calculates the Frequency in Hertz given a
- * Bark-value. It uses the Traunmueller-formula for bark>2
- * and a linear inerpolation below. 
- * KAF
- */
-double bark2hz (double bark)
-{
-    double hz;
-
-    if(bark>2.0)
-	hz = 1960 / (26.81 / (bark + 0.53) - 1);
-    else
-	hz = bark * 102.9;
-
-    return (hz);
-}
-
-/*
- * This Function calculates the Frequency in Bark given a 
- * Frequency-value in Hertz. It uses the Traunmueller-formula 
- * for frequency>200Hz and a linear inerpolation below. 
- * KAF
- */
-double hz2bark (double hz)
-{
-    double bark;
-
-    if(hz>200.0)
-	bark = 26.81 / (1 + (1960 / hz)) - 0.53; 
-    else
-	bark = hz / 102.9;
-
-    return (bark);
-}
-
-void psy_part_table_init(double sampling_rate,
-						 PARTITION_TABLE_LONG *part_tbl_long,
-						 PARTITION_TABLE_SHORT *part_tbl_short
-						 )
-{
-    int b,bb;
-    double tmp;
-	int cbands, prev_cbound, crit_bands, cbound;
-
-
-	cbands = (int)hz2bark(sampling_rate/2.0) + 1;
-	cbands *= 3;
-	part_tbl_long->sampling_rate = (int)sampling_rate;
-	part_tbl_long->w_low[0] = 0;
-	part_tbl_long->w_high[0] = 1;
-	part_tbl_long->width[0] = 1;
-    prev_cbound = 0;
-	crit_bands = 0;
-	for(b = 1; b <= cbands; b++)
-	{
-		cbound = (int)(bark2hz((double)b/3) * (double)BLOCK_LEN_LONG * 2.0 / sampling_rate + 0.5);
-		if(cbound > prev_cbound) {
-			crit_bands++;
-			part_tbl_long->w_low[crit_bands] = min(prev_cbound,BLOCK_LEN_LONG-1);
-			part_tbl_long->w_high[crit_bands] = min(cbound,BLOCK_LEN_LONG);
-			part_tbl_long->width[crit_bands] = 
-				part_tbl_long->w_high[crit_bands] - part_tbl_long->w_low[crit_bands];
-			prev_cbound = cbound;
-			if (part_tbl_long->w_high[crit_bands] == BLOCK_LEN_LONG)
-				break;
-		}
-	}
-	part_tbl_long->len = crit_bands+1;
-//	printf("%d %d\t",part_tbl_long->len, part_tbl_long->w_high[crit_bands]);
-
-	cbands /= 3;
-	part_tbl_short->sampling_rate = (int)sampling_rate;
-	part_tbl_short->w_low[0] = 0;
-	part_tbl_short->w_high[0] = 1;
-	part_tbl_short->width[0] = 1;
-        prev_cbound = 0;
-	crit_bands = 0;
-	for(b = 1; b <= cbands; b++)
-	{
-		cbound = (int)(bark2hz((double)b/*/3*/) * (double)BLOCK_LEN_SHORT * 2.0 / sampling_rate +0.5);
-		if(cbound > prev_cbound) {
-			crit_bands++;
-			part_tbl_short->w_low[crit_bands] = min(prev_cbound,BLOCK_LEN_SHORT-1);
-			part_tbl_short->w_high[crit_bands] = min(cbound,BLOCK_LEN_SHORT);
-			part_tbl_short->width[crit_bands] = 
-				part_tbl_short->w_high[crit_bands] - part_tbl_short->w_low[crit_bands];
-			prev_cbound = cbound;
-			if (part_tbl_short->w_high[crit_bands] == BLOCK_LEN_SHORT)
-				break;
-		}
-	}
-	part_tbl_short->len = crit_bands+1;
-//	printf("%d %d\n",part_tbl_short->len, part_tbl_short->w_high[crit_bands]);
-
-
-	// Using Traunmuller formula for bark, for more info see:
-	// http://www.ling.su.se/staff/hartmut/bark.htm
-	for(b = 0; b < part_tbl_long->len; b++) {
-		double ji = part_tbl_long->w_low[b] + (part_tbl_long->width[b]-1)/2.0;
-		double freq = part_tbl_long->sampling_rate*ji/2048;
-		double bark = 26.81/(1+(1960/freq)) - 0.53;
-		dyn_long.bval[b] = bark;
-	}
-
-	for(b = 0; b < part_tbl_short->len ; b++) {
-		double ji = part_tbl_short->w_low[b] + (part_tbl_short->width[b]-1)/2.0;
-		double freq = part_tbl_short->sampling_rate*ji/256;
-		double bark = 26.81/(1+(1960/freq)) - 0.53;
-		dyn_short.bval[b]=bark;
-	}
-
-	// Calculate the spreading function
-	{
-		double tmpx,tmpy,tmp,x,b1,b2;
-		int b, bb;
-
-		for( b = 0; b < part_tbl_long->len; b++) {
-			b2 = dyn_long.bval[b];
-			for( bb = 0; bb < part_tbl_long->len; bb++) {
-				b1 = dyn_long.bval[bb];
-
-				if (b>=bb) tmpx = (b2 - b1)*3.0;
-				else       tmpx = (b2 - b1)*1.5; 
-
-				if(tmpx>=0.5 && tmpx<=2.5)
-				{
-					tmp = tmpx - 0.5;
-					x = 8.0 * (tmp*tmp - 2.0 * tmp);
-				}
-				else x = 0.0;
-				tmpx += 0.474;
-				tmpy = 15.811389 + 7.5*tmpx - 17.5*sqrt(1.0+tmpx*tmpx);
-
-				if (tmpy <= -60.0) dyn_long.spreading[b][bb] = 0.0;
-				else               dyn_long.spreading[b][bb] = exp( (x + tmpy)*0.2302585093 ); 
-			}
-		}
-
-		for( b = 0; b < part_tbl_short->len; b++) {
-			b2 = dyn_short.bval[b];
-			for( bb = 0; bb < part_tbl_short->len; bb++) {
-				b1 = dyn_short.bval[bb];
-
-				if (b>=bb) tmpx = (b2 - b1)*3.0;
-				else       tmpx = (b2 - b1)*1.5; 
-
-				if(tmpx>=0.5 && tmpx<=2.5)
-				{
-					tmp = tmpx - 0.5;
-					x = 8.0 * (tmp*tmp - 2.0 * tmp);
-				}
-				else x = 0.0;
-				tmpx += 0.474;
-				tmpy = 15.811389 + 7.5*tmpx - 17.5*sqrt(1.0+tmpx*tmpx);
-
-				if (tmpy <= -60.0) dyn_short.spreading[b][bb] = 0.0;
-				else               dyn_short.spreading[b][bb] = exp( (x + tmpy)*0.2302585093 ); 
-			}
-		}
-	}
-
-    for( b = 0; b < part_tbl_long->len; b++){
-		tmp = 0.0;
-		for( bb = 0; bb < part_tbl_long->len; bb++)
-			tmp += dyn_long.spreading[bb][b];
-		dyn_long.rnorm[b] = 1.0/tmp;
-    }
-
-    for( b = 0; b < part_tbl_short->len; b++){
-		tmp = 0.0;
-		for( bb = 0; bb < part_tbl_short->len; bb++)
-			tmp += dyn_short.spreading[bb][b];
-		dyn_short.rnorm[b] = 1.0/tmp;
-    }
-
-	for(b = 0; b < part_tbl_long->len; b++) {
-		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(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))));
-	}
-
-	part_tbl_long->dyn = &dyn_long;
-	part_tbl_short->dyn = &dyn_short;
-}
-
-
-void psy_calc_init( 
-		   double sample[][BLOCK_LEN_LONG*2],
-		   PSY_STATVARIABLE_LONG *psy_stvar_long,
-		   PSY_STATVARIABLE_SHORT *psy_stvar_short
-		   )
-{
-	int ch = 0;
-	int i;
-
-	for(i = 0; i < BLOCK_LEN_LONG*2; i++){
-		sample[ch][i] = 0.0;
-	}
-
-    for(i = 0; i < BLOCK_LEN_LONG*3; i++){
-		psy_stvar_long->fft_r[i] = 0.0;
-		psy_stvar_long->fft_f[i] = 0.0;
-    }
-
-	psy_stvar_long->p_fft = 0;
-
-    for(i = 0; i < NPART_LONG*2; i++){
-		psy_stvar_long->nb[i] = 90.0;
-    }
-
-	psy_stvar_long->p_nb = NPART_LONG;
-
-	for(i = 0; i < BLOCK_LEN_SHORT; i++) {
-		psy_stvar_short->last6_fft_r[i] = 0.0;
-		psy_stvar_short->last6_fft_f[i] = 0.0;
-		psy_stvar_short->last7_fft_r[i] = 0.0;
-		psy_stvar_short->last7_fft_f[i] = 0.0;
-    }
-
-    for(i = 0; i < NPART_SHORT; i++){
-		psy_stvar_short->last7_nb[i] = 90.0;
-    }
-
-	sqrt2048 = 1/sqrt(2048);
-	sqrt256 = 1/sqrt(256);
-}
-
-void Psy_FillBuffer(double *p_time_signal[], int no_of_chan)
-{
-	int i, ch;
-
-	for (ch = 0; ch < no_of_chan; ch++) {
-		for(i = 0; i < BLOCK_LEN_LONG; i++){
-			sample[ch][i+BLOCK_LEN_LONG] = p_time_signal[ch][i];
-		}
-	}
-}
-
-/* main */
-void Psy_Calculate( 
-			   /* input */
-			   AACQuantInfo *quantInfo,
-			   double sampling_rate,
-			   int    no_of_chan,         /* no of audio channels */
-			   double *p_time_signal[],
-			   enum WINDOW_TYPE block_type[],
-			   int use_MS,
-			   /* output */
-			   CH_PSYCH_OUTPUT_LONG p_chpo_long[],
-			   CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS]
-			   )
-{
-	int             chanNum, i;
-    SR_INFO         *p_sri;
-
-    static int   flag = 0;
-
-    PSY_VARIABLE_LONG    psy_var_long[4];  /* variables for long block */
-    PSY_VARIABLE_SHORT    psy_var_short[4];  /* variables for short block */
-
-
-	memset(&psy_var_long, 0, sizeof(psy_var_long));
-	memset(&psy_var_short, 0, sizeof(psy_var_short));
-
-	if( flag==0 ) {
-		psy_part_table_init(sampling_rate, &part_tbl_long, &part_tbl_short);
-		/* initializing Table B 2.1.*.a, B 2.1.*.b in N1650 */
-		flag = 1;
-	}
-
-	for (chanNum = 0; chanNum < no_of_chan; chanNum++) {
-		if (quantInfo[chanNum].channelInfo.present) {
-			p_sri = quantInfo[chanNum].sr_info;
-			
-			if (quantInfo[chanNum].channelInfo.cpe && quantInfo[chanNum].channelInfo.ch_is_left) { /* CPE */
-				int leftChan = chanNum;
-				int rightChan = quantInfo[chanNum].channelInfo.paired_ch;
-				int midChan = chanNum + MAX_TIME_CHANNELS;
-				int sideChan = chanNum + MAX_TIME_CHANNELS;
-
-				psy_step1(p_time_signal, sample, leftChan);
-				psy_step1(p_time_signal, sample, rightChan);
-
-				psy_step2(sample, &psy_stvar_long[leftChan],
-					&psy_stvar_short[leftChan],	&fft_tbl_long, &fft_tbl_short, leftChan);
-				psy_step2(sample, &psy_stvar_long[rightChan],
-					&psy_stvar_short[rightChan], &fft_tbl_long, &fft_tbl_short, rightChan);
-				if (use_MS == 0)
-					psy_step2MS(psy_stvar_long, psy_stvar_short,
-					leftChan, rightChan, midChan, sideChan);
-
-				psy_step3(&psy_stvar_long[leftChan], &psy_stvar_short[leftChan],
-					&psy_var_long[0], &psy_var_short[0]);
-				psy_step3(&psy_stvar_long[rightChan], &psy_stvar_short[rightChan],
-					&psy_var_long[1], &psy_var_short[1]);
-
-				psy_step4(&psy_stvar_long[leftChan], &psy_stvar_short[leftChan],
-					&psy_var_long[0], &psy_var_short[0]);
-				psy_step4(&psy_stvar_long[rightChan], &psy_stvar_short[rightChan],
-					&psy_var_long[1], &psy_var_short[1]);
-				if (use_MS == 0)
-					psy_step4MS(psy_var_long, psy_var_short, 0, 1, 2, 3);
-
-				psy_step5(&part_tbl_long, &part_tbl_short, &psy_stvar_long[leftChan], &psy_stvar_short[leftChan],
-					&psy_var_long[0], &psy_var_short[0]);
-				psy_step5(&part_tbl_long, &part_tbl_short, &psy_stvar_long[rightChan], &psy_stvar_short[rightChan],
-					&psy_var_long[1], &psy_var_short[1]);
-				if (use_MS == 0) {
-					psy_step5(&part_tbl_long, &part_tbl_short, &psy_stvar_long[midChan], &psy_stvar_short[midChan],
-						&psy_var_long[2], &psy_var_short[2]);
-					psy_step5(&part_tbl_long, &part_tbl_short, &psy_stvar_long[sideChan], &psy_stvar_short[sideChan],
-						&psy_var_long[3], &psy_var_short[3]);
-				}
-
-				psy_step6(&part_tbl_long, &part_tbl_short, &psy_stvar_long[leftChan], &psy_stvar_short[leftChan],
-					&psy_var_long[0], &psy_var_short[0]);
-				psy_step6(&part_tbl_long, &part_tbl_short, &psy_stvar_long[rightChan], &psy_stvar_short[rightChan],
-					&psy_var_long[1], &psy_var_short[1]);
-				if (use_MS == 0) {
-					psy_step6(&part_tbl_long, &part_tbl_short, &psy_stvar_long[midChan], &psy_stvar_short[midChan],
-						&psy_var_long[2], &psy_var_short[2]);
-					psy_step6(&part_tbl_long, &part_tbl_short, &psy_stvar_long[sideChan], &psy_stvar_short[sideChan],
-						&psy_var_long[3], &psy_var_short[3]);
-				}
-
-				psy_step7(&part_tbl_long, &part_tbl_short, &psy_var_long[0], &psy_var_short[0]);
-				psy_step7(&part_tbl_long, &part_tbl_short, &psy_var_long[1], &psy_var_short[1]);
-				if (use_MS == 0) {
-					psy_step7MS(psy_var_long, psy_var_short, 0, 1, 2, 3);
-				}
-
-				psy_step8(&part_tbl_long, &part_tbl_short, &psy_var_long[0], &psy_var_short[0]);
-				psy_step8(&part_tbl_long, &part_tbl_short, &psy_var_long[1], &psy_var_short[1]);
-				if (use_MS == 0) {
-					psy_step8(&part_tbl_long, &part_tbl_short, &psy_var_long[2], &psy_var_short[2]);
-					psy_step8(&part_tbl_long, &part_tbl_short, &psy_var_long[3], &psy_var_short[3]);
-				}
-
-				psy_step9(&part_tbl_long, &part_tbl_short, &psy_var_long[0], &psy_var_short[0]);
-				psy_step9(&part_tbl_long, &part_tbl_short, &psy_var_long[1], &psy_var_short[1]);
-				if (use_MS == 0) {
-					psy_step9(&part_tbl_long, &part_tbl_short, &psy_var_long[2], &psy_var_short[2]);
-					psy_step9(&part_tbl_long, &part_tbl_short, &psy_var_long[3], &psy_var_short[3]);
-				}
-
-				psy_step10(&part_tbl_long, &part_tbl_short, &psy_stvar_long[leftChan], &psy_stvar_short[leftChan], 
-					&psy_var_long[0], &psy_var_short[0]);
-				psy_step10(&part_tbl_long, &part_tbl_short, &psy_stvar_long[rightChan], &psy_stvar_short[rightChan], 
-					&psy_var_long[1], &psy_var_short[1]);
-				if (use_MS == 0) {
-					psy_step10(&part_tbl_long, &part_tbl_short, &psy_stvar_long[midChan], &psy_stvar_short[midChan], 
-						&psy_var_long[2], &psy_var_short[2]);
-					psy_step10(&part_tbl_long, &part_tbl_short, &psy_stvar_long[sideChan], &psy_stvar_short[sideChan], 
-						&psy_var_long[3], &psy_var_short[3]);
-
-					psy_step11MS(&part_tbl_long, &part_tbl_short, psy_stvar_long, psy_stvar_short,
-						leftChan, rightChan, midChan, sideChan);
-				}
-
-				psy_step11(&part_tbl_long, &part_tbl_short, &psy_stvar_long[leftChan], &psy_stvar_short[leftChan]);
-				psy_step11(&part_tbl_long, &part_tbl_short, &psy_stvar_long[rightChan], &psy_stvar_short[rightChan]);
-				if (use_MS == 0) {
-					psy_step11(&part_tbl_long, &part_tbl_short, &psy_stvar_long[midChan], &psy_stvar_short[midChan]);
-					psy_step11(&part_tbl_long, &part_tbl_short, &psy_stvar_long[sideChan], &psy_stvar_short[sideChan]);
-				}
-
-				psy_step12(&part_tbl_long, &part_tbl_short, &psy_stvar_long[leftChan], &psy_stvar_short[leftChan],
-					&psy_var_long[0], &psy_var_short[0], &block_type[leftChan]);
-
-				if (block_type[leftChan] != ONLY_SHORT_WINDOW) {
-					psy_step12(&part_tbl_long, &part_tbl_short, &psy_stvar_long[rightChan], &psy_stvar_short[rightChan],
-						&psy_var_long[1], &psy_var_short[1], &block_type[rightChan]);
-					block_type[leftChan] = block_type[rightChan];
-				} else {
-					block_type[rightChan] = block_type[leftChan];
-				}
-
-				psy_step14(p_sri, &part_tbl_long, &part_tbl_short, &psy_stvar_long[leftChan],
-					&psy_stvar_short[leftChan], &psy_var_long[0], &psy_var_short[0]);
-				psy_step14(p_sri, &part_tbl_long, &part_tbl_short, &psy_stvar_long[rightChan],
-					&psy_stvar_short[rightChan], &psy_var_long[1], &psy_var_short[1]);
-				if (use_MS == 0) {
-					psy_step14(p_sri, &part_tbl_long, &part_tbl_short, &psy_stvar_long[midChan],
-						&psy_stvar_short[midChan], &psy_var_long[2], &psy_var_short[2]);
-					psy_step14(p_sri, &part_tbl_long, &part_tbl_short, &psy_stvar_long[sideChan],
-						&psy_stvar_short[sideChan], &psy_var_long[3], &psy_var_short[3]);
-
-					psy_step15(p_sri, psy_stvar_long, psy_stvar_short,
-						psy_var_long, psy_var_short,
-						leftChan, rightChan, midChan, sideChan);
-				}
-
-				p_chpo_long[leftChan].p_ratio   = psy_stvar_long[leftChan].ismr;
-				p_chpo_long[rightChan].p_ratio   = psy_stvar_long[rightChan].ismr;
-
-				memcpy(p_chpo_long[rightChan].use_ms, psy_stvar_long[rightChan].use_ms, NSFB_LONG*sizeof(int));
-
-				for( i=0; i<MAX_SHORT_WINDOWS; i++ ) {
-					p_chpo_short[leftChan][i].p_ratio  = psy_stvar_short[leftChan].ismr[i];
-					p_chpo_short[rightChan][i].p_ratio  = psy_stvar_short[rightChan].ismr[i];
-
-					memcpy(p_chpo_short[rightChan][i].use_ms, psy_stvar_short[rightChan].use_ms[i], NSFB_SHORT*sizeof(int));
-				}
-
-			} else if (!quantInfo[chanNum].channelInfo.cpe && quantInfo[chanNum].channelInfo.lfe) { /* LFE */
-
-				// LFE psych ratios are set to -24 dB for low frequencies
-				for (i = 0; i < 10; i++) {
-					psy_stvar_long[chanNum].ismr[i] = 0.004; /* -24 dB */
-				}
-				for (i = 10; i < NSFB_LONG; i++) {
-					psy_stvar_long[chanNum].ismr[i] = 1.0;
-				}
-				p_chpo_long[chanNum].p_ratio   = psy_stvar_long[chanNum].ismr;
-
-				block_type[chanNum] = ONLY_LONG_WINDOW;
-
-				// set the scalefactor band values
-				for( i=0; i<MAX_SHORT_WINDOWS; i++ ) {
-					p_chpo_short[chanNum][i].p_ratio  = psy_stvar_short[chanNum].ismr[i];
-				}
-
-			} else if (!quantInfo[chanNum].channelInfo.cpe) { /* SCE */
-
-				psy_step1(p_time_signal, sample, chanNum);
-				psy_step2(sample, &psy_stvar_long[chanNum], &psy_stvar_short[chanNum],
-					&fft_tbl_long, &fft_tbl_short, chanNum);
-				psy_step3(&psy_stvar_long[chanNum], &psy_stvar_short[chanNum], &psy_var_long[0], &psy_var_short[0]);
-				psy_step4(&psy_stvar_long[chanNum], &psy_stvar_short[chanNum], &psy_var_long[0], &psy_var_short[0]);
-				psy_step5(&part_tbl_long, &part_tbl_short, &psy_stvar_long[chanNum], &psy_stvar_short[chanNum],
-					&psy_var_long[0], &psy_var_short[0]);
-				psy_step6(&part_tbl_long, &part_tbl_short, &psy_stvar_long[chanNum], &psy_stvar_short[chanNum],
-					&psy_var_long[0], &psy_var_short[0]);
-				psy_step7(&part_tbl_long, &part_tbl_short, &psy_var_long[0], &psy_var_short[0]);
-				psy_step8(&part_tbl_long, &part_tbl_short, &psy_var_long[0], &psy_var_short[0]);
-				psy_step9(&part_tbl_long, &part_tbl_short, &psy_var_long[0], &psy_var_short[0]);
-				psy_step10(&part_tbl_long, &part_tbl_short, &psy_stvar_long[chanNum], &psy_stvar_short[chanNum], 
-					&psy_var_long[0], &psy_var_short[0]);
-				psy_step11(&part_tbl_long, &part_tbl_short, &psy_stvar_long[chanNum], &psy_stvar_short[chanNum]);
-				psy_step12(&part_tbl_long, &part_tbl_short, &psy_stvar_long[chanNum], &psy_stvar_short[chanNum],
-					&psy_var_long[0], &psy_var_short[0], &block_type[chanNum]);
-				psy_step14(p_sri, &part_tbl_long, &part_tbl_short, &psy_stvar_long[chanNum],
-					&psy_stvar_short[chanNum], &psy_var_long[0], &psy_var_short[0]);
-
-				p_chpo_long[chanNum].p_ratio   = psy_stvar_long[chanNum].ismr;
-
-				for( i=0; i<MAX_SHORT_WINDOWS; i++ ) {
-					p_chpo_short[chanNum][i].p_ratio  = psy_stvar_short[chanNum].ismr[i];
-				}
-			}
-		}
-	}
-
-}
-
-
-/* input samples */
-void psy_step1(double* p_time_signal[],
-			   double sample[][BLOCK_LEN_LONG*2],
-			   int ch)
-{
-	int i;
-
-	for(i = 0; i < BLOCK_LEN_LONG; i++){
-		sample[ch][i] = sample[ch][i+BLOCK_LEN_LONG];
-		sample[ch][i+BLOCK_LEN_LONG] = p_time_signal[ch][i];
-	}
-}
-
-/* FFT */
-void psy_step2(double sample[][BLOCK_LEN_LONG*2],
-               PSY_STATVARIABLE_LONG *psy_stvar_long,
-               PSY_STATVARIABLE_SHORT *psy_stvar_short,
-			   FFT_TABLE_LONG *fft_tbl_long,
-			   FFT_TABLE_SHORT *fft_tbl_short,
-			   int ch
-			   )
-{
-    int w,l;
-    double data[2048],a,b;
-
-    /* FFT for long */
-    psy_stvar_long->p_fft += BLOCK_LEN_LONG;
-
-    if(psy_stvar_long->p_fft == BLOCK_LEN_LONG * 3)
-		psy_stvar_long->p_fft = 0;
-
-    /* windowing */
-	for(w = 0; w < BLOCK_LEN_LONG; w++){
-		FFTarray[w].re = fft_tbl_long->hw[(w<<1)] * sample[ch][w<<1];
-		FFTarray[w].im = fft_tbl_long->hw[(w<<1)+1] * sample[ch][(w<<1)+1];
-	}
-
-	realft2048(data);
-
-	for(w = 0; w < BLOCK_LEN_LONG; w++){
-		a = data[(w<<1)];
-		b = data[(w<<1)+1];
-		psy_stvar_long->fft_r[w+psy_stvar_long->p_fft] = sqrt(a*a + b*b) * sqrt2048;
-	}
-
-	for(w = 0; w < 16; w++){
-		a = data[(w<<1)];
-		b = data[(w<<1)+1];
-		if( a > 0.0 ){
-			if( b >= 0.0 )
-				psy_stvar_long->fft_f[w+psy_stvar_long->p_fft] = atan2( b, a );
-			else
-				psy_stvar_long->fft_f[w+psy_stvar_long->p_fft] = atan2( b, a )+ M_PI * 2.0;
-		} else if( a < 0.0 ) {
-			psy_stvar_long->fft_f[w+psy_stvar_long->p_fft] = atan2( b, a ) + M_PI;
-		} else {
-			if( b > 0.0 )
-				psy_stvar_long->fft_f[w+psy_stvar_long->p_fft] = M_PI * 0.5;
-			else if( b < 0.0 )
-				psy_stvar_long->fft_f[w+psy_stvar_long->p_fft] = M_PI * 1.5;
-			else
-				psy_stvar_long->fft_f[w+psy_stvar_long->p_fft] = 0.0;
-		}
-	}
-
-	/* FFT for short */
-	for(l = 0; l < MAX_SHORT_WINDOWS; l++){
-
-        /* windowing */
-        for(w = 0; w < BLOCK_LEN_SHORT; w++){
-			FFTarray[w].re = fft_tbl_short->hw[w<<1] * sample[ch][OFFSET_FOR_SHORT + (BLOCK_LEN_SHORT * l) + (w<<1)];
-			FFTarray[w].im = fft_tbl_short->hw[(w<<1)+1] * sample[ch][OFFSET_FOR_SHORT + (BLOCK_LEN_SHORT * l) + (w<<1)+1];
-		}
-
-		realft256(data);
-
-		for(w = 0; w < BLOCK_LEN_SHORT; w++){
-			a = data[(w<<1)];
-			b = data[(w<<1)+1];
-			psy_stvar_short->fft_r[l][w]= sqrt(a*a + b*b) * sqrt256;
-
-			if( a > 0.0 ){
-				if( b >= 0.0 )
-					psy_stvar_short->fft_f[l][w] = atan2( b, a );
-				else
-					psy_stvar_short->fft_f[l][w] = atan2( b, a )+ M_PI * 2.0;
-			} else if( a < 0.0 ) {
-				psy_stvar_short->fft_f[l][w] = atan2( b, a ) + M_PI;
-			} else {
-				if( b > 0.0 )
-					psy_stvar_short->fft_f[l][w] = M_PI * 0.5;
-				else if( b < 0.0 )
-					psy_stvar_short->fft_f[l][w] = M_PI * 1.5;
-				else
-					psy_stvar_short->fft_f[l][w] = 0.0;
-			}
-		}
-    }
-}
-
-/* FFT for Mid/Side */
-void psy_step2MS(PSY_STATVARIABLE_LONG *psy_stvar_long,
-			PSY_STATVARIABLE_SHORT *psy_stvar_short,
-			int leftChan, int rightChan,
-			int midChan, int sideChan)
-{
-	int w, l;
-	psy_stvar_long[midChan].p_fft += BLOCK_LEN_LONG;
-	if(psy_stvar_long[midChan].p_fft == BLOCK_LEN_LONG * 3)
-		psy_stvar_long[midChan].p_fft = 0;
-
-	psy_stvar_long[sideChan].p_fft += BLOCK_LEN_LONG;
-	if(psy_stvar_long[sideChan].p_fft == BLOCK_LEN_LONG * 3)
-		psy_stvar_long[sideChan].p_fft = 0;
-
-	for (w = 0; w < BLOCK_LEN_LONG; w++) {
-		psy_stvar_long[midChan].fft_r[w+psy_stvar_long[midChan].p_fft] = (psy_stvar_long[leftChan].fft_r[w+psy_stvar_long[leftChan].p_fft]+psy_stvar_long[rightChan].fft_r[w+psy_stvar_long[rightChan].p_fft])*0.5;
-		psy_stvar_long[sideChan].fft_r[w+psy_stvar_long[sideChan].p_fft] = (psy_stvar_long[leftChan].fft_r[w+psy_stvar_long[leftChan].p_fft]-psy_stvar_long[rightChan].fft_r[w+psy_stvar_long[rightChan].p_fft])*0.5;
-	}
-	for (l = 0; l < MAX_SHORT_WINDOWS; l++) {
-		for (w = 0; w < BLOCK_LEN_SHORT; w++) {
-			psy_stvar_short[midChan].fft_r[l][w] = (psy_stvar_short[leftChan].fft_r[l][w]+psy_stvar_short[rightChan].fft_r[l][w])*0.5;
-			psy_stvar_short[sideChan].fft_r[l][w] = (psy_stvar_short[leftChan].fft_r[l][w]-psy_stvar_short[rightChan].fft_r[l][w])*0.5;
-		}
-	}
-}
-
-/* caluculation of predicted FFT values, from previous FFT's */
-void psy_step3(PSY_STATVARIABLE_LONG *psy_stvar_long,
-               PSY_STATVARIABLE_SHORT *psy_stvar_short,
-               PSY_VARIABLE_LONG *psy_var_long,
-               PSY_VARIABLE_SHORT *psy_var_short
-			   )
-{
-    int w,i;
-    int p1_l,p2_l;
-
-	p1_l = psy_stvar_long->p_fft - BLOCK_LEN_LONG;
-    if( p1_l < 0 )
-		p1_l = BLOCK_LEN_LONG * 2;
-    p2_l = p1_l - BLOCK_LEN_LONG;
-    if( p2_l < 0 )
-		p2_l = BLOCK_LEN_LONG;
-
-    for(w = 0; w < 16; w++){
-		psy_var_long->r_pred[w] = 2.0 * psy_stvar_long->fft_r[p1_l + w] - psy_stvar_long->fft_r[p2_l + w];
-		psy_var_long->f_pred[w] = 2.0 * psy_stvar_long->fft_f[p1_l + w] - psy_stvar_long->fft_f[p2_l + w];
-    }
-
-    for(w = 0; w < BLOCK_LEN_SHORT; w++){
-        psy_var_short->r_pred[0][w] = 2.0 * psy_stvar_short->last7_fft_r[w] - psy_stvar_short->last6_fft_r[w];
-        psy_var_short->f_pred[0][w] = 2.0 * psy_stvar_short->last7_fft_f[w] - psy_stvar_short->last6_fft_f[w];
-        psy_var_short->r_pred[1][w] = 2.0 * psy_stvar_short->fft_r[0][w] - psy_stvar_short->last7_fft_r[w];
-        psy_var_short->f_pred[1][w] = 2.0 * psy_stvar_short->fft_f[0][w] - psy_stvar_short->last7_fft_f[w];
-    }
-
-    for(i = 2; i < MAX_SHORT_WINDOWS; i++){
-        for(w = 0; w < BLOCK_LEN_SHORT; w++){
-			psy_var_short->r_pred[i][w] = 2.0 * psy_stvar_short->fft_r[i - 1][w] - psy_stvar_short->fft_r[i - 2][w];
-			psy_var_short->f_pred[i][w] = 2.0 * psy_stvar_short->fft_f[i - 1][w] - psy_stvar_short->fft_f[i - 2][w];
-		}
-    }
-
-    for(w = 0; w < BLOCK_LEN_SHORT; w++){
-        psy_stvar_short->last6_fft_r[w] = psy_stvar_short->fft_r[6][w];
-		psy_stvar_short->last6_fft_f[w] = psy_stvar_short->fft_f[6][w];
-        psy_stvar_short->last7_fft_r[w] = psy_stvar_short->fft_r[7][w];
-		psy_stvar_short->last7_fft_f[w] = psy_stvar_short->fft_f[7][w];
-    }
-}
-
-/* caluculation of unpredictability measure */
-void psy_step4(PSY_STATVARIABLE_LONG *psy_stvar_long,
-               PSY_STATVARIABLE_SHORT *psy_stvar_short,
-			   PSY_VARIABLE_LONG *psy_var_long,
-			   PSY_VARIABLE_SHORT *psy_var_short
-			   )
-{
-    int w,i;
-    double r,f,rp,fp;
-
-    for(i = 0; i < MAX_SHORT_WINDOWS; i++){
-        for(w = 0; w < BLOCK_LEN_SHORT; w++){
-			r = psy_stvar_short->fft_r[i][w];
-			f = psy_stvar_short->fft_f[i][w];
-			rp = psy_var_short->r_pred[i][w];
-			fp = psy_var_short->f_pred[i][w];
-
-			if( fabs(r) + fabs(rp) != 0.0 )
-/* Replacing with something faster
-				psy_var_short->c[i][w] = sqrt( psy_sqr(r*cos(f) - rp*cos(fp))
-					+psy_sqr(r*sin(f) - rp*sin(fp)) )/ ( r + fabs(rp) ) ;
-*/
-				psy_var_short->c[i][w] = sqrt( r*r+rp*rp-2*r*rp*cos(f+fp) )/ ( r + fabs(rp) );
-			else
-				psy_var_short->c[i][w] = 0.0; /* tmp */
-		}
-    }
-
-    for(w = 0; w < 16; w++){
-		r = psy_stvar_long->fft_r[psy_stvar_long->p_fft+w];
-		f = psy_stvar_long->fft_f[psy_stvar_long->p_fft+w];
-		rp = psy_var_long->r_pred[w];
-		fp = psy_var_long->f_pred[w];
-
-		if( fabs(r) + fabs(rp) != 0.0 )
-/* Replacing with something faster
-			psy_var_long->c[w] = sqrt( psy_sqr(r*cos(f) - rp*cos(fp))
-				+psy_sqr(r*sin(f) - rp*sin(fp)) )/ ( r + fabs(rp) );
-*/
-			psy_var_long->c[w] = sqrt( r*r+rp*rp-2*r*rp*cos(f+fp) )/ ( r + fabs(rp) );
-
-		else
-			psy_var_long->c[w] = 0.0; /* tmp */
-    }
-    for(w = 16; w < 416; w+=8) {
-		double temp_c = 0.0;
-
-		for(i = 0; i < MAX_SHORT_WINDOWS; i++) {
-			temp_c += psy_var_short->c[i][w/8];
-		}
-		temp_c = temp_c/8.0;
-		for(i = 0; i < MAX_SHORT_WINDOWS; i++) {
-			psy_var_long->c[w+i] = temp_c;
-		}
-	}
-
-	for(w = 416; w < BLOCK_LEN_LONG; w++){
-		psy_var_long->c[w] = 0.4;
-	}
-}
-
-/* caluculation of unpredictability measure for Mid/Side */
-void psy_step4MS(PSY_VARIABLE_LONG *psy_var_long,
-			PSY_VARIABLE_SHORT *psy_var_short,
-			int leftChan, int rightChan,
-			int midChan, int sideChan)
-{
-	int b, i;
-
-	for (b = 0; b < NPART_LONG; b++)
-		psy_var_long[midChan].c[b] = psy_var_long[sideChan].c[b] = min(psy_var_long[leftChan].c[b], psy_var_long[rightChan].c[b]);
-	for (i = 0; i < MAX_SHORT_WINDOWS; i++)
-		for (b = 0; b < NPART_SHORT; b++)
-			psy_var_short[midChan].c[i][b] = psy_var_short[sideChan].c[i][b] = min(psy_var_short[leftChan].c[i][b], psy_var_short[rightChan].c[i][b]);
-}
-
-/* calculation of energy and unpredictability in each partition */
-void psy_step5(PARTITION_TABLE_LONG *part_tbl_long,
-			   PARTITION_TABLE_SHORT *part_tbl_short,
-			   PSY_STATVARIABLE_LONG *psy_stvar_long,
-               PSY_STATVARIABLE_SHORT *psy_stvar_short,
-			   PSY_VARIABLE_LONG *psy_var_long,
-			   PSY_VARIABLE_SHORT *psy_var_short
-			   )
-{
-    int b,w,i;
-    double tmp_cb;
-
-    for(b = 0; b < part_tbl_long->len; b++){
-		psy_var_long->e[b] = 0.0;
-		tmp_cb = 0.0;
-
-		for(w = part_tbl_long->w_low[b]; w < part_tbl_long->w_high[b]; w++){
-			psy_var_long->e[b] += psy_sqr(psy_stvar_long->fft_r[psy_stvar_long->p_fft+w]);
-			tmp_cb += psy_sqr(psy_stvar_long->fft_r[psy_stvar_long->p_fft+w]) * psy_var_long->c[w];
-		}
-
-		psy_var_long->cb[b] = tmp_cb;
-    }
-
-    for(i = 0; i < MAX_SHORT_WINDOWS; i++){
-        for(b = 0; b < part_tbl_short->len; b++){
-			psy_var_short->e[i][b] = 0.0;
-			tmp_cb = 0.0;
-
-			for(w = part_tbl_short->w_low[b]; w < part_tbl_short->w_high[b]; w++){
-				psy_var_short->e[i][b] += psy_sqr(psy_stvar_short->fft_r[i][w]);
-				tmp_cb += psy_sqr(psy_stvar_short->fft_r[i][w]) * psy_var_short->c[i][w];
-			}
-
-			psy_var_short->cb[i][b] = tmp_cb;
-		}
-    }
-}
-
-/* convolution of energy and unpredictability */
-void psy_step6(PARTITION_TABLE_LONG *part_tbl_long, 
-			   PARTITION_TABLE_SHORT *part_tbl_short, 
-			   PSY_STATVARIABLE_LONG *psy_stvar_long,
-               PSY_STATVARIABLE_SHORT *psy_stvar_short,
-			   PSY_VARIABLE_LONG *psy_var_long, 
-			   PSY_VARIABLE_SHORT *psy_var_short
-			   )
-{
-	int b,bb,i;
-	double ecb,ct;
-	double sprd;
-
-	for(b = 0; b < part_tbl_long->len; b++){
-		ecb = 0.0;
-		ct = 0.0;
-
-		for(bb = 0; bb < part_tbl_long->len; bb++){
-			sprd = part_tbl_long->dyn->spreading[bb][b];
-			ecb += psy_var_long->e[bb] * sprd;
-			ct += psy_var_long->cb[bb] * sprd;
-		}
-
-		if (ecb!=0.0) {
-			psy_var_long->cbb[b] = ct / ecb;
-			psy_stvar_long->en[b] = psy_var_long->en[b] = ecb
-				* part_tbl_long->dyn->rnorm[b];
-		} else {
-			psy_var_long->cbb[b] = 0.0;
-			psy_stvar_long->en[b] = psy_var_long->en[b] = 0;
-		}
-	}
-
-	for(i = 0; i < MAX_SHORT_WINDOWS; i++){ 
-		for(b = 0; b < part_tbl_short->len; b++){
-			ecb = 0.0;
-			ct = 0.0;
-			
-			for(bb = 0; bb < part_tbl_short->len; bb++){
-				sprd = part_tbl_short->dyn->spreading[bb][b];
-				ecb += psy_var_short->e[i][bb] * sprd;
-				ct += psy_var_short->cb[i][bb] * sprd;
-			}
-
-			if (ecb!=0.0) {	
-				psy_var_short->cbb[i][b] = ct / ecb;
-				psy_stvar_short->en[i][b] = psy_var_short->en[i][b] = ecb
-					* part_tbl_short->dyn->rnorm[b];
-			} else {
-				psy_var_short->cbb[i][b] = 0.0;
-				psy_stvar_short->en[i][b] = psy_var_short->en[i][b] = 0;
-			}
-		}
-	}
-}
-
-/* calculation of tonality in each partition */
-void psy_step7(PARTITION_TABLE_LONG *part_tbl_long,
-	       PARTITION_TABLE_SHORT *part_tbl_short,
-	       PSY_VARIABLE_LONG *psy_var_long, 
-	       PSY_VARIABLE_SHORT *psy_var_short)
-{
-    int b,i;
-
-    for(b = 0; b < part_tbl_long->len; b++){
-		if (psy_var_long->cbb[b] > 0.0) {
-			psy_var_long->tb[b] = -0.299 - 0.43 * log(psy_var_long->cbb[b]);
-		} else {
-			psy_var_long->tb[b] = 1.0;
-		}
-		if( psy_var_long->tb[b] > 1.0 )
-			psy_var_long->tb[b] = 1.0;
-		else if( psy_var_long->tb[b] < 0.0 )
-			psy_var_long->tb[b] = 0.0;
-//		if ((psy_var_long->tb[b]<1.0)&&(psy_var_long->tb[b]>0.5))
-//			printf("%d\t%.2f\n", b, psy_var_long->tb[b]);
-    }
-
-
-    for(i = 0;  i < MAX_SHORT_WINDOWS; i++){
-        for(b = 0; b < part_tbl_short->len; b++){
-			if (psy_var_short->cbb[i][b]>0.0) {
-				psy_var_short->tb[i][b] = -0.299 - 0.43 * log(psy_var_short->cbb[i][b]);
-			} else {
-				psy_var_short->tb[i][b] = 1.0;
-			}
-			if( psy_var_short->tb[i][b] > 1.0 )
-				psy_var_short->tb[i][b] = 1.0;
-			else if( psy_var_short->tb[i][b] < 0.0 )
-				psy_var_short->tb[i][b] = 0.0;
-//			if ((psy_var_short->tb[i][b]<1.0)&&(psy_var_short->tb[i][b]>0.5))
-//				printf("%d\t%.2f\n", b, psy_var_short->tb[i][b]);
-		}
-    }
-}
-
-/* caluculation of tonality in each partition for Mid/Side */
-void psy_step7MS(PSY_VARIABLE_LONG *psy_var_long,
-				 PSY_VARIABLE_SHORT *psy_var_short,
-				 int leftChan, int rightChan,
-				 int midChan, int sideChan)
-{
-	int b, i;
-
-	for (b = 0; b < NPART_LONG; b++) {
-		psy_var_long[midChan].tb[b] = psy_var_long[leftChan].tb[b];
-		psy_var_long[sideChan].tb[b] = psy_var_long[rightChan].tb[b];
-	}
-	for (i = 0; i < MAX_SHORT_WINDOWS; i++)
-		for (b = 0; b < NPART_SHORT; b++) {
-			psy_var_short[midChan].tb[i][b] = psy_var_short[leftChan].tb[i][b];
-			psy_var_short[sideChan].tb[i][b] = psy_var_short[rightChan].tb[i][b];
-		}
-}
-
-/* caluculation of SNR in each partition */
-void psy_step8(PARTITION_TABLE_LONG *part_tbl_long,
-	       PARTITION_TABLE_SHORT *part_tbl_short,
-	       PSY_VARIABLE_LONG *psy_var_long, 
-	       PSY_VARIABLE_SHORT *psy_var_short)
-{
-	int b,i;
-	double tmn = 18.0, nmt = 6.0;
-
-	for(b = 0; b < part_tbl_long->len; b++) {
-		psy_var_long->snr[b] = psy_var_long->tb[b] * tmn + (1.0 - psy_var_long->tb[b] ) * nmt;
-	}
-
-	for(i = 0;  i < MAX_SHORT_WINDOWS; i++){
-		for(b = 0; b < part_tbl_short->len; b++)
-			psy_var_short->snr[i][b] = psy_var_short->tb[i][b] * tmn + (1.0 - psy_var_short->tb[i][b] ) * nmt ;
-	}
-}    
-
-/* caluculation of power ratio in each partition */
-void psy_step9(PARTITION_TABLE_LONG *part_tbl_long,
-	       PARTITION_TABLE_SHORT *part_tbl_short,
-	       PSY_VARIABLE_LONG *psy_var_long, 
-	       PSY_VARIABLE_SHORT *psy_var_short
-	       )
-{
-    int b,i;
-    
-    for(b = 0; b < part_tbl_long->len; b++)
-		psy_var_long->bc[b] = pow(10.0, -psy_var_long->snr[b]/10.0);
-
-    for(i = 0;  i < MAX_SHORT_WINDOWS; i++){
-        for(b = 0; b < part_tbl_short->len; b++)
-			psy_var_short->bc[i][b] = pow(10.0, -psy_var_short->snr[i][b]/10.0);
-    }
-}
-
-/* caluculation of actual energy threshold in each partition */
-void psy_step10(PARTITION_TABLE_LONG *part_tbl_long,
-		PARTITION_TABLE_SHORT *part_tbl_short,
-		PSY_STATVARIABLE_LONG *psy_stvar_long,
-		PSY_STATVARIABLE_SHORT *psy_stvar_short,
-		PSY_VARIABLE_LONG *psy_var_long,
-		PSY_VARIABLE_SHORT *psy_var_short
-		)
-{
-    int b,i;
-
-    psy_stvar_long->p_nb += NPART_LONG;
-
-    if( psy_stvar_long->p_nb == NPART_LONG*2 ) psy_stvar_long->p_nb = 0;
-
-    for(b = 0; b < part_tbl_long->len; b++){
-		psy_stvar_long->nb[psy_stvar_long->p_nb + b]
-			= psy_var_long->en[b] * psy_var_long->bc[b];
-    }
-
-    for(i = 0;  i < MAX_SHORT_WINDOWS; i++){
-        for(b = 0; b < part_tbl_short->len; b++){
-			psy_stvar_short->nb[i][b]
-				= psy_var_short->en[i][b] * psy_var_short->bc[i][b];
-		}
-    }
-}
-
-/* check for small energy threshold in previous block */
-void psy_step11(PARTITION_TABLE_LONG *part_tbl_long, 
-		PARTITION_TABLE_SHORT *part_tbl_short, 
-		PSY_STATVARIABLE_LONG *psy_stvar_long, 
-		PSY_STATVARIABLE_SHORT *psy_stvar_short
-		)
-{
-    int b,i;
-    int p1,p2;
-	double temp;
-
-    p1 = psy_stvar_long->p_nb;
-    if( p1 == 0 ) p2 = NPART_LONG;
-    else if( p1 == NPART_LONG ) p2 = 0;
-
-    for(b = 0; b < part_tbl_long->len; 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 = 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;
-    }
-
-	for(b = 0; b < part_tbl_short->len; b++){
-		psy_stvar_short->last7_nb[b] = psy_stvar_short->nb[7][b];
-	}
-
-	for(i = 1;  i < MAX_SHORT_WINDOWS; i++){
-		for(b = 0; b < part_tbl_short->len; 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;
-		}
-	}
-}
-
-/* calculate Mid/Side energy thresholds */
-void psy_step11MS(PARTITION_TABLE_LONG *part_tbl_long,
-						PARTITION_TABLE_SHORT *part_tbl_short,
-						PSY_STATVARIABLE_LONG *psy_stvar_long,
-						PSY_STATVARIABLE_SHORT *psy_stvar_short,
-						int leftChan, int rightChan,
-						int midChan, int sideChan)
-{
-#if 1 // LAME's version
-	int b, i, p1;
-	double tempM, tempS;
-
-    p1 = psy_stvar_long[leftChan].p_nb;
-
-	for(b = 0; b < part_tbl_long->len; b++) {
-		tempM = max(psy_stvar_long[midChan].nb[p1+b], min(part_tbl_long->dyn->bmax[b]*psy_stvar_long[sideChan].en[b], psy_stvar_long[sideChan].nb[p1+b]));
-		tempS = max(psy_stvar_long[sideChan].nb[p1+b], min(part_tbl_long->dyn->bmax[b]*psy_stvar_long[midChan].en[b], psy_stvar_long[midChan].nb[p1+b]));
-
-		if ((psy_stvar_long[leftChan].nb[p1+b] <= 1.58*psy_stvar_long[rightChan].nb[p1+b])&&(psy_stvar_long[rightChan].nb[p1+b] <= 1.58*psy_stvar_long[leftChan].nb[p1+b])) {
-			psy_stvar_long[midChan].nb[p1+b] = tempM;
-			psy_stvar_long[sideChan].nb[p1+b] = tempS;
-		}
-	}
-
-	for (i = 0; i < MAX_SHORT_WINDOWS; i++) {
-		for(b = 0; b < part_tbl_short->len; b++) {
-			tempM = max(psy_stvar_short[midChan].nb[i][b], min(part_tbl_short->dyn->bmax[b]*psy_stvar_short[sideChan].en[i][b], psy_stvar_short[sideChan].nb[i][b]));
-			tempS = max(psy_stvar_short[sideChan].nb[i][b], min(part_tbl_short->dyn->bmax[b]*psy_stvar_short[midChan].en[i][b], psy_stvar_short[midChan].nb[i][b]));
-
-			if ((psy_stvar_short[leftChan].nb[i][b] <= 1.58*psy_stvar_short[rightChan].nb[i][b])&&(psy_stvar_short[rightChan].nb[i][b] <= 1.58*psy_stvar_short[leftChan].nb[i][b])) {
-				psy_stvar_short[midChan].nb[i][b] = tempM;
-				psy_stvar_short[sideChan].nb[i][b] = tempS;
-			}
-		}
-	}
-#else
-	int b, i,p1;
-	double t;
-	double tempL, tempR, tempM, tempS;
-
-    p1 = psy_stvar_long[leftChan].p_nb;
-
-	for(b = 0; b < part_tbl_long->len; b++) {
-
-		if (psy_stvar_long[sideChan].nb[p1+b] != 0.0)
-			t = psy_stvar_long[midChan].nb[p1+b]/psy_stvar_long[sideChan].nb[p1+b];
-		else
-			t = 0;
-		if (t>1)
-			t = 1/t;
-		tempL = max(psy_stvar_long[leftChan].nb[p1+b]*t, min(psy_stvar_long[leftChan].nb[p1+b], part_tbl_long->dyn->bmax[b]*psy_stvar_long[leftChan].en[b]));
-		tempR = max(psy_stvar_long[rightChan].nb[p1+b]*t, min(psy_stvar_long[rightChan].nb[p1+b], part_tbl_long->dyn->bmax[b]*psy_stvar_long[rightChan].en[b]));
-
-		t = min(tempL,tempR);
-		tempM = min(t, max(psy_stvar_long[midChan].nb[p1+b], min(part_tbl_long->dyn->bmax[b]*psy_stvar_long[sideChan].en[b], psy_stvar_long[sideChan].nb[p1+b])));
-		tempS = min(t, max(psy_stvar_long[sideChan].nb[p1+b], min(part_tbl_long->dyn->bmax[b]*psy_stvar_long[midChan].en[b], psy_stvar_long[midChan].nb[p1+b])));
-
-		if ((psy_stvar_long[leftChan].nb[p1+b] >= 1.58*psy_stvar_long[rightChan].nb[p1+b])&&(psy_stvar_long[rightChan].nb[p1+b] >= 1.58*psy_stvar_long[leftChan].nb[p1+b])) {
-			psy_stvar_long[midChan].nb[p1+b] = tempM;
-			psy_stvar_long[sideChan].nb[p1+b] = tempS;
-			psy_stvar_long[leftChan].nb[p1+b] = tempL;
-			psy_stvar_long[rightChan].nb[p1+b] = tempR;
-		}
-	}
-
-	for (i = 0; i < MAX_SHORT_WINDOWS; i++) {
-		for(b = 0; b < part_tbl_short->len; b++) {
-			if (psy_stvar_short[sideChan].nb[i][b] != 0.0)
-				t = psy_stvar_short[midChan].nb[i][b]/psy_stvar_short[sideChan].nb[i][b];
-			else
-				t = 0;
-			if (t>1)
-				t = 1/t;
-			tempL = max(psy_stvar_short[leftChan].nb[i][b]*t, min(psy_stvar_short[leftChan].nb[i][b], part_tbl_short->dyn->bmax[b]*psy_stvar_short[leftChan].en[i][b]));
-			tempR = max(psy_stvar_short[rightChan].nb[i][b]*t, min(psy_stvar_short[rightChan].nb[i][b], part_tbl_short->dyn->bmax[b]*psy_stvar_short[rightChan].en[i][b]));
-
-			t = min(tempL,tempR);
-			tempM = min(t, max(psy_stvar_short[midChan].nb[i][b], min(part_tbl_short->dyn->bmax[b]*psy_stvar_short[sideChan].en[i][b], psy_stvar_short[sideChan].nb[i][b])));
-			tempS = min(t, max(psy_stvar_short[sideChan].nb[i][b], min(part_tbl_short->dyn->bmax[b]*psy_stvar_short[midChan].en[i][b], psy_stvar_short[midChan].nb[i][b])));
-
-			if ((psy_stvar_short[leftChan].nb[i][b] >= 1.58*psy_stvar_short[rightChan].nb[i][b])&&(psy_stvar_short[rightChan].nb[i][b] >= 1.58*psy_stvar_short[leftChan].nb[i][b])) {
-				psy_stvar_short[midChan].nb[i][b] = tempM;
-				psy_stvar_short[sideChan].nb[i][b] = tempS;
-				psy_stvar_short[leftChan].nb[i][b] = tempL;
-				psy_stvar_short[rightChan].nb[i][b] = tempR;
-			}
-		}
-	}
-#endif
-}
-
-/* pre-echo control using PE and energy surges */
-void psy_step12(PARTITION_TABLE_LONG *part_tbl_long,
-				PARTITION_TABLE_SHORT *part_tbl_short,
-				PSY_STATVARIABLE_LONG *psy_stvar_long,
-				PSY_STATVARIABLE_SHORT *psy_stvar_short,
-				PSY_VARIABLE_LONG *psy_var_long,
-				PSY_VARIABLE_SHORT *psy_var_short,
-				enum WINDOW_TYPE *block_type
-				)
-{
-	int b,i,shb;
-	double temp, pe;
-	double tot, mx, estot[8];
-
-	pe = 0.0;
-	for(b = 0; b < part_tbl_long->len; b++){
-		temp = part_tbl_long->width[b]
-			* log((psy_stvar_long->nb[psy_stvar_long->p_nb + b] + 0.0000000001)
-			/ (psy_var_long->e[b] + 0.0000000001));
-		temp = min(0,temp);
-
-		pe -= temp;
-	}
-	
-	for (i=0; i < MAX_SHORT_WINDOWS; i++) {
-		estot[i]=0;
-		for ( b = 0; b < NPART_SHORT; b++)
-			estot[i] += psy_var_short->e[i][b];
-		if (estot[i] != 0.0)
-			estot[i] /= NPART_SHORT;
-	}
-
-	tot = mx = estot[0];
-	for (i=1; i < MAX_SHORT_WINDOWS; i++) {
-		tot += estot[i];
-		mx = max(mx, estot[i]);
-	}
-	
-	shb = 0;
-
-	if (pe > 5600) shb = 1;
-
-	if ((mx/tot) > 0.3) shb = 1;
-	
-	if (shb) *block_type = ONLY_SHORT_WINDOW;
-	else *block_type = ONLY_LONG_WINDOW;
-}
-
-/* calculation of 1/SMR in each band */
-void psy_step14(SR_INFO *p_sri,
-				PARTITION_TABLE_LONG *part_tbl_long,
-				PARTITION_TABLE_SHORT *part_tbl_short,
-				PSY_STATVARIABLE_LONG *psy_stvar_long,
-				PSY_STATVARIABLE_SHORT *psy_stvar_short,
-				PSY_VARIABLE_LONG *psy_var_long,
-				PSY_VARIABLE_SHORT *psy_var_short
-				)
-{
-    int b, n, w, i;
-    int w_low, w_high;
-    double thr, minthr;
-
-    w_high = 0;
-    for(n = 0; n < p_sri->num_cb_long; n++){
-		w_low = w_high;
-		w_high += p_sri->cb_width_long[n];
-
-        psy_var_long->epart[n] = 0.0;
-		for(w = w_low; w < w_high; w++){
-			psy_var_long->epart[n] += psy_sqr(psy_stvar_long->fft_r[psy_stvar_long->p_fft + w]);
-		}
-    }
-
-    for(b = 0; b < part_tbl_long->len; b++){
-        thr = psy_stvar_long->nb[psy_stvar_long->p_nb + b]
-			/ part_tbl_long->width[b];
-        for(w = part_tbl_long->w_low[b]; w < part_tbl_long->w_high[b]; w++){
-			psy_var_long->thr[w] = thr;
-		}
-    }
-
-    w_high = 0;
-    for(n = 0; n < p_sri->num_cb_long; n++){
-        w_low = w_high;
-		w_high += p_sri->cb_width_long[n];
-
-        minthr = psy_var_long->thr[w_low];
-		for(w = w_low+1; w < w_high; w++){
-			if(psy_var_long->thr[w] < minthr){
-				minthr = psy_var_long->thr[w];
-			}
-		}
-
-		psy_var_long->npart[n] = minthr * (w_high - w_low);
-    }
-
-    for(n = 0; n < p_sri->num_cb_long; n++){
-		if (psy_var_long->epart[n]!=0.0) {
-			psy_stvar_long->ismr[n] = psy_var_long->npart[n] / psy_var_long->epart[n];
-		} else {
-			psy_stvar_long->ismr[n] = 0.0;
-		}
-    }
-
-    for(i = 0; i < MAX_SHORT_WINDOWS; i++){
-        w_high = 0;
-		for(n = 0; n < p_sri->num_cb_short; n++){
-			w_low = w_high;
-			w_high += p_sri->cb_width_short[n];
-
-			psy_var_short->epart[i][n] = 0.0;
-			for(w = w_low; w < w_high; w++){
-				psy_var_short->epart[i][n] += psy_sqr(psy_stvar_short->fft_r[i][w]);
-			}
-		}
-
-		for(b = 0; b < part_tbl_short->len; b++){
-            thr = psy_stvar_short->nb[i][b] / part_tbl_short->width[b];
-			for(w = part_tbl_short->w_low[b]; w < part_tbl_short->w_high[b]; w++){
-				psy_var_short->thr[i][w] = thr;
-			}
-		}
-
-		w_high = 0;
-		for(n = 0; n < p_sri->num_cb_short; n++){
-            w_low = w_high;
-			w_high += p_sri->cb_width_short[n];
-
-			minthr = psy_var_short->thr[i][w_low];
-			for(w = w_low + 1; w < w_high; w++){
-				if(psy_var_short->thr[i][w] < minthr){
-					minthr = psy_var_short->thr[i][w];
-				}
-			}
-
-			psy_var_short->npart[i][n] = minthr * (w_high - w_low);
-        }
-
-		for(n = 0; n < p_sri->num_cb_short; n++){
-			if (psy_var_short->epart[i][n]!=0.0) {
-				psy_stvar_short->ismr[i][n] = psy_var_short->npart[i][n] / psy_var_short->epart[i][n];
-			} else {
-				psy_stvar_short->ismr[i][n] = 0.0;
-			}
-		}
-    }
-}
-
-/* decision of Mid/Side coding */
-void psy_step15(SR_INFO *p_sri,
-				PSY_STATVARIABLE_LONG *psy_stvar_long,
-				PSY_STATVARIABLE_SHORT *psy_stvar_short,
-				PSY_VARIABLE_LONG *psy_var_long, PSY_VARIABLE_SHORT *psy_var_short,
-				int leftChan, int rightChan, int midChan, int sideChan
-				)
-{
-	int b, i;
-	double temp, x1, x2, db;
-
-	for (b = 0; b < p_sri->num_cb_long; b++) {
-		x1 = min(psy_var_long[0].npart[b],psy_var_long[1].npart[b]);
-		x2 = max(psy_var_long[0].npart[b],psy_var_long[1].npart[b]);
-		if (x2 >= 1000*x1)
-			db=30;
-		else
-			db = 10*log10(x2/x1);
-		temp = 0.35*(db)/5.0;
-//		printf("%d\t%f\n", b, temp);
-		if (temp < 0.35) {
-			psy_stvar_long[rightChan].use_ms[b] = 1;
-			psy_stvar_long[leftChan].ismr[b] = psy_stvar_long[midChan].ismr[b];
-			psy_stvar_long[rightChan].ismr[b] = psy_stvar_long[sideChan].ismr[b];
-		} else {
-			psy_stvar_long[rightChan].use_ms[b] = 0;
-		}
-	}
-	for (i = 0; i < 8; i++) {
-		for (b = 0; b < p_sri->num_cb_short; b++) {
-			x1 = min(psy_var_short[0].npart[i][b],psy_var_short[1].npart[i][b]);
-			x2 = max(psy_var_short[0].npart[i][b],psy_var_short[1].npart[i][b]);
-			if (x2 >= 1000*x1)
-				db=30;
-			else
-				db = 10*log10(x2/x1);
-			temp = 0.35*(db)/5.0;
-//			printf("%d\t%f\n", b, temp);
-			if (temp < 0.35) {
-				psy_stvar_short[rightChan].use_ms[i][b] = 1;
-				psy_stvar_short[leftChan].ismr[i][b] = psy_stvar_short[midChan].ismr[i][b];
-				psy_stvar_short[rightChan].ismr[i][b] = psy_stvar_short[sideChan].ismr[i][b];
-			} else {
-				psy_stvar_short[rightChan].use_ms[i][b] = 0;
-			}
-		}
-	}
-}
-
-
--- a/psych.h
+++ /dev/null
@@ -1,319 +1,0 @@
-/*
- *	Function prototypes for psychoacoustics
- *
- *	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.25 $
-  $Date: 2000/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include "interface.h"
-#include "quant.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
-
-
-#define OFFSET_FOR_SHORT 448
-#define NPART_LONG 100
-#define NPART_SHORT 100
-
-typedef struct {
-  double hw[BLOCK_LEN_LONG*2];     /* Hann window table */
-} FFT_TABLE_LONG;
-
-typedef struct {
-  double hw[BLOCK_LEN_SHORT*2];     /* Hann window table */
-} FFT_TABLE_SHORT;
- 
-typedef struct {
-  double bval[NPART_LONG];
-  double qsthr[NPART_LONG];
-  double rnorm[NPART_LONG];
-  double bmax[NPART_LONG];
-  double spreading[NPART_LONG][NPART_LONG];
-} DYN_PART_TABLE_LONG;
-
-typedef struct {
-  int    sampling_rate;
-  int    len;      /* length of the table */
-  int    w_low[NPART_LONG];
-  int    w_high[NPART_LONG];
-  int    width[NPART_LONG];
-  DYN_PART_TABLE_LONG *dyn;
-} PARTITION_TABLE_LONG;
-
-typedef struct {
-  double bval[NPART_SHORT];
-  double qsthr[NPART_SHORT];
-  double rnorm[NPART_SHORT];
-  double bmax[NPART_SHORT];
-  double spreading[NPART_SHORT][NPART_SHORT];
-} DYN_PART_TABLE_SHORT;
-
-typedef struct {
-  int    sampling_rate;
-  int    len;      /* length of the table */ 
-  int    w_low[NPART_SHORT];
-  int    w_high[NPART_SHORT];
-  int    width[NPART_SHORT];
-  DYN_PART_TABLE_SHORT *dyn;
-} PARTITION_TABLE_SHORT;
-
-typedef struct {
-  double fft_r[BLOCK_LEN_LONG*3];
-  double fft_f[BLOCK_LEN_LONG*3];
-  int    p_fft; /* pointer for fft_r and fft_f */
-  double nb[NPART_LONG*2];
-  double en[NPART_LONG];
-  int    p_nb; /* pointer for nb */
-  double ismr[NSFB_LONG]; /* 1/SMR in each swb */
-  int use_ms[NSFB_LONG];
-} PSY_STATVARIABLE_LONG;
-
-typedef struct {
-  double r_pred[BLOCK_LEN_LONG];
-  double f_pred[BLOCK_LEN_LONG];
-  double c[BLOCK_LEN_LONG];
-  double e[NPART_LONG];
-  double cw[NPART_LONG];
-  double en[NPART_LONG];
-  double cb[NPART_LONG];
-  double cbb[NPART_LONG];
-  double tb[NPART_LONG];
-  double snr[NPART_LONG];
-  double bc[NPART_LONG];
-  double epart[NSFB_LONG];
-  double thr[BLOCK_LEN_LONG];
-  double npart[NSFB_LONG];
-} PSY_VARIABLE_LONG;
-
-typedef struct {
-  double fft_r[MAX_SHORT_WINDOWS][BLOCK_LEN_SHORT];
-  double fft_f[MAX_SHORT_WINDOWS][BLOCK_LEN_SHORT];
-  double last6_fft_r[BLOCK_LEN_SHORT];
-  double last6_fft_f[BLOCK_LEN_SHORT];
-  double last7_fft_r[BLOCK_LEN_SHORT];
-  double last7_fft_f[BLOCK_LEN_SHORT];
-  double nb[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double en[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double last7_nb[NPART_SHORT];
-  double ismr[MAX_SHORT_WINDOWS][NSFB_SHORT]; /* 1/SMR in each swb */
-  int use_ms[MAX_SHORT_WINDOWS][NSFB_SHORT];
-} PSY_STATVARIABLE_SHORT;
-
-typedef struct {
-  double r_pred[MAX_SHORT_WINDOWS][BLOCK_LEN_SHORT];
-  double f_pred[MAX_SHORT_WINDOWS][BLOCK_LEN_SHORT];
-  double c[MAX_SHORT_WINDOWS][BLOCK_LEN_SHORT];
-  double e[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double cw[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double en[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double cb[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double cbb[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double tb[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double snr[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double bc[MAX_SHORT_WINDOWS][NPART_SHORT];
-  double epart[MAX_SHORT_WINDOWS][NSFB_SHORT];
-  double thr[MAX_SHORT_WINDOWS][BLOCK_LEN_SHORT];
-  double npart[MAX_SHORT_WINDOWS][NSFB_SHORT];
-} PSY_VARIABLE_SHORT;
-
-typedef struct {
-  double *p_ratio;
-  int    use_ms[NSFB_LONG];
-} CH_PSYCH_OUTPUT_LONG;
-
-typedef struct {
-  double *p_ratio;
-  int    use_ms[NSFB_SHORT];
-} CH_PSYCH_OUTPUT_SHORT;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void Psy_Init( void );
-void Psy_FillBuffer(double *p_time_signal[], int no_of_chan);
-void Psy_Calculate( 
-  /* input */
-  AACQuantInfo *quantInfo,
-  double sampling_rate,
-  int    no_of_chan,         /* no of audio channels */
-  double *p_time_signal[],
-  enum WINDOW_TYPE block_type[],
-  int use_MS,
-  /* output */
-  CH_PSYCH_OUTPUT_LONG p_chpo_long[],
-  CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS]
-);
-
-#define psy_sqr(x) ((x)*(x))
-
-
-double psy_get_absthr(double f); /* Jul 8 */
-
-void psy_fft_table_init(FFT_TABLE_LONG *fft_tbl_long, 
-			FFT_TABLE_SHORT *fft_tbl_short
-			);
-
-void psy_part_table_init(double sampling_rate,
-			 PARTITION_TABLE_LONG *part_tbl_long, 
-			 PARTITION_TABLE_SHORT *part_tbl_short
-			 );
-
-void psy_calc_init(double sample[][BLOCK_LEN_LONG*2],
-		   PSY_STATVARIABLE_LONG *psy_stvar_long, 
-		   PSY_STATVARIABLE_SHORT *psy_stvar_short
-		   ); 
-
-void psy_step1(double* p_time_signal[], 
-	       double sample[][BLOCK_LEN_LONG*2], 
-	       int ch
-	       );
-
-void psy_step2(double sample[][BLOCK_LEN_LONG*2], 
-               PSY_STATVARIABLE_LONG *psy_stvar_long, 
-               PSY_STATVARIABLE_SHORT *psy_stvar_short,
-	       FFT_TABLE_LONG *fft_tbl_long,
-	       FFT_TABLE_SHORT *fft_tbl_short,
-	       int ch
-	       );
-
-void psy_step3(PSY_STATVARIABLE_LONG *psy_stvar_long, 
-               PSY_STATVARIABLE_SHORT *psy_stvar_short, 
-               PSY_VARIABLE_LONG *psy_var_long, 
-               PSY_VARIABLE_SHORT *psy_var_short
-	       );
-
-void psy_step4(PSY_STATVARIABLE_LONG *psy_stvar_long,
-               PSY_STATVARIABLE_SHORT *psy_stvar_short,
-	       PSY_VARIABLE_LONG *psy_var_long,
-	       PSY_VARIABLE_SHORT *psy_var_short
-	       );
-
-void psy_step5(PARTITION_TABLE_LONG *part_tbl_long,
-			   PARTITION_TABLE_SHORT *part_tbl_short,
-			   PSY_STATVARIABLE_LONG *psy_stvar_long,
-                           PSY_STATVARIABLE_SHORT *psy_stvar_short,
-			   PSY_VARIABLE_LONG *psy_var_long,
-			   PSY_VARIABLE_SHORT *psy_var_short
-			   );
-
-void psy_step6(PARTITION_TABLE_LONG *part_tbl_long,
-			   PARTITION_TABLE_SHORT *part_tbl_short,
-			   PSY_STATVARIABLE_LONG *psy_stvar_long,
-                           PSY_STATVARIABLE_SHORT *psy_stvar_short,
-			   PSY_VARIABLE_LONG *psy_var_long,
-			   PSY_VARIABLE_SHORT *psy_var_short
-			   );
-
-void psy_step7(PARTITION_TABLE_LONG *part_tbl_long,
-	       PARTITION_TABLE_SHORT *part_tbl_short,
-	       PSY_VARIABLE_LONG *psy_var_long,
-	       PSY_VARIABLE_SHORT *psy_var_short
-	       );
-
-void psy_step8(PARTITION_TABLE_LONG *part_tbl_long,
-	       PARTITION_TABLE_SHORT *part_tbl_short,
-	       PSY_VARIABLE_LONG *psy_var_long,
-	       PSY_VARIABLE_SHORT *psy_var_short
-	       );
-
-void psy_step9(PARTITION_TABLE_LONG *part_tbl_long,
-	       PARTITION_TABLE_SHORT *part_tbl_short,
-	       PSY_VARIABLE_LONG *psy_var_long,
-	       PSY_VARIABLE_SHORT *psy_var_short
-	       );
-
-void psy_step10(PARTITION_TABLE_LONG *part_tbl_long,
-		PARTITION_TABLE_SHORT *part_tbl_short,
-		PSY_STATVARIABLE_LONG *psy_stvar_long,
-		PSY_STATVARIABLE_SHORT *psy_stvar_short,
-		PSY_VARIABLE_LONG *psy_var_long,
-		PSY_VARIABLE_SHORT *psy_var_short
-		);
-
-void psy_step11(PARTITION_TABLE_LONG *part_tbl_long,
-		PARTITION_TABLE_SHORT *part_tbl_short,
-		PSY_STATVARIABLE_LONG *psy_stvar_long,
-		PSY_STATVARIABLE_SHORT *psy_stvar_short
-		);
-
-void psy_step12(PARTITION_TABLE_LONG *part_tbl_long,
-				PARTITION_TABLE_SHORT *part_tbl_short,
-				PSY_STATVARIABLE_LONG *psy_stvar_long,
-				PSY_STATVARIABLE_SHORT *psy_stvar_short,
-				PSY_VARIABLE_LONG *psy_var_long,
-				PSY_VARIABLE_SHORT *psy_var_short,
-				enum WINDOW_TYPE *block_type
-				);
-
-void psy_step14(SR_INFO *p_sri,
-				PARTITION_TABLE_LONG *part_tbl_long,
-				PARTITION_TABLE_SHORT *part_tbl_short,
-				PSY_STATVARIABLE_LONG *psy_stvar_long,
-				PSY_STATVARIABLE_SHORT *psy_stvar_short,
-				PSY_VARIABLE_LONG *psy_var_long,
-				PSY_VARIABLE_SHORT *psy_var_short
-                );
-
-void psy_step15(SR_INFO *p_sri,
-				PSY_STATVARIABLE_LONG *psy_stvar_long,
-				PSY_STATVARIABLE_SHORT *psy_stvar_short,
-				PSY_VARIABLE_LONG *psy_var_long, PSY_VARIABLE_SHORT *psy_var_short,
-				int leftChan, int rightChan, int midChan, int sideChan
-				);
-
-void psy_step2MS(PSY_STATVARIABLE_LONG *psy_stvar_long,
-				 PSY_STATVARIABLE_SHORT *psy_stvar_short,
-				 int leftChan, int rightChan,
-				 int midChan, int sideChan);
-
-void psy_step4MS(PSY_VARIABLE_LONG *psy_var_long,
-				 PSY_VARIABLE_SHORT *psy_var_short,
-				 int leftChan, int rightChan,
-				 int midChan, int sideChan);
-
-void psy_step7MS(PSY_VARIABLE_LONG *psy_var_long,
-				 PSY_VARIABLE_SHORT *psy_var_short,
-				 int leftChan, int rightChan,
-				 int midChan, int sideChan);
-
-void psy_step11MS(PARTITION_TABLE_LONG *part_tbl_long,
-				  PARTITION_TABLE_SHORT *part_tbl_short,
-				  PSY_STATVARIABLE_LONG *psy_stvar_long,
-				  PSY_STATVARIABLE_SHORT *psy_stvar_short,
-				  int leftChan, int rightChan,
-				  int midChan, int sideChan);
-
-#ifdef __cplusplus
-}
-#endif
--- a/pulse.c
+++ /dev/null
@@ -1,115 +1,0 @@
-/*
- *	Pulse Coding
- *
- *	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.4 $
-  $Date: 2000/10/06 14:47:27 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <math.h>
-
-#include "quant.h"
-#include "huffman.h"
-
-#define STARTSFB 16 // approx. 2kHz
-
-void PulseCoder(AACQuantInfo *quantInfo, int *quant)
-{
-	int i, j, sb, k;
-	int pulses = 0;
-	pulse pul_arr[4];
-
-#if 1
-	for (sb = STARTSFB; sb < quantInfo->nr_of_sfb; sb++)
-	{
-		for (i = quantInfo->sfb_offset[sb]; i < quantInfo->sfb_offset[sb+1]; i++)
-		{
-			if ((i != 0)&&(i<quantInfo->sfb_offset[quantInfo->nr_of_sfb]))
-			{
-				/* This is a peak */
-				if ((abs(quant[i]) > abs(quant[i-1])+4)&&(abs(quant[i]) > abs(quant[i+1])+4))
-				{
-					pulses++;
-					if (pulses == 1) {
-						j = i;
-						pul_arr[pulses-1].offset = i-quantInfo->sfb_offset[sb];
-						pul_arr[pulses-1].sfb = sb;
-						pul_arr[pulses-1].amp = min(15,(int)(abs((quant[i-1])+abs(quant[i+1]))/2+0.5));
-						if (pul_arr[pulses-1].offset >= 32) {
-							pulses = 0;
-						}
-					} else {
-						pul_arr[pulses-1].offset = i-j;
-						j = i;
-						pul_arr[pulses-1].amp = min(15,(int)((abs(quant[i-1])+abs(quant[i+1]))/2+0.5));
-						if (pul_arr[pulses-1].offset >= 32) {
-							pulses--;
-							goto end;
-						}
-					}
-				}
-				if (pulses == 4)
-					goto end;
-			}
-		}
-	}
-#endif
-
-end:
-	if (pulses) {
-		quantInfo->pulseInfo.pulse_data_present = 1;
-		quantInfo->pulseInfo.number_pulse = pulses-1;
-		quantInfo->pulseInfo.pulse_start_sfb = pul_arr[0].sfb;
-		k = quantInfo->sfb_offset[pul_arr[0].sfb];
-
-		for (i = 0; i < pulses; i++) {
-			quantInfo->pulseInfo.pulse_offset[i] = pul_arr[i].offset;
-			quantInfo->pulseInfo.pulse_amp[i] = pul_arr[i].amp;
-
-			k += pul_arr[i].offset;
-			if (quant[k] > 0)
-				quant[k] -= pul_arr[i].amp;
-			else
-				quant[k] += pul_arr[i].amp;
-		}
-	} else {
-		quantInfo->pulseInfo.pulse_data_present = 0;
-	}
-}
-
-void PulseDecoder(AACQuantInfo *quantInfo, int *quant)
-{
-	int i, offset;
-
-	if (quantInfo->pulseInfo.pulse_data_present)
-	{
-		offset = quantInfo->sfb_offset[quantInfo->pulseInfo.pulse_start_sfb];
-		for(i = 0; i < quantInfo->pulseInfo.number_pulse+1; i++) {
-			offset += quantInfo->pulseInfo.pulse_offset[i];
-			if (quant[offset] > 0)
-				quant[offset] -= quantInfo->pulseInfo.pulse_amp[i];
-			else
-				quant[offset] += quantInfo->pulseInfo.pulse_amp[i];
-		}
-	}
-}
--- a/pulse.h
+++ /dev/null
@@ -1,57 +1,0 @@
-/*
- *	Function prototypes for pulse coding
- *
- *	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.3 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef PULSE_H_
-#define PULSE_H_
-
-#include "interface.h"
-//#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
-
-typedef struct
-{
-    int pulse_data_present;
-    int number_pulse;
-    int pulse_start_sfb;
-    int pulse_position[NUM_NEC_LINES];
-    int pulse_offset[NUM_NEC_LINES];
-    int pulse_amp[NUM_NEC_LINES];
-} AACPulseInfo;
-
-typedef struct {
-	int offset;
-	int sfb;
-	int amp;
-} pulse;
-
-
-#endif
--- a/quant.c
+++ /dev/null
@@ -1,1261 +1,0 @@
-/*
- *	AAC quantization
- *
- *	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.14 $
-  $Date: 2000/11/10 13:27:06 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <math.h>
-#include <memory.h>
-
-#include "aacenc.h"
-#include "quant.h"
-#include "bitstream.h"
-#include "pulse.h"
-#include "huffman.h"
-#include "aac_se_enc.h"
-
-
-
-double pow_quant[9000];
-double adj_quant[9000];
-double adj_quant_asm[9000];
-int sign[1024];
-int g_Count;
-int old_startsf;
-int pns_sfb_start = 1000;         /* lower border for Perceptual Noise Substitution
-                                      (off by default) */
-
-double ATH[MAX_SCFAC_BANDS];
-
-double ATHformula(double f)
-{
-	double ath;
-	f  = max(0.02, f);
-	/* from Painter & Spanias, 1997 */
-	/* minimum: (i=77) 3.3kHz = -5db */
-	ath=(3.640 * pow(f,-0.8)
-		-  6.500 * exp(-0.6*pow(f-3.3,2.0))
-		+  0.001 * pow(f,4.0));
-
-	/* convert to energy */
-	ath = pow( 10.0, ath/10.0 );
-	return ath;
-}
-
-
-void compute_ath(AACQuantInfo *quantInfo, double ATH[MAX_SCFAC_BANDS])
-{
-	int sfb,i,start=0,end=0;
-	double ATH_f;
-	double samp_freq = 44.1;
-	static int width[] = {0, 4,  4,  4,  4,  4,  8,  8,  8, 12, 12, 12, 16, 16, 16};
-	if (quantInfo->block_type==ONLY_SHORT_WINDOW) {
-		for ( sfb = 0; sfb < 14; sfb++ ) {
-			start = start+(width[sfb]*8);
-			end   = end+(width[sfb+1]*8);
-			ATH[sfb]=1e99;
-			for (i=start ; i < end; i++) {
-				ATH_f = ATHformula(samp_freq*i/(128)); /* freq in kHz */
-				ATH[sfb]=min(ATH[sfb],ATH_f);
-			}
-		}
-	} else {
-		for ( sfb = 0; sfb < quantInfo->nr_of_sfb; sfb++ ) {
-			start = quantInfo->sfb_offset[sfb];
-			end   = quantInfo->sfb_offset[sfb+1];
-			ATH[sfb]=1e99;
-			for (i=start ; i < end; i++) {
-				ATH_f = ATHformula(samp_freq*i/(1024)); /* freq in kHz */
-				ATH[sfb]=min(ATH[sfb],ATH_f);
-			}
-		}
-	}
-}
-
-
-void aacQuantizeInit(int quality)
-{
-	int i;
-
-	g_Count = quality;
-	old_startsf = 0;
-
-	for (i=0;i<9000;i++){
-		pow_quant[i]=pow(i, ((double)4.0/(double)3.0));
-	}
-    for (i = 0; i < 8999; i++)
-		adj_quant[i] = (i + 1) - pow(0.5 * (pow_quant[i] + pow_quant[i + 1]), 0.75);
-    adj_quant[i] = 0.5;
-
-	adj_quant_asm[0] = 0.0;
-	for (i = 1; i < 9000; i++) {
-		adj_quant_asm[i] = i - 0.5 - pow(0.5 * (pow_quant[i - 1] + pow_quant[i]),0.75);
-	}
-}
-
-
-
-#if (defined(__GNUC__) && defined(__i386__))
-#define USE_GNUC_ASM
-#endif
-
-#ifdef USE_GNUC_ASM
-#  define QUANTFAC(rx)  adj_quant_asm[rx]
-#  define XRPOW_FTOI(src, dest) \
-     asm ("fistpl %0 " : "=m"(dest) : "t"(src) : "st")
-#else
-#  define QUANTFAC(rx)  adj_quant[rx]
-#  define XRPOW_FTOI(src,dest) ((dest) = (int)(src))
-#endif
-
-/*********************************************************************
- * nonlinear quantization of xr
- * More accurate formula than the ISO formula.  Takes into account
- * the fact that we are quantizing xr -> ix, but we want ix^4/3 to be
- * as close as possible to x^4/3.  (taking the nearest int would mean
- * ix is as close as possible to xr, which is different.)
- * From Segher Boessenkool <segher@eastsite.nl>  11/1999
- * ASM optimization from
- *    Mathew Hendry <scampi@dial.pipex.com> 11/1999
- *    Acy Stapp <AStapp@austin.rr.com> 11/1999
- *    Takehiro Tominaga <tominaga@isoternet.org> 11/1999
- *********************************************************************/
-void quantize(AACQuantInfo *quantInfo,
-			  double *pow_spectrum,
-			  int *quant)
-{
-	const double istep = pow(2.0, -0.1875*quantInfo->common_scalefac);
-
-#if ((defined _MSC_VER) || (defined __BORLANDC__))
-	{
-		/* asm from Acy Stapp <AStapp@austin.rr.com> */
-		int rx[4];
-		_asm {
-			fld qword ptr [istep]
-			mov esi, dword ptr [pow_spectrum]
-			lea edi, dword ptr [adj_quant_asm]
-			mov edx, dword ptr [quant]
-			mov ecx, 1024/4
-		}
-loop1:
-		_asm {
-			fld qword ptr [esi]         // 0
-			fld qword ptr [esi+8]       // 1 0
-			fld qword ptr [esi+16]      // 2 1 0
-			fld qword ptr [esi+24]      // 3 2 1 0
-
-
-			fxch st(3)                  // 0 2 1 3
-			fmul st(0), st(4)
-			fxch st(2)                  // 1 2 0 3
-			fmul st(0), st(4)
-			fxch st(1)                  // 2 1 0 3
-			fmul st(0), st(4)
-			fxch st(3)                  // 3 1 0 2
-			fmul st(0), st(4)
-			add esi, 32
-			add edx, 16
-
-			fxch st(2)                  // 0 1 3 2
-			fist dword ptr [rx]
-			fxch st(1)                  // 1 0 3 2
-			fist dword ptr [rx+4]
-			fxch st(3)                  // 2 0 3 1
-			fist dword ptr [rx+8]
-			fxch st(2)                  // 3 0 2 1
-			fist dword ptr [rx+12]
-
-			dec ecx
-
-			mov eax, dword ptr [rx]
-			mov ebx, dword ptr [rx+4]
-			fxch st(1)                  // 0 3 2 1
-			fadd qword ptr [edi+eax*8]
-			fxch st(3)                  // 1 3 2 0
-			fadd qword ptr [edi+ebx*8]
-
-			mov eax, dword ptr [rx+8]
-			mov ebx, dword ptr [rx+12]
-			fxch st(2)                  // 2 3 1 0
-			fadd qword ptr [edi+eax*8]
-			fxch st(1)                  // 3 2 1 0
-			fadd qword ptr [edi+ebx*8]
-
-			fxch st(3)                  // 0 2 1 3
-			fistp dword ptr [edx-16]    // 2 1 3
-			fxch st(1)                  // 1 2 3
-			fistp dword ptr [edx-12]    // 2 3
-			fistp dword ptr [edx-8]     // 3
-			fistp dword ptr [edx-4]
-
-			jnz loop1
-
-			mov dword ptr [pow_spectrum], esi
-			mov dword ptr [quant], edx
-			fstp st(0)
-		}
-	}
-#elif defined (USE_GNUC_ASM)
-  {
-      int rx[4];
-      __asm__ __volatile__(
-        "\n\nloop1:\n\t"
-
-        "fldl (%1)\n\t"
-        "fldl 8(%1)\n\t"
-        "fldl 16(%1)\n\t"
-        "fldl 24(%1)\n\t"
-
-        "fxch %%st(3)\n\t"
-        "fmul %%st(4)\n\t"
-        "fxch %%st(2)\n\t"
-        "fmul %%st(4)\n\t"
-        "fxch %%st(1)\n\t"
-        "fmul %%st(4)\n\t"
-        "fxch %%st(3)\n\t"
-        "fmul %%st(4)\n\t"
-
-        "addl $32, %1\n\t"
-        "addl $16, %3\n\t"
-
-        "fxch %%st(2)\n\t"
-        "fistl %5\n\t"
-        "fxch %%st(1)\n\t"
-        "fistl 4+%5\n\t"
-        "fxch %%st(3)\n\t"
-        "fistl 8+%5\n\t"
-        "fxch %%st(2)\n\t"
-        "fistl 12+%5\n\t"
-
-        "dec %4\n\t"
-
-        "movl %5, %%eax\n\t"
-        "movl 4+%5, %%ebx\n\t"
-        "fxch %%st(1)\n\t"
-        "faddl (%2,%%eax,8)\n\t"
-        "fxch %%st(3)\n\t"
-        "faddl (%2,%%ebx,8)\n\t"
-
-        "movl 8+%5, %%eax\n\t"
-        "movl 12+%5, %%ebx\n\t"
-        "fxch %%st(2)\n\t"
-        "faddl (%2,%%eax,8)\n\t"
-        "fxch %%st(1)\n\t"
-        "faddl (%2,%%ebx,8)\n\t"
-
-        "fxch %%st(3)\n\t"
-        "fistpl -16(%3)\n\t"
-        "fxch %%st(1)\n\t"
-        "fistpl -12(%3)\n\t"
-        "fistpl -8(%3)\n\t"
-        "fistpl -4(%3)\n\t"
-
-        "jnz loop1\n\n"
-        : /* no outputs */
-        : "t" (istep), "r" (pow_spectrum), "r" (adj_quant_asm), "r" (quant), "r" (1024 / 4), "m" (rx)
-        : "%eax", "%ebx", "memory", "cc"
-      );
-  }
-  {/* from Wilfried.Behne@t-online.de.  Reported to be 2x faster than
-      the above code (when not using ASM) on PowerPC */
-     	int j;
-
-     	for ( j = 1024/8; j > 0; --j)
-     	{
-			double	x1, x2, x3, x4, x5, x6, x7, x8;
-			int rx1, rx2, rx3, rx4, rx5, rx6, rx7, rx8;
-			x1 = *pow_spectrum++ * istep;
-			x2 = *pow_spectrum++ * istep;
-			XRPOW_FTOI(x1, rx1);
-			x3 = *pow_spectrum++ * istep;
-			XRPOW_FTOI(x2, rx2);
-			x4 = *pow_spectrum++ * istep;
-			XRPOW_FTOI(x3, rx3);
-			x5 = *pow_spectrum++ * istep;
-			XRPOW_FTOI(x4, rx4);
-			x6 = *pow_spectrum++ * istep;
-			XRPOW_FTOI(x5, rx5);
-			x7 = *pow_spectrum++ * istep;
-			XRPOW_FTOI(x6, rx6);
-			x8 = *pow_spectrum++ * istep;
-			XRPOW_FTOI(x7, rx7);
-			x1 += QUANTFAC(rx1);
-			XRPOW_FTOI(x8, rx8);
-			x2 += QUANTFAC(rx2);
-			XRPOW_FTOI(x1,*quant++);
-			x3 += QUANTFAC(rx3);
-			XRPOW_FTOI(x2,*quant++);
-			x4 += QUANTFAC(rx4);
-			XRPOW_FTOI(x3,*quant++);
-			x5 += QUANTFAC(rx5);
-			XRPOW_FTOI(x4,*quant++);
-			x6 += QUANTFAC(rx6);
-			XRPOW_FTOI(x5,*quant++);
-			x7 += QUANTFAC(rx7);
-			XRPOW_FTOI(x6,*quant++);
-			x8 += QUANTFAC(rx8);
-			XRPOW_FTOI(x7,*quant++);
-			XRPOW_FTOI(x8,*quant++);
-     	}
-	}
-#endif
-}
-
-int inner_loop(AACQuantInfo *quantInfo,
-			   double *pow_spectrum,
-			   int quant[BLOCK_LEN_LONG],
-			   int max_bits)
-{
-	int bits;
-
-	/*  count bits */
-	bits = count_bits(quantInfo, pow_spectrum, quant);
-
-	/*  increase quantizer stepsize until needed bits are below maximum */
-	while (bits > max_bits) {
-		quantInfo->common_scalefac += 1;
-		bits = count_bits(quantInfo, pow_spectrum, quant);
-	}
-
-	return bits;
-}
-
-
-int search_common_scalefac(AACQuantInfo *quantInfo,
-						   double *pow_spectrum,
-						   int quant[BLOCK_LEN_LONG],
-						   int desired_rate)
-{
-	int flag_GoneOver = 0;
-	int CurrentStep = 4;
-	int nBits;
-	int StepSize = old_startsf;
-	int Direction = 0;
-	do
-	{
-		quantInfo->common_scalefac = StepSize;
-		nBits = count_bits(quantInfo, pow_spectrum, quant);
-
-		if (CurrentStep == 1 ) {
-			break; /* nothing to adjust anymore */
-		}
-		if (flag_GoneOver) {
-			CurrentStep /= 2;
-		}
-		if (nBits > desired_rate) { /* increase Quantize_StepSize */
-			if (Direction == -1 && !flag_GoneOver) {
-				flag_GoneOver = 1;
-				CurrentStep /= 2; /* late adjust */
-			}
-			Direction = 1;
-			StepSize += CurrentStep;
-		} else if (nBits < desired_rate) {
-			if (Direction == 1 && !flag_GoneOver) {
-				flag_GoneOver = 1;
-				CurrentStep /= 2; /* late adjust */
-			}
-			Direction = -1;
-			StepSize -= CurrentStep;
-		} else break;
-    } while (1);
-
-    old_startsf = StepSize;
-
-    return nBits;
-}
-
-int calc_noise(AACQuantInfo *quantInfo,
-				double *p_spectrum,
-				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
-				)
-{
-	int i, sb, sbw;
-	int over = 0, count = 0;
-	double invQuantFac;
-	double linediff, noise;
-
-	*over_noise = 1;
-	*tot_noise = 1;
-	*max_noise = 1E-20;
-
-	if (quantInfo->block_type!=ONLY_SHORT_WINDOW)
-		PulseDecoder(quantInfo, quant);
-
-	for (sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-
-		double max_sb_noise = 0.0;
-
-		sbw = quantInfo->sfb_offset[sb+1] - quantInfo->sfb_offset[sb];
-
-		invQuantFac = pow(2.0, -0.25*(quantInfo->scale_factor[sb] - quantInfo->common_scalefac));
-
-		error_energy[sb] = 0.0;
-
-		for (i = quantInfo->sfb_offset[sb]; i < quantInfo->sfb_offset[sb+1]; i++){
-			requant[i] =  pow_quant[min(ABS(quant[i]),8999)] * invQuantFac; 
-
-			/* measure the distortion in each scalefactor band */
-			linediff = (double)(ABS(p_spectrum[i]) - ABS(requant[i]));
-			linediff *= linediff;
-			error_energy[sb] += linediff;
-			max_sb_noise = max(max_sb_noise, linediff);
-		}
-		error_energy[sb] = error_energy[sb] / sbw;		
-		
-		noise = error_energy[sb] / allowed_dist[sb];
-
-		/* multiplying here is adding in dB */
-		*tot_noise *= max(noise, 1E-20);
-		if (noise>1) {
-			over++;
-			/* multiplying here is adding in dB */
-			*over_noise *= noise;
-		}
-		*max_noise = max(*max_noise,noise);
-		error_energy[sb] = noise;
-		count++;
-  	}
-
-	return over;
-}
-
-int quant_compare(int best_over, double best_tot_noise, double best_over_noise,
-				  double best_max_noise, int over, double tot_noise, double over_noise,
-				  double max_noise)
-//int quant_compare(double best_tot_noise, double best_over_noise,
-//		  double tot_noise, double over_noise)
-{
-	/*
-	noise is given in decibals (db) relative to masking thesholds.
-
-	over_noise:  sum of quantization noise > masking
-	tot_noise:   sum of all quantization noise
-	max_noise:   max quantization noise
-
-	*/
-	int better;
-
-	better =   over  < best_over ||  ( over == best_over
-		&& over_noise < best_over_noise )
-		||  ( over == best_over && over_noise==best_over_noise
-		&& tot_noise < best_tot_noise);
-
-#if 0
-	better = ((over < best_over) ||
-		((over==best_over) && (over_noise<best_over_noise)) ) ;
-	better = min(better, max_noise < best_max_noise);
-	better = min(better, tot_noise < best_tot_noise);
-	better = min(better, (tot_noise < best_tot_noise) &&
-		(max_noise < best_max_noise + 2));
-	better = min(better, ( ( (0>=max_noise) && (best_max_noise>2)) ||
-		( (0>=max_noise) && (best_max_noise<0) && ((best_max_noise+2)>max_noise) && (tot_noise<best_tot_noise) ) ||
-		( (0>=max_noise) && (best_max_noise>0) && ((best_max_noise+2)>max_noise) && (tot_noise<(best_tot_noise+best_over_noise)) ) ||
-		( (0<max_noise) && (best_max_noise>-0.5) && ((best_max_noise+1)>max_noise) && ((tot_noise+over_noise)<(best_tot_noise+best_over_noise)) ) ||
-		( (0<max_noise) && (best_max_noise>-1) && ((best_max_noise+1.5)>max_noise) && ((tot_noise+over_noise+over_noise)<(best_tot_noise+best_over_noise+best_over_noise)) ) ));
-	better = min(better, (over_noise <  best_over_noise)
-		|| ((over_noise == best_over_noise)&&(tot_noise < best_tot_noise)));
-	better = min(better, (over_noise < best_over_noise)
-		||( (over_noise == best_over_noise)
-		&&( (max_noise < best_max_noise)
-		||( (max_noise == best_max_noise)
-		&&(tot_noise <= best_tot_noise)
-		)
-		)
-		));
-#endif
-
-	return better;
-}
-
-
-int count_bits_long(AACQuantInfo* quantInfo,
-			   int quant[BLOCK_LEN_LONG]
-			   )
-{
-	int i, bits = 0;
-
-	if (quantInfo->block_type==ONLY_SHORT_WINDOW)
-		quantInfo->pulseInfo.pulse_data_present = 0;
-	else
-		PulseCoder(quantInfo, quant);
-
-	/* find a good method to section the scalefactor bands into huffman codebook sections */
-	bit_search(quant,              /* Quantized spectral values */
-		quantInfo);         /* Quantization information */
-
-    /* Set special codebook for bands coded via PNS  */
-    if (quantInfo->block_type != ONLY_SHORT_WINDOW) {     /* long blocks only */
-		for(i=0;i<quantInfo->nr_of_sfb;i++) {
-			if (quantInfo->pns_sfb_flag[i]) {
-				quantInfo->book_vector[i] = PNS_HCB;
-			}
-		}
-    }
-
-	/* calculate the amount of bits needed for encoding the huffman codebook numbers */
-	bits += sort_book_numbers(quantInfo,             /* Quantization information */
-		NULL,          /* Bitstream */
-		0);                    /* Write flag: 0 count, 1 write */
-
-	/* calculate the amount of bits needed for the spectral values */
-	quantInfo -> spectralCount = 0;
-	for(i=0;i< quantInfo -> nr_of_sfb;i++) {  
-		bits += output_bits(
-			quantInfo,
-			quantInfo->book_vector[i],
-			quant,
-			quantInfo->sfb_offset[i], 
-			quantInfo->sfb_offset[i+1]-quantInfo->sfb_offset[i],
-			0);
-	}
-
-	/* the number of bits for the scalefactors */
-	bits += write_scalefactor_bitstream(
-		NULL,             /* Bitstream */  
-		0,                        /* Write flag */
-		quantInfo
-		);
-
-	/* the total amount of bits required */
-	return bits;
-}
-
-int count_bits(AACQuantInfo* quantInfo,
-			   double *pow_spectrum,
-			   int quant[BLOCK_LEN_LONG])
-{
-	int bits = 0, i;
-	double w = 8192 / pow(2.0, (double)quantInfo->common_scalefac * -0.1875);
-
-	for ( i = 0; i < BLOCK_LEN_LONG; i++ )  {
-		if (pow_spectrum[i] > w)
-			return LARGE_BITS;
-	}
-
-	quantize(quantInfo, pow_spectrum, quant);
-
-	bits = count_bits_long(quantInfo, quant);
-
-	return bits;
-}
-
-int aacQuantize(AACQuantInfo* quantInfo,      /* AAC quantization information */
-				double      *p_spectrum[MAX_TIME_CHANNELS],
-				double      *PsySigMaskRatio[MAX_TIME_CHANNELS],
-				double      allowed_dist[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-				double      energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-				enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS],
-				int         sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-				int         average_block_bits,
-				BsBitStream *fixed_stream,
-				double      *p_reconstructed_spectrum[MAX_TIME_CHANNELS]
-				)
-{
-	int quant[BLOCK_LEN_LONG];
-	int s_quant[BLOCK_LEN_LONG];
-	int i;
-//	int j=0;
-	int k;
-	double max_dct_line = 0;
-//	int global_gain;
-	int store_common_scalefac;
-	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[MAX_SCFAC_BANDS*2];
-	double SigMaskRatio[MAX_SCFAC_BANDS];
-	MS_Info *ms_info;
-	int *ptr_book_vector;
-
-	/* Set up local pointers to quantInfo elements for convenience */
-	int* sfb_offset = quantInfo -> sfb_offset;
-	int* scale_factor = quantInfo -> scale_factor;
-	int* common_scalefac = &(quantInfo -> common_scalefac);
-
-	int outer_loop_count, notdone;
-	int over, better;
-	int best_over = 100;
-//	int sfb_overflow;
-	int best_common_scalefac;
-	double noise_thresh;
-	double sfQuantFac;
-	double over_noise, tot_noise, max_noise;
-	double noise[MAX_SCFAC_BANDS];
-	double best_max_noise = 0;
-	double best_over_noise = 0;
-	double best_tot_noise = 0;
-//	static int init = -1;
-
-	/* Set block type in quantization info */
-	quantInfo -> block_type = block_type[0];
-
-#if 0
-	if (init != quantInfo->block_type) {
-		init = quantInfo->block_type;
-		compute_ath(quantInfo, ATH);
-	}
-#endif
-
-	sfQuantFac = pow(2.0, 0.1875);
-
-	/** create the sfb_offset tables **/
-	if (quantInfo->block_type == ONLY_SHORT_WINDOW) {
-
-		/* Now compute interleaved sf bands and spectrum */
-		sort_for_grouping(
-			quantInfo,                       /* ptr to quantization information */
-			sfb_width_table[0],      /* Widths of single window */
-			p_spectrum,                      /* Spectral values, noninterleaved */
-			SigMaskRatio,
-			PsySigMaskRatio[0]
-			);
-
-		extra_bits = 51;
-	} else{
-		/* For long windows, band are not actually interleaved */
-		if ((quantInfo -> block_type == ONLY_LONG_WINDOW) ||  
-			(quantInfo -> block_type == LONG_SHORT_WINDOW) ||
-			(quantInfo -> block_type == SHORT_LONG_WINDOW)) {
-			quantInfo->nr_of_sfb = quantInfo->max_sfb;
-
-			sfb_offset[0] = 0;
-			k=0;
-			for( i=0; i< quantInfo -> nr_of_sfb; i++ ){
-				sfb_offset[i] = k;
-				k +=sfb_width_table[0][i];
-				SigMaskRatio[i]=PsySigMaskRatio[0][i];
-			}
-			sfb_offset[i] = k;
-			extra_bits = 100; /* header bits and more ... */
-
-		} 
-	}
-
-	extra_bits += 1;
-
-    /* Take into account bits for TNS data */
-    extra_bits += WriteTNSData(quantInfo,fixed_stream,0);    /* Count but don't write */
-
-    if(quantInfo->block_type!=ONLY_SHORT_WINDOW)
-		/* Take into account bits for LTP data */
-		extra_bits += WriteLTP_PredictorData(quantInfo, fixed_stream, 0); /* Count but don't write */
-
-    /* for short windows, compute interleaved energy here */
-    if (quantInfo->block_type==ONLY_SHORT_WINDOW) {
-		int numWindowGroups = quantInfo->num_window_groups;
-		int maxBand = quantInfo->max_sfb;
-		int windowOffset=0;
-		int sfb_index=0;
-		int g;
-		for (g=0;g<numWindowGroups;g++) {
-			int numWindowsThisGroup = quantInfo->window_group_length[g];
-			int b;
-			for (b=0;b<maxBand;b++) {
-				double sum=0.0;
-				int w;
-				for (w=0;w<numWindowsThisGroup;w++) {
-					int bandNum = (w+windowOffset)*maxBand + b;
-					sum += energy[0][bandNum];
-				}
-				energy[0][sfb_index] = sum/numWindowsThisGroup;
-				sfb_index++;
-			}
-			windowOffset += numWindowsThisGroup;
-		}
-    } 
-
-	/* initialize the scale_factors that aren't intensity stereo bands */
-	for(k=0; k< quantInfo -> nr_of_sfb ;k++) {
-		scale_factor[k] = 0;
-	}
-
-	/* Mark IS bands by setting book_vector to INTENSITY_HCB */
-	ptr_book_vector=quantInfo->book_vector;
-	for (k=0;k<quantInfo->nr_of_sfb;k++) {
-		ptr_book_vector[k] = 0;
-	}
-
-	/* PNS prepare */
-	ms_info=&(quantInfo->channelInfo.ms_info);
-    for(sb=0; sb < quantInfo->nr_of_sfb; sb++ )
-		quantInfo->pns_sfb_flag[sb] = 0;
-
-//	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) {
-				quantInfo->pns_sfb_flag[sb] = 0;
-				continue;
-			}
-
-			if ((ms_info->is_present)&&(!ms_info->ms_used[sb])) {
-				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;
-
-					/* Erase spectral lines */
-					for( i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++ ) {
-						p_spectrum[0][i] = 0.0;
-					}
-				}
-			}
-		}
-//	}
-
-	/* Compute allowed distortion */
-	for(sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-		allowed_dist[0][sb] = energy[0][sb] * SigMaskRatio[sb];
-//		if (allowed_dist[0][sb] < ATH[sb]) {
-//			printf("%d Yes\n", sb);
-//			allowed_dist[0][sb] = ATH[sb];
-//		}
-//		printf("%d\t\t%.3f\n", sb, SigMaskRatio[sb]);
-	}
-
-	/** find the maximum spectral coefficient **/
-	/* Bug fix, 3/10/98 CL */
-	/* 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]);
-		if ((ABS(p_spectrum[0][i])) > max_dct_line){
-			max_dct_line = ABS(p_spectrum[0][i]);
-		}
-	}
-
-	if (max_dct_line!=0.0) {
-		if ((int)(16/3 * (log(ABS(pow(max_dct_line,0.75)/MAX_QUANT)/log(2.0)))) > old_startsf) {
-			old_startsf = (int)(16/3 * (log(ABS(pow(max_dct_line,0.75)/MAX_QUANT)/log(2.0))));
-		}
-		if ((old_startsf > 200) || (old_startsf < 40))
-			old_startsf = 40;
-	}
-
-	outer_loop_count = 0;
-
-	notdone = 1;
-	if (max_dct_line == 0) {
-		notdone = 0;
-	}
-	while (notdone) { // outer iteration loop
-
-		outer_loop_count++;
-		over = 0;
-//		sfb_overflow = 0;
-
-//		if (max_dct_line == 0.0)
-//			sfb_overflow = 1;
-
-		if (outer_loop_count == 1) {
-//			max_bits = search_common_scalefac(quantInfo, p_spectrum[0], pow_spectrum,
-//				quant, average_block_bits);
-			search_common_scalefac(quantInfo, pow_spectrum, quant, average_block_bits);
-		}
-
-//		max_bits = inner_loop(quantInfo, p_spectrum[0], pow_spectrum,
-//			quant, average_block_bits) + extra_bits;
-		inner_loop(quantInfo, pow_spectrum, quant, average_block_bits);
-
-		store_common_scalefac = quantInfo->common_scalefac;
-
-		if (notdone) {
-			over = calc_noise(quantInfo, p_spectrum[0], quant, requant, noise, allowed_dist[0],
-				&over_noise, &tot_noise, &max_noise);
-
-			better = quant_compare(best_over, best_tot_noise, best_over_noise,
-				best_max_noise, over, tot_noise, over_noise, max_noise);
-//			better = quant_compare(best_tot_noise, best_over_noise,
-//				               tot_noise, over_noise);
-
-			for (sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-				if (scale_factor[sb] > 59) {
-//					sfb_overflow = 1;
-					better = 0;
-				}
-			}
-
-			if (outer_loop_count == 1)
-				better = 1;
-
-			if (better) {
-//				best_over = over;
-//				best_max_noise = max_noise;
-				best_over_noise = over_noise;
-				best_tot_noise = tot_noise;
-				best_common_scalefac = store_common_scalefac;
-
-				for (sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-					best_scale_factor[sb] = scale_factor[sb];
-				}
-				memcpy(s_quant, quant, sizeof(int)*BLOCK_LEN_LONG);
-			}
-		}
-
-		if (over == 0) notdone=0;
-
-		if (notdone) {
-			notdone = 0;
-			noise_thresh = -900;
-			for ( sb = 0; sb < quantInfo->nr_of_sfb; sb++ )
-				noise_thresh = max(1.05*noise[sb], noise_thresh);
-			noise_thresh = min(noise_thresh, 0.0);
-
-			for (sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-				if ((noise[sb] > noise_thresh)&&(quantInfo->book_vector[sb]!=INTENSITY_HCB)&&(quantInfo->book_vector[sb]!=INTENSITY_HCB2)) {
-
-					allowed_dist[0][sb] *= 2;
-					scale_factor[sb]++;
-					for (i = quantInfo->sfb_offset[sb]; i < quantInfo->sfb_offset[sb+1]; i++){
-						pow_spectrum[i] *= sfQuantFac;
-					}
-					notdone = 1;
-				}
-			}
-			for (sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-				if (scale_factor[sb] > 59)
-					notdone = 0;
-			}
-		}
-
-		if (notdone) {
-			notdone = 0;
-			for (sb = 0; sb < quantInfo->nr_of_sfb; sb++)
-				if (scale_factor[sb] == 0)
-					notdone = 1;
-		}
-
-	}
-
-	if (max_dct_line > 0) {
-		*common_scalefac = best_common_scalefac;
-		for (sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-			scale_factor[sb] = best_scale_factor[sb];
-//			printf("%d\t%d\n", sb, scale_factor[sb]);
-		}
-		for (i = 0; i < 1024; i++)
-			quant[i] = s_quant[i]*sign[i];
-	} else {
-		*common_scalefac = 0;
-		for (sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-			scale_factor[sb] = 0;
-		}
-		for (i = 0; i < 1024; i++)
-			quant[i] = 0;
-	}
-
-	calc_noise(quantInfo, p_spectrum[0], quant, requant, noise, allowed_dist[0],
-			&over_noise, &tot_noise, &max_noise);
-	count_bits_long(quantInfo, quant);
-	if (quantInfo->block_type!=ONLY_SHORT_WINDOW)
-		PulseDecoder(quantInfo, quant);
-
-//	for( sb=0; sb< quantInfo -> nr_of_sfb; sb++ ) {
-//		printf("%d error: %.4f all.dist.: %.4f energy: %.4f\n", sb,
-//			noise[sb], allowed_dist[0][sb], energy[0][sb]);
-//	}
-
-	/* offset the differenec of common_scalefac and scalefactors by SF_OFFSET  */
-	for (i=0; i<quantInfo->nr_of_sfb; i++){
-		if ((ptr_book_vector[i]!=INTENSITY_HCB)&&(ptr_book_vector[i]!=INTENSITY_HCB2)) {
-			scale_factor[i] = *common_scalefac - scale_factor[i] + SF_OFFSET;
-		}
-	}
-//	*common_scalefac = global_gain = scale_factor[0];
-	*common_scalefac = scale_factor[0];
-
-	/* place the codewords and their respective lengths in arrays data[] and len[] respectively */
-	/* there are 'counter' elements in each array, and these are variable length arrays depending on the input */
-
-	quantInfo -> spectralCount = 0;
-	for(k=0;k< quantInfo -> nr_of_sfb; k++) {
-		output_bits(
-			quantInfo,
-			quantInfo->book_vector[k],
-			quant,
-			quantInfo->sfb_offset[k],
-			quantInfo->sfb_offset[k+1]-quantInfo->sfb_offset[k],
-			1);
-//		printf("%d\t%d\n",k,quantInfo->book_vector[k]);
-	}
-
-	/* write the reconstructed spectrum to the output for use with prediction */
-	{
-		int i;
-		for (sb=0; sb<quantInfo -> nr_of_sfb; sb++){
-			if ((ptr_book_vector[sb]==INTENSITY_HCB)||(ptr_book_vector[sb]==INTENSITY_HCB2)){
-				for (i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++){
-					p_reconstructed_spectrum[0][i]=673;
-				}
-			} else {
-				for (i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++){
-					p_reconstructed_spectrum[0][i] = sgn(p_spectrum[0][i]) * requant[i];
-				}
-			}
-		}
-	}
-
-	return FNO_ERROR;
-}
-
-
-
-int sort_for_grouping(AACQuantInfo* quantInfo,        /* ptr to quantization information */
-		      int sfb_width_table[],          /* Widths of single window */
-		      double *p_spectrum[],           /* Spectral values, noninterleaved */
-		      double *SigMaskRatio,
-		      double *PsySigMaskRatio)
-{
-	int i,j,ii;
-	int index;
-	double tmp[1024];
-//	int book=1;
-	int group_offset;
-	int k=0;
-	int windowOffset;
-
-	/* set up local variables for used quantInfo elements */
-	int* sfb_offset = quantInfo -> sfb_offset;
-	int* nr_of_sfb = &(quantInfo -> nr_of_sfb);
-	int* window_group_length;
-	int num_window_groups;
-	*nr_of_sfb = quantInfo->max_sfb;              /* Init to max_sfb */
-	window_group_length = quantInfo -> window_group_length;
-	num_window_groups = quantInfo -> num_window_groups;
-
-	/* calc org sfb_offset just for shortblock */
-	sfb_offset[k]=0;
-	for (k=0; k < 1024; k++) {
-		tmp[k] = 0.0;
-	}
-	for (k=1 ; k <*nr_of_sfb+1; k++) {
-		sfb_offset[k] = sfb_offset[k-1] + sfb_width_table[k-1];
-	}
-
-	/* sort the input spectral coefficients */
-	index = 0;
-	group_offset=0;
-	for (i=0; i< num_window_groups; i++) {
-		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[0][ii+ sfb_offset[k] + 128*j +group_offset];
-			}
-		}
-		group_offset +=  128*window_group_length[i];
-	}
-
-	for (k=0; k<1024; k++){
-		p_spectrum[0][k] = tmp[k];
-	}
-
-	/* now calc the new sfb_offset table for the whole p_spectrum vector*/
-	index = 0;
-	sfb_offset[index] = 0;
-	index++;
-	windowOffset = 0;
-	for (i=0; i < num_window_groups; i++) {
-		for (k=0 ; k <*nr_of_sfb; k++) {
-			/* for this window group and this band, find worst case inverse sig-mask-ratio */
-			int bandNum=windowOffset*NSFB_SHORT + k;
-			double worstISMR = PsySigMaskRatio[bandNum];
-			int w;
-			for (w=1;w<window_group_length[i];w++) {
-				bandNum=(w+windowOffset)*NSFB_SHORT + k;
-				if (PsySigMaskRatio[bandNum]<worstISMR) {
-					worstISMR += (PsySigMaskRatio[bandNum] > 0)?PsySigMaskRatio[bandNum]:worstISMR;
-				}
-			}
-			worstISMR /= 2.0;
-			SigMaskRatio[k+ i* *nr_of_sfb]=worstISMR/window_group_length[i];
-			sfb_offset[index] = sfb_offset[index-1] + sfb_width_table[k]*window_group_length[i] ;
-			index++;
-		}
-		windowOffset += window_group_length[i];
-	}
-
-	*nr_of_sfb = *nr_of_sfb * num_window_groups;  /* Number interleaved bands. */
-
-	return 0;
-}
-
-#if 0
-
-int iteration_loop(
-			   double      *p_spectrum[MAX_TIME_CHANNELS],
-			   double      *PsySigMaskRatio[MAX_TIME_CHANNELS],
-			   double      allowed_dist[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			   double      energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			   enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS],
-			   int         sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			   int         average_block_bits,
-			   BsBitStream *fixed_stream,
-			   double      *p_reconstructed_spectrum[MAX_TIME_CHANNELS],
-			   AACQuantInfo* quantInfo,      /* AAC quantization information */ 
-			   Ch_Info* ch_info
-               )
-{
-	int quant[BLOCK_LEN_LONG];
-	int s_quant[BLOCK_LEN_LONG];
-	int i;
-	int k;
-	double max_dct_line = 0;
-	int store_common_scalefac;
-	int best_scale_factor[MAX_SCFAC_BANDS];
-	double pow_spectrum[BLOCK_LEN_LONG];
-	double requant[BLOCK_LEN_LONG];
-	int sb;
-	int extra_bits;
-	double SigMaskRatio[MAX_SCFAC_BANDS];
-	MS_Info *ms_info;
-	int *ptr_book_vector;
-
-	/* Set up local pointers to quantInfo elements for convenience */
-	int* sfb_offset = quantInfo -> sfb_offset;
-	int* scale_factor = quantInfo -> scale_factor;
-	int* common_scalefac = &(quantInfo -> common_scalefac);
-
-	int outer_loop_count, notdone;
-	int over, better;
-	int best_over = 100;
-	int best_common_scalefac;
-	double noise_thresh;
-	double sfQuantFac;
-	double over_noise, tot_noise, max_noise;
-	double noise[MAX_SCFAC_BANDS];
-	double best_max_noise = 0;
-	double best_over_noise = 0;
-	double best_tot_noise = 0;
-
-	/* Set block type in quantization info */
-	quantInfo -> block_type = block_type[0];
-
-	sfQuantFac = pow(2.0, 0.1875);
-
-	/** create the sfb_offset tables **/
-	if (quantInfo->block_type == ONLY_SHORT_WINDOW) {
-
-		/* Now compute interleaved sf bands and spectrum */
-		sort_for_grouping(
-			quantInfo,                       /* ptr to quantization information */
-			sfb_width_table[0],      /* Widths of single window */
-			p_spectrum,                      /* Spectral values, noninterleaved */
-			SigMaskRatio,
-			PsySigMaskRatio[0]
-			);
-
-		extra_bits = 51;
-	} else{
-		/* For long windows, band are not actually interleaved */
-		if ((quantInfo -> block_type == ONLY_LONG_WINDOW) ||  
-			(quantInfo -> block_type == LONG_SHORT_WINDOW) ||
-			(quantInfo -> block_type == SHORT_LONG_WINDOW)) {
-			quantInfo->nr_of_sfb = quantInfo->max_sfb;
-
-			sfb_offset[0] = 0;
-			k=0;
-			for( i=0; i< quantInfo -> nr_of_sfb; i++ ){
-				sfb_offset[i] = k;
-				k +=sfb_width_table[0][i];
-				SigMaskRatio[i]=PsySigMaskRatio[0][i];
-			}
-			sfb_offset[i] = k;
-			extra_bits = 100; /* header bits and more ... */
-
-		} 
-	}
-
-	extra_bits += 1;
-
-    /* Take into account bits for TNS data */
-    extra_bits += WriteTNSData(quantInfo,fixed_stream,0);    /* Count but don't write */
-
-    if(quantInfo->block_type!=ONLY_SHORT_WINDOW)
-		/* Take into account bits for LTP data */
-		extra_bits += WriteLTP_PredictorData(quantInfo, fixed_stream, 0); /* Count but don't write */
-
-    /* for short windows, compute interleaved energy here */
-    if (quantInfo->block_type==ONLY_SHORT_WINDOW) {
-		int numWindowGroups = quantInfo->num_window_groups;
-		int maxBand = quantInfo->max_sfb;
-		int windowOffset=0;
-		int sfb_index=0;
-		int g;
-		for (g=0;g<numWindowGroups;g++) {
-			int numWindowsThisGroup = quantInfo->window_group_length[g];
-			int b;
-			for (b=0;b<maxBand;b++) {
-				double sum=0.0;
-				int w;
-				for (w=0;w<numWindowsThisGroup;w++) {
-					int bandNum = (w+windowOffset)*maxBand + b;
-					sum += energy[0][bandNum];
-				}
-				energy[0][sfb_index] = sum/numWindowsThisGroup;
-				sfb_index++;
-			}
-			windowOffset += numWindowsThisGroup;
-		}
-    } 
-
-	/* initialize the scale_factors that aren't intensity stereo bands */
-	for(k=0; k< quantInfo -> nr_of_sfb ;k++) {
-		scale_factor[k] = 0;
-	}
-
-	/* Mark IS bands by setting book_vector to INTENSITY_HCB */
-	ptr_book_vector=quantInfo->book_vector;
-	for (k=0;k<quantInfo->nr_of_sfb;k++) {
-		ptr_book_vector[k] = 0;
-	}
-
-	/* PNS prepare */
-	ms_info=&(ch_info->ms_info);
-    for(sb=0; sb < quantInfo->nr_of_sfb; sb++ )
-		quantInfo->pns_sfb_flag[sb] = 0;
-
-//	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) {
-				quantInfo->pns_sfb_flag[sb] = 0;
-				continue;
-			}
-
-			if ((ms_info->is_present)&&(!ms_info->ms_used[sb])) {
-				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;
-
-					/* Erase spectral lines */
-					for( i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++ ) {
-						p_spectrum[0][i] = 0.0;
-					}
-				}
-			}
-		}
-//	}
-
-	/* Compute allowed distortion */
-	for(sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-		allowed_dist[0][sb] = energy[0][sb] * SigMaskRatio[sb];
-	}
-
-	/** find the maximum spectral coefficient **/
-	/* Bug fix, 3/10/98 CL */
-	/* 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]);
-		if ((ABS(p_spectrum[0][i])) > max_dct_line){
-			max_dct_line = ABS(p_spectrum[0][i]);
-		}
-	}
-
-	if (max_dct_line!=0.0) {
-		if ((int)(16/3 * (log(ABS(pow(max_dct_line,0.75)/MAX_QUANT)/log(2.0)))) > old_startsf) {
-			old_startsf = (int)(16/3 * (log(ABS(pow(max_dct_line,0.75)/MAX_QUANT)/log(2.0))));
-		}
-		if ((old_startsf > 200) || (old_startsf < 40))
-			old_startsf = 40;
-	}
-
-	outer_loop_count = 0;
-
-    bit_rate = bitrate_table [gfc->gfp->version] [gfc->bitrate_index];
-    getframebits (gfc, &bitsPerFrame, &mean_bits);
-    ResvFrameBegin (gfc, l3_side, mean_bits, bitsPerFrame );
-
-	/*  calculate needed bits
-	*/
-	max_bits = on_pe (gfc, pe, l3_side, targ_bits, mean_bits, gr);
-	
-	cod_info = &l3_side->gr[gr].ch[ch].tt; 
-
-	/*  init_outer_loop sets up cod_info, scalefac and xrpow 
-	*/
-	if (!init_outer_loop (cod_info, &scalefac[gr][ch], xr[gr][ch],
-		xrpow )) {
-		/*  xr contains no energy, l3_enc will be quantized to zero
-		*/
-		memset (l3_enc[gr][ch], 0, sizeof(int)*576);
-	} else {
-		/*  xr contains energy we will have to encode 
-		 *  calculate the masking abilities
-		 *  find some good quantization in outer_loop 
-		 */
-		calc_xmin (gfc, xr[gr][ch], &ratio[gr][ch], cod_info, 
-			&l3_xmin[ch]);
-		outer_loop (gfc, cod_info, xr[gr][ch], &l3_xmin[ch], 
-			&scalefac[gr][ch], xrpow, l3_enc[gr][ch],
-			ch, targ_bits[ch]);
-	}
-	assert (cod_info->part2_3_length < 4096);
-
-	/*  try some better scalefac storage
-	*/
-	best_scalefac_store (gfc, gr, ch, l3_enc, l3_side, scalefac);
-
-	/*  best huffman_divide may save some bits too
-	*/
-	if (gfc->use_best_huffman == 1) 
-		best_huffman_divide (gfc, gr, ch, cod_info, l3_enc[gr][ch]);
-
-	/*  set the sign of l3_enc from the sign of xr
-	*/
-	for (i = 0; i < 576; i++) {
-		if (xr[gr][ch][i] < 0) l3_enc[gr][ch][i] *= -1; 
-	}
-    
-    ResvFrameEnd (gfc, l3_side, mean_bits);
-
-	/* write the reconstructed spectrum to the output for use with prediction */
-	{
-		int i;
-		for (sb=0; sb<quantInfo -> nr_of_sfb; sb++){
-			if ((ptr_book_vector[sb]==INTENSITY_HCB)||(ptr_book_vector[sb]==INTENSITY_HCB2)){
-				for (i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++){
-					p_reconstructed_spectrum[0][i]=673;
-				}
-			} else {
-				for (i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++){
-					p_reconstructed_spectrum[0][i] = sgn(p_spectrum[0][i]) * requant[i];
-				}
-			}
-		}
-	}
-
-	return FNO_ERROR;
-}
-
-#endif
--- a/quant.h
+++ /dev/null
@@ -1,154 +1,0 @@
-/*
- *	Function prototypes for AAC quantization
- *
- *	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.9 $
-  $Date: 2000/11/10 13:27:06 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef QUANT_H
-#define QUANT_H
-
-#include "pulse.h"
-#include "interface.h"
-#include "tns.h"
-#include "ltp_enc.h"
-#include "bitstream.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-
-
-/* assumptions for the first run of this quantizer */
-#define CHANNEL  1
-#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 MAXFAC 121   /* maximum scale factor */
-#define MIDFAC (MAXFAC-1)/2
-#define SF_OFFSET 100   /* global gain must be positive */
-#define LARGE_BITS 100000
-
-#define INTENSITY_HCB 15
-#define INTENSITY_HCB2 14
-
-
-extern int pns_sfb_start;                        /* lower border for PNS */
-
-
-/*********************************************************/
-/* AACQuantInfo, info for AAC quantization and coding.   */
-/*********************************************************/
-typedef struct _AACQuantInfo {
-  int max_sfb;                          /* max_sfb, should = nr_of_sfb/num_window_groups */
-  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[MAX_SCFAC_BANDS];        /* Scalefactor data array , interleaved */			
-  int sfb_offset[250];                  /* Scalefactor spectral offset, interleaved */
-  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*BLOCK_LEN_LONG];                 /* Lengths of spectral bitstream elements */
-  int num_window_groups;                /* Number of window groups */
-  int window_group_length[MAX_SHORT_WINDOWS]; /* Length (in windows) of each window group */
-  int common_scalefac;                  /* Global gain */
-  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[MAX_SCFAC_BANDS];       /* Prediction enable flag for each scalefactor band */
-  int reset_group_number;               /* Prediction reset group number */
-  AACPulseInfo pulseInfo;
-  SR_INFO *sr_info;
-  TNS_INFO tnsInfo;
-  struct _LT_PRED_STATUS ltpInfo;
-  Ch_Info channelInfo;
-
-  int pns_sfb_nrg[MAX_SCFAC_BANDS];
-  int pns_sfb_flag[MAX_SCFAC_BANDS];
-  int profile;
-  int srate_idx;
-} AACQuantInfo;
-
-
-void quantize(AACQuantInfo *quantInfo,
-			  double *pow_spectrum,
-			  int quant[BLOCK_LEN_LONG]
-			  );
-void dequantize(AACQuantInfo *quantInfo,
-				double *p_spectrum,
-				int quant[BLOCK_LEN_LONG],
-				double requant[BLOCK_LEN_LONG],
-				double error_energy[MAX_SCFAC_BANDS]
-				);
-int count_bits_long(AACQuantInfo* quantInfo,
-					int quant[BLOCK_LEN_LONG]
-					);
-int count_bits(AACQuantInfo* quantInfo,
-			   double *pow_spectrum,
-			   int quant[BLOCK_LEN_LONG]);
-
-
-/*********************************************************/
-/* sort_for_grouping                                     */
-/*********************************************************/
-int sort_for_grouping(AACQuantInfo* quantInfo,        /* ptr to quantization information */
-		      int sfb_width_table[],          /* Widths of single window */
-		      double *p_spectrum[],           /* Spectral values, noninterleaved */
-		      double *SigMaskRatio,
-		      double *PsySigMaskRatio);
-
-/*********************************************************/
-/* tf_init_encode_spectrum_aac                           */
-/*********************************************************/
-void aacQuantizeInit(int quality);
-
-
-/*********************************************************/
-/* tf_encode_spectrum_aac                                */
-/*********************************************************/
-int aacQuantize(AACQuantInfo* quantInfo,      /* AAC quantization information */
-				double      *p_spectrum[MAX_TIME_CHANNELS],
-				double      *SigMaksRatio[MAX_TIME_CHANNELS],
-				double      allowed_dist[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-				double      energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-				enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS],
-				int         sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-				int         average_block_bits,
-				BsBitStream *fixed_stream,
-				double      *p_reconstructed_spectrum[MAX_TIME_CHANNELS]			   
-				);
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--- a/rateconv.c
+++ /dev/null
@@ -1,810 +1,0 @@
-/**********************************************************************
-audio sample rate converter
-
-$Id: rateconv.c,v 1.5 2000/10/04 19:45:33 menno Exp $
-
-Source file: rateconv.c
-
-Authors:
-NM    Nikolaus Meine, Uni Hannover (c/o Heiko Purnhagen)
-HP    Heiko Purnhagen, Uni Hannover <purnhage@tnt.uni-hannover.de>
-
-Changes:
-xx-jun-98   NM      resamp.c
-18-sep-98   HP      converted into module
-03-aug-99   NM      now even faster ...
-04-nov-99   NM/HP   double ratio, htaps1 /= 2
-11-nov-99   HP      improved RateConvInit() debuglevel
-**********************************************************************/
-
-/*
- * Sample-rate converter
- *
- * Realized in three steps:
- *
- * 1. Upsampling by factor two while doing appropriate lowpass-filtering.
- *    This is done by using an FFT-based convolution algorithm with a multi-tap
- *    Kaiser-windowed lowpass filter.
- *    If the cotoff-frequency is less than 0.5, only lowpass-filtering without
- *    the upsampling is done.
- * 2. Upsampling by factor 128 using a 15 tap Kaiser-windowed lowpass filter
- *    (alpha=12.5) and conventional convolution algorithm.
- *    Two values (the next neighbours) are computed for every sample needed.
- * 3. Linear interpolation between the two bounding values.
- *
- * Stereo and mono data is supported.
- * Up- and downsampling of any ratio is possible.
- * Input and output file format is Sun-audio.
- *
- * Written by N.Meine, 1998
- *
- */
-
-/* Multi channel data is interleaved: l0 r0 l1 r1 ... */
-/* Total number of samples (over all channels) is used. */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-
-
-#include "aacenc.h"
-#include "rateconv.h"
-
-/* ---------- declarations ---------- */
-
-#ifndef min
-#define min(a,b) ((a) < (b) ? (a) : (b))
-#endif
-#ifndef min
-#define max(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-/* ---------- declarations (structures) ---------- */
-
-#define real	double	/* float seems to be precise enough, but it	*/
-			/* doesn't run much faster than double		*/
-
-typedef struct {
-	real	re,im;
-} complex;
-
-
-struct RCBufStruct		/* buffer handle */
-{
-  int numChannel;		/* number of channels */
-  long currentSampleIn;		/* number of input samples */
-  long currentSampleOut;	/* number of output samples */
-
-  real *wtab;
-  complex *x;
-  real *tp1;
-  real *tp2;
-  complex *ibuf;
-
-  long nfn;
-  long adv;
-  long istart;
-  long numode;
-  long fm;
-  double p1;
-  double d1;
-
-  long outSize;
-  float *out;
-};
-
-
-/* ---------- variables ---------- */
-
-int RCdebugLevel = 0;	/* debug level */
-
-
-#define deftaps1	485
-
-#define ov2exp	7		/* Oversampling exponent in the second step */
-#define ov2fac	(1<<ov2exp)	/* Oversampling factor in the second step */
-#define htaps2	7		/* Num. taps of the 2nd filter: 2*htaps2+1 */
-#define alpha2	12.5		/* Kaiser-parameter for the second filter */
-#define cutoff2	0.97		/* cutoff-frequency for the second filter */
-
-#define cexp	(CACHE1-(sizeof(real)==4 ? 3 : 4 ))
-#define cache	(1<<cexp)
-
-#define pi	3.1415926535897932
-#define zpi	6.2831853071795965
-
-
-/* ---------- local functions ---------- */
-
-
-void mkeiwutab(real *st,long fn)
-{
-	register int	i,k;
-	register double	phi;
-
-	for (k=fn; k; k>>=1)
-	{
-		phi = zpi/((double) k);
-		for (i=0; i<k; i++) st[i]=(real) sin(phi*((double) i));
-		st+=k;
-	}
-}
-
-void r4fftstep(register real *x0,register long n,register real *t)
-{
-	register long		n4 = n/4;
-	register real		*x1 = x0+2*n4;
-	register real		*x2 = x1+2*n4;
-	register real		*x3 = x2+2*n4;
-	register real		*y;
-	register real		wr,wi,ar,ai,br,bi,cr,ci,dr,di,hr,hi;
-	register long		i;
-
-
-	if ( n>16 )
-	{
-		y=t+6*n4;
-		r4fftstep(x0,n4,y);
-		r4fftstep(x1,n4,y);
-		r4fftstep(x2,n4,y);
-		r4fftstep(x3,n4,y);
-	}
-	else
-	{
-		if ( n==8 )
-		{
-			for (y=x0; y<x0+16; y+=4)
-			{
-				ar=y[0]; ai=y[1];
-				br=y[2]; bi=y[3];
-				y[0]=ar+br;
-				y[1]=ai+bi;
-				y[2]=ar-br;
-				y[3]=ai-bi;
-			}
-		}
-		else
-		{
-			for (y=x0; y<x0+32; y+=8)
-			{
-				ar=y[0]; ai=y[1];
-				br=y[2]; bi=y[3];
-				cr=y[4]; ci=y[5];
-				dr=y[6]; di=y[7];
-				hr=ar+cr; wr=ar-cr; hi=ai+ci; wi=ai-ci;
-				ar=br+dr; cr=br-dr; ai=bi+di; ci=bi-di;
-				y[0]=hr+ar; y[1]=hi+ai;
-				y[2]=wr+ci; y[3]=wi-cr;
-				y[4]=hr-ar; y[5]=hi-ai;
-				y[6]=wr-ci; y[7]=wi+cr;
-			}
-		}
-	}
-
-	y=t+n4;
-	for (i=0; i<n4; i++)
-	{
-		ar=x0[0]; ai=x0[1];
-		wr=y[  i]; wi=t[  i]; hr=x1[0]; hi=x1[1]; br=wr*hr+wi*hi; bi=wr*hi-wi*hr;
-		wr=y[2*i]; wi=t[2*i]; hr=x2[0]; hi=x2[1]; cr=wr*hr+wi*hi; ci=wr*hi-wi*hr;
-		wr=y[3*i]; wi=t[3*i]; hr=x3[0]; hi=x3[1]; dr=wr*hr+wi*hi; di=wr*hi-wi*hr;
-		hr=ar+cr; wr=ar-cr; hi=ai+ci; wi=ai-ci;
-		ar=br+dr; cr=br-dr; ai=bi+di; ci=bi-di;
-		x0[0]=hr+ar; x0[1]=hi+ai;
-		x1[0]=wr+ci; x1[1]=wi-cr;
-		x2[0]=hr-ar; x2[1]=hi-ai;
-		x3[0]=wr-ci; x3[1]=wi+cr;
-		x0+=2; x1+=2; x2+=2; x3+=2;
-	}
-}
-
-
-void r4ifftstep(register real *x0,register long n,register real *t)
-{
-	register long		n4 = n/4;
-	register real		*x1 = x0+2*n4;
-	register real		*x2 = x1+2*n4;
-	register real		*x3 = x2+2*n4;
-	register real		*y;
-	register real		wr,wi,ar,ai,br,bi,cr,ci,dr,di,hr,hi;
-	register long		i;
-
-	if ( n>16 )
-	{
-		y=t+6*n4;
-		r4ifftstep(x0,n4,y);
-		r4ifftstep(x1,n4,y);
-		r4ifftstep(x2,n4,y);
-		r4ifftstep(x3,n4,y);
-	}
-	else
-	{
-		if ( n==8 )
-		{
-			for (y=x0; y<x0+16; y+=4)
-			{
-				ar=y[0]; ai=y[1];
-				br=y[2]; bi=y[3];
-				y[0]=ar+br;
-				y[1]=ai+bi;
-				y[2]=ar-br;
-				y[3]=ai-bi;
-			}
-		}
-		else
-		{
-			for (y=x0; y<x0+32; y+=8)
-			{
-				ar=y[0]; ai=y[1];
-				br=y[2]; bi=y[3];
-				cr=y[4]; ci=y[5];
-				dr=y[6]; di=y[7];
-				hr=ar+cr; wr=ar-cr; hi=ai+ci; wi=ai-ci;
-				ar=br+dr; cr=br-dr; ai=bi+di; ci=bi-di;
-				y[0]=hr+ar; y[1]=hi+ai;
-				y[2]=wr-ci; y[3]=wi+cr;
-				y[4]=hr-ar; y[5]=hi-ai;
-				y[6]=wr+ci; y[7]=wi-cr;
-			}
-		}
-	}
-
-	y=t+n4;
-	for (i=0; i<n4; i++)
-	{
-		ar=x0[0]; ai=x0[1];
-		wr=y[  i]; wi=t[  i]; hr=x1[0]; hi=x1[1]; br=wr*hr-wi*hi; bi=wr*hi+wi*hr;
-		wr=y[2*i]; wi=t[2*i]; hr=x2[0]; hi=x2[1]; cr=wr*hr-wi*hi; ci=wr*hi+wi*hr;
-		wr=y[3*i]; wi=t[3*i]; hr=x3[0]; hi=x3[1]; dr=wr*hr-wi*hi; di=wr*hi+wi*hr;
-		hr=ar+cr; wr=ar-cr; hi=ai+ci; wi=ai-ci;
-		ar=br+dr; cr=br-dr; ai=bi+di; ci=bi-di;
-		x0[0]=hr+ar; x0[1]=hi+ai;
-		x1[0]=wr-ci; x1[1]=wi+cr;
-		x2[0]=hr-ar; x2[1]=hi-ai;
-		x3[0]=wr+ci; x3[1]=wi-cr;
-		x0+=2; x1+=2; x2+=2; x3+=2;
-	}
-}
-
-
-void perm4(real *x,long p)
-{
-	register real	a,b,c,d;
-	register long	i,j,k,l;
-
-	l=1<<(p-1);
-	for (i=j=0; i<(2<<p); i+=2)
-	{
-		if ( j>i )
-		{
-			a=x[i]; b=x[i+1]; c=x[j]; d=x[j+1]; x[j]=a; x[j+1]=b; x[i]=c; x[i+1]=d;	
-		}
-		j+=l;
-		for (k=l<<2; j&k; k>>=2) j=(j^=k)+(k>>4);
-	}
-}
-
-void perm42(real *x,long p)
-{
-	register real	*y,*z;
-	register long	i,n;
-
-	n=1<<p;
-	perm4(x  ,p-1);
-	perm4(x+n,p-1);
-
-	y=x+2*n;
-	z=x+n;
-	for (i=0; i<n; i+=2)
-	{
-		y[2*i  ]=x[i  ];
-		y[2*i+1]=x[i+1];
-		y[2*i+2]=z[i  ];
-		y[2*i+3]=z[i+1];
-		x[i  ]=y[i  ];
-		x[i+1]=y[i+1];
-	}
-	for (; i<2*n; i+=2)
-	{
-		x[i  ]=y[i  ];
-		x[i+1]=y[i+1];
-	}
-}
-
-void r4fft(real *t,real *x,long p)
-{
-	register long	n  = 1<<p;
-
-	if ( p&1 ) perm42(x,p); else perm4(x,p);
-	r4fftstep(x,n,t);
-}
-
-void r4ifft(real *t,real *x,long p)
-{
-	register long	n  = 1<<p;
-
-	if ( p&1 ) perm42(x,p); else perm4(x,p);
-	r4ifftstep(x,n,t);
-}
-
-
-double bessel(double x)
-{
-  register double	p,s,ds,k;
-
-  x*=0.5;
-  k=0.0;
-  p=s=1.0;
-  do
-    {
-      k+=1.0;
-      p*=x/k;
-      ds=p*p;
-      s+=ds;
-    }
-  while ( ds>1.0e-17*s ); 
-
-  return s;
-}
-
-void mktp1(complex *y,double fg,double a,long fn,long htaps1)
-{
-  register long	i;
-  register double	f,g,x,px;
-
-  y[0].re=fg;
-  y[0].im=0.0;
-
-  f=1.0/bessel(a);
-  g=1.0/(htaps1+0.5);
-  g*=g;
-
-  for (i=1; i<=htaps1; i++)
-    {
-      x=(double) i;
-      px=pi*x;
-      y[i].re=(real) f*bessel(a*sqrt(1.0-g*x*x))*sin(fg*px)/px;
-      y[i].im=(real) 0.0;
-      y[fn-i]=y[i];
-    }
-  for (; i<fn-htaps1; i++) y[i].re=y[i].im=0.0;
-}
-
-void mktp2(real *y,double fg,double a)
-{
-  register long	i;
-  register double	f,g,x,px;
-
-  y[0]=fg;
-
-  f=1.0/bessel(a);
-  g=1.0/(((double) ((htaps2+1)*ov2fac))-0.5);
-  g*=g;
-
-  for (i=1; i<(htaps2+1)*ov2fac; i++)
-    {
-      x=(double) i;
-      px=(pi/ov2fac)*x;
-      y[i]=(real) f*bessel(a*sqrt(1.0-g*x*x))*sin(fg*px)/px;
-    }
-  for (; i<(htaps2+2)*ov2fac; i++) y[i]=0.0;
-}
-
-void ctp2_m(real *x,double p,real *k,float **out)
-{
-  register long	n,i,j;
-  register double	h,l,r;
-  register real	*ka,*kb;
-  register real	*xa,*xb;
-
-  h=ov2fac*p;
-  i=(long) h;
-  h-=(double) i;
-
-  j=i&(ov2fac-1); i>>=ov2exp;
-
-  l=r=0.0;
-  ka=k+j;	kb=k+ov2fac-j;
-  i<<=1;
-  xa=x+i;	xb=x+i+2;
-
-  n=htaps2+1;
-  do
-    {
-      l+=xa[0]*ka[ 0] + xb[0]*kb[ 0];
-      r+=xa[0]*ka[ 1] + xb[0]*kb[-1];
-
-      ka+=ov2fac;
-      kb+=ov2fac;
-      xa-=2;
-      xb+=2;
-    }
-  while (--n);
-
-  *(*out)++ = (float) (l+h*(r-l));
-}
-
-void ctp2_s(complex *x,double p,real *k,float **out)
-{
-  register long	n,i,j;
-  register double	h,l0,l1,r0,r1;
-  register real	*ka,*kb;
-  register complex *xa,*xb;
-
-  h=ov2fac*p;
-  i=(long) h;
-  h-=(double) i;
-
-  j=i&(ov2fac-1); i>>=ov2exp;
-
-  l0=l1=r0=r1=0.0;
-  ka=k+j;	kb=k+ov2fac-j;
-  xa=x+i;	xb=x+i+1;
-
-  n=htaps2+1;
-  do
-    {
-      l0+=xa[0].re*ka[ 0] + xb[0].re*kb[ 0];
-      l1+=xa[0].im*ka[ 0] + xb[0].im*kb[ 0];
-      r0+=xa[0].re*ka[ 1] + xb[0].re*kb[-1];
-      r1+=xa[0].im*ka[ 1] + xb[0].im*kb[-1];
-
-      ka+=ov2fac;
-      kb+=ov2fac;
-      xa--;
-      xb++;
-    }
-  while (--n);
-
-  *(*out)++ = (float) (l0+h*(r0-l0));
-  *(*out)++ = (float) (l1+h*(r1-l1));
-}
-
-void ctp1_1(complex *x,real *tp1,real *wtab,long fm)
-{
-  register long	i,fn2;
-
-  fn2=1<<(fm-1);
-  r4fft(wtab,(real *) x,fm);
-  for (i=0; i<fn2; i++)
-    {
-      x[i+fn2].re*=tp1[fn2-i];
-      x[i+fn2].im*=tp1[fn2-i];
-      x[i    ].re*=tp1[i    ];
-      x[i    ].im*=tp1[i    ];
-    }
-  r4ifft(wtab,(real *) x,fm);
-}
-
-void ctp1_2(complex *x,real *tp1,real *wtab,long fm)
-{
-  register long	i,fn2;
-
-  fn2=1<<(fm-1);
-
-  r4fft(wtab+(1<<fm),(real *) x,fm-1);
-  for (i=0; i<fn2; i++)
-    {
-      x[i+fn2].re=x[i].re*tp1[fn2-i];
-      x[i+fn2].im=x[i].im*tp1[fn2-i];
-      x[i].re*=tp1[i];
-      x[i].im*=tp1[i];
-    }
-  r4ifft(wtab,(real *) x,fm);
-}
-
-
-/* ---------- functions ---------- */
-
-/* RateConvInit() */
-/* Init audio sample rate conversion. */
-
-RCBuf *RateConvInit (
-  int debugLevel,		/* in: debug level */
-				/*     0=off  1=basic  2=full */
-  double ratio,			/* in: outputRate / inputRate */
-  int numChannel,		/* in: number of channels */
-  int htaps1,			/* in: num taps */
-				/*      -1 = auto */
-  float a1,			/* in: alpha for Kaiser window */
-				/*      -1 = auto */
-  float fc,			/* in: 6dB cutoff freq / input bandwidth */
-				/*      -1 = auto */
-  float fd,			/* in: 100dB cutoff freq / input bandwidth */
-				/*      -1 = auto */
-  int *numSampleIn)		/* out: num input samples / frame */
-				/* returns: */
-				/*  buffer (handle) */
-				/*  or NULL if error */
-{
-  real *wtab;
-  complex *x;
-  real *tp1;
-  real *tp2;
-  complex *ibuf;
-
-  long nfn;
-  long adv;
-  long istart;
-  long numode;
-  long fm;
-  double p1;
-  double d1;
-
-  double sf2;
-  double trw2;
-  long fn;
-  long fn2;
-  long i;
-  double h;
-  double a;
-
-  RCBuf *buf;
-
-  RCdebugLevel = debugLevel;
-  if (RCdebugLevel)
-    printf("RateConvInit: debugLevel=%d ratio=%f numChannel=%d\n"
-	   "htaps1=%d a1=%f fc=%f fd=%f\n",
-	   RCdebugLevel,ratio,numChannel,htaps1,a1,fc,fd);
-
-  buf=(RCBuf*)malloc(sizeof(RCBuf));
-//  if (!(buf=(RCBuf*)malloc(sizeof(RCBuf))))
-//    CommonExit(-1,"RateConvInit: Can not allocate memory");
-  buf->currentSampleIn = 0;
-  buf->currentSampleOut = 0;
-  buf->numChannel = numChannel;
-
-  if (htaps1<0)
-    htaps1 = deftaps1;
-  htaps1 /= 2;	/* NM 991104 */
-  if (a1<0)
-    a1 = 10.0;
-  numode = 0;
-  for (fm=2; (1<<fm)<8*htaps1; fm+=2);
-  fn=1<<fm;
-  fn2=fn/2;
-
-  wtab=(real *) malloc((4*fn + fn2+1 + (htaps2+2)*ov2fac)*sizeof(real));
-//  if (!(wtab=
-//	(real *) malloc((4*fn + fn2+1 + (htaps2+2)*ov2fac)*sizeof(real))))
-//    CommonExit(-1,"RateConvInit: Can not allocate memory");
-  x=((complex *) wtab)+fn;
-  tp1=(real *) (x+fn);
-  tp2=tp1+fn2+1;
-
-  mkeiwutab(wtab,fn);
-  mktp1(x,0.5,a1,fn,htaps1);
-  r4fft(wtab,(real *) x,fm);
-  h=x[0].re*x[0].re*1.0e-10;
-  for (i=fn/2; x[i].re*x[i].re<h; i--);
-  trw2=((double) (i-(fn2/2)))/((double) (fn2/2));
-
-  sf2 = ratio;
-  if ( sf2<0.0 ) sf2=1.0;
-
-  d1=1.0/sf2;
-  p1=htaps1+htaps2+2;		/* delay compensation */
-
-  if ( fc<0.0 )
-    {
-      if ( fd<0.0 )
-	{
-	  fc=(float)(1.0/d1-trw2);
-	  if ( fc<0.5-0.5*trw2 ) { numode=1; fc=(float)(2.0/d1-trw2); }
-	  if ( fc>1.0-trw2 ) fc=(float)(1.0-trw2);
-	}
-      else
-	{
-	  fc=(float)(fd-trw2);
-	  if ( fd<=0.5 ) { numode=1; fc=(float)(2.0*fd-trw2); }
-	}
-    }
-  else
-    {
-      if ( fc<0.5-trw2 ) { numode=1; fc+=fc; }
-    }
-
-  if ( fc>2.0 ) fc=2.0;
-
-  if ( fc<=0.0 ) {
-//    CommonWarning("RateConvInit: cutoff frequency to low: %f %f %f\n",
-//		  fc,fd,trw2);
-    free(wtab);
-    free(buf);
-    return NULL;
-  }
-
-  nfn=fn;
-  adv=fn-2*(htaps1+htaps2+2);
-  istart=htaps1+htaps2+2;
-  if ( !numode ) { nfn>>=1; adv>>=1; d1+=d1; }
-
-  mktp1(x,0.5*fc,a1,fn,htaps1);
-  r4fft(wtab,(real *) x,fm);
-  a=1.0/((double) (((1+numode)*fn2)));
-  for (i=0; i<=fn2 ; i++) tp1[i]=a*x[i].re;
-
-  mktp2(tp2,cutoff2,alpha2);
-
-  *numSampleIn = (int) 2*adv;
-  buf->outSize = (long)((2*adv+4)*ratio+4);
-  buf->out=(float*)malloc(buf->outSize*sizeof(float));
-//  if (!(buf->out=(float*)malloc(buf->outSize*sizeof(float))))
-//    CommonExit(-1,"RateConvInit: Can not allocate memory");
-
-  ibuf = (complex *) malloc((nfn-adv)*sizeof(complex));
-//  if (!(ibuf = (complex *) malloc((nfn-adv)*sizeof(complex))))
-//    CommonExit(-1,"RateConvInit: Can not allocate memory");
-
-
-  if ( buf->numChannel==1 ) {
-    /* ibuf[?].im not used ... */
-    for (i=0; i<(nfn-adv)/2; i++)
-      ibuf[i].re=0.0;
-    for (   ; i<(nfn-adv)  ; i++)
-      ibuf[i].re=0.0;
-    /* ibuf[i].re=(real) dataIn[idxIn++]; */
-  }
-  else {
-    for (i=0; i<  (nfn-adv); i++)
-      ((real *) ibuf)[i]=0.0;
-    for (   ; i<2*(nfn-adv); i++)
-      ((real *) ibuf)[i]=0.0;
-    /* ((real *) ibuf)[i]=(real) dataIn[idxIn++]; */
-  }
-
-  if (RCdebugLevel)
-    printf("RateConvInit: inSize=%ld outSize=%ld\n"
-	   "  output/input ratio : %8.2f\n"
-	   "  cutoff frequency   : %10.4f\n"
-	   "  Kaiser parameter   : %10.4f\n"
-	   "  filter 1 taps      : %5li\n"
-	   "  filter 1 transition: %10.4f\n"
-	   "  FFT length         : %5li\n"
-	   "  oversampling factor: %5li\n",
-	   2*adv,buf->outSize,
-	   sf2,fc/(1+numode),a1,(long)2*htaps1+1,0.5*trw2,
-	   fn,ov2fac*(2-numode));
-
-  buf->wtab = wtab;
-  buf->x= x;
-  buf->tp1 = tp1;
-  buf->tp2 = tp2;
-  buf->ibuf = ibuf;
-
-  buf->nfn = nfn;
-  buf->adv = adv;
-  buf->istart = istart;
-  buf->numode = numode;
-  buf->fm = fm;
-  buf->p1 = p1;
-  buf->d1 = d1;
-
-  return buf;
-}
-
-
-/* RateConv() */
-/* Convert sample rate for one frame of audio data. */
-
-long RateConv (
-  RCBuf *buf,			/* in: buffer (handle) */
-  short *dataIn,		/* in: input data[] */
-  long numSampleIn,		/* in: number of input samples */
-  float **dataOut)		/* out: output data[] */
-				/* returns: */
-				/*  numSampleOut */
-{
-  real *wtab = buf->wtab;
-  complex *x = buf->x;
-  real *tp1 = buf->tp1;
-  real *tp2 = buf->tp2;
-  complex *ibuf = buf->ibuf;
-
-  long nfn = buf->nfn;
-  long adv = buf->adv;
-  long istart = buf->istart;
-  long numode = buf->numode;
-  long fm = buf->fm;
-  double p1 = buf->p1;
-  double d1 = buf->d1;
-
-  long i;
-  double p,h;
-
-  long idxIn,numOut;
-  float *out;
-
-  if (RCdebugLevel)
-    printf("RateConv: numSampleIn=%ld\n",numSampleIn);
-
-//  if (numSampleIn != 2*adv)
-//    CommonExit(-1,"RateConv: wrong numSampleIn");
-
-  idxIn = 0;
-  out = buf->out;
-
-  if ( buf->numChannel==1 ) {
-    /* ibuf[?].im not used ... */
-    for (i=0      ; i<nfn-adv; i++)
-      x[i].re=ibuf[i].re;
-    for (         ; i<    adv; i++)
-      x[i].re=(real) dataIn[idxIn++];
-    for (         ; i<    nfn; i++)
-      x[i].re=x[i-adv].im=(real) dataIn[idxIn++];
-    for (i=nfn-adv; i<    adv; i++)
-      x[i].im=(real) dataIn[idxIn++];
-    for (         ; i<    nfn; i++)
-      x[i].im=ibuf[i-adv].re=(real) dataIn[idxIn++];
-      
-    if ( numode )
-      ctp1_1(x,tp1,wtab,fm);
-    else
-      ctp1_2(x,tp1,wtab,fm);
-      
-    i=adv;
-    h=(double) ((2*i)>>numode);
-    for (p=p1; p<h; p+=d1) ctp2_m(&(x[istart].re),p,tp2,&out);
-    p1=p-h;
-      
-    i=adv;
-    h=(double) ((2*i)>>numode);
-    for (p=p1; p<h; p+=d1) ctp2_m(&(x[istart].im),p,tp2,&out);
-    p1=p-h;
-  }
-  else {
-    for (i=0; i<nfn-adv; i++)
-      x[i]=ibuf[i];
-    for (; i<adv; i++) {
-      x[i].re=(real) dataIn[idxIn++];
-      x[i].im=(real) dataIn[idxIn++];
-    }
-    for (; i<nfn; i++) {
-      x[i].re=ibuf[i-adv].re=(real) dataIn[idxIn++];
-      x[i].im=ibuf[i-adv].im=(real) dataIn[idxIn++];
-    }
-      
-    if ( numode )
-      ctp1_1(x,tp1,wtab,fm);
-    else
-      ctp1_2(x,tp1,wtab,fm);
-      
-    i=2*adv;
-    h=(double) (i>>numode);
-    for (p=p1; p<h; p+=d1) ctp2_s(x+istart,p,tp2,&out);
-    p1=p-h;
-  }
-
-  buf->p1 = p1;
-
-  *dataOut = buf->out;
-  numOut = out - buf->out;
-//  if (numOut > buf->outSize)
-//    CommonExit(-1,"RateConv: output buffer size troubles");
-  buf->currentSampleIn += 2*adv;
-  buf->currentSampleOut += numOut;
-  
-  return numOut;
-}
-
-
-/* RateConvFree() */
-/* Free RateConv buffers. */
-
-void RateConvFree (
-  RCBuf *buf)			/* in: buffer (handle) */
-{
-  if (RCdebugLevel)
-    printf("RateConvFree: sampleIn=%ld sampleOut=%ld\n",
-	   buf->currentSampleIn,buf->currentSampleOut);
-  free(buf->out);
-  free(buf->wtab);
-  free(buf->ibuf);
-  free(buf);
-}
-
-
-/* end of rateconv.c */
-
--- a/rateconv.h
+++ /dev/null
@@ -1,107 +1,0 @@
-/**********************************************************************
-audio sample rate converter
-
-$Id: rateconv.h,v 1.2 2000/02/18 09:17:28 lenox Exp $
-
-Header file: rateconv.h
-
-Authors:
-NM    Nikolaus Meine, Uni Hannover (c/o Heiko Purnhagen)
-HP    Heiko Purnhagen, Uni Hannover <purnhage@tnt.uni-hannover.de>
-
-Changes:
-xx-jun-98   NM      resamp.c
-18-sep-98   HP      converted into module
-04-nov-99   NM/HP   double ratio
-**********************************************************************/
-
-/*
- * Sample-rate converter
- *
- * Realized in three steps:
- *
- * 1. Upsampling by factor two while doing appropriate lowpass-filtering.
- *    This is done by using an FFT-based convolution algorithm with a multi-tap
- *    Kaiser-windowed lowpass filter.
- *    If the cotoff-frequency is less than 0.5, only lowpass-filtering without
- *    the upsampling is done.
- * 2. Upsampling by factor 128 using a 15 tap Kaiser-windowed lowpass filter
- *    (alpha=12.5) and conventional convolution algorithm.
- *    Two values (the next neighbours) are computed for every sample needed.
- * 3. Linear interpolation between the two bounding values.
- *
- * Stereo and mono data is supported.
- * Up- and downsampling of any ratio is possible.
- * Input and output file format is Sun-audio.
- *
- * Written by N.Meine, 1998
- *
- */
-
-/* Multi channel data is interleaved: l0 r0 l1 r1 ... */
-/* Total number of samples (over all channels) is used. */
-
-
-#ifndef _rateconv_h_
-#define _rateconv_h_
-
-
-/* ---------- declarations ---------- */
-
-
-
-/* ---------- functions ---------- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* RateConvInit() */
-/* Init audio sample rate conversion. */
-
-RCBuf *RateConvInit (
-  int debugLevel,		/* in: debug level */
-				/*     0=off  1=basic  2=full */
-  double ratio,			/* in: outputRate / inputRate */
-  int numChannel,		/* in: number of channels */
-  int htaps1,			/* in: num taps */
-				/*      -1 = auto */
-  float a1,			/* in: alpha for Kaiser window */
-				/*      -1 = auto */
-  float fc,			/* in: 6dB cutoff freq / input bandwidth */
-				/*      -1 = auto */
-  float fd,			/* in: 100dB cutoff freq / input bandwidth */
-				/*      -1 = auto */
-  int *numSampleIn);		/* out: num input samples / frame */
-				/* returns: */
-				/*  buffer (handle) */
-				/*  or NULL if error */
-
-
-/* RateConv() */
-/* Convert sample rate for one frame of audio data. */
-
-long RateConv (
-  RCBuf *buf,			/* in: buffer (handle) */
-  short *dataIn,		/* in: input data[] */
-  long numSampleIn,		/* in: number of input samples */
-  float **dataOut);		/* out: output data[] */
-				/* returns: */
-				/*  numSampleOut */
-
-
-/* RateConvFree() */
-/* Free RateConv buffers. */
-
-void RateConvFree (
-  RCBuf *buf);			/* in: buffer (handle) */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif	/* #ifndef _rateconv_h_ */
-
-/* end of rateconv.h */
--- a/shape_win.h
+++ /dev/null
@@ -1,1195 +1,0 @@
-/*
- *	Window functions
- *
- *	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.2 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _SHAPE_WIN_H_
-#define _SHAPE_WIN_H_
-
-double sin_window_long[BLOCK_LEN_LONG];
-double sin_window_short[BLOCK_LEN_SHORT];
-
-double kbd_window_long[1024] = {
-  0.00029256153896361,
-  0.00042998567353047,
-  0.00054674074589540,
-  0.00065482304299792,
-  0.00075870195068747,
-  0.00086059331713336,
-  0.00096177541439010,
-  0.0010630609410878,
-  0.0011650036308132,
-  0.0012680012194148,
-  0.0013723517232956,
-  0.0014782864109136,
-  0.0015859901976719,
-  0.0016956148252373,
-  0.0018072876903517,
-  0.0019211179405514,
-  0.0020372007924215,
-  0.0021556206591754,
-  0.0022764534599614,
-  0.0023997683540995,
-  0.0025256290631156,
-  0.0026540948920831,
-  0.0027852215281403,
-  0.0029190616715331,
-  0.0030556655443223,
-  0.0031950812943391,
-  0.0033373553240392,
-  0.0034825325586930,
-  0.0036306566699199,
-  0.0037817702604646,
-  0.0039359150179719,
-  0.0040931318437260,
-  0.0042534609610026,
-  0.0044169420066964,
-  0.0045836141091341,
-  0.0047535159544086,
-  0.0049266858431214,
-  0.0051031617390698,
-  0.0052829813111335,
-  0.0054661819693975,
-  0.0056528008963682,
-  0.0058428750739943,
-  0.0060364413070882,
-  0.0062335362436492,
-  0.0064341963925079,
-  0.0066384581386503,
-  0.0068463577565218,
-  0.0070579314215715,
-  0.0072732152202559,
-  0.0074922451586909,
-  0.0077150571701162,
-  0.0079416871213115,
-  0.0081721708180857,
-  0.0084065440099458,
-  0.0086448423940363,
-  0.0088871016184291,
-  0.0091333572848345,
-  0.0093836449507939,
-  0.0096380001314086,
-  0.0098964583006517,
-  0.010159054892306,
-  0.010425825300561,
-  0.010696804880310,
-  0.010972028947167,
-  0.011251532777236,
-  0.011535351606646,
-  0.011823520630897,
-  0.012116075003993,
-  0.012413049837429,
-  0.012714480198999,
-  0.013020401111478,
-  0.013330847551161,
-  0.013645854446288,
-  0.013965456675352,
-  0.014289689065314,
-  0.014618586389712,
-  0.014952183366697,
-  0.015290514656976,
-  0.015633614861688,
-  0.015981518520214,
-  0.016334260107915,
-  0.016691874033817,
-  0.017054394638241,
-  0.017421856190380,
-  0.017794292885832,
-  0.018171738844085,
-  0.018554228105962,
-  0.018941794631032,
-  0.019334472294980,
-  0.019732294886947,
-  0.020135296106839,
-  0.020543509562604,
-  0.020956968767488,
-  0.021375707137257,
-  0.021799757987407,
-  0.022229154530343,
-  0.022663929872540,
-  0.023104117011689,
-  0.023549748833816,
-  0.024000858110398,
-  0.024457477495451,
-  0.024919639522613,
-  0.025387376602207,
-  0.025860721018295,
-  0.026339704925726,
-  0.026824360347160,
-  0.027314719170100,
-  0.027810813143900,
-  0.028312673876775,
-  0.028820332832801,
-  0.029333821328905,
-  0.029853170531859,
-  0.030378411455255,
-  0.030909574956490,
-  0.031446691733739,
-  0.031989792322926,
-  0.032538907094693,
-  0.033094066251369,
-  0.033655299823935,
-  0.034222637668991,
-  0.034796109465717,
-  0.035375744712844,
-  0.035961572725616,
-  0.036553622632758,
-  0.037151923373446,
-  0.037756503694277,
-  0.038367392146243,
-  0.038984617081711,
-  0.039608206651398,
-  0.040238188801359,
-  0.040874591269976,
-  0.041517441584950,
-  0.042166767060301,
-  0.042822594793376,
-  0.043484951661852,
-  0.044153864320760,
-  0.044829359199509,
-  0.045511462498913,
-  0.046200200188234,
-  0.046895598002228,
-  0.047597681438201,
-  0.048306475753074,
-  0.049022005960455,
-  0.049744296827725,
-  0.050473372873129,
-  0.051209258362879,
-  0.051951977308273,
-  0.052701553462813,
-  0.053458010319350,
-  0.054221371107223,
-  0.054991658789428,
-  0.055768896059787,
-  0.056553105340134,
-  0.057344308777513,
-  0.058142528241393,
-  0.058947785320893,
-  0.059760101322019,
-  0.060579497264926,
-  0.061405993881180,
-  0.062239611611049,
-  0.063080370600799,
-  0.063928290700012,
-  0.064783391458919,
-  0.065645692125747,
-  0.066515211644086,
-  0.067391968650269,
-  0.068275981470777,
-  0.069167268119652,
-  0.070065846295935,
-  0.070971733381121,
-  0.071884946436630,
-  0.072805502201299,
-  0.073733417088896,
-  0.074668707185649,
-  0.075611388247794,
-  0.076561475699152,
-  0.077518984628715,
-  0.078483929788261,
-  0.079456325589986,
-  0.080436186104162,
-  0.081423525056808,
-  0.082418355827392,
-  0.083420691446553,
-  0.084430544593841,
-  0.085447927595483,
-  0.086472852422178,
-  0.087505330686900,
-  0.088545373642744,
-  0.089592992180780,
-  0.090648196827937,
-  0.091710997744919,
-  0.092781404724131,
-  0.093859427187640,
-  0.094945074185163,
-  0.096038354392069,
-  0.097139276107423,
-  0.098247847252041,
-  0.099364075366580,
-  0.10048796760965,
-  0.10161953075597,
-  0.10275877119451,
-  0.10390569492671,
-  0.10506030756469,
-  0.10622261432949,
-  0.10739262004941,
-  0.10857032915821,
-  0.10975574569357,
-  0.11094887329534,
-  0.11214971520402,
-  0.11335827425914,
-  0.11457455289772,
-  0.11579855315274,
-  0.11703027665170,
-  0.11826972461510,
-  0.11951689785504,
-  0.12077179677383,
-  0.12203442136263,
-  0.12330477120008,
-  0.12458284545102,
-  0.12586864286523,
-  0.12716216177615,
-  0.12846340009971,
-  0.12977235533312,
-  0.13108902455375,
-  0.13241340441801,
-  0.13374549116025,
-  0.13508528059173,
-  0.13643276809961,
-  0.13778794864595,
-  0.13915081676677,
-  0.14052136657114,
-  0.14189959174027,
-  0.14328548552671,
-  0.14467904075349,
-  0.14608024981336,
-  0.14748910466804,
-  0.14890559684750,
-  0.15032971744929,
-  0.15176145713790,
-  0.15320080614414,
-  0.15464775426459,
-  0.15610229086100,
-  0.15756440485987,
-  0.15903408475193,
-  0.16051131859170,
-  0.16199609399712,
-  0.16348839814917,
-  0.16498821779156,
-  0.16649553923042,
-  0.16801034833404,
-  0.16953263053270,
-  0.17106237081842,
-  0.17259955374484,
-  0.17414416342714,
-  0.17569618354193,
-  0.17725559732720,
-  0.17882238758238,
-  0.18039653666830,
-  0.18197802650733,
-  0.18356683858343,
-  0.18516295394233,
-  0.18676635319174,
-  0.18837701650148,
-  0.18999492360384,
-  0.19162005379380,
-  0.19325238592940,
-  0.19489189843209,
-  0.19653856928714,
-  0.19819237604409,
-  0.19985329581721,
-  0.20152130528605,
-  0.20319638069594,
-  0.20487849785865,
-  0.20656763215298,
-  0.20826375852540,
-  0.20996685149083,
-  0.21167688513330,
-  0.21339383310678,
-  0.21511766863598,
-  0.21684836451719,
-  0.21858589311922,
-  0.22033022638425,
-  0.22208133582887,
-  0.22383919254503,
-  0.22560376720111,
-  0.22737503004300,
-  0.22915295089517,
-  0.23093749916189,
-  0.23272864382838,
-  0.23452635346201,
-  0.23633059621364,
-  0.23814133981883,
-  0.23995855159925,
-  0.24178219846403,
-  0.24361224691114,
-  0.24544866302890,
-  0.24729141249740,
-  0.24914046059007,
-  0.25099577217522,
-  0.25285731171763,
-  0.25472504328019,
-  0.25659893052556,
-  0.25847893671788,
-  0.26036502472451,
-  0.26225715701781,
-  0.26415529567692,
-  0.26605940238966,
-  0.26796943845439,
-  0.26988536478190,
-  0.27180714189742,
-  0.27373472994256,
-  0.27566808867736,
-  0.27760717748238,
-  0.27955195536071,
-  0.28150238094021,
-  0.28345841247557,
-  0.28542000785059,
-  0.28738712458038,
-  0.28935971981364,
-  0.29133775033492,
-  0.29332117256704,
-  0.29530994257338,
-  0.29730401606034,
-  0.29930334837974,
-  0.30130789453132,
-  0.30331760916521,
-  0.30533244658452,
-  0.30735236074785,
-  0.30937730527195,
-  0.31140723343430,
-  0.31344209817583,
-  0.31548185210356,
-  0.31752644749341,
-  0.31957583629288,
-  0.32162997012390,
-  0.32368880028565,
-  0.32575227775738,
-  0.32782035320134,
-  0.32989297696566,
-  0.33197009908736,
-  0.33405166929523,
-  0.33613763701295,
-  0.33822795136203,
-  0.34032256116495,
-  0.34242141494820,
-  0.34452446094547,
-  0.34663164710072,
-  0.34874292107143,
-  0.35085823023181,
-  0.35297752167598,
-  0.35510074222129,
-  0.35722783841160,
-  0.35935875652060,
-  0.36149344255514,
-  0.36363184225864,
-  0.36577390111444,
-  0.36791956434930,
-  0.37006877693676,
-  0.37222148360070,
-  0.37437762881878,
-  0.37653715682603,
-  0.37870001161834,
-  0.38086613695607,
-  0.38303547636766,
-  0.38520797315322,
-  0.38738357038821,
-  0.38956221092708,
-  0.39174383740701,
-  0.39392839225157,
-  0.39611581767449,
-  0.39830605568342,
-  0.40049904808370,
-  0.40269473648218,
-  0.40489306229101,
-  0.40709396673153,
-  0.40929739083810,
-  0.41150327546197,
-  0.41371156127524,
-  0.41592218877472,
-  0.41813509828594,
-  0.42035022996702,
-  0.42256752381274,
-  0.42478691965848,
-  0.42700835718423,
-  0.42923177591866,
-  0.43145711524314,
-  0.43368431439580,
-  0.43591331247564,
-  0.43814404844658,
-  0.44037646114161,
-  0.44261048926688,
-  0.44484607140589,
-  0.44708314602359,
-  0.44932165147057,
-  0.45156152598727,
-  0.45380270770813,
-  0.45604513466581,
-  0.45828874479543,
-  0.46053347593880,
-  0.46277926584861,
-  0.46502605219277,
-  0.46727377255861,
-  0.46952236445718,
-  0.47177176532752,
-  0.47402191254100,
-  0.47627274340557,
-  0.47852419517009,
-  0.48077620502869,
-  0.48302871012505,
-  0.48528164755674,
-  0.48753495437962,
-  0.48978856761212,
-  0.49204242423966,
-  0.49429646121898,
-  0.49655061548250,
-  0.49880482394273,
-  0.50105902349665,
-  0.50331315103004,
-  0.50556714342194,
-  0.50782093754901,
-  0.51007447028990,
-  0.51232767852971,
-  0.51458049916433,
-  0.51683286910489,
-  0.51908472528213,
-  0.52133600465083,
-  0.52358664419420,
-  0.52583658092832,
-  0.52808575190648,
-  0.53033409422367,
-  0.53258154502092,
-  0.53482804148974,
-  0.53707352087652,
-  0.53931792048690,
-  0.54156117769021,
-  0.54380322992385,
-  0.54604401469766,
-  0.54828346959835,
-  0.55052153229384,
-  0.55275814053768,
-  0.55499323217338,
-  0.55722674513883,
-  0.55945861747062,
-  0.56168878730842,
-  0.56391719289930,
-  0.56614377260214,
-  0.56836846489188,
-  0.57059120836390,
-  0.57281194173835,
-  0.57503060386439,
-  0.57724713372458,
-  0.57946147043912,
-  0.58167355327012,
-  0.58388332162591,
-  0.58609071506528,
-  0.58829567330173,
-  0.59049813620770,
-  0.59269804381879,
-  0.59489533633802,
-  0.59708995413996,
-  0.59928183777495,
-  0.60147092797329,
-  0.60365716564937,
-  0.60584049190582,
-  0.60802084803764,
-  0.61019817553632,
-  0.61237241609393,
-  0.61454351160718,
-  0.61671140418155,
-  0.61887603613527,
-  0.62103735000336,
-  0.62319528854167,
-  0.62534979473088,
-  0.62750081178042,
-  0.62964828313250,
-  0.63179215246597,
-  0.63393236370030,
-  0.63606886099946,
-  0.63820158877577,
-  0.64033049169379,
-  0.64245551467413,
-  0.64457660289729,
-  0.64669370180740,
-  0.64880675711607,
-  0.65091571480603,
-  0.65302052113494,
-  0.65512112263906,
-  0.65721746613689,
-  0.65930949873289,
-  0.66139716782102,
-  0.66348042108842,
-  0.66555920651892,
-  0.66763347239664,
-  0.66970316730947,
-  0.67176824015260,
-  0.67382864013196,
-  0.67588431676768,
-  0.67793521989751,
-  0.67998129968017,
-  0.68202250659876,
-  0.68405879146403,
-  0.68609010541774,
-  0.68811639993588,
-  0.69013762683195,
-  0.69215373826012,
-  0.69416468671849,
-  0.69617042505214,
-  0.69817090645634,
-  0.70016608447958,
-  0.70215591302664,
-  0.70414034636163,
-  0.70611933911096,
-  0.70809284626630,
-  0.71006082318751,
-  0.71202322560554,
-  0.71398000962530,
-  0.71593113172842,
-  0.71787654877613,
-  0.71981621801195,
-  0.72175009706445,
-  0.72367814394990,
-  0.72560031707496,
-  0.72751657523927,
-  0.72942687763803,
-  0.73133118386457,
-  0.73322945391280,
-  0.73512164817975,
-  0.73700772746796,
-  0.73888765298787,
-  0.74076138636020,
-  0.74262888961827,
-  0.74449012521027,
-  0.74634505600152,
-  0.74819364527663,
-  0.75003585674175,
-  0.75187165452661,
-  0.75370100318668,
-  0.75552386770515,
-  0.75734021349500,
-  0.75915000640095,
-  0.76095321270137,
-  0.76274979911019,
-  0.76453973277875,
-  0.76632298129757,
-  0.76809951269819,
-  0.76986929545481,
-  0.77163229848604,
-  0.77338849115651,
-  0.77513784327849,
-  0.77688032511340,
-  0.77861590737340,
-  0.78034456122283,
-  0.78206625827961,
-  0.78378097061667,
-  0.78548867076330,
-  0.78718933170643,
-  0.78888292689189,
-  0.79056943022564,
-  0.79224881607494,
-  0.79392105926949,
-  0.79558613510249,
-  0.79724401933170,
-  0.79889468818046,
-  0.80053811833858,
-  0.80217428696334,
-  0.80380317168028,
-  0.80542475058405,
-  0.80703900223920,
-  0.80864590568089,
-  0.81024544041560,
-  0.81183758642175,
-  0.81342232415032,
-  0.81499963452540,
-  0.81656949894467,
-  0.81813189927991,
-  0.81968681787738,
-  0.82123423755821,
-  0.82277414161874,
-  0.82430651383076,
-  0.82583133844180,
-  0.82734860017528,
-  0.82885828423070,
-  0.83036037628369,
-  0.83185486248609,
-  0.83334172946597,
-  0.83482096432759,
-  0.83629255465130,
-  0.83775648849344,
-  0.83921275438615,
-  0.84066134133716,
-  0.84210223882952,
-  0.84353543682130,
-  0.84496092574524,
-  0.84637869650833,
-  0.84778874049138,
-  0.84919104954855,
-  0.85058561600677,
-  0.85197243266520,
-  0.85335149279457,
-  0.85472279013653,
-  0.85608631890295,
-  0.85744207377513,
-  0.85879004990298,
-  0.86013024290422,
-  0.86146264886346,
-  0.86278726433124,
-  0.86410408632306,
-  0.86541311231838,
-  0.86671434025950,
-  0.86800776855046,
-  0.86929339605590,
-  0.87057122209981,
-  0.87184124646433,
-  0.87310346938840,
-  0.87435789156650,
-  0.87560451414719,
-  0.87684333873173,
-  0.87807436737261,
-  0.87929760257204,
-  0.88051304728038,
-  0.88172070489456,
-  0.88292057925645,
-  0.88411267465117,
-  0.88529699580537,
-  0.88647354788545,
-  0.88764233649580,
-  0.88880336767692,
-  0.88995664790351,
-  0.89110218408260,
-  0.89223998355154,
-  0.89337005407600,
-  0.89449240384793,
-  0.89560704148345,
-  0.89671397602074,
-  0.89781321691786,
-  0.89890477405053,
-  0.89998865770993,
-  0.90106487860034,
-  0.90213344783689,
-  0.90319437694315,
-  0.90424767784873,
-  0.90529336288690,
-  0.90633144479201,
-  0.90736193669708,
-  0.90838485213119,
-  0.90940020501694,
-  0.91040800966776,
-  0.91140828078533,
-  0.91240103345685,
-  0.91338628315231,
-  0.91436404572173,
-  0.91533433739238,
-  0.91629717476594,
-  0.91725257481564,
-  0.91820055488334,
-  0.91914113267664,
-  0.92007432626589,
-  0.92100015408120,
-  0.92191863490944,
-  0.92282978789113,
-  0.92373363251740,
-  0.92463018862687,
-  0.92551947640245,
-  0.92640151636824,
-  0.92727632938624,
-  0.92814393665320,
-  0.92900435969727,
-  0.92985762037477,
-  0.93070374086684,
-  0.93154274367610,
-  0.93237465162328,
-  0.93319948784382,
-  0.93401727578443,
-  0.93482803919967,
-  0.93563180214841,
-  0.93642858899043,
-  0.93721842438279,
-  0.93800133327637,
-  0.93877734091223,
-  0.93954647281807,
-  0.94030875480458,
-  0.94106421296182,
-  0.94181287365556,
-  0.94255476352362,
-  0.94328990947213,
-  0.94401833867184,
-  0.94474007855439,
-  0.94545515680855,
-  0.94616360137644,
-  0.94686544044975,
-  0.94756070246592,
-  0.94824941610434,
-  0.94893161028248,
-  0.94960731415209,
-  0.95027655709525,
-  0.95093936872056,
-  0.95159577885924,
-  0.95224581756115,
-  0.95288951509097,
-  0.95352690192417,
-  0.95415800874314,
-  0.95478286643320,
-  0.95540150607863,
-  0.95601395895871,
-  0.95662025654373,
-  0.95722043049100,
-  0.95781451264084,
-  0.95840253501260,
-  0.95898452980058,
-  0.95956052937008,
-  0.96013056625336,
-  0.96069467314557,
-  0.96125288290073,
-  0.96180522852773,
-  0.96235174318622,
-  0.96289246018262,
-  0.96342741296604,
-  0.96395663512424,
-  0.96448016037959,
-  0.96499802258499,
-  0.96551025571985,
-  0.96601689388602,
-  0.96651797130376,
-  0.96701352230768,
-  0.96750358134269,
-  0.96798818295998,
-  0.96846736181297,
-  0.96894115265327,
-  0.96940959032667,
-  0.96987270976912,
-  0.97033054600270,
-  0.97078313413161,
-  0.97123050933818,
-  0.97167270687887,
-  0.97210976208030,
-  0.97254171033525,
-  0.97296858709871,
-  0.97339042788392,
-  0.97380726825843,
-  0.97421914384017,
-  0.97462609029350,
-  0.97502814332534,
-  0.97542533868127,
-  0.97581771214160,
-  0.97620529951759,
-  0.97658813664749,
-  0.97696625939282,
-  0.97733970363445,
-  0.97770850526884,
-  0.97807270020427,
-  0.97843232435704,
-  0.97878741364771,
-  0.97913800399743,
-  0.97948413132414,
-  0.97982583153895,
-  0.98016314054243,
-  0.98049609422096,
-  0.98082472844313,
-  0.98114907905608,
-  0.98146918188197,
-  0.98178507271438,
-  0.98209678731477,
-  0.98240436140902,
-  0.98270783068385,
-  0.98300723078342,
-  0.98330259730589,
-  0.98359396579995,
-  0.98388137176152,
-  0.98416485063031,
-  0.98444443778651,
-  0.98472016854752,
-  0.98499207816463,
-  0.98526020181980,
-  0.98552457462240,
-  0.98578523160609,
-  0.98604220772560,
-  0.98629553785362,
-  0.98654525677772,
-  0.98679139919726,
-  0.98703399972035,
-  0.98727309286089,
-  0.98750871303556,
-  0.98774089456089,
-  0.98796967165036,
-  0.98819507841154,
-  0.98841714884323,
-  0.98863591683269,
-  0.98885141615285,
-  0.98906368045957,
-  0.98927274328896,
-  0.98947863805473,
-  0.98968139804554,
-  0.98988105642241,
-  0.99007764621618,
-  0.99027120032501,
-  0.99046175151186,
-  0.99064933240208,
-  0.99083397548099,
-  0.99101571309153,
-  0.99119457743191,
-  0.99137060055337,
-  0.99154381435784,
-  0.99171425059582,
-  0.99188194086414,
-  0.99204691660388,
-  0.99220920909823,
-  0.99236884947045,
-  0.99252586868186,
-  0.99268029752989,
-  0.99283216664606,
-  0.99298150649419,
-  0.99312834736847,
-  0.99327271939167,
-  0.99341465251338,
-  0.99355417650825,
-  0.99369132097430,
-  0.99382611533130,
-  0.99395858881910,
-  0.99408877049612,
-  0.99421668923778,
-  0.99434237373503,
-  0.99446585249289,
-  0.99458715382906,
-  0.99470630587254,
-  0.99482333656229,
-  0.99493827364600,
-  0.99505114467878,
-  0.99516197702200,
-  0.99527079784214,
-  0.99537763410962,
-  0.99548251259777,
-  0.99558545988178,
-  0.99568650233767,
-  0.99578566614138,
-  0.99588297726783,
-  0.99597846149005,
-  0.99607214437834,
-  0.99616405129947,
-  0.99625420741595,
-  0.99634263768527,
-  0.99642936685928,
-  0.99651441948352,
-  0.99659781989663,
-  0.99667959222978,
-  0.99675976040620,
-  0.99683834814063,
-  0.99691537893895,
-  0.99699087609774,
-  0.99706486270391,
-  0.99713736163442,
-  0.99720839555593,
-  0.99727798692461,
-  0.99734615798589,
-  0.99741293077431,
-  0.99747832711337,
-  0.99754236861541,
-  0.99760507668158,
-  0.99766647250181,
-  0.99772657705478,
-  0.99778541110799,
-  0.99784299521785,
-  0.99789934972976,
-  0.99795449477828,
-  0.99800845028730,
-  0.99806123597027,
-  0.99811287133042,
-  0.99816337566108,
-  0.99821276804596,
-  0.99826106735952,
-  0.99830829226732,
-  0.99835446122649,
-  0.99839959248609,
-  0.99844370408765,
-  0.99848681386566,
-  0.99852893944805,
-  0.99857009825685,
-  0.99861030750869,
-  0.99864958421549,
-  0.99868794518504,
-  0.99872540702178,
-  0.99876198612738,
-  0.99879769870160,
-  0.99883256074295,
-  0.99886658804953,
-  0.99889979621983,
-  0.99893220065356,
-  0.99896381655254,
-  0.99899465892154,
-  0.99902474256924,
-  0.99905408210916,
-  0.99908269196056,
-  0.99911058634952,
-  0.99913777930986,
-  0.99916428468421,
-  0.99919011612505,
-  0.99921528709576,
-  0.99923981087174,
-  0.99926370054150,
-  0.99928696900779,
-  0.99930962898876,
-  0.99933169301910,
-  0.99935317345126,
-  0.99937408245662,
-  0.99939443202674,
-  0.99941423397457,
-  0.99943349993572,
-  0.99945224136972,
-  0.99947046956130,
-  0.99948819562171,
-  0.99950543049000,
-  0.99952218493439,
-  0.99953846955355,
-  0.99955429477803,
-  0.99956967087154,
-  0.99958460793242,
-  0.99959911589494,
-  0.99961320453077,
-  0.99962688345035,
-  0.99964016210433,
-  0.99965304978499,
-  0.99966555562769,
-  0.99967768861231,
-  0.99968945756473,
-  0.99970087115825,
-  0.99971193791510,
-  0.99972266620792,
-  0.99973306426121,
-  0.99974314015288,
-  0.99975290181568,
-  0.99976235703876,
-  0.99977151346914,
-  0.99978037861326,
-  0.99978895983845,
-  0.99979726437448,
-  0.99980529931507,
-  0.99981307161943,
-  0.99982058811377,
-  0.99982785549283,
-  0.99983488032144,
-  0.99984166903600,
-  0.99984822794606,
-  0.99985456323584,
-  0.99986068096572,
-  0.99986658707386,
-  0.99987228737764,
-  0.99987778757524,
-  0.99988309324717,
-  0.99988820985777,
-  0.99989314275675,
-  0.99989789718072,
-  0.99990247825468,
-  0.99990689099357,
-  0.99991114030376,
-  0.99991523098456,
-  0.99991916772971,
-  0.99992295512891,
-  0.99992659766930,
-  0.99993009973692,
-  0.99993346561824,
-  0.99993669950161,
-  0.99993980547870,
-  0.99994278754604,
-  0.99994564960642,
-  0.99994839547033,
-  0.99995102885747,
-  0.99995355339809,
-  0.99995597263451,
-  0.99995829002249,
-  0.99996050893264,
-  0.99996263265183,
-  0.99996466438460,
-  0.99996660725452,
-  0.99996846430558,
-  0.99997023850356,
-  0.99997193273736,
-  0.99997354982037,
-  0.99997509249183,
-  0.99997656341810,
-  0.99997796519400,
-  0.99997930034415,
-  0.99998057132421,
-  0.99998178052220,
-  0.99998293025975,
-  0.99998402279338,
-  0.99998506031574,
-  0.99998604495686,
-  0.99998697878536,
-  0.99998786380966,
-  0.99998870197921,
-  0.99998949518567,
-  0.99999024526408,
-  0.99999095399401,
-  0.99999162310077,
-  0.99999225425649,
-  0.99999284908128,
-  0.99999340914435,
-  0.99999393596510,
-  0.99999443101421,
-  0.99999489571473,
-  0.99999533144314,
-  0.99999573953040,
-  0.99999612126300,
-  0.99999647788395,
-  0.99999681059383,
-  0.99999712055178,
-  0.99999740887647,
-  0.99999767664709,
-  0.99999792490431,
-  0.99999815465123,
-  0.99999836685427,
-  0.99999856244415,
-  0.99999874231676,
-  0.99999890733405,
-  0.99999905832493,
-  0.99999919608613,
-  0.99999932138304,
-  0.99999943495056,
-  0.99999953749392,
-  0.99999962968950,
-  0.99999971218563,
-  0.99999978560337,
-  0.99999985053727,
-  0.99999990755616,
-  0.99999995720387
-};
-
-
-double kbd_window_short[128] = {
-4.3795702929468881e-005,
-0.00011867384265436617,
-0.0002307165763996192,
-0.00038947282760568383,
-0.00060581272288302553,
-0.00089199695169487453,
-0.0012617254423430522,
-0.0017301724373162003,
-0.0023140071937421476,
-0.0030313989666022221,
-0.0039020049735530842,
-0.0049469401815512024,
-0.0061887279335368318,
-0.0076512306364647726,
-0.0093595599562652423,
-0.011339966208377799,
-0.013619706891715299,
-0.016226894586323766,
-0.019190324717288168,
-0.022539283975960878,
-0.026303340480472455,
-0.030512117046644357,
-0.03519504922365594,
-0.040381130021856941,
-0.046098643518702249,
-0.052374889768730587,
-0.059235903660769147,
-0.066706170556282418,
-0.074808341703430481,
-0.083562952548726227,
-0.092988147159339674,
-0.1030994120216919,
-0.11390932249409955,
-0.12542730516149531,
-0.13765941926783826,
-0.15060816028651081,
-0.16427228853114245,
-0.17864668550988483,
-0.19372224048676889,
-0.20948576943658073,
-0.22591996826744942,
-0.24300340184133981,
-0.26071052995068139,
-0.27901177101369551,
-0.29787360383626599,
-0.3172587073594233,
-0.33712613787396362,
-0.35743154274286698,
-0.37812740923363009,
-0.39916334663203618,
-0.42048639939189658,
-0.4420413886774246,
-0.4637712792815169,
-0.4856175685594023,
-0.50752069370766872,
-0.52942045344797806,
-0.55125643994680196,
-0.57296847662071559,
-0.59449705734411495,
-0.61578378249506627,
-0.63677178724712891,
-0.65740615754163356,
-0.67763432925662526,
-0.69740646622548552,
-0.71667581294953808,
-0.73539901809352737,
-0.75353642514900732,
-0.77105232699609816,
-0.78791518148597028,
-0.80409778560147072,
-0.81957740622770781,
-0.83433586607383625,
-0.84835958382689225,
-0.86163956818294229,
-0.87417136598406997,
-0.88595496528524853,
-0.89699465477567619,
-0.90729884157670959,
-0.91687983002436779,
-0.92575356460899649,
-0.93393934077779084,
-0.94145948779657318,
-0.94833902830402828,
-0.95460531956280026,
-0.96028768170574896,
-0.96541701848104766,
-0.97002543610646474,
-0.97414586584250062,
-0.97781169577969584,
-0.98105641710392333,
-0.98391328975491177,
-0.98641503193166202,
-0.98859353733226141,
-0.99047962335771556,
-0.9921028127769449,
-0.99349115056397752,
-0.99467105680259038,
-0.9956672157341897,
-0.99650250022834352,
-0.99719793020823266,
-0.99777266288955657,
-0.99824401211201486,
-0.99862749357391212,
-0.99893689243401962,
-0.99918434952623147,
-0.99938046234161726,
-0.99953439696357238,
-0.99965400728430465,
-0.99974595807027455,
-0.99981584876278362,
-0.99986833527824281,
-0.99990724749057802,
-0.99993570051598468,
-0.99995619835942084,
-0.99997072890647543,
-0.9999808496399144,
-0.99998776381655818,
-0.99999238714961569,
-0.99999540529959718,
-0.99999732268176988,
-0.99999850325054862,
-0.99999920402413744,
-0.9999996021706401,
-0.99999981649545566,
-0.99999992415545547,
-0.99999997338493041,
-0.99999999295825959,
-0.99999999904096815
-};
-
-#endif
-
--- a/tns.c
+++ /dev/null
@@ -1,478 +1,0 @@
-/*
- *	Temporal Noise Shaping
- *
- *	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.14 $
-  $Date: 2000/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <math.h>
-#include <stdlib.h>
-#include "tns.h"
-#include "aacenc.h"
-#include "quant.h"
-
-/***********************************************/
-/* TNS Profile/Frequency Dependent Parameters  */
-/***********************************************/
-unsigned long tnsSupportedSamplingRates[13] = 
-  {8000,11025,12000,16000,22050,24000,32000,44100,48000,64000,88200,96000,0};
-
-/* Limit bands to > 1.5 kHz */
-/* unsigned short tnsMinBandNumberLong[12] = 
-  { 26, 25, 24, 20, 23, 22, 17, 14, 13, 12, 9, 8 };
- unsigned short tnsMinBandNumberShort[12] = 
-  { 10, 9, 8, 8, 5, 4, 3, 3, 2, 2, 1, 1 }; */
-       
-/* Limit bands to > 2.0 kHz */
-unsigned short tnsMinBandNumberLong[12] = 
-  { 31, 30, 28, 24, 26, 25, 20, 17, 16, 15, 12, 11 };
-unsigned short tnsMinBandNumberShort[12] = 
-  { 12, 10, 10, 8, 6, 6, 4, 3, 3, 2, 2, 2 };
-       
-/**************************************/
-/* Main/Low Profile TNS Parameters    */
-/**************************************/
-unsigned short tnsMaxBandsLongMainLow[12] = 
-  { 39, 42, 42, 42, 46, 46, 51, 42, 40, 34, 31, 31 };
-
-unsigned short tnsMaxBandsShortMainLow[12] = 
-  { 14, 14, 14, 14, 14, 14, 14, 14, 14, 10, 9, 9 };
-
-unsigned short tnsMaxOrderLongMain = 20;
-unsigned short tnsMaxOrderLongLow = 12;
-unsigned short tnsMaxOrderShortMainLow = 7;
-
-/**************************************/
-/* SSR Profile TNS Parameters         */
-/**************************************/
-unsigned short tnsMaxBandsLongSSR[12] = 
-  { 19, 23, 23, 23, 29, 29, 26, 26, 26, 27, 28, 28 };
-
-unsigned short tnsMaxBandsShortSSR[12] = 
-  { 7, 8, 8, 8, 7, 7, 6, 6, 6, 7, 7, 7 };
-
-unsigned short tnsMaxOrderLongSSR = 12;
-unsigned short tnsMaxOrderShortSSR = 7;
-
-
-/*****************************************************/
-/* InitTns:                                          */
-/*****************************************************/
-void TnsInit(long samplingRate,enum AAC_PROFILE profile,TNS_INFO* tnsInfo) 
-{
-  int fsIndex=0;
-
-  /* Determine if sampling rate is supported */
-  while ((unsigned long)(samplingRate)!=tnsSupportedSamplingRates[fsIndex]) {
-    fsIndex++;
-  }
-  
-  switch( profile ) {
-    case MAIN :
-      tnsInfo->tnsMaxBandsLong = tnsMaxBandsLongMainLow[fsIndex];
-      tnsInfo->tnsMaxBandsShort = tnsMaxBandsShortMainLow[fsIndex];
-      tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongMain;
-      tnsInfo->tnsMaxOrderShort = tnsMaxOrderShortMainLow;
-      break;
-    case LOW :
-      tnsInfo->tnsMaxBandsLong = tnsMaxBandsLongMainLow[fsIndex];
-      tnsInfo->tnsMaxBandsShort = tnsMaxBandsShortMainLow[fsIndex];
-      tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongLow;
-      tnsInfo->tnsMaxOrderShort = tnsMaxOrderShortMainLow;
-      break;
-    case SSR :
-      tnsInfo->tnsMaxBandsLong = tnsMaxBandsLongSSR[fsIndex];
-      tnsInfo->tnsMaxBandsShort = tnsMaxBandsShortSSR[fsIndex];
-      tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongSSR;
-      tnsInfo->tnsMaxOrderShort = tnsMaxOrderShortSSR;
-      break;
-  }
-  tnsInfo->tnsMinBandNumberLong = tnsMinBandNumberLong[fsIndex];
-  tnsInfo->tnsMinBandNumberShort = tnsMinBandNumberShort[fsIndex];
-}
-
-
-/*****************************************************/
-/* TnsEncode:                                        */
-/*****************************************************/
-int TnsEncode(AACQuantInfo *quantInfo,
-			  int numberOfBands,       /* Number of bands per window */
-			  enum WINDOW_TYPE blockType,   /* block type */
-			  int* sfbOffsetTable,     /* Scalefactor band offset table */
-			  double* spec,            /* Spectral data array */
-			  int use_tns)
-{
-	int numberOfWindows,windowSize;
-	int startBand,stopBand,order;    /* Bands over which to apply TNS */
-	int lengthInBands;               /* Length to filter, in bands */
-	int w, error;
-	int startIndex,length;
-	double gain;
-	TNS_INFO *tnsInfo = &quantInfo->tnsInfo;
-
-	switch( blockType ) {
-	case ONLY_SHORT_WINDOW :
-		numberOfWindows = MAX_SHORT_WINDOWS;
-		windowSize = BLOCK_LEN_SHORT;
-		startBand = tnsInfo->tnsMinBandNumberShort;
-		stopBand = numberOfBands; 
-		lengthInBands = stopBand-startBand;
-		order = tnsInfo->tnsMaxOrderShort;
-		startBand = min(startBand,tnsInfo->tnsMaxBandsShort);
-		stopBand = min(stopBand,tnsInfo->tnsMaxBandsShort);
-		break;
-
-	default:
-		numberOfWindows = 1;
-		windowSize = BLOCK_LEN_LONG;
-		startBand = tnsInfo->tnsMinBandNumberLong;
-		stopBand = numberOfBands;
-		lengthInBands = stopBand - startBand;
-		order = tnsInfo->tnsMaxOrderLong;
-		startBand = min(startBand,tnsInfo->tnsMaxBandsLong);
-		stopBand = min(stopBand,tnsInfo->tnsMaxBandsLong);
-		break;
-	}
-	
-	/* Make sure that start and stop bands < maxSfb */
-	/* Make sure that start and stop bands >= 0 */
-	startBand = min(startBand,quantInfo->max_sfb);
-	stopBand = min(stopBand,quantInfo->max_sfb);
-	startBand = max(startBand,0);
-	stopBand = max(stopBand,0);
-
-	tnsInfo->tnsDataPresent=0;     /* default TNS not used */
-
-#if 1
-	if (use_tns)
-	/* Doesn't work well on short windows. */
-	if (blockType == ONLY_LONG_WINDOW)
-	/* Perform analysis and filtering for each window */
-	for (w=0;w<numberOfWindows;w++) {
-
-		TNS_WINDOW_DATA* windowData = &tnsInfo->windowData[w];
-		TNS_FILTER_DATA* tnsFilter = windowData->tnsFilter;
-		double* k = tnsFilter->kCoeffs;    /* reflection coeffs */
-		double* a = tnsFilter->aCoeffs;    /* prediction coeffs */
-
-		windowData->numFilters=0;
-		windowData->coefResolution = DEF_TNS_COEFF_RES;
-		startIndex = w * windowSize + sfbOffsetTable[startBand];
-		length = sfbOffsetTable[stopBand] - sfbOffsetTable[startBand];
-		gain = LevinsonDurbin(order,length,&spec[startIndex],k);
-
-		if (gain>DEF_TNS_GAIN_THRESH) {  /* Use TNS */
-			int truncatedOrder;
-
-			windowData->numFilters++;
-			tnsInfo->tnsDataPresent=1;
-			tnsFilter->direction = 0;
-			tnsFilter->coefCompress = 0;
-			tnsFilter->length = lengthInBands;
-			QuantizeReflectionCoeffs(order,DEF_TNS_COEFF_RES,k,tnsFilter->index);
-			truncatedOrder = TruncateCoeffs(order,DEF_TNS_COEFF_THRESH,k);
-			tnsFilter->order = truncatedOrder;
-			StepUp(truncatedOrder,k,a);    /* Compute predictor coefficients */
-			error = TnsInvFilter(length,&spec[startIndex],tnsFilter);      /* Filter */
-			if (error == FERROR)
-				return FERROR;
-		}
-	}
-	return FNO_ERROR;
-#endif
-}
-
-
-/*****************************************************/
-/* TnsFilter:                                        */
-/*   Filter the given spec with specified length     */
-/*   using the coefficients specified in filter.     */
-/*   Not that the order and direction are specified  */
-/*   withing the TNS_FILTER_DATA structure.          */
-/*****************************************************/
-void TnsFilter(int length,double* spec,TNS_FILTER_DATA* filter) {
-	int i,j,k=0;
-	int order=filter->order;
-	double* a=filter->aCoeffs;
-
-	/* Determine loop parameters for given direction */
-	if (filter->direction) {
-
-		/* Startup, initial state is zero */
-		for (i=length-2;i>(length-1-order);i--) {
-			k++;
-			for (j=1;j<=k;j++) {
-				spec[i]-=spec[i+j]*a[j];
-			}
-		}
-		
-		/* Now filter completely inplace */
-		for	(i=length-1-order;i>=0;i--) {
-			for (j=1;j<=order;j++) {
-				spec[i]-=spec[i+j]*a[j];
-			}
-		}
-
-
-	} else {
-
-		/* Startup, initial state is zero */
-		for (i=1;i<order;i++) {
-			for (j=1;j<=i;j++) {
-				spec[i]-=spec[i-j]*a[j];
-			}
-		}
-		
-		/* Now filter completely inplace */
-		for	(i=order;i<length;i++) {
-			for (j=1;j<=order;j++) {
-				spec[i]-=spec[i-j]*a[j];
-			}
-		}
-	}
-}
-
-
-/********************************************************/
-/* TnsInvFilter:                                        */
-/*   Inverse filter the given spec with specified       */
-/*   length using the coefficients specified in filter. */
-/*   Not that the order and direction are specified     */
-/*   withing the TNS_FILTER_DATA structure.             */
-/********************************************************/
-int TnsInvFilter(int length,double* spec,TNS_FILTER_DATA* filter) {
-	int i,j,k=0;
-	int order=filter->order;
-	double* a=filter->aCoeffs;
-	double* temp;
-
-    temp = (double *) malloc( length * sizeof (double));
-    if (!temp) {
-		return FERROR;
-//      CommonExit( 1, "TnsInvFilter: Could not allocate memory for TNS array\nExiting program...\n");
-    }
-
-	/* Determine loop parameters for given direction */
-	if (filter->direction) {
-
-		/* Startup, initial state is zero */
-		temp[length-1]=spec[length-1];
-		for (i=length-2;i>(length-1-order);i--) {
-			temp[i]=spec[i];
-			k++;
-			for (j=1;j<=k;j++) {
-				spec[i]+=temp[i+j]*a[j];
-			}
-		}
-		
-		/* Now filter the rest */
-		for	(i=length-1-order;i>=0;i--) {
-			temp[i]=spec[i];
-			for (j=1;j<=order;j++) {
-				spec[i]+=temp[i+j]*a[j];
-			}
-		}
-
-
-	} else {
-
-		/* Startup, initial state is zero */
-		temp[0]=spec[0];
-		for (i=1;i<order;i++) {
-			temp[i]=spec[i];
-			for (j=1;j<=i;j++) {
-				spec[i]+=temp[i-j]*a[j];
-			}
-		}
-		
-		/* Now filter the rest */
-		for	(i=order;i<length;i++) {
-			temp[i]=spec[i];
-			for (j=1;j<=order;j++) {
-				spec[i]+=temp[i-j]*a[j];
-			}
-		}
-	}
-	free(temp);
-	return FNO_ERROR;
-}
-
-
-
-
-
-/*****************************************************/
-/* TruncateCoeffs:                                   */
-/*   Truncate the given reflection coeffs by zeroing */
-/*   coefficients in the tail with absolute value    */
-/*   less than the specified threshold.  Return the  */
-/*   truncated filter order.                         */
-/*****************************************************/
-int TruncateCoeffs(int fOrder,double threshold,double* kArray) {
-	int i;
-
-	for (i=fOrder;i>=0;i--) {
-		kArray[i] = (fabs(kArray[i])>threshold) ? kArray[i] : 0.0;
-		if (kArray[i]!=0.0) return i;
-	}
-return 0; // Avoid compiler warning
-}
-
-/*****************************************************/
-/* QuantizeReflectionCoeffs:                         */
-/*   Quantize the given array of reflection coeffs   */
-/*   to the specified resolution in bits.            */
-/*****************************************************/
-void QuantizeReflectionCoeffs(int fOrder,
-			      int coeffRes,
-			      double* kArray,
-			      int* indexArray) {
-
-	double iqfac,iqfac_m;
-	int i;
-
-	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++) {
-		indexArray[i] = (int)(0.5+(asin(kArray[i])*((kArray[i]>=0)?iqfac:iqfac_m)));
-		kArray[i] = sin((double)indexArray[i]/((indexArray[i]>=0)?iqfac:iqfac_m));
-	}
-}
-
-/*****************************************************/
-/* Autocorrelation,                                  */
-/*   Compute the autocorrelation function            */
-/*   estimate for the given data.                    */
-/*****************************************************/
-void Autocorrelation(int maxOrder,        /* Maximum autocorr order */
-		     int dataSize,		  /* Size of the data array */
-		     double* data,		  /* Data array */
-		     double* rArray) {	  /* Autocorrelation array */
-
-  int order,index;
-
-  for (order=0;order<=maxOrder;order++) {
-    rArray[order]=0.0;
-    for (index=0;index<dataSize;index++) {
-      rArray[order]+=data[index]*data[index+order];
-    }
-    dataSize--;
-  }
-}
-
-
-
-/*****************************************************/
-/* LevinsonDurbin:                                   */
-/*   Compute the reflection coefficients for the     */
-/*   given data using LevinsonDurbin recursion.      */
-/*   Return the prediction gain.                     */
-/*****************************************************/
-double LevinsonDurbin(int fOrder,          /* Filter order */
-					  int dataSize,		   /* Size of the data array */
-					  double* data,		   /* Data array */
-					  double* kArray) 	   /* Reflection coeff array */
-{
-	int order,i;
-	double signal;
-	double error, kTemp;				/* Prediction error */
-	double aArray1[TNS_MAX_ORDER+1];	/* Predictor coeff array */
-	double aArray2[TNS_MAX_ORDER+1];	/* Predictor coeff array 2 */
-	double rArray[TNS_MAX_ORDER+1];		/* Autocorrelation coeffs */
-	double* aPtr = aArray1;				/* Ptr to aArray1 */
-	double* aLastPtr = aArray2;			/* Ptr to aArray2 */
-	double* aTemp;
-
-	/* Compute autocorrelation coefficients */
-	Autocorrelation(fOrder,dataSize,data,rArray);
-	signal=rArray[0];	/* signal energy */
-
-	/* Set up pointers to current and last iteration */ 
-	/* predictor coefficients.						 */
-//	aPtr = aArray1;
-//	aLastPtr = aArray2;
-	/* If there is no signal energy, return */
-	if (!signal) {
-		kArray[0]=1.0;
-		for (order=1;order<=fOrder;order++) {
-			kArray[order]=0.0;
-		}
-		return 0;
-	} else {
-
-		/* Set up first iteration */
-		kArray[0]=1.0;
-		aPtr[0]=1.0;		/* Ptr to predictor coeffs, current iteration*/
-		aLastPtr[0]=1.0;	/* Ptr to predictor coeffs, last iteration */
-		error=rArray[0];
-
-		/* Now perform recursion */
-		for (order=1;order<=fOrder;order++) {
-			kTemp = aLastPtr[0]*rArray[order-0];
-			for (i=1;i<order;i++) {
-				kTemp += aLastPtr[i]*rArray[order-i];
-			}
-			kTemp = -kTemp/error;
-			kArray[order]=kTemp;
-			aPtr[order]=kTemp;
-			for (i=1;i<order;i++) {
-				aPtr[i] = aLastPtr[i] + kTemp*aLastPtr[order-i];
-			}
-			error = error * (1 - kTemp*kTemp);
-
-			/* Now make current iteration the last one */
-			aTemp=aLastPtr;
-			aLastPtr=aPtr;		/* Current becomes last */
-			aPtr=aTemp;			/* Last becomes current */
-		}
-		return signal/error;	/* return the gain */
-	}
-}
-
-
-/*****************************************************/
-/* StepUp:                                           */
-/*   Convert reflection coefficients into            */
-/*   predictor coefficients.                         */
-/*****************************************************/
-void StepUp(int fOrder,double* kArray,double* aArray) {
-
-	double aTemp[TNS_MAX_ORDER+2];
-	int i,order;
-
-	aArray[0]=1.0;
-	aTemp[0]=1.0;
-	for (order=1;order<=fOrder;order++) {
-		aArray[order]=0.0;
-		for (i=1;i<=order;i++) {
-			aTemp[i] = aArray[i] + kArray[order]*aArray[order-i];
-		}
-		for (i=1;i<=order;i++) {
-			aArray[i]=aTemp[i];
-		}
-	}
-}
-
--- a/tns.h
+++ /dev/null
@@ -1,110 +1,0 @@
-/*
- *	Function prototypes for TNS
- *
- *	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.8 $
-  $Date: 2000/11/01 14:05:32 $ (check in)
-  $Author: menno $
-  *************************************************************************/
- 
-#ifndef _TNS_H_INCLUDED
-#define _TNS_H_INCLUDED
- 
-#include "interface.h"
-
-/*************************/
-/* #defines              */
-/*************************/
-#define TNS_MAX_ORDER 20				   
-#define DEF_TNS_GAIN_THRESH 1.4 //new2
-#define DEF_TNS_COEFF_THRESH 0.1
-#define DEF_TNS_COEFF_RES 4
-#define DEF_TNS_RES_OFFSET 3
-#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
-
-/**************************/
-/* Structure definitions  */
-/**************************/
-typedef struct {
-  int order;                           /* Filter order */
-  int direction;		       /* Filtering direction */
-  int coefCompress;		       /* Are coeffs compressed? */
-  int length;                          /* Length, in bands */                     
-  double aCoeffs[TNS_MAX_ORDER+1];     /* AR Coefficients */
-  double kCoeffs[TNS_MAX_ORDER+1];     /* Reflection Coefficients */
-  int index[TNS_MAX_ORDER+1];	       /* Coefficient indices */
-} TNS_FILTER_DATA;
-
-
-typedef struct {
-  int numFilters;				/* Number of filters */
-  int coefResolution;				/* Coefficient resolution */
-  TNS_FILTER_DATA tnsFilter[1<<LEN_TNS_NFILTL];	/* TNS filters */
-} TNS_WINDOW_DATA;
-
-
-typedef struct {
-  int tnsDataPresent;
-  int tnsMinBandNumberLong;
-  int tnsMinBandNumberShort;
-  int tnsMaxBandsLong;
-  int tnsMaxBandsShort;
-  int tnsMaxOrderLong;
-  int tnsMaxOrderShort;
-  TNS_WINDOW_DATA windowData[MAX_SHORT_WINDOWS];	/* TNS data per window */
-} TNS_INFO;
-
-
-/*************************/
-/* Function prototypes   */
-/*************************/
-void Autocorrelation(int maxOrder,        /* Maximum autocorr order */
-		     int dataSize,		  /* Size of the data array */
-		     double* data,		  /* Data array */
-		     double* rArray);	  /* Autocorrelation array */
-
-double LevinsonDurbin(int maxOrder,       /* Maximum filter order */
-		      int dataSize,		   /* Size of the data array */
-		      double* data,		   /* Data array */
-		      double* kArray);	   /* Reflection coeff array */
-
-void StepUp(int fOrder,
-	    double* kArray,
-	    double* aArray);
-
-void QuantizeReflectionCoeffs(int fOrder,int coeffRes,double* rArray,int* indexArray);
-int TruncateCoeffs(int fOrder,double threshold,double* kArray);
-void TnsFilter(int length,double* spec,TNS_FILTER_DATA* filter);
-int TnsInvFilter(int length,double* spec,TNS_FILTER_DATA* filter);
-void TnsInit(long samplingRate,enum AAC_PROFILE profile,TNS_INFO* tnsInfo); 
-int TnsEncode(struct _AACQuantInfo *quantInfo,int numberOfBands,enum WINDOW_TYPE blockType,int* sfbOffsetTable,double* spec,int use_tns);
-
-#endif
-
--- /dev/null
+++ b/todo.txt
@@ -1,0 +1,26 @@
+TODO: In any order
+Big list, but a lot of it can be done fairly easily with some old code
+
+
+- Add ADTS headers
+- Add frequency cutoff filter
+- Add TNS
+- Add PNS
+- Add LTP
+- Add backward prediction (MPEG2-AAC)????
+- Add IS
+- Add bit reservoir control
+- Add pulse coding
+- VBR quantizer
+- Rewrite noiseless coding (now taken from old version)
+- Fix short block psychoacoustics
+- Clean up psychoacoustics code
+- Better grouping support
+- Add Window shape switching
+- Test (and maybe fix) sample rates other than 44100 Hz
+- Test (and maybe fix) multichannel and mono support
+- Write GUI
+- Improve command line tool (wildcards)
+- Write documentation for library interface
+- Speedup?? (no priority)
+- Figure out how to read and write ".mp4" format
\ No newline at end of file
--- a/transfo.c
+++ /dev/null
@@ -1,620 +1,0 @@
-/*
- *	MDCT transform
- *
- *	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.19 $
-  $Date: 2000/10/06 14:47:27 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#include <math.h>
-#include <memory.h>
-
-#include "transfo.h"
-#include "shape_win.h"
-
-#define NFLAT_LS 448  // (BLOCK_LEN_LONG - BLOCK_LEN_SHORT) / 2
-
-#ifndef M_PI
-#define M_PI        3.14159265358979323846
-#endif
-
-#ifndef M_PI_2
-#define M_PI_2      1.57079632679489661923
-#endif
-
-int sizedouble;
-double wpi256,wpr256;
-double wpi2048,wpr2048;
-
-/*******************************************************************************
-                               Fast MDCT & IMDCT Code
-*******************************************************************************/
-void MDCT (double *data, int N)
-{
-  double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
-  double freq = 2.0 * M_PI / N;
-  double fac,cosfreq8,sinfreq8;
-  int i, n;
-  int b = N >> 1;
-  int N4 = N >> 2;
-  int N2 = N >> 1;
-  int a = N - b;
-  int a2 = a >> 1;
-  int a4 = a >> 2;
-  int b4 = b >> 2;
-  int unscambled;
-
-  /* Choosing to allocate 2/N factor to Inverse Xform! */
-  fac = 2.; /* 2 from MDCT inverse  to forward */
-
-  /* prepare for recurrence relation in pre-twiddle */
-  cfreq = cos (freq);
-  sfreq = sin (freq);
-  cosfreq8 = cos (freq * 0.125);
-  sinfreq8 = sin (freq * 0.125);
-  c = cosfreq8;
-  s = sinfreq8;
-
-  for (i = 0; i < N4; i++) {
-    /* calculate real and imaginary parts of g(n) or G(p) */
-    n = N / 2 - 1 - 2 * i;
-
-    if (i < b4)
-      tempr = data [a2 + n] + data [N + a2 - 1 - n]; /* use second form of e(n) for n = N / 2 - 1 - 2i */
-    else
-      tempr = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n = N / 2 - 1 - 2i */
-
-    n = 2 * i;
-    if (i < a4)
-      tempi = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n=2i */
-    else
-      tempi = data [a2 + n] + data [N + a2 - 1 - n]; /* use second form of e(n) for n=2i*/
-
-    /* calculate pre-twiddled FFT input */
-    FFTarray [i].re = tempr * c + tempi * s;
-    FFTarray [i].im = tempi * c - tempr * s;
-
-    /* use recurrence to prepare cosine and sine for next value of i */
-    cold = c;
-    c = c * cfreq - s * sfreq;
-    s = s * cfreq + cold * sfreq;
-  }
-
-  /* Perform in-place complex FFT of length N/4 */
-  switch (N) {
-    case 256:
-      pfftw_64(FFTarray);
-      break;
-    case 2048:
-      pfftw_512(FFTarray);
-  }
-
-  /* prepare for recurrence relations in post-twiddle */
-  c = cosfreq8;
-  s = sinfreq8;
-
-  /* post-twiddle FFT output and then get output data */
-  for (i = 0; i < N4; i++) {
-    /* get post-twiddled FFT output  */
-    /* Note: fac allocates 4/N factor from IFFT to forward and inverse */
-    switch (N) {
-      case 256:
-      	unscambled = unscambled64[i];
-      	break;
-      case 2048:
-	unscambled = unscambled512[i];
-    }
-    tempr = fac * (FFTarray [unscambled].re * c + FFTarray [unscambled].im * s);
-    tempi = fac * (FFTarray [unscambled].im * c - FFTarray [unscambled].re * s);
-
-    /* fill in output values */
-    data [2 * i] = -tempr;   /* first half even */
-    data [N2 - 1 - 2 * i] = tempi;  /* first half odd */
-    data [N2 + 2 * i] = -tempi;  /* second half even */
-    data [N - 1 - 2 * i] = tempr;  /* second half odd */
-
-    /* use recurrence to prepare cosine and sine for next value of i */
-    cold = c;
-    c = c * cfreq - s * sfreq;
-    s = s * cfreq + cold * sfreq;
-  }
-}
-
-void IMDCT(double *data, int N)
-{
-  double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
-  double freq = 2.0 * M_PI / N;
-  double fac, cosfreq8, sinfreq8;
-  int i;
-  int Nd2 = N >> 1;
-  int Nd4 = N >> 2;
-  int Nd8 = N >> 3;
-  int unscambled;
-
-  /* Choosing to allocate 2/N factor to Inverse Xform! */
-  fac = 2. / N; /* remaining 2/N from 4/N IFFT factor */
-
-  /* prepare for recurrence relation in pre-twiddle */
-  cfreq = cos (freq);
-  sfreq = sin (freq);
-  cosfreq8 = cos (freq * 0.125);
-  sinfreq8 = sin (freq * 0.125);
-  c = cosfreq8;
-  s = sinfreq8;
-
-  for (i = 0; i < Nd4; i++) {
-    /* calculate real and imaginary parts of g(n) or G(p) */
-    tempr = -data [2 * i];
-    tempi = data [Nd2 - 1 - 2 * i];
-
-    /* calculate pre-twiddled FFT input */
-    switch (N) {
-      case 256:
-	unscambled = unscambled64[i];
-	break;
-      case 2048:
-	unscambled = unscambled512[i];
-    }
-
-    FFTarray [unscambled].re = tempr * c - tempi * s;
-    FFTarray [unscambled].im = tempi * c + tempr * s;
-
-    /* use recurrence to prepare cosine and sine for next value of i */
-    cold = c;
-    c = c * cfreq - s * sfreq;
-    s = s * cfreq + cold * sfreq;
-	}
-
-    /* Perform in-place complex IFFT of length N/4 */
-    switch (N) {
-      case 256:
-        pfftwi_64(FFTarray);
-	break;
-      case 2048:pfftwi_512(FFTarray);
-    }
-
-    /* prepare for recurrence relations in post-twiddle */
-    c = cosfreq8;
-    s = sinfreq8;
-
-    /* post-twiddle FFT output and then get output data */
-    for (i = 0; i < Nd4; i++) {
-
-    /* get post-twiddled FFT output  */
-    tempr = fac * (FFTarray[i].re * c - FFTarray[i].im * s);
-    tempi = fac * (FFTarray[i].im * c + FFTarray[i].re * s);
-
-    /* fill in output values */
-    data [Nd2 + Nd4 - 1 - 2 * i] = tempr;
-    if (i < Nd8)
-      data [Nd2 + Nd4 + 2 * i] = tempr;
-    else
-      data [2 * i - Nd4] = -tempr;
-
-    data [Nd4 + 2 * i] = tempi;
-    if (i < Nd8)
-      data [Nd4 - 1 - 2 * i] = -tempi;
-    else
-      data [Nd4 + N - 1 - 2*i] = tempi;
-
-    /* use recurrence to prepare cosine and sine for next value of i */
-    cold = c;
-    c = c * cfreq - s * sfreq;
-    s = s * cfreq + cold * sfreq;
-  }
-}
-
-void make_MDCT_windows(void)
-{
-  int i;
-  for( i=0; i<BLOCK_LEN_LONG; i++ )
-    sin_window_long[i] = sin((M_PI/(2*BLOCK_LEN_LONG)) * (i + 0.5));
-  for( i=0; i<BLOCK_LEN_SHORT; i++ )
-    sin_window_short[i] = sin((M_PI/(2*BLOCK_LEN_SHORT)) * (i + 0.5));
-  sizedouble = sizeof (double);
-}
-/*******************************************************************************
-                                    T/F mapping
-*******************************************************************************/
-void buffer2freq(double           p_in_data[],
-		 double           p_out_mdct[],
-		 double           p_overlap[],
-		 enum WINDOW_TYPE block_type,
-		 Window_shape     wfun_select,      /*  current window shape */
-		 Window_shape     wfun_select_prev, /*  previous window shape */
-		 Mdct_in          overlap_select
-		 )
-{
-  double         transf_buf[ 2*BLOCK_LEN_LONG ];
-  double         *p_o_buf, *first_window, *second_window;
-  int            k,i;
-
-  static int firstTime=1;
-
-  /* create / shift old values */
-  /* We use p_overlap here as buffer holding the last frame time signal*/
-  if(overlap_select != MNON_OVERLAPPED){
-    if (firstTime){
-      firstTime=0;
-      memset(transf_buf,0,BLOCK_LEN_LONG*sizedouble);
-    }
-    else
-      memcpy(transf_buf,p_overlap,BLOCK_LEN_LONG*sizedouble);
-    memcpy(transf_buf+BLOCK_LEN_LONG,p_in_data,BLOCK_LEN_LONG*sizedouble);
-    memcpy(p_overlap,p_in_data,BLOCK_LEN_LONG*sizedouble);
-  }
-  else {
-    memcpy(transf_buf,p_in_data,2*BLOCK_LEN_LONG*sizedouble);
-  }
-
-  /*  Window shape processing */
-  switch (wfun_select_prev){
-    case WS_SIN:
-      if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
-        first_window = sin_window_long;
-      else
-        first_window = sin_window_short;
-      break;
-    case WS_KBD:
-      if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
-        first_window = kbd_window_long;
-      else
-        first_window = kbd_window_short;
-      break;
-  }
-
-  switch (wfun_select){
-    case WS_SIN:
-      if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
-        second_window = sin_window_long;
-      else
-        second_window = sin_window_short;
-      break;
-    case WS_KBD:
-      if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
-        second_window = kbd_window_long;
-      else
-        second_window = kbd_window_short;
-      break;
-  }
-
-  /* Set ptr to transf-Buffer */
-  p_o_buf = transf_buf;
-
-  /* Separate action for each Block Type */
-  switch( block_type ) {
-    case ONLY_LONG_WINDOW :
-      for ( i = 0 ; i < BLOCK_LEN_LONG ; i++){
-        p_out_mdct[i] = p_o_buf[i] * first_window[i];
-        p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
-      }
-      MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
-      break;
-
-    case LONG_SHORT_WINDOW :
-      for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
-         p_out_mdct[i] = p_o_buf[i] * first_window[i];
-      memcpy(p_out_mdct+BLOCK_LEN_LONG,p_o_buf+BLOCK_LEN_LONG,NFLAT_LS*sizedouble);
-//    for ( ; i < NFLAT_LS + BLOCK_LEN_LONG; i++){
-//      p_out_mdct[i] = 1.0;
-//      p_out_mdct[i+NFLAT_LS+BLOCK_LEN_SHORT] = 0.0;
-//    }
-      for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
-        p_out_mdct[i+BLOCK_LEN_LONG+NFLAT_LS] = p_o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
-      memset(p_out_mdct+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
-      MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
-      break;
-
-    case SHORT_LONG_WINDOW :
-      memset(p_out_mdct,0,NFLAT_LS*sizedouble);
-//    for ( i = 0 ; i < NFLAT_LS ; i++){
-//      p_out_mdct[i] = 0.0;
-//      p_out_mdct[i+NFLAT_LS+BLOCK_LEN_SHORT] = 1.0;
-//    }
-      for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
-        p_out_mdct[i+NFLAT_LS] = p_o_buf[i+NFLAT_LS] * first_window[i];
-      memcpy(p_out_mdct+NFLAT_LS+BLOCK_LEN_SHORT,p_o_buf+NFLAT_LS+BLOCK_LEN_SHORT,NFLAT_LS*sizedouble);
-      for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
-        p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
-	MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
-      break;
-
-    case ONLY_SHORT_WINDOW :
-      if(overlap_select != MNON_OVERLAPPED){ /* YT 970615 for sonPP */
-      	p_o_buf += NFLAT_LS;
-      }
-      for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
-        for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++ ){
-          p_out_mdct[i] = p_o_buf[i] * first_window[i];
-          p_out_mdct[i+BLOCK_LEN_SHORT] = p_o_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
-          }
-        MDCT( p_out_mdct, 2*BLOCK_LEN_SHORT );
-        p_out_mdct += BLOCK_LEN_SHORT;
-	if(overlap_select != MNON_OVERLAPPED)
-          p_o_buf += BLOCK_LEN_SHORT;
-        else
-          p_o_buf += 2*BLOCK_LEN_SHORT;
-        first_window = second_window;
-      }
-      break;
-  }
-}
-
-void freq2buffer(double           p_in_data[],
-		 double           p_out_data[],
-		 double           p_overlap[],
-		 enum WINDOW_TYPE block_type,
-		 Window_shape     wfun_select,      /*  current window shape */
-		 Window_shape     wfun_select_prev, /*  previous window shape */
-		 Mdct_in	  overlap_select
-		 )
-{
-  double           *o_buf, transf_buf[ 2*BLOCK_LEN_LONG ];
-  double           overlap_buf[ 2*BLOCK_LEN_LONG ], *first_window, *second_window;
-
-  double  *fp;
-  int     k,i;
-
-  /*  Window shape processing */
-  switch (wfun_select_prev){
-    case WS_SIN:
-      if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
-        first_window = sin_window_long;
-      else
-        first_window = sin_window_short;
-      break;
-    case WS_KBD:
-      if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
-        first_window = kbd_window_long;
-      else
-        first_window = kbd_window_short;
-      break;
-  }
-
-  switch (wfun_select){
-    case WS_SIN:
-      if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
-        second_window = sin_window_long;
-      else
-        second_window = sin_window_short;
-      break;
-    case WS_KBD:
-      if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
-        second_window = kbd_window_long;
-      else
-        second_window = kbd_window_short;
-      break;
-  }
-
-  /* Assemble overlap buffer */
-  memcpy(overlap_buf,p_overlap,BLOCK_LEN_LONG*sizedouble);
-  o_buf = overlap_buf;
-
-  /* Separate action for each Block Type */
-  switch( block_type ) {
-    case ONLY_LONG_WINDOW :
-      memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizedouble);
-      IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
-      for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
-        transf_buf[i] *= first_window[i];
-      if (overlap_select != MNON_OVERLAPPED) {
-        for ( i = 0 ; i < BLOCK_LEN_LONG; i++ ){
-          o_buf[i] += transf_buf[i];
-          o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
-        }
-      }
-      else { /* overlap_select == NON_OVERLAPPED */
-        for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
-          transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
-        }
-      break;
-
-    case LONG_SHORT_WINDOW :
-      memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizedouble);
-      IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
-      for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
-        transf_buf[i] *= first_window[i];
-        if (overlap_select != MNON_OVERLAPPED) {
-          for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
-            o_buf[i] += transf_buf[i];
-          memcpy(o_buf+BLOCK_LEN_LONG,transf_buf+BLOCK_LEN_LONG,NFLAT_LS*sizedouble);
-          for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
-            o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] = transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
-          memset(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
-        }
-        else { /* overlap_select == NON_OVERLAPPED */
-          for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
-            transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] *= second_window[BLOCK_LEN_SHORT-i-1];
-          memset(transf_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
-        }
-        break;
-
-    case SHORT_LONG_WINDOW :
-      memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizedouble);
-      IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
-      for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
-        transf_buf[i+NFLAT_LS] *= first_window[i];
-      if (overlap_select != MNON_OVERLAPPED) {
-        for ( i = 0 ; i < BLOCK_LEN_SHORT; i++ )
-          o_buf[i+NFLAT_LS] += transf_buf[i+NFLAT_LS];
-        memcpy(o_buf+BLOCK_LEN_SHORT+NFLAT_LS,transf_buf+BLOCK_LEN_SHORT+NFLAT_LS,NFLAT_LS*sizedouble);
-        for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
-          o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
-      }
-      else { /* overlap_select == NON_OVERLAPPED */
-        memset(transf_buf,0,NFLAT_LS*sizedouble);
-        for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
-          transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
-      }
-      break;
-
-    case ONLY_SHORT_WINDOW :
-      if (overlap_select != MNON_OVERLAPPED) {
-        fp = o_buf + NFLAT_LS;
-      }
-      else { /* overlap_select == NON_OVERLAPPED */
-      fp = transf_buf;
-      }
-      for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
-        memcpy(transf_buf,p_in_data,BLOCK_LEN_SHORT*sizedouble);
-        IMDCT( transf_buf, 2*BLOCK_LEN_SHORT );
-        p_in_data += BLOCK_LEN_SHORT;
-        if (overlap_select != MNON_OVERLAPPED) {
-          for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
-            transf_buf[i] *= first_window[i];
-            fp[i] += transf_buf[i];
-            fp[i+BLOCK_LEN_SHORT] = transf_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
-          }
-    	fp    += BLOCK_LEN_SHORT;
-        }
-        else { /* overlap_select == NON_OVERLAPPED */
-          for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
-            fp[i] *= first_window[i];
-            fp[i+BLOCK_LEN_SHORT] *= second_window[BLOCK_LEN_SHORT-i-1];
-          }
-      	  fp += 2*BLOCK_LEN_SHORT;
-        }
-        first_window = second_window;
-      }
-      memset(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
-      break;
-  }
-
-  if (overlap_select != MNON_OVERLAPPED)
-    memcpy(p_out_data,o_buf,BLOCK_LEN_LONG*sizedouble);
-  else  /* overlap_select == NON_OVERLAPPED */
-    memcpy(p_out_data,transf_buf,2*BLOCK_LEN_LONG*sizedouble);
-
-  /* save unused output data */
-  memcpy(p_overlap,o_buf+BLOCK_LEN_LONG,BLOCK_LEN_LONG*sizedouble);
-}
-
-/******************************************************************************/
-
-void specFilter (double p_in[],
-                 double p_out[],
-		 int  samp_rate,
-		 int lowpass_freq,
-		 int    specLen
-		 )
-{
-  int lowpass,xlowpass;
-
-  /* calculate the last line which is not zero */
-  lowpass = (lowpass_freq * specLen) / (samp_rate>>1) + 1;
-  xlowpass = (lowpass < specLen) ? lowpass : specLen ;
-
-  if( p_out != p_in )
-    memcpy(p_out,p_in,specLen*sizedouble);
-  memset(p_out+xlowpass,0,(specLen-xlowpass)*sizedouble);
-}
-
-void initrft(void)
-{
-  double theta,wtemp;
-
-  theta  = -M_PI/128.0;
-  wpi256 = sin(theta);
-  wtemp  = sin(0.5*theta);
-  wpr256 = -2.0*wtemp*wtemp;
-
-  theta   = -M_PI/1024.0;
-  wpi2048 = sin(theta);
-  wtemp   = sin(0.5*theta);
-  wpr2048 = -2.0*wtemp*wtemp;
-}
-
-void realft256(double *data)
-{
-  int i,i1,i2,i3,i4;
-  double h1r,h1i,h2r,h2i,t1,t2,t3;
-  double wr,wi,wtemp;
-
-  pfftw_128(FFTarray);
-  for (i = 0; i < 128; i++){
-    data[(i<<1)] = FFTarray[unscambled128[i]].re;
-    data[(i<<1)+1]= FFTarray[unscambled128[i]].im;
-  }
-
-  wr=1.0+wpr256;
-  wi=wpi256;
-  for (i=1;i<64;i++) {
-    i4=1+(i3=257-(i2=1+(i1=i+i)));
-    h1r=0.5*(data[i1]+data[i3]);
-    h1i=0.5*(data[i2]-data[i4]);
-    h2r=0.5*(data[i2]+data[i4]);
-    h2i=-0.5*(data[i1]-data[i3]);
-    t1=wr*h2r;
-    t2=wi*h2i;
-    t3=wr*h2i+wi*h2r;
-
-    data[i1]=h1r+t1-t2;
-    data[i2]=h1i+t3;
-    data[i3]=h1r-t1+t2;
-    data[i4]=-h1i+t3;
-    wtemp=wr;
-    wr=wtemp*wpr256-wi*wpi256+wr;
-    wi=wi*wpr256+wtemp*wpi256+wi;
-  }
-  data[0] = data[0]+data[1];
-  data[1] = 0;
-  data[129] = -data[129]; // hack to emulate complex FFT
-}
-
-void realft2048(double *data)
-{
-  int i,i1,i2,i3,i4;
-  double h1r,h1i,h2r,h2i,t1,t2,t3;
-  double wr,wi,wtemp;
-
-  pfftw_1024(FFTarray);
-  for (i = 0; i < 1024; i++){
-    data[(i<<1)] = FFTarray[unscambled1024[i]].re;
-    data[(i<<1)+1]= FFTarray[unscambled1024[i]].im;
-  }
-
-  wr=1.0+wpr2048;
-  wi=wpi2048;
-  for (i=1;i<512;i++) {
-    i4=1+(i3=2049-(i2=1+(i1=i+i)));
-    h1r=0.5*(data[i1]+data[i3]);
-    h1i=0.5*(data[i2]-data[i4]);
-    h2r=0.5*(data[i2]+data[i4]);
-    h2i=-0.5*(data[i1]-data[i3]);
-    t1=wr*h2r;
-    t2=wi*h2i;
-    t3=wr*h2i+wi*h2r;
-
-    data[i1]=h1r+t1-t2;
-    data[i2]=h1i+t3;
-    data[i3]=h1r-t1+t2;
-    data[i4]=-h1i+t3;
-    wtemp=wr;
-    wr=wtemp*wpr2048-wi*wpi2048+wr;
-    wi=wi*wpr2048+wtemp*wpi2048+wi;
-  }
-  data[0] = data[0]+data[1];
-  data[1] = 0;
-  data[1025] = -data[1025]; // hack to emulate complex FFT
-}
-
--- a/transfo.h
+++ /dev/null
@@ -1,103 +1,0 @@
-/*
- *	Function prototypes for MDCT transform
- *
- *	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.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;
-
-// Use this for encoder - double precision
-typedef double fftw_real;
-
-typedef struct {
-     fftw_real re, im;
-} fftw_complex;
-
-#define c_re(c)  ((c).re)
-#define c_im(c)  ((c).im)
-
-#define DEFINE_PFFTW(size)			\
- void pfftwi_##size(fftw_complex *input);	\
- void pfftw_##size(fftw_complex *input);	\
- int  pfftw_permutation_##size(int i);
-
-DEFINE_PFFTW(16)
-DEFINE_PFFTW(32)
-DEFINE_PFFTW(64)
-DEFINE_PFFTW(128)
-DEFINE_PFFTW(256)
-DEFINE_PFFTW(512)
-DEFINE_PFFTW(1024)
-
-void make_FFT_order(void);
-void make_MDCT_windows(void);
-void IMDCT(fftw_real *data, int N);
-void MDCT(fftw_real *data, int N);
-void realft2048(double *data);
-void realft256(double *data);
-void initrft(void);
-
-extern int unscambled64[64];      /* the permutation array for FFT64*/
-extern int unscambled128[128];    /* the permutation array for FFT128*/
-extern int unscambled512[512];    /* the permutation array for FFT512*/
-extern int unscambled1024[1024];  /* the permutation array for FFT1024*/
-extern fftw_complex FFTarray[1024];    /* the array for in-place FFT */
-
-#endif	  /*	TRANSFORM_H		*/