shithub: aacenc

Download patch

ref: 708eea7d2978b554421e6f485ce237430cfeed80
parent: a6c5046f22be23435ab21c679e4bf14631f0e233
author: menno <menno>
date: Fri Oct 6 10:47:27 EDT 2000

Code cleanup

--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@
 
 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 nok_ltp_enc.c nok_pitch.c rateconv.c faac.c quant.c huffman.c
+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)
 
--- a/aac_se_enc.c
+++ b/aac_se_enc.c
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.13 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.14 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -315,10 +315,10 @@
     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_IN_LONG_BLOCK - 1);  /* the grouping bits */
+      BsPutBit(fixed_stream,grouping_bits,MAX_SHORT_WINDOWS - 1);  /* the grouping bits */
     }
     bit_count += LEN_MAX_SFBS;
-    bit_count += MAX_SHORT_IN_LONG_BLOCK - 1;
+    bit_count += MAX_SHORT_WINDOWS - 1;
   }
   /* Otherwise, write out max_sfb and predictor data */
   else { /* block type is either start, stop, or long */
@@ -341,7 +341,7 @@
 {
   int bit_count = 0;
 
-  bit_count += nok_ltp_encode (fixed_stream, quantInfo->block_type, quantInfo->nr_of_sfb,
+  bit_count += ltp_encode (fixed_stream, quantInfo->block_type, quantInfo->nr_of_sfb,
                                quantInfo->ltpInfo, writeFlag);
 
   return (bit_count);
@@ -413,7 +413,7 @@
 
   /* Set window-dependent TNS parameters */
   if (quantInfo->block_type == ONLY_SHORT_WINDOW) {
-    numWindows = MAX_SHORT_IN_LONG_BLOCK;
+    numWindows = MAX_SHORT_WINDOWS;
     len_tns_nfilt = LEN_TNS_NFILTS;
     len_tns_length = LEN_TNS_LENGTHS;
     len_tns_order = LEN_TNS_ORDERS;
--- a/aac_se_enc.h
+++ b/aac_se_enc.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.7 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.8 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -31,7 +31,7 @@
 
 #include "bitstream.h"
 #include "quant.h"
-#include "nok_ltp_enc.h"
+#include "ltp_enc.h"
 
 extern int max_pred_sfb;
 
--- a/bitstream.c
+++ b/bitstream.c
@@ -21,12 +21,13 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.5 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $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 */
 
--- a/enc_tf.c
+++ b/enc_tf.c
@@ -21,12 +21,13 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.63 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.64 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
 
 #include <stdlib.h>
+#include <memory.h>
 
 #include "aacenc.h"
 #include "bitstream.h"
@@ -37,7 +38,7 @@
 #include "ms.h"
 #include "quant.h"
 #include "aac_se_enc.h"
-#include "nok_ltp_enc.h"
+#include "ltp_enc.h"
 #include "transfo.h"
 
 
@@ -53,8 +54,6 @@
 int max_sfb_l[] = { 49, 49, 47, 48, 49, 51, 47, 47, 43, 43, 43, 40 };
 
 
-int     block_size_samples = 1024;  /* nr of samples per block in one! audio channel */
-int     short_win_in_long  = 8;
 int     max_ch;    /* no of of audio channels */
 double *spectral_line_vector[MAX_TIME_CHANNELS];
 double *reconstructed_spectrum[MAX_TIME_CHANNELS];
@@ -61,7 +60,7 @@
 double *overlap_buffer[MAX_TIME_CHANNELS];
 double *DTimeSigBuf[MAX_TIME_CHANNELS];
 double *DTimeSigLookAheadBuf[MAX_TIME_CHANNELS*2];
-double *nok_tmp_DTimeSigBuf[MAX_TIME_CHANNELS]; /* temporary fix to the buffer size problem. */
+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];
@@ -69,9 +68,8 @@
 enum WINDOW_TYPE next_desired_block_type[MAX_TIME_CHANNELS];
 
 /* Additional variables for AAC */
-int aacAllowScalefacs = 1;              /* Allow AAC scalefactors to be nonconstant */
 TNS_INFO tnsInfo[MAX_TIME_CHANNELS];
-NOK_LT_PRED_STATUS nok_lt_status[MAX_TIME_CHANNELS];
+LT_PRED_STATUS ltp_status[MAX_TIME_CHANNELS];
 
 AACQuantInfo quantInfo[MAX_TIME_CHANNELS];               /* Info structure for AAC quantization and coding */
 
@@ -78,10 +76,7 @@
 /* Channel information */
 Ch_Info channelInfo[MAX_TIME_CHANNELS];
 
-/* AAC shorter windows 960-480-120 */
-int useShortWindows=0;  /* don't use shorter windows */
 
-
 /* EncTfFree() */
 /* Free memory allocated by t/f-based encoder core. */
 
@@ -95,8 +90,8 @@
 
     if (reconstructed_spectrum[chanNum]) free(reconstructed_spectrum[chanNum]);
     if (overlap_buffer[chanNum]) free(overlap_buffer[chanNum]);
-    if (nok_lt_status[chanNum].delay) free(nok_lt_status[chanNum].delay);
-    if (nok_tmp_DTimeSigBuf[chanNum]) free(nok_tmp_DTimeSigBuf[chanNum]);
+    if (ltp_status[chanNum].delay) free(ltp_status[chanNum].delay);
+    if (tmp_DTimeSigBuf[chanNum]) free(tmp_DTimeSigBuf[chanNum]);
   }
   for (chanNum=0;chanNum<MAX_TIME_CHANNELS*2;chanNum++) {
     if (DTimeSigLookAheadBuf[chanNum]) free(DTimeSigLookAheadBuf[chanNum]);
@@ -147,21 +142,21 @@
 
   /* some global initializations */
   for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
-    DTimeSigBuf[chanNum]            = (double*)malloc(block_size_samples*sizeof(double));
-    memset(DTimeSigBuf[chanNum],0,(block_size_samples)*sizeof(double));
-    spectral_line_vector[chanNum]   = (double*)malloc(2*block_size_samples*sizeof(double));
-    reconstructed_spectrum[chanNum] = (double*)malloc(block_size_samples*sizeof(double));
-    memset(reconstructed_spectrum[chanNum], 0, block_size_samples*sizeof(double));
-    overlap_buffer[chanNum] = (double*)malloc(sizeof(double)*block_size_samples);
-    memset(overlap_buffer[chanNum],0,(block_size_samples)*sizeof(double));
+    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;
-    nok_lt_status[chanNum].delay =  (int*)malloc(MAX_SHORT_WINDOWS*sizeof(int));
-    nok_tmp_DTimeSigBuf[chanNum]  = (double*)malloc(2*block_size_samples*sizeof(double));
-    memset(nok_tmp_DTimeSigBuf[chanNum],0,(2*block_size_samples)*sizeof(double));
+    ltp_status[chanNum].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_size_samples)*sizeof(double));
-    memset(DTimeSigLookAheadBuf[chanNum],0,(block_size_samples)*sizeof(double));
+    DTimeSigLookAheadBuf[chanNum]   = (double*)malloc((BLOCK_LEN_LONG)*sizeof(double));
+    memset(DTimeSigLookAheadBuf[chanNum],0,(BLOCK_LEN_LONG)*sizeof(double));
   }
 
   /* initialize psychoacoustic module */
