Index: pjproject/trunk/pjmedia/src/pjmedia-codec/speex/nb_celp.h
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia-codec/speex/nb_celp.h	(revision 278)
+++ pjproject/trunk/pjmedia/src/pjmedia-codec/speex/nb_celp.h	(revision 628)
@@ -49,18 +49,18 @@
 /**Structure representing the full state of the narrowband encoder*/
 typedef struct EncState {
-   const SpeexMode *mode;       /**< Mode corresponding to the state */
-   int    first;          /**< Is this the first frame? */
-   int    frameSize;      /**< Size of frames */
-   int    subframeSize;   /**< Size of sub-frames */
-   int    nbSubframes;    /**< Number of sub-frames */
-   int    windowSize;     /**< Analysis (LPC) window length */
-   int    lpcSize;        /**< LPC order */
-   int    min_pitch;      /**< Minimum pitch value allowed */
-   int    max_pitch;      /**< Maximum pitch value allowed */
+   const SpeexMode *mode;        /**< Mode corresponding to the state */
+   int    first;                 /**< Is this the first frame? */
+   int    frameSize;             /**< Size of frames */
+   int    subframeSize;          /**< Size of sub-frames */
+   int    nbSubframes;           /**< Number of sub-frames */
+   int    windowSize;            /**< Analysis (LPC) window length */
+   int    lpcSize;               /**< LPC order */
+   int    min_pitch;             /**< Minimum pitch value allowed */
+   int    max_pitch;             /**< Maximum pitch value allowed */
 
-   int    safe_pitch;     /**< Don't use too large values for pitch (in case we lose a packet) */
-   int    bounded_pitch;  /**< Next frame should not rely on previous frames for pitch */
-   int    ol_pitch;       /**< Open-loop pitch */
-   int    ol_voiced;      /**< Open-loop voiced/non-voiced decision */
+   spx_word32_t cumul_gain;      /**< Product of previously used pitch gains (Q10) */
+   int    bounded_pitch;         /**< Next frame should not rely on previous frames for pitch */
+   int    ol_pitch;              /**< Open-loop pitch */
+   int    ol_voiced;             /**< Open-loop voiced/non-voiced decision */
    int   *pitch;
 
@@ -71,4 +71,5 @@
 #ifdef VORBIS_PSYCHO
    VorbisPsy *psy;
+   float *psy_window;
    float *curve;
    float *old_curve;
@@ -77,52 +78,43 @@
    spx_word16_t  gamma1;         /**< Perceptual filter: A(z/gamma1) */
    spx_word16_t  gamma2;         /**< Perceptual filter: A(z/gamma2) */
-   float  lag_factor;     /**< Lag windowing Gaussian width */
+   float  lag_factor;            /**< Lag windowing Gaussian width */
    spx_word16_t  lpc_floor;      /**< Noise floor multiplier for A[0] in LPC analysis*/
-   char  *stack;          /**< Pseudo-stack allocation for temporary memory */
-   spx_sig_t *inBuf;          /**< Input buffer (original signal) */
-   spx_sig_t *frame;          /**< Start of original frame */
-   spx_sig_t *excBuf;         /**< Excitation buffer */
-   spx_sig_t *exc;            /**< Start of excitation frame */
-   spx_sig_t *swBuf;          /**< Weighted signal buffer */
-   spx_sig_t *sw;             /**< Start of weighted signal frame */
-   spx_sig_t *innov;          /**< Innovation for the frame */
-   spx_word16_t *window;         /**< Temporary (Hanning) window */
-   spx_word16_t *autocorr;       /**< auto-correlation */
+   char  *stack;                 /**< Pseudo-stack allocation for temporary memory */
+   spx_word16_t *winBuf;         /**< Input buffer (original signal) */
+   spx_word16_t *excBuf;         /**< Excitation buffer */
+   spx_word16_t *exc;            /**< Start of excitation frame */
+   spx_word16_t *swBuf;          /**< Weighted signal buffer */
+   spx_word16_t *sw;             /**< Start of weighted signal frame */
+   const spx_word16_t *window;   /**< Temporary (Hanning) window */
    spx_word16_t *lagWindow;      /**< Window applied to auto-correlation */
-   spx_coef_t *lpc;            /**< LPCs for current frame */
-   spx_lsp_t *lsp;            /**< LSPs for current frame */
-   spx_lsp_t *qlsp;           /**< Quantized LSPs for current frame */
-   spx_lsp_t *old_lsp;        /**< LSPs for previous frame */
-   spx_lsp_t *old_qlsp;       /**< Quantized LSPs for previous frame */
-   spx_lsp_t *interp_lsp;     /**< Interpolated LSPs */
-   spx_lsp_t *interp_qlsp;    /**< Interpolated quantized LSPs */
-   spx_coef_t *interp_lpc;     /**< Interpolated LPCs */
-   spx_coef_t *interp_qlpc;    /**< Interpolated quantized LPCs */
-   spx_coef_t *bw_lpc1;        /**< LPCs after bandwidth expansion by gamma1 for perceptual weighting*/
-   spx_coef_t *bw_lpc2;        /**< LPCs after bandwidth expansion by gamma2 for perceptual weighting*/
-   spx_mem_t *mem_sp;         /**< Filter memory for signal synthesis */
-   spx_mem_t *mem_sw;         /**< Filter memory for perceptually-weighted signal */
-   spx_mem_t *mem_sw_whole;   /**< Filter memory for perceptually-weighted signal (whole frame)*/
-   spx_mem_t *mem_exc;        /**< Filter memory for excitation (whole frame) */
+   spx_lsp_t *old_lsp;           /**< LSPs for previous frame */
+   spx_lsp_t *old_qlsp;          /**< Quantized LSPs for previous frame */
+   spx_mem_t *mem_sp;            /**< Filter memory for signal synthesis */
+   spx_mem_t *mem_sw;            /**< Filter memory for perceptually-weighted signal */
+   spx_mem_t *mem_sw_whole;      /**< Filter memory for perceptually-weighted signal (whole frame)*/
+   spx_mem_t *mem_exc;           /**< Filter memory for excitation (whole frame) */
+   spx_mem_t *mem_exc2;          /**< Filter memory for excitation (whole frame) */
    spx_word32_t *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */
-
-   VBRState *vbr;         /**< State of the VBR data */
-   float  vbr_quality;    /**< Quality setting for VBR encoding */
-   float  relative_quality; /**< Relative quality that will be needed by VBR */
-   int    vbr_enabled;    /**< 1 for enabling VBR, 0 otherwise */
-   int    vad_enabled;    /**< 1 for enabling VAD, 0 otherwise */
-   int    dtx_enabled;    /**< 1 for enabling DTX, 0 otherwise */
-   int    dtx_count;      /**< Number of consecutive DTX frames */
-   int    abr_enabled;    /**< ABR setting (in bps), 0 if off */
+   spx_sig_t *innov_save;        /**< If non-NULL, innovation is copied here */
+         
+   VBRState *vbr;                /**< State of the VBR data */
+   float  vbr_quality;           /**< Quality setting for VBR encoding */
+   float  relative_quality;      /**< Relative quality that will be needed by VBR */
+   int    vbr_enabled;           /**< 1 for enabling VBR, 0 otherwise */
+   spx_int32_t vbr_max;          /**< Max bit-rate allowed in VBR mode */
+   int    vad_enabled;           /**< 1 for enabling VAD, 0 otherwise */
+   int    dtx_enabled;           /**< 1 for enabling DTX, 0 otherwise */
+   int    dtx_count;             /**< Number of consecutive DTX frames */
+   spx_int32_t abr_enabled;      /**< ABR setting (in bps), 0 if off */
    float  abr_drift;
    float  abr_drift2;
    float  abr_count;
-   int    complexity;     /**< Complexity setting (0-10 from least complex to most complex) */
-   int    sampling_rate;
+   int    complexity;            /**< Complexity setting (0-10 from least complex to most complex) */
+   spx_int32_t sampling_rate;
    int    plc_tuning;
    int    encode_submode;
    const SpeexSubmode * const *submodes; /**< Sub-mode data */
-   int    submodeID;      /**< Activated sub-mode */
-   int    submodeSelect;  /**< Mode chosen by the user (may differ from submodeID if VAD is on) */
+   int    submodeID;             /**< Activated sub-mode */
+   int    submodeSelect;         /**< Mode chosen by the user (may differ from submodeID if VAD is on) */
 } EncState;
 
@@ -130,13 +122,13 @@
 typedef struct DecState {
    const SpeexMode *mode;       /**< Mode corresponding to the state */
-   int    first;          /**< Is this the first frame? */
-   int    count_lost;     /**< Was the last frame lost? */
-   int    frameSize;      /**< Size of frames */
-   int    subframeSize;   /**< Size of sub-frames */
-   int    nbSubframes;    /**< Number of sub-frames */
-   int    lpcSize;        /**< LPC order */
-   int    min_pitch;      /**< Minimum pitch value allowed */
-   int    max_pitch;      /**< Maximum pitch value allowed */
-   int    sampling_rate;
+   int    first;                /**< Is this the first frame? */
+   int    count_lost;           /**< Was the last frame lost? */
+   int    frameSize;            /**< Size of frames */
+   int    subframeSize;         /**< Size of sub-frames */
+   int    nbSubframes;          /**< Number of sub-frames */
+   int    lpcSize;              /**< LPC order */
+   int    min_pitch;            /**< Minimum pitch value allowed */
+   int    max_pitch;            /**< Maximum pitch value allowed */
+   spx_int32_t sampling_rate;
 
 #ifdef EPIC_48K
@@ -144,29 +136,26 @@
 #endif
 
-   spx_word16_t  last_ol_gain;   /**< Open-loop gain for previous frame */
+   spx_word16_t  last_ol_gain;  /**< Open-loop gain for previous frame */
 
-   char  *stack;          /**< Pseudo-stack allocation for temporary memory */
-   spx_sig_t *inBuf;          /**< Input buffer (original signal) */
-   spx_sig_t *frame;          /**< Start of original frame */
-   spx_sig_t *excBuf;         /**< Excitation buffer */
-   spx_sig_t *exc;            /**< Start of excitation frame */
-   spx_sig_t *innov;          /**< Innovation for the frame */
-   spx_lsp_t *qlsp;           /**< Quantized LSPs for current frame */
-   spx_lsp_t *old_qlsp;       /**< Quantized LSPs for previous frame */
-   spx_lsp_t *interp_qlsp;    /**< Interpolated quantized LSPs */
-   spx_coef_t *interp_qlpc;    /**< Interpolated quantized LPCs */
-   spx_mem_t *mem_sp;         /**< Filter memory for synthesis signal */
-   spx_word32_t *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */
-   int    last_pitch;     /**< Pitch of last correctly decoded frame */
+   char  *stack;                /**< Pseudo-stack allocation for temporary memory */
+   spx_word16_t *excBuf;        /**< Excitation buffer */
+   spx_word16_t *exc;           /**< Start of excitation frame */
+   spx_lsp_t *old_qlsp;         /**< Quantized LSPs for previous frame */
+   spx_coef_t *interp_qlpc;     /**< Interpolated quantized LPCs */
+   spx_mem_t *mem_sp;           /**< Filter memory for synthesis signal */
+   spx_word32_t *pi_gain;       /**< Gain of LPC filter at theta=pi (fe/2) */
+   spx_sig_t *innov_save;       /** If non-NULL, innovation is copied here */
+   
+   /* This is used in packet loss concealment */
+   int    last_pitch;           /**< Pitch of last correctly decoded frame */
    spx_word16_t  last_pitch_gain; /**< Pitch gain of last correctly decoded frame */
-   spx_word16_t  pitch_gain_buf[3];  /**< Pitch gain of last decoded frames */
-   int    pitch_gain_buf_idx; /**< Tail of the buffer */
-   spx_int32_t seed;          /** Seed used for random number generation */
+   spx_word16_t  pitch_gain_buf[3]; /**< Pitch gain of last decoded frames */
+   int    pitch_gain_buf_idx;   /**< Tail of the buffer */
+   spx_int32_t seed;            /** Seed used for random number generation */
    
    int    encode_submode;
    const SpeexSubmode * const *submodes; /**< Sub-mode data */
-   int    submodeID;      /**< Activated sub-mode */
-   int    lpc_enh_enabled; /**< 1 when LPC enhancer is on, 0 otherwise */
-   CombFilterMem *comb_mem;
+   int    submodeID;            /**< Activated sub-mode */
+   int    lpc_enh_enabled;      /**< 1 when LPC enhancer is on, 0 otherwise */
    SpeexCallback speex_callbacks[SPEEX_MAX_CALLBACKS];
 
@@ -174,6 +163,6 @@
 
    /*Vocoder data*/
-   float  voc_m1;
-   float  voc_m2;
+   spx_word16_t  voc_m1;
+   spx_word32_t  voc_m2;
    float  voc_mean;
    int    voc_offset;
