diff options
Diffstat (limited to 'media/libstagefright/codecs/amrwbenc/src/wb_vad.c')
-rw-r--r-- | media/libstagefright/codecs/amrwbenc/src/wb_vad.c | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/media/libstagefright/codecs/amrwbenc/src/wb_vad.c b/media/libstagefright/codecs/amrwbenc/src/wb_vad.c index 7e1d673..13dd2aa 100644 --- a/media/libstagefright/codecs/amrwbenc/src/wb_vad.c +++ b/media/libstagefright/codecs/amrwbenc/src/wb_vad.c @@ -52,7 +52,7 @@ static Word16 ilog2( /* return: output value of the log2 * if (mant <= 0) { - mant = 1; + mant = 1; } ex = norm_s(mant); mant = mant << ex; @@ -88,14 +88,14 @@ static void filter5( temp0 = vo_sub(*in0, vo_mult(COEFF5_1, data[0])); temp1 = add1(data[0], vo_mult(COEFF5_1, temp0)); - data[0] = temp0; + data[0] = temp0; temp0 = vo_sub(*in1, vo_mult(COEFF5_2, data[1])); temp2 = add1(data[1], vo_mult(COEFF5_2, temp0)); - data[1] = temp0; + data[1] = temp0; - *in0 = extract_h((vo_L_add(temp1, temp2) << 15)); - *in1 = extract_h((vo_L_sub(temp1, temp2) << 15)); + *in0 = extract_h((vo_L_add(temp1, temp2) << 15)); + *in1 = extract_h((vo_L_sub(temp1, temp2) << 15)); } /****************************************************************************** @@ -116,10 +116,10 @@ static void filter3( temp1 = vo_sub(*in1, vo_mult(COEFF3, *data)); temp2 = add1(*data, vo_mult(COEFF3, temp1)); - *data = temp1; + *data = temp1; - *in1 = extract_h((vo_L_sub(*in0, temp2) << 15)); - *in0 = extract_h((vo_L_add(*in0, temp2) << 15)); + *in1 = extract_h((vo_L_sub(*in0, temp2) << 15)); + *in0 = extract_h((vo_L_add(*in0, temp2) << 15)); } /****************************************************************************** @@ -149,14 +149,14 @@ static Word16 level_calculation( /* return: signal level */ Word32 i, l_temp1, l_temp2; Word16 level; - l_temp1 = 0L; + l_temp1 = 0L; for (i = count1; i < count2; i++) { l_temp1 += (abs_s(data[ind_m * i + ind_a])<<1); } l_temp2 = vo_L_add(l_temp1, L_shl(*sub_level, 16 - scale)); - *sub_level = extract_h(L_shl(l_temp1, scale)); + *sub_level = extract_h(L_shl(l_temp1, scale)); for (i = 0; i < count1; i++) { @@ -187,7 +187,7 @@ static void filter_bank( /* shift input 1 bit down for safe scaling */ for (i = 0; i < FRAME_LEN; i++) { - tmp_buf[i] = in[i] >> 1; + tmp_buf[i] = in[i] >> 1; } /* run the filter bank */ @@ -222,29 +222,29 @@ static void filter_bank( /* calculate levels in each frequency band */ /* 4800 - 6400 Hz */ - level[11] = level_calculation(tmp_buf, &st->sub_level[11], 16, 64, 4, 1, 14); + level[11] = level_calculation(tmp_buf, &st->sub_level[11], 16, 64, 4, 1, 14); /* 4000 - 4800 Hz */ - level[10] = level_calculation(tmp_buf, &st->sub_level[10], 8, 32, 8, 7, 15); + level[10] = level_calculation(tmp_buf, &st->sub_level[10], 8, 32, 8, 7, 15); /* 3200 - 4000 Hz */ - level[9] = level_calculation(tmp_buf, &st->sub_level[9],8, 32, 8, 3, 15); + level[9] = level_calculation(tmp_buf, &st->sub_level[9],8, 32, 8, 3, 15); /* 2400 - 3200 Hz */ - level[8] = level_calculation(tmp_buf, &st->sub_level[8],8, 32, 8, 2, 15); + level[8] = level_calculation(tmp_buf, &st->sub_level[8],8, 32, 8, 2, 15); /* 2000 - 2400 Hz */ - level[7] = level_calculation(tmp_buf, &st->sub_level[7],4, 16, 16, 14, 16); + level[7] = level_calculation(tmp_buf, &st->sub_level[7],4, 16, 16, 14, 16); /* 1600 - 2000 Hz */ - level[6] = level_calculation(tmp_buf, &st->sub_level[6],4, 16, 16, 6, 16); + level[6] = level_calculation(tmp_buf, &st->sub_level[6],4, 16, 16, 6, 16); /* 1200 - 1600 Hz */ - level[5] = level_calculation(tmp_buf, &st->sub_level[5],4, 16, 16, 4, 16); + level[5] = level_calculation(tmp_buf, &st->sub_level[5],4, 16, 16, 4, 16); /* 800 - 1200 Hz */ - level[4] = level_calculation(tmp_buf, &st->sub_level[4],4, 16, 16, 12, 16); + level[4] = level_calculation(tmp_buf, &st->sub_level[4],4, 16, 16, 12, 16); /* 600 - 800 Hz */ - level[3] = level_calculation(tmp_buf, &st->sub_level[3],2, 8, 32, 8, 17); + level[3] = level_calculation(tmp_buf, &st->sub_level[3],2, 8, 32, 8, 17); /* 400 - 600 Hz */ - level[2] = level_calculation(tmp_buf, &st->sub_level[2],2, 8, 32, 24, 17); + level[2] = level_calculation(tmp_buf, &st->sub_level[2],2, 8, 32, 24, 17); /* 200 - 400 Hz */ - level[1] = level_calculation(tmp_buf, &st->sub_level[1],2, 8, 32, 16, 17); + level[1] = level_calculation(tmp_buf, &st->sub_level[1],2, 8, 32, 16, 17); /* 0 - 200 Hz */ - level[0] = level_calculation(tmp_buf, &st->sub_level[0],2, 8, 32, 0, 17); + level[0] = level_calculation(tmp_buf, &st->sub_level[0],2, 8, 32, 0, 17); } /****************************************************************************** @@ -266,31 +266,31 @@ static void update_cntrl( /* if a tone has been detected for a while, initialize stat_count */ if (sub((Word16) (st->tone_flag & 0x7c00), 0x7c00) == 0) { - st->stat_count = STAT_COUNT; + 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; + st->stat_count = STAT_COUNT; } else { - stat_rat = 0; + stat_rat = 0; for (i = 0; i < COMPLEN; i++) { if(level[i] > st->ave_level[i]) { - num = level[i]; - denom = st->ave_level[i]; + num = level[i]; + denom = st->ave_level[i]; } else { num = st->ave_level[i]; - denom = 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; + num = STAT_THR_LEVEL; } if(denom < STAT_THR_LEVEL) { @@ -307,7 +307,7 @@ static void update_cntrl( /* compare stat_rat with a threshold and update stat_count */ if(stat_rat > STAT_THR) { - st->stat_count = STAT_COUNT; + st->stat_count = STAT_COUNT; } else { if ((st->vadreg & 0x4000) != 0) @@ -315,7 +315,7 @@ static void update_cntrl( if (st->stat_count != 0) { - st->stat_count = st->stat_count - 1; + st->stat_count = st->stat_count - 1; } } } @@ -323,17 +323,17 @@ static void update_cntrl( } /* Update average amplitude estimate for stationarity estimation */ - alpha = ALPHA4; + alpha = ALPHA4; if(st->stat_count == STAT_COUNT) { - alpha = 32767; + alpha = 32767; } else if ((st->vadreg & 0x4000) == 0) { - alpha = ALPHA5; + alpha = ALPHA5; } for (i = 0; i < COMPLEN; i++) { - st->ave_level[i] = add1(st->ave_level[i], vo_mult_r(alpha, vo_sub(level[i], st->ave_level[i]))); + st->ave_level[i] = add1(st->ave_level[i], vo_mult_r(alpha, vo_sub(level[i], st->ave_level[i]))); } } @@ -354,25 +354,25 @@ static Word16 hangover_addition( /* return: VAD_flag indica /* if the input power (pow_sum) is lower than a threshold, clear counters and set VAD_flag to "0" */ if (low_power != 0) { - st->burst_count = 0; - st->hang_count = 0; + st->burst_count = 0; + st->hang_count = 0; return 0; } /* update the counters (hang_count, burst_count) */ if ((st->vadreg & 0x4000) != 0) { - st->burst_count = st->burst_count + 1; + st->burst_count = st->burst_count + 1; if(st->burst_count >= burst_len) { - st->hang_count = hang_len; + st->hang_count = hang_len; } return 1; } else { - st->burst_count = 0; + st->burst_count = 0; if (st->hang_count > 0) { - st->hang_count = st->hang_count - 1; + st->hang_count = st->hang_count - 1; return 1; } } @@ -391,7 +391,7 @@ static void noise_estimate_update( Word16 level[] /* i : sub-band levels of the input frame */ ) { - Word32 i; + Word32 i; Word16 alpha_up, alpha_down, bckr_add = 2; /* Control update of bckr_est[] */ @@ -400,19 +400,19 @@ static void noise_estimate_update( /* Choose update speed */ if ((0x7800 & st->vadreg) == 0) { - alpha_up = ALPHA_UP1; - alpha_down = ALPHA_DOWN1; + alpha_up = ALPHA_UP1; + alpha_down = ALPHA_DOWN1; } else { if ((st->stat_count == 0)) { - alpha_up = ALPHA_UP2; - alpha_down = ALPHA_DOWN2; + alpha_up = ALPHA_UP2; + alpha_down = ALPHA_DOWN2; } else { - alpha_up = 0; - alpha_down = ALPHA3; - bckr_add = 0; + alpha_up = 0; + alpha_down = ALPHA3; + bckr_add = 0; } } @@ -424,20 +424,20 @@ static void noise_estimate_update( if (temp < 0) { /* update downwards */ - st->bckr_est[i] = add1(-2, add(st->bckr_est[i],vo_mult_r(alpha_down, temp))); + st->bckr_est[i] = add1(-2, add(st->bckr_est[i],vo_mult_r(alpha_down, temp))); /* limit minimum value of the noise estimate to NOISE_MIN */ if(st->bckr_est[i] < NOISE_MIN) { - st->bckr_est[i] = NOISE_MIN; + st->bckr_est[i] = NOISE_MIN; } } else { /* update upwards */ - st->bckr_est[i] = add1(bckr_add, add1(st->bckr_est[i],vo_mult_r(alpha_up, temp))); + st->bckr_est[i] = add1(bckr_add, add1(st->bckr_est[i],vo_mult_r(alpha_up, temp))); /* limit maximum value of the noise estimate to NOISE_MAX */ if(st->bckr_est[i] > NOISE_MAX) { - st->bckr_est[i] = NOISE_MAX; + st->bckr_est[i] = NOISE_MAX; } } } @@ -445,7 +445,7 @@ static void noise_estimate_update( /* Update signal levels of the previous frame (old_level) */ for (i = 0; i < COMPLEN; i++) { - st->old_level[i] = level[i]; + st->old_level[i] = level[i]; } } @@ -473,7 +473,7 @@ static Word16 vad_decision( /* return value : VAD_flag /* Calculate squared sum of the input levels (level) divided by the background noise components * (bckr_est). */ - L_snr_sum = 0; + L_snr_sum = 0; for (i = 0; i < COMPLEN; i++) { Word16 exp; @@ -486,7 +486,7 @@ static Word16 vad_decision( /* return value : VAD_flag } /* Calculate average level of estimated background noise */ - L_temp = 0; + L_temp = 0; for (i = 1; i < COMPLEN; i++) /* ignore lowest band */ { L_temp = vo_L_add(L_temp, st->bckr_est[i]); @@ -498,7 +498,7 @@ static Word16 vad_decision( /* return value : VAD_flag if(st->speech_level < temp) { - st->speech_level = temp; + st->speech_level = temp; } ilog2_noise_level = ilog2(noise_level); @@ -511,33 +511,33 @@ static Word16 vad_decision( /* return value : VAD_flag temp2 = add1(SP_CH_MIN, vo_mult(SP_SLOPE, (ilog2_speech_level - SP_P1))); if (temp2 < SP_CH_MIN) { - temp2 = SP_CH_MIN; + temp2 = SP_CH_MIN; } if (temp2 > SP_CH_MAX) { - temp2 = SP_CH_MAX; + temp2 = SP_CH_MAX; } vad_thr = temp + temp2; if(vad_thr < THR_MIN) { - vad_thr = THR_MIN; + vad_thr = THR_MIN; } /* Shift VAD decision register */ - st->vadreg = (st->vadreg >> 1); + st->vadreg = (st->vadreg >> 1); /* Make intermediate VAD decision */ if(L_snr_sum > vo_L_mult(vad_thr, (512 * COMPLEN))) { - st->vadreg = (Word16) (st->vadreg | 0x4000); + st->vadreg = (Word16) (st->vadreg | 0x4000); } /* check if the input power (pow_sum) is lower than a threshold" */ if(pow_sum < VAD_POW_LOW) { - low_power_flag = 1; + low_power_flag = 1; } else { - low_power_flag = 0; + low_power_flag = 0; } /* Update background noise estimates */ noise_estimate_update(st, level); @@ -546,7 +546,7 @@ static Word16 vad_decision( /* return value : VAD_flag hang_len = add1(vo_mult(HANG_SLOPE, (vad_thr - HANG_P1)), HANG_HIGH); if(hang_len < HANG_LOW) { - hang_len = HANG_LOW; + hang_len = HANG_LOW; } burst_len = add1(vo_mult(BURST_SLOPE, (vad_thr - BURST_P1)), BURST_HIGH); @@ -575,20 +575,20 @@ static void Estimate_Speech( /* if the required activity count cannot be achieved, reset counters */ if((st->sp_est_cnt - st->sp_max_cnt) > (SP_EST_COUNT - SP_ACTIVITY_COUNT)) { - st->sp_est_cnt = 0; - st->sp_max = 0; - st->sp_max_cnt = 0; + st->sp_est_cnt = 0; + st->sp_max = 0; + st->sp_max_cnt = 0; } - st->sp_est_cnt += 1; + st->sp_est_cnt += 1; if (((st->vadreg & 0x4000)||(in_level > st->speech_level)) && (in_level > MIN_SPEECH_LEVEL1)) { /* update sp_max */ if(in_level > st->sp_max) { - st->sp_max = in_level; + st->sp_max = in_level; } - st->sp_max_cnt += 1; + st->sp_max_cnt += 1; if(st->sp_max_cnt >= SP_ACTIVITY_COUNT) { @@ -599,19 +599,19 @@ static void Estimate_Speech( /* select update speed */ if(tmp > st->speech_level) { - alpha = ALPHA_SP_UP; + alpha = ALPHA_SP_UP; } else { - alpha = ALPHA_SP_DOWN; + alpha = ALPHA_SP_DOWN; } if(tmp > MIN_SPEECH_LEVEL2) { - st->speech_level = add1(st->speech_level, vo_mult_r(alpha, vo_sub(tmp, st->speech_level))); + st->speech_level = add1(st->speech_level, vo_mult_r(alpha, vo_sub(tmp, st->speech_level))); } /* clear all counters used for speech estimation */ - st->sp_max = 0; - st->sp_max_cnt = 0; - st->sp_est_cnt = 0; + st->sp_max = 0; + st->sp_max_cnt = 0; + st->sp_est_cnt = 0; } } } @@ -767,22 +767,22 @@ Word16 wb_vad( /* Return value : VAD Decision, 1 Word32 L_temp, pow_sum; /* Calculate power of the input frame. */ - L_temp = 0L; + L_temp = 0L; for (i = 0; i < FRAME_LEN; i++) { L_temp = L_mac(L_temp, in_buf[i], in_buf[i]); } /* pow_sum = power of current frame and previous frame */ - pow_sum = L_add(L_temp, st->prev_pow_sum); + pow_sum = L_add(L_temp, st->prev_pow_sum); /* save power of current frame for next call */ - st->prev_pow_sum = L_temp; + st->prev_pow_sum = L_temp; /* If input power is very low, clear tone flag */ if (pow_sum < POW_TONE_THR) { - st->tone_flag = (Word16) (st->tone_flag & 0x1fff); + st->tone_flag = (Word16) (st->tone_flag & 0x1fff); } /* Run the filter bank and calculate signal levels at each band */ filter_bank(st, in_buf, level); @@ -791,7 +791,7 @@ Word16 wb_vad( /* Return value : VAD Decision, 1 VAD_flag = vad_decision(st, level, pow_sum); /* Calculate input level */ - L_temp = 0; + L_temp = 0; for (i = 1; i < COMPLEN; i++) /* ignore lowest band */ { L_temp = vo_L_add(L_temp, level[i]); |