@@ -179,8 +174,8 @@
 
   /* Init LTP predictor */
   for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
-    nok_init_lt_pred (&nok_lt_status[chanNum]);
-    quantInfo[chanNum].ltpInfo = &nok_lt_status[chanNum];  /* Set pointer to LTP data */
+    init_lt_pred (&ltp_status[chanNum]);
+    quantInfo[chanNum].ltpInfo = &ltp_status[chanNum];  /* Set pointer to LTP data */
     quantInfo[chanNum].prev_window_shape = WS_SIN;
   }
 
@@ -270,7 +265,7 @@
 				  int rightChan = channelInfo[chanNum].paired_ch;
 
 				  if (as->use_MS == 1) {
-					  for(i = 0; i < block_size_samples; i++){
+					  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;
 					  }
@@ -278,12 +273,12 @@
 			  }
 
 			  if(as->use_LTP) {
-				  for( i=0; i<block_size_samples; i++ ) {
-					  nok_tmp_DTimeSigBuf[chanNum][i] = DTimeSigBuf[chanNum][i];
-					  nok_tmp_DTimeSigBuf[chanNum][block_size_samples + i] = DTimeSigLookAheadBuf[chanNum][i];
+				  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_size_samples; i++ ) {
+			  for( i=0; i< BLOCK_LEN_LONG; i++ ) {
 				  DTimeSigBuf[chanNum][i] = DTimeSigLookAheadBuf[chanNum][i];
 				  DTimeSigLookAheadBuf[chanNum][i] = as->inputBuffer[chanNum][i];
 			  }
@@ -558,41 +553,41 @@
 	    int leftChan=chanNum;
 	    int rightChan=channelInfo[chanNum].paired_ch;
 
-  	    nok_ltp_enc(spectral_line_vector[leftChan],
-		        nok_tmp_DTimeSigBuf[leftChan],
+  	    ltp_enc(spectral_line_vector[leftChan],
+		        tmp_DTimeSigBuf[leftChan],
 		        block_type[leftChan],
 		        WS_SIN,
 		        &sfb_offset_table[leftChan][0],
 		        nr_of_sfb[leftChan],
-		        &nok_lt_status[leftChan]);
+		        &ltp_status[leftChan]);
 
-            nok_lt_status[rightChan].global_pred_flag = nok_lt_status[leftChan].global_pred_flag;
+            ltp_status[rightChan].global_pred_flag = ltp_status[leftChan].global_pred_flag;
   	    for(i = 0; i < BLOCK_LEN_LONG; i++)
-    	      nok_lt_status[rightChan].pred_mdct[i] = nok_lt_status[leftChan].pred_mdct[i];
+    	      ltp_status[rightChan].pred_mdct[i] = ltp_status[leftChan].pred_mdct[i];
   	    for(i = 0; i < MAX_SCFAC_BANDS; i++)
-  	      nok_lt_status[rightChan].sfb_prediction_used[i] = nok_lt_status[leftChan].sfb_prediction_used[i];
-  	    nok_lt_status[rightChan].weight = nok_lt_status[leftChan].weight;
-	    nok_lt_status[rightChan].delay[0] = nok_lt_status[leftChan].delay[0];
+  	      ltp_status[rightChan].sfb_prediction_used[i] = ltp_status[leftChan].sfb_prediction_used[i];
+  	    ltp_status[rightChan].weight = ltp_status[leftChan].weight;
+	    ltp_status[rightChan].delay[0] = ltp_status[leftChan].delay[0];
 
 	    if (!channelInfo[leftChan].common_window) {
-	      nok_ltp_enc(spectral_line_vector[rightChan],
-			  nok_tmp_DTimeSigBuf[rightChan],
+	      ltp_enc(spectral_line_vector[rightChan],
+			  tmp_DTimeSigBuf[rightChan],
 			  block_type[rightChan],
 			  WS_SIN,
 			  &sfb_offset_table[rightChan][0],
 			  nr_of_sfb[rightChan],
-			  &nok_lt_status[rightChan]);
+			  &ltp_status[rightChan]);
             }
           } /* if(channelInfo[chanNum].ch_is_left) */
         } /* if(channelInfo[chanNum].cpe) */
         else
