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

📄 pvamrwbdecoder.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    {        st->state >>=  1;    }    /* If this frame is the first speech frame after CNI period,     * set the BFH state machine to an appropriate state depending     * on whether there was DTX muting before start of speech or not     * If there was DTX muting, the first speech frame is muted.     * If there was no DTX muting, the first speech frame is not     * muted. The BFH state machine starts from state 5, however, to     * keep the audible noise resulting from a SID frame which is     * erroneously interpreted as a good speech frame as small as     * possible (the decoder output in this case is quickly muted)     */    if (st->dtx_decSt.dtxGlobalState == DTX)    {        st->state = 5;        st->prev_bfi = 0;    }    else if (st->dtx_decSt.dtxGlobalState == DTX_MUTE)    {        st->state = 5;        st->prev_bfi = 1;    }    if (newDTXState == SPEECH)    {        vad_flag = Serial_parm_1bit(&prms);        if (bfi == 0)        {            if (vad_flag == 0)            {                st->vad_hist = add_int16(st->vad_hist, 1);            }            else            {                st->vad_hist = 0;            }        }    }    /*     *  DTX-CNG     */    if (newDTXState != SPEECH)     /* CNG mode */    {        /* increase slightly energy of noise below 200 Hz */        /* Convert ISFs to the cosine domain */        Isf_isp(isf, ispnew, M);        Isp_Az(ispnew, Aq, M, 1);        pv_memcpy((void *)isf_tmp, (void *)st->isfold, M*sizeof(*isf_tmp));        for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)        {            j = i_subfr >> 6;            for (i = 0; i < M; i++)            {                L_tmp = mul_16by16_to_int32(isf_tmp[i], sub_int16(32767, interpol_frac[j]));                L_tmp = mac_16by16_to_int32(L_tmp, isf[i], interpol_frac[j]);                HfIsf[i] = amr_wb_round(L_tmp);            }            synthesis_amr_wb(Aq,                             &exc2[i_subfr],                             0,                             &synth16k[i_subfr *5/4],                             (short) 1,                             HfIsf,                             nb_bits,                             newDTXState,                             st,                             bfi,                             ScratchMem);        }        /* reset speech coder memories */        pvDecoder_AmrWb_Reset(st, 0);        pv_memcpy((void *)st->isfold, (void *)isf, M*sizeof(*isf));        st->prev_bfi = bfi;        st->dtx_decSt.dtxGlobalState = newDTXState;        return 0;    }    /*     *  ACELP     */    /* copy coder memory state into working space (internal memory for DSP) */    pv_memcpy((void *)old_exc, (void *)st->old_exc, (PIT_MAX + L_INTERPOL)*sizeof(*old_exc));    exc = old_exc + PIT_MAX + L_INTERPOL;    /* Decode the ISFs */    if (nb_bits > NBBITS_7k)        /* all rates but 6.6 Kbps */    {        ind[0] = Serial_parm(8, &prms);     /* index of 1st ISP subvector */        ind[1] = Serial_parm(8, &prms);     /* index of 2nd ISP subvector */        ind[2] = Serial_parm(6, &prms);     /* index of 3rd ISP subvector */        ind[3] = Serial_parm(7, &prms);     /* index of 4th ISP subvector */        ind[4] = Serial_parm(7, &prms);     /* index of 5th ISP subvector */        ind[5] = Serial_parm(5, &prms);     /* index of 6th ISP subvector */        ind[6] = Serial_parm(5, &prms);     /* index of 7th ISP subvector */        Dpisf_2s_46b(ind, isf, st->past_isfq, st->isfold, st->isf_buf, bfi, 1);    }    else    {        ind[0] = Serial_parm(8, &prms);        ind[1] = Serial_parm(8, &prms);        ind[2] = Serial_parm(14, &prms);        ind[3] = ind[2] & 0x007F;        ind[2] >>= 7;        ind[4] = Serial_parm(6, &prms);        Dpisf_2s_36b(ind, isf, st->past_isfq, st->isfold, st->isf_buf, bfi, 1);    }    /* Convert ISFs to the cosine domain */    Isf_isp(isf, ispnew, M);    if (st->first_frame != 0)    {        st->first_frame = 0;        pv_memcpy((void *)st->ispold, (void *)ispnew, M*sizeof(*ispnew));    }    /* Find the interpolated ISPs and convert to a[] for all subframes */    interpolate_isp(st->ispold, ispnew, interpol_frac, Aq);    /* update ispold[] for the next frame */    pv_memcpy((void *)st->ispold, (void *)ispnew, M*sizeof(*ispnew));    /* Check stability on isf : distance between old isf and current isf */    L_tmp = 0;    for (i = 0; i < M - 1; i++)    {        tmp = sub_int16(isf[i], st->isfold[i]);        L_tmp = mac_16by16_to_int32(L_tmp, tmp, tmp);    }    tmp = extract_h(shl_int32(L_tmp, 8));    tmp = mult_int16(tmp, 26214);                /* tmp = L_tmp*0.8/256 */    tmp = 20480 - tmp;                 /* 1.25 - tmp */    stab_fac = shl_int16(tmp, 1);                /* Q14 -> Q15 with saturation */    if (stab_fac < 0)    {        stab_fac = 0;    }    pv_memcpy((void *)isf_tmp, (void *)st->isfold, M*sizeof(*isf_tmp));    pv_memcpy((void *)st->isfold, (void *)isf, M*sizeof(*isf));    /*     *          Loop for every subframe in the analysis frame     *     * The subframe size is L_SUBFR and the loop is repeated L_FRAME/L_SUBFR     *  times     *     - decode the pitch delay and filter mode     *     - decode algebraic code     *     - decode pitch and codebook gains     *     - find voicing factor and tilt of code for next subframe.     *     - find the excitation and compute synthesis speech     */    p_Aq = Aq;                                /* pointer to interpolated LPC parameters */    /*     *   Sub process next 3 subframes     */    for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)    {        pit_flag = i_subfr;        if ((i_subfr == 2*L_SUBFR) && (nb_bits > NBBITS_7k))        {            pit_flag = 0;        /* set to 0 for 3rd subframe, <=> is not 6.6 kbps */        }        /*-------------------------------------------------*         * - Decode pitch lag                              *         * Lag indeces received also in case of BFI,       *         * so that the parameter pointer stays in sync.    *         *-------------------------------------------------*/        if (pit_flag == 0)        {            if (nb_bits <= NBBITS_9k)            {                index = Serial_parm(8, &prms);                if (index < (PIT_FR1_8b - PIT_MIN) * 2)                {                    T0 = PIT_MIN + (index >> 1);                    T0_frac = sub_int16(index, shl_int16(sub_int16(T0, PIT_MIN), 1));                    T0_frac = shl_int16(T0_frac, 1);                }                else                {                    T0 = add_int16(index, PIT_FR1_8b - ((PIT_FR1_8b - PIT_MIN) * 2));                    T0_frac = 0;                }            }            else            {                index = Serial_parm(9, &prms);                if (index < (PIT_FR2 - PIT_MIN) * 4)                {                    T0 = PIT_MIN + (index >> 2);                    T0_frac = sub_int16(index, shl_int16(sub_int16(T0, PIT_MIN), 2));                }                else if (index < (((PIT_FR2 - PIT_MIN) << 2) + ((PIT_FR1_9b - PIT_FR2) << 1)))                {                    index -= (PIT_FR2 - PIT_MIN) << 2;                    T0 = PIT_FR2 + (index >> 1);                    T0_frac = sub_int16(index, shl_int16(sub_int16(T0, PIT_FR2), 1));                    T0_frac = shl_int16(T0_frac, 1);                }                else                {                    T0 = add_int16(index, (PIT_FR1_9b - ((PIT_FR2 - PIT_MIN) * 4) - ((PIT_FR1_9b - PIT_FR2) * 2)));                    T0_frac = 0;                }            }            /* find T0_min and T0_max for subframe 2 and 4 */            T0_min = T0 - 8;            if (T0_min < PIT_MIN)            {                T0_min = PIT_MIN;            }            T0_max = T0_min + 15;            if (T0_max > PIT_MAX)            {                T0_max = PIT_MAX;                T0_min = PIT_MAX - 15;            }        }        else        {                                  /* if subframe 2 or 4 */            if (nb_bits <= NBBITS_9k)            {                index = Serial_parm(5, &prms);                T0 = T0_min + (index >> 1);                T0_frac = sub_int16(index, shl_int16(T0 - T0_min, 1));                T0_frac = shl_int16(T0_frac, 1);            }            else            {                index = Serial_parm(6, &prms);                T0 = T0_min + (index >> 2);                T0_frac = sub_int16(index, shl_int16(T0 - T0_min, 2));            }        }        /* check BFI after pitch lag decoding */        if (bfi != 0)                      /* if frame erasure */        {            lagconceal(&(st->dec_gain[17]), st->lag_hist, &T0, &(st->old_T0), &(st->seed3), unusable_frame);            T0_frac = 0;        }        /*         *  Find the pitch gain, the interpolation filter         *  and the adaptive codebook vector.         */        Pred_lt4(&exc[i_subfr], T0, T0_frac, L_SUBFR + 1);        if (unusable_frame)        {            select = 1;        }        else        {            if (nb_bits <= NBBITS_9k)            {                select = 0;            }            else            {                select = Serial_parm_1bit(&prms);            }        }        if (select == 0)        {            /* find pitch excitation with lp filter */            for (i = 0; i < L_SUBFR; i++)            {                L_tmp  = ((int32) exc[i-1+i_subfr] + exc[i+1+i_subfr]);                L_tmp *= 5898;                L_tmp += ((int32) exc[i+i_subfr] * 20972);                code[i] = amr_wb_round(L_tmp << 1);            }            pv_memcpy((void *)&exc[i_subfr], (void *)code, L_SUBFR*sizeof(*code));        }        /*         * Decode innovative codebook.         * Add the fixed-gain pitch contribution to code[].         */        if (unusable_frame != 0)        {            /* the innovative code doesn't need to be scaled (see Q_gain2) */            for (i = 0; i < L_SUBFR; i++)            {                code[i] = noise_gen_amrwb(&(st->seed)) >> 3;            }        }        else if (nb_bits <= NBBITS_7k)        {            ind[0] = Serial_parm(12, &prms);            dec_acelp_2p_in_64(ind[0], code);        }        else if (nb_bits <= NBBITS_9k)        {            for (i = 0; i < 4; i++)            {                ind[i] = Serial_parm(5, &prms);            }            dec_acelp_4p_in_64(ind, 20, code);        }        else if (nb_bits <= NBBITS_12k)        {            for (i = 0; i < 4; i++)            {                ind[i] = Serial_parm(9, &prms);            }            dec_acelp_4p_in_64(ind, 36, code);        }        else if (nb_bits <= NBBITS_14k)        {            ind[0] = Serial_parm(13, &prms);            ind[1] = Serial_parm(13, &prms);            ind[2] = Serial_parm(9, &prms);            ind[3] = Serial_parm(9, &prms);            dec_acelp_4p_in_64(ind, 44, code);        }        else if (nb_bits <= NBBITS_16k)        {            for (i = 0; i < 4; i++)            {                ind[i] = Serial_parm(13, &prms);            }            dec_acelp_4p_in_64(ind, 52, code);        }        else if (nb_bits <= NBBITS_18k)        {            for (i = 0; i < 4; i++)            {                ind[i] = Serial_parm(2, &prms);            }            for (i = 4; i < 8; i++)            {

⌨️ 快捷键说明

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