⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpisf_2s.c

📁 通讯协议
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-------------------------------------------------------------------*
 *                         QPISF_2S.C								 *
 *-------------------------------------------------------------------*
 * Coding/Decoding of ISF parameters  with prediction.               *
 *                                                                   *
 * The ISF vector is quantized using two-stage VQ with split-by-2    *
 * in 1st stage and split-by-5 (or 3)in the second stage.            *
 *-------------------------------------------------------------------*/


#include "typedef.h"
#include "basic_op.h"
#include "cnst.h"
#include "acelp.h"
#include "count.h"

#include "qpisf_2s.tab"                    /* Codebooks of isfs */

#define MU         10923                   /* Prediction factor   (1.0/3.0) in Q15 */
#define N_SURV_MAX 4                       /* 4 survivors max */
#define ALPHA      29491                   /* 0. 9 in Q15     */
#define ONE_ALPHA (32768-ALPHA)            /* (1.0 - ALPHA) in Q15 */

/* local functions */

static void VQ_stage1(
     Word16 * x,                           /* input : ISF residual vector           */
     Word16 * dico,                        /* input : quantization codebook         */
     Word16 dim,                           /* input : dimention of vector           */
     Word16 dico_size,                     /* input : size of quantization codebook */
     Word16 * index,                       /* output: indices of survivors          */
     Word16 surv                           /* input : number of survivor            */
);

/*-------------------------------------------------------------------*
 * Function   Qpisf_2s_46B()                                         *
 *            ~~~~~~~~~                                              *
 * Quantization of isf parameters with prediction. (46 bits)         *
 *                                                                   *
 * The isf vector is quantized using two-stage VQ with split-by-2 in *
 *  1st stage and split-by-5 in the second stage.                    *
 *-------------------------------------------------------------------*/


void Qpisf_2s_46b(
     Word16 * isf1,                        /* (i) Q15 : ISF in the frequency domain (0..0.5) */
     Word16 * isf_q,                       /* (o) Q15 : quantized ISF               (0..0.5) */
     Word16 * past_isfq,                   /* (io)Q15 : past ISF quantizer                   */
     Word16 * indice,                      /* (o)     : quantization indices                 */
     Word16 nb_surv                        /* (i)     : number of survivor (1, 2, 3 or 4)    */
)
{
    Word16 i, k, tmp_ind[5];
    Word16 surv1[N_SURV_MAX];              /* indices of survivors from 1st stage */
    Word32 temp, min_err, distance;
    Word16 isf[ORDER];
    Word16 isf_stage2[ORDER];


    for (i = 0; i < ORDER; i++)
    {
        /* isf[i] = isf1[i] - mean_isf[i] - MU*past_isfq[i] */
        isf[i] = sub(isf1[i], mean_isf[i]);move16();
        isf[i] = sub(isf[i], mult(MU, past_isfq[i]));   move16();
    }

    VQ_stage1(&isf[0], dico1_isf, 9, SIZE_BK1, surv1, nb_surv);

    distance = MAX_32;                     move32();

    for (k = 0; k < nb_surv; k++)
    {
        for (i = 0; i < 9; i++)
        {
            isf_stage2[i] = sub(isf[i], dico1_isf[i + surv1[k] * 9]);   move16();
        }

        tmp_ind[0] = Sub_VQ(&isf_stage2[0], dico21_isf, 3, SIZE_BK21, &min_err);        move16();
        temp = min_err;                    move32();
        tmp_ind[1] = Sub_VQ(&isf_stage2[3], dico22_isf, 3, SIZE_BK22, &min_err);        move16();
        temp = L_add(temp, min_err);
        tmp_ind[2] = Sub_VQ(&isf_stage2[6], dico23_isf, 3, SIZE_BK23, &min_err);        move16();
        temp = L_add(temp, min_err);

        test();
        if (L_sub(temp, distance) < (Word32) 0)
        {
            distance = temp;               move32();
            indice[0] = surv1[k];          move16();
            for (i = 0; i < 3; i++)
            {
                indice[i + 2] = tmp_ind[i];move16();
            }
        }
    }


    VQ_stage1(&isf[9], dico2_isf, 7, SIZE_BK2, surv1, nb_surv);

    distance = MAX_32;                     move32();

    for (k = 0; k < nb_surv; k++)
    {
        for (i = 0; i < 7; i++)
        {
            isf_stage2[i] = sub(isf[9 + i], dico2_isf[i + surv1[k] * 7]);       move16();
        }

        tmp_ind[0] = Sub_VQ(&isf_stage2[0], dico24_isf, 3, SIZE_BK24, &min_err);        move16();
        temp = min_err;                    move32();
        tmp_ind[1] = Sub_VQ(&isf_stage2[3], dico25_isf, 4, SIZE_BK25, &min_err);        move16();
        temp = L_add(temp, min_err);

        test();
        if (L_sub(temp, distance) < (Word32) 0)
        {
            distance = temp;               move32();
            indice[1] = surv1[k];          move16();
            for (i = 0; i < 2; i++)
            {
                indice[i + 5] = tmp_ind[i];move16();
            }
        }
    }

    Dpisf_2s_46b(indice, isf_q, past_isfq, isf_q, isf_q, 0, 0);

    return;
}

/*-------------------------------------------------------------------*
 * Function   Qpisf_2s_36B()                                         *
 *            ~~~~~~~~~                                              *
 * Quantization of isf parameters with prediction. (36 bits)         *
 *                                                                   *
 * The isf vector is quantized using two-stage VQ with split-by-2 in *
 *  1st stage and split-by-3 in the second stage.                    *
 *-------------------------------------------------------------------*/