-	  nok_ltp_enc(spectral_line_vector[chanNum],
-		      nok_tmp_DTimeSigBuf[chanNum],
+	  ltp_enc(spectral_line_vector[chanNum],
+		      tmp_DTimeSigBuf[chanNum],
 		      block_type[chanNum],
 		      WS_SIN,
 		      &sfb_offset_table[chanNum][0],
 		      nr_of_sfb[chanNum],
-		      &nok_lt_status[chanNum]);
+		      &ltp_status[chanNum]);
       } /* if(channelInfo[chanNum].present... */
       else
         quantInfo[chanNum].ltpInfo->global_pred_flag = 0;
@@ -686,12 +681,12 @@
     if(as->use_LTP)
       for (chanNum=0;chanNum<max_ch;chanNum++) {
 		  if (!channelInfo[chanNum].lfe) {  /* no reconstruction needed for LFE channel*/
-			  nok_ltp_reconstruct(reconstructed_spectrum[chanNum],
+			  ltp_reconstruct(reconstructed_spectrum[chanNum],
 				  block_type[chanNum],
 				  WS_SIN,
 				  &sfb_offset_table[chanNum][0],
 				  nr_of_sfb[chanNum],
-				  &nok_lt_status[chanNum]);
+				  &ltp_status[chanNum]);
 		  }
       }
 
--- a/faac.dsp
+++ b/faac.dsp
@@ -116,19 +116,15 @@
 # End Source File
 # Begin Source File
 
-SOURCE=.\mc_enc.c
+SOURCE=.\ltp_enc.c
 # End Source File
 # Begin Source File
 
-SOURCE=.\ms.c
+SOURCE=.\mc_enc.c
 # End Source File
 # Begin Source File
 
-SOURCE=.\nok_ltp_enc.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\nok_pitch.c
+SOURCE=.\ms.c
 # End Source File
 # Begin Source File
 
--- a/faac_dll.dsp
+++ b/faac_dll.dsp
@@ -120,19 +120,15 @@
 # End Source File
 # Begin Source File
 
-SOURCE=.\mc_enc.c
+SOURCE=.\ltp_enc.c
 # End Source File
 # Begin Source File
 
-SOURCE=.\ms.c
+SOURCE=.\mc_enc.c
 # End Source File
 # Begin Source File
 
-SOURCE=.\nok_ltp_enc.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\nok_pitch.c
+SOURCE=.\ms.c
 # End Source File
 # Begin Source File
 
--- a/huffman.c
+++ b/huffman.c
@@ -21,10 +21,12 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.4 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.5 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
+
+#include <math.h>
 
 #include "aacenc.h"
 #include "bitstream.h"
--- a/huffman.h
+++ b/huffman.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.5 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.6 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -32,7 +32,6 @@
 #include "pulse.h"
 #include "interface.h"
 #include "tns.h"
-#include "nok_ltp_common.h"
 
 #ifdef __cplusplus
 extern "C" {
--- a/interface.h
+++ b/interface.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.3 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.4 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -44,83 +44,29 @@
 
 #define NSFB_LONG  51
 #define NSFB_SHORT 15
-#define MAX_SHORT_IN_LONG_BLOCK 8
 
 #define MAX_SHORT_WINDOWS 8
 
 /* if static memory allocation is used, this value tells the max. nr of
    audio channels to be supported */
-/*#define MAX_TIME_CHANNELS (MAX_CHANNELS)*/
 #define MAX_TIME_CHANNELS 6
 
 /* max. number of scale factor bands */
-#define MAX_SCFAC_BANDS ((NSFB_SHORT+1)*MAX_SHORT_IN_LONG_BLOCK)
+#define MAX_SCFAC_BANDS ((NSFB_SHORT+1)*MAX_SHORT_WINDOWS)
 
-#define IN_DATATYPE  double
-#define OUT_DATATYPE double
-
 #define BLOCK_LEN_LONG	   1024
 #define BLOCK_LEN_SHORT    128
 
-#define NWINLONG	(BLOCK_LEN_LONG)
-#define ALFALONG	4.0
-#define NWINSHORT	(BLOCK_LEN_SHORT)
-#define ALFASHORT	7.0
 
-#define	NWINFLAT	(NWINLONG)					/* flat params */
-#define	NWINADV		(NWINLONG-NWINSHORT)		/* Advanced flat params */
-#define NFLAT		((NWINFLAT-NWINSHORT)/2)
-#define NADV0		((NWINADV-NWINSHORT)/2)
-
-
 typedef enum {
     WS_SIN, WS_KBD, N_WINDOW_SHAPES
-} 
-Window_shape;
+} Window_shape;
 
-/* YT 970615 for Son_PP  */
 typedef enum {
 	MOVERLAPPED,
 	MNON_OVERLAPPED
-}
-Mdct_in,Imdct_out;
+} Mdct_in,Imdct_out;
 
