📄 dec_amr.c
字号:
/*************************************************************************** GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001* R99 Version 3.3.0 * REL-4 Version 4.1.0 ******************************************************************************** File : dec_amr.c* Purpose : Decoding of one speech frame using given codec mode*******************************************************************************//******************************************************************************* MODULE INCLUDE FILE AND VERSION ID******************************************************************************/#include "dec_amr.h"const char dec_amr_id[] = "@(#)$Id $" dec_amr_h;#include <stdlib.h>#include <stdio.h>#include "typedef.h"#include "basic_op.h"#include "count.h"#include "cnst.h"#include "copy.h"#include "set_zero.h"#include "syn_filt.h"#include "d_plsf.h"#include "agc.h"#include "int_lpc.h"#include "dec_gain.h"#include "dec_lag3.h"#include "dec_lag6.h"#include "d2_9pf.h"#include "d2_11pf.h"#include "d3_14pf.h"#include "d4_17pf.h"#include "d8_31pf.h"#include "d1035pf.h"#include "pred_lt.h"#include "d_gain_p.h"#include "d_gain_c.h"#include "dec_gain.h"#include "ec_gains.h"#include "ph_disp.h"#include "c_g_aver.h"#include "int_lsf.h"#include "lsp_lsf.h"#include "lsp_avg.h"#include "bgnscd.h"#include "ex_ctrl.h"#include "sqrt_l.h"#include "frame.h"#include "lsp.tab"#include "bitno.tab"#include "b_cn_cod.h"/******************************************************************************* LOCAL VARIABLES AND TABLES******************************************************************************//*-----------------------------------------------------------------* * Decoder constant parameters (defined in "cnst.h") * *-----------------------------------------------------------------* * L_FRAME : Frame size. * * L_FRAME_BY2 : Half the frame size. * * L_SUBFR : Sub-frame size. * * M : LPC order. * * MP1 : LPC order+1 * * PIT_MIN : Minimum pitch lag. * * PIT_MIN_MR122 : Minimum pitch lag for the MR122 mode. * * PIT_MAX : Maximum pitch lag. * * L_INTERPOL : Length of filter for interpolation * * PRM_SIZE : size of vector containing analysis parameters * *-----------------------------------------------------------------*//******************************************************************************* PUBLIC PROGRAM CODE******************************************************************************//***************************************************************************** Function : Decoder_amr_init* Purpose : Allocates and initializes state memory****************************************************************************/int Decoder_amr_init (Decoder_amrState **state){ Decoder_amrState* s; Word16 i; if (state == (Decoder_amrState **) NULL){ fprintf(stderr, "Decoder_amr_init: invalid parameter\n"); return -1; } *state = NULL; /* allocate memory */ if ((s= (Decoder_amrState *) malloc(sizeof(Decoder_amrState))) == NULL){ fprintf(stderr, "Decoder_amr_init: can not malloc state structure\n"); return -1; } s->T0_lagBuff = 40; s->inBackgroundNoise = 0; s->voicedHangover = 0; for (i = 0; i < 9; i++) s->ltpGainHistory[i] = 0; s->lsfState = NULL; s->ec_gain_p_st = NULL; s->ec_gain_c_st = NULL; s->pred_state = NULL; s->ph_disp_st = NULL; s->dtxDecoderState = NULL; if (D_plsf_init(&s->lsfState) || ec_gain_pitch_init(&s->ec_gain_p_st) || ec_gain_code_init(&s->ec_gain_c_st) || gc_pred_init(&s->pred_state) || Cb_gain_average_init(&s->Cb_gain_averState) || lsp_avg_init(&s->lsp_avg_st) || Bgn_scd_init(&s->background_state) || ph_disp_init(&s->ph_disp_st) || dtx_dec_init(&s->dtxDecoderState)) { Decoder_amr_exit(&s); return -1; } Decoder_amr_reset(s, (enum Mode)0); *state = s; return 0;}/***************************************************************************** Function : Decoder_amr_reset* Purpose : Resets state memory****************************************************************************/int Decoder_amr_reset (Decoder_amrState *state, enum Mode mode){ Word16 i; if (state == (Decoder_amrState *) NULL){ fprintf(stderr, "Decoder_amr_reset: invalid parameter\n"); return -1; } /* Initialize static pointer */ state->exc = state->old_exc + PIT_MAX + L_INTERPOL; /* Static vectors to zero */ Set_zero (state->old_exc, PIT_MAX + L_INTERPOL); if (mode != MRDTX) Set_zero (state->mem_syn, M); /* initialize pitch sharpening */ state->sharp = SHARPMIN; state->old_T0 = 40; /* Initialize state->lsp_old [] */ if (mode != MRDTX) { Copy(lsp_init_data, &state->lsp_old[0], M); } /* Initialize memories of bad frame handling */ state->prev_bf = 0; state->prev_pdf = 0; state->state = 0; state->T0_lagBuff = 40; state->inBackgroundNoise = 0; state->voicedHangover = 0; if (mode != MRDTX) { for (i=0;i<9;i++) state->excEnergyHist[i] = 0; } for (i = 0; i < 9; i++) state->ltpGainHistory[i] = 0; Cb_gain_average_reset(state->Cb_gain_averState); if (mode != MRDTX) lsp_avg_reset(state->lsp_avg_st); D_plsf_reset(state->lsfState); ec_gain_pitch_reset(state->ec_gain_p_st); ec_gain_code_reset(state->ec_gain_c_st); if (mode != MRDTX) gc_pred_reset(state->pred_state); Bgn_scd_reset(state->background_state); state->nodataSeed = 21845; ph_disp_reset(state->ph_disp_st); if (mode != MRDTX) dtx_dec_reset(state->dtxDecoderState); return 0;}/***************************************************************************** Function : Decoder_amr_exit* Purpose : The memory used for state memory is freed****************************************************************************/void Decoder_amr_exit (Decoder_amrState **state){ if (state == NULL || *state == NULL) return; D_plsf_exit(&(*state)->lsfState); ec_gain_pitch_exit(&(*state)->ec_gain_p_st); ec_gain_code_exit(&(*state)->ec_gain_c_st); gc_pred_exit(&(*state)->pred_state); Bgn_scd_exit(&(*state)->background_state); ph_disp_exit(&(*state)->ph_disp_st); Cb_gain_average_exit(&(*state)->Cb_gain_averState); lsp_avg_exit(&(*state)->lsp_avg_st); dtx_dec_exit(&(*state)->dtxDecoderState); /* deallocate memory */ free(*state); *state = NULL; return;}/***************************************************************************** Function : Decoder_amr* Purpose : Speech decoder routine.****************************************************************************/int Decoder_amr ( Decoder_amrState *st, /* i/o : State variables */ enum Mode mode, /* i : AMR mode */ Word16 parm[], /* i : vector of synthesis parameters (PRM_SIZE) */ enum RXFrameType frame_type, /* i : received frame type */ Word16 synth[], /* o : synthesis speech (L_FRAME) */ Word16 A_t[] /* o : decoded LP filter in 4 subframes (AZ_SIZE) */){ /* LPC coefficients */ Word16 *Az; /* Pointer on A_t */ /* LSPs */ Word16 lsp_new[M]; Word16 lsp_mid[M]; /* LSFs */ Word16 prev_lsf[M]; Word16 lsf_i[M]; /* Algebraic codevector */ Word16 code[L_SUBFR]; /* excitation */ Word16 excp[L_SUBFR]; Word16 exc_enhanced[L_SUBFR]; /* Scalars */ Word16 i, i_subfr; Word16 T0, T0_frac, index, index_mr475 = 0; Word16 gain_pit, gain_code, gain_code_mix, pit_sharp, pit_flag, pitch_fac; Word16 t0_min, t0_max; Word16 delta_frc_low, delta_frc_range; Word16 tmp_shift; Word16 temp; Word32 L_temp; Word16 flag4; Word16 carefulFlag; Word16 excEnergy; Word16 subfrNr; Word16 evenSubfr = 0; Word16 bfi = 0; /* bad frame indication flag */ Word16 pdfi = 0; /* potential degraded bad frame flag */ enum DTXStateType newDTXState; /* SPEECH , DTX, DTX_MUTE */ /* find the new DTX state SPEECH OR DTX */ newDTXState = rx_dtx_handler(st->dtxDecoderState, frame_type); move16 (); /* function result */ /* DTX actions */ test(); if (sub(newDTXState, SPEECH) != 0 ) { Decoder_amr_reset (st, MRDTX); dtx_dec(st->dtxDecoderState, st->mem_syn, st->lsfState, st->pred_state, st->Cb_gain_averState, newDTXState, mode, parm, synth, A_t); /* update average lsp */ Lsf_lsp(st->lsfState->past_lsf_q, st->lsp_old, M); lsp_avg(st->lsp_avg_st, st->lsfState->past_lsf_q); goto the_end; } /* SPEECH action state machine */ test (); test (); test (); if ((sub(frame_type, RX_SPEECH_BAD) == 0) || (sub(frame_type, RX_NO_DATA) == 0) || (sub(frame_type, RX_ONSET) == 0)) { bfi = 1; move16 (); test(); test(); if ((sub(frame_type, RX_NO_DATA) == 0) || (sub(frame_type, RX_ONSET) == 0)) { build_CN_param(&st->nodataSeed, prmno[mode], bitno[mode], parm); } } else if (sub(frame_type, RX_SPEECH_DEGRADED) == 0) { pdfi = 1; move16 (); } test(); if (bfi != 0) { st->state = add (st->state, 1); } else if (sub (st->state, 6) == 0) { st->state = 5; move16 (); } else { st->state = 0; move16 (); } test (); if (sub (st->state, 6) > 0) { st->state = 6; move16 (); } /* 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. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -