--- apps/app_amd.c.old 2018-02-01 16:05:12.242093243 -0500 +++ apps/app_amd.c 2018-02-01 21:51:01.536223303 -0500 @@ -166,7 +166,7 @@ int res = 0; struct ast_frame *f = NULL; struct ast_dsp *silenceDetector = NULL; - int dspsilence = 0, framelength = 0; + int dspsilence = 0; RAII_VAR(struct ast_format *, readFormat, NULL, ao2_cleanup); int inInitialSilence = 1; int inGreeting = 0; @@ -290,14 +290,16 @@ } if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_NULL || f->frametype == AST_FRAME_CNG) { - /* If the total time exceeds the analysis time then give up as we are not too sure */ - if (f->frametype == AST_FRAME_VOICE) { - framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS); - } else { - framelength = 2 * maxWaitTimeForFrame; + if ( f->frametype == AST_FRAME_VOICE ) { + ast_debug(1, "AMD: Channel [%s] frametype [AST_FRAME_VOICE] iTotalTime [%d] framelength [%d] totalAnalysisTime [%d]\n", ast_channel_name(chan), iTotalTime, f->len, totalAnalysisTime ); + } else if ( f->frametype == AST_FRAME_NULL ) { + ast_debug(1, "AMD: Channel [%s] frametype [AST_FRAME_NULL] iTotalTime [%d] framelength [%d] totalAnalysisTime [%d]\n", ast_channel_name(chan), iTotalTime, f->len, totalAnalysisTime ); + } else if ( f->frametype == AST_FRAME_CNG ) { + ast_debug(1, "AMD: Channel [%s] frametype [AST_FRAME_CNG] iTotalTime [%d] framelength [%d] totalAnalysisTime [%d]\n", ast_channel_name(chan), iTotalTime, f->len, totalAnalysisTime ); } - iTotalTime += framelength; + /* If the total time exceeds the analysis time then give up as we are not too sure */ + iTotalTime += f->len; if (iTotalTime >= totalAnalysisTime) { ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan)); ast_frfree(f); @@ -308,7 +310,7 @@ /* Feed the frame of audio into the silence detector and see if we get a result */ if (f->frametype != AST_FRAME_VOICE) - dspsilence += 2 * maxWaitTimeForFrame; + dspsilence += f->len; else { dspsilence = 0; ast_dsp_silence(silenceDetector, f, &dspsilence); @@ -350,8 +352,8 @@ } } else { - consecutiveVoiceDuration += framelength; - voiceDuration += framelength; + consecutiveVoiceDuration += f->len; + voiceDuration += f->len; /* If I have enough consecutive voice to say that I am in a Word, I can only increment the number of words if my previous state was Silence, which means that I moved into a word. */