-typedef enum {
-    WT_LONG, 
-    WT_SHORT, 
-    WT_FLAT, 
-    WT_ADV,			/* Advanced flat window */
-    N_WINDOW_TYPES
-} 
-WINDOW_TYPE_AAC; 
-
-typedef enum {                  /* ADVanced transform types */
-    LONG_BLOCK,
-    START_BLOCK,
-    SHORT_BLOCK,
-    STOP_BLOCK,
-    START_ADV_BLOCK,
-    STOP_ADV_BLOCK,
-    START_FLAT_BLOCK,
-    STOP_FLAT_BLOCK,
-    N_BLOCK_TYPES
-} 
-BLOCK_TYPE;
-
-typedef enum {  		/* Advanced window sequence (frame) types */
-    ONLY_LONG,
-    LONG_START, 
-    LONG_STOP,
-    SHORT_START, 
-    SHORT_STOP,
-    EIGHT_SHORT, 
-    SHORT_EXT_STOP,
-    NINE_SHORT,
-    OLD_START,
-    OLD_STOP,
-    N_WINDOW_SEQUENCES
-} 
-WINDOW_SEQUENCE;
 
 
 /* 
--- /dev/null
+++ b/ltp_enc.c
@@ -1,0 +1,901 @@
+/*
+ *	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.1 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
+  $Author: menno $
+  *************************************************************************/
+
+#include <stdio.h>
+#include <math.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 (BsBitStream *bs, enum WINDOW_TYPE win_type, int num_of_sfb, 
+            LT_PRED_STATUS *lt_status, int write_flag)
+{
+	int i, last_band;
+//	int first_subblock;
+//	int prev_subblock;
+	int bit_count = 0;
+
+
+	bit_count += 1;
+	
+	if (lt_status->side_info > 1)
+	{
+		if(write_flag)
+			BsPutBit (bs, 1, 1);    	/* LTP used */
+
+		switch(win_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, lt_status->delay[0], LEN_LTP_LAG);
+				BsPutBit (bs, lt_status->weight_idx,  LEN_LTP_COEF);
+			}
+
+			last_band = (num_of_sfb < MAX_LT_PRED_LONG_SFB) ? num_of_sfb : MAX_LT_PRED_LONG_SFB;
+			bit_count += last_band;
+			if(write_flag)
+			{
+				for (i = 0; i < last_band; i++)
+					BsPutBit (bs, lt_status->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);
+}
--- /dev/null
+++ b/ltp_enc.h
@@ -1,0 +1,124 @@
+/*
+ *	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.1 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
+  $Author: menno $
+  *************************************************************************/
+
+#ifndef _LTP_ENC_H
+#define _LTP_ENC_H
+
+#include "interface.h"
+#include "bitstream.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
+{
+    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 (BsBitStream *bs, enum WINDOW_TYPE win_type, int num_of_sfb, 
+                       LT_PRED_STATUS *lt_status, int write_flag);
+
+#endif /* not defined _LTP_ENC_H */
+
--- a/nok_ltp_common.h
+++ /dev/null
@@ -1,67 +1,0 @@
-/*
- *	Common definitions 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.4 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _NOK_LTP_COMMON_H
-#define _NOK_LTP_COMMON_H
-
-/*
-  Macro:	MAX_SHORT_WINDOWS
-  Purpose:	Number of short windows in one long window.
-  Explanation:	-  */
-#ifndef MAX_SHORT_WINDOWS
-#define MAX_SHORT_WINDOWS MAX_SHORT_IN_LONG_BLOCK
-#endif
-
-/*
-  Macro:	NOK_LT_BLEN
-  Purpose:	Length of the history buffer.
-  Explanation:	Has to hold two long windows of time domain data.  */
-#ifndef	NOK_LT_BLEN
-#define NOK_LT_BLEN (4 * BLOCK_LEN_LONG)
-#endif
-
-/*
-  Type:		NOK_LT_PRED_STATUS
-  Purpose:	Type of the struct holding the LTP encoding parameters.
-  Explanation:	-  */
-typedef struct
-  {
-    short buffer[NOK_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;
-  }
-NOK_LT_PRED_STATUS;
-
-
-#endif /* _NOK_LTP_COMMON_H */
--- a/nok_ltp_common_internal.h
+++ /dev/null
@@ -1,100 +1,0 @@
-/*
- *	Internal definitions 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.3 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _NOK_LTP_COMMON_INTERNAL_H
-#define _NOK_LTP_COMMON_INTERNAL_H
-
-
-/*
-  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	NOK_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..NOK_MAX_LT_PRED_SFB-1 can use lt prediction.  */
-#define	NOK_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..NOK_MAX_LT_PRED_SFB-1 can use lt prediction.  */
-#define	NOK_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;
-
-
-#endif /* _NOK_LTP_COMMON_INTERNAL_H */
--- a/nok_ltp_enc.c
+++ /dev/null
@@ -1,492 +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.14 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-/**************************************************************************
-  External Objects Needed
-  *************************************************************************/
-/*
-  Standard library declarations.  */
-#include <stdio.h>
-
-/*
-  Interface to related modules.  */
-#include "interface.h"
-#include "transfo.h"
-#include "bitstream.h"
-#include "nok_ltp_common.h"
-#include "nok_pitch.h"
-
-/**************************************************************************
-  External Objects Provided
-  *************************************************************************/
-#include "nok_ltp_enc.h"
-
-/**************************************************************************
-  Internal Objects
-  *************************************************************************/
-#include "nok_ltp_common_internal.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))))
-
-
-/**************************************************************************
-  Title:	nok_init_lt_pred
-
-  Purpose:	Initialize the history buffer for long term prediction
-
-  Usage:        nok_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
-nok_init_lt_pred (NOK_LT_PRED_STATUS *lt_status)
-{
-	int i;
-
-	for (i = 0; i < NOK_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_IN_LONG_BLOCK; 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:	nok_ltp_enc
-
-  Purpose:      Performs long term prediction.
-
-  Usage:	nok_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 nok_pitch.c
-                2.) pitch in nok_pitch.c
-                3.) buffer2freq
-                4.) snr_pred in nok_pitch.c
-                5.) freq2buffer
-                6.) double_to_int
-
-  Explanation:  -
-
-  Author(s):	Juha Ojanpera
-  *************************************************************************/
-
-int
-nok_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,
-            NOK_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 < NOK_MAX_LT_PRED_LONG_SFB) ? num_of_sfb : NOK_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:	nok_ltp_reconstruct
-
-  Purpose:      Updates LTP history buffer.
-
-  Usage:	nok_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
-nok_ltp_reconstruct(double *p_spectrum, enum WINDOW_TYPE win_type, 
-                    Window_shape win_shape, int *sfb_offset, int num_of_sfb,
-                    NOK_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 < NOK_MAX_LT_PRED_LONG_SFB) ? num_of_sfb : NOK_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 < NOK_LT_BLEN - BLOCK_LEN_LONG; i++)
-			lt_status->buffer[i] = lt_status->buffer[i + BLOCK_LEN_LONG];
-
-		j = NOK_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[NOK_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 < NOK_LT_BLEN - block_size_long; i++)
-			lt_status->buffer[i] = lt_status->buffer[i + block_size_long];
-
-		for (i = NOK_LT_BLEN - block_size_long; i < NOK_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 = NOK_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:	nok_ltp_encode
-
-  Purpose:      Writes LTP parameters to the bit stream.
-
-  Usage:	nok_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
-nok_ltp_encode (BsBitStream *bs, enum WINDOW_TYPE win_type, int num_of_sfb, 
-                NOK_LT_PRED_STATUS *lt_status, int write_flag)
-{
-	int i, last_band;
-//	int first_subblock;
-//	int prev_subblock;
-	int bit_count = 0;
-
-
-	bit_count += 1;
-	
-	if (lt_status->side_info > 1)
-	{
-		if(write_flag)
-			BsPutBit (bs, 1, 1);    	/* LTP used */
-
-		switch(win_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, lt_status->delay[0], LEN_LTP_LAG);
-				BsPutBit (bs, lt_status->weight_idx,  LEN_LTP_COEF);
-			}
-
-			last_band = (num_of_sfb < NOK_MAX_LT_PRED_LONG_SFB) ? num_of_sfb : NOK_MAX_LT_PRED_LONG_SFB;
-			bit_count += last_band;
-			if(write_flag)
-			{
-				for (i = 0; i < last_band; i++)
-					BsPutBit (bs, lt_status->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 + NOK_LTP_LAG_OFFSET, LEN_LTP_SHORT_LAG);
-							}
-						}
-						else
-						{
-							bit_count += 1;
-							if(write_flag)
-								BsPutBit (bs, 0, 1);
-						}
-					}
-				}
-			}
-			break;
-#endif
-		default:
-			//        CommonExit(1, "nok_ltp_encode : unsupported window sequence %i", win_type);
-			break;
-		}
-	}
-	else
-		if(write_flag)
-			BsPutBit (bs, 0, 1);    	/* LTP not used */
-
-	return (bit_count);
-}
-
-
-/**************************************************************************
-  Title:	double_to_int
-
-  Purpose:      Converts floating point format to integer (16-bit).
-
-  Usage:	y = double_to_int(sig_in)
-
-  Input:	sig_in  - floating point number
-
-  Output:	y  - integer number
-
-  References:	-
-
-  Explanation:  -
-
-  Author(s):	Juha Ojanpera
-  *************************************************************************/
-
-/*short
-double_to_int (double sig_in)
-{
-	short sig_out;
-
-	if (sig_in > 32767)
-		sig_out = 32767;
-	else if (sig_in < -32768)
-		sig_out = -32768;
-	else if (sig_in > 0.0)
-		sig_out = (short) (sig_in + 0.5);
-	else if (sig_in <= 0.0)
-		sig_out = (short) (sig_in - 0.5);
-
-	return (sig_out);
-}
-*/
--- a/nok_ltp_enc.h
+++ /dev/null
@@ -1,52 +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.4 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef _NOK_LTP_ENC_H
-#define _NOK_LTP_ENC_H
-
-#include "interface.h"
-#include "bitstream.h"
-#include "nok_ltp_common.h"
-
-extern void nok_init_lt_pred (NOK_LT_PRED_STATUS * lt_status);
-
-extern int nok_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,
-		       NOK_LT_PRED_STATUS *lt_status);
-
-extern void nok_ltp_reconstruct(double *p_spectrum, enum WINDOW_TYPE win_type, 
-                                Window_shape win_shape, 
-                                int *sfb_offset, int num_of_sfb,
-                                NOK_LT_PRED_STATUS *lt_status);
-
-extern int nok_ltp_encode (BsBitStream *bs, enum WINDOW_TYPE win_type, int num_of_sfb, 
-                           NOK_LT_PRED_STATUS *lt_status, int write_flag);
-
-#endif /* not defined _NOK_LTP_ENC_H */
-
--- a/nok_pitch.c
+++ /dev/null
@@ -1,514 +1,0 @@
-/*
- *	Long Term Prediction 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.9 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-/**************************************************************************
-  External Objects Needed
-  *************************************************************************/
-
-/*
-  Interface to related modules.  */
-#include "interface.h"
-#include "nok_ltp_common.h"
-#include "nok_ltp_enc.h"
-
-/*************************************************************************
-  External Objects Provided
-  *************************************************************************/
-#include "nok_pitch.h"
-
-
-
-/**************************************************************************
-  Internal Objects
-  *************************************************************************/
-#include "nok_ltp_common_internal.h"
-
-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 = NOK_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[NOK_LT_BLEN - j] * sb_samples[2048 - j];
-			energy += x_buffer[NOK_LT_BLEN - j] * x_buffer[NOK_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++)
-	{
-//NOK_LT_BLEN=4096
-		energy -= x_buffer[NOK_LT_BLEN - i] * x_buffer[NOK_LT_BLEN - i];
-		energy += x_buffer[NOK_LT_BLEN - i - 2048] * x_buffer[NOK_LT_BLEN - i - 2048]; //2048=j_max
-		corr[i] = corrtmp;
-		corr[i] -= x_buffer[NOK_LT_BLEN - i] * sb_samples[2047];
-		corr[i] += x_buffer[NOK_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[NOK_LT_BLEN - i - j] * sb_samples[2048 - j];
-//			energy += x_buffer[NOK_LT_BLEN - i - j] * x_buffer[NOK_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 = NOK_LT_BLEN - flen - delay + i - (LPC - 1) / 2;
-			offset2 = NOK_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 = NOK_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]];
-}
-
--- a/nok_pitch.h
+++ /dev/null
@@ -1,47 +1,0 @@
-/*
- *	Function prototypes for LTP 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.3 $
-  $Date: 2000/10/05 08:39:02 $ (check in)
-  $Author: menno $
-  *************************************************************************/
-
-#ifndef NOK_PITCH_H_
-#define NOK_PITCH_H_
-
-
-extern 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);
-
-extern void prediction (short *buffer, double *predicted_samples, double *weight,
-                        int delay, int flen);
-
-//extern int estimate_delay (double *sb_samples, short *x_buffer, int flen);
-extern int estimate_delay (double *sb_samples, short *x_buffer);
-
-extern void pitch (double *sb_samples, double *sb_samples_pred, short *x_buffer,
-                   int *ltp_coef, int delay, int flen);
-
-
-#endif
--- a/psych.c
+++ b/psych.c
@@ -21,12 +21,14 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.68 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.69 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
 
 #include <math.h>
+#include <memory.h>
+
 #include "psych.h"
 #include "transfo.h"
 
--- a/pulse.c
+++ b/pulse.c
@@ -21,10 +21,12 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.3 $
-  $Date: 2000/10/05 08:39:03 $ (check in)
+  $Revision: 1.4 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
+
+#include <math.h>
 
 #include "quant.h"
 #include "huffman.h"
--- a/quant.c
+++ b/quant.c
@@ -21,12 +21,14 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.10 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.11 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
 
 #include <math.h>
+#include <memory.h>
+
 #include "aacenc.h"
 #include "quant.h"
 #include "bitstream.h"
--- a/quant.h
+++ b/quant.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.4 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.5 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -32,7 +32,7 @@
 #include "pulse.h"
 #include "interface.h"
 #include "tns.h"
-#include "nok_ltp_common.h"
+#include "ltp_enc.h"
 #include "bitstream.h"
 
 #ifdef __cplusplus
@@ -76,8 +76,7 @@
                                            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_IN_LONG_BLOCK];          /* Length (in windows) of each window group */
+  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 */
@@ -86,7 +85,7 @@
   int reset_group_number;               /* Prediction reset group number */
   TNS_INFO* tnsInfo;                    /* Ptr to tns data */
   AACPulseInfo pulseInfo;
