/**************************************************************************
 *
 *   File Name:  d_homing.c
 *
 *   Purpose:
 *      This file contains the following functions:
 *
 *      decoder_reset()              called to reset all of
 *                                   the state variables for the decoder
 *
 **************************************************************************/

#include "typedef.h"
#include "cnst.h"
#include "codec.h"
#include "d_homing.h"
#include "q_plsf_5.tab"


/***************************************************************************
 *
 *   FUNCTION NAME:  decoder_reset
 *
 *   PURPOSE:
 *      resets all of the state variables for the decoder
 *
 *   INPUT:
 *      None
 *
 *   OUTPUT:
 *      None
 *
 *   RETURN:
 *      None
 *
 **************************************************************************/

void decoder_reset (void)
{
    /* External declarations for decoder variables which need to be reset */

    /* variable defined in decoder.c */
    /* ----------------------------- */
    extern Word16 synth_buf[L_FRAME + M];

    /* variable defined in agc.c */
    /* -------------------------- */
    extern Word16 past_gain;

    /* variables defined in d_gains.c */
    /* ------------------------------ */

    /* Memories of gain dequantization: */
    extern Word16 past_qua_en[4], pred[4];

    /* variables defined in d_plsf_5.c */
    /* ------------------------------ */
    /* Past quantized prediction error */
    extern Word16 past_r2_q[M];

    /* variables defined in dec_lag6.c */
    /* ------------------------------ */
    extern Word16 old_T0;

    /* variable defined in preemph.c */
    /* ------------------------------ */
    extern Word16 mem_pre;

    Word16 i;

    /* reset all the decoder state variables */
    /* ------------------------------------- */

    /* Variable in decoder.c: */
    for (i = 0; i < M; i++)
    {
        synth_buf[i] = 0;
    }

    /* Variables in dec_12k2.c: */
    Init_Decoder_12k2 ();

    /* Variable in agc.c: */
    past_gain = 4096;

    /* Variables in d_gains.c: */

    for (i = 0; i < 4; i++)
    {
        past_qua_en[i] = -2381; /* past quantized energies */
    }

    pred[0] = 44;               /* MA prediction coeff */
    pred[1] = 37;               /* MA prediction coeff */
    pred[2] = 22;               /* MA prediction coeff */
    pred[3] = 12;               /* MA prediction coeff */

    /* Variables in d_plsf_5.c: */
    for (i = 0; i < M; i++)
    {
        past_r2_q[i] = 0;               /* Past quantized prediction error */
    }

    /* Variable in dec_lag6.c: */
    old_T0 = 40;                /* Old integer lag */

    /* Variable in preemph.c: */
    mem_pre = 0;                /* Filter memory */

    /* Variables in pstfilt2.c: */
    Init_Post_Filter ();
}
