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

📄 pvamrwbdecoder.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                ind[i] = Serial_parm(14, &prms);            }            dec_acelp_4p_in_64(ind, 64, code);        }        else if (nb_bits <= NBBITS_20k)        {            ind[0] = Serial_parm(10, &prms);            ind[1] = Serial_parm(10, &prms);            ind[2] = Serial_parm(2, &prms);            ind[3] = Serial_parm(2, &prms);            ind[4] = Serial_parm(10, &prms);            ind[5] = Serial_parm(10, &prms);            ind[6] = Serial_parm(14, &prms);            ind[7] = Serial_parm(14, &prms);            dec_acelp_4p_in_64(ind, 72, code);        }        else        {            for (i = 0; i < 8; i++)            {                ind[i] = Serial_parm(11, &prms);            }            dec_acelp_4p_in_64(ind, 88, code);        }        preemph_amrwb_dec(code, st->tilt_code, L_SUBFR);        tmp = T0;        if (T0_frac > 2)        {            tmp++;        }        Pit_shrp(code, tmp, PIT_SHARP, L_SUBFR);        /*         *  Decode codebooks gains.         */        if (nb_bits <= NBBITS_9k)        {            index = Serial_parm(6, &prms); /* codebook gain index */            dec_gain2_amr_wb(index,                             6,                             code,                             L_SUBFR,                             &gain_pit,                             &L_gain_code,                             bfi,                             st->prev_bfi,                             st->state,                             unusable_frame,                             st->vad_hist,                             st->dec_gain);        }        else        {            index = Serial_parm(7, &prms); /* codebook gain index */            dec_gain2_amr_wb(index,                             7,                             code,                             L_SUBFR,                             &gain_pit,                             &L_gain_code,                             bfi,                             st->prev_bfi,                             st->state,                             unusable_frame,                             st->vad_hist,                             st->dec_gain);        }        /* find best scaling to perform on excitation (Q_new) */        tmp = st->Qsubfr[0];        for (i = 1; i < 4; i++)        {            if (st->Qsubfr[i] < tmp)            {                tmp = st->Qsubfr[i];            }        }        /* limit scaling (Q_new) to Q_MAX: see pv_amr_wb_cnst.h and syn_filt_32() */        if (tmp > Q_MAX)        {            tmp = Q_MAX;        }        Q_new = 0;        L_tmp = L_gain_code;                  /* L_gain_code in Q16 */        while ((L_tmp < 0x08000000L) && (Q_new < tmp))        {            L_tmp <<= 1;            Q_new += 1;        }        gain_code = amr_wb_round(L_tmp);          /* scaled gain_code with Qnew */        scale_signal(exc + i_subfr - (PIT_MAX + L_INTERPOL),                     PIT_MAX + L_INTERPOL + L_SUBFR,                     (int16)(Q_new - st->Q_old));        st->Q_old = Q_new;        /*         * Update parameters for the next subframe.         * - tilt of code: 0.0 (unvoiced) to 0.5 (voiced)         */        if (bfi == 0)        {            /* LTP-Lag history update */            for (i = 4; i > 0; i--)            {                st->lag_hist[i] = st->lag_hist[i - 1];            }            st->lag_hist[0] = T0;            st->old_T0 = T0;            st->old_T0_frac = 0;              /* Remove fraction in case of BFI */        }        /* find voice factor in Q15 (1=voiced, -1=unvoiced) */        /*         * Scale down by 1/8         */        for (i = L_SUBFR - 1; i >= 0; i--)        {            exc2[i] = (exc[i_subfr + i] + (0x0004 * (exc[i_subfr + i] != MAX_16))) >> 3;        }        /* post processing of excitation elements */        if (nb_bits <= NBBITS_9k)        {            pit_sharp = shl_int16(gain_pit, 1);            if (pit_sharp > 16384)            {                for (i = 0; i < L_SUBFR; i++)                {                    tmp = mult_int16(exc2[i], pit_sharp);                    L_tmp = mul_16by16_to_int32(tmp, gain_pit);                    L_tmp >>= 1;                    excp[i] = amr_wb_round(L_tmp);                }            }        }        else        {            pit_sharp = 0;        }        voice_fac = voice_factor(exc2, -3, gain_pit, code, gain_code, L_SUBFR);        /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */        st->tilt_code = (voice_fac >> 2) + 8192;        /*         * - Find the total excitation.         * - Find synthesis speech corresponding to exc[].         * - Find maximum value of excitation for next scaling         */        pv_memcpy((void *)exc2, (void *)&exc[i_subfr], L_SUBFR*sizeof(*exc2));        max = 1;        for (i = 0; i < L_SUBFR; i++)        {            L_tmp = mul_16by16_to_int32(code[i], gain_code);            L_tmp = shl_int32(L_tmp, 5);            L_tmp = mac_16by16_to_int32(L_tmp, exc[i + i_subfr], gain_pit);            L_tmp = shl_int32(L_tmp, 1);            tmp = amr_wb_round(L_tmp);            exc[i + i_subfr] = tmp;            tmp = tmp - (tmp < 0);            max |= tmp ^(tmp >> 15);  /* |= tmp ^sign(tmp) */        }        /* tmp = scaling possible according to max value of excitation */        tmp = add_int16(norm_s(max), Q_new) - 1;        st->Qsubfr[3] = st->Qsubfr[2];        st->Qsubfr[2] = st->Qsubfr[1];        st->Qsubfr[1] = st->Qsubfr[0];        st->Qsubfr[0] = tmp;        /*         * phase dispersion to enhance noise in low bit rate         */        if (nb_bits <= NBBITS_7k)        {            j = 0;      /* high dispersion for rate <= 7.5 kbit/s */        }        else if (nb_bits <= NBBITS_9k)        {            j = 1;      /* low dispersion for rate <= 9.6 kbit/s */        }        else        {            j = 2;      /* no dispersion for rate > 9.6 kbit/s */        }        /* L_gain_code in Q16 */        phase_dispersion((int16)(L_gain_code >> 16),                         gain_pit,                         code,                         j,                         st->disp_mem,                         ScratchMem);        /*         * noise enhancer         * - Enhance excitation on noise. (modify gain of code)         *   If signal is noisy and LPC filter is stable, move gain         *   of code 1.5 dB toward gain of code threshold.         *   This decrease by 3 dB noise energy variation.         */        tmp = 16384 - (voice_fac >> 1);  /* 1=unvoiced, 0=voiced */        fac = mult_int16(stab_fac, tmp);        L_tmp = L_gain_code;        if (L_tmp < st->L_gc_thres)        {            L_tmp += fxp_mul32_by_16b(L_gain_code, 6226) << 1;            if (L_tmp > st->L_gc_thres)            {                L_tmp = st->L_gc_thres;            }        }        else        {            L_tmp = fxp_mul32_by_16b(L_gain_code, 27536) << 1;            if (L_tmp < st->L_gc_thres)            {                L_tmp = st->L_gc_thres;            }        }        st->L_gc_thres = L_tmp;        L_gain_code = fxp_mul32_by_16b(L_gain_code, (32767 - fac)) << 1;        L_gain_code = add_int32(L_gain_code, fxp_mul32_by_16b(L_tmp, fac) << 1);        /*         * pitch enhancer         * - Enhance excitation on voice. (HP filtering of code)         *   On voiced signal, filtering of code by a smooth fir HP         *   filter to decrease energy of code in low frequency.         */        tmp = (voice_fac >> 3) + 4096;/* 0.25=voiced, 0=unvoiced */        /* build excitation */        gain_code = amr_wb_round(shl_int32(L_gain_code, Q_new));        L_tmp = (int32)(code[0] << 16);        L_tmp = msu_16by16_from_int32(L_tmp, code[1], tmp);        L_tmp = mul_16by16_to_int32(amr_wb_round(L_tmp), gain_code);        L_tmp = shl_int32(L_tmp, 5);        L_tmp = mac_16by16_to_int32(L_tmp, exc2[0], gain_pit);        L_tmp = shl_int32(L_tmp, 1);       /* saturation can occur here */        exc2[0] = amr_wb_round(L_tmp);        for (i = 1; i < L_SUBFR - 1; i++)        {            L_tmp = (int32)(code[i] << 16);            L_tmp = msu_16by16_from_int32(L_tmp, (code[i + 1] + code[i - 1]), tmp);            L_tmp = mul_16by16_to_int32(amr_wb_round(L_tmp), gain_code);            L_tmp = shl_int32(L_tmp, 5);            L_tmp = mac_16by16_to_int32(L_tmp, exc2[i], gain_pit);            L_tmp = shl_int32(L_tmp, 1);       /* saturation can occur here */            exc2[i] = amr_wb_round(L_tmp);        }        L_tmp = (int32)(code[L_SUBFR - 1] << 16);        L_tmp = msu_16by16_from_int32(L_tmp, code[L_SUBFR - 2], tmp);        L_tmp = mul_16by16_to_int32(amr_wb_round(L_tmp), gain_code);        L_tmp = shl_int32(L_tmp, 5);        L_tmp = mac_16by16_to_int32(L_tmp, exc2[L_SUBFR - 1], gain_pit);        L_tmp = shl_int32(L_tmp, 1);       /* saturation can occur here */        exc2[L_SUBFR - 1] = amr_wb_round(L_tmp);        if (nb_bits <= NBBITS_9k)        {            if (pit_sharp > 16384)            {                for (i = 0; i < L_SUBFR; i++)                {                    excp[i] = add_int16(excp[i], exc2[i]);                }                agc2_amr_wb(exc2, excp, L_SUBFR);                pv_memcpy((void *)exc2, (void *)excp, L_SUBFR*sizeof(*exc2));            }        }        if (nb_bits <= NBBITS_7k)        {            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);            }        }        else        {            pv_memset((void *)st->mem_syn_hf,                      0,                      (M16k - M)*sizeof(*st->mem_syn_hf));        }        if (nb_bits >= NBBITS_24k)        {            corr_gain = Serial_parm(4, &prms);        }        else        {            corr_gain = 0;        }        synthesis_amr_wb(p_Aq,                         exc2,                         Q_new,                         &synth16k[i_subfr + (i_subfr>>2)],                         corr_gain,                         HfIsf,                         nb_bits,                         newDTXState,                         st,                         bfi,                         ScratchMem);        p_Aq += (M + 1);                   /* interpolated LPC parameters for next subframe */    }    /*     *   Update signal for next frame.     *   -> save past of exc[]     *   -> save pitch parameters     */    pv_memcpy((void *)st->old_exc,              (void *)&old_exc[L_FRAME],              (PIT_MAX + L_INTERPOL)*sizeof(*old_exc));    scale_signal(exc, L_FRAME, (int16)(-Q_new));    dtx_dec_amr_wb_activity_update(&(st->dtx_decSt), isf, exc);    st->dtx_decSt.dtxGlobalState = newDTXState;    st->prev_bfi = bfi;    return 0;}

⌨️ 快捷键说明

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