-  NOK_LT_PRED_STATUS *ltpInfo;          /* Prt to LTP data */
+  LT_PRED_STATUS *ltpInfo;              /* Prt to LTP data */
   int pns_sfb_nrg[MAX_SCFAC_BANDS];
   int pns_sfb_flag[MAX_SCFAC_BANDS];
   int profile;
--- a/tns.c
+++ b/tns.c
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.12 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.13 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -131,7 +131,7 @@
 
 	switch( blockType ) {
 	case ONLY_SHORT_WINDOW :
-		numberOfWindows = MAX_SHORT_IN_LONG_BLOCK;
+		numberOfWindows = MAX_SHORT_WINDOWS;
 		windowSize = BLOCK_LEN_SHORT;
 		startBand = tnsInfo->tnsMinBandNumberShort;
 		stopBand = numberOfBands; 
--- a/tns.h
+++ b/tns.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.6 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $Revision: 1.7 $
+  $Date: 2000/10/06 14:47:27 $ (check in)
   $Author: menno $
   *************************************************************************/
  
@@ -78,7 +78,7 @@
   int tnsMaxBandsShort;
   int tnsMaxOrderLong;
   int tnsMaxOrderShort;
-  TNS_WINDOW_DATA windowData[MAX_SHORT_IN_LONG_BLOCK];	/* TNS data per window */
+  TNS_WINDOW_DATA windowData[MAX_SHORT_WINDOWS];	/* TNS data per window */
 } TNS_INFO;
 
 
--- a/transfo.c
+++ b/transfo.c
@@ -21,12 +21,14 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.18 $
-  $Date: 2000/10/05 13:04:05 $ (check in)
+  $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"