Changeset 655 for pjproject/trunk/pjmedia/src/pjmedia/silencedet.c
- Timestamp:
- Aug 6, 2006 2:15:47 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/silencedet.c
r465 r655 39 39 struct pjmedia_silence_det 40 40 { 41 char objname[PJ_MAX_OBJ_NAME]; /**< VAD name. */ 42 41 43 int mode; /**< VAD mode. */ 42 44 unsigned ptime; /**< Frame time, in msec. */ … … 71 73 sd = pj_pool_zalloc(pool, sizeof(struct pjmedia_silence_det)); 72 74 75 pj_ansi_strncpy(sd->objname, THIS_FILE, PJ_MAX_OBJ_NAME); 76 sd->objname[PJ_MAX_OBJ_NAME-1] = '\0'; 77 73 78 sd->ptime = samples_per_frame * 1000 / clock_rate; 74 79 sd->signal_cnt = 0; … … 87 92 return PJ_SUCCESS; 88 93 } 94 95 96 PJ_DEF(pj_status_t) pjmedia_silence_det_set_name( pjmedia_silence_det *sd, 97 const char *name) 98 { 99 PJ_ASSERT_RETURN(sd && name, PJ_EINVAL); 100 101 pj_ansi_snprintf(sd->objname, PJ_MAX_OBJ_NAME, name, sd); 102 sd->objname[PJ_MAX_OBJ_NAME-1] = '\0'; 103 return PJ_SUCCESS; 104 } 105 89 106 90 107 PJ_DEF(pj_status_t) pjmedia_silence_det_set_adaptive(pjmedia_silence_det *sd, … … 234 251 if (sd->mode == VAD_MODE_ADAPTIVE) { 235 252 pj_bool_t updated = PJ_TRUE; 236 unsigned pct_signal ;253 unsigned pct_signal, new_threshold = sd->cur_threshold; 237 254 238 255 /* Get percentage of signal */ … … 242 259 /* Adjust according to signal/silence proportions. */ 243 260 if (pct_signal > 95) { 244 sd->cur_threshold += (sd->weakest_signal - sd->cur_threshold)/4;261 new_threshold += (sd->weakest_signal - sd->cur_threshold)/4; 245 262 } else if (pct_signal < 5) { 246 sd->cur_threshold = (sd->cur_threshold+sd->loudest_silence)/2+1;263 new_threshold = (sd->cur_threshold+sd->loudest_silence)/2+1; 247 264 } else if (pct_signal > 90) { 248 sd->cur_threshold++;265 new_threshold++; 249 266 } else if (pct_signal < 10) { 250 sd->cur_threshold--;267 new_threshold--; 251 268 } else { 252 269 updated = PJ_FALSE; 253 270 } 254 271 255 if (updated) { 256 PJ_LOG(5,(THIS_FILE, "Vad cur_threshold updated to %d", 272 if (updated && sd->cur_threshold != new_threshold) { 273 sd->cur_threshold = new_threshold; 274 PJ_LOG(5,(sd->objname, "Vad cur_threshold updated to %d", 257 275 sd->cur_threshold)); 258 276 }
Note: See TracChangeset
for help on using the changeset viewer.