void Qpisf_2s_36b(
     Word16 * isf1,                        /* (i) Q15 : ISF in the frequency domain (0..0.5) */
     Word16 * isf_q,                       /* (o) Q15 : quantized ISF               (0..0.5) */
     Word16 * past_isfq,                   /* (io)Q15 : past ISF quantizer                   */
     Word16 * indice,                      /* (o)     : quantization indices                 */
     Word16 nb_surv                        /* (i)     : number of survivor (1, 2, 3 or 4)    */
)
{
    Word16 i, k, tmp_ind[5];
    Word16 surv1[N_SURV_MAX];              /* indices of survivors from 1st stage */
    Word32 temp, min_err, distance;
    Word16 isf[ORDER];
    Word16 isf_stage2[ORDER];

    for (i = 0; i < ORDER; i++)
    {
        /* isf[i] = isf1[i] - mean_isf[i] - MU*past_isfq[i] */
        isf[i] = sub(isf1[i], mean_isf[i]);move16();
        isf[i] = sub(isf[i], mult(MU, past_isfq[i]));   move16();
    }

    VQ_stage1(&isf[0], dico1_isf, 9, SIZE_BK1, surv1, nb_surv);

    distance = MAX_32;                     move32();

    for (k = 0; k < nb_surv; k++)
    {
        for (i = 0; i < 9; i++)
        {
            isf_stage2[i] = sub(isf[i], dico1_isf[i + surv1[k] * 9]);   move16();
        }

        tmp_ind[0] = Sub_VQ(&isf_stage2[0], dico21_isf_36b, 5, SIZE_BK21_36b, &min_err);        move16();
        temp = min_err;                    move32();
        tmp_ind[1] = Sub_VQ(&isf_stage2[5], dico22_isf_36b, 4, SIZE_BK22_36b, &min_err);        move16();
        temp = L_add(temp, min_err);

        test();
        if (L_sub(temp, distance) < (Word32) 0)
        {
            distance = temp;               move32();
            indice[0] = surv1[k];          move16();
            for (i = 0; i < 2; i++)
            {
                indice[i + 2] = tmp_ind[i];move16();
            }
        }
    }


    VQ_stage1(&isf[9], dico2_isf, 7, SIZE_BK2, surv1, nb_surv);

    distance = MAX_32;                     move32();

    for (k = 0; k < nb_surv; k++)
    {
        for (i = 0; i < 7; i++)
        {
            isf_stage2[i] = sub(isf[9 + i], dico2_isf[i + surv1[k] * 7]);       move16();
        }

        tmp_ind[0] = Sub_VQ(&isf_stage2[0], dico23_isf_36b, 7, SIZE_BK23_36b, &min_err);        move16();
        temp = min_err;                    move32();

        test();
        if (L_sub(temp, distance) < (Word32) 0)
        {
            distance = temp;               move32();
            indice[1] = surv1[k];          move16();
            indice[4] = tmp_ind[0];        move16();
        }
    }

    Dpisf_2s_36b(indice, isf_q, past_isfq, isf_q, isf_q, 0, 0);

    return;
}

/*-------------------------------------------------------------------*
 * routine:   Disf_2s_46b()                                          *
 *            ~~~~~~~~~                                              *
 * Decoding of ISF parameters                                        *
 *-------------------------------------------------------------------*/

void Dpisf_2s_46b(
     Word16 * indice,                      /* input:  quantization indices                       */
     Word16 * isf_q,                       /* output: quantized ISF in frequency domain (0..0.5) */
     Word16 * past_isfq,                   /* i/0   : past ISF quantizer                    */
     Word16 * isfold,                      /* input : past quantized ISF                    */
     Word16 * isf_buf,                     /* input : isf buffer                                                        */
     Word16 bfi,                           /* input : Bad frame indicator                   */
     Word16 enc_dec
)
{
    Word16 ref_isf[M];
    Word16 i, j, tmp;
    Word32 L_tmp;

    test();
    if (bfi == 0)                          /* Good frame */
    {
        for (i = 0; i < 9; i++)
        {
            isf_q[i] = dico1_isf[indice[0] * 9 + i];    move16();
        }
        for (i = 0; i < 7; i++)
        {
            isf_q[i + 9] = dico2_isf[indice[1] * 7 + i];        move16();
        }

        for (i = 0; i < 3; i++)
        {
            isf_q[i] = add(isf_q[i], dico21_isf[indice[2] * 3 + i]);    move16();
        }
        for (i = 0; i < 3; i++)
        {
            isf_q[i + 3] = add(isf_q[i + 3], dico22_isf[indice[3] * 3 + i]);    move16();
        }
        for (i = 0; i < 3; i++)
        {
            isf_q[i + 6] = add(isf_q[i + 6], dico23_isf[indice[4] * 3 + i]);    move16();
        }
        for (i = 0; i < 3; i++)
        {
            isf_q[i + 9] = add(isf_q[i + 9], dico24_isf[indice[5] * 3 + i]);    move16();
        }
        for (i = 0; i < 4; i++)
        {
            isf_q[i + 12] = add(isf_q[i + 12], dico25_isf[indice[6] * 4 + i]);  move16();
        }

        for (i = 0; i < ORDER; i++)
        {
            tmp = isf_q[i];                move16();
            isf_q[i] = add(tmp, mean_isf[i]);   move16();
            isf_q[i] = add(isf_q[i], mult(MU, past_isfq[i]));   move16();
            past_isfq[i] = tmp;            move16();
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -