📄 vad1.cpp
字号:
------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable used to represent cycle count for each subroutine called) where: (cycle count variable) = cycle count for [subroutine name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/static Word16 complex_vad( vadState1 *st, /* i/o : VAD state struct */ Word16 low_power, /* i : flag power of the input frame */ Flag *pOverflow /* o : Flag set when overflow occurs */){ st->complex_high = shr(st->complex_high, 1, pOverflow); st->complex_low = shr(st->complex_low, 1, pOverflow); if (low_power == 0) { if (st->corr_hp_fast > CVAD_THRESH_ADAPT_HIGH) { st->complex_high |= 0x4000; } if (st->corr_hp_fast > CVAD_THRESH_ADAPT_LOW) { st->complex_low |= 0x4000; } } if (st->corr_hp_fast > CVAD_THRESH_HANG) { st->complex_hang_timer = add(st->complex_hang_timer, 1, pOverflow); } else { st->complex_hang_timer = 0; } return ((Word16)(st->complex_high & 0x7f80) == 0x7f80 || (Word16)(st->complex_low & 0x7fff) == 0x7fff);}/*------------------------------------------------------------------------------ FUNCTION NAME: vad_decision------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: st -- pointer to type vadState1 -- State struct level -- array of type Word16 -- sub-band levels of the input frame pow_sum -- Word32 -- power of the input frame Outputs: st -- pointer to type vadState1 -- State struct pOverflow -- pointer to type Flag -- overflow indicator Returns: VAD_flag (Word16) Global Variables Used: None Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose : Calculates VAD_flag Inputs : bckr_est: background noise estimate vadreg: intermediate VAD flags Outputs : noise_level: average level of the noise estimates vadreg: intermediate VAD flags Return value : VAD_flag------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable used to represent cycle count for each subroutine called) where: (cycle count variable) = cycle count for [subroutine name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/static Word16 vad_decision( vadState1 *st, /* i/o : State struct */ Word16 level[COMPLEN], /* i : sub-band levels of the input frame */ Word32 pow_sum, /* i : power of the input frame */ Flag *pOverflow /* o : Flag set when overflow occurs */){ Word16 i; Word16 snr_sum; Word32 L_temp; Word16 vad_thr; Word16 temp; Word16 noise_level; Word16 low_power_flag; Word16 temp1; /* Calculate squared sum of the input levels (level) divided by the background noise components (bckr_est). */ L_temp = 0; for (i = 0; i < COMPLEN; i++) { Word16 exp; exp = norm_s(st->bckr_est[i]); temp = shl(st->bckr_est[i], exp, pOverflow); temp = div_s(shr(level[i], 1, pOverflow), temp); temp = shl(temp, sub(exp, UNIRSHFT - 1, pOverflow), pOverflow); L_temp = L_mac(L_temp, temp, temp, pOverflow); } snr_sum = extract_h(L_shl(L_temp, 6, pOverflow)); snr_sum = mult(snr_sum, INV_COMPLEN, pOverflow); /* Calculate average level of estimated background noise */ L_temp = 0; for (i = 0; i < COMPLEN; i++) { L_temp = L_add(L_temp, st->bckr_est[i], pOverflow); } noise_level = extract_h(L_shl(L_temp, 13, pOverflow)); /* Calculate VAD threshold */ temp1 = sub(noise_level, VAD_P1, pOverflow); temp1 = mult(VAD_SLOPE, temp1, pOverflow); vad_thr = add(temp1, VAD_THR_HIGH, pOverflow); if (vad_thr < VAD_THR_LOW) { vad_thr = VAD_THR_LOW; } /* Shift VAD decision register */ st->vadreg = shr(st->vadreg, 1, pOverflow); /* Make intermediate VAD decision */ if (snr_sum > vad_thr) { st->vadreg |= 0x4000; } /* primary vad decsion made */ /* check if the input power (pow_sum) is lower than a threshold" */ if (L_sub(pow_sum, VAD_POW_LOW, pOverflow) < 0) { low_power_flag = 1; } else { low_power_flag = 0; } /* update complex signal estimate st->corr_hp_fast and hangover reset timer using */ /* low_power_flag and corr_hp_fast and various adaptation speeds */ complex_estimate_adapt(st, low_power_flag, pOverflow); /* check multiple thresholds of the st->corr_hp_fast value */ st->complex_warning = complex_vad(st, low_power_flag, pOverflow); /* Update speech subband vad background noise estimates */ noise_estimate_update(st, level, pOverflow); /* Add speech and complex hangover and return speech VAD_flag */ /* long term complex hangover may be added */ st->speech_vad_decision = hangover_addition(st, noise_level, low_power_flag, pOverflow); return (st->speech_vad_decision);}/*------------------------------------------------------------------------------ FUNCTION NAME: vad1_init------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: state -- double pointer to type vadState1 -- pointer to memory to be initialized. Outputs: state -- points to initalized area in memory. Returns: None Global Variables Used: None Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Allocates state memory and initializes state memory------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable used to represent cycle count for each subroutine called) where: (cycle count variable) = cycle count for [subroutine name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/Word16 vad1_init(vadState1 **state){ vadState1* s; if (state == (vadState1 **) NULL) { return -1; } *state = NULL; /* allocate memory */ if ((s = (vadState1 *) oscl_malloc(sizeof(vadState1))) == NULL) { return -1; } vad1_reset(s); *state = s; return 0;}/*------------------------------------------------------------------------------ FUNCTION NAME: vad1_reset------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: state -- pointer to type vadState1 -- State struct Outputs: state -- pointer to type vadState1 -- State struct Returns: None Global Variables Used: None Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose: Resets state memory to zero------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable used to represent cycle count for each subroutine called) where: (cycle count variable) = cycle count for [subroutine name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/Word16 vad1_reset(vadState1 *state){ Word16 i; Word16 j; if (state == (vadState1 *) NULL) { return -1; } /* Initialize pitch detection variables */ state->oldlag_count = 0; state->oldlag = 0; state->pitch = 0; state->tone = 0; state->complex_high = 0; state->complex_low = 0; state->complex_hang_timer = 0; state->vadreg = 0; state->stat_count = 0; state->burst_count = 0; state->hang_count = 0; state->complex_hang_count = 0; /* initialize memory used by the filter bank */ for (i = 0; i < 3; i++) { for (j = 0; j < 2; j++) { state->a_data5[i][j] = 0; } } for (i = 0; i < 5; i++) { state->a_data3[i] = 0; } /* initialize the rest of the memory */ for (i = 0; i < COMPLEN; i++) { state->bckr_est[i] = NOISE_INIT; state->old_level[i] = NOISE_INIT; state->ave_level[i] = NOISE_INIT; state->sub_level[i] = 0; } state->best_corr_hp = CVAD_LOWPOW_RESET; state->speech_vad_decision = 0; state->complex_warning = 0; state->sp_burst_count = 0; state->corr_hp_fast = CVAD_LOWPOW_RESET;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -