📄 vad1.cpp
字号:
ind_m -- Word16 -- step size for the index of the data buffer ind_a -- Word16 -- starting index of the data buffer scale -- Word16 -- scaling for the level calculation Outputs: sub_level -- pointer to tyep Word16 -- level of signal calculated from the last (count2 - count1) samples. pOverflow -- pointer to type Flag -- overflow indicator Returns: signal level Global Variables Used: Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose : Calculate signal level in a sub-band. Level is calculated by summing absolute values of the input data.------------------------------------------------------------------------------ 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 level_calculation( Word16 data[], /* i : signal buffer */ Word16 *sub_level, /* i : level calculate at the end of */ /* the previous frame */ /* o : level of signal calculated from the last */ /* (count2 - count1) samples */ Word16 count1, /* i : number of samples to be counted */ Word16 count2, /* i : number of samples to be counted */ Word16 ind_m, /* i : step size for the index of the data buffer */ Word16 ind_a, /* i : starting index of the data buffer */ Word16 scale, /* i : scaling for the level calculation */ Flag *pOverflow /* o : Flag set when overflow occurs */){ Word32 l_temp1; Word32 l_temp2; Word16 level; Word16 i; l_temp1 = 0L; for (i = count1; i < count2; i++) { l_temp1 = L_mac(l_temp1, 1, abs_s(data[ind_m*i+ind_a]), pOverflow); } l_temp2 = L_add(l_temp1, L_shl(*sub_level, sub(16, scale, pOverflow), pOverflow), pOverflow); *sub_level = extract_h(L_shl(l_temp1, scale, pOverflow)); for (i = 0; i < count1; i++) { l_temp2 = L_mac(l_temp2, 1, abs_s(data[ind_m*i+ind_a]), pOverflow); } level = extract_h(L_shl(l_temp2, scale, pOverflow)); return level;}/*------------------------------------------------------------------------------ FUNCTION NAME: filter_bank------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: st -- pointer to type vadState1 -- State struct in -- array of type Word16 -- input frame Outputs: level -- array of type Word16 -- signal levels at each band st -- pointer to type vadState1 -- State struct pOverflow -- pointer to type Flag -- overflow indicator Returns: None Global Variables Used: None Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose : Divides input signal into 9-bands and calculas level of the signal in each band------------------------------------------------------------------------------ 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 void filter_bank( vadState1 *st, /* i/o : State struct */ Word16 in[], /* i : input frame */ Word16 level[], /* 0 : signal levels at each band */ Flag *pOverflow /* o : Flag set when overflow occurs */){ Word16 i; Word16 tmp_buf[FRAME_LEN]; /* calculate the filter bank */ first_filter_stage(in, tmp_buf, st->a_data5[0], pOverflow); for (i = 0; i < FRAME_LEN / 4; i++) { filter5(&tmp_buf[4*i], &tmp_buf[4*i+2], st->a_data5[1], pOverflow); filter5(&tmp_buf[4*i+1], &tmp_buf[4*i+3], st->a_data5[2], pOverflow); } for (i = 0; i < FRAME_LEN / 8; i++) { filter3(&tmp_buf[8*i+0], &tmp_buf[8*i+4], &st->a_data3[0], pOverflow); filter3(&tmp_buf[8*i+2], &tmp_buf[8*i+6], &st->a_data3[1], pOverflow); filter3(&tmp_buf[8*i+3], &tmp_buf[8*i+7], &st->a_data3[4], pOverflow); } for (i = 0; i < FRAME_LEN / 16; i++) { filter3(&tmp_buf[16*i+0], &tmp_buf[16*i+8], &st->a_data3[2], pOverflow); filter3(&tmp_buf[16*i+4], &tmp_buf[16*i+12], &st->a_data3[3], pOverflow); } /* calculate levels in each frequency band */ /* 3000 - 4000 Hz*/ level[8] = level_calculation(tmp_buf, &st->sub_level[8], FRAME_LEN / 4 - 8, FRAME_LEN / 4, 4, 1, 15, pOverflow); /* 2500 - 3000 Hz*/ level[7] = level_calculation(tmp_buf, &st->sub_level[7], FRAME_LEN / 8 - 4, FRAME_LEN / 8, 8, 7, 16, pOverflow); /* 2000 - 2500 Hz*/ level[6] = level_calculation(tmp_buf, &st->sub_level[6], FRAME_LEN / 8 - 4, FRAME_LEN / 8, 8, 3, 16, pOverflow); /* 1500 - 2000 Hz*/ level[5] = level_calculation(tmp_buf, &st->sub_level[5], FRAME_LEN / 8 - 4, FRAME_LEN / 8, 8, 2, 16, pOverflow); /* 1000 - 1500 Hz*/ level[4] = level_calculation(tmp_buf, &st->sub_level[4], FRAME_LEN / 8 - 4, FRAME_LEN / 8, 8, 6, 16, pOverflow); /* 750 - 1000 Hz*/ level[3] = level_calculation(tmp_buf, &st->sub_level[3], FRAME_LEN / 16 - 2, FRAME_LEN / 16, 16, 4, 16, pOverflow); /* 500 - 750 Hz*/ level[2] = level_calculation(tmp_buf, &st->sub_level[2], FRAME_LEN / 16 - 2, FRAME_LEN / 16, 16, 12, 16, pOverflow); /* 250 - 500 Hz*/ level[1] = level_calculation(tmp_buf, &st->sub_level[1], FRAME_LEN / 16 - 2, FRAME_LEN / 16, 16, 8, 16, pOverflow); /* 0 - 250 Hz*/ level[0] = level_calculation(tmp_buf, &st->sub_level[0], FRAME_LEN / 16 - 2, FRAME_LEN / 16, 16, 0, 16, pOverflow);}/*------------------------------------------------------------------------------ FUNCTION NAME: update_cntrl------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: st -- pointer to type vadState1 -- State struct level -- array of type Word16 -- sub-band levels of the input frame Outputs: st -- pointer to type vadState1 -- State struct pOverflow -- pointer to type Flag -- overflow indicator Returns: None Global Variables Used: None Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose : Control update of the background noise estimate. Inputs : pitch: flags for pitch detection stat_count: stationary counter tone: flags indicating presence of a tone complex: flags for complex detection vadreg: intermediate VAD flags Output : stat_count: stationary counter------------------------------------------------------------------------------ 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 void update_cntrl( vadState1 *st, /* i/o : State struct */ Word16 level[], /* i : sub-band levels of the input frame */ Flag *pOverflow /* o : Flag set when overflow occurs */){ Word16 i; Word16 temp; Word16 stat_rat; Word16 exp; Word16 num; Word16 denom; Word16 alpha; /* handle highband complex signal input separately */ /* if ther has been highband correlation for some time */ /* make sure that the VAD update speed is low for a while */ if (st->complex_warning != 0) { if (st->stat_count < CAD_MIN_STAT_COUNT) { st->stat_count = CAD_MIN_STAT_COUNT; } } /* NB stat_count is allowed to be decreased by one below again */ /* deadlock in speech is not possible unless the signal is very */ /* complex and need a high rate */ /* if fullband pitch or tone have been detected for a while, initialize stat_count */ if (((Word16)(st->pitch & 0x6000) == 0x6000) || ((Word16)(st->tone & 0x7c00) == 0x7c00)) { st->stat_count = STAT_COUNT; } else { /* if 8 last vad-decisions have been "0", reinitialize stat_count */ if ((st->vadreg & 0x7f80) == 0) { st->stat_count = STAT_COUNT; } else { stat_rat = 0; for (i = 0; i < COMPLEN; i++) { if (level[i] > st->ave_level[i]) { num = level[i]; denom = st->ave_level[i]; } else { num = st->ave_level[i]; denom = level[i]; } /* Limit nimimum value of num and denom to STAT_THR_LEVEL */ if (num < STAT_THR_LEVEL) { num = STAT_THR_LEVEL; } if (denom < STAT_THR_LEVEL) { denom = STAT_THR_LEVEL; } exp = norm_s(denom); denom = shl(denom, exp, pOverflow); /* stat_rat = num/denom * 64 */ temp = shr(num, 1, pOverflow); temp = div_s(temp, denom); stat_rat = add(stat_rat, shr(temp, sub(8, exp, pOverflow), pOverflow), pOverflow); } /* compare stat_rat with a threshold and update stat_count */ if (stat_rat > STAT_THR) { st->stat_count = STAT_COUNT; } else { if ((st->vadreg & 0x4000) != 0) { if (st->stat_count != 0) { st->stat_count = sub(st->stat_count, 1, pOverflow); } } } } } /* Update average amplitude estimate for stationarity estimation */ alpha = ALPHA4; if (st->stat_count == STAT_COUNT) { alpha = 32767; } else if ((st->vadreg & 0x4000) == 0) { alpha = ALPHA5; } for (i = 0; i < COMPLEN; i++) { temp = sub(level[i], st->ave_level[i], pOverflow); temp = mult_r(alpha, temp, pOverflow); st->ave_level[i] = add( st->ave_level[i], temp, pOverflow); }}/*------------------------------------------------------------------------------ FUNCTION NAME: hangover_addition------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: noise_level -- Word16 -- average level of the noise estimates low_power -- Word16 -- flag power of the input frame Outputs: st -- pointer to type vadState1 -- State struct pOverflow -- pointer to type Flag -- overflow indicato Returns: VAD_flag indicating final VAD decision (Word16) Global Variables Used:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -